diff options
author | Remi NGUYEN VAN <reminv@google.com> | 2021-03-23 00:57:38 +0000 |
---|---|---|
committer | Remi NGUYEN VAN <reminv@google.com> | 2021-03-23 11:21:21 +0000 |
commit | 86ae725fb9832c50a244e2abe0d3c4a1d181a35c (patch) | |
tree | de2e1b1a59c01d7a2b5feb5b5574555ddff193d7 /native | |
parent | 49148d762db93e13ef0776c68df17563dce8921e (diff) |
Add NDK API for getprocdns,setprocdns
The API allows callers to control the default network that is used for
DNS hostname resolution.
Test: atest CtsNetTestCases
Tests in change I00143cafcd3eb1d71e8d5c7ea9c839a99dc6f4ce
Bug: 171540887
Change-Id: I42f0d9b17b3058f6e10fd2e651278b290f26667f
Diffstat (limited to 'native')
-rw-r--r-- | native/android/libandroid.map.txt | 2 | ||||
-rw-r--r-- | native/android/libandroid_net.map.txt | 2 | ||||
-rw-r--r-- | native/android/net.c | 32 |
3 files changed, 36 insertions, 0 deletions
diff --git a/native/android/libandroid.map.txt b/native/android/libandroid.map.txt index 85513cad489c..6d7badb08905 100644 --- a/native/android/libandroid.map.txt +++ b/native/android/libandroid.map.txt @@ -287,6 +287,8 @@ LIBANDROID { android_getaddrinfofornetwork; # introduced=23 android_getprocnetwork; # introduced=31 android_setprocnetwork; # introduced=23 + android_getprocdns; # introduced=31 + android_setprocdns; # introduced=31 android_setsocknetwork; # introduced=23 android_res_cancel; # introduced=29 android_res_nquery; # introduced=29 diff --git a/native/android/libandroid_net.map.txt b/native/android/libandroid_net.map.txt index cc8dd727408f..a6c1b5098066 100644 --- a/native/android/libandroid_net.map.txt +++ b/native/android/libandroid_net.map.txt @@ -16,6 +16,8 @@ LIBANDROID_NET { android_res_nsend; # llndk # These functions have been part of the NDK since API 31. android_getprocnetwork; # llndk + android_setprocdns; # llndk + android_getprocdns; # llndk local: *; }; diff --git a/native/android/net.c b/native/android/net.c index d4b888845b27..e2f36a77b7c6 100644 --- a/native/android/net.c +++ b/native/android/net.c @@ -90,6 +90,38 @@ int android_getprocnetwork(net_handle_t *network) { return 0; } +int android_setprocdns(net_handle_t network) { + unsigned netid; + if (!getnetidfromhandle(network, &netid)) { + errno = EINVAL; + return -1; + } + + int rval = setNetworkForResolv(netid); + if (rval < 0) { + errno = -rval; + rval = -1; + } + return rval; +} + +int android_getprocdns(net_handle_t *network) { + if (network == NULL) { + errno = EINVAL; + return -1; + } + + unsigned netid; + int rval = getNetworkForDns(&netid); + if (rval < 0) { + errno = -rval; + return -1; + } + + *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) { |