wmppp.app: Fix segfault when HOME undefined.
[dockapps.git] / wmppp.app / wmppp.c
blob7758eeeb9fdb8e1f517cf429a4a1211bb60c550d
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 <stdio.h> /* for fprintf, stderr, NULL, etc */
165 #include <stdlib.h> /* for exit, atoi, getenv, etc */
166 #include <string.h> /* for strcpy, memset, strcmp, etc */
167 #include <sys/ioctl.h> /* for ioctl */
168 #include <sys/socket.h> /* for socket, AF_INET */
169 #include <sys/stat.h> /* for stat, st_mtime */
170 #include <sys/types.h> /* for pid_t */
171 #include <sys/wait.h> /* for waitpid, WNOHANG */
172 #include <time.h> /* for timespec, nanosleep, time */
173 #include "wmgeneral/misc.h" /* for execCommand */
174 #include "wmgeneral/wmgeneral.h" /* for copyXPMArea, RedrawWindow, etc */
175 #include "wmppp-master.xpm" /* for wmppp_master_xpm */
177 /***********/
178 /* Defines */
179 /***********/
181 /* Fill in and uncomment the hardcoded actions. */
182 /* #define START_ACTION (NULL) */
183 /* #define STOP_ACTION (NULL) */
184 /* #define SPEED_ACTION (NULL) */
185 /* #define IFDOWN_ACTION (NULL) */
187 #define STAMP_FILE_PRE "/var/run/wmppp."
189 /* Defines voor alle coordinate */
191 #define LED_PPP_RX (1)
192 #define LED_PPP_TX (2)
193 #define LED_PPP_POWER (3)
195 #define BUT_V (1)
196 #define BUT_X (2)
198 #define TIMER_X (9)
199 #define TIMER_Y (14)
201 #define TIMER_SRC_Y (65)
202 #define TIMER_DES_Y (6)
203 #define TIMER_SZE_X (6)
205 #define WMPPP_VERSION "1.3.0"
207 #define ORANGE_LED_TIMEOUT (60)
209 /**********************/
210 /* External Variables */
211 /**********************/
213 extern char **environ;
215 /********************/
216 /* Global Variables */
217 /********************/
219 char *ProgName;
220 char *active_interface = "ppp0";
221 int TimerDivisor=60;
222 int updaterate = 5;
224 int wmppp_mask_width = 64;
225 int wmppp_mask_height = 64;
226 char wmppp_mask_bits[64*64];
229 /*****************/
230 /* PPP variables */
231 /*****************/
233 #define PPP_UNIT 0
234 int ppp_h = -1;
236 #define PPP_STATS_HIS 54
238 int pixels_per_byte;
240 int ppp_history[PPP_STATS_HIS+1][2];
242 /***********************/
243 /* Function Prototypes */
244 /***********************/
246 void usage(void);
247 void printversion(void);
248 void DrawTime(int, int);
249 void DrawStats(int *, int, int, int, int);
250 void DrawSpeedInd(char *);
251 void DrawLoadInd(int);
253 void SetOnLED(int);
254 void SetErrLED(int);
255 void SetWaitLED(int);
256 void SetOffLED(int);
258 void ButtonUp(int);
259 void ButtonDown(int);
261 void wmppp_routine(int, char **);
263 int get_statistics(long *, long *, long *, long *);
264 void get_ppp_stats(struct ppp_stats *cur);
265 int stillonline(char *);
268 /********/
269 /* Main */
270 /********/
272 int main(int argc, char *argv[]) {
274 int i;
277 /* Parse Command Line */
279 ProgName = argv[0];
280 if (strlen(ProgName) >= 5)
281 ProgName += (strlen(ProgName) - 5);
283 for (i=1; i<argc; i++) {
284 char *arg = argv[i];
286 if (*arg=='-') {
287 switch (arg[1]) {
288 case 'd' :
289 if (strcmp(arg+1, "display")) {
290 usage();
291 exit(1);
293 break;
294 case 'g' :
295 if (strcmp(arg+1, "geometry")) {
296 usage();
297 exit(1);
299 break;
300 case 'i' :
301 if (!argv[i+1]) {
302 usage();
303 exit(1);
305 /* following removed to allow experiments with
306 * new devices, i.e. ippp
308 #if 0
309 if (strncmp(argv[i+1], "ppp", 3)) {
310 usage();
311 exit(1);
313 #endif
314 active_interface = argv[i+1];
315 i++;
316 break;
317 case 't' :
318 TimerDivisor = 1;
319 break;
320 case 'u' :
321 i++;
322 if (!argv[i]) {
323 usage();
324 exit(1);
326 updaterate = atoi(argv[i]);
327 if (updaterate < 1 || updaterate > 10) {
328 usage();
329 exit(1);
331 break;
332 case 'v' :
333 printversion();
334 exit(0);
335 break;
336 default:
337 usage();
338 exit(0);
339 break;
344 wmppp_routine(argc, argv);
346 return 0;
349 /*****************/
350 /* wmppp_routine */
351 /*****************/
353 char *start_action = NULL;
354 char *stop_action = NULL;
355 char *speed_action = NULL;
356 char *ifdown_action = NULL;
357 char *stamp_file = NULL;
359 void wmppp_routine(int argc, char **argv) {
361 rckeys wmppp_keys[] = {
362 { "start", &start_action },
363 { "stop", &stop_action },
364 { "speed", &speed_action },
365 { "ifdown", &ifdown_action },
366 { "stampfile", &stamp_file },
367 { NULL, NULL }
370 int j;
372 int but_stat;
374 long starttime;
375 long currenttime;
376 long waittime;
377 long ppptime;
378 int hour,minute;
380 long ppp_send,ppp_sl=-1;
381 long ppp_recv,ppp_rl=-1;
382 long ppp_sbytes,ppp_rbytes;
383 long ppp_osbytes,ppp_orbytes;
385 struct stat st;
387 pid_t stop_child = 0;
388 pid_t start_child = 0;
389 int status;
391 XEvent Event;
393 char *p;
394 char temp[128];
396 int speed_ind=60;
398 /* Initialize some stuff */
400 get_statistics(&ppp_rl, &ppp_sl, &ppp_orbytes, &ppp_osbytes);
402 /* Scan through ~/.wmifsrc for the mouse button actions. */
403 #ifdef START_ACTION
404 start_action = strdup(START_ACTION);
405 #endif
406 #ifdef STOP_ACTION
407 stop_action = strdup(STOP_ACTION);
408 #endif
409 #ifdef SPEED_ACTION
410 speed_action = strdup(SPEED_ACTION);
411 #endif
412 #ifdef IFDOWN_ACTION
413 ifdown_action = strdup(IFDOWN_ACTION);
414 #endif
415 #ifdef STAMP_FILE_PRE
416 sprintf (temp, "%s%s", STAMP_FILE_PRE, active_interface);
417 stamp_file = strdup (temp);
418 #endif
421 strcpy(temp, "/etc/wmppprc");
422 parse_rcfile(temp, wmppp_keys);
424 p = getenv("HOME");
425 if (p == NULL) {
426 fprintf(stderr,
427 "error: HOME environment variable not defined\n");
428 exit(EXIT_FAILURE);
430 strcpy(temp, p);
431 strcat(temp, "/.wmppprc");
432 parse_rcfile(temp, wmppp_keys);
434 strcpy(temp, "/etc/wmppprc.fixed");
435 parse_rcfile(temp, wmppp_keys);
437 /* Open the display */
439 createXBMfromXPM(wmppp_mask_bits, wmppp_master_xpm, wmppp_mask_width, wmppp_mask_height);
441 openXwindow(argc, argv, wmppp_master_xpm, wmppp_mask_bits, wmppp_mask_width, wmppp_mask_height);
443 /* V Button */
444 AddMouseRegion(0, 35, 48, 46, 58);
445 /* x Button */
446 AddMouseRegion(1, 47, 48, 58, 58);
448 starttime = 0;
449 currenttime = time(0);
450 ppptime = 0;
451 but_stat = -1;
452 waittime = 0;
453 copyXPMArea(28, 95, 25, 11, 5, 48);
455 /* wmppp main loop */
456 while (1) {
457 int i;
458 long lasttime;
459 struct timespec ts;
461 lasttime = currenttime;
462 currenttime = time(0);
463 /* Check if any child has left the playground */
464 i = waitpid(0, &status, WNOHANG);
465 if (i == stop_child && stop_child != 0) {
467 starttime = 0;
468 SetOffLED(LED_PPP_POWER);
469 SetOffLED(LED_PPP_RX);
470 SetOffLED(LED_PPP_TX);
471 copyXPMArea(28, 95, 25, 11, 5, 48);
473 RedrawWindow();
475 stop_child = 0;
477 if (i == start_child && start_child != 0) {
478 if (WIFEXITED(status)) {
479 if (WEXITSTATUS(status) == 10) {
481 starttime = 0;
482 copyXPMArea(28, 95, 25, 11, 5, 48);
483 SetOffLED(LED_PPP_POWER);
484 DrawTime(0, 1);
485 RedrawWindow();
487 start_child = 0;
491 /* On-line detectie! 1x per second */
493 if (currenttime != lasttime) {
494 i = 0;
496 if (stillonline(active_interface)) {
497 i = 1;
498 if (!starttime) {
499 starttime = currenttime;
501 if (stat(stamp_file, &st) == 0)
502 starttime = st.st_mtime;
504 SetOnLED(LED_PPP_POWER);
505 waittime = 0;
507 copyXPMArea(28, 95, 25, 11, 5, 48);
509 if (speed_action)
510 DrawSpeedInd(speed_action);
512 speed_ind = currenttime + 60;
514 RedrawWindow();
517 if (!i && starttime) {
518 starttime = 0;
519 SetErrLED(LED_PPP_POWER);
521 copyXPMArea(0, 95, 26, 11, 5, 48);
523 if (ifdown_action)
524 execCommand(ifdown_action);
526 RedrawWindow();
530 if (waittime && waittime <= currenttime) {
531 SetOffLED(LED_PPP_POWER);
532 RedrawWindow();
533 waittime = 0;
536 /* If we are on-line. Print the time we are */
537 if (starttime) {
538 i = currenttime - starttime;
540 i /= TimerDivisor;
542 if (TimerDivisor == 1)
543 if (i > 59 * 60 + 59) i /= 60;
545 minute = i % 60;
546 hour = (i / 60) % 100;
547 i = hour * 100 + minute;
549 DrawTime(i, currenttime % 2);
550 /* We are online, so we can check for send/recv packets */
552 get_statistics(&ppp_recv, &ppp_send, &ppp_rbytes, &ppp_sbytes);
554 if (ppp_send != ppp_sl) SetOnLED(LED_PPP_TX);
555 else SetOffLED(LED_PPP_TX);
557 if (ppp_recv != ppp_rl) SetOnLED(LED_PPP_RX);
558 else SetOffLED(LED_PPP_RX);
560 ppp_sl = ppp_send;
561 ppp_rl = ppp_recv;
563 /* Every five seconds we check to load on the line */
565 if ((currenttime - ppptime >= 0) || (ppptime == 0)) {
567 ppptime = currenttime + updaterate;
569 ppp_history[PPP_STATS_HIS][0] = ppp_rbytes - ppp_orbytes;
570 ppp_history[PPP_STATS_HIS][1] = ppp_sbytes - ppp_osbytes;
572 ppp_orbytes = ppp_rbytes;
573 ppp_osbytes = ppp_sbytes;
575 DrawStats(&ppp_history[0][0], 54, 25, 5, 43);
577 for (j=1; j<55; j++) {
578 ppp_history[j-1][0] = ppp_history[j][0];
579 ppp_history[j-1][1] = ppp_history[j][1];
581 if (currenttime > speed_ind) {
582 DrawLoadInd((ppp_history[54][0] + ppp_history[54][1]) / updaterate);
586 RedrawWindow();
590 while (XPending(display)) {
591 XNextEvent(display, &Event);
592 switch (Event.type) {
593 case Expose:
594 RedrawWindow();
595 break;
596 case DestroyNotify:
597 XCloseDisplay(display);
598 while (start_child | stop_child) {
599 i = waitpid(0, &status, WNOHANG);
600 if (i == stop_child) stop_child = 0;
601 if (i == start_child) start_child = 0;
602 ts.tv_sec = 0;
603 ts.tv_nsec = 50000000L;
604 nanosleep(&ts, NULL);
606 exit(0);
607 break;
608 case ButtonPress:
609 i = CheckMouseRegion(Event.xbutton.x, Event.xbutton.y);
610 switch (i) {
611 case 0:
612 ButtonDown(BUT_V);
613 break;
614 case 1:
615 ButtonDown(BUT_X);
616 break;
618 but_stat = i;
620 RedrawWindow();
621 break;
622 case ButtonRelease:
623 i = CheckMouseRegion(Event.xbutton.x, Event.xbutton.y);
624 /* Button but_stat omhoogdoen! */
625 switch (but_stat) {
626 case 0:
627 ButtonUp(BUT_V);
628 break;
629 case 1:
630 ButtonUp(BUT_X);
631 break;
634 if (i == but_stat && but_stat >= 0) {
635 switch (i) {
636 case 0:
637 if (!starttime) {
638 copyXPMArea(28, 95, 25, 11, 5, 48);
639 DrawTime(0, 1);
640 start_child = execCommand(start_action);
641 SetWaitLED(LED_PPP_POWER);
642 waittime = ORANGE_LED_TIMEOUT + currenttime;
645 break;
646 case 1:
647 if (stop_child == 0) {
648 stop_child = execCommand(stop_action);
650 break;
653 RedrawWindow();
655 but_stat = -1;
656 break;
657 default:
658 break;
661 ts.tv_sec = 0;
662 ts.tv_nsec = 50000000L;
663 nanosleep(&ts, NULL);
667 /*******************************************************************************\
668 |* get_statistics *|
669 \*******************************************************************************/
671 int get_statistics(long *ip, long *op, long *is, long *os) {
673 struct ppp_stats ppp_cur;
674 static int ppp_opened = 0;
677 if (!ppp_opened) {
678 /* Open the ppp device. */
679 memset(&ppp_cur, 0, sizeof(ppp_cur));
680 if ((ppp_h = socket(AF_INET, SOCK_DGRAM, 0)) < 0)
681 return -1;
682 ppp_opened = 1;
685 get_ppp_stats(&ppp_cur);
687 *op = ppp_cur.p.ppp_opackets;
688 *ip = ppp_cur.p.ppp_ipackets;
690 *is = ppp_cur.p.ppp_ibytes;
691 *os = ppp_cur.p.ppp_obytes;
693 return 0;
696 /*******************************************************************************\
697 |* stillonline *|
698 \*******************************************************************************/
700 int stillonline(char *ifs) {
702 FILE *fp;
703 int i;
705 i = 0;
706 fp = fopen("/proc/net/route", "r");
707 if (fp) {
708 char temp[128];
709 while (fgets(temp, 128, fp)) {
710 if (strstr(temp, ifs)) {
711 i = 1; /* Line is alive */
714 fclose(fp);
716 return i;
719 /*******************************************************************************\
720 |* DrawTime *|
721 \*******************************************************************************/
723 void DrawTime(int i, int j) {
725 int k = 1000;
727 copyXPMArea(TIMER_SZE_X*((i / k)%10)+1, TIMER_SRC_Y, 5, 7, 6+6*0, TIMER_DES_Y);
728 k = k /10;
729 copyXPMArea(TIMER_SZE_X*((i / k)%10)+1, TIMER_SRC_Y, 5, 7, 6+6*1, TIMER_DES_Y);
730 k = k /10;
732 if (j)
733 copyXPMArea(62, TIMER_SRC_Y, 1, 7, 6+6*2+1, TIMER_DES_Y);
734 else
735 copyXPMArea(63, TIMER_SRC_Y, 1, 7, 6+6*2+1, TIMER_DES_Y);
737 copyXPMArea(TIMER_SZE_X*((i / k)%10)+1, TIMER_SRC_Y, 5, 7, 6+6*2 + 4, TIMER_DES_Y);
738 k = k /10;
739 copyXPMArea(TIMER_SZE_X*((i / k)%10)+1, TIMER_SRC_Y, 5, 7, 6+6*3 + 4, TIMER_DES_Y);
742 /*******************************************************************************\
743 |* DrawStats *|
744 \*******************************************************************************/
746 void DrawStats(int *his, int num, int size, int x_left, int y_bottom) {
748 int pixels_per_byte;
749 int j,k;
750 int *p;
752 pixels_per_byte = 1*size;
753 p = his;
754 for (j=0; j<num; j++) {
755 if (p[0] + p[1] > pixels_per_byte)
756 pixels_per_byte = p[0] + p[1];
757 p += 2;
760 pixels_per_byte /= size;
761 p = his;
763 for (k=0; k<num; k++) {
766 for (j=0; j<size; j++) {
768 if (j < p[0] / pixels_per_byte)
769 copyXPMArea(57+2, 85, 1, 1, k+x_left, y_bottom-j);
770 else if (j < (p[0] + p[1]) / pixels_per_byte)
771 copyXPMArea(57+1, 85, 1, 1, k+x_left, y_bottom-j);
772 else
773 copyXPMArea(57+0, 85, 1, 1, k+x_left, y_bottom-j);
775 p += 2;
779 /*******************************************************************************\
780 |* DrawSpeedInd *|
781 \*******************************************************************************/
783 void PrintLittle(int i, int *k) {
785 switch (i) {
786 case -2:
787 *k -= 5;
788 /* Print the "k" letter */
789 copyXPMArea(11*5-5, 86, 4, 9, *k, 48);
790 break;
791 case -1:
792 *k -= 5;
793 copyXPMArea(13*5-5, 86, 4, 9, *k, 48);
794 break;
795 case 0:
796 *k -= 5;
797 copyXPMArea(45, 86, 5, 9, *k, 48);
798 break;
799 default:
800 *k -= 5;
801 copyXPMArea(i*5-5, 86, 5, 9, *k, 48);
802 break;
806 void DrawSpeedInd(char *speed_action) {
808 int k;
809 FILE *fp;
811 fp = popen(speed_action, "r");
813 if (fp) {
814 char *p;
815 char temp[128];
816 int i, linespeed;
818 linespeed = 0;
820 while (fgets(temp, 128, fp))
823 pclose(fp);
825 if ((p=strstr(temp, "CONNECT"))) {
826 linespeed = atoi(p + 8);
829 k = 30;
831 i = (linespeed % 1000) / 100;
832 linespeed /= 1000;
833 PrintLittle(i, &k);
835 k -= 5;
836 copyXPMArea(50, 86, 5, 9, k, 48);
838 do {
839 PrintLittle(linespeed % 10, &k);
840 linespeed /= 10;
841 } while (linespeed);
845 /*******************************************************************************\
846 |* DrawLoadInd *|
847 \*******************************************************************************/
849 void DrawLoadInd(int speed) {
851 int i, k;
853 k = 30;
854 for (i=0; i<5; i++) PrintLittle(-1, &k);
856 k = 30;
858 /* If speed is greater than 99999, display it in K */
859 if (speed > 99999 )
861 speed /= 1024 ;
862 PrintLittle(-2, &k) ;
865 do {
866 PrintLittle(speed % 10, &k);
867 speed /= 10;
868 } while (speed);
871 /*******************************************************************************\
872 |* usage *|
873 \*******************************************************************************/
875 void usage(void) {
877 fprintf(stderr, "\nwmppp - programming: tijno, design & ideas: warp\n\n");
878 fprintf(stderr, "usage:\n");
879 fprintf(stderr, "-display <display name>\n");
880 fprintf(stderr, "-geometry +XPOS+YPOS initial window position\n");
881 fprintf(stderr, "-h this help screen\n");
882 fprintf(stderr, "-i <device> (ppp0, ppp1, etc) EXPERIMENTAL! Please send bugreports!\n");
883 fprintf(stderr, "-t set the on-line timer to MM:SS instead of HH:MM\n");
884 fprintf(stderr, "-u <update rate> (1..10), default 5 seconds\n");
885 fprintf(stderr, "-v print the version number\n");
886 fprintf(stderr, "\n");
889 /*******************************************************************************\
890 |* printversion *|
891 \*******************************************************************************/
893 void printversion(void) {
895 fprintf(stderr, "%s\n", WMPPP_VERSION);
898 /*******************************************************************************\
899 |* get_ppp_stats *|
900 \*******************************************************************************/
902 void get_ppp_stats(struct ppp_stats *cur) {
904 struct ifpppstatsreq req;
906 memset(&req, 0, sizeof(req));
908 req.stats_ptr = (void*) &req.stats;
910 strcpy(req.ifr__name, active_interface);
912 if (ioctl(ppp_h, SIOCGPPPSTATS, &req) >= 0)
913 *cur = req.stats;
916 #define LED_ON_X (50)
917 #define LED_ON_Y (80)
918 #define LED_OFF_Y (75)
919 #define LED_OFF_X (50)
921 #define LED_ERR_X (56)
922 #define LED_ERR_Y (75)
923 #define LED_WTE_X (56)
924 #define LED_WTE_Y (80)
925 #define LED_SZE_X (4)
926 #define LED_SZE_Y (4)
928 #define LED_PWR_X (53)
929 #define LED_PWR_Y (7)
930 #define LED_SND_X (47)
931 #define LED_SND_Y (7)
932 #define LED_RCV_X (41)
933 #define LED_RCV_Y (7)
935 #define LED_SW_X (38)
936 #define LED_SW_Y (14)
938 /*******************************************************************************\
939 |* SetOnLED *|
940 \*******************************************************************************/
941 void SetOnLED(int led) {
943 switch (led) {
944 case LED_PPP_POWER:
945 copyXPMArea(LED_ON_X, LED_ON_Y, LED_SZE_X, LED_SZE_Y, LED_PWR_X, LED_PWR_Y);
946 break;
947 case LED_PPP_RX:
948 copyXPMArea(LED_ON_X, LED_ON_Y, LED_SZE_X, LED_SZE_Y, LED_RCV_X, LED_RCV_Y);
949 break;
950 case LED_PPP_TX:
951 copyXPMArea(LED_ON_X, LED_ON_Y, LED_SZE_X, LED_SZE_Y, LED_SND_X, LED_SND_Y);
952 break;
956 /*******************************************************************************\
957 |* SetOffLED *|
958 \*******************************************************************************/
959 void SetOffLED(int led) {
961 switch (led) {
962 case LED_PPP_POWER:
963 copyXPMArea(LED_OFF_X, LED_OFF_Y, LED_SZE_X, LED_SZE_Y, LED_PWR_X, LED_PWR_Y);
964 break;
965 case LED_PPP_RX:
966 copyXPMArea(LED_OFF_X, LED_OFF_Y, LED_SZE_X, LED_SZE_Y, LED_RCV_X, LED_RCV_Y);
967 break;
968 case LED_PPP_TX:
969 copyXPMArea(LED_OFF_X, LED_OFF_Y, LED_SZE_X, LED_SZE_Y, LED_SND_X, LED_SND_Y);
970 break;
975 /*******************************************************************************\
976 |* SetErrLED *|
977 \*******************************************************************************/
978 void SetErrLED(int led) {
980 switch (led) {
981 case LED_PPP_POWER:
982 copyXPMArea(LED_ERR_X, LED_ERR_Y, LED_SZE_X, LED_SZE_Y, LED_PWR_X, LED_PWR_Y);
983 break;
987 /*******************************************************************************\
988 |* SetWaitLED *|
989 \*******************************************************************************/
990 void SetWaitLED(int led) {
992 switch (led) {
993 case LED_PPP_POWER:
994 copyXPMArea(LED_WTE_X, LED_WTE_Y, LED_SZE_X, LED_SZE_Y, LED_PWR_X, LED_PWR_Y);
995 break;
999 /*******************************************************************************\
1000 |* ButtonUp *|
1001 \*******************************************************************************/
1002 void ButtonUp(int button) {
1004 switch (button) {
1005 case BUT_V :
1006 copyXPMArea(24, 74, 12, 11, 35, 48);
1007 break;
1008 case BUT_X :
1009 copyXPMArea(36, 74, 12, 11, 47, 48);
1010 break;
1014 /*******************************************************************************\
1015 |* ButtonDown *|
1016 \*******************************************************************************/
1017 void ButtonDown(int button) {
1019 switch (button) {
1020 case BUT_V :
1021 copyXPMArea(0, 74, 12, 11, 35, 48);
1022 break;
1023 case BUT_X :
1024 copyXPMArea(12, 74, 12, 11, 47, 48);
1025 break;