From: Dave Hart Date: Sat, 23 May 2009 02:02:18 +0000 (+0000) Subject: Bug [1041] manycastclient fails with 4.2.5p120. X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=98308e93bcf623a35f0250b3ee006269ea66a9b1;p=thirdparty%2Fntp.git Bug [1041] manycastclient fails with 4.2.5p120. (fixed by Dave Mills' prior delta to ntp_peer.c xmt -> aorg) Bug [1196] VC6 winsock2.h does not define SO_EXLUSIVEADDRUSE. bk: 4a17592aQ9uzDy_lGlZt2_YqU1O2Rw --- diff --git a/ChangeLog b/ChangeLog index 40727a4c2f..271970d428 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,6 @@ -* Bug [1193] Compile error: conflicting types for emalloc +* Bug [1041] manycastclient fails with 4.2.5p120. +* Bug [1193] Compile error: conflicting types for emalloc. +* Bug [1196] VC6 winsock2.h does not define SO_EXLUSIVEADDRUSE. * xmt -> aorg timestamp cleanup from Dave Mills, reported by Dave Hart. * Leap/expire cleanup from Dave Mills. (4.2.5p178) 2009/05/21 Released by Harlan Stenn diff --git a/ntpd/ntp_io.c b/ntpd/ntp_io.c index 981f846069..08c912b164 100644 --- a/ntpd/ntp_io.c +++ b/ntpd/ntp_io.c @@ -3435,7 +3435,9 @@ findinterface( } /* - * findlocalinterface - find local interface index corresponding to address + * findlocalinterface - find local interface corresponding to addr, + * which does not have any of flags set. If bast is nonzero, addr is + * a broadcast address. * * This code attempts to find the local sending address for an outgoing * address by connecting a new socket to destinationaddress:NTP_PORT @@ -3451,7 +3453,7 @@ static struct interface * findlocalinterface( struct sockaddr_storage *addr, int flags, - int bflag + int bcast ) { SOCKET s; @@ -3488,9 +3490,9 @@ findlocalinterface( * If we are looking for broadcast interface we need to set this * socket to allow broadcast */ - if (bflag & INT_BROADCAST) + if (bcast) setsockopt(s, SOL_SOCKET, SO_BROADCAST, - (char *)&on, sizeof(on)); + (char *)&on, sizeof(on)); rtn = connect(s, (struct sockaddr *)&saddr, SOCKLEN(&saddr)); if (rtn == SOCKET_ERROR) @@ -3507,6 +3509,15 @@ findlocalinterface( DPRINTF(4, ("findlocalinterface: kernel maps %s to %s\n", stoa(addr), stoa(&saddr))); iface = getinterface(&saddr, flags); + + /* + * if we didn't find an exact match on saddr check for an + * interface on the same subnet as saddr. This handles the + * case of the address suggested by the kernel being + * excluded by the user's -I and -L options to ntpd, when + * another address is enabled on the same subnet. + * See http://bugs.ntp.org/1184 for more detail. + */ if (NULL == iface) iface = getsamenetinterface(&saddr, flags); @@ -3660,11 +3671,11 @@ findbcastinter( DPRINTF(4, ("Finding broadcast/multicast interface for addr %s in list of addresses\n", stoa(addr))); - interface = findlocalinterface(addr, INT_LOOPBACK|INT_WILDCARD, INT_BROADCAST); + interface = findlocalinterface(addr, INT_LOOPBACK | INT_WILDCARD, 1); if (interface != NULL) { - DPRINTF(4, ("Found bcast-/mcast- interface index #%d %s\n", interface->ifnum, interface->name)); + DPRINTF(4, ("Easily found bcast-/mcast- interface index #%d %s\n", interface->ifnum, interface->name)); return interface; } diff --git a/ports/winnt/include/config.h b/ports/winnt/include/config.h index b1dc8cb445..ce72b5a3ef 100644 --- a/ports/winnt/include/config.h +++ b/ports/winnt/include/config.h @@ -143,6 +143,13 @@ typedef int socklen_t; */ #define GETSOCKNAME_SOCKLEN_TYPE socklen_t +/* + * Older SDKs do not define SO_EXCLUSIVEADDRUSE in winsock2.h + */ +#ifndef SO_EXCLUSIVEADDRUSE +#define SO_EXCLUSIVEADDRUSE ((int)(~SO_REUSEADDR)) +#endif + #if defined _MSC_VER && _MSC_VER < 1400 /* * Use 32-bit time definitions for versions prior to VS 2005