FreeBSD/contrib/ntp/ntpd/ntp_io.c
/*
 * Multicast servers need to set the appropriate Multicast interface
 * socket option in order for it to know which interface to use for
 * send the multicast packet.
 */
Multicast servers need to set the appropriate Multicast interface
socket option in order for it to know which interface to use for
send the multicast packet.
Multicast servers need to set the appropriate Multicast interface socket option in order for it to know which interface to use for send the multicast packet .
void
enable_multicast_if(
	struct interface *	iface,
	sockaddr_u *		maddr
	)
{
#ifdef MCAST
#ifdef IP_MULTICAST_LOOP
	TYPEOF_IP_MULTICAST_LOOP off = 0;
#endif
#if defined(INCLUDE_IPV6_MULTICAST_SUPPORT) && defined(IPV6_MULTICAST_LOOP)
	u_int off6 = 0;
#endif
	REQUIRE(AF(maddr) == AF(&iface->sin));
	switch (AF(&iface->sin)) {
	case AF_INET:
#ifdef IP_MULTICAST_LOOP
		if (setsockopt(iface->fd, IPPROTO_IP,
			       IP_MULTICAST_LOOP,
			       SETSOCKOPT_ARG_CAST &off,
			       sizeof(off))) {
			msyslog(LOG_ERR,
				"setsockopt IP_MULTICAST_LOOP failed: %m on socket %d, addr %s for multicast address %s",
				iface->fd, stoa(&iface->sin),
				stoa(maddr));
		}
#endif
		break;
	case AF_INET6:
#ifdef INCLUDE_IPV6_MULTICAST_SUPPORT
#ifdef IPV6_MULTICAST_LOOP
		if (setsockopt(iface->fd, IPPROTO_IPV6,
			       IPV6_MULTICAST_LOOP,
			       (char *) &off6, sizeof(off6))) {
			msyslog(LOG_ERR,
				"setsockopt IPV6_MULTICAST_LOOP failed: %m on socket %d, addr %s for multicast address %s",
				iface->fd, stoa(&iface->sin),
				stoa(maddr));
		}
#endif
		break;
#else
		return;
#endif	
	}
	return;
#endif
}
void enable_multicast_if ( struct interface * iface , sockaddr_u * maddr ) { #ifdef MCAST #ifdef IP_MULTICAST_LOOP TYPEOF_IP_MULTICAST_LOOP off = 0 ; #endif #if defined ( INCLUDE_IPV6_MULTICAST_SUPPORT ) && defined ( IPV6_MULTICAST_LOOP ) u_int off6 = 0 ; #endif REQUIRE ( AF ( maddr ) == AF ( & iface -> sin ) ) ; switch ( AF ( & iface -> sin ) ) { case AF_INET : #ifdef IP_MULTICAST_LOOP if ( setsockopt ( iface -> fd , IPPROTO_IP , IP_MULTICAST_LOOP , SETSOCKOPT_ARG_CAST & off , sizeof ( off ) ) ) { msyslog ( LOG_ERR , " " , iface -> fd , stoa ( & iface -> sin ) , stoa ( maddr ) ) ; } #endif break ; case AF_INET6 : #ifdef INCLUDE_IPV6_MULTICAST_SUPPORT #ifdef IPV6_MULTICAST_LOOP if ( setsockopt ( iface -> fd , IPPROTO_IPV6 , IPV6_MULTICAST_LOOP , ( char * ) & off6 , sizeof ( off6 ) ) ) { msyslog ( LOG_ERR , " " , iface -> fd , stoa ( & iface -> sin ) , stoa ( maddr ) ) ; } #endif break ; #else return ; #endif } return ; #endif }
Multicast servers need to set the appropriate Multicast interface
 socket option in order for it to know which interface to use for
 send the multicast packet.
Multicast servers need to set the appropriate Multicast interface socket option in order for it to know which interface to use for send the multicast packet .
/*
		 * Don't send back to itself, but allow failure to set
		 */ /*
		 * Don't send back to itself, but allow failure to set
		 */ /* INCLUDE_IPV6_MULTICAST_SUPPORT */