From: Fred Morcos Date: Wed, 16 Mar 2022 12:55:16 +0000 (+0100) Subject: Formatting makeIPv6sockaddr X-Git-Tag: rec-4.7.0-beta1~51^2~1 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=3a9b5bc57d2ba65f9f260f87f573804c80868d52;p=thirdparty%2Fpdns.git Formatting makeIPv6sockaddr --- diff --git a/pdns/misc.cc b/pdns/misc.cc index b14a7616ef..b13910a588 100644 --- a/pdns/misc.cc +++ b/pdns/misc.cc @@ -701,36 +701,34 @@ string stripDot(const string& dom) return dom.substr(0,dom.size()-1); } - - int makeIPv6sockaddr(const std::string& addr, struct sockaddr_in6* ret) { - if(addr.empty()) + if (addr.empty()) return -1; string ourAddr(addr); bool portSet = false; uint16_t port; - if(addr[0]=='[') { // [::]:53 style address + if (addr[0] == '[') { // [::]:53 style address string::size_type pos = addr.find(']'); - if(pos == string::npos) + if (pos == string::npos) return -1; - ourAddr.assign(addr.c_str() + 1, pos-1); + ourAddr.assign(addr.c_str() + 1, pos - 1); if (pos + 1 != addr.size()) { // complete after ], no port specified - if (pos + 2 > addr.size() || addr[pos+1]!=':') + if (pos + 2 > addr.size() || addr[pos + 1] != ':') return -1; try { pdns::checked_stoi_into(port, addr.substr(pos + 2)); portSet = true; } - catch(const std::out_of_range&) { + catch (const std::out_of_range&) { return -1; } } } - ret->sin6_scope_id=0; - ret->sin6_family=AF_INET6; + ret->sin6_scope_id = 0; + ret->sin6_family = AF_INET6; - if(inet_pton(AF_INET6, ourAddr.c_str(), (void*)&ret->sin6_addr) != 1) { + if (inet_pton(AF_INET6, ourAddr.c_str(), (void*)&ret->sin6_addr) != 1) { struct addrinfo* res; struct addrinfo hints; memset(&hints, 0, sizeof(hints)); @@ -747,7 +745,7 @@ int makeIPv6sockaddr(const std::string& addr, struct sockaddr_in6* ret) freeaddrinfo(res); } - if(portSet) { + if (portSet) { ret->sin6_port = htons(port); }