]> git.ipfire.org Git - thirdparty/ntp.git/commitdiff
Bug #854 Broadcast address was not correctly set for interface addresses
authorDanny Mayer <mayer@ntp.org>
Thu, 7 Jun 2007 13:25:17 +0000 (09:25 -0400)
committerDanny Mayer <mayer@ntp.org>
Thu, 7 Jun 2007 13:25:17 +0000 (09:25 -0400)
bk: 4668073dfuyAKHd-T-mdBQXTvRp-aw

ports/winnt/libisc/interfaceiter.c

index 48a931cfcc952ae4997c212e71a781da6530a058..212122fb65c7c546c838fa713b08139b37eacfb5 100644 (file)
@@ -99,6 +99,26 @@ get_addr(unsigned int family, isc_netaddr_t *dst, struct sockaddr *src) {
        }
 }
 
+/*
+ * The WSAIoctl code is not fetching the broadcast address for each interface address
+ * so we need to reconstruct it from the address and its network mask
+ */
+static void
+get_broadcastaddr(isc_netaddr_t *bcastaddr, isc_netaddr_t *addr, isc_netaddr_t *netmask) {
+
+       unsigned char *p, *a, *n;
+       int i;
+
+       p = (unsigned char *) &bcastaddr->type.in;
+       a = (unsigned char *) &addr->type.in;
+       n = (unsigned char *) &netmask->type.in;
+
+       for (i=0; i < 4; i++) {
+               p[i] = (unsigned char) (a[i] | ~n[i]);
+       }
+
+}
+
 isc_result_t
 isc_interfaceiter_create(isc_mem_t *mctx, isc_interfaceiter_t **iterp) {
        char strbuf[ISC_STRERRORSIZE]; 
@@ -270,6 +290,18 @@ internal_current(isc_interfaceiter_t *iter, int family) {
                iter->current.flags |= INTERFACE_F_MULTICAST;
        }
 
+       /*
+        * Get the network mask.
+        */
+       switch (family) {
+       case AF_INET:
+               get_addr(family, &iter->current.netmask,
+                        (struct sockaddr *)&(iter->IFData.iiNetmask));
+               break;
+       case AF_INET6:
+               break;
+       }
+
        /*
         * If the interface is point-to-point, get the destination address.
         */
@@ -281,26 +313,16 @@ internal_current(isc_interfaceiter_t *iter, int family) {
         * If the interface is broadcast, get the broadcast address.
         */
        if ((iter->current.flags & INTERFACE_F_BROADCAST) != 0) {
-               get_addr(family, &iter->current.broadcast,
+               get_addr(family, &iter->current.broadcast, 
                (struct sockaddr *)&(iter->IFData.iiBroadcastAddress));
+               get_broadcastaddr(&iter->current.broadcast, &iter->current.address,
+                                  &iter->current.netmask);
        }
 
        if (ifNamed == FALSE)
                sprintf(iter->current.name,
                        "IP Interface %d", iter->numIF);
 
-       /*
-        * Get the network mask.
-        */
-       switch (family) {
-       case AF_INET:
-               get_addr(family, &iter->current.netmask,
-                        (struct sockaddr *)&(iter->IFData.iiNetmask));
-               break;
-       case AF_INET6:
-               break;
-       }
-
        return (ISC_R_SUCCESS);
 }