]> git.ipfire.org Git - thirdparty/HylaFAX.git/commitdiff
IPv6: Rework initial bind
authorAidan Van Dyk <aidan@ifax.com>
Fri, 7 Aug 2009 17:42:33 +0000 (13:42 -0400)
committerAidan Van Dyk <aidan@ifax.com>
Fri, 7 Aug 2009 19:01:40 +0000 (15:01 -0400)
From the getaddrinfo man page:
                    AI_PASSIVE      If the AI_PASSIVE bit is set it indicates
                                    that the returned socket address structure
                                    is intended for use in a call to bind(2).
                                    In this case, if the hostname argument is
                                    the null pointer, then the IP address por-
                                    tion of the socket address structure will
                                    be set to INADDR_ANY for an IPv4 address
                                    or IN6ADDR_ANY_INIT for an IPv6 address.

                                    If the AI_PASSIVE bit is not set, the
                                    returned socket address structure will be
                                    ready for use in a call to connect(2) for
                                    a connection-oriented protocol or
                                    connect(2), sendto(2), or sendmsg(2) if a
                                    connectionless protocol was chosen.  The
                                    IP address portion of the socket address
                                    structure will be set to the loopback
                                    address if hostname is the null pointer
                                    and AI_PASSIVE is not set.

We were doing this manually by memset-ing the sockaddr if bindaddress was
null, but this is the proper way to do it.

hfaxd/InetFaxServer.c++

index 420a1e96a997d3e32b71551c690d049f13919123..33e6216ed5c43c2f5353da468874a2010c78c504 100644 (file)
@@ -61,9 +61,10 @@ InetSuperServer::startServer(void)
     Socket::Address addr;
     struct addrinfo hints, *ai;
     memset(&hints, 0, sizeof(hints));
-    hints.ai_family = AF_INET6;
+    hints.ai_family = AF_UNSPEC;
+    hints.ai_flags = AI_PASSIVE;
 #ifdef AI_ADDRCONFIG
-    hints.ai_flags = AI_ADDRCONFIG;
+    hints.ai_flags |= AI_ADDRCONFIG;
 #endif
     hints.ai_socktype = SOCK_STREAM;
 
@@ -74,12 +75,6 @@ InetSuperServer::startServer(void)
     if (getaddrinfo(bindaddress, port, &hints, &ai) == 0)  {
        memcpy(&addr, ai->ai_addr, ai->ai_addrlen);
        freeaddrinfo(ai);
-       /*
-        * an empty bindaddr returns localhost, but we want to
-        * listen on everything
-        */
-       if (! bindaddress)
-           memset(Socket::addr(addr), 0, Socket::addrlen(addr));
     } else {
        logDebug("Couldn't get address information for port \"%s\"",
                (const char*) port);