rsc | d709423 | 2003-11-23 18:23:20 +0000 | [diff] [blame] | 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 | /* Make one exist */ |
| 12 | if(*dev == '/') |
| 13 | sprint(buf, "%s/clone", dev); |
| 14 | else |
| 15 | sprint(buf, "/net/%s/clone", dev); |
| 16 | fd = open(buf, ORDWR); |
| 17 | if(fd >= 0) |
| 18 | close(fd); |
| 19 | |
| 20 | if(*dev == '/') |
| 21 | sprint(buf, "%s/0/stats", dev); |
| 22 | else |
| 23 | sprint(buf, "/net/%s/0/stats", dev); |
| 24 | fd = open(buf, OREAD); |
| 25 | if(fd < 0) |
| 26 | return -1; |
| 27 | |
| 28 | n = read(fd, buf, sizeof(buf)-1); |
| 29 | close(fd); |
| 30 | if(n <= 0) |
| 31 | return -1; |
| 32 | buf[n] = 0; |
| 33 | |
| 34 | ptr = strstr(buf, "addr: "); |
| 35 | if(!ptr) |
| 36 | return -1; |
| 37 | ptr += 6; |
| 38 | |
| 39 | parseether(to, ptr); |
| 40 | return 0; |
| 41 | } |