2011-03-25 18:45:13 +00:00
|
|
|
/* wmnet -- X IP accounting monitor
|
|
|
|
* Copyright 1998, 2000 Jesse B. Off, Katharine Osborne
|
2014-10-05 15:29:59 +00:00
|
|
|
* <kaos@digitalkaos.net>
|
2011-03-25 18:45:13 +00:00
|
|
|
*
|
|
|
|
* $Id: wmnet.h,v 1.2 1998/10/06 00:06:12 joff Exp $
|
2014-10-05 15:29:59 +00:00
|
|
|
*
|
2011-03-25 18:45:13 +00:00
|
|
|
* This software is released under the GNU Public License agreement.
|
|
|
|
* No warranties, whatever.... you know the usuals.... this is free
|
|
|
|
* software. if you use it, great... if you wanna make a change to it,
|
|
|
|
* great, but please send me the diff. If you put it on a distributed
|
|
|
|
* CD, great... I'd appreciate a copy of the CD though ;).
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#define TOPBOX_X 4
|
|
|
|
#define TOPBOX_Y 4
|
2014-10-05 15:29:59 +00:00
|
|
|
#define TOPBOX_WIDTH 56
|
|
|
|
#define TOPBOX_HEIGHT 11
|
2011-03-25 18:45:13 +00:00
|
|
|
|
|
|
|
/* Graphing area extents */
|
|
|
|
#define GRAPHBOX_X 4
|
2014-10-05 15:29:59 +00:00
|
|
|
#define GRAPHBOX_Y 15
|
2011-03-25 18:45:13 +00:00
|
|
|
#define GRAPHBOX_WIDTH 56
|
|
|
|
#define GRAPHBOX_HEIGHT graphbox_height
|
|
|
|
|
|
|
|
#define GRAPHBOX_X_RIGHT (GRAPHBOX_X + GRAPHBOX_WIDTH - 1)
|
|
|
|
#define GRAPHBOX_X_LEFT (GRAPHBOX_X)
|
|
|
|
#define GRAPHBOX_Y_TOP (GRAPHBOX_Y)
|
|
|
|
#define GRAPHBOX_Y_BOTTOM (GRAPHBOX_Y + GRAPHBOX_HEIGHT - 1)
|
|
|
|
|
|
|
|
/* Graphing area minus the borders */
|
|
|
|
#define GRAPH_X (GRAPHBOX_X + 1)
|
|
|
|
#define GRAPH_Y (GRAPHBOX_Y)
|
|
|
|
#define GRAPH_WIDTH (GRAPHBOX_WIDTH - 2)
|
|
|
|
#define GRAPH_HEIGHT (GRAPHBOX_HEIGHT - 1)
|
|
|
|
|
|
|
|
#define GRAPH_X_LEFT (GRAPH_X)
|
|
|
|
#define GRAPH_X_RIGHT (GRAPH_X + GRAPH_WIDTH - 1)
|
2014-10-05 15:29:59 +00:00
|
|
|
#define GRAPH_Y_UPPER (GRAPH_Y)
|
2011-03-25 18:45:13 +00:00
|
|
|
#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)
|
|
|
|
#define LABEL_WIDTH (GRAPHBOX_WIDTH)
|
|
|
|
#define LABEL_HEIGHT 11
|
|
|
|
|
|
|
|
#define LABEL_X_LEFT (LABEL_X_LEFT)
|
|
|
|
#define LABEL_X_RIGHT (LABEL_X_LEFT + LABEL_WIDTH - 1)
|
|
|
|
#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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* 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;
|
wmnet: Cope with interface name longer than 6 characters
After a recent change in the kernel (their commit 6e094bd) my
wireless interface name is 8 characters long, wlp3s0b1. But
the wmnet code to read the received bytes
totalbytes_in = strtoul(&buffer[7], NULL, 10);
assumed that the interface name in /proc/net/dev would be 6 characters
long (and would start reading at position 7).
In the linux kernel mailing list I reported the regression and none
other than Al Viro replied,
> I am not sure if 'wmnet' could do this better (any suggestions?),
*snort*
well, yes - it's called scanf(). And if one is really, really nervous
about the overhead of <gasp> parsing a bunch of integers (as if fopen/
fgets/fclose alone won't cost enough to make constantly calling that
sucker a bad idea), just use ptr + <something> - 6 instead of
&buffer[<something>] in there. That thing has just found where the
colon was (and replaced it with NUL), so dealing with "the first field
turned out to be too long and shifted everything past it" isn't hard.
******
I also took the oportunity to remove the unused variables diffpackets_{in,out}
2015-01-11 12:20:02 +00:00
|
|
|
unsigned long long int totalbytes_in, totalbytes_out, lastbytes_in, lastbytes_out;
|
|
|
|
unsigned long long int totalpackets_in, totalpackets_out, lastpackets_in, lastpackets_out;
|
|
|
|
unsigned int diffbytes_in, diffbytes_out;
|
2015-01-11 21:31:40 +00:00
|
|
|
unsigned int delayTime = 100000, displayDelay = 55000, maxRate = 120000;
|
2011-03-25 18:45:13 +00:00
|
|
|
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;
|
2014-10-05 15:29:59 +00:00
|
|
|
|
2011-03-25 18:45:13 +00:00
|
|
|
|
|
|
|
|
|
|
|
void exit_func(void);
|
2014-10-05 15:29:59 +00:00
|
|
|
void got_signal(int x);
|
2011-03-25 18:45:13 +00:00
|
|
|
void setup_wmnet(int argc, char **argv);
|
|
|
|
void setupX(void);
|
|
|
|
void createWin(Window *win);
|
2014-10-05 15:29:59 +00:00
|
|
|
int updateStats(void);
|
|
|
|
void redraw(XExposeEvent *ee);
|
2011-03-25 18:45:13 +00:00
|
|
|
void tock(void);
|
|
|
|
int updateSpeedometer(int rxRate, int txRate);
|
2014-10-05 15:29:59 +00:00
|
|
|
void drawColoredLine(int y1, int y2, unsigned long *shadecolor);
|
2011-03-25 18:45:13 +00:00
|
|
|
void shadesOf(XColor *shade, unsigned long *returnarray);
|
|
|
|
|
|
|
|
extern parser_func setup_driver(char *parser);
|
|
|
|
extern char * available_drivers(void);
|
|
|
|
|