]> git.ipfire.org Git - thirdparty/ntp.git/commitdiff
Fix Linux' broadcastclient mode.
authorMatthias Andree <matthias.andree@gmx.de>
Sun, 5 Jan 2003 05:10:42 +0000 (06:10 +0100)
committerMatthias Andree <matthias.andree@gmx.de>
Sun, 5 Jan 2003 05:10:42 +0000 (06:10 +0100)
Patch by Allen Mcintosh.

bk: 3e17be52-DlBU8g1n2E7AdZ-kLn7cg

configure.in
ntpd/ntp_io.c

index 5e2eb661cffaad7acf47c0e9bf7daa964bd9a4ec..228971b157027cecfddf970d3b2700e971fb5892 100644 (file)
@@ -947,9 +947,6 @@ case "$host" in
  *-*-domainos)
     ans=no
     ;;
- *-*-linux*)
-    ans=no
-    ;;
 esac
 ac_cv_var_open_bcast_socket=$ans])
 case "$ac_cv_var_open_bcast_socket" in
index ef0c14698f5bff9936e1893a6b6ae415ca31d343..6797950765b04038ec6451a4ad65a6e0817fd7aa 100644 (file)
@@ -142,6 +142,7 @@ static      int open_socket         P((struct sockaddr_in *, int, int));
 static void    close_socket    P((int));
 static void    close_file      P((int));
 static char *  fdbits          P((int, fd_set *));
+static void    set_reuseaddr   P((int));
 
 /*
  * init_io - initialize I/O data structures and call socket creation routine
@@ -615,21 +616,7 @@ create_sockets(
         * Now that we have opened all the sockets, turn off the reuse flag for
         * security.
         */
-       for (i = 0; i < ninterfaces; i++) {
-               int off = 0;
-
-               /*
-                * if inter_list[ n ].fd  is -1, we might have a adapter
-                * configured but not present
-                */
-               if ( inter_list[ i ].fd != -1 ) {
-                       if (setsockopt(inter_list[i].fd, SOL_SOCKET,
-                                      SO_REUSEADDR, (char *)&off,
-                                      sizeof(off))) {
-                               msyslog(LOG_ERR, "create_sockets: setsockopt(SO_REUSEADDR,off) failed: %m");
-                       }
-               }
-       }
+       set_reuseaddr(0);
 
 #if defined(MCAST)
        /*
@@ -684,6 +671,10 @@ io_setbclient(void)
 {
        int i;
 
+#ifdef OPEN_BCAST_SOCKET
+       set_reuseaddr(1);
+#endif
+
        for (i = 1; i < ninterfaces; i++) {
                if (!(inter_list[i].flags & INT_BROADCAST))
                        continue;
@@ -700,6 +691,34 @@ io_setbclient(void)
                inter_list[i].flags |= INT_BCASTOPEN;
 #endif
        }
+
+#ifdef OPEN_BCAST_SOCKET
+       set_reuseaddr(0);
+#endif
+}
+
+/*
+ * set_reuseaddr() - set/clear REUSEADDR on all sockets
+ *             NB possible hole - should we be doing this on broadcast
+ *                     fd's also?
+ */
+static void
+set_reuseaddr(int flag) {
+       int i;
+
+       for (i = 0; i < ninterfaces; i++) {
+               /*
+                * if inter_list[ n ].fd  is -1, we might have a adapter
+                * configured but not present
+                */
+               if ( inter_list[ i ].fd != -1 ) {
+                       if (setsockopt(inter_list[i].fd, SOL_SOCKET,
+                                      SO_REUSEADDR, (char *)&flag,
+                                      sizeof(flag))) {
+                               msyslog(LOG_ERR, "create_sockets: setsockopt(SO_REUSEADDR,%s) failed: %m", flag ? "on" : "off");
+                       }
+               }
+       }
 }