From: Danny Mayer Date: Thu, 7 Jun 2007 13:25:17 +0000 (-0400) Subject: Bug #854 Broadcast address was not correctly set for interface addresses X-Git-Tag: NTP_4_2_4P2_RC6~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c907669f71ffffdbb34b24c3cf69a71a8d4e581c;p=thirdparty%2Fntp.git Bug #854 Broadcast address was not correctly set for interface addresses bk: 4668073dfuyAKHd-T-mdBQXTvRp-aw --- diff --git a/ports/winnt/libisc/interfaceiter.c b/ports/winnt/libisc/interfaceiter.c index 48a931cfc..212122fb6 100644 --- a/ports/winnt/libisc/interfaceiter.c +++ b/ports/winnt/libisc/interfaceiter.c @@ -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); }