Hi,
plan9/plan9port is broken after network stack changes in net/if_var.h
here is a diff that convert plan9port to use getifaddrs(3) instead of kvm(3) in
p9p auxstats.
builds and runs fine(auxstats is incrementing and seems ok), but I would
appreciate other eyes(review),
// gsoares
Index: Makefile
===
RCS file: /cvs/ports/plan9/plan9port/Makefile,v
retrieving revision 1.10
diff -u -p -u -p -r1.10 Makefile
--- Makefile4 Dec 2015 04:26:33 - 1.10
+++ Makefile7 Dec 2015 21:36:31 -
@@ -6,7 +6,7 @@ BROKEN-powerpc =threading issues
COMMENT = Plan 9 from user space
DISTNAME = plan9port-2015
-REVISION = 0
+REVISION = 1
GH_ACCOUNT = 9fans
GH_PROJECT = plan9port
Index: patches/patch-src_cmd_auxstats_OpenBSD_c
===
RCS file: patches/patch-src_cmd_auxstats_OpenBSD_c
diff -N patches/patch-src_cmd_auxstats_OpenBSD_c
--- /dev/null 1 Jan 1970 00:00:00 -
+++ patches/patch-src_cmd_auxstats_OpenBSD_c7 Dec 2015 21:36:31 -
@@ -0,0 +1,157 @@
+$OpenBSD$
+
+replace kvm(3) with getifaddrs(3)
+
+--- src/cmd/auxstats/OpenBSD.c.origWed Nov 11 12:09:34 2015
src/cmd/auxstats/OpenBSD.c Mon Dec 7 02:20:58 2015
+@@ -1,14 +1,12 @@
+ #include
+-#include
+-#include
+ #include
+ #include
+ #include
+ #include
++#include
+ #include
+ #include
+ #include
+-#include
+ #include
+ #include
+ #include
+@@ -24,11 +22,9 @@ void xcpu(int);
+ void xswap(int);
+ void xsysctl(int);
+ void xnet(int);
+-void xkvm(int);
+
+ void (*statfn[])(int) =
+ {
+- xkvm,
+ xapm,
+ xloadavg,
+ xcpu,
+@@ -37,14 +33,6 @@ void (*statfn[])(int) =
+ 0
+ };
+
+-static kvm_t *kvm;
+-
+-static struct nlist nl[] = {
+- { "_ifnet" },
+- { "_cp_time" },
+- { "" }
+-};
+-
+ void
+ xloadavg(int first)
+ {
+@@ -76,78 +64,37 @@ xapm(int first)
+ Bprint(, "battery =%d 100\n", ai.battery_life);
+ }
+
+-
+ void
+-kvminit(void)
+-{
+- char buf[_POSIX2_LINE_MAX];
+-
+- if(kvm)
+- return;
+- kvm = kvm_openfiles(nil, nil, nil, O_RDONLY, buf);
+- if(kvm == nil) {
+- fprint(2, "kvm open error\n%s", buf);
+- return;
+- }
+- if(kvm_nlist(kvm, nl) < 0 || nl[0].n_type == 0){
+- kvm = nil;
+- return;
+- }
+-}
+-
+-void
+-xkvm(int first)
+-{
+- if(first)
+- kvminit();
+-}
+-
+-int
+-kread(ulong addr, char *buf, int size)
+-{
+- if(kvm_read(kvm, addr, buf, size) != size){
+- memset(buf, 0, size);
+- return -1;
+- }
+- return size;
+-}
+-
+-void
+ xnet(int first)
+ {
+ ulong out, in, outb, inb, err;
+- static ulong ifnetaddr;
+- ulong addr;
+- struct ifnet ifnet;
+- struct ifnet_head ifnethead;
+- char name[16];
++ struct ifaddrs *ifa, *ifap;
++ struct if_data *ifd = NULL;
+
+- if(first)
++ if (first)
+ return;
+
+- if(ifnetaddr == 0){
+- ifnetaddr = nl[0].n_value;
+- if(ifnetaddr == 0)
+- return;
+- }
++ out = in = outb = inb = err = 0;
+
+- if(kread(ifnetaddr, (char*), sizeof ifnethead) < 0)
++ if (getifaddrs() == -1)
+ return;
+
+- out = in = outb = inb = err = 0;
+- addr = (ulong)TAILQ_FIRST();
+- while(addr){
+- if(kread(addr, (char*), sizeof ifnet) < 0
+- || kread((ulong)ifnet.if_xname, name, 16) < 0)
+- return;
+- name[15] = 0;
+- addr = (ulong)TAILQ_NEXT(, if_list);
+- out += ifnet.if_opackets;
+- in += ifnet.if_ipackets;
+- outb += ifnet.if_obytes;
+- inb += ifnet.if_ibytes;
+- err += ifnet.if_oerrors+ifnet.if_ierrors;
++ for (ifa = ifap; ifa != NULL; ifa = ifa->ifa_next) {
++ if (ifa->ifa_addr == NULL ||
++ ifa->ifa_addr->sa_family != AF_LINK)
++ continue;
++
++ ifd = ifa->ifa_data;
++
++ if (ifd != NULL) {
++ out += ifd->ifi_opackets;
++ in += ifd->ifi_ipackets;
++ outb += ifd->ifi_obytes;
++ inb += ifd->ifi_ibytes;
++ err += ifd->ifi_ierrors;
++ }
+ }
++
+ Bprint(, "etherin %lud 1000\n", in);
+ Bprint(, "etherout %lud 1000\n", out);
+ Bprint(, "etherinb %lud 100\n", inb);
+@@ -155,6 +102,8 @@ xnet(int first)
+ Bprint(, "ethererr %lud 1000\n", err);
+ Bprint(, "ether %lud 1000\n", in+out);
+ Bprint(, "etherb %lud 100\n", inb+outb);
++
++ freeifaddrs(ifap);
+ }
+
+ void