Add NetworkUtil function for marking sockets
Add NetworkUtil function for setting the SO_MARK field of sockets Change-Id: I94389b64296d87ee928293f24a26f8dd08c3bf37
This commit is contained in:
committed by
Geremy Condra
parent
a77b479408
commit
3f3b4e6462
@@ -103,6 +103,11 @@ public class NetworkUtils {
|
|||||||
*/
|
*/
|
||||||
public native static String getDhcpError();
|
public native static String getDhcpError();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the SO_MARK of {@code socketfd} to {@code mark}
|
||||||
|
*/
|
||||||
|
public native static void markSocket(int socketfd, int mark);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert a IPv4 address from an integer to an InetAddress.
|
* Convert a IPv4 address from an integer to an InetAddress.
|
||||||
* @param hostAddress an int corresponding to the IPv4 address in network byte order
|
* @param hostAddress an int corresponding to the IPv4 address in network byte order
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
#define LOG_TAG "NetUtils"
|
#define LOG_TAG "NetUtils"
|
||||||
|
|
||||||
#include "jni.h"
|
#include "jni.h"
|
||||||
|
#include "JNIHelp.h"
|
||||||
#include <utils/misc.h>
|
#include <utils/misc.h>
|
||||||
#include <android_runtime/AndroidRuntime.h>
|
#include <android_runtime/AndroidRuntime.h>
|
||||||
#include <utils/Log.h>
|
#include <utils/Log.h>
|
||||||
@@ -239,6 +240,13 @@ static jstring android_net_utils_getDhcpError(JNIEnv* env, jobject clazz)
|
|||||||
return env->NewStringUTF(::dhcp_get_errmsg());
|
return env->NewStringUTF(::dhcp_get_errmsg());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void android_net_utils_markSocket(JNIEnv *env, jobject thiz, jint socket, jint mark)
|
||||||
|
{
|
||||||
|
if (setsockopt(socket, SOL_SOCKET, SO_MARK, &mark, sizeof(mark)) < 0) {
|
||||||
|
jniThrowException(env, "java/lang/IllegalStateException", "Error marking socket");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -255,6 +263,7 @@ static JNINativeMethod gNetworkUtilMethods[] = {
|
|||||||
{ "stopDhcp", "(Ljava/lang/String;)Z", (void *)android_net_utils_stopDhcp },
|
{ "stopDhcp", "(Ljava/lang/String;)Z", (void *)android_net_utils_stopDhcp },
|
||||||
{ "releaseDhcpLease", "(Ljava/lang/String;)Z", (void *)android_net_utils_releaseDhcpLease },
|
{ "releaseDhcpLease", "(Ljava/lang/String;)Z", (void *)android_net_utils_releaseDhcpLease },
|
||||||
{ "getDhcpError", "()Ljava/lang/String;", (void*) android_net_utils_getDhcpError },
|
{ "getDhcpError", "()Ljava/lang/String;", (void*) android_net_utils_getDhcpError },
|
||||||
|
{ "markSocket", "(II)V", (void*) android_net_utils_markSocket },
|
||||||
};
|
};
|
||||||
|
|
||||||
int register_android_net_NetworkUtils(JNIEnv* env)
|
int register_android_net_NetworkUtils(JNIEnv* env)
|
||||||
|
|||||||
Reference in New Issue
Block a user