Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 12324b46 authored by Chad Brubaker's avatar Chad Brubaker Committed by Geremy Condra
Browse files

Add NetworkUtil function for marking sockets

Add NetworkUtil function for setting the SO_MARK field of sockets

Change-Id: I94389b64296d87ee928293f24a26f8dd08c3bf37
parent f33468e6
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -103,6 +103,11 @@ public class NetworkUtils {
     */
    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.
     * @param hostAddress an int corresponding to the IPv4 address in network byte order
+9 −0
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
#define LOG_TAG "NetUtils"

#include "jni.h"
#include "JNIHelp.h"
#include <utils/misc.h>
#include <android_runtime/AndroidRuntime.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());
}

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 },
    { "releaseDhcpLease", "(Ljava/lang/String;)Z",  (void *)android_net_utils_releaseDhcpLease },
    { "getDhcpError", "()Ljava/lang/String;", (void*) android_net_utils_getDhcpError },
    { "markSocket", "(II)V", (void*) android_net_utils_markSocket },
};

int register_android_net_NetworkUtils(JNIEnv* env)