From 0c9de4fcb2221bda6720846106be61ead66c79de Mon Sep 17 00:00:00 2001 From: bert hubert Date: Wed, 21 May 2014 14:39:07 +0200 Subject: [PATCH] stay away from getaddrinfo unless we really can't help it for ascii ipv6 conversions to binary --- pdns/misc.cc | 35 ++++++++++++++++------------------- 1 file changed, 16 insertions(+), 19 deletions(-) diff --git a/pdns/misc.cc b/pdns/misc.cc index dbbc7f9d3..70f81170f 100644 --- a/pdns/misc.cc +++ b/pdns/misc.cc @@ -672,29 +672,26 @@ int makeIPv6sockaddr(const std::string& addr, struct sockaddr_in6* ret) port = atoi(addr.c_str()+pos+2); } - struct addrinfo* res; - struct addrinfo hints; - memset(&hints, 0, sizeof(hints)); - - hints.ai_family = AF_INET6; - hints.ai_flags = AI_NUMERICHOST; + if(inet_pton(AF_INET6, ourAddr.c_str(), (void*)&ret->sin6_addr) != 1) { + struct addrinfo* res; + struct addrinfo hints; + memset(&hints, 0, sizeof(hints)); + + hints.ai_family = AF_INET6; + hints.ai_flags = AI_NUMERICHOST; + + int error; + if((error=getaddrinfo(ourAddr.c_str(), 0, &hints, &res))) { // this is correct + return -1; + } - int error; - if((error=getaddrinfo(ourAddr.c_str(), 0, &hints, &res))) { // this is correct - /* - cerr<<"Error translating IPv6 address '"<ai_addr, res->ai_addrlen); + freeaddrinfo(res); } - - memcpy(ret, res->ai_addr, res->ai_addrlen); + if(port >= 0) ret->sin6_port = htons(port); - freeaddrinfo(res); + return 0; } -- 2.40.0