From ba43fb8406b94ff9374cc2f679467a74bb7458f2 Mon Sep 17 00:00:00 2001 From: Remi NGUYEN VAN Date: Tue, 23 Mar 2021 00:57:38 +0000 Subject: 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 Merged-In: I42f0d9b17b3058f6e10fd2e651278b290f26667f Change-Id: Id6c40145b8886a7ec6f2bd3a25ad85e8df32f4bb --- native/android/net.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'native/android/net.c') 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) { -- cgit v1.2.3-59-g8ed1b