aboutsummaryrefslogtreecommitdiff
path: root/src/libip/myetheraddr.c
blob: a6b12def48c7783a6e75fd8be9a7604b503a891e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include <u.h>
#include <libc.h>
#include <ip.h>

static char zea[6];

int
myetheraddr(uchar *to, char *dev)
{
	Ipifc *ifclist, *ifc;
	
	ifclist = readipifc(nil, nil, -1);
	for(ifc=ifclist; ifc; ifc=ifc->next){
		if(dev && strcmp(ifc->dev, dev) != 0)
			continue;
		if(memcmp(zea, ifc->ether, 6) == 0)
			continue;
		memmove(to, ifc->ether, 6);
		freeipifc(ifclist);
		return 0;
	}
	freeipifc(ifclist);
	werrstr("no ethernet devices");
	return -1;
}