]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Fix replying from ANY address for non-standard port 7341/head
authorbert hubert <bert.hubert@netherlabs.nl>
Mon, 7 Jan 2019 14:28:37 +0000 (15:28 +0100)
committerbert hubert <bert.hubert@netherlabs.nl>
Mon, 7 Jan 2019 14:28:37 +0000 (15:28 +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.

pdns/nameserver.cc

index 64757705ec3d3308f50d2ee2fe4d18c3cbaaa038..60e2e72ed536aeab0327778bd89c42619932fccc 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);