]> granicus.if.org Git - pdns/commitdiff
Fix replying from ANY address for non-standard port
authorbert hubert <bert.hubert@netherlabs.nl>
Mon, 7 Jan 2019 14:28:37 +0000 (15:28 +0100)
committerErik Winkels <erik.winkels@powerdns.com>
Thu, 21 Mar 2019 11:47:42 +0000 (12:47 +0100)
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)

pdns/nameserver.cc

index 0222cd17fdec7e76f6b9d1d4c84608f337763b65..30df153de539355f0167c292760e35a1248d30c5 100644 (file)
@@ -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);