#include <u.h>
#include <libc.h>
#include <thread.h>
#include <ip.h>
#include "dat.h"
#include "fns.h"
void
put24(uchar *p, int x)
{
p[0] = x>>16;
p[1] = x>>8;
p[2] = x;
}
int
apetheraddr(uchar *eaddr, char *dir)
{
char fname[256];
char buf[2048];
int fd;
int n;
char *p, *e;
char *s;
int l;
s = "Base station: ";
l = strlen(s);
snprint(fname, sizeof(fname), "%s/ifstats", dir);
fd = open(fname, OREAD);
if (fd < 0) {
print("cannot open %s: %r", fname);
return -1;
}
n = read(fd, buf, sizeof(buf));
if (n < 0) {
print("cannot read ifstats %s: %r", fname);
close(fd);
return -1;
}
close(fd);
p = buf;
e = p + n;
while ((e - p > l) && strncmp(p, s, l) != 0) {
p = strchr(p, '\n');
p++;
}
if ((e - p > l) && strncmp(p, s, l) == 0) {
p += l;
if (parseether(eaddr, p) < 0) {
print("cannot parse ether from ifstats");
return -1;
}
}
return 0;
}
|