FreeBSD/contrib/ntp/ntpd/ntp_io.c
/*
 * findbcastinter - find broadcast interface corresponding to address
 */
find broadcast interface corresponding to address
find broadcast interface corresponding to address
endpt *
findbcastinter(
	sockaddr_u *addr
	)
{
	endpt *	iface;
	iface = NULL;
#if !defined(MPE) && (defined(SIOCGIFCONF) || defined(SYS_WINNT))
	DPRINTF(4, ("Finding broadcast/multicast interface for addr %s in list of addresses\n",
		    stoa(addr)));
	iface = findlocalinterface(addr, INT_LOOPBACK | INT_WILDCARD,
				   1);
	if (iface != NULL) {
		DPRINTF(4, ("Easily found bcast-/mcast- interface index #%d %s\n",
			    iface->ifnum, iface->name));
		return iface;
	}
	for (iface = ep_list; iface != NULL; iface = iface->elink) {
		if (iface->flags & INT_WILDCARD)
			continue;
		if (iface->ignore_packets)
			continue;
		if(AF(&iface->sin) != AF(addr))
			continue;
		if (iface->flags & INT_LOOPBACK)
			continue;
		if (addr_ismulticast(addr)
		    && (iface->flags & INT_MULTICAST)) {
#ifdef INCLUDE_IPV6_SUPPORT
			if (IS_IPV6(addr)
			    && IN6_IS_ADDR_MC_LINKLOCAL(PSOCK_ADDR6(addr))
			    && !IN6_IS_ADDR_LINKLOCAL(PSOCK_ADDR6(&iface->sin)))
				continue;
#endif
			break;
		}
		if (IS_IPV4(addr)) {
			if (SOCK_EQ(&iface->bcast, addr))
				break;
			if ((NSRCADR(&iface->sin) & NSRCADR(&iface->mask))
			    == (NSRCADR(addr)	  & NSRCADR(&iface->mask)))
				break;
		}
#ifdef INCLUDE_IPV6_SUPPORT
		else if (IS_IPV6(addr)) {
			if (SOCK_EQ(&iface->bcast, addr))
				break;
			if (SOCK_EQ(netof(&iface->sin), netof(addr)))
				break;
		}
#endif
	}
#endif 
	if (NULL == iface) {
		DPRINTF(4, ("No bcast interface found for %s\n",
			    stoa(addr)));
		iface = ANY_INTERFACE_CHOOSE(addr);
	} else {
		DPRINTF(4, ("Found bcast-/mcast- interface index #%d %s\n",
			    iface->ifnum, iface->name));
	}
	return iface;
}
endpt * findbcastinter ( sockaddr_u * addr ) { endpt * iface ; iface = NULL ; #if ! defined ( MPE ) && ( defined ( SIOCGIFCONF ) || defined ( SYS_WINNT ) ) DPRINTF ( 4 , ( " \n " , stoa ( addr ) ) ) ; iface = findlocalinterface ( addr , INT_LOOPBACK | INT_WILDCARD , 1 ) ; if ( iface != NULL ) { DPRINTF ( 4 , ( " \n " , iface -> ifnum , iface -> name ) ) ; return iface ; } for ( iface = ep_list ; iface != NULL ; iface = iface -> elink ) { if ( iface -> flags & INT_WILDCARD ) continue ; if ( iface -> ignore_packets ) continue ; if ( AF ( & iface -> sin ) != AF ( addr ) ) continue ; if ( iface -> flags & INT_LOOPBACK ) continue ; if ( addr_ismulticast ( addr ) && ( iface -> flags & INT_MULTICAST ) ) { #ifdef INCLUDE_IPV6_SUPPORT if ( IS_IPV6 ( addr ) && IN6_IS_ADDR_MC_LINKLOCAL ( PSOCK_ADDR6 ( addr ) ) && ! IN6_IS_ADDR_LINKLOCAL ( PSOCK_ADDR6 ( & iface -> sin ) ) ) continue ; #endif break ; } if ( IS_IPV4 ( addr ) ) { if ( SOCK_EQ ( & iface -> bcast , addr ) ) break ; if ( ( NSRCADR ( & iface -> sin ) & NSRCADR ( & iface -> mask ) ) == ( NSRCADR ( addr ) & NSRCADR ( & iface -> mask ) ) ) break ; } #ifdef INCLUDE_IPV6_SUPPORT else if ( IS_IPV6 ( addr ) ) { if ( SOCK_EQ ( & iface -> bcast , addr ) ) break ; if ( SOCK_EQ ( netof ( & iface -> sin ) , netof ( addr ) ) ) break ; } #endif } #endif if ( NULL == iface ) { DPRINTF ( 4 , ( " \n " , stoa ( addr ) ) ) ; iface = ANY_INTERFACE_CHOOSE ( addr ) ; } else { DPRINTF ( 4 , ( " \n " , iface -> ifnum , iface -> name ) ) ; } return iface ; }
findbcastinter - find broadcast interface corresponding to address
findbcastinter - find broadcast interface corresponding to address
/*
	 * plan B - try to find something reasonable in our lists in
	 * case kernel lookup doesn't help
	 */ /* Don't bother with ignored interfaces */ /*
		 * First look if this is the correct family
		 */ /* Skip the loopback addresses */ /*
		 * If we are looking to match a multicast address and
		 * this interface is one...
		 */ /*
			 * ...it is the winner unless we're looking for
			 * an interface to use for link-local multicast
			 * and its address is not link-local.
			 */ /*
		 * We match only those interfaces marked as
		 * broadcastable and either the explicit broadcast
		 * address or the network portion of the IP address.
		 * Sloppy.
		 */ /* SIOCGIFCONF */