FreeBSD/contrib/ntp/ntpd/ntp_io.c
/*
 * find an interface suitable for the src address
 */
find an interface suitable for the src address
find an interface suitable for the src address
endpt *
select_peerinterface(
	struct peer *	peer,
	sockaddr_u *	srcadr,
	endpt *		dstadr
	)
{
	endpt *ep;
#ifndef SIM
	endpt *wild;
	wild = ANY_INTERFACE_CHOOSE(srcadr);
	if (ISREFCLOCKADR(srcadr)) {
		ep = loopback_interface;
	} else if (peer->cast_flags &
		   (MDF_BCLNT | MDF_ACAST | MDF_MCAST | MDF_BCAST)) {
		ep = findbcastinter(srcadr);
		if (ep != NULL)
			DPRINTF(4, ("Found *-cast interface %s for address %s\n",
				stoa(&ep->sin), stoa(srcadr)));
		else
			DPRINTF(4, ("No *-cast local address found for address %s\n",
				stoa(srcadr)));
	} else {
		ep = dstadr;
		if (NULL == ep)
			ep = wild;
	}
	if (wild == ep)
		ep = findinterface(srcadr);
	if (ep != NULL && INT_WILDCARD & ep->flags)
		if (!accept_wildcard_if_for_winnt)
			ep = NULL;
#else	
	ep = loopback_interface;
#endif
	return ep;
}
endpt * select_peerinterface ( struct peer * peer , sockaddr_u * srcadr , endpt * dstadr ) { endpt * ep ; #ifndef SIM endpt * wild ; wild = ANY_INTERFACE_CHOOSE ( srcadr ) ; if ( ISREFCLOCKADR ( srcadr ) ) { ep = loopback_interface ; } else if ( peer -> cast_flags & ( MDF_BCLNT | MDF_ACAST | MDF_MCAST | MDF_BCAST ) ) { ep = findbcastinter ( srcadr ) ; if ( ep != NULL ) DPRINTF ( 4 , ( " \n " , stoa ( & ep -> sin ) , stoa ( srcadr ) ) ) ; else DPRINTF ( 4 , ( " \n " , stoa ( srcadr ) ) ) ; } else { ep = dstadr ; if ( NULL == ep ) ep = wild ; } if ( wild == ep ) ep = findinterface ( srcadr ) ; if ( ep != NULL && INT_WILDCARD & ep -> flags ) if ( ! accept_wildcard_if_for_winnt ) ep = NULL ; #else ep = loopback_interface ; #endif return ep ; }
find an interface suitable for the src address
find an interface suitable for the src address
/*
	 * Initialize the peer structure and dance the interface jig.
	 * Reference clocks step the loopback waltz, the others
	 * squaredance around the interface list looking for a buddy. If
	 * the dance peters out, there is always the wildcard interface.
	 * This might happen in some systems and would preclude proper
	 * operation with public key cryptography.
	 */ /*
	 * If it is a multicast address, findbcastinter() may not find
	 * it.  For unicast, we get to find the interface when dstadr is
	 * given to us as the wildcard (ANY_INTERFACE_CHOOSE).  Either
	 * way, try a little harder.
	 */ /*
	 * we do not bind to the wildcard interfaces for output
	 * as our (network) source address would be undefined and
	 * crypto will not work without knowing the own transmit address
	 */ /* SIM follows */