FreeBSD/sys/netinet6/scope6.c
/*
 * Determine the appropriate scope zone ID for in6 and ifp.  If ret_id is
 * non NULL, it is set to the zone ID.  If the zone ID needs to be embedded
 * in the in6_addr structure, in6 will be modified.
 *
 * ret_id - unnecessary?
 */
Determine the appropriate scope zone ID for in6 and ifp.  If ret_id is
non NULL, it is set to the zone ID.  If the zone ID needs to be embedded
in the in6_addr structure, in6 will be modified.


Determine the appropriate scope zone ID for in6 and ifp . If ret_id is non NULL it is set to the zone ID . If the zone ID needs to be embedded in the in6_addr structure in6 will be modified .
int
in6_setscope(struct in6_addr *in6, struct ifnet *ifp, u_int32_t *ret_id)
{
	int scope;
	u_int32_t zoneid = 0;
	struct scope6_id *sid;
	if (IN6_IS_ADDR_LOOPBACK(in6)) {
		if (!(ifp->if_flags & IFF_LOOPBACK))
			return (EINVAL);
	} else {
		scope = in6_addrscope(in6);
		if (scope == IPV6_ADDR_SCOPE_INTFACELOCAL ||
		    scope == IPV6_ADDR_SCOPE_LINKLOCAL) {
			zoneid = ifp->if_index;
			in6->s6_addr16[1] = htons(zoneid & 0xffff); 
		} else if (scope != IPV6_ADDR_SCOPE_GLOBAL) {
			IF_AFDATA_RLOCK(ifp);
			sid = SID(ifp);
			zoneid = sid->s6id_list[scope];
			IF_AFDATA_RUNLOCK(ifp);
		}
	}
	if (ret_id != NULL)
		*ret_id = zoneid;
	return (0);
}
int in6_setscope ( struct in6_addr * in6 , struct ifnet * ifp , u_int32_t * ret_id ) { int scope ; u_int32_t zoneid = 0 ; struct scope6_id * sid ; if ( IN6_IS_ADDR_LOOPBACK ( in6 ) ) { if ( ! ( ifp -> if_flags & IFF_LOOPBACK ) ) return ( EINVAL ) ; } else { scope = in6_addrscope ( in6 ) ; if ( scope == IPV6_ADDR_SCOPE_INTFACELOCAL || scope == IPV6_ADDR_SCOPE_LINKLOCAL ) { zoneid = ifp -> if_index ; in6 -> s6_addr16 [ 1 ] = htons ( zoneid & 0xffff ) ; } else if ( scope != IPV6_ADDR_SCOPE_GLOBAL ) { IF_AFDATA_RLOCK ( ifp ) ; sid = SID ( ifp ) ; zoneid = sid -> s6id_list [ scope ] ; IF_AFDATA_RUNLOCK ( ifp ) ; } } if ( ret_id != NULL ) * ret_id = zoneid ; return ( 0 ) ; }
Determine the appropriate scope zone ID for in6 and ifp.
Determine the appropriate scope zone ID for in6 and ifp .
/*
	 * special case: the loopback address can only belong to a loopback
	 * interface.
	 */ /*
			 * Currently we use interface indeces as the
			 * zone IDs for interface-local and link-local
			 * scopes.
			 */ /* XXX */