FreeBSD/tools/tools/netmap/pkt-gen.c
/*
 * locate the src mac address for our interface, put it
 * into the user-supplied buffer. return 0 if ok, -1 on error.
 */
locate the src mac address for our interface, put it
into the user-supplied buffer. return 0 if ok, -1 on error.
locate the src mac address for our interface put it into the user - supplied buffer . return 0 if ok - 1 on error .
static int
source_hwaddr(const char *ifname, char *buf)
{
	struct ifaddrs *ifaphead, *ifap;
	int l = sizeof(ifap->ifa_name);
	if (getifaddrs(&ifaphead) != 0) {
		D("getifaddrs %s failed", ifname);
		return (-1);
	}
	for (ifap = ifaphead; ifap; ifap = ifap->ifa_next) {
		struct sockaddr_dl *sdl =
			(struct sockaddr_dl *)ifap->ifa_addr;
		uint8_t *mac;
		if (!sdl || sdl->sdl_family != AF_LINK)
			continue;
		if (strncmp(ifap->ifa_name, ifname, l) != 0)
			continue;
		mac = (uint8_t *)LLADDR(sdl);
		sprintf(buf, "%02x:%02x:%02x:%02x:%02x:%02x",
			mac[0], mac[1], mac[2],
			mac[3], mac[4], mac[5]);
		if (verbose)
			D("source hwaddr %s", buf);
		break;
	}
	freeifaddrs(ifaphead);
	return ifap ? 0 : 1;
}
static int source_hwaddr ( const char * ifname , char * buf ) { struct ifaddrs * ifaphead , * ifap ; int l = sizeof ( ifap -> ifa_name ) ; if ( getifaddrs ( & ifaphead ) != 0 ) { D ( " " , ifname ) ; return ( -1 ) ; } for ( ifap = ifaphead ; ifap ; ifap = ifap -> ifa_next ) { struct sockaddr_dl * sdl = ( struct sockaddr_dl * ) ifap -> ifa_addr ; uint8_t * mac ; if ( ! sdl || sdl -> sdl_family != AF_LINK ) continue ; if ( strncmp ( ifap -> ifa_name , ifname , l ) != 0 ) continue ; mac = ( uint8_t * ) LLADDR ( sdl ) ; sprintf ( buf , " " , mac [ 0 ] , mac [ 1 ] , mac [ 2 ] , mac [ 3 ] , mac [ 4 ] , mac [ 5 ] ) ; if ( verbose ) D ( " " , buf ) ; break ; } freeifaddrs ( ifaphead ) ; return ifap ? 0 : 1 ; }
locate the src mac address for our interface, put it
 into the user-supplied buffer.
locate the src mac address for our interface put it into the user - supplied buffer .