Removing obsolete ports wmnet

This commit is contained in:
solene 2018-06-01 18:04:06 +00:00
parent 569e047783
commit 2a3741e7f7
9 changed files with 0 additions and 923 deletions

View File

@ -1,22 +0,0 @@
# $OpenBSD: Makefile,v 1.24 2015/12/07 18:00:42 jasper Exp $
COMMENT= little X dock.app network monitor
DISTNAME= wmnet-1.06
REVISION= 9
CATEGORIES= net x11 x11/windowmaker
HOMEPAGE= http://www.katharineosborne.com/wmnet/
MASTER_SITES= http://dockapps.org/files/77/115/
MAINTAINER= Vladimir Popov <pva48@mail.ru>
# GPL
PERMIT_PACKAGE_CDROM= Yes
WANTLIB= X11 Xau Xdmcp Xext c m
MAKE_FLAGS= CC="${CC}" CCOPTIONS="${CFLAGS}"
CONFIGURE_STYLE=imake
NO_TEST= Yes
.include <bsd.port.mk>

View File

@ -1,2 +0,0 @@
SHA256 (wmnet-1.06.tar.gz) = ecbvkxJtKkkogYORwKogY41HzZ3KEtmZ53RZH5stNl0=
SIZE (wmnet-1.06.tar.gz) = 27506

View File

@ -1,24 +0,0 @@
$OpenBSD: patch-Imakefile,v 1.2 2015/12/07 18:00:42 jasper Exp $
--- Imakefile.orig Fri May 5 02:34:29 2000
+++ Imakefile Mon Dec 7 18:54:24 2015
@@ -10,14 +10,18 @@ DEFINES = -Dlinux_libc6
LOCAL_LIBRARIES = $(XLIB) -lm
#endif
-#if defined (FreeBSDArchitecture) || defined (OpenBSDArchitecture)
+#if defined (FreeBSDArchitecture)
LOCAL_LIBRARIES = $(XLIB) -lm -lkvm
INSTPGMFLAGS = -s -g kmem -m 2755
#endif
+#if defined (OpenBSDArchitecture)
+LOCAL_LIBRARIES = $(XLIB) -lm
+#endif
+
LINTLIBS = $(LINTXLIB)
-#if defined (FreeBSDArchitecture) || defined (OpenBSDArchitecture)
+#if defined (FreeBSDArchitecture)
SRCS = wmnet.c drivers.c getopt.c getopt1.c
OBJS = wmnet.o drivers.o getopt.o getopt1.o
#else

View File

@ -1,16 +0,0 @@
$OpenBSD: patch-config_h,v 1.1 2015/12/07 18:00:42 jasper Exp $
--- config.h.orig Mon Dec 7 18:52:28 2015
+++ config.h Mon Dec 7 18:52:47 2015
@@ -1,4 +1,4 @@
-#if defined (__FreeBSD__) || defined (__OpenBSD__)
+#if defined (__FreeBSD__)
/* Our only FreeBSD driver, this goes straight into kernel memory
* and reads the raw structures from right underneath the kernel using the
@@ -54,3 +54,6 @@
#define USE_2_1_DEV
#endif /* linux */
+#if defined(__OpenBSD__)
+#define USE_GETIFADDRS
+#endif

View File

@ -1,210 +0,0 @@
$OpenBSD: patch-drivers_c,v 1.6 2015/12/07 18:00:42 jasper Exp $
--- drivers.c.orig Fri May 5 02:34:29 2000
+++ drivers.c Mon Dec 7 18:51:16 2015
@@ -9,18 +9,21 @@
* great, but please send me the diff.
*/
-#include<stdlib.h>
-#include<stdio.h>
-#include<string.h>
-#include<X11/Xlib.h>
-#include<fcntl.h>
-#include<sys/types.h>
-#include<sys/stat.h>
-#include<sys/socket.h>
-#include<unistd.h>
-#include"config.h"
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <sys/stat.h>
+#include <X11/Xlib.h>
+#include <err.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include "config.h"
+#include "wmnet.h"
+
/* For FreeBSD */
#ifdef USE_KVM
#include<net/if.h>
@@ -57,18 +60,6 @@ static struct ifpppstatsreq ppp_stats_req;
#define ACCOUNT_IN_FOUND 1
#define ACCOUNT_OUT_FOUND 2
-extern char buffer[256];
-extern char *in_rule_string, *out_rule_string, *device;
-extern unsigned long totalbytes_in, totalbytes_out, lastbytes_in, lastbytes_out;
-extern unsigned long totalpackets_in, totalpackets_out, lastpackets_in, lastpackets_out;
-extern unsigned int diffpackets_in, diffpackets_out, diffbytes_in, diffbytes_out;
-extern unsigned int out_rule, in_rule; /* number of rule in /proc/net/ip_acct to use */
-extern Bool current_tx, current_rx, rx, tx;
-
-
-
-char *available_drivers(void);
-
#ifdef USE_IPFWADM
int updateStats_ipfwadm(void);
int ipfwadm_test(void);
@@ -81,11 +72,16 @@ int ipchains_test(void);
int updateStats_dev(void);
int dev_test(void);
#endif
+#ifdef USE_GETIFADDRS
+#include <ifaddrs.h>
+#include <net/if.h>
+int updateStats_bsd(struct if_data_t *);
+int bsd_test(struct if_data_t *);
+#endif
-typedef int (*parser_func)(void);
static struct drivers_struct {
- char * name;
+ char *name;
parser_func function;
parser_func test;
} drivers[] = {
@@ -104,10 +100,14 @@ static struct drivers_struct {
#ifdef USE_KVM
{"kmem",kvm_updateStats, kvm_test},
#endif
+#ifdef USE_GETIFADDRS
+ {"bsd", updateStats_bsd, bsd_test},
+#endif
{NULL, NULL}
};
-char* available_drivers(void) {
+char *
+available_drivers(void) {
int ind = 0;
int len = 0;
char *string, *ptr;
@@ -127,14 +127,12 @@ char* available_drivers(void) {
*(--string) = '\0';
return ptr;
}
-
-
-parser_func find_driver(void) {
+parser_func find_driver(struct if_data_t *id) {
int ind = 0;
while(drivers[ind].name != NULL) {
- if(drivers[ind].test()) {
- return drivers[ind].function;
+ if(drivers[ind].test(id)) {
+ return (parser_func)drivers[ind].function;
}
ind++;
}
@@ -143,12 +141,13 @@ parser_func find_driver(void) {
}
-parser_func setup_driver(char * parser_name) {
+setup_func
+setup_driver(char *parser_name, struct if_data_t *id) {
int ind = 0;
- if (parser_name == NULL) return find_driver();
+ if (parser_name == NULL) return (void *)find_driver(id);
while(drivers[ind].name != NULL) {
if(!strcmp(parser_name, drivers[ind].name)) {
- if (drivers[ind].test()) return drivers[ind].function;
+ if (drivers[ind].test(id)) return (void *)drivers[ind].function;
fprintf(stderr, "wmnet: driver %s not appropriate for this machine\n", parser_name);
exit(18);
}
@@ -157,10 +156,7 @@ parser_func setup_driver(char * parser_name) {
fprintf(stderr, "wmnet: no driver %s\n", parser_name);
exit(18);
}
-
-
-
#ifdef linux
/* All the data gathering is done in here.
* Return True if no change to tx/rx.
@@ -503,7 +499,71 @@ int kvm_updateStats(void) {
#endif
-
-
-
+
+#ifdef USE_GETIFADDRS
+int bsd_test(struct if_data_t *id) {
+ struct ifaddrs *ifa;
+
+ if (getifaddrs(&ifa) != 0) {
+ freeifaddrs(ifa);
+ return False;
+ }
+
+ warnx("using getifaddrs(3) to monitor %s", id->device);
+ return True;
+}
+
+int updateStats_bsd(struct if_data_t *id) {
+ struct ifaddrs *ifap, *ifa;
+
+ id->rx = False;
+ id->tx = False;
+
+ if (getifaddrs(&ifap) != 0) {
+ freeifaddrs(ifap);
+ return False;
+ }
+
+ for (ifa = ifap; ifa != NULL; ifa = ifa->ifa_next) {
+ if (strcmp(id->device, ifa->ifa_name)) {
+ continue;
+ }
+
+ if (ifa->ifa_addr->sa_family == AF_LINK) {
+ struct if_data *ifd = NULL;
+
+ ifd = ifa->ifa_data;
+
+ if (ifd != NULL) {
+ totalpackets_in = ifd->ifi_ipackets;
+ if (totalpackets_in != lastpackets_in) {
+ totalbytes_in = ifd->ifi_ibytes;
+ diffpackets_in += totalpackets_in - lastpackets_in;
+ diffbytes_in += totalbytes_in - lastbytes_in;
+ lastpackets_in = totalpackets_in;
+ lastbytes_in = totalbytes_in;
+ id->rx = True;
+ }
+
+ totalpackets_out = ifd->ifi_opackets;
+ if (totalpackets_out != lastpackets_out) {
+ totalbytes_out =ifd->ifi_ibytes;
+ diffpackets_out += totalpackets_out - lastpackets_out;
+ diffbytes_out += totalbytes_out - lastbytes_out;
+ lastpackets_out = totalpackets_out;
+ lastbytes_out = totalbytes_out;
+ id->tx = True;
+ }
+
+ return 0;
+ }
+ }
+ }
+
+ /* return True if no change to tx/rx
+ * return False if display will need to be updated
+ */
+ return ((id->rx == id->current_rx) && (id->tx == id->current_tx));
+}
+#endif

View File

@ -1,549 +0,0 @@
$OpenBSD: patch-wmnet_c,v 1.4 2013/11/22 15:35:22 sthen Exp $
--- wmnet.c.orig Fri May 5 02:01:14 2000
+++ wmnet.c Fri Nov 22 15:32:16 2013
@@ -49,34 +49,51 @@
* 5/4/2000 -- Support added for OpenBSD
*/
-#include<stdlib.h>
-#include<stdio.h>
-#include<X11/X.h>
-#include<X11/Xlib.h>
-#include<X11/Xutil.h>
-#include<X11/Xatom.h>
-#if defined (__FreeBSD__) || defined (__OpenBSD__)
-# include<sys/socket.h>
-# include"getopt.h"
-#else
-# include<getopt.h>
-#endif
-#include<net/if.h>
-#include<signal.h>
-#include<unistd.h>
-#include<string.h>
-#include<math.h>
-#include<sys/time.h>
-#include<sys/socket.h>
-#include<sys/types.h>
-#include<sys/ioctl.h>
-#include<sys/wait.h>
-#include<X11/extensions/shape.h>
+#include <sys/types.h>
+#include <sys/ioctl.h>
+#include <sys/socket.h>
+#include <sys/time.h>
+#include <sys/wait.h>
+#include <net/if.h>
+
+#include <X11/extensions/shape.h>
+#include <X11/X.h>
+#include <X11/Xatom.h>
+#include <X11/Xlib.h>
+#include <X11/Xutil.h>
+
+#include <err.h>
+#include <getopt.h>
+#include <math.h>
+#include <signal.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
#include "XPM/arrow.xbm"
#include "wmnet.h"
+/* X Stuff */
+static Display *dpy;
+static Window root_window, main_window, icon_window, *visible_window;
+static Pixmap arrow;
+static Atom delete_atom;
+static int screen, specified_state = -1;
+static GC graphics_context;
+static unsigned long tx_pixel[3], rx_pixel[3], labelfg_pixel, labelbg_pixel, black_pixel, white_pixel, darkgrey_pixel, grey_pixel;
+static char *click_command = NULL, *label = NULL;
+static struct timeval timenow, timelast;
+static unsigned int delayTime = 25000, displayDelay = 55000, maxRate = 6000;
+static unsigned int graphbox_height = 44; /* number of rule in /proc/net/ip_acct to use */
+static Bool logscale = False;
+
+parser_func stat_gather;
+
+static struct if_data_t id;
+
/* Called on exit() from atexit() */
void exit_func(void) {
XCloseDisplay(dpy);
@@ -90,8 +107,6 @@ void got_signal(int x) {
} else exit(7);
}
-
-
/* Does generic setting up of wmnet, (option parsing) and calls setupX() */
void setup_wmnet(int argc, char **argv) {
int c;
@@ -143,10 +158,14 @@ void setup_wmnet(int argc, char **argv) {
exit(14);
break;
case 'W':
- device = strdup(optarg);
+ id.device = strdup(optarg);
+ if (id.device == NULL)
+ err(1, "memory allocation for device");
break;
case 'D':
parser = strdup(optarg);
+ if (parser == NULL)
+ err(1, "memory allocation for parser");
break;
#ifdef linux
case 'T':
@@ -162,9 +181,10 @@ void setup_wmnet(int argc, char **argv) {
graphbox_height = 35;
if (label == NULL) {
label = strdup(optarg);
+ if (label == NULL)
+ err(22, "memory allocation for label");
} else {
- fprintf(stderr, "wmnet: duplicate --label\n");
- exit(22);
+ errx(22, "duplicate --label");
}
break;
case 'B':
@@ -172,8 +192,7 @@ void setup_wmnet(int argc, char **argv) {
labelbgcolorString = (char *)alloca(strlen(optarg)+1);
strncpy(labelbgcolorString, optarg, strlen(optarg)+1);
} else {
- fprintf(stderr, "wmnet: duplicate --labelbg\n");
- exit(23);
+ errx(23, "duplicate --labelbg");
}
break;
case 'F':
@@ -181,8 +200,7 @@ void setup_wmnet(int argc, char **argv) {
labelfgcolorString = (char *)alloca(strlen(optarg)+1);
strncpy(labelfgcolorString, optarg, strlen(optarg)+1);
} else {
- fprintf(stderr, "wmnet: duplicate --labelfg\n");
- exit(23);
+ errx(23, "duplicate --labelfg");
}
break;
case 'l':
@@ -193,8 +211,7 @@ void setup_wmnet(int argc, char **argv) {
rxcolorString = (char *)alloca(strlen(optarg)+1);
strncpy(rxcolorString, optarg, strlen(optarg)+1);
} else {
- fprintf(stderr, "wmnet: duplicate --rxcolor\n");
- exit(18);
+ errx(18, "duplicate --rxcolor");
}
break;
case 't':
@@ -202,8 +219,7 @@ void setup_wmnet(int argc, char **argv) {
txcolorString = (char *)alloca(strlen(optarg)+1);
strncpy(txcolorString, optarg, strlen(optarg)+1);
} else {
- fprintf(stderr, "wmnet: duplicate --rxcolor\n");
- exit(19);
+ errx(19, "duplicate --txcolor");
}
break;
case 'x':
@@ -217,9 +233,10 @@ void setup_wmnet(int argc, char **argv) {
case 'e':
if (click_command == NULL) {
click_command = strdup(optarg);
+ if (click_command == NULL)
+ err(17, "memory allocation for click command");
} else {
- fprintf(stderr, "wmnet: duplicate --execute\n");
- exit(17);
+ errx(17, "duplicate --execute");
}
break;
case 'w':
@@ -234,19 +251,16 @@ void setup_wmnet(int argc, char **argv) {
struct ifreq ifr;
strncpy(ifr.ifr_name, optarg, IFNAMSIZ );
ifr.ifr_name[IFNAMSIZ-1] = 0;
- if ((fds = socket(AF_INET, SOCK_DGRAM, 0)) == -1 || ioctl(fds, SIOCGIFFLAGS, &ifr) == -1 ) {
- perror("wmnet");
- exit(20);
- }
+ if ((fds = socket(AF_INET, SOCK_DGRAM, 0)) == -1)
+ err(20, "socket()");
+ if (ioctl(fds, SIOCGIFFLAGS, &ifr) == -1 )
+ err(20, "SIOCGIFFLAGS");
if ((ifr.ifr_flags & IFF_PROMISC) != 0) { /* Is promiscuous mode not already unset? */
ifr.ifr_flags &= ~IFF_PROMISC;
- if (geteuid() != 0) {
- fprintf(stderr, "wmnet: this must be suid or you must be root!\n");
- }
- if(ioctl(fds, SIOCSIFFLAGS, &ifr) != 0) {
- fprintf(stderr, "wmnet: cannot unset promiscuous mode on %s\n", optarg);
- exit(21);
- }
+ if (geteuid() != 0)
+ warnx("this must be suid or you must be root!");
+ if(ioctl(fds, SIOCSIFFLAGS, &ifr) != 0)
+ err(21, "cannot unset promiscuous mode on %s", optarg);
}
close(fds);
}
@@ -257,19 +271,16 @@ void setup_wmnet(int argc, char **argv) {
struct ifreq ifr;
strncpy(ifr.ifr_name, optarg, IFNAMSIZ );
ifr.ifr_name[IFNAMSIZ-1] = 0;
- if ((fds = socket(AF_INET, SOCK_DGRAM, 0)) == -1 || ioctl(fds, SIOCGIFFLAGS, &ifr) == -1 ) {
- perror("wmnet");
- exit(16);
- }
+ if ((fds = socket(AF_INET, SOCK_DGRAM, 0)) == -1)
+ err(16, "socket()");
+ if (ioctl(fds, SIOCGIFFLAGS, &ifr) == -1 )
+ err(16, "SIOCGIFFLAGS");
if ((ifr.ifr_flags & IFF_PROMISC) == 0) { /* Is promiscuous mode not already set? */
ifr.ifr_flags |= IFF_PROMISC;
- if (geteuid() != 0) {
- fprintf(stderr, "wmnet: this must be suid or you must be root!\n");
- }
- if(ioctl(fds, SIOCSIFFLAGS, &ifr) != 0) {
- fprintf(stderr, "wmnet: cannot set promiscuous mode on %s\n", optarg);
- exit(13);
- }
+ if (geteuid() != 0)
+ warnx("wmnet: this must be suid or you must be root!");
+ if(ioctl(fds, SIOCSIFFLAGS, &ifr) != 0)
+ err(13, "cannot set promiscuous mode on %s", optarg);
}
close(fds);
}
@@ -313,31 +324,24 @@ void setup_wmnet(int argc, char **argv) {
/* Relinquish suid privileges if there */
seteuid(getuid());
- stat_gather = setup_driver(parser);
+ stat_gather = (parser_func)setup_driver(parser, &id);
-
if (txcolorString == NULL) txcolorString = "white";
if (rxcolorString == NULL) rxcolorString = "red";
if (labelfgcolorString == NULL) labelfgcolorString = "white";
if (labelbgcolorString == NULL) labelbgcolorString = "black";
/* Change dir to /, security precaution, and common courtesy */
- if (chdir("/") == -1) {
- perror("wmnet: chdir()");
- exit(16);
- }
+ if (chdir("/") == -1)
+ err(16, "chdir()");
/* Open X Display */
- if ((dpy = XOpenDisplay(NULL)) == NULL) {
- fprintf(stderr,"wmnet: doh...can't connect to X server, giving up\n");
- exit(1);
- }
+ if ((dpy = XOpenDisplay(NULL)) == NULL)
+ err(1, "doh...can't connect to X server");
/* assure ourself for a graceful exit */
- if (atexit(exit_func)) {
- fprintf(stderr,"wmnet: atexit() failed\n");
- exit(6);
- }
+ if (atexit(exit_func))
+ err(6, "atexit() failed");
signal_action.sa_handler = got_signal;
sigemptyset(&signal_action.sa_mask);
@@ -347,40 +351,29 @@ void setup_wmnet(int argc, char **argv) {
#endif
if ((sigaction(SIGCHLD, &signal_action, NULL) == -1) ||
(sigaction(SIGINT, &signal_action, NULL) == -1) ||
- (sigaction(SIGTERM, &signal_action, NULL) == -1)) {
- fprintf(stderr,"wmnet: couldn't set signal handler\n");
- exit(8);
- }
-
+ (sigaction(SIGTERM, &signal_action, NULL) == -1))
+ err(8, "couldn't set signal handler");
/* Setup initial foreground color */
if(rxcolorString) {
- if(!XParseColor(dpy, DefaultColormap(dpy, screen), rxcolorString, &thecolor)) {
- fprintf(stderr, "wmnet: what the heck is %s for a color?\n", rxcolorString);
- exit(12);
- }
+ if(!XParseColor(dpy, DefaultColormap(dpy, screen), rxcolorString, &thecolor))
+ err(12, "RX color %s", rxcolorString);
shadesOf(&thecolor, rx_pixel);
}
if(txcolorString) {
- if(!XParseColor(dpy, DefaultColormap(dpy, screen), txcolorString, &thecolor)) {
- fprintf(stderr, "wmnet: what the heck is %s for a color?\n", txcolorString);
- exit(5);
- }
+ if(!XParseColor(dpy, DefaultColormap(dpy, screen), txcolorString, &thecolor))
+ err(5, "TX color %s", txcolorString);
shadesOf(&thecolor, tx_pixel);
}
if(labelfgcolorString) {
- if(!XParseColor(dpy, DefaultColormap(dpy, screen), labelfgcolorString, &thecolor)) {
- fprintf(stderr, "wmnet: what the heck is %s for a color?\n", labelfgcolorString);
- exit(24);
- }
+ if(!XParseColor(dpy, DefaultColormap(dpy, screen), labelfgcolorString, &thecolor))
+ err(24, "foreground label color %s", labelfgcolorString);
XAllocColor(dpy, DefaultColormap(dpy, screen), &thecolor);
labelfg_pixel = thecolor.pixel;
}
if(labelbgcolorString) {
- if(!XParseColor(dpy, DefaultColormap(dpy, screen), labelbgcolorString, &thecolor)) {
- fprintf(stderr, "wmnet: what the heck is %s for a color?\n", labelbgcolorString);
- exit(25);
- }
+ if(!XParseColor(dpy, DefaultColormap(dpy, screen), labelbgcolorString, &thecolor))
+ err(25, "background label color %s", labelbgcolorString);
XAllocColor(dpy, DefaultColormap(dpy, screen), &thecolor);
labelbg_pixel = thecolor.pixel;
}
@@ -393,9 +386,8 @@ void setup_wmnet(int argc, char **argv) {
XSetCommand(dpy, main_window, argv, argc);
/* Get the initial stats for startup */
- stat_gather();
+ stat_gather(&id);
-
/* Rock n Roll */
XMapWindow(dpy, main_window);
@@ -410,14 +402,11 @@ void setupX(void) {
XColor color;
XRectangle bound = { 0, 0, 56, 56 };
-
screen = DefaultScreen(dpy);
delete_atom = XInternAtom(dpy, "WM_DELETE_WINDOW", False);
- if (delete_atom == None) {
- fprintf(stderr,"wmnet: I need WindowMaker running! (or at least some window manager)\n");
- exit(2);
- }
+ if (delete_atom == None)
+ err(2, "test for window manager");
if (XInternAtom(dpy,"_WINDOWMAKER_WM_FUNCTION", True) != None) {
if (specified_state == -1) specified_state = WithdrawnState;
} else {
@@ -436,10 +425,8 @@ void setupX(void) {
grey_pixel = color.pixel;
- if ((arrow = XCreateBitmapFromData(dpy, root_window, arrow_bits, arrow_width, arrow_height)) == None) {
- fprintf(stderr, "wmnet: unable to create arrow bitmap\n");
- exit(11);
- }
+ if ((arrow = XCreateBitmapFromData(dpy, root_window, arrow_bits, arrow_width, arrow_height)) == None)
+ err(11, "unable to create arrow bitmap");
gcv.graphics_exposures = False;
gcv.foreground = tx_pixel[HIGH_INTENSITY];
gcv.background = darkgrey_pixel;
@@ -468,7 +455,6 @@ void setupX(void) {
shints.max_height = 64;
shints.flags = PMinSize | PMaxSize;
XSetWMNormalHints(dpy, main_window, &shints);
-
XStoreName(dpy, main_window, "wmnet");
XShapeCombineRectangles(dpy, *visible_window, ShapeBounding, 4, 4, &bound, 1, ShapeBounding, 0);
@@ -489,8 +475,6 @@ void createWin(Window *win) {
XSetClassHint(dpy, *win, &classHint);
}
-
-
/* Handles Expose events, repaints the window */
void redraw(XExposeEvent *ee) {
static XRectangle cliprect = { 4, 51, 56, 9 };
@@ -498,7 +482,6 @@ void redraw(XExposeEvent *ee) {
/* if (wmaker_present == False) XFillRectangle(dpy, *visible_window, graphics_context, 0, 0, 64, 64); */
XFillRectangle(dpy, *visible_window, graphics_context, GRAPHBOX_X, GRAPHBOX_Y, GRAPHBOX_WIDTH, GRAPHBOX_HEIGHT);
-
XSetForeground(dpy, graphics_context, black_pixel);
XFillRectangle(dpy, *visible_window, graphics_context, TOPBOX_X, TOPBOX_Y, TOPBOX_WIDTH, TOPBOX_HEIGHT);
XDrawLine(dpy, *visible_window, graphics_context, GRAPHBOX_X_LEFT, GRAPHBOX_Y_TOP, GRAPHBOX_X_LEFT, GRAPHBOX_Y_BOTTOM);
@@ -512,19 +495,16 @@ void redraw(XExposeEvent *ee) {
XSetClipMask(dpy, graphics_context, None);
}
-
XSetForeground(dpy, graphics_context, white_pixel);
XDrawLine(dpy, *visible_window, graphics_context, GRAPHBOX_X_RIGHT, GRAPHBOX_Y_BOTTOM, GRAPHBOX_X_RIGHT, (GRAPHBOX_Y_TOP + 1));
XDrawLine(dpy, *visible_window, graphics_context, GRAPHBOX_X_LEFT, GRAPHBOX_Y_BOTTOM, GRAPHBOX_X_RIGHT, GRAPHBOX_Y_BOTTOM);
-
XSetForeground(dpy, graphics_context, grey_pixel);
XSetBackground(dpy, graphics_context, black_pixel);
XCopyPlane(dpy, arrow, *visible_window, graphics_context, 7, 0, 7, 9, 53, 5, 1);
XCopyPlane(dpy, arrow, *visible_window, graphics_context, 0, 0, 7, 9, 46, 5, 1);
}
-
/* Main loop that is called every delaytime. This calls stat_gather() and updateSpeedometer() when needed
* and takes care of the displaying and scrolling the graph */
void tock(void) {
@@ -537,18 +517,14 @@ void tock(void) {
static unsigned long lifo_out[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
static unsigned int t = 0, blank = 0;
- if (gettimeofday(&timenow, NULL)) {
- perror("wmnet: gettimeofday()");
- exit(10);
- }
+ if (gettimeofday(&timenow, NULL))
+ err(10, "gettimeofday()");
since = (timenow.tv_sec * 1000000L + timenow.tv_usec) - (timelast.tv_sec * 1000000L + timelast.tv_usec);
if (since > displayDelay) {
- lifo_in[t] = diffbytes_in * (1000000L / since);
- lifo_out[t] = diffbytes_out * (1000000L / since);
+ lifo_in[t] = id.db_in * (1000000L / since);
+ lifo_out[t] = id.db_out * (1000000L / since);
t = (t + 1) % 8;
-
-
/* in */
rate_rx = (lifo_in[0] + lifo_in[1] + lifo_in[2] + lifo_in[3] + lifo_in[4] + lifo_in[5] + lifo_in[6] + lifo_in[7]) / (unsigned long)8;
if(logscale) percent_rx = (log10( ((rate_rx * 10000/ maxRate) < 1) ? 1 : ((double)rate_rx / (double)maxRate) * 10000.) / 4.);
@@ -563,52 +539,48 @@ void tock(void) {
yy = GRAPH_Y_UPPER + (GRAPH_HEIGHT * percent_tx) ;
yy = yy > GRAPH_Y_BOTTOM ? GRAPH_Y_BOTTOM : yy;
-
/* only update the speedometer every 7th displayDelay */
if (t == 7) updateSpeedometer(rate_rx, rate_tx);
/* blank var is just for stopping executing the X* funcs when the disp is all black */
- if ((y == GRAPH_Y_BOTTOM && yy == GRAPH_Y_UPPER) && (diffbytes_in + diffbytes_out) == 0) blank++; else blank = 0;
+ if ((y == GRAPH_Y_BOTTOM && yy == GRAPH_Y_UPPER) && (id.db_in + id.db_out) == 0) blank++; else blank = 0;
if (blank < (GRAPH_WIDTH + 1) ) {
XCopyArea(dpy, *visible_window, *visible_window, graphics_context, GRAPH_X + 1,
GRAPH_Y, GRAPH_WIDTH - 1, GRAPH_HEIGHT, GRAPH_X, GRAPH_Y);
XSetForeground(dpy, graphics_context, darkgrey_pixel);
XDrawLine(dpy, *visible_window, graphics_context, GRAPH_X_RIGHT, y, GRAPH_X_RIGHT, yy);
- if (( (yy == GRAPH_Y_UPPER && diffbytes_out > 0 && rate_rx > rate_tx) || (rate_rx >= rate_tx && yy != GRAPH_Y_UPPER)) ) {
+ if (( (yy == GRAPH_Y_UPPER && id.db_out > 0 && rate_rx > rate_tx) || (rate_rx >= rate_tx && yy != GRAPH_Y_UPPER)) ) {
drawColoredLine(GRAPH_Y_UPPER, yy, tx_pixel);
}
- if ( y != GRAPH_Y_BOTTOM || diffbytes_in > 0) {
+ if ( y != GRAPH_Y_BOTTOM || id.db_in > 0) {
drawColoredLine(GRAPH_Y_BOTTOM, y, rx_pixel);
}
- if (( (yy == GRAPH_Y_UPPER && diffbytes_out > 0) || (rate_rx < rate_tx && yy != GRAPH_Y_UPPER)) ) {
+ if (( (yy == GRAPH_Y_UPPER && id.db_out > 0) || (rate_rx < rate_tx && yy != GRAPH_Y_UPPER)) ) {
drawColoredLine(GRAPH_Y_UPPER, yy, tx_pixel);
}
}
-
- diffbytes_in = diffbytes_out = 0;
+ id.db_in = id.db_out = 0;
timelast = timenow;
}
- if (!stat_gather()) { /* Anything change? */
- current_rx = rx;
- current_tx = tx;
+ if (!stat_gather(&id)) { /* Anything change? */
+ id.current_rx = id.rx;
+ id.current_tx = id.tx;
XSetBackground(dpy, graphics_context, black_pixel);
- if(current_tx == True) {
+ if(id.current_tx == True) {
XSetForeground(dpy, graphics_context, tx_pixel[HIGH_INTENSITY]);
XCopyPlane(dpy, arrow, *visible_window, graphics_context, 7, 0, 7, 9, 53, 5, 1);
/* XFillRectangle(dpy, *visible_window, graphics_context, 55, 5, 4, 4); */
- }
- else {
+ } else {
XSetForeground(dpy, graphics_context, grey_pixel);
XCopyPlane(dpy, arrow, *visible_window, graphics_context, 7, 0, 7, 9, 53, 5, 1);
}
- if(current_rx == True) {
+ if(id.current_rx == True) {
XSetForeground(dpy, graphics_context, rx_pixel[HIGH_INTENSITY]);
XCopyPlane(dpy, arrow, *visible_window, graphics_context, 0, 0, 7, 9, 46, 5, 1);
/* XFillRectangle(dpy, *visible_window, graphics_context, 55, 12, 4, 4); */
- }
- else {
+ } else {
XSetForeground(dpy, graphics_context, grey_pixel);
XCopyPlane(dpy, arrow, *visible_window, graphics_context, 0, 0, 7, 9, 46, 5, 1);
}
@@ -634,8 +606,6 @@ int updateSpeedometer(int rxRate, int txRate) {
}
collectandreturn = True;
-
-
if (txRate > rxRate) {
rate = (txRate + txRate_last) / 2000.;
color = tx_pixel[HIGH_INTENSITY];
@@ -644,7 +614,6 @@ int updateSpeedometer(int rxRate, int txRate) {
color = rx_pixel[HIGH_INTENSITY];
}
-
if (!clear) {
XSetForeground(dpy, graphics_context, black_pixel);
XFillRectangle(dpy, *visible_window, graphics_context, 4, 5, 37, 9);
@@ -675,7 +644,6 @@ int updateSpeedometer(int rxRate, int txRate) {
}
-
/* called from within tock to draw the shaded lines making up our bar-graph */
void drawColoredLine(int y1, int y2, unsigned long *shadecolor) {
int subline[4], i;
@@ -709,15 +677,14 @@ void shadesOf(XColor *shade, unsigned long *returnarra
XAllocColor(dpy, DefaultColormap(dpy, screen), shade);
returnarray[LOW_INTENSITY] = shade->pixel;
}
-
/* Here is main, clear at the bottom. Handles the event loop and calls tock() every delayTime milliseconds */
int main(int argc, char ** argv) {
unsigned int done = False;
XEvent event;
-
+
setup_wmnet(argc, argv);
-
+
while(!done) {
while(XPending(dpy)) {
XNextEvent(dpy, &event);
@@ -732,9 +699,8 @@ int main(int argc, char ** argv) {
case ButtonPress:
if(event.xbutton.button == Button1 && click_command != NULL) {
if (fork() == 0) {
- execl("/bin/sh", "sh", "-c", click_command, NULL);
- perror("wmnet: execl()");
- exit(15);
+ execl("/bin/sh", "sh", "-c", click_command, (void *)NULL);
+ err(15, "execl(/bin/sh)");
}
}
break;
@@ -747,4 +713,3 @@ int main(int argc, char ** argv) {
}
return 0;
}
-

View File

@ -1,82 +0,0 @@
$OpenBSD: patch-wmnet_h,v 1.3 2015/12/07 18:00:42 jasper Exp $
--- wmnet.h.orig Fri May 5 03:02:26 2000
+++ wmnet.h Mon Dec 7 18:35:01 2015
@@ -12,6 +12,8 @@
*
*/
+#ifndef WMNET_H__
+#define WMNET_H__
#define TOPBOX_X 4
#define TOPBOX_Y 4
@@ -40,7 +42,6 @@
#define GRAPH_Y_UPPER (GRAPH_Y)
#define GRAPH_Y_BOTTOM (GRAPH_Y + GRAPH_HEIGHT - 1)
-
/* Label area box */
#define LABEL_X (GRAPHBOX_X_LEFT)
#define LABEL_Y (GRAPHBOX_Y_BOTTOM + 1)
@@ -52,40 +53,31 @@
#define LABEL_Y_TOP (LABEL_Y)
#define LABEL_Y_BOTTOM (LABEL_Y + LABEL_HEIGHT - 1)
-
#define LOW_INTENSITY 0
#define NORMAL_INTENSITY 1
#define HIGH_INTENSITY 2
+struct if_data_t {
+ char *device;
+ Bool rx;
+ Bool tx;
+ Bool current_rx;
+ Bool current_tx;
+ unsigned int db_in;
+ unsigned int db_out;
+};
+typedef int (*parser_func)(struct if_data_t *);
+typedef void (*setup_func)(char *, struct if_data_t *);
+setup_func setup_driver(char *, struct if_data_t *);
+char *available_drivers(void);
-/* X Stuff */
-Display *dpy;
-Window root_window, main_window, icon_window, *visible_window;
-Font thefont;
-Pixmap arrow;
-Atom delete_atom;
-int screen, specified_state = -1;
-GC graphics_context;
-unsigned long tx_pixel[3], rx_pixel[3], labelfg_pixel, labelbg_pixel, black_pixel, white_pixel, darkgrey_pixel, grey_pixel;
-typedef int (*parser_func)(void);
-
-/* I know statically declared buffers are against GNU coding standards, so sue me */
-char buffer[256], *click_command = NULL, *label = NULL;
-struct timeval timenow, timelast;
unsigned long totalbytes_in, totalbytes_out, lastbytes_in, lastbytes_out;
unsigned long totalpackets_in, totalpackets_out, lastpackets_in, lastpackets_out;
unsigned int diffpackets_in, diffpackets_out, diffbytes_in, diffbytes_out;
-unsigned int delayTime = 25000, displayDelay = 55000, maxRate = 6000;
-unsigned int out_rule = 2, in_rule = 1, graphbox_height = 44; /* number of rule in /proc/net/ip_acct to use */
-char *in_rule_string = NULL, *out_rule_string = NULL, *device=NULL;
-Bool current_tx = False, current_rx = False, rx, tx, logscale = False;
-parser_func stat_gather;
-
-
void exit_func(void);
void got_signal(int x);
void setup_wmnet(int argc, char **argv);
@@ -98,6 +90,4 @@ int updateSpeedometer(int rxRate, int txRate);
void drawColoredLine(int y1, int y2, unsigned long *shadecolor);
void shadesOf(XColor *shade, unsigned long *returnarray);
-extern parser_func setup_driver(char *parser);
-extern char * available_drivers(void);
-
+#endif /* WMNET_H__ */

View File

@ -1,11 +0,0 @@
WMnet polls network statistics and does a few things with the data it gets.
It has small blinking lights for the rx and tx of IP packets, a digital
speedometer of your polled stat's current speed and a bar graph like xload
et. al which has a tx speed graph from bottom-up and rx speed graph from
the top-down.
The speedometer keeps track of the current speed per second and shows it
in a color corresponding to which of rx or tx that has the highest speed
at the moment. Also, the graph is drawn in a way that the highest speed
is drawn on top of the other while the other is in the background.

View File

@ -1,7 +0,0 @@
@comment $OpenBSD: PLIST,v 1.4 2013/10/11 20:39:41 naddy Exp $
@mode 2555
@group kmem
@bin bin/wmnet
@mode
@group
@man man/man1/wmnet.1