]> git.ipfire.org Git - thirdparty/ntp.git/commitdiff
address_okay note. Fixes to take account of wildcard addresses. Fix SOCKET usage.
authorDanny Mayer <mayer@ntp.org>
Mon, 10 Mar 2003 04:12:12 +0000 (23:12 -0500)
committerDanny Mayer <mayer@ntp.org>
Mon, 10 Mar 2003 04:12:12 +0000 (23:12 -0500)
Cleanup conditional ioctl for nonblocking.

bk: 3e6c109cLVGbif1aBFrlEWNeVFOHsw

ntpd/ntp_io.c

index 67f4d2738709a5a9e9d72feb3e835ee9ba3d91d2..13c629e05083e5dc2e6bf99030fbf5184ff0fbb7 100644 (file)
@@ -251,6 +251,11 @@ create_wildcards(u_short port) {
 
 isc_boolean_t
 address_okay(isc_interface_t *isc_if) {
+
+       /* XXXPDM This should be fixed later, but since we may not have set
+        * the UP flag, we at least get to use the interface. The listen_to
+        * _virtual_ips check should be last.
+        */
        if (listen_to_virtual_ips == 1)
                return (ISC_TRUE);
        if ((isc_if->flags & INTERFACE_F_UP) == 0)      /* Ignore interfaces not up */
@@ -521,7 +526,7 @@ set_reuseaddr(int flag) {
                        if (setsockopt(inter_list[i].fd, SOL_SOCKET,
                                        SO_REUSEADDR, (char *)&flag,
                                        sizeof(flag))) {
-                               netsyslog(LOG_ERR, "create_sockets: setsockopt(SO_REUSEADDR, %s) failed: %m", flag ? "on" : "off");
+                               netsyslog(LOG_ERR, "set_reuseaddr: setsockopt(SO_REUSEADDR, %s) failed: %m", flag ? "on" : "off");
                        }
                }
        }
@@ -541,7 +546,7 @@ io_multicast_add(
        int i = ninterfaces;    /* Use the next interface */
        u_int32 haddr = ntohl(((struct sockaddr_in*)&addr)->sin_addr.s_addr);
        struct in_addr iaddr;
-       int s;
+       SOCKET s;
        struct sockaddr_in *sinp;
 
 #ifdef HAVE_IPV6
@@ -587,7 +592,7 @@ io_multicast_add(
                set_reuseaddr(1);
                s = open_socket((struct sockaddr_storage*)sinp, 0, 1);
                set_reuseaddr(0);
-               if (s < 0) {
+               if (s == INVALID_SOCKET) {
                        memset((char *)&inter_list[i], 0, sizeof(struct interface));
                        if (wildipv4 >= 0) {
                                i = wildipv4;
@@ -664,7 +669,7 @@ io_multicast_add(
                set_reuseaddr(1);
                s = open_socket((struct sockaddr_storage*)sin6p, 0, 1);
                set_reuseaddr(0);
-               if(s < 0){
+               if(s == INVALID_SOCKET){
                        memset((char *)&inter_list[i], 0, sizeof(struct interface));
                        if (wildipv6 >= 0) {
                                i = wildipv6;
@@ -774,7 +779,7 @@ io_multicast_del(
                */
                mreq.imr_multiaddr = ((struct sockaddr_in*)&addr)->sin_addr;
                mreq.imr_interface.s_addr = htonl(INADDR_ANY);
-               for (i = nwilds; i < ninterfaces; i++)
+               for (i = 0; i < ninterfaces; i++)
                {
                        /* Be sure it's the correct family */
                        if (inter_list[i].sin.ss_family != AF_INET)
@@ -785,7 +790,7 @@ io_multicast_del(
                                continue;
                        if (!SOCKCMP(&addr, &inter_list[i].sin))
                                continue;
-                       if (i != 0)
+                       if (i != wildipv4)
                        {
                                /* we have an explicit fd, so we can close it */
                                close_socket(inter_list[i].fd);
@@ -824,7 +829,7 @@ io_multicast_del(
                */
                mreq6.ipv6mr_multiaddr = ((struct sockaddr_in6*)&addr)->sin6_addr;
                mreq6.ipv6mr_interface = 0;
-               for (i = nwilds; i < ninterfaces; i++)
+               for (i = 0; i < ninterfaces; i++)
                {
                        /* Be sure it's the correct family */
                        if (inter_list[i].sin.ss_family != AF_INET6)
@@ -835,7 +840,7 @@ io_multicast_del(
                                continue;
                        if (!SOCKCMP(&addr, &inter_list[i].sin))
                                continue;
-                       if (i != 0)
+                       if (i != wildipv6)
                        {
                                /* we have an explicit fd, so we can close it */
                                close_socket(inter_list[i].fd);
@@ -1058,15 +1063,13 @@ open_socket(
                /*NOTREACHED*/
        }
 #elif defined(FIONBIO)
-       if (
 # if defined(VMS)
-               (ioctl(fd,FIONBIO,&1) < 0)
+               if (ioctl(fd,FIONBIO,&on) < 0)
 # elif defined(SYS_WINNT)
-               (ioctlsocket(fd,FIONBIO,(u_long *) &on) == SOCKET_ERROR)
+               if (ioctlsocket(fd,FIONBIO,(u_long *) &on) == SOCKET_ERROR)
 # else
-               (ioctl(fd,FIONBIO,&on) < 0)
+               if (ioctl(fd,FIONBIO,&on) < 0)
 # endif
-          )
        {
                netsyslog(LOG_ERR, "ioctl(FIONBIO) fails on address %s: %m",
                        stoa(addr));