Loading core/jni/Android.bp +1 −0 Original line number Diff line number Diff line Loading @@ -227,6 +227,7 @@ cc_library_shared { shared_libs: [ "android.hardware.memtrack-V1-ndk_platform", "libandroidicu", "libandroid_net", "libbpf_android", "libnetdbpf", "libnetdutils", Loading native/android/libandroid.map.txt +1 −0 Original line number Diff line number Diff line Loading @@ -274,6 +274,7 @@ LIBANDROID { ATrace_endAsyncSection; # introduced=29 ATrace_setCounter; # introduced=29 android_getaddrinfofornetwork; # introduced=23 android_getprocnetwork; # introduced=31 android_setprocnetwork; # introduced=23 android_setsocknetwork; # introduced=23 android_res_cancel; # introduced=29 Loading native/android/libandroid_net.map.txt +2 −0 Original line number Diff line number Diff line Loading @@ -14,6 +14,8 @@ LIBANDROID_NET { android_res_nquery; # llndk android_res_nresult; # llndk android_res_nsend; # llndk # These functions have been part of the NDK since API 31. android_getprocnetwork; # llndk local: *; }; native/android/net.c +21 −3 Original line number Diff line number Diff line Loading @@ -22,12 +22,13 @@ #include <stdlib.h> #include <sys/limits.h> static int getnetidfromhandle(net_handle_t handle, unsigned *netid) { static const uint32_t k32BitMask = 0xffffffff; // This value MUST be kept in sync with the corresponding value in // the android.net.Network#getNetworkHandle() implementation. static const uint32_t kHandleMagic = 0xcafed00d; static const uint32_t kHandleMagicSize = 32; static int getnetidfromhandle(net_handle_t handle, unsigned *netid) { static const uint32_t k32BitMask = 0xffffffff; // Check for minimum acceptable version of the API in the low bits. if (handle != NETWORK_UNSPECIFIED && Loading @@ -41,6 +42,12 @@ static int getnetidfromhandle(net_handle_t handle, unsigned *netid) { return 1; } static net_handle_t gethandlefromnetid(unsigned netid) { if (netid == NETID_UNSET) { return NETWORK_UNSPECIFIED; } return (((net_handle_t) netid) << kHandleMagicSize) | kHandleMagic; } int android_setsocknetwork(net_handle_t network, int fd) { unsigned netid; Loading Loading @@ -72,6 +79,17 @@ int android_setprocnetwork(net_handle_t network) { return rval; } int android_getprocnetwork(net_handle_t *network) { if (network == NULL) { errno = EINVAL; return -1; } unsigned netid = getNetworkForProcess(); *network = gethandlefromnetid(netid); return 0; } int android_getaddrinfofornetwork(net_handle_t network, const char *node, const char *service, const struct addrinfo *hints, struct addrinfo **res) { Loading Loading
core/jni/Android.bp +1 −0 Original line number Diff line number Diff line Loading @@ -227,6 +227,7 @@ cc_library_shared { shared_libs: [ "android.hardware.memtrack-V1-ndk_platform", "libandroidicu", "libandroid_net", "libbpf_android", "libnetdbpf", "libnetdutils", Loading
native/android/libandroid.map.txt +1 −0 Original line number Diff line number Diff line Loading @@ -274,6 +274,7 @@ LIBANDROID { ATrace_endAsyncSection; # introduced=29 ATrace_setCounter; # introduced=29 android_getaddrinfofornetwork; # introduced=23 android_getprocnetwork; # introduced=31 android_setprocnetwork; # introduced=23 android_setsocknetwork; # introduced=23 android_res_cancel; # introduced=29 Loading
native/android/libandroid_net.map.txt +2 −0 Original line number Diff line number Diff line Loading @@ -14,6 +14,8 @@ LIBANDROID_NET { android_res_nquery; # llndk android_res_nresult; # llndk android_res_nsend; # llndk # These functions have been part of the NDK since API 31. android_getprocnetwork; # llndk local: *; };
native/android/net.c +21 −3 Original line number Diff line number Diff line Loading @@ -22,12 +22,13 @@ #include <stdlib.h> #include <sys/limits.h> static int getnetidfromhandle(net_handle_t handle, unsigned *netid) { static const uint32_t k32BitMask = 0xffffffff; // This value MUST be kept in sync with the corresponding value in // the android.net.Network#getNetworkHandle() implementation. static const uint32_t kHandleMagic = 0xcafed00d; static const uint32_t kHandleMagicSize = 32; static int getnetidfromhandle(net_handle_t handle, unsigned *netid) { static const uint32_t k32BitMask = 0xffffffff; // Check for minimum acceptable version of the API in the low bits. if (handle != NETWORK_UNSPECIFIED && Loading @@ -41,6 +42,12 @@ static int getnetidfromhandle(net_handle_t handle, unsigned *netid) { return 1; } static net_handle_t gethandlefromnetid(unsigned netid) { if (netid == NETID_UNSET) { return NETWORK_UNSPECIFIED; } return (((net_handle_t) netid) << kHandleMagicSize) | kHandleMagic; } int android_setsocknetwork(net_handle_t network, int fd) { unsigned netid; Loading Loading @@ -72,6 +79,17 @@ int android_setprocnetwork(net_handle_t network) { return rval; } int android_getprocnetwork(net_handle_t *network) { if (network == NULL) { errno = EINVAL; return -1; } unsigned netid = getNetworkForProcess(); *network = gethandlefromnetid(netid); return 0; } int android_getaddrinfofornetwork(net_handle_t network, const char *node, const char *service, const struct addrinfo *hints, struct addrinfo **res) { Loading