FreeBSD/sys/net/rtsock.c
/*
 * Extract the addresses of the passed sockaddrs.
 * Do a little sanity checking so as to avoid bad memory references.
 * This data is derived straight from userland.
 */
Extract the addresses of the passed sockaddrs.
Do a little sanity checking so as to avoid bad memory references.
This data is derived straight from userland.
Extract the addresses of the passed sockaddrs . Do a little sanity checking so as to avoid bad memory references . This data is derived straight from userland .
static int
rt_xaddrs(caddr_t cp, caddr_t cplim, struct rt_addrinfo *rtinfo)
{
	struct sockaddr *sa;
	int i;
	for (i = 0; i < RTAX_MAX && cp < cplim; i++) {
		if ((rtinfo->rti_addrs & (1 << i)) == 0)
			continue;
		sa = (struct sockaddr *)cp;
		if (cp + sa->sa_len > cplim)
			return (EINVAL);
		if (sa->sa_len == 0) {
			rtinfo->rti_info[i] = &sa_zero;
			return (0); 
		}
#ifdef INET6
		if (sa->sa_family == AF_INET6)
			sa6_embedscope((struct sockaddr_in6 *)sa,
			    V_ip6_use_defzone);
#endif
		rtinfo->rti_info[i] = sa;
		cp += SA_SIZE(sa);
	}
	return (0);
}
static int rt_xaddrs ( caddr_t cp , caddr_t cplim , struct rt_addrinfo * rtinfo ) { struct sockaddr * sa ; int i ; for ( i = 0 ; i < RTAX_MAX && cp < cplim ; i ++ ) { if ( ( rtinfo -> rti_addrs & ( 1 << i ) ) == 0 ) continue ; sa = ( struct sockaddr * ) cp ; if ( cp + sa -> sa_len > cplim ) return ( EINVAL ) ; if ( sa -> sa_len == 0 ) { rtinfo -> rti_info [ i ] = & sa_zero ; return ( 0 ) ; } #ifdef INET6 if ( sa -> sa_family == AF_INET6 ) sa6_embedscope ( ( struct sockaddr_in6 * ) sa , V_ip6_use_defzone ) ; #endif rtinfo -> rti_info [ i ] = sa ; cp += SA_SIZE ( sa ) ; } return ( 0 ) ; }
Extract the addresses of the passed sockaddrs.
Extract the addresses of the passed sockaddrs .
/*
		 * It won't fit.
		 */ /*
		 * there are no more.. quit now
		 * If there are more bits, they are in error.
		 * I've seen this. route(1) can evidently generate these. 
		 * This causes kernel to core dump.
		 * for compatibility, If we see this, point to a safe address.
		 */ /* should be EINVAL but for compat */ /* accept it */