FreeBSD/contrib/ntp/ntpd/ntp_io.c
/*
 * create_interface - create a new interface for a given prototype
 *		      binding the socket.
 */
create a new interface for a given prototype
binding the socket.
create a new interface for a given prototype binding the socket .
static struct interface *
create_interface(
	u_short			port,
	struct interface *	protot
	)
{
	sockaddr_u	resmask;
	endpt *		iface;
#if defined(MCAST) && defined(MULTICAST_NONEWSOCKET)
	remaddr_t *	entry;
	remaddr_t *	next_entry;
#endif
	DPRINTF(2, ("create_interface(%s#%d)\n", stoa(&protot->sin),
		    port));
	iface = new_interface(protot);
	iface->fd = open_socket(&iface->sin, 0, 0, iface);
	if (iface->fd != INVALID_SOCKET)
		log_listen_address(iface);
	if ((INT_BROADCAST & iface->flags)
	    && iface->bfd != INVALID_SOCKET)
		msyslog(LOG_INFO, "Listening on broadcast address %s#%d",
			stoa((&iface->bcast)), port);
	if (INVALID_SOCKET == iface->fd
	    && INVALID_SOCKET == iface->bfd) {
		msyslog(LOG_ERR, "unable to create socket on %s (%d) for %s#%d",
			iface->name,
			iface->ifnum,
			stoa((&iface->sin)),
			port);
		delete_interface(iface);
		return NULL;
	}
	SET_HOSTMASK(&resmask, AF(&iface->sin));
	hack_restrict(RESTRICT_FLAGS, &iface->sin, &resmask,
		      RESM_NTPONLY | RESM_INTERFACE, RES_IGNORE, 0);
	if (NULL == loopback_interface && AF_INET == iface->family
	    && (INT_LOOPBACK & iface->flags))
		loopback_interface = iface;
	add_addr_to_list(&iface->sin, iface);
	add_interface(iface);
#if defined(MCAST) && defined(MULTICAST_NONEWSOCKET)
	if (INT_MULTICAST & iface->flags &&
	    !((INT_LOOPBACK | INT_WILDCARD) & iface->flags) &&
	    !iface->ignore_packets) {
		for (entry = remoteaddr_list;
		     entry != NULL;
		     entry = next_entry) {
			next_entry = entry->link;
			if (AF(&iface->sin) != AF(&entry->addr) ||
			    !IS_MCAST(&entry->addr))
				continue;
			if (socket_multicast_enable(iface,
						    &entry->addr))
				msyslog(LOG_INFO,
					"Joined %s socket to multicast group %s",
					stoa(&iface->sin),
					stoa(&entry->addr));
			else
				msyslog(LOG_ERR,
					"Failed to join %s socket to multicast group %s",
					stoa(&iface->sin),
					stoa(&entry->addr));
		}
	}
#endif	
	DPRINT_INTERFACE(2, (iface, "created ", "\n"));
	return iface;
}
static struct interface * create_interface ( u_short port , struct interface * protot ) { sockaddr_u resmask ; endpt * iface ; #if defined ( MCAST ) && defined ( MULTICAST_NONEWSOCKET ) remaddr_t * entry ; remaddr_t * next_entry ; #endif DPRINTF ( 2 , ( " \n " , stoa ( & protot -> sin ) , port ) ) ; iface = new_interface ( protot ) ; iface -> fd = open_socket ( & iface -> sin , 0 , 0 , iface ) ; if ( iface -> fd != INVALID_SOCKET ) log_listen_address ( iface ) ; if ( ( INT_BROADCAST & iface -> flags ) && iface -> bfd != INVALID_SOCKET ) msyslog ( LOG_INFO , " " , stoa ( ( & iface -> bcast ) ) , port ) ; if ( INVALID_SOCKET == iface -> fd && INVALID_SOCKET == iface -> bfd ) { msyslog ( LOG_ERR , " " , iface -> name , iface -> ifnum , stoa ( ( & iface -> sin ) ) , port ) ; delete_interface ( iface ) ; return NULL ; } SET_HOSTMASK ( & resmask , AF ( & iface -> sin ) ) ; hack_restrict ( RESTRICT_FLAGS , & iface -> sin , & resmask , RESM_NTPONLY | RESM_INTERFACE , RES_IGNORE , 0 ) ; if ( NULL == loopback_interface && AF_INET == iface -> family && ( INT_LOOPBACK & iface -> flags ) ) loopback_interface = iface ; add_addr_to_list ( & iface -> sin , iface ) ; add_interface ( iface ) ; #if defined ( MCAST ) && defined ( MULTICAST_NONEWSOCKET ) if ( INT_MULTICAST & iface -> flags && ! ( ( INT_LOOPBACK | INT_WILDCARD ) & iface -> flags ) && ! iface -> ignore_packets ) { for ( entry = remoteaddr_list ; entry != NULL ; entry = next_entry ) { next_entry = entry -> link ; if ( AF ( & iface -> sin ) != AF ( & entry -> addr ) || ! IS_MCAST ( & entry -> addr ) ) continue ; if ( socket_multicast_enable ( iface , & entry -> addr ) ) msyslog ( LOG_INFO , " " , stoa ( & iface -> sin ) , stoa ( & entry -> addr ) ) ; else msyslog ( LOG_ERR , " " , stoa ( & iface -> sin ) , stoa ( & entry -> addr ) ) ; } } #endif DPRINT_INTERFACE ( 2 , ( iface , " " , " \n " ) ) ; return iface ; }
create_interface - create a new interface for a given prototype
                    binding the socket.
create_interface - create a new interface for a given prototype binding the socket .
/* build an interface */ /*
	 * create socket
	 */ /*
	 * Blacklist our own addresses, no use talking to ourself
	 */ /*
	 * set globals with the first found
	 * loopback interface of the appropriate class
	 */ /*
	 * put into our interface list
	 */ /*
	 * Join any previously-configured compatible multicast groups.
	 */ /* MCAST && MCAST_NONEWSOCKET */