From: bert hubert Date: Mon, 7 Jan 2019 14:28:37 +0000 (+0100) Subject: Fix replying from ANY address for non-standard port X-Git-Tag: auth-4.1.8~2^2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b4924b2057957b8ff6119166794886f75a71ea9e;p=pdns Fix replying from ANY address for non-standard port Previously, we would not recognize 0.0.0.0:5300 or even 0.0.0.0:53 as the 'any' address, leading us to answer from the wrong address. (cherry picked from commit 36025a51ed16e31e5d186b2c126ef1178a39a569) --- diff --git a/pdns/nameserver.cc b/pdns/nameserver.cc index 0222cd17f..30df153de 100644 --- a/pdns/nameserver.cc +++ b/pdns/nameserver.cc @@ -112,10 +112,12 @@ void UDPNameserver::bindIPv4() if(!setNonBlocking(s)) throw PDNSException("Unable to set UDP socket to non-blocking: "+stringerror()); - locala.reset(); - locala.sin4.sin_family=AF_INET; + locala=ComboAddress(localname, ::arg().asNum("local-port")); + + if(locala.sin4.sin_family != AF_INET) + throw PDNSException("Attempting to bind IPv4 socket to IPv6 address"); - if(localname=="0.0.0.0") + if(IsAnyAddress(locala)) setsockopt(s, IPPROTO_IP, GEN_IP_PKTINFO, &one, sizeof(one)); if (!setSocketTimestamps(s)) @@ -130,9 +132,6 @@ void UDPNameserver::bindIPv4() if( ::arg().mustDo("non-local-bind") ) Utility::setBindAny(AF_INET, s); - locala=ComboAddress(localname, ::arg().asNum("local-port")); - if(locala.sin4.sin_family != AF_INET) - throw PDNSException("Attempting to bind IPv4 socket to IPv6 address"); if( !d_additional_socket ) g_localaddresses.push_back(locala);