wmnd_0.2.1/0040755000175000000120000000000007221077017011343 5ustar reedwheelwmnd_0.2.1/COPYING0100644000175000000120000004307607146456765012426 0ustar reedwheel GNU GENERAL PUBLIC LICENSE Version 2, June 1991 Copyright (C) 1989, 1991 Free Software Foundation, Inc. 675 Mass Ave, Cambridge, MA 02139, USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Library General Public License instead.) You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you". Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does. 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change. b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License. c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program. In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following: a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.) The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code. 4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License. 7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation. 10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS Appendix: How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) 19yy This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. 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. Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) 19yy name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (which makes passes at compilers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice This General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Library General Public License instead of this License. wmnd_0.2.1/CHANGELOGS0100644000175000000120000000711507221057367012707 0ustar reedwheel Changes in WMND ------------------------------------------------------------------------------ 0.2.1 Bug fix Wrong scale at 1K, 1M, and 1G. Wrong display scale when (rx_max + tx_max) is bigger than the value of the unsigned long int. 0.2.0 Thank to Timecop who has re-written almost whole codes of wmnd and given it optimization of efficiency. User configurable items in wmnd source file (.wmndrc) rx/tx graph color status refresh interval graph scroll speed user scripts for 3 buttons PPP conection time. 0.1.0 Changed time gap method from time() to signal driven. This change resolves the race problem when the system wakes up from hibernation mode. The values of max-meter and rate-meter are defaultly scaled by base 10 floating point division. K=1000 (10e3), M=10000000 (10e6), G=1000000000 (10e9). Using the option -b scales bitwise instead. K=1024 (2^10), M=1048576 (2^20), G=1073741824 (2^30). There is no floating point in binary mode. Displayed device name defaults to short format. Right click on the device name to toggle between full name and short name. For example, tunl1 is normally shortened to tun1, but in full name mode, tunl1 is displayed. Added a new graph display mode that is similar to wmnet, right click on the main display area to switch modes. Now there are two modes for max-meter. Default shows the maximum value from screen graphed. The second mode shows the maximum value from historical record since wmnd is started. Left click on max-meter to switch modes, right click on max-meter to toggle the display of the max-meter. Fixed the overflow bug when reading a statistics value from /proc/net/dev that's larger than INT_MAX by replacing a long integer with an unsigned long integer. 0.0.4 One more bug has been fixed. Replace line 1200 in wmnd.c while (!stat_devices[j].name[0] && j < MAX_STAT_DEVICES) { with while (j < MAX_STAT_DEVICES && !stat_devices[j].name[0]) { This bug allowed stat_devices[j] to be checked even if j is out of the range of stat_devices[], and causes a segmentation fault on some system. Thanks to Ben (rain@insane.loonybin.net) 0.0.3b The size of the device name buffer from WMiFS is 4. In other words, if there are more than 4 network devices on system, wmnd will crash. I do not know what the reasonable number is. Just change 4 to 32 if you need more. Theoretically, it will support up to 32 devices. Thanks to Paul (paul@luon.net) 0.0.3 Bug fix Changed the size of reading buffer to 256 bytes. The original size is 128 bytes, and will cause segmentation fault when the line from /proc/net/dev or /proc/net/route is longer than 128 bytes. Thanks to John Bafford (dshadow@zort.net) 0.0.2 Bug fix Corrected the AddMouseRegion for mouse-triggered user script. Thanks to Anstinus (http://www.acm.rpi.edu/~anstinus/) Added codes to skip the statistics reading of invalid device "irda?." The invalid entries in /proc/net/dev look like this: ... irda0: No statistics available. irlan0: 0 0 0 0 ... ... Thanks to Paul (paul@luon.net) 0.0.1 Initially created by Reed Lai (reed@wingeer.org) Created and modified based on WMiFS-1.3b. Displays last send and receive bytes/packets. Displays the maxima for rx and tx in current display history. Default update time gap is 1 sec. Defaults to waveform mode. Runtime switchable to waveform or traditional mode. Runtime switchable to packets or bytes mode. Runtime togglable display of maxima. wmnd_0.2.1/INSTALL0100644000175000000120000000340407214615756012404 0ustar reedwheelInstallation instructions for WMND. Installation -------------------------------------------------------------- 1) % tar -zxvf wmnd_version.tar.gz 2) % cd wmnd 3) % make 4) % su root 5) # make install or for example % make install prefix=$HOME or whatever you want. The install can be influenced by the following variables (the values listed are the defaults): prefix = /usr/local bindir = $(prefix)/bin mandir = $(prefix)/share/man/ datadir = $(prefix)/share/ docdir = $(datadir)/doc/wmnd/ 6) If this is your first time to install wmnd, copy src/wmndrc to your your home directory. Since the wmnd 0.2 has diffenent style of wmndrc to old, you should copy the new one instead of the old one. The copy command is looked like % cp wmndrc ~/.wmndrc wmnd can be run without .wmndrc, it just use the default value, and no user script defined. 7) % Edit .wmndrc to suit your use. 7) % wmnd & (or wmnd -h for brief help). Usage ------------------------------------------------------------- WMND support the following commandline options: -h Help screen -b Scale value by bitwise, read the version section 0.1.0 of file CHANGELOGS for detail. -d X server display where wmnd should appear (default = 0:0) -i Interface name, note: 'lo' can ONLY be specified with '-i lo' ;-) (default = default interface as it appears in /proc/net/route) -w Draw the statistics graph in waveform like mode. -v Print wmnd version number General Notes -------------------------------------------------------------- Note 1: Please DO read the HINTS, this file contains some very usefull tips about WMND. wmnd_0.2.1/TODO0100644000175000000120000000061307221021416012020 0ustar reedwheelTODO list for WMND. ------------------------------------------------------------------------ Your feedback! If you have nice suggestions, ideas, whatever, that aren't on this list, feel free to post to Wall or mail them to me :) A protable version of wmnd. Allows the default graph mode from command-line and rc file. TODO are updated at web page http://www.wingeer.org/wmnd/todo.shtml wmnd_0.2.1/man/0040755000175000000120000000000007214621306012114 5ustar reedwheelwmnd_0.2.1/man/wmnd.10100644000175000000120000001010207214621306013132 0ustar reedwheel.\" Hey, EMACS: -*- nroff -*- .\" .\" This documentation may be distributed under the terms of .\" the GNU General Public Licence version 2. .\" .\" First parameter, NAME, should be all caps .\" Second parameter, SECTION, should be 1-8, maybe w/ subsection .\" other parameters are allowed: see man(7), man(1) .TH WMND 1 "Dec 8, 2000" .\" Please adjust this date whenever revising the manpage. .\" .\" Some roff macros, for reference: .\" .nh disable hyphenation .\" .hy enable hyphenation .\" .ad l left justify .\" .ad b justify to both left and right margins .\" .nf disable filling .\" .fi enable filling .\" .br insert line break .\" .sp insert n+1 empty lines .\" for manpage-specific macros, see man(7) .SH NAME wmnd \- WindowMaker network device monitor .SH SYNOPSIS .BR wmnd " [ " -v " | " -h " | [ " -d .IR display " ] [ " .BI -i " interface " .RB " ] [ " -w " ] [ " -b " ] ]" .SH DESCRIPTION .BR wmnd (1) is a WindowMaker dock application that shows a graph of the network traffic of the past few minutes, current activity and current and overall send and receive rates. Additionally it can launch any program in response to mouse clicks. .PP There are two modes for the max-meter (the one on top of the graph). Per default it shows the maximum value on the graph. The second mode shows the maximum value of a historical record since wmnd was started. You may left click on max-meter to switch modes, right click on max-meter to hide the max-meter. .SH OPTIONS .TP .BI "\-i " interface Start showing the status of network interface \fIinterface\fP. .TP .B \-w Draw the graph in waveform mode (default is inverse waveform mode). Right clicks cycle through all available modes. .TP .B \-b Scale the values of the maximum and current rate by factors of base 2 instead of the default 10-based scaling. (\fB1K\fP equals 1024 in binary mode, but 1000 in decimal mode.) .TP .B \-h Show summary of options. .TP .BI "\-d " display Draw onto X11 display \fIdisplay\fP. .TP .B \-v Show version of wmnd. .SH USAGE .SS Active Interface You can cycle in realtime through all available active interfaces by simply left-clicking on the interface name gadget on the upperleft corner of wmnd. .PP The 'lo' interface is an exception, 'lo' ONLY works when invoked from the commandline (\fBwmnd \-i lo\fP), lo was mainly built in for testing purposes. .SS Device Name By default, wmnd show device name in short term of four characters, for example, the ippp0 will be displayed as ipp0. You can toggle the device name between short and long by right-click on it. .SS Graphic Mode Left-click on the main graphic area to cycle the graphic mode. .SS Max Meter Left-click to toggle the history max or screen max, default is screen max when wmnd is startup. Right-click to hide or display. .SS Byte/Packet Mode Left-click on the letter gadgeted on the right-top corner can switch between the Byte or Packet counter mode. "B" for byte, "p" for packet. .SS User Script Click on the bottom rate meter can invoke the user command defined in resource file .wmndrc. .SS Dragging WMND Be sure to drag WMND on it's outer edges, it's a bit picky due to the large gfx pixmap it keeps. You can also use a keyboard and mouse shortcut (perhaps ALT+left-click) in your window manager to drag it around. .SH FILES ~/.wmndrc User configuration. .PP The format of this file is: .nf .IP # WMND configuration file .IP # middle line in wave mode color md_color=#71e371 .IP # RX/TX color (can be #xxxxxx, or color name from rgb.txt) rx_color=#188a86 tx_color=#00fff2 .IP # refresh between status polling (not graph scroll speed) # numbering in nanoseconds refresh=50000 .IP # bar graph scroll speed (in seconds) this setting also affectsi # the rate and max speed displays. the longer the delay, more # inaccurate these are since the max and rate values are averaged # across this interval scroll=1 .IP # buttons for user scripts # bt1_action=su -c ethereal # bt2_action= # bt3_action= .fi .SH SEE ALSO .BR X (3x), .BR wmaker (1x). .SH AUTHOR This manual page was written by Arthur Korn . wmnd_0.2.1/src/0040755000175000000120000000000007221077017012132 5ustar reedwheelwmnd_0.2.1/src/wmnd.c0100644000175000000120000010543207221077017013245 0ustar reedwheel/* * wmnd.c * by Reed Lai * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * */ #include #include #include #include #include #include #include #include #include #include /* for set_bit / clear_bit / friends */ #include #include #include #include #include #include "beat.h" #include "misc.h" #include "master.xpm" #define WMND_VERSION "0.2.1" #define NET_DEV "/proc/net/dev" #define NET_ROUTE "/proc/net/route" #define MAXBUF 256 #ifdef PRO #define eprint(level, fmt, arg...) \ switch (level) { \ case 0: \ break; \ case 1: \ fprintf(stderr, __FUNCTION__": " fmt, ##arg); \ fprintf(stderr, "\n"); \ break; \ } #else #define eprint(level, fmt, arg...) \ do { } while (0) #endif char *active_interface = NULL; struct Devices { struct Devices *next; /* ptr to next structure */ char *name; /* device name from /proc/net/dev */ time_t ts; /* add timestamp */ unsigned long int his[59][4]; unsigned long int ib_stat_last; unsigned long int ob_stat_last; unsigned long int ip_stat_last; unsigned long int op_stat_last; unsigned long int ib_max_his; /* maximum input bytes in history */ unsigned long int ob_max_his; /* maximum output bytes in history */ unsigned long int ip_max_his; /* maximum input packets in history */ unsigned long int op_max_his; /* maximum output packets in history */ }; struct var { struct var *v_next; /* ptr to next structure */ char *v_name; /* option name */ char *v_value; /* option value */ }; typedef struct { unsigned int nr_devices; /* number of devices in list */ unsigned char current[16]; /* currently showing device */ unsigned long int flags; /* big bit-mapped flags mask */ time_t pppstart; /* special case for ppp connection time */ unsigned int wavemode; /* type of wave graph */ void (*draw) (struct Devices *); /* draw stats function */ void (*scale) (unsigned char sign, unsigned long value, char *buf); /* scale * function */ unsigned int refresh; /* speed of the refresh */ unsigned long scroll; /* speed of the graph scrolling */ } DevTable; typedef struct { Display *d; int xfd; int screen; Window root; Window win; Window iconwin; Pixmap pixmap; Pixmap mask; GC gc; int width; int height; int x; int y; int button; int update; } Dockapp; typedef struct { int enable; int x; int y; int width; int height; } MRegion; struct var *vars; /* config file option structure */ struct Devices *devices; /* devices to monitor */ DevTable wmnd; /* interesting information about devices */ Dockapp dockapp; /* dockapp structure */ MRegion mr[32]; /* mouse regions */ /* store all configuration in one place */ #define RUN_ONLINE 3 /* current device is online */ #define LED_POWER 4 /* next 3 are for different leds */ #define LED_RX 5 #define LED_TX 6 #define CFG_MAXSCREEN 16 /* 1: yes 0: no, max history */ #define CFG_SHORTNAME 17 /* 1: use 0: no */ #define CFG_MODE 18 /* 1: bytes 0: packets */ #define CFG_SHOWMAX 19 /* 1: yes 0: no */ /* bit ops */ #define bit_set(n) set_bit(n, &wmnd.flags) #define bit_off(n) clear_bit(n, &wmnd.flags) #define bit_tgl(n) change_bit(n, &wmnd.flags) #define bit_get(n) test_bit(n, &wmnd.flags) /* GUI */ static void redraw_window(void); unsigned long get_color(char *name); void new_window(char *name, int width, int height); /* config file read/write */ void conf_read(char *filename); void conf_write(char *filename); void assign(char *name, char *value); void vdel(char *name); struct var *lookup(char *name); char *value(char *name); char *vcopy(char *str); /* support */ int add_mr(int index, int x, int y, int width, int height); int check_mr(int x, int y); void beat_event(void); void click_event(unsigned int region, unsigned int button); static void led_control(const unsigned char led, const unsigned char mode); void scale(char *rx_buf, char *tx_buf, unsigned long rx, unsigned long tx); void metric_scale(unsigned char sign, unsigned long value, char *buf); void binary_scale(unsigned char sign, unsigned long value, char *buf); void draw_string(unsigned char *buf, unsigned int x, unsigned int y); /* device statistics */ struct Devices *add_device(char *name, struct Devices **list, time_t ts); void delete_device(char *name, struct Devices **list); struct Devices *lookup_device(char *name, struct Devices *list); int device_list(void); void cycle_devices(char *def); void draw_interface(void); void draw_rate(unsigned long rx, unsigned long tx); void draw_max(unsigned long rx, unsigned long tx); void draw_error(struct Devices *ptr); void draw_stats(struct Devices *ptr); static int get_statistics(const char *dev, unsigned long *ip, unsigned long *op, unsigned long *ib, unsigned long *ob); int still_online(char *dev); /* useless shit */ void usage(void); void printversion(void); /* device structure handling */ struct Devices *add_device(char *name, struct Devices **list, time_t ts) { struct Devices *new; struct Devices *ptr = NULL; if ((ptr = lookup_device(name, *list))) { /* this is done to "save" history data */ /* renew timestamp so that we don't get deleted later */ ptr->ts = ts; eprint(1, "device already exists"); return ptr; } new = (struct Devices *) malloc(sizeof(struct Devices)); if (*list == NULL || strcmp((*list)->name, name) >= 0) { new->next = *list; *list = new; } else { ptr = *list; while (ptr->next && strcmp(ptr->next->name, name) <= 0) { ptr = ptr->next; } new->next = ptr->next; ptr->next = new; } eprint(1, "adding %s", name); new->name = strdup(name); new->ts = ts; memset(new->his, 0, sizeof(new->his)); new->ib_stat_last = new->ob_stat_last = 0; new->ip_stat_last = new->op_stat_last = 0; new->ib_max_his = new->ob_max_his = 0; new->ip_max_his = new->op_max_his = 0; wmnd.nr_devices++; return new; } void delete_device(char *name, struct Devices **list) { struct Devices *ptr; struct Devices *new; while (*list && !strcmp((*list)->name, name)) { ptr = (*list)->next; free((struct Devices *) *list); *list = ptr; eprint(1, "deleting %s", name); } if (*list) for (new = *list; new->next;) if (!strcmp(new->next->name, name)) { eprint(1, "deleting %s", name); ptr = new->next->next; free(new->next); new->next = ptr; } else new = new->next; wmnd.nr_devices--; } struct Devices *lookup_device(char *name, struct Devices *list) { struct Devices *ptr; for (ptr = list; ptr; ptr = ptr->next) { if (!strcmp(name, ptr->name)) { eprint(0, "found %s [%p]", name, ptr); return ptr; } } return NULL; } #define copy_xpm_area(x, y, w, h, dx, dy) \ { \ XCopyArea(dockapp.d, dockapp.pixmap, dockapp.pixmap, dockapp.gc, \ x, y, w, h, dx, dy); \ dockapp.update = 1; \ } int add_mr(int index, int x, int y, int width, int height) { mr[index].enable = 1; mr[index].x = x; mr[index].y = y; mr[index].width = width; mr[index].height = height; return 0; } int check_mr(int x, int y) { register int i; register int found = 0; for (i = 0; i < 32 && !found; i++) { if (mr[i].enable && x >= mr[i].x && x <= mr[i].x + mr[i].width && y >= mr[i].y && y <= mr[i].y + mr[i].height) found = 1; } if (!found) return -1; return (i - 1); } static void redraw_window(void) { if (dockapp.update) { eprint(0, "redrawing window"); XCopyArea(dockapp.d, dockapp.pixmap, dockapp.iconwin, dockapp.gc, 0, 0, dockapp.width, dockapp.height, 0, 0); XCopyArea(dockapp.d, dockapp.pixmap, dockapp.win, dockapp.gc, 0, 0, dockapp.width, dockapp.height, 0, 0); dockapp.update = 0; } } unsigned long get_color(char *name) { XColor color; XWindowAttributes attr; color.pixel = 0; XGetWindowAttributes(dockapp.d, DefaultRootWindow(dockapp.d), &attr); XParseColor(dockapp.d, DefaultColormap(dockapp.d, DefaultScreen(dockapp.d)), name, &color); color.flags = DoRed | DoGreen | DoBlue; XAllocColor(dockapp.d, attr.colormap, &color); eprint(1, "pixel: %08lx\n", color.pixel); return color.pixel; } void new_window(char *name, int width, int height) { XpmAttributes attr; XpmColorSymbol cols[3] = { {"rx_color", NULL, 0}, {"tx_color", NULL, 0}, {"md_color", NULL, 0} }; Pixel fg, bg; XGCValues gcval; XSizeHints sizehints; XClassHint classhint; XWMHints wmhints; dockapp.width = width; dockapp.height = height; dockapp.screen = DefaultScreen(dockapp.d); dockapp.root = DefaultRootWindow(dockapp.d); sizehints.flags = USSize | USPosition; sizehints.x = dockapp.x ? dockapp.x : 0; sizehints.y = dockapp.y ? dockapp.y : 0; sizehints.width = width; sizehints.height = height; fg = BlackPixel(dockapp.d, dockapp.screen); bg = WhitePixel(dockapp.d, dockapp.screen); dockapp.win = XCreateSimpleWindow(dockapp.d, dockapp.root, sizehints.x, sizehints.y, sizehints.width, sizehints.height, 1, fg, bg); dockapp.iconwin = XCreateSimpleWindow(dockapp.d, dockapp.win, sizehints.x, sizehints.y, sizehints.width, sizehints.height, 1, fg, bg); XSetWMNormalHints(dockapp.d, dockapp.win, &sizehints); classhint.res_name = name; classhint.res_class = name; XSetClassHint(dockapp.d, dockapp.win, &classhint); XSelectInput(dockapp.d, dockapp.win, ExposureMask | ButtonPressMask | ButtonReleaseMask | StructureNotifyMask); XSelectInput(dockapp.d, dockapp.iconwin, ExposureMask | ButtonPressMask | ButtonReleaseMask | StructureNotifyMask); XStoreName(dockapp.d, dockapp.win, name); XSetIconName(dockapp.d, dockapp.win, name); gcval.foreground = fg; gcval.background = bg; gcval.graphics_exposures = False; dockapp.gc = XCreateGC(dockapp.d, dockapp.win, GCForeground | GCBackground | GCGraphicsExposures, &gcval); cols[0].pixel = get_color(value("rx_color")); cols[1].pixel = get_color(value("tx_color")); cols[2].pixel = get_color(value("md_color")); attr.exactColors = 0; attr.alloc_close_colors = 1; attr.closeness = 1L << 15; attr.colorsymbols = cols; attr.numsymbols = 3; attr.valuemask = (XpmColorSymbols | XpmExactColors | XpmAllocCloseColors | XpmCloseness); if (XpmCreatePixmapFromData (dockapp.d, dockapp.win, master_xpm, &dockapp.pixmap, &dockapp.mask, &attr) != XpmSuccess) { fprintf(stderr, "Not enough colors!\n"); exit(-1); } XShapeCombineMask(dockapp.d, dockapp.win, ShapeBounding, 0, 0, dockapp.mask, ShapeSet); XShapeCombineMask(dockapp.d, dockapp.iconwin, ShapeBounding, 0, 0, dockapp.mask, ShapeSet); wmhints.initial_state = WithdrawnState; wmhints.flags = StateHint; wmhints.icon_window = dockapp.iconwin; wmhints.icon_x = sizehints.x; wmhints.icon_y = sizehints.y; wmhints.window_group = dockapp.win; wmhints.flags = StateHint | IconWindowHint | IconPositionHint | WindowGroupHint; XSetWMHints(dockapp.d, dockapp.win, &wmhints); XMapWindow(dockapp.d, dockapp.win); dockapp.xfd = ConnectionNumber(dockapp.d); } /* support function - chop cr/lf off the end of a string */ void chomp(char *buffer) { int i = strlen(buffer) - 1; while (buffer[i] == '\n' || buffer[i] == '\r') { buffer[i--] = '\0'; } } void conf_read(char *filename) { FILE *fp; char buf[1024]; int pos; int line = 0; /* * default settings. overwritten by actual config file. assigned here * with sensible defaults, incase there is no config file or one of * these is missing from the config file */ assign("tx_color", "#00fff2"); assign("rx_color", "#188a86"); assign("md_color", "#71e371"); assign("refresh", "50000"); assign("scroll", "1"); fp = fopen(filename, "r"); if (fp) { /* actually read in the config file, skipping over short and #lines */ while (fgets(buf, 1024, fp)) { line++; if (buf[0] == '#' || (strlen(buf) < 2)) { continue; } chomp(buf); pos = strcspn(buf, "="); if (pos < strlen(buf)) { buf[pos++] = '\0'; assign(buf, buf + pos); } memset(buf, 0, 1024); } fclose(fp); } else { /* can't open the rc file, make a new one */ fprintf(stderr, "Can't open WMND config file %s\n", filename); fprintf(stderr, "Using default settings\n"); conf_write(filename); } /* set stuff here */ wmnd.refresh = atoi(value("refresh")); wmnd.scroll = atoi(value("scroll")); } void conf_write(char *filename) { FILE *fp; struct var *vp; fp = fopen(filename, "w"); if (!fp) { fprintf(stderr, "Can't open config file for writing\n"); exit(1); } fprintf(fp, "# WMND configuration file\n\n"); for (vp = vars; vp; vp = vp->v_next) fprintf(fp, "%s=%s\n", vp->v_name, vp->v_value); fclose(fp); } void assign(char *name, char *value) { struct var *vp; struct var *new; new = (struct var *) malloc(sizeof(struct var)); vdel(name); if (vars == NULL || strcmp(vars->v_name, name) >= 0) { new->v_next = vars; vars = new; } else { vp = vars; while (vp->v_next && strcmp(vp->v_next->v_name, name) <= 0) { vp = vp->v_next; } new->v_next = vp->v_next; vp->v_next = new; } new->v_name = vcopy(name); new->v_value = vcopy(value); } void vdel(char *name) { struct var *vp; struct var *new; while (vars && !strcmp(vars->v_name, name)) { vp = vars->v_next; free((struct var *) vars); vars = vp; } if (vars) for (new = vars; new->v_next;) if (!strcmp(new->v_next->v_name, name)) { vp = new->v_next->v_next; free(new->v_next); new->v_next = vp; } else new = new->v_next; } char *vcopy(char *str) { char *new; unsigned int len; if (str == NULL) return ""; len = strlen(str) + 1; new = malloc(len); memcpy(new, str, len); return new; } char *value(char *name) { struct var *vp; if ((vp = lookup(name)) == NULL) return NULL; return vp->v_value; } struct var *lookup(char *name) { struct var *vp; for (vp = vars; vp; vp = vp->v_next) if (!strcmp(name, vp->v_name)) return vp; return NULL; } void beat_event(void) { unsigned long diff; unsigned int min, hr; char temp[16]; eprint(0, "activated"); if (still_online(wmnd.current)) { if (!bit_get(RUN_ONLINE)) { bit_set(RUN_ONLINE); led_control(LED_POWER, bit_get(RUN_ONLINE)); } } else { if (bit_get(RUN_ONLINE)) { bit_off(RUN_ONLINE); led_control(LED_POWER, bit_get(RUN_ONLINE)); } } diff = difftime(time(NULL), wmnd.pppstart) / 60; min = diff % 60; hr = (diff / 60) % 100; sprintf(temp, "%02d.%02d", hr, min); draw_string(temp, 71, 36); } /* call me after initializing X11 */ void cycle_devices(char *def) { struct Devices *ptr; if (!dockapp.d) fprintf(stderr, "I told you, don't call me before initializing X11\n"); device_list(); /* * dirty hack for setting default device at the beginning hahahaha * gawd this looks like BASIC code */ if (def != NULL) { ptr = lookup_device(def, devices); if (ptr) goto ugly; } /* this will return NULL during the first call cause wmnd.current = NULL */ ptr = lookup_device(wmnd.current, devices); if (ptr != NULL) { if (ptr->next) ptr = ptr->next; else ptr = devices; } else ptr = devices; ugly: strcpy(wmnd.current, ptr->name); eprint(1, "Current: %s", wmnd.current); if (still_online(wmnd.current)) bit_set(RUN_ONLINE); else bit_off(RUN_ONLINE); draw_interface(); } void click_event(unsigned int region, unsigned int button) { char *action = NULL; if (region == -1) /* no region */ return; eprint(1, "clicked btn %d in region %d", button, region); if (region == 0) { switch (button) { case Button1: cycle_devices(NULL); break; case Button3: bit_tgl(CFG_SHORTNAME); eprint(1, "shortname: %d", bit_get(CFG_SHORTNAME)); draw_interface(); break; } } else if (region == 1) { if (button == Button1) { bit_tgl(CFG_MODE); led_control(LED_POWER, bit_get(RUN_ONLINE)); } } else if (region == 2) { if (button == Button1) { if (wmnd.wavemode < 2) wmnd.wavemode++; else wmnd.wavemode = 0; eprint(1, "wavemode: %d", wmnd.wavemode); } } else if (region == 3) { switch (button) { case Button1: /* switch max screen/history */ bit_tgl(CFG_MAXSCREEN); break; case Button3: /* toggle max display */ bit_tgl(CFG_SHOWMAX); break; } } else if (region == 4) { switch (button) { case Button1: action = value("bt1_action"); break; case Button2: action = value("bt2_action"); break; case Button3: action = value("bt3_action"); break; } if (action) execCommand(action); } } int main(int argc, char **argv) { char *dispname = NULL; char *conf_file = NULL; struct Devices *ptr; unsigned long int ib, ob, ip, op; int ch; int btn = 0, rgn = -1; XEvent event; #ifdef PRO int counter = 10000; #endif eprint(1, "wmnd start"); wmnd.wavemode = 2; wmnd.scale = metric_scale; while ((ch = getopt(argc, argv, "bd:i:hvw")) != EOF) { switch (ch) { case 'b': wmnd.scale = binary_scale; break; case 'd': if (optarg) dispname = strdup(optarg); break; case 'i': if (optarg) active_interface = strdup(optarg); break; case 'v': printversion(); exit(0); break; case 'w': wmnd.wavemode = 0; break; default: usage(); exit(0); break; } } wmnd.nr_devices = 0; wmnd.flags = 0; if (!device_list()) { fprintf(stderr, "No network interfaces found, exiting\n"); exit(1); } /* set default config options */ bit_set(RUN_ONLINE); bit_set(CFG_SHORTNAME); bit_set(CFG_SHOWMAX); bit_set(CFG_MAXSCREEN); bit_set(CFG_MODE); if (!conf_file) { char *tmp; tmp = getenv("HOME"); conf_file = calloc(1, strlen(tmp) + 9); strcat(conf_file, tmp); strcat(conf_file, "/.wmndrc"); } conf_read(conf_file); eprint(1, "open X display"); if (!(dockapp.d = XOpenDisplay(dispname))) { fprintf(stderr, "Unable to open display '%s'\n", dispname); exit(-1); } new_window("wmnd", 64, 64); add_mr(0, 3, 3, 38, 9); /* device */ add_mr(1, 54, 3, 7, 9); /* up/down packet/byte mode */ add_mr(2, 3, 22, 58, 31); /* main display area */ add_mr(3, 3, 13, 58, 9); /* scale meter */ add_mr(4, 3, 54, 58, 7); /* user script? huh wtf does that do */ beat_init(wmnd.scroll * 1000000); /* init graph updates */ wmnd.draw = draw_stats; cycle_devices(active_interface); /* set default device name */ eprint(1, "found %d devices [%s]", wmnd.nr_devices, wmnd.current); /* fill the history with stuff so that we don't get total bytes as max after startup and fuckup all the scales */ for (ptr = devices; ptr; ptr = ptr->next) { ptr->ib_max_his = 0; ptr->ob_max_his = 0; ptr->ip_max_his = 0; ptr->op_max_his = 0; get_statistics(ptr->name, &ip, &op, &ib, &ob); ptr->ib_stat_last = ib; ptr->ob_stat_last = ob; ptr->ip_stat_last = ip; ptr->op_stat_last = op; } eprint(1, "looping"); XSync(dockapp.d, False); /* kick off X11 queue */ /* loop forever */ #ifndef PRO #define EVER 1 #else #define EVER (counter--) #endif while (EVER) { char *name; unsigned int j; /* get statistics for each existing device */ for (ptr = devices; ptr; ptr = ptr->next) { name = ptr->name; if (get_statistics(name, &ip, &op, &ib, &ob) == -1) break; ptr->his[57][0] += ib - ptr->ib_stat_last; ptr->his[57][1] += ob - ptr->ob_stat_last; ptr->his[57][2] += ip - ptr->ip_stat_last; ptr->his[57][3] += op - ptr->op_stat_last; ptr->ib_max_his = MAX(ptr->ib_max_his, ptr->his[57][0]); ptr->ob_max_his = MAX(ptr->ob_max_his, ptr->his[57][1]); ptr->ip_max_his = MAX(ptr->ip_max_his, ptr->his[57][2]); ptr->ip_max_his = MAX(ptr->ip_max_his, ptr->his[57][3]); if (!strcmp(ptr->name, wmnd.current)) { /* displayed */ if (ptr->ib_stat_last == ib) { led_control(LED_RX, 0); } else { led_control(LED_RX, 1); } if (ptr->ob_stat_last == ob) { led_control(LED_TX, 0); } else { led_control(LED_TX, 1); } } ptr->ib_stat_last = ib; ptr->ob_stat_last = ob; ptr->ip_stat_last = ip; ptr->op_stat_last = op; } /* end get statistics */ if (beat > 0) { beat_roger(0); beat_event(); /* scroll the statistics */ for (ptr = devices; ptr; ptr = ptr->next) { if (!strcmp(ptr->name, wmnd.current)) { wmnd.draw(ptr); } for (j = 1; j < 58; j++) { ptr->his[j - 1][0] = ptr->his[j][0]; ptr->his[j - 1][1] = ptr->his[j][1]; ptr->his[j - 1][2] = ptr->his[j][2]; ptr->his[j - 1][3] = ptr->his[j][3]; } ptr->his[57][0] = 0; ptr->his[57][1] = 0; ptr->his[57][2] = 0; ptr->his[57][3] = 0; } } while (XPending(dockapp.d)) { eprint(1, "X11 activity"); XNextEvent(dockapp.d, &event); switch (event.type) { case Expose: dockapp.update = 1; redraw_window(); break; case DestroyNotify: XCloseDisplay(dockapp.d); exit(0); break; case ButtonPress: btn = event.xbutton.button; rgn = check_mr(event.xbutton.x, event.xbutton.y); break; case ButtonRelease: if (btn == event.xbutton.button) { if (rgn == check_mr(event.xbutton.x, event.xbutton.y)) { click_event(rgn, btn); } } break; } } redraw_window(); #ifndef PRO usleep(wmnd.refresh); #endif } exit(0); } int device_list(void) { FILE *fd; int found = 0; /* number of devices we'll find */ char temp[MAXBUF]; /* string buffer */ char *tokens = " :\t\n"; /* parse tokens */ char *p; /* ptr into temp */ time_t ts; /* add timestamp */ fd = fopen(NET_DEV, "r"); ts = time(NULL); /* Skip the first 2 lines */ fgets(temp, MAXBUF, fd); fgets(temp, MAXBUF, fd); /* grab all active devices, adding them as we go */ while (fgets(temp, MAXBUF, fd)) { p = strtok(temp, tokens); if (!strncmp(p, "dummy", 5) || !strncmp(p, "irda", 4)) continue; if (strcmp(p, "lo") || (active_interface && !strcmp(active_interface, "lo"))) { add_device(p, &devices, ts); found++; wmnd.draw = draw_stats; } } fclose(fd); while (found < wmnd.nr_devices) { struct Devices *ptr; /* something happened - device is removed */ eprint(1, "detected device removal"); for (ptr = devices; ptr; ptr = ptr->next) { if (ptr->ts < ts) { eprint(1, "delete candidate name: %s, ts: %ld", ptr->name, ptr->ts); strcpy(temp, ptr->name); } } delete_device(temp, &devices); if (!wmnd.nr_devices) { /* we've deleted them all, so add "null0" */ add_device("null0", &devices, ts); wmnd.draw = draw_error; } } return found; } void binary_scale(unsigned char sign, unsigned long value, char *buf) { unsigned char scale; unsigned int i; char *r; if (value > 1073741823) { /* scale in giga */ value = value >> 30; scale = 'G'; } else if (value > 1048575) { /* scale in mega */ value = value >> 20; scale = 'M'; } else if (value > 1023) { /* scale in kilo */ value = value >> 10; scale = 'K'; } else { scale = ' '; } sprintf(buf, "%c%lu", sign, value); /* to string */ r = buf; r++; for (i = 3; i > 0 && *r != '\0'; i--) { if (*r == '+' || *r == '-' || *r == '.') { ++i; } ++r; } *r++ = scale; *r = '\0'; } void metric_scale(unsigned char sign, unsigned long value, char *buf) { float f; unsigned char scale; unsigned int i; char *r; f = (float) value; if (value > 999999999) { /* scale in giga */ f /= 1000000000; scale = 'G'; } else if (value > 999999) { /* scale in mega */ f /= 1000000; scale = 'M'; } else if (value > 999) { /* scale in kilo */ f /= 1000; scale = 'K'; } else { scale = ' '; } sprintf(buf, "%c%f", sign, f); /* to string */ r = buf; r++; for (i = 3; i > 0 && *r != '\0'; i--) { if (*r == '+' || *r == '-' || *r == '.') { ++i; } ++r; } *r++ = scale; *r = '\0'; } void scale(char *rx_buf, char *tx_buf, unsigned long rx, unsigned long tx) { char rx_sign, tx_sign; if (rx > tx) { rx_sign = '+'; tx_sign = '#'; } else if (rx < tx) { rx_sign = '-'; tx_sign = '*'; } else { rx_sign = '-'; tx_sign = '#'; } if (wmnd.scroll != 1) { tx /= wmnd.scroll; rx /= wmnd.scroll; } wmnd.scale(tx_sign, tx, tx_buf); wmnd.scale(rx_sign, rx, rx_buf); } void draw_string(unsigned char *buf, unsigned int x, unsigned int y) { unsigned int w, sx = 0, sy = 0; unsigned int draw; char *r; w = 3; draw = 0; for (r = buf; *r != '\0'; r++) { if (*r >= '0' && *r <= '9') { w = 5; sx = 1 + (w * (*r - '0')); sy = 85; draw = 1; } else if (*r == '.') { w = 2; sx = 62; sy = 85; draw = 1; } else if (*r >= 'A' && *r <= 'Z') { w = 5; sx = 1 + (w * (*r - 'A')); sy = 93; draw = 1; } else if (*r == '+') { w = 6; if (bit_get(CFG_MAXSCREEN)) { sx = 133; sy = 93; } else { sx = 66; sy = 46; } draw = 1; } else if (*r == '-') { w = 6; if (bit_get(CFG_MAXSCREEN)) { sx = 139; sy = 93; } else { sx = 72; sy = 46; } draw = 1; } else if (*r == '*') { w = 6; if (bit_get(CFG_MAXSCREEN)) { sx = 145; sy = 93; } else { sx = 78; sy = 46; } draw = 1; } else if (*r == '#') { w = 6; if (bit_get(CFG_MAXSCREEN)) { sx = 151; sy = 93; } else { sx = 84; sy = 46; } draw = 1; } if (draw) { copy_xpm_area(sx, sy, w, 7, x, y); draw = 0; } x += w; } } void draw_rate(unsigned long rx, unsigned long tx) { char rx_buf[16]; char tx_buf[16]; /* clear rate bar */ copy_xpm_area(100, 85, 58, 7, 3, 54); /* put rx/tx numbers into strings, scaling them */ scale(rx_buf, tx_buf, rx, tx); /* draw rx/tx strings */ draw_string(rx_buf, 3, 54); draw_string(tx_buf, 32, 54); } void draw_max(unsigned long rx, unsigned long tx) { char rx_buf[16]; char tx_buf[16]; /* clear rate bar */ copy_xpm_area(100, 85, 58, 7, 3, 11); /* put rx/tx numbers into strings, scaling them */ scale(rx_buf, tx_buf, rx, tx); /* draw rx/tx strings */ draw_string(rx_buf, 3, 11); draw_string(tx_buf, 32, 11); } void draw_error(struct Devices *ptr) { copy_xpm_area(25, 75, 5, 7, 12, 30); copy_xpm_area(103, 75, 5, 7, 18, 30); copy_xpm_area(103, 75, 5, 7, 24, 30); copy_xpm_area(85, 75, 5, 7, 30, 30); copy_xpm_area(103, 75, 5, 7, 36, 30); } void draw_stats(struct Devices *ptr) { int bpp = 1; /* bytes per pixel */ unsigned int k; unsigned long int *p; unsigned int in, out; unsigned long int rx_max_his, tx_max_his; unsigned long long int rx_max, tx_max, max; unsigned int size; if (bit_get(CFG_SHOWMAX)) size = 35; /* with max bar mode */ else size = 41; /* without max bar */ if (bit_get(CFG_MODE)) { /* bytes mode */ in = 0; out = 1; rx_max_his = ptr->ib_max_his; tx_max_his = ptr->ob_max_his; } else { /* packets mode */ in = 2; out = 3; rx_max_his = ptr->ip_max_his; tx_max_his = ptr->op_max_his; } /* find maximum value in screen history */ rx_max = tx_max = 0; p = (unsigned long *) ptr->his; for (k = 0; k < 58; k++) { rx_max = MAX(rx_max, p[in]); tx_max = MAX(tx_max, p[out]); p += 4; } if ((max = rx_max + tx_max) > size) { bpp = max / size; if ((max % size) > 0) { ++bpp; } } /* draw rx/tx rate */ p -= 4; /* sets p to his[58] or so */ draw_rate(p[in], p[out]); if (bit_get(CFG_MAXSCREEN)) draw_max(rx_max, tx_max); else draw_max(rx_max_his, tx_max_his); p = (unsigned long *) ptr->his; switch (wmnd.wavemode) { case 0: /* traditional mode */ for (k = 0; k < 58; k++) { unsigned int txlev, rxlev, nolev; rxlev = p[in] / bpp; txlev = p[out] / bpp; nolev = size - (rxlev + txlev); copy_xpm_area(66, 0, 1, txlev, k + 3, 53 - (rxlev + txlev)); copy_xpm_area(65, 0, 1, nolev, k + 3, 53 - size); copy_xpm_area(67, 0, 1, rxlev, k + 3, 53 - rxlev); p += 4; } copy_xpm_area(70, 1, 58, 1, 3, 53 - size); break; case 1: /* wave form mode */ for (k = 0; k < 58; k++) { unsigned int txlev, rxlev, center; rxlev = p[in] / bpp / 2; /* we need them like this */ txlev = p[out] / bpp / 2; /* we need it like this */ center = 53 - size / 2; copy_xpm_area(65, 0, 1, size, k + 3, 53 - size); copy_xpm_area(66, 0, 1, txlev, k + 3, (center - rxlev) - txlev); copy_xpm_area(66, 0, 1, txlev, k + 3, (center + rxlev)); copy_xpm_area(67, 0, 1, rxlev * 2, k + 3, center - rxlev); p += 4; } copy_xpm_area(70, 1, 58, 1, 3, 53 - size); copy_xpm_area(70, 0, 58, 1, 3, 53 - size / 2); break; case 2: /* WMNET mode */ for (k = 0; k < 58; k++) { unsigned int txlev, rxlev, nolev; txlev = p[out] / bpp; rxlev = p[in] / bpp; nolev = size - (rxlev + txlev); copy_xpm_area(66, 0, 1, txlev, k + 3, 53 - size); copy_xpm_area(65, 0, 1, nolev, k + 3, (53 - size) + txlev); copy_xpm_area(67, 0, 1, rxlev, k + 3, 53 - rxlev); p += 4; } copy_xpm_area(70, 1, 58, 1, 3, 53 - size); break; } /* copy PPP connection time over the graph */ if (strstr(ptr->name, "ppp")) { copy_xpm_area(70, 36, 23, 7, 37, 46); } } static int get_statistics(const char *devname, unsigned long *ip, unsigned long *op, unsigned long *ib, unsigned long *ob) { FILE *fp; char temp[MAXBUF]; char *p; struct ifpppstatsreq req; static int ppp_opened = 0; static int ppp_h = -1; eprint(0, "device: %s", devname); /* handle special ppp case */ if (!strncmp(devname, "ppp", 3)) { if (!ppp_opened) { struct stat mstat; char pidname[MAXBUF]; snprintf(pidname, strlen(devname) + 14, "/var/run/%s.pid", devname); stat(pidname, &mstat); eprint(1, "pidfile: %s", pidname); wmnd.pppstart = mstat.st_mtime; /* Open the ppp device. */ if ((ppp_h = socket(AF_INET, SOCK_DGRAM, 0)) < 0) { return -1; } ppp_opened = 1; eprint(1, "ppp monitor connection ON\n-- %s", ctime(&wmnd.pppstart)); } memset(&req, 0, sizeof(req)); req.stats_ptr = (caddr_t) & req.stats; sprintf(req.ifr__name, devname); if (ioctl(ppp_h, SIOCGPPPSTATS, &req) < 0) { eprint(1, "ppp monitor disconnected"); close(ppp_h); ppp_opened = 0; wmnd.pppstart = 0; cycle_devices(NULL); return -1; } *op = req.stats.p.ppp_opackets; *ip = req.stats.p.ppp_ipackets; *ib = req.stats.p.ppp_ibytes; *ob = req.stats.p.ppp_obytes; eprint(0, "ppp: ip:%lu op:%lu ib:%lu ob:%lu", *ip, *op, *ib, *ob); return 0; } /* or else, read statistics from /proc/net/dev */ fp = fopen(NET_DEV, "r"); fgets(temp, MAXBUF, fp); fgets(temp, MAXBUF, fp); while (fgets(temp, MAXBUF, fp)) { if (strstr(temp, devname)) { p = strchr(temp, ':'); p++; sscanf(p, "%lu %lu %*s %*s %*s %*s %*s %*s %lu %lu", ib, ip, ob, op); eprint(0, "ip:%lu op:%lu ib:%lu ob:%lu", *ip, *op, *ib, *ob); } } fclose(fp); return 0; } int still_online(char *dev) { FILE *fp; char temp[MAXBUF]; fp = fopen(NET_ROUTE, "r"); while (fgets(temp, MAXBUF, fp)) { if (strstr(temp, dev)) { fclose(fp); return 1; /* Line is alive */ } } fclose(fp); return 0; } static void led_control(const unsigned char led, const unsigned char mode) { eprint(0, "led: %02x[%02x]", led, mode); switch (led) { case LED_POWER: switch (bit_get(CFG_MODE)) { case 1: /* bytes */ if (mode) { /* on-line */ copy_xpm_area(116, 64, 5, 7, 55, 4); } else { /* off-line */ copy_xpm_area(122, 64, 5, 7, 55, 4); } break; case 0: /* packets */ if (mode) { /* on-line */ copy_xpm_area(128, 64, 5, 7, 55, 4); } else { /* off-line */ copy_xpm_area(134, 64, 5, 7, 55, 4); } break; } break; case LED_RX: if (mode) { /* turn on */ if (bit_get(LED_RX)) { eprint(0, "RX led already on"); return; /* already on */ } copy_xpm_area(86, 69, 5, 4, 41, 4); bit_set(LED_RX); eprint(0, "RX led on"); } else { /* turn off */ if (!bit_get(LED_RX)) { eprint(0, "RX led already off"); return; } copy_xpm_area(92, 69, 5, 4, 41, 4); bit_off(LED_RX); eprint(0, "RX led off"); } break; case LED_TX: if (mode) { /* turn on */ if (bit_get(LED_TX)) { eprint(0, "TX led already on"); return; /* already on */ } copy_xpm_area(86, 64, 5, 4, 48, 4); bit_set(LED_TX); eprint(0, "TX led on"); } else { /* turn off */ if (!bit_get(LED_TX)) { eprint(0, "TX led already off"); return; } copy_xpm_area(92, 64, 5, 4, 48, 4); bit_off(LED_TX); eprint(0, "TX led off"); } break; } } void draw_interface(void) { int i; int c; int k = 3; unsigned char temp[7]; /* refresh */ copy_xpm_area(65, 54, 38, 9, 3, 3); led_control(LED_POWER, bit_get(RUN_ONLINE)); if (bit_get(CFG_SHORTNAME)) { strncpy(temp, wmnd.current, 3); temp[3] = wmnd.current[strlen(wmnd.current) - 1]; temp[4] = '\0'; } else { strncpy(temp, wmnd.current, 6); temp[7] = '\0'; } for (i = 0; temp[i]; i++) { c = temp[i]; if (c >= '0' && c <= '9') { c -= '0'; copy_xpm_area(c * 6, 64, 6, 9, k, 3); k += 6; } else { if (c >= 'a' && c <= 'z') c = c - 'a' + 'A'; c -= 'A'; copy_xpm_area(c * 6, 74, 6, 9, k, 3); k += 6; } } } void usage(void) { fprintf(stderr, "\nwmnd - WindowMaker Network Devices v%s\n" "Home page: http://www.wingeer.org/wmnd/\n\n" "usage:\n" " -b base 2 scale (no fractions)\n" " -d \n" " -h this help screen\n" " -i default (as it appears in /proc/net/route)\n" " -v print the version number\n" " -w traditional mode\n" "\n", WMND_VERSION); } void printversion(void) { fprintf(stderr, "%s\n", WMND_VERSION); } wmnd_0.2.1/src/beat.c0100644000175000000120000000466407221077017013220 0ustar reedwheel/* * beat.c * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * History: * * v 0.0.1 2000.05.03 by Reed Lai * replace alarm() with setitimer(), beat resolution up to 1 microsecond * * v 0.0.0 2000.04.28 by Reed Lai * create, use alarm() and SIGALRM, 1 second time beat resolution * */ #define BEAT_DEBUG /* unmark to show beat debug message */ #include "beat.h" struct itimerval itv, oitv; unsigned int beat; unsigned int beat2; /* * beat_next * * set the next time beat * * Arguments: * t time in microseconds */ int beat_next(unsigned long long int t) { itv.it_value.tv_sec = t / 1000000; itv.it_value.tv_usec = t % 1000000; itv.it_interval.tv_sec = itv.it_value.tv_sec; itv.it_interval.tv_usec = itv.it_value.tv_usec; return (setitimer(ITIMER_REAL, &itv, 0)); } /* * beat_close * * restore original itimerval */ void beat_close() { setitimer(ITIMER_REAL, &oitv, &itv); } /* beat_roger */ void beat_roger(int which) { switch (which) { case 0: beat = 0; break; case 1: beat2 = 0; break; } } /* * beat_handler * * routine to handle time beat */ void beat_handler(int sig) { ++beat; ++beat2; } /* * beat_init * * routine to handle time beat * * Arguments: * usecs time in microseconds */ int beat_init(unsigned long long int usecs) { static struct sigaction act; /* clear old beat */ itv.it_interval.tv_sec = 0; itv.it_interval.tv_usec = 0; itv.it_value.tv_sec = 0; itv.it_value.tv_usec = 0; setitimer(ITIMER_REAL, &itv, &oitv); beat = 0; /* set action for alarm */ act.sa_handler = beat_handler; sigemptyset(&act.sa_mask); sigaddset(&act.sa_mask, SIGALRM); sigaction(SIGALRM, &act, NULL); /* rocking roll */ return (beat_next(usecs)); } wmnd_0.2.1/src/beat.h0100644000175000000120000000143007221077017013211 0ustar reedwheel/********************************************************************** **********************************************************************/ /********************************************************************** * * beat.h * * v 0.0.0 2000.04.28 by Reed Lai * * header of beat.c * * History: * * v 0.0.0 2000.04.28 by Reed Lai * create, yeh * **********************************************************************/ #ifndef BEAT_H #define BEAT_H #include #include #include extern struct itimerval itv, oitv; extern unsigned int beat; extern unsigned int beat2; int beat_next(unsigned long long int); void beat_roger(int); void beat_handler(int); int beat_init(unsigned long long int); void beat_close(); #endif /* BEAT_H */ wmnd_0.2.1/src/master.xpm0100644000175000000120000004077507204536723014172 0ustar reedwheel/* XPM */ static char * master_xpm[] = { "160 100 27 1", " c None", ". c #202020", "+ c #00FFFF s tx_color", "@ c #1C8C8C s rx_color", "# c #004941", "$ c #72E572 s md_color", "% c #000000", "& c #333133", "* c #666366", "= c #999599", "- c #22332F", "; c #283C38", "> c #C7C3C7", ", c #B59900", "' c #D8BB00", ") c #188A86", "! c #20B2AE", "~ c #FFDD00", "{ c #00FFF2", "] c #B60418", "^ c #009900", "/ c #FF0724", "( c #00EB00", "_ c #00AD00", ": c #F7F3FF", "< c #1E1E27", "[ c #1F1F22", " .+@# $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ ", " .+@# ########################################################## ", " %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%&* .+@# ", " %..........................................................= .+@# ", " %.-###-.-###-.-###-.-###-..-###-.-###-.;;;;;....;....-;;;-.> .+@# ", " %.#...#.#...#.#...#.#...#..#...#.#...#..;;;....;;;...;...;.> .+@# ", " %.#...#.#...#.#...#.#...#..#...#.#...#..;;;....;;;...;...;.> .+@# ", " %.-###-.-###-.-###-.-###-..-###-.-###-...;....;;;;;..-;;;-.> .+@# ", " %.#...#.#...#.#...#.#...#..#...#.#...#...............;...;.> .+@# ", " %.#...#.#...#.#...#.#...#..#...#.#...#.-;-;-..-;-;-..;...;.> .+@# ", " %.-###-.-###-.-###-.-###-..-###-.-###-.;.;.;..;.;.;..-;;;-.> .+@# ", " %..........................................................> .+@# ", " %##########################################################> .+@# ", " %..........................................................> .+@# ", " %..........................................................> .+@# ", " %..........................................................> .+@# ", " %..........................................................> .+@# ", " %..........................................................> .+@# ", " %##########################################################> .+@# ", " %..........................................................> .+@# ", " %..........................................................> .+@# ", " %..........................................................> .+@# ", " %..........................................................> .+@# ", " %..........................................................> .+@# ", " %..........................................................> .+@# ", " %..........................................................> .+@# ", " %..........................................................> .+@# ", " %..........................................................> .+@# ", " %..........................................................> .+@# ", " %..........................................................> .+@# ", " %..........................................................> .+@# ", " %..........................................................> .+@# ", " %..........................................................> .+@# ", " %..........................................................> .+@# ", " %..........................................................> .+@# ", " %..........................................................> .+@# ", " %..........................................................> .+@# ........................ ", " %..........................................................> .+@# ........................ ", " %..........................................................> .+@# ........................ ", " %..........................................................> .+@# ........................ ", " %..........................................................> .+@# ........................ ", " %..........................................................> .+@# ........................ ", " %..........................................................> .+@# ........................ ", " %..........................................................> .+@# ........................ ", " %..........................................................> .+@# ", " %..........................................................> .+@# ", " %..........................................................> ......................................................................... ", " %..........................................................> .,''',.)!!!)...,.....)...,''',.)!!!)...,.....)...,''',.)!!!)...,.....)... ", " %..........................................................> ...~.....{.....'.....!.....~.....{.....'.....!...,.~...).{.....'.....!... ", " %..........................................................> ...~.....{.....~.....{....'~'...!{!...'~'...!{!..,.~...).{...,.~...).{... ", " %..........................................................> ...'.....!.....~.....{.....'.....!.....~.....{.....'.....!...,.~...).{... ", " %..........................................................> ...,.....)...,''',.)!!!)...,.....)...,''',.)!!!)...,.....)...,''',.)!!!). ", " %..........................................................> ......................................................................... ", " %##########################################################> ", " %..........................................................> .......................................................... ,~,~, ,~~, ", " %..........................................................> .-###-.-###-.-###-.-###-..-###-.-###-.;;;;;....;....-;;;-. ~.~.~ ~..~ ", " %..........................................................> .#...#.#...#.#...#.#...#..#...#.#...#..;;;....;;;...;...;. ", " %..........................................................> .#...#.#...#.#...#.#...#..#...#.#...#..;;;....;;;...;...;. ", " %..........................................................> .-###-.-###-.-###-.-###-..-###-.-###-...;....;;;;;..-;;;-. ", " %..........................................................> .#...#.#...#.#...#.#...#..#...#.#...#...............;...;. ,~,~, ,~~, ", " &..........................................................> .#...#.#...#.#...#.#...#..#...#.#...#.-;-;-..-;-;-..;...;. ~.~.~ ~..~ ", " *=>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> .-###-.-###-.-###-.-###-..-###-.-###-.;.;.;..;.;.;..-;;;-. ", " .......................................................... ", " ", "............................................................................... ..].. ..^.. ..;.. .//. .((. .;;. _(((- ]///- _(((_ ]///] -;;;- ", "..!!!...###).)!!!).)!!!).)###).)!!!).)!!!).)!!!).)!!!).)!!!)................... .]/]. .^(^. .-;-. /:// (:(( ;;;; (...( /.../ (...( /.../ ;...; ", ".!...!.#...!.#...!.#...!.!...!.!...#.!...#.#...!.!...!.!...!............!...... .///. .(((. .;;;. //// (((( ;;;; (...( /.../ (...( /.../ ;...; ", ".!...!.#...!.#...!.#...!.!...!.!...#.!...#.#...!.!...!.!...!.......!....!...... ]///] ^(((^ -;;;- .//. .((. .;;. _(((; ]///; _(((_ ]///] -;;;- ", ".)###)..###).)!!!)..!!!).)!!!).)!!!).)!!!)..###).)!!!).)!!!)..)!...)...!....... (...( /.../ (...; /...; ;...; ", ".!...!.#...!.!...#.#...!.#...!.#...!.!...!.#...!.!...!.#...!...........!....... ]///] ^(((^ -;;;- ]//] _((_ -;;- (...( /.../ (...; /...; ;...; ", ".!...!.#...!.!...#.#...!.#...!.#...!.!...!.#...!.!...!.#...!.......!..!........ .///. .(((. .;;;. //// (((( ;;;; _(((- ]///- _;;;. ];;;. -;;;- ", "..!!!...###).)!!!).)!!!)..###).)!!!).)!!!)..###).)!!!).)!!!).......)..!........ .]/]. .^(^. .-;-. //// (((( ;;;; ", "............................................................................... ..].. ..^.. ..;.. ]//] _((_ -;;- ", " ", "................................................................................................................................................................", ".#!!!#.)!!!...!!!).)!!!..)!!!).)!!!).)!!!).)###)..###)..###).)###).)###..!###!.)!!!..)!!!).)!!!).)!!!).)!!!).)!!!).)!!!).)###).)###).)###).)###).)###).)!!!)....", ".!...!.!...!.!...#.!...!.!...#.!...#.!...#.!...!.#...!.#...!.!...!.!...#.!!.!!.!...!.!...!.!...!.!...!.!...!.!...#.#.!.#.!...!.!...!.!...!.!...!.!...!.#...!....", ".!...!.!...!.!...#.!...!.!...#.!...#.!...#.!...!.#...!.#...!.!...!.!...#.!.!.!.!...!.!...!.!...!.!...!.!...!.!...#.#.!.#.!...!.!...!.!...!..!.!..!...!.#..!#....", ".)!!!).)!!!..)###..)###).)!!!..)!!!..)#)!).)!!!)..###)..###).)!!!..)###..)###).)###).)###).)!!!).)!##).)!!!..)!!!)..#)#..)###).)###).)###)...!...)!!!)..#!#.....", ".!...!.!...!.!...#.!...!.!...#.!...#.!...!.!...!.#...!.#...!.!...!.!...#.!...!.!...!.!...!.!...#.!.!.!.!...!.#...!.#.!.#.!...!.!...!.!.!.!..!.!..#...!.#!..#....", ".!...!.!...!.!...#.!...!.!...#.!...#.!...!.!...!.#...!.#...!.!...!.!...#.!...!.!...!.!...!.!...#.!..!!.!...!.#...!.#.!.#.!...!.!...!.!!.!!.!...!.#...!.!...#....", ".)###).)!!!...!!!).)!!!..)!!!).)###..)!!!).)###)..###).)!!!).)###).)!!!).)###).)###).)!!!).)###..)!!!).)###).)!!!)..#)#..)!!!!..!!!..)###).)###).)!!!).)!!!)....", "................................................................................................................................................................", " ", " ", "................................................................... .......................................................... ", "..!!...##).)!!).)!!).)##).)!!).)!!).)!!).)!!).)!!)................. .......................................................... ", ".!..!.#..!.#..!.#..!.!..!.!..#.!..#.#..!.!..!.!..!..........!...)!. .......................................................... ", ".)##)..##).)!!)..!!).)!!).)!!).)!!)..##).)!!).)!!)..)!..!..!....<[. .......................................................... ", ".!..!.#..!.!..#.#..!.#..!.#..!.!..!.#..!.!..!.#..!.........!....)!. .......................................................... ", "..!!...##).)!!).)!!)..##).)!!).)!!)..##).)!!).)!!)......!.!...{.... .......................................................... ", "................................................................... .......................................................... ", " ", "................................................................................................................................... ......................... ", ".#!!#.)!!...!!).)!!..)!!).)!!).)!!).)##)..##)..##).)##).)##..!##!.)!!..)!!).)!!).)!!).)!!).)!!).)!!).)##).)##).)##).)##).)##).)!!). .,''',.)!!!)...,.....)... ", ".!..!.!..!.!..#.!..!.!..#.!..#.!..#.!..!.#..!.#..!.!.!..!..#.!!!!.!..!.!..!.!..!.!..!.!..!.!..#.#.!#.!..!.!..!.!..!.!..!.!..!.#..!. ..'~'...!{!....'.....!... ", ".)!!).)!!..)##..)##).)!!..)!!..)#)).)!!)..##)..##).)!...)##..)##).)##).)##).)!!).)!#).)!!..)!!)..#)..)##).)##).)##)..!!..)!!)..#!.. ..,~,...){)...,~,...){).. ", ".!..!.!..!.!..#.!..!.!..#.!..#.!..!.!..!.#..!.#..!.!.!..!..#.!..!.!..!.!..!.!..#.!.!!.!..!.#..!.#.!#.!..!.!..!.!..!.!..!.#..!.#!.#. ...'.....!....'~'...!{!.. ", ".)##).)!!...!!).)!!..)!!).)##..)!!).)##)..##).)!!).)##).)!!).)##).)##).)!!).)##..)!!!.)##).)!!)..#)..)!!!..!!..)##).)##).)!!).)!!). ...,.....)...,''',.)!!!). ", "...................................................................................!............................................... ......................... "}; wmnd_0.2.1/src/misc.c0100644000175000000120000000704507221077017013234 0ustar reedwheel/* * dock.c- built-in Dock module for WindowMaker WindowMaker window * manager Copyright (c) 1997 Alfredo K. Kojima This program is free * software; you can redistribute it and/or modify it under the terms of * the GNU General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) any * later version. 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. */ #include #include #include "list.h" #include "misc.h" /* *---------------------------------------------------------------------- * parse_command-- * Divides a command line into a argv/argc pair. *---------------------------------------------------------------------- */ #define PRC_ALPHA 0 #define PRC_BLANK 1 #define PRC_ESCAPE 2 #define PRC_DQUOTE 3 #define PRC_EOS 4 #define PRC_SQUOTE 5 typedef struct { short nstate; short output; } DFA; static DFA mtable[9][6] = { {{3, 1}, {0, 0}, {4, 0}, {1, 0}, {8, 0}, {6, 0}}, {{1, 1}, {1, 1}, {2, 0}, {3, 0}, {5, 0}, {1, 1}}, {{1, 1}, {1, 1}, {1, 1}, {1, 1}, {5, 0}, {1, 1}}, {{3, 1}, {5, 0}, {4, 0}, {1, 0}, {5, 0}, {6, 0}}, {{3, 1}, {3, 1}, {3, 1}, {3, 1}, {5, 0}, {3, 1}}, {{-1, -1}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}}, /* final state */ {{6, 1}, {6, 1}, {7, 0}, {6, 1}, {5, 0}, {3, 0}}, {{6, 1}, {6, 1}, {6, 1}, {6, 1}, {5, 0}, {6, 1}}, {{-1, -1}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}}, /* final state */ }; char *next_token(char *word, char **next) { char *ptr; char *ret, *t; int state, ctype; t = ret = malloc(strlen(word) + 1); ptr = word; state = 0; *t = 0; while (1) { if (*ptr == 0) ctype = PRC_EOS; else if (*ptr == '\\') ctype = PRC_ESCAPE; else if (*ptr == '"') ctype = PRC_DQUOTE; else if (*ptr == '\'') ctype = PRC_SQUOTE; else if (*ptr == ' ' || *ptr == '\t') ctype = PRC_BLANK; else ctype = PRC_ALPHA; if (mtable[state][ctype].output) { *t = *ptr; t++; *t = 0; } state = mtable[state][ctype].nstate; ptr++; if (mtable[state][0].output < 0) { break; } } if (*ret == 0) t = NULL; else t = strdup(ret); free(ret); if (ctype == PRC_EOS) *next = NULL; else *next = ptr; return t; } extern void parse_command(char *command, char ***argv, int *argc) { LinkedList *list = NULL; char *token, *line; int count, i; line = command; do { token = next_token(line, &line); if (token) { list = list_cons(token, list); } } while (token != NULL && line != NULL); count = list_length(list); *argv = malloc(sizeof(char *) * count); i = count; while (list != NULL) { (*argv)[--i] = list->head; list_remove_head(&list); } *argc = count; } extern pid_t execCommand(char *command) { pid_t pid; char **argv; int argc; parse_command(command, &argv, &argc); if (argv == NULL) { return 0; } if ((pid = fork()) == 0) { char **args; int i; args = malloc(sizeof(char *) * (argc + 1)); if (!args) exit(10); for (i = 0; i < argc; i++) { args[i] = argv[i]; } args[argc] = NULL; execvp(argv[0], args); exit(10); } return pid; } wmnd_0.2.1/src/README0100644000175000000120000000026107204547606013015 0ustar reedwheeldon't edit master.xpm using gimp or any other image editing tool. or if you do, make sure and restore the symbolic color names (see inside file). better just not mess with it. wmnd_0.2.1/src/list.c0100644000175000000120000000712107221077017013247 0ustar reedwheel/* * Generic single linked list to keep various information Copyright (C) * 1993, 1994 Free Software Foundation, Inc. * * * Author: Kresten Krab Thorup * * Many modifications by Alfredo K. Kojima * * * This file is part of GNU CC. * * GNU CC is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License as published by the Free * Software Foundation; either version 2, or (at your option) any later * version. * * GNU CC 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 GNU CC; see the file COPYING. If not, write to the Free Software * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* * As a special exception, if you link this library with files compiled * with GCC to produce an executable, this does not cause the resulting * executable to be covered by the GNU General Public License. This * exception does not however invalidate any other reasons why the * executable file might be covered by the GNU General Public License. */ #include "list.h" #ifdef HAVE_SYS_TYPES_H # include #endif #include /* * Return a cons cell produced from (head . tail) */ INLINE LinkedList *list_cons(void *head, LinkedList * tail) { LinkedList *cell; cell = (LinkedList *) malloc(sizeof(LinkedList)); cell->head = head; cell->tail = tail; return cell; } /* * Return the length of a list, list_length(NULL) returns zero */ INLINE int list_length(LinkedList * list) { int i = 0; while (list) { i += 1; list = list->tail; } return i; } /* * Return the Nth element of LIST, where N count from zero. If N larger * than the list length, NULL is returned */ INLINE void *list_nth(int index, LinkedList * list) { while (index-- != 0) { if (list->tail) list = list->tail; else return 0; } return list->head; } /* * Remove the element at the head by replacing it by its successor */ INLINE void list_remove_head(LinkedList ** list) { if (!*list) return; if ((*list)->tail) { LinkedList *tail = (*list)->tail; /* fetch next */ *(*list) = *tail; /* copy next to list head */ free(tail); /* free next */ } else { /* only one element in list */ free(*list); (*list) = 0; } } /* * Remove the element with `car' set to ELEMENT */ /* * INLINE void list_remove_elem(LinkedList** list, void* elem) { while * (*list) { if ((*list)->head == elem) list_remove_head(list); *list = * (*list ? (*list)->tail : NULL); } } */ INLINE LinkedList *list_remove_elem(LinkedList * list, void *elem) { LinkedList *tmp; if (list) { if (list->head == elem) { tmp = list->tail; free(list); return tmp; } list->tail = list_remove_elem(list->tail, elem); return list; } return NULL; } /* * Return element that has ELEM as car */ INLINE LinkedList *list_find(LinkedList * list, void *elem) { while (list) { if (list->head == elem) return list; list = list->tail; } return NULL; } /* * Free list (backwards recursive) */ INLINE void list_free(LinkedList * list) { if (list) { list_free(list->tail); free(list); } } /* * Map FUNCTION over all elements in LIST */ INLINE void list_mapcar(LinkedList * list, void (*function) (void *)) { while (list) { (*function) (list->head); list = list->tail; } } wmnd_0.2.1/src/list.h0100644000175000000120000000364507221077017013263 0ustar reedwheel/* * Generic single linked list to keep various information Copyright (C) * 1993, 1994 Free Software Foundation, Inc. * * Author: Kresten Krab Thorup * * This file is part of GNU CC. * * GNU CC is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License as published by the Free * Software Foundation; either version 2, or (at your option) any later * version. * * GNU CC 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 GNU CC; see the file COPYING. If not, write to the Free Software * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* * As a special exception, if you link this library with files compiled * with GCC to produce an executable, this does not cause the resulting * executable to be covered by the GNU General Public License. This * exception does not however invalidate any other reasons why the * executable file might be covered by the GNU General Public License. */ #ifndef __LIST_H_ #define __LIST_H_ #if defined(__GNUC__) && !defined(__STRICT_ANSI__) # define INLINE inline #else # define INLINE #endif typedef struct LinkedList { void *head; struct LinkedList *tail; } LinkedList; INLINE LinkedList *list_cons(void *head, LinkedList * tail); INLINE int list_length(LinkedList * list); INLINE void *list_nth(int index, LinkedList * list); INLINE void list_remove_head(LinkedList ** list); INLINE LinkedList *list_remove_elem(LinkedList * list, void *elem); INLINE void list_mapcar(LinkedList * list, void (*function) (void *)); INLINE LinkedList *list_find(LinkedList * list, void *elem); INLINE void list_free(LinkedList * list); #endif wmnd_0.2.1/src/misc.h0100644000175000000120000000025007221077017013230 0ustar reedwheel#ifndef __MISC_H #define __MISC_H #include extern void parse_command(char *, char ***, int *); extern pid_t execCommand(char *); #endif /* __MISC_H */ wmnd_0.2.1/Makefile0100644000175000000120000000232607221077013012777 0ustar reedwheelPJ = wmnd VERSION = 0.2.1 PRE = # source code directory SRC = src/ MAN = man/ VPATH = $(SRC):$(MAN) # Optimizing #CFLAGS = -Wall -O3 -mcpu=i586 -fomit-frame-pointer -pipe CFLAGS = -Wall -O3 -fomit-frame-pointer -pipe # Profiling #CFLAGS = -Wall -ansi -pg -g -O3 -pipe -D_GNU_SOURCE -DPRO # Test coverage #CFLAGS = -fprofile-arcs -ftest-coverage -Wall -pipe -DPRO LDFLAGS = -L/usr/X11R6/lib -lXpm -lXext -lX11 OBJS = wmnd.o beat.o misc.o list.o prefix = /usr/local/ bindir = $(prefix)/bin/ mandir = $(prefix)/man/ datadir = $(prefix)/share/ docdir = $(datadir)/doc/$(PJ)/ all: $(PJ) $(PJ): $(OBJS) %.gz: % gzip -c9 $^ > $@ clean: $(foreach dir,./ $(subst :, ,$(VPATH)),cd $(dir) && rm -f *.o wmnd *~ .*.swp trace *.bb *.bbg *.gcov *.da *.out *.gz && cd - && ) echo done. install: $(PJ) wmnd.1.gz set -e install -d $(bindir)/ $(mandir)/man1/ $(docdir)/example/ install -m 755 wmnd $(bindir)/ install wmndrc $(docdir)/example/ install wmnd.1.gz $(mandir)/man1/ package: indent clean rm -f ../$(PJ)_$(VERSION)*.tar.gz (cd .. && tar -cf - $(PJ)_$(VERSION) | gzip -c > $(PJ)_$(VERSION)$(PRE).tar.gz) indent: indent -kr $(SRC)/*.c $(SRC)/*.h # indent -orig *.c *.h .PHONY = all clean install package indent # vim:nosta wmnd_0.2.1/README0100644000175000000120000000227707214073046012230 0ustar reedwheelWMND -------------------------------------------------------------- Web site: http://www.wingeer.org/wmnd/ Author: Reed Lai http://www.wingeer.org/bv4qo/ Description -------------------------------------------------------------- WMND (WindowMaker Network Devices) is a network monitoring dock app improved and based on WMiFS 1.3b. The version 0.2 of wmnd is almost totally written by Timecop, given the optimization and flexibility. Enjoy! Files -------------------------------------------------------------- README This file. INSTALL Installation instructions. HINTS Hints about what you can do with WMND. CHANGELOGS Description of changes. TODO Things we've already planned for WMND. COPYING GNU General Public License Version 2. Bugs -------------------------------------------------------------- If you discover any bugs in this software, please post it to http://www.wingeer.org/wmnd/wall/ Please describe the problems in as much detail as you can. Copyright -------------------------------------------------------------- WMND is copyright (c) 2000 by Reed Lai and licensed under the GNU General Public License. Read the COPYING file for the complete GNU license. wmnd_0.2.1/HINTS0100644000175000000120000000516507214100573012153 0ustar reedwheelHints for WMND Generic -------------------------------------------------------------- WMND supports commandline options, 'wmnd -h' prints help about them. Use option -i to monitor a particular interface at startup: wmnd -i eth0 & wmnd -i ppp0 & wmnd -i lo & Without the -i option, wmnd will automagicly use the interface that is first found in /proc/net/dev, but skip the lo and irda. Active Interface You can cycle in realtime through all available active interfaces by simply left-clicking on the interface name gadget on the upperleft corner of wmnd. The 'lo' interface is an exception, 'lo' ONLY works when invoked from the commandline (wmnd -i lo), lo was mainly built in for testing purposes. Device Name By default, wmnd show device name in short term of four characters, for example, the ippp0 will be displayed as ipp0. You can toggle the device name between short and long by right-click on it. Graphic Mode Left-click on the main graphic area to cycle the graphic mode. Max Meter Left-click to toggle the history max or screen max, default is screen max when wmnd is startup. Right-click to hide or display. Byte/Packet Mode Left-click on the letter gadgeted on the right-top corner can switch between the Byte or Packet counter mode. "B" for byte, "p" for packet. User Script Click on the bottom rate meter can invoke the user command defined in resource file .wmndrc. Dragging WMND Be sure to drag WMND on it's outer edges, it's a bit picky due to the large gfx pixmap it keeps ;-). You can also use a keyboard+mouse shortcut (perhaps ALT+left-click) in your window manager to drag it around. WindowMaker -------------------------------------------------------------- WindowMaker users simply drag and drop the WMND dock.app on the WindowMaker Dock (preferred) or on the Fiend, and then press the rightmouse button on the outer edges of WMND and then enable 'Autolaunch' from the Dock popup menu. Afterstep -------------------------------------------------------------- Afterstep users put the following in their .steprc "Wharf wmnd - MaxSwallow "wmnd" wmnd -i eth0 -w &". Other WindowManagers -------------------------------------------------------------- For other windowmanagers, WMND runs nicely as 64x64 pixel shaped icon on your desktop. p.s. FVWM can swallow it too, so we've heard ;-) Creating PPP dialup scripts -------------------------------------------------------------- Because a very good PPP HowTo already exists, it's quite pointless for us to explain to you how you should and can make them. Read the PPP HowTo, and you'll see that it's very easy to create your own PPP scripts. wmnd_0.2.1/CREDIT0100644000175000000120000000175507213047521012243 0ustar reedwheelCredits for wmnd This file lists names of people who have helped with the project of wmnd in one way or another. Since bug reports was logged to web page http://www.wingeer.org/wmnd/bugreport.shtml, I did not log them here. However, this file was created too late, if you feel you should be mentioned here, please drop a note to wmnd@wingeer.org Arthur Korn Wmnd man page author. Makefile maintenance. Debian package maintenance: http://www.korn.ch/arthur/wmnd-deb/ Michael Leuchtenburg http://otter.yi.org/ Web site adminstration: http://www.wingeer.org/wmnd/ English refinement of articles Paul van Tilburg (Mozillion) http://www.utopiamoo.net/ Provides ultimate test environment for function and stability of wmnd. Reed Lai http://www.wingeer.org/bv4qo/ Project initiation. Timecop http://www.ne.jp/asahi/linux/timecop/ Source code optimization (Re-wrote the source code of wmnd 0.2.0) wmnd_0.2.1/todo/0040755000175000000120000000000007214065227012312 5ustar reedwheelwmnd_0.2.1/todo/TODO.0.1.00100644000175000000120000000147707214065016013437 0ustar reedwheelTODO list for WMND. ------------------------------------------------------------------------ Your feedback! If you have nice suggestions, ideas, whatever, that aren't on this list, feel free to post to Wall or mail them to me :) Reduce dirty and redundant codes, and debug. WMND is a great tool! I like it! But it would be even better if there's the possibility of adding a timer like in wmppp (pretty useful the timer in the countries where the phone costs a lot of $$) Thanks to Pascal Jermini Colors changable for your favor or video enhancement. Thanks to Mark Manning A larger font version? Thanks to Mark Manning Use the libdockapp? Thanks to Paulo E. Abreu TODO are updated at web page http://www.wingeer.org/wmnd/todo.shtml wmnd_0.2.1/wmndrc0100644000175000000120000000110707214071754012560 0ustar reedwheel# WMND configuration file # middle line in wave mode color md_color=#71e371 # RX/TX color (can be #xxxxxx, or color name from rgb.txt) rx_color=#188a86 tx_color=#00fff2 # refresh between status polling (not graph scroll speed) # numbering in nanoseconds refresh=50000 # bar graph scroll speed (in seconds) this setting also affectsi # the rate and max speed displays. the longer the delay, more # inaccurate these are since the max and rate values are averaged # across this interval scroll=1 # buttons for user scripts # bt1_action=su -c ethereal # bt2_action= # bt3_action=