diff options
author | skrll <skrll> | 2002-08-21 15:33:05 +0000 |
---|---|---|
committer | skrll <skrll> | 2002-08-21 15:33:05 +0000 |
commit | e4098ce073a892c1d36e4faa240e1703620d24fe (patch) | |
tree | 235b9ca290ee4978cda987c8877a1855a27ea4a2 /x11/kdebase3 | |
parent | 702cd9a2b8c2b9d4160a75d73bacc93e6c53ca93 (diff) | |
download | pkgsrc-e4098ce073a892c1d36e4faa240e1703620d24fe.tar.gz |
Apply the fixes provided in pkg/17912 and pkg/17981 so that ksysguardd
can show something useful.
Both PRs are from Hume Smith <hclsmith at yahoo dot ca>
PKGREVISION++
Diffstat (limited to 'x11/kdebase3')
-rw-r--r-- | x11/kdebase3/Makefile | 4 | ||||
-rw-r--r-- | x11/kdebase3/distinfo | 6 | ||||
-rw-r--r-- | x11/kdebase3/patches/patch-dd | 109 | ||||
-rw-r--r-- | x11/kdebase3/patches/patch-df | 570 |
4 files changed, 573 insertions, 116 deletions
diff --git a/x11/kdebase3/Makefile b/x11/kdebase3/Makefile index d34fc0fda17..36dccf6331a 100644 --- a/x11/kdebase3/Makefile +++ b/x11/kdebase3/Makefile @@ -1,7 +1,7 @@ -# $NetBSD: Makefile,v 1.4 2002/08/20 11:48:23 skrll Exp $ +# $NetBSD: Makefile,v 1.5 2002/08/21 15:33:05 skrll Exp $ DISTNAME= kdebase-3.0.2 -PKGREVISION= 1 +PKGREVISION= 2 CATEGORIES= x11 COMMENT= Base modules for the KDE 3 integrated X11 desktop diff --git a/x11/kdebase3/distinfo b/x11/kdebase3/distinfo index c8043781c98..48c6d2be375 100644 --- a/x11/kdebase3/distinfo +++ b/x11/kdebase3/distinfo @@ -1,4 +1,4 @@ -$NetBSD: distinfo,v 1.4 2002/08/20 11:48:24 skrll Exp $ +$NetBSD: distinfo,v 1.5 2002/08/21 15:33:05 skrll Exp $ SHA1 (kdebase-3.0.2.tar.bz2) = 763af0ddce718789fae3dfe2b67036dbc2d01a02 Size (kdebase-3.0.2.tar.bz2) = 13115043 bytes @@ -87,9 +87,9 @@ SHA1 (patch-cz) = 54f8fe86f485a05bc568d3219a3aa2f1db804792 SHA1 (patch-da) = ad54da1bc81cfd6cecebaa57f5a0c0a56d6d589f SHA1 (patch-db) = 9af64d1118aa30d99202430efc2921c731ae4a81 SHA1 (patch-dc) = ae7d541d91bd466142984b3680cc1e40834f528d -SHA1 (patch-dd) = 16248be0933c5d48c276d397e57eee959d2143b2 +SHA1 (patch-dd) = 2e9da1069c86ccafd19dbd0ed2b4594c5a4e2f71 SHA1 (patch-de) = 1fbea1abe5a8aefc0eacdc94d4ff60d26fb3c02a -SHA1 (patch-df) = 8c2ac2dda76839be08c4ed8667cd50b7a3cd4c2b +SHA1 (patch-df) = 21055681477de84f526af1a552f39bb433627089 SHA1 (patch-dg) = 2a0e3e14049665549a793cf0f785fc55cc1c7d5d SHA1 (patch-dh) = b84568ed97b14b16bbfdbc73dcb91b920242ad1b SHA1 (patch-di) = c6044dc47bde5eee686163ca2f3e90d016dacd59 diff --git a/x11/kdebase3/patches/patch-dd b/x11/kdebase3/patches/patch-dd index 1771716e172..180a425df61 100644 --- a/x11/kdebase3/patches/patch-dd +++ b/x11/kdebase3/patches/patch-dd @@ -1,7 +1,7 @@ -$NetBSD: patch-dd,v 1.1.1.1 2002/05/31 13:19:18 skrll Exp $ +$NetBSD: patch-dd,v 1.2 2002/08/21 15:33:05 skrll Exp $ --- ksysguard/ksysguardd/FreeBSD/Memory.c.orig Fri Sep 14 22:11:20 2001 -+++ ksysguard/ksysguardd/FreeBSD/Memory.c ++++ ksysguard/ksysguardd/FreeBSD/Memory.c Tue Aug 20 14:20:49 2002 @@ -32,7 +32,12 @@ #include <sys/types.h> #include <sys/vmmeter.h> @@ -15,68 +15,57 @@ $NetBSD: patch-dd,v 1.1.1.1 2002/05/31 13:19:18 skrll Exp $ #include "Command.h" #include "Memory.h" -@@ -82,15 +87,25 @@ - struct vmtotal p; - FILE *file; - char buf[256]; -+ int rc; -+#ifndef __NetBSD__ - struct kvm_swap kswap[16]; - int i, swap_count, hlen, pagesize = getpagesize(); - long blocksize; -+#endif - - len = sizeof (Total); -+#ifdef __NetBSD__ -+ mib[0] = CTL_HW; -+ mib[1] = HW_PHYSMEM; -+ sysctl(mib, sizeof(mib), &Total, &len, NULL, 0); -+#else - sysctlbyname("hw.physmem", &Total, &len, NULL, 0); -+#endif - Total /= 1024; - - /* Borrowed from pstat */ -+#ifndef __NetBSD__ - swap_count = kvm_getswapinfo(kd, kswap, 16, SWIF_DEV_PREFIX); - getbsize(&hlen, &blocksize); - -@@ -101,24 +116,42 @@ - SUsed = CONVERT(kswap[0].ksw_used); - SFree = CONVERT(kswap[0].ksw_total - kswap[0].ksw_used); - } -+#endif - -+#ifdef __NetBSD__ -+ /* NetBSD doesn't know about vfs.bufspace */ -+ Buffers = -1; -+#else - len = sizeof (Buffers); - if ((sysctlbyname("vfs.bufspace", &Buffers, &len, NULL, 0) == -1) || !len) - Buffers = 0; /* Doesn't work under FreeBSD v2.2.x */ -+#endif - Buffers /= 1024; - - +@@ -77,6 +82,49 @@ exitMemory(void) + int + updateMemory(void) + { +#ifdef __NetBSD__ ++#define ARRLEN(X) (sizeof(X)/sizeof(X[0])) ++ long pagesize; /* using a long promotes the arithmetic */ ++ size_t len; ++ ++ { static int mib[]={ CTL_HW, HW_PHYSMEM }; ++ ++ len = sizeof(Total); ++ sysctl(mib, ARRLEN(mib), &Total, &len, NULL, 0); ++ Total >>= 10; ++ } ++ ++ { struct uvmexp x; ++ static int mib[] = { CTL_VM, VM_UVMEXP }; ++ ++ len = sizeof(x); ++ STotal = SUsed = SFree = -1; ++ pagesize = 1; ++ if (-1 < sysctl(mib, ARRLEN(mib), &x, &len, NULL, 0)) { ++ pagesize = x.pagesize; ++ STotal = (pagesize*x.swpages) >> 10; ++ SUsed = (pagesize*x.swpginuse) >> 10; ++ SFree = STotal - SUsed; ++ } ++ } ++ ++ /* can't find NetBSD filesystem buffer info */ ++ Buffers = -1; ++ + /* NetBSD doesn't know about vm.stats */ + Cached = -1; ++ ++ { static int mib[]={ CTL_VM, VM_METER }; ++ struct vmtotal x; ++ ++ len = sizeof(x); ++ MFree = Used = -1; ++ if (sysctl(mib, ARRLEN(mib), &x, &len, NULL, 0) > -1) { ++ MFree = (x.t_free * pagesize) >> 10; ++ Used = (x.t_rm * pagesize) >> 10; ++ } ++ } +#else - len = sizeof (Cached); - if ((sysctlbyname("vm.stats.vm.v_cache_count", &Cached, &len, NULL, 0) == -1) || !len) - Cached = 0; /* Doesn't work under FreeBSD v2.2.x */ -+#endif - Cached *= getpagesize() / 1024; - - -+#ifdef __NetBSD__ -+ /* No idea where to get them right now. -+ * I don't want to start kmem-digging... */ -+ MFree = -1; -+ Used = -1; -+#else - /* initializes the pointer to the vmmeter struct */ - len = sizeof (p); + int mib[2]; + size_t len; + struct vmtotal p; +@@ -119,6 +167,7 @@ updateMemory(void) sysctlbyname("vm.vmmeter", &p, &len, NULL, 0); MFree = p.t_free * getpagesize() / 1024; Used = p.t_arm * getpagesize() / 1024 + Buffers + Cached; diff --git a/x11/kdebase3/patches/patch-df b/x11/kdebase3/patches/patch-df index 4eaab5c7b82..b7086d8d4b8 100644 --- a/x11/kdebase3/patches/patch-df +++ b/x11/kdebase3/patches/patch-df @@ -1,69 +1,537 @@ -$NetBSD: patch-df,v 1.2 2002/08/20 11:48:25 skrll Exp $ +$NetBSD: patch-df,v 1.3 2002/08/21 15:33:06 skrll Exp $ --- ksysguard/ksysguardd/FreeBSD/netdev.c.orig Tue Sep 18 15:03:53 2001 -+++ ksysguard/ksysguardd/FreeBSD/netdev.c -@@ -20,4 +20,11 @@ - */ - -+#if defined(__NetBSD__) -+#include <sys/types.h> -+#include <sys/socket.h> ++++ ksysguard/ksysguardd/FreeBSD/netdev.c Tue Aug 20 13:51:32 2002 +@@ -1,319 +1,263 @@ +-/* +- KSysGuard, the KDE System Guard +- +- Copyright (c) 2001 Tobias Koenig <tokoe82@yahoo.de> +- +- This program is free software; you can redistribute it and/or +- modify it under the terms of version 2 of the GNU General Public +- License as published by the Free Software Foundation. +- +- This program is distributed in the hope that it will be useful, +- but WITHOUT ANY WARRANTY; without even the implied warranty of +- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +- GNU General Public License for more details. +- +- You should have received a copy of the GNU General Public License +- along with this program; if not, write to the Free Software +- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +- +- $Id: patch-df,v 1.3 2002/08/21 15:33:06 skrll Exp $ +-*/ +- +-#include <fcntl.h> ++#include <sys/types.h> /* for sys/socket.h, ifaddrs.h */ +#include <ifaddrs.h> -+#include <net/if.h> -+#include <string.h> -+#else - #include <fcntl.h> #include <sys/socket.h> -@@ -30,4 +37,5 @@ - #include <sys/types.h> - #include <unistd.h> -+#endif ++#include <sys/param.h> /* for sys/sysctl.h */ ++#include <sys/sysctl.h> ++#include <net/route.h> + #include <net/if.h> +-#include <net/if_mib.h> +-#include <stdio.h> ++#include <net/if_dl.h> ++#include <stdlib.h> + #include <string.h> +-#include <sys/sysctl.h> +-#include <sys/time.h> +-#include <sys/types.h> +-#include <unistd.h> +- + + #include "Command.h" + #include "ksysguardd.h" + #include "netdev.h" +- ++#define I_bytes 0 ++#define I_packs 1 ++#define I_errs 2 ++#define I_mcasts 3 ++#define I_lost 4 + typedef struct { + char name[32]; +- u_long recBytes; +- u_long recPacks; +- u_long recErrs; +- u_long recDrop; +- u_long recMulticast; +- u_long sentBytes; +- u_long sentPacks; +- u_long sentErrs; +- u_long sentMulticast; +- u_long sentColls; ++ u_long recv[5],Drecv[5],sent[5],Dsent[5]; + } NetDevInfo; + ++#define LEN(X) (sizeof(X)/sizeof(X[0])) ++ + #define MAXNETDEVS 64 +-static NetDevInfo NetDevs[MAXNETDEVS]; ++static NetDevInfo NetDevs[MAXNETDEVS], newval[MAXNETDEVS]; + static int NetDevCnt = 0; -@@ -84,4 +92,17 @@ int numActivIfaces(void) - { - int counter = 0; +-char **parseCommand(const char *cmd) +-{ +- char tmp_cmd[1024]; +- char *begin; +- static char sensor[100]; +- static char interface[100]; +- static char* retval[2]; +- +- strncpy(tmp_cmd, cmd, 1024); +- +- begin = rindex(tmp_cmd, '/'); +- *begin = '\0'; +- begin++; +- strcpy(sensor, begin); +- retval[1] = sensor; +- +- begin = rindex(tmp_cmd, '/'); +- *begin = '\0'; +- begin = rindex(tmp_cmd, '/'); +- begin++; +- strcpy(interface, begin); +- retval[0] = interface; + +- return retval; +-} +- +-int numActivIfaces(void) +-{ +- int counter = 0; +- int name[6]; +- int num_iface, i; ++/* Read the system's traffic registers. ++ * Merely count the IFs if countp nonzero. ++ * Returns count of IFs read, or -1; the data are written into newval. ++ * Based on getifaddrs source; getifaddrs itself seems to ++ * compile incorrectly, omitting the traffic data. (It also ++ * does things this doesn't need, thus this is slightly more efficient.) ++ */ ++static int readSys(int countp) { + size_t len; +- struct ifmibdata ifmd; +- +- len = sizeof(num_iface); +- sysctlbyname("net.link.generic.system.ifcount", &num_iface, &len, NULL, 0); +- +- for (i = 1; i < num_iface + 1; i++) { +- name[0] = CTL_NET; +- name[1] = PF_LINK; +- name[2] = NETLINK_GENERIC; +- name[3] = IFMIB_IFDATA; +- name[4] = i; +- name[5] = IFDATA_GENERAL; +- +- len = sizeof(ifmd); +- sysctl(name, 6, &ifmd, &len, NULL, 0); +- if (ifmd.ifmd_flags & IFF_UP) +- counter++; ++ char *bfr, *ptr; ++ struct rt_msghdr *rtm; ++ NetDevInfo *nv; ++ static int mib[] = { ++ /* see sysctl(3): */ ++ CTL_NET, ++ PF_ROUTE, ++ 0, /* `currently always 0' */ ++ 0, /* `may be set to 0 to select all address families' */ ++ NET_RT_IFLIST, ++ 0 /* ignored but six levels are needed */ ++ }; ++ ++ if (-1==sysctl(mib, LEN(mib), NULL, &len, NULL, 0)) ++ return -1; ++ if (!(bfr = malloc(len))) ++ return -1; ++ if (-1==sysctl(mib, LEN(mib), bfr, &len, NULL, 0)) { ++ free(bfr); ++ return -1; + } ++ nv = newval; ++ for (ptr=bfr; ptr<bfr+len; ptr+=rtm->rtm_msglen) { ++ struct if_msghdr *ifm; + -+#if defined(__NetBSD__) -+ struct ifaddrs *ifap, *ifa; ++ rtm = (void*)ptr; /* chg ptr type to router msg */ ++ if (rtm->rtm_version != RTM_VERSION) continue; ++ if (rtm->rtm_type != RTM_IFINFO) continue; ++ ifm = (void*)rtm; /* chg ptr type to interface msg */ ++ if (!(ifm->ifm_flags & IFF_UP)) continue; + -+ if (getifaddrs(&ifap) != 0) -+ return 0; ++ if (!countp) { ++ /* a sdl is concat'd to the if msg */ ++ struct sockaddr_dl *sdl = (void*)(ifm+1); + -+ for (ifa = ifap; ifa; ifa=ifa->ifa_next) { -+ if (ifa->ifa_flags & IFF_UP) -+ counter++; ++ /* copy and terminate the name */ ++ /*fixme: check for overruns */ ++ memcpy(nv->name, sdl->sdl_data, sdl->sdl_nlen); ++ nv->name[sdl->sdl_nlen] = 0; ++ ++ /* copy the data */ ++ nv->recv[I_bytes] = ifm->ifm_data.ifi_ibytes; ++ nv->recv[I_packs] = ifm->ifm_data.ifi_ipackets; ++ nv->recv[I_errs] = ifm->ifm_data.ifi_ierrors; ++ nv->recv[I_mcasts] = ifm->ifm_data.ifi_imcasts; ++ nv->recv[I_lost] = ifm->ifm_data.ifi_iqdrops; ++ nv->sent[I_bytes] = ifm->ifm_data.ifi_obytes; ++ nv->sent[I_packs] = ifm->ifm_data.ifi_opackets; ++ nv->sent[I_errs] = ifm->ifm_data.ifi_oerrors; ++ nv->sent[I_mcasts] = ifm->ifm_data.ifi_omcasts; ++ nv->sent[I_lost] = ifm->ifm_data.ifi_collisions; ++ } + +- return counter; ++ /*fixme: guard against buffer overrun */ ++ nv++; + } -+ freeifaddrs(ifap); -+#else - int name[6]; - int num_iface, i; -@@ -105,4 +126,5 @@ int numActivIfaces(void) - counter++; - } -+#endif ++ free(bfr); ++ return nv-newval; + } + ++ ++ ++ + /* ------------------------------ public part --------------------------- */ - return counter; -@@ -175,4 +197,16 @@ void exitNetDev(void) - void updateNetDev(void) - { -+#if defined(__NetBSD__) -+ struct ifaddrs *ifap, *ifa; +-void initNetDev(void) +-{ +- int i; +- char monitor[1024]; ++static void prVal(const char*, int); ++void printNetDevRecv(const char *cmd) { prVal(cmd,0); } ++void printNetDevSent(const char *cmd) { prVal(cmd,1); } ++ ++static void prInfo(const char*, int); ++void printNetDevRecvInfo(const char *cmd) { prInfo(cmd,0); } ++void printNetDevSentInfo(const char *cmd) { prInfo(cmd,1); } ++ ++static struct { ++ char *label; ++ cmdExecutor read, inform; ++ struct { ++ char *label, *info; ++ int index; ++ } op[5]; ++} opTable[] = { ++ {"receiver", ++ printNetDevRecv, printNetDevRecvInfo, ++ {{"data", "Received Data\t0\t0\tB/s\n", I_bytes}, ++ {"packets", "Received Packets\t0\t0\tHz\n", I_packs}, ++ {"errors", "Receiver Errors\t0\t0\tHz\n", I_errs}, ++ {"multicast", "Received Multicast Packets\t0\t0\tHz\n", I_mcasts}, ++ {"drops", "Receiver Drops\t0\t0\tHz\n", I_lost}}}, ++ {"transmitter", ++ printNetDevSent, printNetDevSentInfo, ++ {{"data", "Sent Data\t0\t0\tB/s\n", I_bytes}, ++ {"packets", "Sent Packets\t0\t0\tHz\n", I_packs}, ++ {"errors", "Transmitter Errors\t0\t0\tHz\n", I_errs}, ++ {"multicast", "Sent Multicast Packets\t0\t0\tHz\n", I_mcasts}, ++ {"collisions", "Transmitter Collisions\t0\t0\tHz\n", I_lost}}} ++}; + -+ if (getifaddrs(&ifap) != 0) ++ ++static void prVal(const char *cmd, int N) { ++ char *p, *q, *r; ++ int i, d; + +- updateNetDev(); +- +- for (i = 0; i < NetDevCnt; i++) { +- snprintf(monitor, sizeof(monitor), "network/interfaces/%s/receiver/data", NetDevs[i].name); +- registerMonitor(monitor, "integer", printNetDevRecBytes, printNetDevRecBytesInfo); +- snprintf(monitor, sizeof(monitor), "network/interfaces/%s/receiver/packets", NetDevs[i].name); +- registerMonitor(monitor, "integer", printNetDevRecBytes, printNetDevRecBytesInfo); +- snprintf(monitor, sizeof(monitor), "network/interfaces/%s/receiver/errors", NetDevs[i].name); +- registerMonitor(monitor, "integer", printNetDevRecBytes, printNetDevRecBytesInfo); +- snprintf(monitor, sizeof(monitor), "network/interfaces/%s/receiver/drops", NetDevs[i].name); +- registerMonitor(monitor, "integer", printNetDevRecBytes, printNetDevRecBytesInfo); +- snprintf(monitor, sizeof(monitor), "network/interfaces/%s/receiver/multicast", NetDevs[i].name); +- registerMonitor(monitor, "integer", printNetDevRecBytes, printNetDevRecBytesInfo); +- +- snprintf(monitor, sizeof(monitor), "network/interfaces/%s/transmitter/data", NetDevs[i].name); +- registerMonitor(monitor, "integer", printNetDevSentBytes, printNetDevSentBytesInfo); +- snprintf(monitor, sizeof(monitor), "network/interfaces/%s/transmitter/packets", NetDevs[i].name); +- registerMonitor(monitor, "integer", printNetDevSentBytes, printNetDevSentBytesInfo); +- snprintf(monitor, sizeof(monitor), "network/interfaces/%s/transmitter/errors", NetDevs[i].name); +- registerMonitor(monitor, "integer", printNetDevSentBytes, printNetDevSentBytesInfo); +- snprintf(monitor, sizeof(monitor), "network/interfaces/%s/transmitter/multicast", NetDevs[i].name); +- registerMonitor(monitor, "integer", printNetDevSentBytes, printNetDevSentBytesInfo); +- snprintf(monitor, sizeof(monitor), "network/interfaces/%s/transmitter/collisions", NetDevs[i].name); +- registerMonitor(monitor, "integer", printNetDevSentBytes, printNetDevSentBytesInfo); +- } ++ if (!(p=rindex(cmd, '/'))) + return; ++ *p=0; ++ q=rindex(cmd, '/'); ++ *q=0; ++ r=rindex(cmd, '/'); ++ r++; ++ for (d=NetDevCnt; d--; ) ++ if (!strcmp(r, NetDevs[d].name)) ++ break; ++ *q=*p='/'; + -+ for (ifa = ifap; ifa; ifa=ifa->ifa_next) { -+ if (ifa->ifa_flags & IFF_UP) -+ ; -+ } -+ freeifaddrs(ifap); -+#else - int name[6]; - int num_iface, i; -@@ -209,4 +243,5 @@ void updateNetDev(void) ++ if (-1 == d) return; ++ ++ p++; ++ for (i=0; i<LEN(opTable[0].op); i++) ++ if (!strcmp(p, opTable[N].op[i].label)) ++ fprintf(CurrentClient, "%lu", ++ /*fixme: ugly and presumptuous */ ++ (N?NetDevs[d].Dsent:NetDevs[d].Drecv)[opTable[N].op[i].index]); ++ fprintf(CurrentClient, "\n"); + } + +-void exitNetDev(void) +-{ ++ ++static void prInfo(const char *cmd, int N) { ++ char *p, *q; + int i; +- char monitor[1024]; + +- for (i = 0; i < NetDevCnt; i++) { +- snprintf(monitor, sizeof(monitor), "network/interfaces/%s/receiver/data", NetDevs[i].name); +- removeMonitor(monitor); +- snprintf(monitor, sizeof(monitor), "network/interfaces/%s/receiver/packets", NetDevs[i].name); +- removeMonitor(monitor); +- snprintf(monitor, sizeof(monitor), "network/interfaces/%s/receiver/errors", NetDevs[i].name); +- removeMonitor(monitor); +- snprintf(monitor, sizeof(monitor), "network/interfaces/%s/receiver/drops", NetDevs[i].name); +- removeMonitor(monitor); +- snprintf(monitor, sizeof(monitor), "network/interfaces/%s/receiver/multicast", NetDevs[i].name); +- removeMonitor(monitor); +- +- snprintf(monitor, sizeof(monitor), "network/interfaces/%s/transmitter/data", NetDevs[i].name); +- removeMonitor(monitor); +- snprintf(monitor, sizeof(monitor), "network/interfaces/%s/transmitter/packets", NetDevs[i].name); +- removeMonitor(monitor); +- snprintf(monitor, sizeof(monitor), "network/interfaces/%s/transmitter/errors", NetDevs[i].name); +- removeMonitor(monitor); +- snprintf(monitor, sizeof(monitor), "network/interfaces/%s/transmitter/multicast", NetDevs[i].name); +- removeMonitor(monitor); +- snprintf(monitor, sizeof(monitor), "network/interfaces/%s/transmitter/collisions", NetDevs[i].name); +- removeMonitor(monitor); +- } +-} ++ if (!(p=rindex(cmd, '/'))) return; ++ p++; + +-void updateNetDev(void) +-{ +- int name[6]; +- int num_iface, i; +- size_t len; +- struct ifmibdata ifmd; ++ q = p+strlen(p)-1; ++ if ('?' != *q) return; ++ *q=0; ++ ++ for (i=0; i<LEN(opTable[0].op); i++) ++ if (!strcmp(p, opTable[N].op[i].label)) ++ fputs(opTable[N].op[i].info, CurrentClient); + +- len = sizeof(num_iface); +- sysctlbyname("net.link.generic.system.ifcount", &num_iface, &len, NULL, 0); +- +- NetDevCnt = 0; +- for (i = 1; i < num_iface + 1; i++) { +- name[0] = CTL_NET; +- name[1] = PF_LINK; +- name[2] = NETLINK_GENERIC; +- name[3] = IFMIB_IFDATA; +- name[4] = i; +- name[5] = IFDATA_GENERAL; +- +- len = sizeof(ifmd); +- sysctl(name, 6, &ifmd, &len, NULL, 0); +- if (ifmd.ifmd_flags & IFF_UP) { +- strncpy(NetDevs[NetDevCnt].name, ifmd.ifmd_name, 32); +- NetDevs[NetDevCnt].recBytes = ifmd.ifmd_data.ifi_ibytes - NetDevs[NetDevCnt].recBytes; +- NetDevs[NetDevCnt].recPacks = ifmd.ifmd_data.ifi_ipackets - NetDevs[NetDevCnt].recPacks; +- NetDevs[NetDevCnt].recErrs = ifmd.ifmd_data.ifi_ierrors - NetDevs[NetDevCnt].recErrs; +- NetDevs[NetDevCnt].recDrop = ifmd.ifmd_data.ifi_iqdrops - NetDevs[NetDevCnt].recDrop; +- NetDevs[NetDevCnt].recMulticast = ifmd.ifmd_data.ifi_imcasts - NetDevs[NetDevCnt].recMulticast; +- NetDevs[NetDevCnt].sentBytes = ifmd.ifmd_data.ifi_obytes - NetDevs[NetDevCnt].sentBytes; +- NetDevs[NetDevCnt].sentPacks = ifmd.ifmd_data.ifi_opackets - NetDevs[NetDevCnt].sentPacks; +- NetDevs[NetDevCnt].sentErrs = ifmd.ifmd_data.ifi_oerrors - NetDevs[NetDevCnt].sentErrs; +- NetDevs[NetDevCnt].sentMulticast = ifmd.ifmd_data.ifi_omcasts - NetDevs[NetDevCnt].sentMulticast; +- NetDevs[NetDevCnt].sentColls = ifmd.ifmd_data.ifi_collisions - NetDevs[NetDevCnt].sentColls; +- NetDevCnt++; +- } +- } ++ *q='?'; + } + +-void checkNetDev(void) +-{ +- if (numActivIfaces() != NetDevCnt) { +- /* interface has been added or removed +- so we do a reset */ +- exitNetDev(); +- initNetDev(); +- } +-} + +-void printNetDevRecBytes(const char *cmd) +-{ ++static void NDreg(int setp) { + int i; +- char **retval; +- +- retval = parseCommand(cmd); +- +- if (retval[0] == NULL || retval[1] == NULL) +- return; + +- for (i = 0; i < NetDevCnt; i++) { +- if (!strcmp(NetDevs[i].name, retval[0])) { +- if (!strncmp(retval[1], "data", 4)) +- fprintf(CurrentClient, "%lu", NetDevs[i].recBytes); +- if (!strncmp(retval[1], "packets", 7)) +- fprintf(CurrentClient, "%lu", NetDevs[i].recPacks); +- if (!strncmp(retval[1], "errors", 6)) +- fprintf(CurrentClient, "%lu", NetDevs[i].recErrs); +- if (!strncmp(retval[1], "drops", 5)) +- fprintf(CurrentClient, "%lu", NetDevs[i].recDrop); +- if (!strncmp(retval[1], "multicast", 9)) +- fprintf(CurrentClient, "%lu", NetDevs[i].recMulticast); ++ for (i = 0; i<NetDevCnt; i++) { ++ int j; ++ ++ for (j=0; j<LEN(opTable); j++) { ++ int k; ++ ++ for (k=0; k<LEN(opTable[0].op); k++) { ++ char buffer[1024]; ++ ++ snprintf(buffer, sizeof(buffer), ++ "network/interfaces/%s/%s/%s", ++ NetDevs[i].name, ++ opTable[j].label, ++ opTable[j].op[k].label); ++ ++ /* printf("%d %d %d %s\n",i,j,k,buffer); */ ++ ++ if (setp) ++ registerMonitor(buffer, ++ "integer", ++ opTable[j].read, ++ opTable[j].inform); ++ else ++ removeMonitor(buffer); ++ } } } -+#endif +- +- fprintf(CurrentClient, "\n"); } +-void printNetDevRecBytesInfo(const char *cmd) +-{ +- char **retval; +- +- retval = parseCommand(cmd); +- +- if (retval[1] == NULL) +- return; ++void initNetDev(void) { ++ int i; ++ updateNetDev(); ++ for (i=LEN(NetDevs); i--;) ++ strcpy(NetDevs[i].name, newval[i].name); ++ NDreg(!0); ++} + +- if (!strncmp(retval[1], "data", 4)) +- fprintf(CurrentClient, "Received Data\t0\t0\tkBytes/s\n"); +- if (!strncmp(retval[1], "packets", 7)) +- fprintf(CurrentClient, "Received Packets\t0\t0\t1/s\n"); +- if (!strncmp(retval[1], "errors", 6)) +- fprintf(CurrentClient, "Receiver Errors\t0\t0\t1/s\n"); +- if (!strncmp(retval[1], "drops", 5)) +- fprintf(CurrentClient, "Receiver Drops\t0\t0\t1/s\n"); +- if (!strncmp(retval[1], "multicast", 9)) +- fprintf(CurrentClient, "Received Multicast Packets\t0\t0\t1/s\n"); ++void exitNetDev(void) { ++ NDreg(0); + } + +-void printNetDevSentBytes(const char *cmd) +-{ +- int i; +- char **retval; +- +- retval = parseCommand(cmd); +- +- if (retval[0] == NULL || retval[1] == NULL) ++void updateNetDev(void) { ++ NetDevInfo *p, *q; ++ int n; ++ ++ if (-1==(n = readSys(0))) + return; + +- for (i = 0; i < NetDevCnt; i++) { +- if (!strcmp(NetDevs[i].name, retval[0])) { +- if (!strncmp(retval[1], "data", 4)) +- fprintf(CurrentClient, "%lu", NetDevs[i].sentBytes); +- if (!strncmp(retval[1], "packets", 7)) +- fprintf(CurrentClient, "%lu", NetDevs[i].sentPacks); +- if (!strncmp(retval[1], "errors", 6)) +- fprintf(CurrentClient, "%lu", NetDevs[i].sentErrs); +- if (!strncmp(retval[1], "multicast", 9)) +- fprintf(CurrentClient, "%lu", NetDevs[i].sentMulticast); +- if (!strncmp(retval[1], "collisions", 10)) +- fprintf(CurrentClient, "%lu", NetDevs[i].sentColls); ++ NetDevCnt = n; ++ /*fixme: assumes the interfaces are in the same order each time */ ++ for (p=NetDevs, q=newval; n--; p++, q++) { ++ int i; ++ /* calculate deltas */ ++ for (i=0; i<5; i++) { ++ p->Drecv[i] = q->recv[i]-p->recv[i]; ++ p->recv[i] = q->recv[i]; ++ p->Dsent[i] = q->sent[i]-p->sent[i]; ++ p->sent[i] = q->sent[i]; + } + } +- +- fprintf(CurrentClient, "\n"); + } + +-void printNetDevSentBytesInfo(const char *cmd) +-{ +- char **retval; +- +- retval = parseCommand(cmd); +- +- if (retval[1] == NULL) +- return; + +- if (!strncmp(retval[1], "data", 4)) +- fprintf(CurrentClient, "Sent Data\t0\t0\tkBytes/s\n"); +- if (!strncmp(retval[1], "packets", 7)) +- fprintf(CurrentClient, "Sent Packets\t0\t0\t1/s\n"); +- if (!strncmp(retval[1], "errors", 6)) +- fprintf(CurrentClient, "Transmitter Errors\t0\t0\t1/s\n"); +- if (!strncmp(retval[1], "multicast", 9)) +- fprintf(CurrentClient, "Sent Multicast Packets\t0\t0\t1/s\n"); +- if (!strncmp(retval[1], "collisions", 10)) +- fprintf(CurrentClient, "Transmitter Collisions\t0\t0\t1/s\n"); ++void checkNetDev(void) { ++ if (readSys(!0) != NetDevCnt) { ++ /* interface has been added or removed ++ so we do a reset */ ++ exitNetDev(); ++ initNetDev(); ++ } + } ++ ++ ++/* eof */ |