FreeBSD/sbin/atm/atmconfig/natm.c
/*
 * Fetch the INET routes that a ours
 */
Fetch the INET routes that a ours
Fetch the INET routes that a ours
static void
natm_route_fetch(void)
{
	int name[6];
	size_t needed;
	u_char *buf, *next;
	struct rt_msghdr *rtm;
	name[0] = CTL_NET;
	name[1] = PF_ROUTE;
	name[2] = 0;
	name[3] = AF_INET;
	name[4] = NET_RT_DUMP;
	name[5] = 0;
	if (sysctl(name, 6, NULL, &needed, NULL, 0) == -1)
		err(1, "rtable estimate");
	needed *= 2;
	if ((buf = malloc(needed)) == NULL)
		err(1, "rtable buffer (%zu)", needed);
	if (sysctl(name, 6, buf, &needed, NULL, 0) == -1)
		err(1, "rtable get");
	next = buf;
	while (next < buf + needed) {
		rtm = (struct rt_msghdr *)(void *)next;
		next += rtm->rtm_msglen;
		if (rtm->rtm_type == RTM_GET) {
			if ((rtm->rtm_flags & (RTF_UP | RTF_HOST |
			    RTF_STATIC)) == (RTF_UP | RTF_HOST | RTF_STATIC) &&
			    (rtm->rtm_addrs & (RTA_DST | RTA_GATEWAY |
			    RTA_IFP)) == (RTA_DST | RTA_GATEWAY | RTA_IFP))
				store_route(rtm);
		}
	}
}
static void natm_route_fetch ( void ) { int name [ 6 ] ; size_t needed ; u_char * buf , * next ; struct rt_msghdr * rtm ; name [ 0 ] = CTL_NET ; name [ 1 ] = PF_ROUTE ; name [ 2 ] = 0 ; name [ 3 ] = AF_INET ; name [ 4 ] = NET_RT_DUMP ; name [ 5 ] = 0 ; if ( sysctl ( name , 6 , NULL , & needed , NULL , 0 ) == -1 ) err ( 1 , " " ) ; needed *= 2 ; if ( ( buf = malloc ( needed ) ) == NULL ) err ( 1 , " " , needed ) ; if ( sysctl ( name , 6 , buf , & needed , NULL , 0 ) == -1 ) err ( 1 , " " ) ; next = buf ; while ( next < buf + needed ) { rtm = ( struct rt_msghdr * ) ( void * ) next ; next += rtm -> rtm_msglen ; if ( rtm -> rtm_type == RTM_GET ) { if ( ( rtm -> rtm_flags & ( RTF_UP | RTF_HOST | RTF_STATIC ) ) == ( RTF_UP | RTF_HOST | RTF_STATIC ) && ( rtm -> rtm_addrs & ( RTA_DST | RTA_GATEWAY | RTA_IFP ) ) == ( RTA_DST | RTA_GATEWAY | RTA_IFP ) ) store_route ( rtm ) ; } } }
Fetch the INET routes that a ours
Fetch the INET routes that a ours