From 36025a51ed16e31e5d186b2c126ef1178a39a569 Mon Sep 17 00:00:00 2001 From: bert hubert Date: Mon, 7 Jan 2019 15:28:37 +0100 Subject: [PATCH] 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. --- pdns/nameserver.cc | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) 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); -- 2.47.2