diff options
author | Shivani Bhardwaj <shivanib134@gmail.com> | 2016-11-07 17:58:46 +0530 |
---|---|---|
committer | Pablo Neira Ayuso <pablo@netfilter.org> | 2016-11-10 01:34:19 +0100 |
commit | a6a4c04c14e07498026765f85f6b45bc5487d0fe (patch) | |
tree | 53afe0f1048515e3b6e264b9763247883f5a4590 | |
parent | 1ffa23d53cd9bacc272848c92823c1e2c8c71fed (diff) | |
download | platform_external_iptables-a6a4c04c14e07498026765f85f6b45bc5487d0fe.tar.gz platform_external_iptables-a6a4c04c14e07498026765f85f6b45bc5487d0fe.tar.bz2 platform_external_iptables-a6a4c04c14e07498026765f85f6b45bc5487d0fe.zip |
iptables: xtables-arp: Use getaddrinfo()
Replace gethostbyname() with getaddrinfo() as getaddrinfo()
deprecates the former and allows programs to eliminate
IPv4-versus-IPv6 dependencies.
Signed-off-by: Shivani Bhardwaj <shivanib134@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
-rw-r--r-- | iptables/xtables-arp.c | 28 |
1 files changed, 18 insertions, 10 deletions
diff --git a/iptables/xtables-arp.c b/iptables/xtables-arp.c index 346bece9..bd6d57c2 100644 --- a/iptables/xtables-arp.c +++ b/iptables/xtables-arp.c @@ -587,22 +587,30 @@ check_inverse(const char option[], int *invert, int *optidx, int argc) static struct in_addr * host_to_addr(const char *name, unsigned int *naddr) { - struct hostent *host; struct in_addr *addr; + struct addrinfo hints; + struct addrinfo *res, *p; + int err; unsigned int i; - *naddr = 0; - if ((host = gethostbyname(name)) != NULL) { - if (host->h_addrtype != AF_INET || - host->h_length != sizeof(struct in_addr)) - return (struct in_addr *) NULL; + memset(&hints, 0, sizeof(hints)); + hints.ai_flags = AI_CANONNAME; + hints.ai_family = AF_INET; + hints.ai_socktype = SOCK_RAW; - while (host->h_addr_list[*naddr] != (char *) NULL) + *naddr = 0; + err = getaddrinfo(name, NULL, &hints, &res); + if (err != 0) + return NULL; + else { + for (p = res; p != NULL; p = p->ai_next) (*naddr)++; addr = xtables_calloc(*naddr, sizeof(struct in_addr)); - for (i = 0; i < *naddr; i++) - inaddrcpy(&(addr[i]), - (struct in_addr *) host->h_addr_list[i]); + for (i = 0, p = res; p != NULL; p = p->ai_next) + memcpy(&addr[i++], + &((const struct sockaddr_in *)p->ai_addr)->sin_addr, + sizeof(struct in_addr)); + freeaddrinfo(res); return addr; } |