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: rec-4.2.0-alpha1~57^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=refs%2Fpull%2F7341%2Fhead;p=thirdparty%2Fpdns.git 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. --- diff --git a/pdns/nameserver.cc b/pdns/nameserver.cc index 64757705ec..60e2e72ed5 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);