FreeBSD/contrib/ntp/ntpd/ntp_io.c
/*
 * findclosestinterface
 *
 * If there are -I/--interface or -L/novirtualips command-line options,
 * or "nic" or "interface" rules in ntp.conf, findlocalinterface() may
 * find the kernel's preferred local address for a given peer address is
 * administratively unavailable to ntpd, and punt to this routine's more
 * expensive search.
 *
 * Find the numerically closest local address to the one connect()
 * suggested.  This matches an address on the same subnet first, as
 * needed by Bug 1184, and provides a consistent choice if there are
 * multiple feasible local addresses, regardless of the order ntpd
 * enumerated them.
 */


Find the numerically closest local address to the one connect()
suggested.  This matches an address on the same subnet first, as
needed by Bug 1184, and provides a consistent choice if there are
multiple feasible local addresses, regardless of the order ntpd
enumerated them.
Find the numerically closest local address to the one connect () suggested . This matches an address on the same subnet first as needed by Bug 1184 and provides a consistent choice if there are multiple feasible local addresses regardless of the order ntpd enumerated them .
endpt *
findclosestinterface(
	sockaddr_u *	addr,
	int		flags
	)
{
	endpt *		ep;
	endpt *		winner;
	sockaddr_u	addr_dist;
	sockaddr_u	min_dist;
	ZERO_SOCK(&min_dist);
	winner = NULL;
	for (ep = ep_list; ep != NULL; ep = ep->elink) {
		if (ep->ignore_packets ||
		    AF(addr) != ep->family ||
		    flags & ep->flags)
			continue;
		calc_addr_distance(&addr_dist, addr, &ep->sin);
		if (NULL == winner ||
		    -1 == cmp_addr_distance(&addr_dist, &min_dist)) {
			min_dist = addr_dist;
			winner = ep;
		}
	}
	if (NULL == winner)
		DPRINTF(4, ("findclosestinterface(%s) failed\n",
			    stoa(addr)));
	else
		DPRINTF(4, ("findclosestinterface(%s) -> %s\n",
			    stoa(addr), stoa(&winner->sin)));
	return winner;
}
endpt * findclosestinterface ( sockaddr_u * addr , int flags ) { endpt * ep ; endpt * winner ; sockaddr_u addr_dist ; sockaddr_u min_dist ; ZERO_SOCK ( & min_dist ) ; winner = NULL ; for ( ep = ep_list ; ep != NULL ; ep = ep -> elink ) { if ( ep -> ignore_packets || AF ( addr ) != ep -> family || flags & ep -> flags ) continue ; calc_addr_distance ( & addr_dist , addr , & ep -> sin ) ; if ( NULL == winner || -1 == cmp_addr_distance ( & addr_dist , & min_dist ) ) { min_dist = addr_dist ; winner = ep ; } } if ( NULL == winner ) DPRINTF ( 4 , ( " \n " , stoa ( addr ) ) ) ; else DPRINTF ( 4 , ( " \n " , stoa ( addr ) , stoa ( & winner -> sin ) ) ) ; return winner ; }
findclosestinterface
 If there are -I/--interface or -L/novirtualips command-line options,
 or "nic" or "interface" rules in ntp.conf, findlocalinterface() may
 find the kernel's preferred local address for a given peer address is
 administratively unavailable to ntpd, and punt to this routine's more
 expensive search.
findclosestinterface If there are - I / -- interface or - L / novirtualips command - line options or " nic " or " interface " rules in ntp . conf findlocalinterface () may find the kernel ' s preferred local address for a given peer address is administratively unavailable to ntpd and punt to this routine ' s more expensive search .