FreeBSD/sys/fs/nfsclient/nfs_clport.c
/*
 * Lookups source address which should be used to communicate with
 * @nmp and stores it inside @pdst.
 *
 * Returns 0 on success.
 */
Lookups source address which should be used to communicate with
@nmp and stores it inside @pdst.

Returns 0 on success.
Lookups source address which should be used to communicate with @nmp and stores it inside @pdst . Returns 0 on success .
u_int8_t *
nfscl_getmyip(struct nfsmount *nmp, struct in6_addr *paddr, int *isinet6p)
{
#if defined(INET6) || defined(INET)
	int error, fibnum;
	fibnum = curthread->td_proc->p_fibnum;
#endif
#ifdef INET
	if (nmp->nm_nam->sa_family == AF_INET) {
		struct sockaddr_in *sin;
		struct nhop4_extended nh_ext;
		sin = (struct sockaddr_in *)nmp->nm_nam;
		CURVNET_SET(CRED_TO_VNET(nmp->nm_sockreq.nr_cred));
		error = fib4_lookup_nh_ext(fibnum, sin->sin_addr, 0, 0,
		    &nh_ext);
		CURVNET_RESTORE();
		if (error != 0)
			return (NULL);
		if ((ntohl(nh_ext.nh_src.s_addr) >> IN_CLASSA_NSHIFT) ==
		    IN_LOOPBACKNET) {
			return (NULL);
		}
		*isinet6p = 0;
		*((struct in_addr *)paddr) = nh_ext.nh_src;
		return (u_int8_t *)paddr;
	}
#endif
#ifdef INET6
	if (nmp->nm_nam->sa_family == AF_INET6) {
		struct sockaddr_in6 *sin6;
		sin6 = (struct sockaddr_in6 *)nmp->nm_nam;
		CURVNET_SET(CRED_TO_VNET(nmp->nm_sockreq.nr_cred));
		error = in6_selectsrc_addr(fibnum, &sin6->sin6_addr,
		    sin6->sin6_scope_id, NULL, paddr, NULL);
		CURVNET_RESTORE();
		if (error != 0)
			return (NULL);
		if (IN6_IS_ADDR_LOOPBACK(paddr))
			return (NULL);
		*isinet6p = 1;
		return (u_int8_t *)paddr;
	}
#endif
	return (NULL);
}
u_int8_t * nfscl_getmyip ( struct nfsmount * nmp , struct in6_addr * paddr , int * isinet6p ) { #if defined ( INET6 ) || defined ( INET ) int error , fibnum ; fibnum = curthread -> td_proc -> p_fibnum ; #endif #ifdef INET if ( nmp -> nm_nam -> sa_family == AF_INET ) { struct sockaddr_in * sin ; struct nhop4_extended nh_ext ; sin = ( struct sockaddr_in * ) nmp -> nm_nam ; CURVNET_SET ( CRED_TO_VNET ( nmp -> nm_sockreq . nr_cred ) ) ; error = fib4_lookup_nh_ext ( fibnum , sin -> sin_addr , 0 , 0 , & nh_ext ) ; CURVNET_RESTORE ( ) ; if ( error != 0 ) return ( NULL ) ; if ( ( ntohl ( nh_ext . nh_src . s_addr ) >> IN_CLASSA_NSHIFT ) == IN_LOOPBACKNET ) { return ( NULL ) ; } * isinet6p = 0 ; * ( ( struct in_addr * ) paddr ) = nh_ext . nh_src ; return ( u_int8_t * ) paddr ; } #endif #ifdef INET6 if ( nmp -> nm_nam -> sa_family == AF_INET6 ) { struct sockaddr_in6 * sin6 ; sin6 = ( struct sockaddr_in6 * ) nmp -> nm_nam ; CURVNET_SET ( CRED_TO_VNET ( nmp -> nm_sockreq . nr_cred ) ) ; error = in6_selectsrc_addr ( fibnum , & sin6 -> sin6_addr , sin6 -> sin6_scope_id , NULL , paddr , NULL ) ; CURVNET_RESTORE ( ) ; if ( error != 0 ) return ( NULL ) ; if ( IN6_IS_ADDR_LOOPBACK ( paddr ) ) return ( NULL ) ; * isinet6p = 1 ; return ( u_int8_t * ) paddr ; } #endif return ( NULL ) ; }
Lookups source address which should be used to communicate with
 @nmp and stores it inside @pdst.
Lookups source address which should be used to communicate with @nmp and stores it inside @pdst .
/* Ignore loopback addresses */ /* Scope is embedded in */