1 #include <u.h> 2 #include <libc.h> 3 #include <ip.h> 4 5 int 6 myetheraddr(uchar *to, char *dev) 7 { 8 int n, fd; 9 char buf[256], *ptr; 10 11 if(*dev == '/') 12 sprint(buf, "%s/stats", dev); 13 else 14 sprint(buf, "/net/%s/stats", dev); 15 16 fd = open(buf, OREAD); 17 if(fd < 0) { 18 /* try the old place - this code will disappear on Nov 18th */ 19 /* Make one exist */ 20 if(*dev == '/') 21 sprint(buf, "%s/clone", dev); 22 else 23 sprint(buf, "/net/%s/clone", dev); 24 fd = open(buf, ORDWR); 25 if(fd >= 0) 26 close(fd); 27 28 if(*dev == '/') 29 sprint(buf, "%s/0/stats", dev); 30 else 31 sprint(buf, "/net/%s/0/stats", dev); 32 fd = open(buf, OREAD); 33 if(fd < 0) 34 return -1; 35 } 36 37 n = read(fd, buf, sizeof(buf)-1); 38 close(fd); 39 if(n <= 0) 40 return -1; 41 buf[n] = 0; 42 43 ptr = strstr(buf, "addr: "); 44 if(!ptr) 45 return -1; 46 ptr += 6; 47 48 parseether(to, ptr); 49 return 0; 50 } 51