wmcore: use pkg-config in Makefile.
[dockapps.git] / wmppp.app / wmppp.c
blob3df8cb95def590afefecff5a12c45f02e629102e
1 /*
2 Best viewed with vim5, using ts=4
4 This code was mainly put together by looking at the
5 following programs:
7 asclock
8 A neat piece of equip, used to display the date
9 and time on the screen.
10 Comes with every WindowMaker installation.
12 Source used:
13 How do I create a not so solid window?
14 How do I open a window?
15 How do I use pixmaps?
17 pppstats
18 A program that prints the amount of data that
19 is transferred over a ppp-line.
21 Source used:
22 How do I read the ppp device?
23 ------------------------------------------------------------
25 Authors: Martijn Pieterse (pieterse@xs4all.nl)
26 Antoine Nulle (warp@xs4all.nl)
28 This program might be Y2K resistant. We shall see. :)
30 This program is distributed under the GPL license.
31 (as were asclock and pppstats)
33 Known Features: (or in non M$ talk, BUGS)
34 * none known so far in this release
36 ----
37 Thanks
38 ----
40 CCC (Constructive Code Criticism):
42 Marcelo E. Magallon
43 Thanks a LOT! It takes a while to get me convinced... :)
46 Minor bugs and ideas:
48 Marc De Scheemaecker / David Mihm / Chris Soghoian /
49 Alessandro Usseglio Viretta
51 and ofcourse numerous ppl who send us bug reports.
52 (numerous? hmm.. todo: rephrase this :) )
53 Make that numerous m8ey :)
55 ----
56 Changes:
57 ---
58 05/09/1998 (Martijn Pieterse, pieterse@xs4all.nl)
59 * Added:
60 Speed-O-Meter (after 60 seconds)
61 Fixed Error reporting when pressing X
62 Removed the ugly kb lines
63 Stopped clearing on-line time when pressing X
64 Added createXBMfromXPM
65 08/05/1998 (Martijn Pieterse, pieterse@xs4all.nl)
66 * Removed some code from get_statistics
67 * Check if "ifdown" is empty before execCommanding it!
68 07/05/1998 (Martijn Pieterse, pieterse@xs4all.nl)
69 * Made the program use the xpm like warp wanted it to be :)
70 04/05/1998 (Martijn Pieterse, pieterse@xs4all.nl)
71 * Added pppX support. (EXPERIMENTAL!)
72 Removed HARD_CODED_DEV. (that stayed in long! :) )
73 * Changed 33600 speed indication to 33k6
74 Bugs if larger than 115k2 (depends on how much 1's present)
75 Moved the speed ind. code to DrawSpeedInd
76 * Added 1k lines in the stats
77 * Moved all the "ppp0" references into HARD_CODED_DEV.
78 for easy change
79 03/05/1998 (Martijn Pieterse, pieterse@xs4all.nl)
80 * Removed the number after -t.
81 02/05/1998 (Martijn Pieterse, pieterse@xs4all.nl)
82 * Removed the heyho code :)
83 * Changed read_rc_file to parse_rcfile. suggested bt Marcelo E. Magallon
84 * Added some extra checks for the -t option.
85 If no number was given, it would core dump
86 30/04/1998 (Martijn Pieterse, pieterse@xs4all.nl)
87 * Added execCommand code. (taken from windowmaker soure, as advised by Marcelo E. Magallon)
88 * Cleaned the source up a bit
89 * Decided to split op wmppp and wmifs
90 This is gonna be wmppp
91 * Used the DrawStats routine from wmifs in wmppp
92 * I decided to add a list in this source file
93 with name of ppl who helped me build this code better.
94 * I finally removed the /proc/net/route dependency
95 All of the connections are taken from /proc/net/dev.
96 /proc/net/route is still used for checking if it is on-line.
97 27/04/1998 (Martijn Pieterse, pieterse@xs4all.nl)
98 * WMIFS: stats scrolled, while red led burning
99 * WMPPP: changed positions of line speed
100 25/04/1998 (Martijn Pieterse, pieterse@xs4all.nl)
101 * Changed the checknetdevs routine, a lot!
102 23/04/1998 (Martijn Pieterse, pieterse@xs4all.nl)
103 * Added line speed detection. via separate exec. (this has to be suid root!)
104 Speed has to be no more than 99999
105 * Added speed and forcespeed in ~/.wmppprc and /etc/wmppprc
106 * wmifs: added on-line detection scheme, update the bitmap coordinates
107 * wmppp: the x-button now allways disconnects.
108 22/04/1998 (Martijn Pieterse, pieterse@xs4all.nl)
109 * Added /etc/wmppprc support, including "forced" mode.
110 * Added /etc/wmifsrc support, including "forced" mode.
111 21/04/1998 (Martijn Pieterse, pieterse@xs4all.nl)
112 * Moved the stats one pixel down.
113 * Added status led in wmifs.
114 * Changed RX/TX leds of wmifs to resemble wmppp
115 * Added the "dot" between eth.0 ppp.0 etc.
116 * Changed to wmifs stats to match wmppp stats (only pppX changed)
117 * Made sure that when specified -t 1, it stayed that way, even
118 when longer than 100 minutes online
119 * With -t 1, jump from 59:59 to 01:00 instead of 99:59 to 01:40
120 16/04/1998 (Martijn Pieterse, pieterse@xs4all.nl)
121 * Added "all" devices in wmifs
122 * Added "lo" support only if aked via -i
123 * Added on-line time detection (using /var/run/ppp0.pid)
124 * Added time-out for the orange led. (one minute)
125 15/04/1998 (Martijn Pieterse, pieterse@xs4all.nl)
126 * Another wmppp-master.xpm.
127 Line speed detection being the main problem here.. :(
128 * Moved START_COMMAND / STOP_COMMAND to ~/.wmppprc
129 Return 0, everything went ok.
130 Return 10, the command did not work.
131 Please note, these functions are ran in the background.
132 * Removed the ability to configure
133 * When "v" is clicked, an orange led will appear.
134 if the connect script fails (return value == 10)
135 it will become dark again. Else the on-line detection will
136 pick it up, and "green" it.
137 14/04/1998 (Martijn Pieterse, pieterse@xs4all.nl)
138 * Added "-timer"
139 * Added "-display" support
140 * Changed pixmap to a no-name pixmap.
141 + Changed LED positions
142 + Changed Timer position
143 + Changed Stats Size
144 05/04/1998 (Martijn Pieterse, pieterse@xs4all.nl)
145 * Added ~/.wmifsrc support.
146 * Put some code in DrawStats
147 * Check devices when pressing "device change"
148 03/04/1998 (Martijn Pieterse, pieterse@xs4all.nl)
149 * Added code for wmifs
150 28/03/1998 (Martijn Pieterse, pieterse@xs4all.nl)
151 * forgot what i did.. :)
152 27/03/1998 (Martijn Pieterse, pieterse@xs4all.nl)
153 * Added on-line detection
154 Scan through /proc/net/route and check everye line
155 for "ppp".
156 * A bit of code clean-up.
159 #include <X11/X.h> /* for ButtonPress, ButtonRelease, etc */
160 #include <X11/Xlib.h> /* for XEvent, XButtonEvent, etc */
161 #include <sys/socket.h> /* for SOCK_DGRAM */
162 #include <linux/ppp_defs.h> /* for ppp_stats, pppstat */
163 #include <net/if_ppp.h> /* for ifpppstatsreq, etc */
164 #include <signal.h> /* for signal */
165 #include <stdio.h> /* for fprintf, stderr, NULL, etc */
166 #include <stdlib.h> /* for exit, atoi, getenv, etc */
167 #include <string.h> /* for strcpy, memset, strcmp, etc */
168 #include <sys/ioctl.h> /* for ioctl */
169 #include <sys/socket.h> /* for socket, AF_INET */
170 #include <sys/stat.h> /* for stat, st_mtime */
171 #include <sys/types.h> /* for pid_t */
172 #include <sys/wait.h> /* for waitpid, WNOHANG */
173 #include <time.h> /* for timespec, nanosleep, time */
174 #include <libdockapp/misc.h> /* for execCommand */
175 #include <libdockapp/wmgeneral.h> /* for copyXPMArea, RedrawWindow, etc */
176 #include "wmppp-master.xpm" /* for wmppp_master_xpm */
178 /***********/
179 /* Defines */
180 /***********/
182 /* Fill in and uncomment the hardcoded actions. */
183 /* #define START_ACTION (NULL) */
184 /* #define STOP_ACTION (NULL) */
185 /* #define SPEED_ACTION (NULL) */
186 /* #define IFDOWN_ACTION (NULL) */
188 #define STAMP_FILE_PRE "/var/run/wmppp."
190 /* Defines voor alle coordinate */
192 #define LED_PPP_RX (1)
193 #define LED_PPP_TX (2)
194 #define LED_PPP_POWER (3)
196 #define BUT_V (1)
197 #define BUT_X (2)
199 #define TIMER_X (9)
200 #define TIMER_Y (14)
202 #define TIMER_SRC_Y (65)
203 #define TIMER_DES_Y (6)
204 #define TIMER_SZE_X (6)
206 #define WMPPP_VERSION "1.3.2"
208 #define ORANGE_LED_TIMEOUT (60)
210 /**********************/
211 /* External Variables */
212 /**********************/
214 extern char **environ;
216 /********************/
217 /* Global Variables */
218 /********************/
220 char *ProgName;
221 char *active_interface = "ppp0";
222 int TimerDivisor=60;
223 int updaterate = 5;
225 int wmppp_mask_width = 64;
226 int wmppp_mask_height = 64;
227 char wmppp_mask_bits[64*64];
230 /*****************/
231 /* PPP variables */
232 /*****************/
234 #define PPP_UNIT 0
235 int ppp_h = -1;
237 #define PPP_STATS_HIS 54
239 int pixels_per_byte;
241 int ppp_history[PPP_STATS_HIS+1][2];
243 /***********************/
244 /* Function Prototypes */
245 /***********************/
247 void usage(void);
248 void printversion(void);
249 void DrawTime(int, int);
250 void DrawStats(int *, int, int, int, int);
251 void DrawSpeedInd(char *);
252 void DrawLoadInd(int);
254 void SetOnLED(int);
255 void SetErrLED(int);
256 void SetWaitLED(int);
257 void SetOffLED(int);
259 void ButtonUp(int);
260 void ButtonDown(int);
262 int get_statistics(long *, long *, long *, long *);
263 void get_ppp_stats(struct ppp_stats *cur);
264 int stillonline(char *);
265 void reread(int);
267 char *start_action = NULL;
268 char *stop_action = NULL;
269 char *speed_action = NULL;
270 char *ifdown_action = NULL;
271 char *stamp_file = NULL;
273 char *start_action_cmdline = NULL;
274 char *stop_action_cmdline = NULL;
275 char *speed_action_cmdline = NULL;
276 char *ifdown_action_cmdline = NULL;
277 char *stamp_file_cmdline = NULL;
279 /**********************/
280 /* Parse Command Line */
281 /**********************/
283 int parse_cmdline(int argc, char *argv[]) {
285 int i;
287 ProgName = argv[0];
288 if (strlen(ProgName) >= 5)
289 ProgName += (strlen(ProgName) - 5);
291 for (i=1; i<argc; i++) {
292 char *arg = argv[i];
294 if (*arg=='-') {
295 switch (arg[1]) {
296 case 'd' :
297 if (strcmp(arg+1, "display")) {
298 usage();
299 exit(1);
301 break;
302 case 'g' :
303 if (strcmp(arg+1, "geometry")) {
304 usage();
305 exit(1);
307 break;
308 case 'i' :
309 if (!strcmp(arg+1, "i"))
310 active_interface = argv[++i];
311 else if (!strcmp(arg+1, "ifdown"))
312 ifdown_action_cmdline = argv[++i];
313 else {
314 usage();
315 exit(1);
317 break;
318 case 's' :
319 if (!strcmp(arg+1, "speed"))
320 speed_action_cmdline = argv[++i];
321 else if (!strcmp(arg+1, "start"))
322 start_action_cmdline = argv[++i];
323 else if (!strcmp(arg+1, "stop"))
324 stop_action_cmdline = argv[++i];
325 else if (!strcmp(arg+1, "stampfile"))
326 stamp_file_cmdline = argv[++i];
327 else {
328 usage();
329 exit(1);
331 break;
332 case 't' :
333 TimerDivisor = 1;
334 break;
335 case 'u' :
336 i++;
337 if (!argv[i]) {
338 usage();
339 exit(1);
341 updaterate = atoi(argv[i]);
342 if (updaterate < 1 || updaterate > 10) {
343 usage();
344 exit(1);
346 break;
347 case 'v' :
348 printversion();
349 exit(0);
350 break;
351 default:
352 usage();
353 exit(0);
354 break;
359 return 0;
362 /**********/
363 /* reread */
364 /**********/
366 void reread(int signal) {
367 char *p;
368 char temp[128];
370 rckeys wmppp_keys[] = {
371 { "start", &start_action },
372 { "stop", &stop_action },
373 { "speed", &speed_action },
374 { "ifdown", &ifdown_action },
375 { "stampfile", &stamp_file },
376 { NULL, NULL }
379 strcpy(temp, "/etc/wmppprc");
380 parse_rcfile(temp, wmppp_keys);
382 p = getenv("HOME");
383 if (p == NULL) {
384 fprintf(stderr,
385 "error: HOME environment variable not defined\n");
386 exit(EXIT_FAILURE);
388 strcpy(temp, p);
389 strcat(temp, "/.wmppprc");
390 parse_rcfile(temp, wmppp_keys);
392 strcpy(temp, "/etc/wmppprc.fixed");
393 parse_rcfile(temp, wmppp_keys);
395 /* command line options take precedence */
396 if (start_action_cmdline)
397 strcpy(start_action, start_action_cmdline);
398 if (stop_action_cmdline)
399 strcpy(stop_action, stop_action_cmdline);
400 if (speed_action_cmdline)
401 strcpy(speed_action, speed_action_cmdline);
402 if (ifdown_action_cmdline)
403 strcpy(ifdown_action, ifdown_action_cmdline);
404 if (stamp_file_cmdline)
405 strcpy(stamp_file, stamp_file_cmdline);
409 /********/
410 /* Main */
411 /********/
413 int main(int argc, char **argv) {
415 int j;
417 int but_stat;
419 long starttime;
420 long currenttime;
421 long waittime;
422 long ppptime;
423 int hour,minute;
425 long ppp_send,ppp_sl=-1;
426 long ppp_recv,ppp_rl=-1;
427 long ppp_sbytes,ppp_rbytes;
428 long ppp_osbytes,ppp_orbytes;
430 struct stat st;
432 pid_t stop_child = 0;
433 pid_t start_child = 0;
434 int status;
436 XEvent Event;
438 char temp[128];
440 int speed_ind=60;
442 /* Initialize some stuff */
444 get_statistics(&ppp_rl, &ppp_sl, &ppp_orbytes, &ppp_osbytes);
446 /* Scan through ~/.wmifsrc for the mouse button actions. */
447 #ifdef START_ACTION
448 start_action = strdup(START_ACTION);
449 #endif
450 #ifdef STOP_ACTION
451 stop_action = strdup(STOP_ACTION);
452 #endif
453 #ifdef SPEED_ACTION
454 speed_action = strdup(SPEED_ACTION);
455 #endif
456 #ifdef IFDOWN_ACTION
457 ifdown_action = strdup(IFDOWN_ACTION);
458 #endif
459 #ifdef STAMP_FILE_PRE
460 sprintf (temp, "%s%s", STAMP_FILE_PRE, active_interface);
461 stamp_file = strdup (temp);
462 #endif
464 reread(0);
465 parse_cmdline(argc, argv);
466 signal(SIGHUP, reread);
468 /* Open the display */
470 createXBMfromXPM(wmppp_mask_bits, wmppp_master_xpm, wmppp_mask_width, wmppp_mask_height);
472 openXwindow(argc, argv, wmppp_master_xpm, wmppp_mask_bits, wmppp_mask_width, wmppp_mask_height);
474 /* V Button */
475 AddMouseRegion(0, 35, 48, 46, 58);
476 /* x Button */
477 AddMouseRegion(1, 47, 48, 58, 58);
479 starttime = 0;
480 currenttime = time(0);
481 ppptime = 0;
482 but_stat = -1;
483 waittime = 0;
484 copyXPMArea(28, 95, 25, 11, 5, 48);
486 /* wmppp main loop */
487 while (1) {
488 int i;
489 long lasttime;
490 struct timespec ts;
492 lasttime = currenttime;
493 currenttime = time(0);
494 /* Check if any child has left the playground */
495 i = waitpid(0, &status, WNOHANG);
496 if (i == stop_child && stop_child != 0) {
498 starttime = 0;
499 SetOffLED(LED_PPP_POWER);
500 SetOffLED(LED_PPP_RX);
501 SetOffLED(LED_PPP_TX);
502 copyXPMArea(28, 95, 25, 11, 5, 48);
504 RedrawWindow();
506 stop_child = 0;
508 if (i == start_child && start_child != 0) {
509 if (WIFEXITED(status)) {
510 if (WEXITSTATUS(status) == 10) {
512 starttime = 0;
513 copyXPMArea(28, 95, 25, 11, 5, 48);
514 SetOffLED(LED_PPP_POWER);
515 DrawTime(0, 1);
516 RedrawWindow();
518 start_child = 0;
522 /* On-line detectie! 1x per second */
524 if (currenttime != lasttime) {
525 i = 0;
527 if (stillonline(active_interface)) {
528 i = 1;
529 if (!starttime) {
530 starttime = currenttime;
532 if (stat(stamp_file, &st) == 0)
533 starttime = st.st_mtime;
535 SetOnLED(LED_PPP_POWER);
536 waittime = 0;
538 copyXPMArea(28, 95, 25, 11, 5, 48);
540 if (speed_action)
541 DrawSpeedInd(speed_action);
543 speed_ind = currenttime + 60;
545 RedrawWindow();
548 if (!i && starttime) {
549 starttime = 0;
550 SetErrLED(LED_PPP_POWER);
552 copyXPMArea(0, 95, 26, 11, 5, 48);
554 if (ifdown_action)
555 execCommand(ifdown_action);
557 RedrawWindow();
561 if (waittime && waittime <= currenttime) {
562 SetOffLED(LED_PPP_POWER);
563 RedrawWindow();
564 waittime = 0;
567 /* If we are on-line. Print the time we are */
568 if (starttime) {
569 i = currenttime - starttime;
571 i /= TimerDivisor;
573 if (TimerDivisor == 1)
574 if (i > 59 * 60 + 59) i /= 60;
576 minute = i % 60;
577 hour = (i / 60) % 100;
578 i = hour * 100 + minute;
580 DrawTime(i, currenttime % 2);
581 /* We are online, so we can check for send/recv packets */
583 get_statistics(&ppp_recv, &ppp_send, &ppp_rbytes, &ppp_sbytes);
585 if (ppp_send != ppp_sl) SetOnLED(LED_PPP_TX);
586 else SetOffLED(LED_PPP_TX);
588 if (ppp_recv != ppp_rl) SetOnLED(LED_PPP_RX);
589 else SetOffLED(LED_PPP_RX);
591 ppp_sl = ppp_send;
592 ppp_rl = ppp_recv;
594 /* Every five seconds we check to load on the line */
596 if ((currenttime - ppptime >= 0) || (ppptime == 0)) {
598 ppptime = currenttime + updaterate;
600 ppp_history[PPP_STATS_HIS][0] = ppp_rbytes - ppp_orbytes;
601 ppp_history[PPP_STATS_HIS][1] = ppp_sbytes - ppp_osbytes;
603 ppp_orbytes = ppp_rbytes;
604 ppp_osbytes = ppp_sbytes;
606 DrawStats(&ppp_history[0][0], 54, 25, 5, 43);
608 for (j=1; j<55; j++) {
609 ppp_history[j-1][0] = ppp_history[j][0];
610 ppp_history[j-1][1] = ppp_history[j][1];
612 if (currenttime > speed_ind) {
613 DrawLoadInd((ppp_history[54][0] + ppp_history[54][1]) / updaterate);
617 RedrawWindow();
621 while (XPending(display)) {
622 XNextEvent(display, &Event);
623 switch (Event.type) {
624 case Expose:
625 RedrawWindow();
626 break;
627 case DestroyNotify:
628 XCloseDisplay(display);
629 while (start_child | stop_child) {
630 i = waitpid(0, &status, WNOHANG);
631 if (i == stop_child) stop_child = 0;
632 if (i == start_child) start_child = 0;
633 ts.tv_sec = 0;
634 ts.tv_nsec = 50000000L;
635 nanosleep(&ts, NULL);
637 exit(0);
638 break;
639 case ButtonPress:
640 i = CheckMouseRegion(Event.xbutton.x, Event.xbutton.y);
641 switch (i) {
642 case 0:
643 ButtonDown(BUT_V);
644 break;
645 case 1:
646 ButtonDown(BUT_X);
647 break;
649 but_stat = i;
651 RedrawWindow();
652 break;
653 case ButtonRelease:
654 i = CheckMouseRegion(Event.xbutton.x, Event.xbutton.y);
655 /* Button but_stat omhoogdoen! */
656 switch (but_stat) {
657 case 0:
658 ButtonUp(BUT_V);
659 break;
660 case 1:
661 ButtonUp(BUT_X);
662 break;
665 if (i == but_stat && but_stat >= 0) {
666 switch (i) {
667 case 0:
668 if (!starttime) {
669 /* Reread the rcfiles. */
670 reread(0);
671 copyXPMArea(28, 95, 25, 11, 5, 48);
672 DrawTime(0, 1);
673 if (start_action)
674 start_child = execCommand(start_action);
675 SetWaitLED(LED_PPP_POWER);
676 waittime = ORANGE_LED_TIMEOUT + currenttime;
679 break;
680 case 1:
681 if (stop_child == 0) {
682 if (stop_action)
683 stop_child = execCommand(stop_action);
685 break;
688 RedrawWindow();
690 but_stat = -1;
691 break;
692 default:
693 break;
696 ts.tv_sec = 0;
697 ts.tv_nsec = 50000000L;
698 nanosleep(&ts, NULL);
700 return 0;
703 /*******************************************************************************\
704 |* get_statistics *|
705 \*******************************************************************************/
707 int get_statistics(long *ip, long *op, long *is, long *os) {
709 struct ppp_stats ppp_cur;
710 static int ppp_opened = 0;
713 if (!ppp_opened) {
714 /* Open the ppp device. */
715 memset(&ppp_cur, 0, sizeof(ppp_cur));
716 if ((ppp_h = socket(AF_INET, SOCK_DGRAM, 0)) < 0)
717 return -1;
718 ppp_opened = 1;
721 get_ppp_stats(&ppp_cur);
723 *op = ppp_cur.p.ppp_opackets;
724 *ip = ppp_cur.p.ppp_ipackets;
726 *is = ppp_cur.p.ppp_ibytes;
727 *os = ppp_cur.p.ppp_obytes;
729 return 0;
732 /*******************************************************************************\
733 |* stillonline *|
734 \*******************************************************************************/
736 int stillonline(char *ifs) {
738 FILE *fp;
739 int i;
741 i = 0;
742 fp = fopen("/proc/net/route", "r");
743 if (fp) {
744 char temp[128];
745 while (fgets(temp, 128, fp)) {
746 if (strstr(temp, ifs)) {
747 i = 1; /* Line is alive */
750 fclose(fp);
752 return i;
755 /*******************************************************************************\
756 |* DrawTime *|
757 \*******************************************************************************/
759 void DrawTime(int i, int j) {
761 int k = 1000;
763 copyXPMArea(TIMER_SZE_X*((i / k)%10)+1, TIMER_SRC_Y, 5, 7, 6+6*0, TIMER_DES_Y);
764 k = k /10;
765 copyXPMArea(TIMER_SZE_X*((i / k)%10)+1, TIMER_SRC_Y, 5, 7, 6+6*1, TIMER_DES_Y);
766 k = k /10;
768 if (j)
769 copyXPMArea(62, TIMER_SRC_Y, 1, 7, 6+6*2+1, TIMER_DES_Y);
770 else
771 copyXPMArea(63, TIMER_SRC_Y, 1, 7, 6+6*2+1, TIMER_DES_Y);
773 copyXPMArea(TIMER_SZE_X*((i / k)%10)+1, TIMER_SRC_Y, 5, 7, 6+6*2 + 4, TIMER_DES_Y);
774 k = k /10;
775 copyXPMArea(TIMER_SZE_X*((i / k)%10)+1, TIMER_SRC_Y, 5, 7, 6+6*3 + 4, TIMER_DES_Y);
778 /*******************************************************************************\
779 |* DrawStats *|
780 \*******************************************************************************/
782 void DrawStats(int *his, int num, int size, int x_left, int y_bottom) {
784 int pixels_per_byte;
785 int j,k;
786 int *p;
788 pixels_per_byte = 1*size;
789 p = his;
790 for (j=0; j<num; j++) {
791 if (p[0] + p[1] > pixels_per_byte)
792 pixels_per_byte = p[0] + p[1];
793 p += 2;
796 pixels_per_byte /= size;
797 p = his;
799 for (k=0; k<num; k++) {
802 for (j=0; j<size; j++) {
804 if (j < p[0] / pixels_per_byte)
805 copyXPMArea(57+2, 85, 1, 1, k+x_left, y_bottom-j);
806 else if (j < (p[0] + p[1]) / pixels_per_byte)
807 copyXPMArea(57+1, 85, 1, 1, k+x_left, y_bottom-j);
808 else
809 copyXPMArea(57+0, 85, 1, 1, k+x_left, y_bottom-j);
811 p += 2;
815 /*******************************************************************************\
816 |* DrawSpeedInd *|
817 \*******************************************************************************/
819 void PrintLittle(int i, int *k) {
821 switch (i) {
822 case -2:
823 *k -= 5;
824 /* Print the "k" letter */
825 copyXPMArea(11*5-5, 86, 4, 9, *k, 48);
826 break;
827 case -1:
828 *k -= 5;
829 copyXPMArea(13*5-5, 86, 4, 9, *k, 48);
830 break;
831 case 0:
832 *k -= 5;
833 copyXPMArea(45, 86, 5, 9, *k, 48);
834 break;
835 default:
836 *k -= 5;
837 copyXPMArea(i*5-5, 86, 5, 9, *k, 48);
838 break;
842 void DrawSpeedInd(char *speed_action) {
844 int k;
845 FILE *fp;
847 fp = popen(speed_action, "r");
849 if (fp) {
850 char *p;
851 char temp[128];
852 int i, linespeed;
854 linespeed = 0;
856 while (fgets(temp, 128, fp))
859 pclose(fp);
861 if ((p=strstr(temp, "CONNECT"))) {
862 linespeed = atoi(p + 8);
865 k = 30;
867 i = (linespeed % 1000) / 100;
868 linespeed /= 1000;
869 PrintLittle(i, &k);
871 k -= 5;
872 copyXPMArea(50, 86, 5, 9, k, 48);
874 do {
875 PrintLittle(linespeed % 10, &k);
876 linespeed /= 10;
877 } while (linespeed);
881 /*******************************************************************************\
882 |* DrawLoadInd *|
883 \*******************************************************************************/
885 void DrawLoadInd(int speed) {
887 int i, k;
889 k = 30;
890 for (i=0; i<5; i++) PrintLittle(-1, &k);
892 k = 30;
894 /* If speed is greater than 99999, display it in K */
895 if (speed > 99999 )
897 speed /= 1024 ;
898 PrintLittle(-2, &k) ;
901 do {
902 PrintLittle(speed % 10, &k);
903 speed /= 10;
904 } while (speed);
907 /*******************************************************************************\
908 |* usage *|
909 \*******************************************************************************/
911 void usage(void) {
913 fprintf(stderr, "\nwmppp - programming: tijno, design & ideas: warp\n\n");
914 fprintf(stderr, "usage:\n");
915 fprintf(stderr, "-display <display name>\n");
916 fprintf(stderr, "-geometry +XPOS+YPOS initial window position\n");
917 fprintf(stderr, "-h this help screen\n");
918 fprintf(stderr, "-i <device> (ppp0, ppp1, etc) EXPERIMENTAL! Please send\n");
919 fprintf(stderr, " bugreports!\n");
920 fprintf(stderr, "-t set the on-line timer to MM:SS instead of HH:MM\n");
921 fprintf(stderr, "-u <update rate> (1..10), default 5 seconds\n");
922 fprintf(stderr, "-speed <cmd> command to report connection speed\n");
923 fprintf(stderr, "-start <cmd> command to connect\n");
924 fprintf(stderr, "-stop <cmd> command to disconnect\n");
925 fprintf(stderr, "-ifdown <cmd> command to redial\n");
926 fprintf(stderr, "-stampfile <path> file used to calculate uptime\n");
927 fprintf(stderr, "-v print the version number\n");
928 fprintf(stderr, "\n");
931 /*******************************************************************************\
932 |* printversion *|
933 \*******************************************************************************/
935 void printversion(void) {
937 fprintf(stderr, "%s\n", WMPPP_VERSION);
940 /*******************************************************************************\
941 |* get_ppp_stats *|
942 \*******************************************************************************/
944 void get_ppp_stats(struct ppp_stats *cur) {
946 struct ifpppstatsreq req;
948 memset(&req, 0, sizeof(req));
950 req.stats_ptr = (void*) &req.stats;
952 strcpy(req.ifr__name, active_interface);
954 if (ioctl(ppp_h, SIOCGPPPSTATS, &req) >= 0)
955 *cur = req.stats;
958 #define LED_ON_X (50)
959 #define LED_ON_Y (80)
960 #define LED_OFF_Y (75)
961 #define LED_OFF_X (50)
963 #define LED_ERR_X (56)
964 #define LED_ERR_Y (75)
965 #define LED_WTE_X (56)
966 #define LED_WTE_Y (80)
967 #define LED_SZE_X (4)
968 #define LED_SZE_Y (4)
970 #define LED_PWR_X (53)
971 #define LED_PWR_Y (7)
972 #define LED_SND_X (47)
973 #define LED_SND_Y (7)
974 #define LED_RCV_X (41)
975 #define LED_RCV_Y (7)
977 #define LED_SW_X (38)
978 #define LED_SW_Y (14)
980 /*******************************************************************************\
981 |* SetOnLED *|
982 \*******************************************************************************/
983 void SetOnLED(int led) {
985 switch (led) {
986 case LED_PPP_POWER:
987 copyXPMArea(LED_ON_X, LED_ON_Y, LED_SZE_X, LED_SZE_Y, LED_PWR_X, LED_PWR_Y);
988 break;
989 case LED_PPP_RX:
990 copyXPMArea(LED_ON_X, LED_ON_Y, LED_SZE_X, LED_SZE_Y, LED_RCV_X, LED_RCV_Y);
991 break;
992 case LED_PPP_TX:
993 copyXPMArea(LED_ON_X, LED_ON_Y, LED_SZE_X, LED_SZE_Y, LED_SND_X, LED_SND_Y);
994 break;
998 /*******************************************************************************\
999 |* SetOffLED *|
1000 \*******************************************************************************/
1001 void SetOffLED(int led) {
1003 switch (led) {
1004 case LED_PPP_POWER:
1005 copyXPMArea(LED_OFF_X, LED_OFF_Y, LED_SZE_X, LED_SZE_Y, LED_PWR_X, LED_PWR_Y);
1006 break;
1007 case LED_PPP_RX:
1008 copyXPMArea(LED_OFF_X, LED_OFF_Y, LED_SZE_X, LED_SZE_Y, LED_RCV_X, LED_RCV_Y);
1009 break;
1010 case LED_PPP_TX:
1011 copyXPMArea(LED_OFF_X, LED_OFF_Y, LED_SZE_X, LED_SZE_Y, LED_SND_X, LED_SND_Y);
1012 break;
1017 /*******************************************************************************\
1018 |* SetErrLED *|
1019 \*******************************************************************************/
1020 void SetErrLED(int led) {
1022 switch (led) {
1023 case LED_PPP_POWER:
1024 copyXPMArea(LED_ERR_X, LED_ERR_Y, LED_SZE_X, LED_SZE_Y, LED_PWR_X, LED_PWR_Y);
1025 break;
1029 /*******************************************************************************\
1030 |* SetWaitLED *|
1031 \*******************************************************************************/
1032 void SetWaitLED(int led) {
1034 switch (led) {
1035 case LED_PPP_POWER:
1036 copyXPMArea(LED_WTE_X, LED_WTE_Y, LED_SZE_X, LED_SZE_Y, LED_PWR_X, LED_PWR_Y);
1037 break;
1041 /*******************************************************************************\
1042 |* ButtonUp *|
1043 \*******************************************************************************/
1044 void ButtonUp(int button) {
1046 switch (button) {
1047 case BUT_V :
1048 copyXPMArea(24, 74, 12, 11, 35, 48);
1049 break;
1050 case BUT_X :
1051 copyXPMArea(36, 74, 12, 11, 47, 48);
1052 break;
1056 /*******************************************************************************\
1057 |* ButtonDown *|
1058 \*******************************************************************************/
1059 void ButtonDown(int button) {
1061 switch (button) {
1062 case BUT_V :
1063 copyXPMArea(0, 74, 12, 11, 35, 48);
1064 break;
1065 case BUT_X :
1066 copyXPMArea(12, 74, 12, 11, 47, 48);
1067 break;