FreeBSD/sys/nlm/nlm_prot_impl.c
/*
 * Search for an existing NLM host that matches the given remote
 * address. If none is found, create a new host with the requested
 * address and remember 'vers' as the NLM protocol version to use for
 * that host.
 */
Search for an existing NLM host that matches the given remote
address. If none is found, create a new host with the requested
address and remember 'vers' as the NLM protocol version to use for
that host.
Search for an existing NLM host that matches the given remote address . If none is found create a new host with the requested address and remember ' vers ' as the NLM protocol version to use for that host .
struct nlm_host *
nlm_find_host_by_addr(const struct sockaddr *addr, int vers)
{
	char tmp[sizeof "ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255"];
	struct nlm_host *host;
	switch (addr->sa_family) {
	case AF_INET:
		inet_ntop(AF_INET,
		    &((const struct sockaddr_in *) addr)->sin_addr,
		    tmp, sizeof tmp);
		break;
#ifdef INET6
	case AF_INET6:
		inet_ntop(AF_INET6,
		    &((const struct sockaddr_in6 *) addr)->sin6_addr,
		    tmp, sizeof tmp);
		break;
#endif
	default:
		strlcpy(tmp, "<unknown>", sizeof(tmp));
	}
	mtx_lock(&nlm_global_lock);
	TAILQ_FOREACH(host, &nlm_hosts, nh_link) {
		if (nlm_compare_addr(addr,
			(const struct sockaddr *) &host->nh_addr))
			break;
	}
	if (!host) {
		host = nlm_create_host(tmp);
		if (!host) {
			mtx_unlock(&nlm_global_lock);
			return (NULL);
		}
		memcpy(&host->nh_addr, addr, addr->sa_len);
		host->nh_vers = vers;
	}
	refcount_acquire(&host->nh_refs);
	host->nh_idle_timeout = time_uptime + NLM_IDLE_TIMEOUT;
	nlm_check_idle();
	mtx_unlock(&nlm_global_lock);
	return (host);
}
struct nlm_host * nlm_find_host_by_addr ( const struct sockaddr * addr , int vers ) { char tmp [ sizeof " " ] ; struct nlm_host * host ; switch ( addr -> sa_family ) { case AF_INET : inet_ntop ( AF_INET , & ( ( const struct sockaddr_in * ) addr ) -> sin_addr , tmp , sizeof tmp ) ; break ; #ifdef INET6 case AF_INET6 : inet_ntop ( AF_INET6 , & ( ( const struct sockaddr_in6 * ) addr ) -> sin6_addr , tmp , sizeof tmp ) ; break ; #endif default : strlcpy ( tmp , " " , sizeof ( tmp ) ) ; } mtx_lock ( & nlm_global_lock ) ; TAILQ_FOREACH ( host , & nlm_hosts , nh_link ) { if ( nlm_compare_addr ( addr , ( const struct sockaddr * ) & host -> nh_addr ) ) break ; } if ( ! host ) { host = nlm_create_host ( tmp ) ; if ( ! host ) { mtx_unlock ( & nlm_global_lock ) ; return ( NULL ) ; } memcpy ( & host -> nh_addr , addr , addr -> sa_len ) ; host -> nh_vers = vers ; } refcount_acquire ( & host -> nh_refs ) ; host -> nh_idle_timeout = time_uptime + NLM_IDLE_TIMEOUT ; nlm_check_idle ( ) ; mtx_unlock ( & nlm_global_lock ) ; return ( host ) ; }
Search for an existing NLM host that matches the given remote
 address.
Search for an existing NLM host that matches the given remote address .
/*
	 * Fake up a name using inet_ntop. This buffer is
	 * large enough for an IPv6 address.
	 */ /*
	 * The remote host is determined by caller_name.
	 */