aboutsummaryrefslogtreecommitdiff
path: root/src/libip/myetheraddr.c
diff options
context:
space:
mode:
authorrsc <devnull@localhost>2005-12-31 19:33:03 +0000
committerrsc <devnull@localhost>2005-12-31 19:33:03 +0000
commit9aec88f29cf8145f887f31a4bfc7299f723b72e8 (patch)
tree9adf1d233e7e947a506539efe2bbcaefd96853f4 /src/libip/myetheraddr.c
parent9fe7e1a14c84bddc7bb0ec16ce23f44b5479ce94 (diff)
downloadplan9port-9aec88f29cf8145f887f31a4bfc7299f723b72e8.tar.gz
plan9port-9aec88f29cf8145f887f31a4bfc7299f723b72e8.tar.bz2
plan9port-9aec88f29cf8145f887f31a4bfc7299f723b72e8.zip
new
Diffstat (limited to 'src/libip/myetheraddr.c')
-rw-r--r--src/libip/myetheraddr.c51
1 files changed, 18 insertions, 33 deletions
diff --git a/src/libip/myetheraddr.c b/src/libip/myetheraddr.c
index d6995b7a..a51a40d6 100644
--- a/src/libip/myetheraddr.c
+++ b/src/libip/myetheraddr.c
@@ -2,40 +2,25 @@
#include <libc.h>
#include <ip.h>
+static char zea[6];
+
int
myetheraddr(uchar *to, char *dev)
{
- int n, fd;
- char buf[256], *ptr;
-
- /* Make one exist */
- if(*dev == '/')
- sprint(buf, "%s/clone", dev);
- else
- sprint(buf, "/net/%s/clone", dev);
- fd = open(buf, ORDWR);
- if(fd >= 0)
- close(fd);
-
- if(*dev == '/')
- sprint(buf, "%s/0/stats", dev);
- else
- sprint(buf, "/net/%s/0/stats", dev);
- fd = open(buf, OREAD);
- if(fd < 0)
- return -1;
-
- n = read(fd, buf, sizeof(buf)-1);
- close(fd);
- if(n <= 0)
- return -1;
- buf[n] = 0;
-
- ptr = strstr(buf, "addr: ");
- if(!ptr)
- return -1;
- ptr += 6;
-
- parseether(to, ptr);
- return 0;
+ Ipifc *ifclist, *ifc;
+
+ ifclist = readipifc(nil, nil, -1);
+ for(ifc=ifclist; ifc; ifc=ifc->next){
+ if(dev && strcmp(ifc->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;
}
+