pax_global_header00006660000000000000000000000064116313344400014511gustar00rootroot0000000000000052 comment=9e266af43776f97c997452d03bae112de098657a slurm-0.4.0/000077500000000000000000000000001163133444000126545ustar00rootroot00000000000000slurm-0.4.0/.cvsignore000066400000000000000000000001611163133444000146520ustar00rootroot00000000000000slurm slurm.core slurm.o .slurm.c.swp slurm.gmon config.h config.log config.status autom4te.cache .deps stamp-h1 slurm-0.4.0/AUTHORS000066400000000000000000000000461163133444000137240ustar00rootroot00000000000000Hendrik Scholz slurm-0.4.0/COPYING000066400000000000000000000431101163133444000137060ustar00rootroot00000000000000 GNU GENERAL PUBLIC LICENSE Version 2, June 1991 Copyright (C) 1989, 1991 Free Software Foundation, Inc. 59 Temple Place, Suite 330, Boston, MA 02111-1307 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 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) 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 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) year 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. slurm-0.4.0/COPYRIGHT000066400000000000000000000014111163133444000141440ustar00rootroot00000000000000Copyright ========= slurm is copyright (c) 2002 by Hendrik Scholz and licensed through the GNU General Public License. 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, 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. slurm-0.4.0/ChangeLog000066400000000000000000000242371163133444000144360ustar00rootroot000000000000002011-09-05 Matthias Schmitz * tag version 0.4.0 * Remove gnu build system, use scons instead * Add support for GNU/kFreeBSD * Probably break support for any other os than Linux and kFreeBSD ( will fixed soon ) - tag SLURM-0_3_3 2004-10-12 Hendrik Scholz * Makefile: * config.guess: * config.sub: - update config.* to allow configure run on DragonFly BSD (i386 only) 2004-09-28 Hendrik Scholz * Makefile: * configure: * configure.in: bump to VERSION 0.3.3 2004-09-28 Hendrik Scholz * README: minor OS updates * os.h: allow compilation on Sun Forte CC systems again * slurm.c: (main): * theme.c: (theme_readfile): remove NOTICE error * themes/black.theme: new theme 2004-09-27 Hendrik Scholz * src/if_media.c: (get_if_speed): - use better CPP magic to detect OS features - allow compilation on a few OpenBSD systems again 2004-05-27 Hendrik Scholz * .cvsignore: * os.h: * src/if_media.c: (get_if_speed): - add validinterface() check on Mac OS X 2004-02-13 Hendrik Scholz * Makefile: * Makefile.in: * aclocal.m4: * config.h.in: * configure: * configure.in: * slurm.c: (usage): * slurm.h: - remove version name from OS for 'darwin' aka Mac OS X - s/VERSION/PACKAGE_VERSION/ 2004-02-13 Hendrik Scholz * AUTHORS: * COPYING: * Changelog: * INSTALL: * Makefile: * Makefile.am: * Makefile.in: * THEMES: * THEMES.txt: * aclocal.m4: * config.guess: * config.h.in: * config.sub: * configure: * configure.in: * depcomp: * install-sh: * missing: * mkinstalldirs: - major config subsystem replacement - mv THEMES THEMES.txt (welcome to Mac OS X :)) 2004-02-05 Hendrik Scholz * src/if_media.c: (get_if_speed): - add support for pre 4.5-RELEASE FreeBSD (tested on 4.2-REL :)) 2004-02-05 Hendrik Scholz * FAQ: added Linux media Q/A * README: s/raisdorf/wormulon/ * slurm.1: s/raisdorf/wormulon/, added -L option * slurm.c: (slurm_shutdown): s/raisdorf/wormulon/ * slurm.spec: s/raisdorf/wormulon/ * theme.c: (theme_readfile): added -D__Debian__ to search for themes in /usr/share rather than /usr/local/share 2004-02-05 Hendrik Scholz * Makefile: * Makefile.in: add -DWITH_LED per default * slurm.c: (update_stat_large), (update_stat_split), (update_stat_combined), (usage), (draw_face), (main): * slurm.h: - add -L switch to enable LED 2003-10-07 Hendrik Scholz * Makefile: * Makefile.in: * theme.c: (theme_readfile): - reduce overhead in upcoming NetBSD port upgrade 2003-09-18 Hendrik Scholz * TODO: upd * slurm.spec: initial specfile based on 0.2.3 Thu Sep 11 14:08:07 CEST 2003 - clean up Solaris code - 0.3.1 RELEASE Wed Sep 10 21:18:32 CEST 2003 - print usage information if no interface was given at startup Wed Sep 10 21:03:59 CEST 2003 - add Mac OS X support (thanks Jan-Eric Kolbe for providing access!) - 0.3.1-pre2 Mon Sep 8 23:22:00 CEST 2003 - calculate traffic right when using -d option Sat Sep 6 06:01:27 EDT 2003 - disable LED (set -DWITH_LED to enable them) - moved left part of statistics left to allow traffic > 10.000kBytes/s - make slurm Gbit-safe (tests with >100MByte/s will be done soon :)) - make -Wall happy on Linux Fri Aug 22 06:20:36 EDT 2003 - fix 32bit signed vs. unsigned bug - improve Linux /proc/net/dev parsing Sat Aug 16 16:06:32 CEST 2003 - 0.3.0 release - again modify sleep stuff to recognize input while sleeping Wed Aug 13 00:16:57 CEST 2003 - unify sleep method Wed Aug 13 00:03:21 CEST 2003 - add 'make prof' target for profiling and update .cvsignore Thu Aug 7 04:21:01 CEST 2003 - use sleep() instead of usleep() for sleep durations longer than one second on Linux to prevent wasting cpu cycles - update FAQ, README and add THEMES file Wed Jul 9 18:44:24 CEST 2003 - add FAQ - add -Wall to compile flags Wed Jul 9 18:39:26 CEST 2003 - add signalhandler for various signal so killing slurm doesn't leave a scrambled terminal behind - add -t option to usage() Sun May 25 16:44:49 CEST 2003 - remove -H option and make it default - add initial theme engine (only tested on FreeBSD! until now) Sun May 4 13:55:46 CEST 2003 - catch up on FreeBSDs include/net/if_media.h since the typos have been fixed. Sun Apr 27 18:12:49 CEST 2003 - change data_type structure so we won't get into trouble displaying up to 999999.999GB Sat Apr 19 20:09:29 CEST 2003 - add THE missing 'E' Tue Apr 8 22:58:45 CEST 2003 - Solaris interface speed detection code added to src/if_media.c Wed Apr 2 00:00:34 CEST 2003 - add Solaris support to auto* stuff so slurm can be build on Solaris with just ./configure && make Wed Mar 26 23:43:54 CET 2003 - add -z command line option and 'z' key to virtually reset all counters Thu Mar 20 23:23:46 CET 2003 - fix padding problems with speeds changing dimensions Mon Feb 24 19:55:56 CET 2003 - NetBSD support w/ curses only Sun Feb 23 18:26:40 CET 2003 - auto* updates - add checkinterface() for Linux - unify checkinterface() in src/.h - manpage update Thu Feb 20 21:06:22 CET 2003 - use autoconf for Makefile generation Wed Feb 19 17:12:37 CET 2003 - -d delay option (also suggested bt Joe Laffey) Tue Feb 18 23:27:55 CET 2003 - slurm now has transparent graphics (for Eterm, aterm, ...) Tue Feb 18 20:06:22 CET 2003 - add -H flag to display hostname in title as suggested by Joe Laffey Mon Feb 17 22:14:58 CET 2003 - full MicroBSD support using OpenBSD functions Thu Feb 13 10:57:15 CET 2003 - swap rx and tx in large view Fri Feb 7 20:58:12 CET 2003 - slurm 0.2.0 - minor string length fix in split mode Wed Feb 5 19:50:51 CET 2003 - some really minor changes made it into the tree, the most important of them is a small fix the the Linux networking code to fix the 32bit counter overflow issue Jan 10 18:57:20 CET 2003 - add more accurate FreeBSD version description to src/if_media.c so older FreeBSD releases don't break due to missing defines Tue Dec 31 23:24:53 CET 2002 - slurm 0.0.10 Tue Dec 31 20:52:30 MET 2002 - added Solaris curses support. The network code was already working so now slurm can be used on Solaris. Further tests will follow. See TODO for status. Tue Dec 31 01:38:43 CET 2002 - utilize a small char array as temporary storage for all changing strings we print so we can prevent leaving garbage on the screen Tue Dec 31 00:52:54 CET 2002 - revert src/linux.c to 0.0.8 as my untested 0.0.9 version did not work as expected. Thanks to Felix von Leitner for mentioning this. Sat Dec 28 13:41:06 CET 2002 - add another NetBSD Gbit Ethernet type Wed Dec 25 21:00:40 CET 2002 - remove check if interface if up from src/if_media.c as it is causing more and more problems. - speed up interface detection code for NetBSD and OpenBSD while I'm at it Wed Dec 25 12:11:19 CET 2002 - prevent calculation of negative rx/tx speed in case of a 32bit counter overflow Wed Dec 25 10:57:03 CET 2002 - added FreeBSD -stable Wireless speed definitions to src/if_media.c Mon Dec 23 14:00:00 CET 2002 - slurm 0.0.9 released Mon Dec 23 13:19:05 CET 2002 - speedup src/linux.c by fseeking() to the third line before starting to parse each line until we get the needed information Mon Dec 23 12:53:55 CET 2002 - (re)add -s cli option Sat Dec 21 15:29:12 CET 2002 - added Solaris support in the meanwhile. Network stuff works but curses causes segmentation faults. Sat Dec 7 17:00:39 CET 2002 - slurm 0.0.8 Sat Dec 7 16:51:11 CET 2002 - update_() functions now save more data than needed for seamless display mode switching Fri Dec 6 00:44:21 CET 2002 - OpenBSD 2.9 (others?) compile fix - OpenBSD BNC media detection fix (ugly workaround but OpenBSD doesn't seem to set the correct status bits) Wed Dec 4 14:44:20 CET 2002 - improve the HPUX support Wed Dec 4 00:10:20 CET 2002 - added Linux sanity checks and more documentation - remove annoying compiler warnings on Linux for src/if_media.c Tue Dec 3 23:59:16 CET 2002 - added initial HPUX support (thanks Oliver Lehmann) - tagged as SLURM-0_0_8PRE3 Tue Nov 19 00:17:40 CET 2002 - added KEYS file, please read it as there are helpful keys :) I guess it's time for a manpage now Mon Nov 18 23:48:54 CET 2002 - added a new "large split window" mode Fri Nov 15 18:11:07 CET 2002 - add checkinterface() for NetBSD and OpenBSD Wed Nov 13 13:45:53 CET 2002 - NetBSD port Wed Nov 13 07:35:04 CET 2002 - fix 32bit counter overruns Wed Nov 13 07:25:21 CET 2002 (done last night :)) - added OpenBSD support - fixed some ugla off-by-one errors which lead to crashes on OpenBSD and broken graphs in some cases. Mon Nov 11 19:48:11 CET 2002 - code cleanup Mon Nov 11 19:24:05 CET 2002 - FreeBSD -current fix - Bandwidth detection now prints correct strings Mon Nov 11 00:00:34 CET 2002 - fix build problems on FreeBSD -current Sun Nov 10 20:18:57 CET 2002 - merged split and combined view - command line option -c switched back to the classic view - operating system dependend functions moved to src/ Sun Nov 10 18:51:46 CET 2002 - finally added a working splitted view for RX and TX - interface speed detection moved to src/if_media.[ch] Sat Nov 2 00:52:18 CET 2002 - finished getopt() interface and checks for FreeBSD Fri Nov 1 23:50:33 CET 2002 - added compilier flags to produce more errors :) - major graph upgrade so the graph scales up/down to give a better overview Tue Oct 29 23:46:08 CET 2002 - added basic Linux support Sun Oct 27 20:21:12 CET 2002 - solved 32bit counter issues by adding an overflow counter - fixed curses problems Sat Oct 26 18:58:20 CEST 2002 - cannot read speed on tun devices. returns 115200 for my pppoe link - curses problems - received/sent bytes are only 32bit slurm-0.4.0/FAQ000066400000000000000000000042011163133444000132030ustar00rootroot00000000000000This is just kinda Q & A thing, in case you miss something just send a mail to hscholz@wormulon.net. _______________________________________________________________________________ Q: Why does slurm have themes? A: Because it can. Q: I want to use slurm to do traffic accounting or MRTG graphs ... A: slurm will not support this. Feel free to use the data gathering code from src/. I've started a small project called wormulon (http://www.wormulon.net/wormulon) which utilizes the slurm codebase to create output suitable for inclusion in mrtg, rrdtool or even the screen hardstatus line. Q: Can I include slurm into the screen hardstatus line? A: See previous question and have a look at wormulon. Q: WTF is 'slurm'? / How did it all start? A: The idea came up while installing Linux systems during a small Linux installation party. Using pppstatus to monitor the ADSL uplink I did not find any equivalent app for *BSD. Lacking a similar application I removed the Linux dependent ppp code from pppstatus and added FreeBSD sysctl() code for data aquisation at ~3AM the same night. Ripping off the connection time accounting and email checks I ended up with something useful. Adding it to my CVS repository it needed a name, so the first thing that came into my mind was 'slurm' since I just saw the latest Futurama episode featuring 'Slurm Mc Kenzie' and the 'Slurm Factory', hence the name slurm. P.S. wormulon which is based on slurm is the name of the homeplanet of Slurm McKenzie. Q: Why are you not showing link information like 100MBits on Linux? A: Linux does not have a common way to save media type an link information. Gathering those information with tools like mii-tool or ethtool involve reading data directly from the ethernet cards EEPROM and success depends the card. Have a look at the ethtool source code if you want to know how nasty the whole thing might get. Integrating this slurm would need suid root privileges on Linux which is normally a bad idea. _______________________________________________________________________________ $Id: FAQ,v 1.3 2004/02/06 02:33:54 hscholz Exp $ slurm-0.4.0/INSTALL000066400000000000000000000172271163133444000137160ustar00rootroot00000000000000Basic Installation ================== These are generic installation instructions. The `configure' shell script attempts to guess correct values for various system-dependent variables used during compilation. It uses those values to create a `Makefile' in each directory of the package. It may also create one or more `.h' files containing system-dependent definitions. Finally, it creates a shell script `config.status' that you can run in the future to recreate the current configuration, a file `config.cache' that saves the results of its tests to speed up reconfiguring, and a file `config.log' containing compiler output (useful mainly for debugging `configure'). If you need to do unusual things to compile the package, please try to figure out how `configure' could check whether to do them, and mail diffs or instructions to the address given in the `README' so they can be considered for the next release. If at some point `config.cache' contains results you don't want to keep, you may remove or edit it. The file `configure.in' is used to create `configure' by a program called `autoconf'. You only need `configure.in' if you want to change it or regenerate `configure' using a newer version of `autoconf'. The simplest way to compile this package is: 1. `cd' to the directory containing the package's source code and type `./configure' to configure the package for your system. If you're using `csh' on an old version of System V, you might need to type `sh ./configure' instead to prevent `csh' from trying to execute `configure' itself. Running `configure' takes awhile. While running, it prints some messages telling which features it is checking for. 2. Type `make' to compile the package. 3. Optionally, type `make check' to run any self-tests that come with the package. 4. Type `make install' to install the programs and any data files and documentation. 5. You can remove the program binaries and object files from the source code directory by typing `make clean'. To also remove the files that `configure' created (so you can compile the package for a different kind of computer), type `make distclean'. There is also a `make maintainer-clean' target, but that is intended mainly for the package's developers. If you use it, you may have to get all sorts of other programs in order to regenerate files that came with the distribution. Compilers and Options ===================== Some systems require unusual options for compilation or linking that the `configure' script does not know about. You can give `configure' initial values for variables by setting them in the environment. Using a Bourne-compatible shell, you can do that on the command line like this: CC=c89 CFLAGS=-O2 LIBS=-lposix ./configure Or on systems that have the `env' program, you can do it like this: env CPPFLAGS=-I/usr/local/include LDFLAGS=-s ./configure Compiling For Multiple Architectures ==================================== You can compile the package for more than one kind of computer at the same time, by placing the object files for each architecture in their own directory. To do this, you must use a version of `make' that supports the `VPATH' variable, such as GNU `make'. `cd' to the directory where you want the object files and executables to go and run the `configure' script. `configure' automatically checks for the source code in the directory that `configure' is in and in `..'. If you have to use a `make' that does not supports the `VPATH' variable, you have to compile the package for one architecture at a time in the source code directory. After you have installed the package for one architecture, use `make distclean' before reconfiguring for another architecture. Installation Names ================== By default, `make install' will install the package's files in `/usr/local/bin', `/usr/local/man', etc. You can specify an installation prefix other than `/usr/local' by giving `configure' the option `--prefix=PATH'. You can specify separate installation prefixes for architecture-specific files and architecture-independent files. If you give `configure' the option `--exec-prefix=PATH', the package will use PATH as the prefix for installing programs and libraries. Documentation and other data files will still use the regular prefix. In addition, if you use an unusual directory layout you can give options like `--bindir=PATH' to specify different values for particular kinds of files. Run `configure --help' for a list of the directories you can set and what kinds of files go in them. If the package supports it, you can cause programs to be installed with an extra prefix or suffix on their names by giving `configure' the option `--program-prefix=PREFIX' or `--program-suffix=SUFFIX'. Optional Features ================= Some packages pay attention to `--enable-FEATURE' options to `configure', where FEATURE indicates an optional part of the package. They may also pay attention to `--with-PACKAGE' options, where PACKAGE is something like `gnu-as' or `x' (for the X Window System). The `README' should mention any `--enable-' and `--with-' options that the package recognizes. For packages that use the X Window System, `configure' can usually find the X include and library files automatically, but if it doesn't, you can use the `configure' options `--x-includes=DIR' and `--x-libraries=DIR' to specify their locations. Specifying the System Type ========================== There may be some features `configure' can not figure out automatically, but needs to determine by the type of host the package will run on. Usually `configure' can figure that out, but if it prints a message saying it can not guess the host type, give it the `--host=TYPE' option. TYPE can either be a short name for the system type, such as `sun4', or a canonical name with three fields: CPU-COMPANY-SYSTEM See the file `config.sub' for the possible values of each field. If `config.sub' isn't included in this package, then this package doesn't need to know the host type. If you are building compiler tools for cross-compiling, you can also use the `--target=TYPE' option to select the type of system they will produce code for and the `--build=TYPE' option to select the type of system on which you are compiling the package. Sharing Defaults ================ If you want to set default values for `configure' scripts to share, you can create a site shell script called `config.site' that gives default values for variables like `CC', `cache_file', and `prefix'. `configure' looks for `PREFIX/share/config.site' if it exists, then `PREFIX/etc/config.site' if it exists. Or, you can set the `CONFIG_SITE' environment variable to the location of the site script. A warning: not all `configure' scripts look for a site script. Operation Controls ================== `configure' recognizes the following options to control how it operates. `--cache-file=FILE' Use and save the results of the tests in FILE instead of `./config.cache'. Set FILE to `/dev/null' to disable caching, for debugging `configure'. `--help' Print a summary of the options to `configure', and exit. `--quiet' `--silent' `-q' Do not print messages saying which checks are being made. To suppress all normal output, redirect it to `/dev/null' (any error messages will still be shown). `--srcdir=DIR' Look for the package's source code in directory DIR. Usually `configure' can determine that directory automatically. `--version' Print the version of Autoconf used to generate the `configure' script, and exit. `configure' also accepts some other, not widely useful, options. slurm-0.4.0/KEYS000066400000000000000000000006061163133444000133540ustar00rootroot00000000000000 As of 0.0.7 the user can change the display mode without quitting slurm. Just press "m" to cycle between modes or - "c" for the old combined/classic mode - "s" for the split window mode with stats - "l" for the large window mode w/o stats - "z" to reset most counters - "r" to redraw the screen - "q" to quit slurm $Id: KEYS,v 1.2 2003/03/31 20:15:54 hscholz Exp $ slurm-0.4.0/NEWS000066400000000000000000000000001163133444000133410ustar00rootroot00000000000000slurm-0.4.0/README000066400000000000000000000033031163133444000135330ustar00rootroot00000000000000slurm - yet another network load monitor *** see Changelog for Changes *** slurm started as a FreeBSD port of the Linux ppp link monitor called pppstatus by Gabriel Montenegro. I ripped of the ppp dependent parts and the email checks to turn in into a generic network load monitor for *BSD, Linux, HP-UX and Solaris. features: - "realtime" traffic statistics - three graph modes: combined RX and TX and two split views - can monitor any network device - curses ascii graphics - ascii theme support slurm was tested on: - FreeBSD >= 4.6 -stable (earlier should work but not tested) - FreeBSD 6.x -current (May '02 and later, earlier version should work) - Debian GNU/Linux stable and unstable - SuSE 8.0 and 8.1 - OpenBSD 3.x/i386 /sparc64 - NetBSD 1.6-stable/sgimips and /x86, NetBSD 2.0-RC1/sparc64 - HP-UX B.11.00 (10.xx won't work as a result of missing MIB functions. That could change somedays if we decide to implement dlpi API calls, which are supported at least in 10.20, in slurm.) - Solaris 7/sparc (Ultra 30 and E250) - Solaris 8/sparc (X1, E450, E10k) - Solaris 9/sparc (Ultra 30, Sunfire 280,480) - Solaris 8/intel (iprb network interface) - MicroBSD 0.6RC2/x86 - DragonFly 1.1/i386 Compiling: official releases come with GNU configure so ./configure && make should do it. In all other cases autoheader && autoconf && ./configure && make is appropriate to build slurm. Please report all problems as I just switched to autoconf as of 0.2.1 author: Hendrik Scholz website: http://www.wormulon.net/slurm/ email: hendrik@scholz.net As pppstatus is licensed under the GPL, slurm is too. $Id: README,v 1.19 2004/10/12 20:04:53 hscholz Exp $ slurm-0.4.0/SConstruct000066400000000000000000000004671163133444000147150ustar00rootroot00000000000000import os env = Environment() if os.uname()[0] == 'Linux': env.Append(CPPDEFINES=['_HAVE_NCURSES','_HAVE_NCURSES_COLOR']) elif os.uname()[0] == 'GNU/kFreeBSD': env.Append(CPPDEFINES=['_HAVE_NCURSES','_HAVE_NCURSES_COLOR']) env.Append( LIBS = ['ncurses'] ) env.Program(target='slurm', source=['slurm.c']) slurm-0.4.0/THANKS000066400000000000000000000002621163133444000135670ustar00rootroot00000000000000Thanks: - Gabriel for a nice ppp status monitor - Oliver Lehmann for initial HPUX support and testing/suggestions - Joe Laffey for comments/ideas/code - everyone else for ideas slurm-0.4.0/THEMES.txt000066400000000000000000000016201163133444000144010ustar00rootroot00000000000000_______________________________________________________________________________ T H E M E S Themes basicly allow the user to change the look of slurm. In case you don't like the default color set you can create a new one and instruct slurm to use it: $ slurm -i foo0 -t mytheme In this case 'mytheme' is the name of the theme that should be installed in either in the current working directory, ~/.slurm or /usr/local/share/slurm. F I L E L A Y O U T For a quick start just copy an existing theme and modify it. The main part (comments are allowed) is a simple key & value thing you should be familiar with. In case there are any questions please contact me. I'd like to add some themes to the main distribution but won't add all since the codebase should stay small. _______________________________________________________________________________ $Id: THEMES.txt,v 1.1 2004/02/13 05:13:52 hscholz Exp $ slurm-0.4.0/TODO000066400000000000000000000035241163133444000133500ustar00rootroot00000000000000known issues: - when resizing the terminal while running slurm in screen it might be possible that the static parts of the window are not redrawn so we should care about signals. - Solaris curses problems (Sat Dec 21 15:30:45 CET 2002) the solaris network stuff is ok but curses causes crashes UPDATE: fixed as of 2002-12-31. - BNC media detection (Fri Dec 6 00:50:18 CET 2002) While testing slurm on OpenBSD (thanks Auge for the account) I discovered a problem regarding the ifmedireq flags. OpenBSD does not set IFM_ACTIVE or IFM_AVALID for BNC interfaces. - high load on Linux 2.5 (Thu Dec 5 23:30:43 CET 2002) slurm caused 99% load on a Linux 2.5.40 box while transfering data on a saturated 100Mbit link. UPDATE: This hasn't been reproduced until now so it's low priority until someone reports it again. UPDATE: perhaps a usleep() problem might leads to wasting cpu cycles. - NetBSD interface speed detecion code (Thu Dec 5 23:30:43 CET 2002) As of today the interface speed detection code seems to not work correctly on NetBSD/stable. UPDATE: This seems to only concern my sq interface on my Indy. This matrix shows what works and what not. Feel free to contribute code. OS | get_stat | if_media | check_interface || overall ---------+----------+----------+-----------------++---------- FreeBSD | done | done | done || works OpenBSD | done | done | done || works NetBSD | done | done | done || works Solaris | done | done | done || works Linux | done | N/A | done || works HP-UX | done | | || works MicroBSD | done | done | done || works MacOS X | done | done | done || works $Id: TODO,v 1.15 2003/09/18 09:59:01 hscholz Exp $ slurm-0.4.0/config.h000066400000000000000000000000711163133444000142700ustar00rootroot00000000000000#define PACKAGE_VERSION "0.4.0" #define VERSION "0.4.0" slurm-0.4.0/error.c000066400000000000000000000023171163133444000141540ustar00rootroot00000000000000/***************************************************************************** * * error.c - generic error handling function * ***************************************************************************** * $Id: error.c,v 1.1 2003/05/25 14:45:23 hscholz Exp $ ****************************************************************************/ #ifndef _ERROR_C #define _ERROR_C #include "error.h" /***************************************************************************** * * error() * * print error message and exit if asked for * ****************************************************************************/ void error(int level, char *msg, ...) { va_list arguments; int debug = 1; va_start(arguments, msg); switch (level) { case ERR_DEBUG: if (debug != 0) fprintf(stderr, "DEBUG: "); break; case ERR_NOTICE: fprintf(stderr, "NOTICE: "); break; case ERR_WARNING: fprintf(stderr, "WARNING: "); break; case ERR_ERROR: fprintf(stderr, "ERROR: "); break; case ERR_FATAL: fprintf(stderr, "FATAL: "); break; } /* print the remaining arguments */ vfprintf(stderr, msg, arguments); va_end(arguments); fprintf(stderr, "\n"); if (level == ERR_FATAL) exit(1); } #endif slurm-0.4.0/error.h000066400000000000000000000006331163133444000141600ustar00rootroot00000000000000/* $Id: error.h,v 1.1 2003/05/25 14:45:23 hscholz Exp $ */ #ifndef _ERROR_H #define _ERROR_H /* error type definition * * lower Byte identifies the error * upper Byte is reserved for future use * (i.e. & 0x01ff to enable syslog logging) */ #define ERR_DEBUG 0x0001 #define ERR_NOTICE 0x0003 #define ERR_WARNING 0x0004 #define ERR_ERROR 0x0005 #define ERR_FATAL 0x0006 #define ERRBUF BUFSIZ #endif slurm-0.4.0/os.h000066400000000000000000000144411163133444000134520ustar00rootroot00000000000000/****************************************************************************** * * os.h - OS dependent headers * ***************************************************************************** * $Id: os.h,v 1.7 2004/10/12 19:55:58 hscholz Exp $ ***************************************************************************** * * 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. * *****************************************************************************/ #ifndef _OS_H_ #define _OS_H_ /* set variables for extra features */ #if defined (__sun__) || defined (__sun) # ifndef __Solaris__ # define __Solaris__ 1 # endif #endif #if defined (__FreeBSD__) || (__OpenBSD__) || (__NetBSD__) \ || (__MicroBSD__) || (__APPLE__) || (__DragonFly__) #define _HAVE_BSD #define _HAVE_CHECKINTERFACE #elif __HPUX__ #define _HAVE_CHECKINTERFACE #elif __Solaris__ #define _HAVE_CHECKINTERFACE #endif #ifdef __HPUX__ /* H P U X */ #define _XOPEN_SOURCE_EXTENDED #define NO_CURSES_E 1 #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #elif __FreeBSD__ /* F R E E B S D */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #ifndef __DragonFly__ #include #include #endif #elif __NetBSD__ /* N E T B S D */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #elif __OpenBSD__ || __MicroBSD__ /* O P E N B S D */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #elif __APPLE__ /* Mac OS X */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #elif __linux__ /* L I N U X */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #elif __Solaris__ /* S O L A R I S */ #include #define NO_CURSES_E 1 #define _WIDEC_H #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #elif __FreeBSD_kernel__ /* G N U / k F r e e B S D */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #else #error "Your OS is not supported! Please report to hscholz@raisdorf.net" #endif /* OS selection */ #endif slurm-0.4.0/slurm.1000066400000000000000000000030211163133444000140740ustar00rootroot00000000000000.TH slurm 1 .Dd February 23, 2003 .Dt slurm 1 .\" $Id: slurm.1,v 1.4 2004/02/06 02:33:54 hscholz Exp $ .\" .Sh NAME slurm \- yet another network load monitor .Sh SYNOPSIS .Nm slurm .Op Fl hHz .Op Fl csl .Op Fl d Ar delay .B -i interface .Sh DESCRIPTION slurm is a generic network load monitor which shows device statistics together with a nice ascii graph. Three different types of graphs are supported. .Sh OPTIONS .Bl -tag -width Ds .It Fl h Print usage information and quit. .It Fl H add hostname to title .It Fl c start slurm with classic/combined graph .It Fl s start slurm in split graph mode .It Fl l start slurm in large split graph mode .It Fl z virtually zero traffic counters instead of showing values stored in kernel .It Fl d Ar delay delay between screen updates in milliseconds (1000 = once per second) .It Fl i Ar interface select interface to monitor (required) .El .Sh KEYS slurm supports several different keys for interaction: .Bl -tag -width Ds .It Ar c switch to classic mode .It Ar s switch to split graph mode .It Ar l switch to large graph mode .It Ar L enable TX/RX led .It Ar m switch between classic, split and large view .It Ar z zero counters .It Ar r redraw screen .It Ar q quit slurm .El .Sh BUGS Several features of slurm are not supported on certain platforms, i.e. Interface speed detection is only supported on *BSD. Please check the source code documentation to see if your bug is really a bug. Please report bugs to hendrik@scholz.net .Sh AUTHOR Hendrik Scholz http://www.wormulon.net/slurm/ slurm-0.4.0/slurm.c000066400000000000000000001333521163133444000141710ustar00rootroot00000000000000/****************************************************************************** * * slurm - yet another network load monitor * * slurm started as a FreeBSD port of the Linux ppp link monitor called * pppstatus by Gabriel Montenegro. * I ripped of the ppp dependend parts and the email checks to turn in into * a generic network load monitor running on all common Unices. * * author: Hendrik Scholz * website: http://www.wormulon.net/slurm/ * email: hendrik@scholz.net * * As pppstatus is licensed under the GPL, slurm is too. See the following * paragraphs for information about pppstatus and the license. * ***************************************************************************** * $Id: slurm.c,v 1.86 2004/10/12 19:44:36 hscholz Exp $ ***************************************************************************** * * 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 "os.h" #include "config.h" #include "slurm.h" #include "src/if_media.h" #include "src/if_media.c" #include "error.h" #include "error.c" #include "theme.h" #include "theme.c" #ifdef __HPUX__ #include "src/hpux.h" #include "src/hpux.c" #elif __FreeBSD__ || __FreeBSD_kernel__ #include "src/freebsd.h" #include "src/freebsd.c" #elif __linux__ #include "src/linux.h" #include "src/linux.c" #elif __OpenBSD__ || __MicroBSD__ #include "src/openbsd.h" #include "src/openbsd.c" #elif __NetBSD__ #include "src/netbsd.h" #include "src/netbsd.c" #elif __Solaris__ #include "src/solaris.h" #include "src/solaris.c" #elif __APPLE__ #include "src/macos.h" #include "src/macos.c" #elif __DragonFly__ #include "src/freebsd.h" #include "src/freebsd.c" #else #warning "Your OS is not supported. Including dummy code!" #include "src/unsupported.h" #include "src/unsupported.c" #endif /****************************************************************************** * * center() * * center a given string on a given line * this is pppstatus code :) * *****************************************************************************/ void center(short int line, char *strg, ...) { short int where; char *final; va_list trans; final = malloc(80); va_start(trans, strg); (void)vsnprintf(final, 80, strg, trans); va_end(trans); where = (int)(40 - (strlen(final) / 2)); if(line != 0 && line != 24) { move(line, 20); hline(32, 50); } mvprintw(line, where, "%s",final); free(final); } /****************************************************************************** * * get_time() * * uptime stats struct with current time * *****************************************************************************/ void get_time(void) { long x; stats.current_time = time(NULL); x = stats.current_time - stats.connect_time; stats.online_sec = x % 60; stats.online_min = (x / 60) % 60; stats.online_hour = (x / 3600) % 24; stats.online_days = (x / (3600 * 24)) % 365; } /****************************************************************************** * * update_info() * * update the statistics and pay attention to buffer overruns while we are * here. As we allow decreasing values we have to pay attention to * no leave garbage on the screen. * *****************************************************************************/ void update_info(int displaymode) { char draw[DRAWLEN+1]; attrset(COLOR_PAIR(PAIR_VAR) | ((unsigned long)(t.var_attrib==COL_BOLD)?A_BOLD:A_NORMAL)); if (displaymode != MODE_LARGE) { snprintf(draw, DRAWLEN-1, "%lu", stats.rx_packets - stats.rx_packets_off); strncat(draw, " ", DRAWLEN-strlen(draw)); mvprintw(20, 24, "%s", draw); snprintf(draw, DRAWLEN-1, "%lu", stats.tx_packets - stats.tx_packets_off); strncat(draw, " ", DRAWLEN-strlen(draw)); mvprintw(20, 65, "%s", draw); snprintf(draw, DRAWLEN-1, "%lu", stats.rx_errors - stats.rx_errors_off); strncat(draw, " ", DRAWLEN-strlen(draw)); mvprintw(22, 24, "%s", draw); snprintf(draw, DRAWLEN-1, "%lu", stats.tx_errors - stats.tx_errors_off); strncat(draw, " ", DRAWLEN-strlen(draw)); mvprintw(22, 65, "%s", draw); switch(data_type) { case TYPE_MEGA: snprintf(draw, DRAWLEN-1, "%.3f MB", (stats.rx_bytes + (stats.rx_over * SNMPMAXBYTES) - stats.rx_bytes_off) / 1048570); strncat(draw, " ", DRAWLEN-strlen(draw)); mvprintw(21, 24, "%s", draw); snprintf(draw, DRAWLEN-1, "%.3f MB", (stats.tx_bytes + (stats.tx_over * SNMPMAXBYTES) - stats.tx_bytes_off) / 1048570); strncat(draw, " ", DRAWLEN-strlen(draw)); mvprintw(21, 65, "%s", draw); break; case TYPE_GIGA: snprintf(draw, DRAWLEN-1, "%.3f GB", (stats.rx_bytes + (stats.rx_over * SNMPMAXBYTES) - stats.rx_bytes_off) / 1073735680); strncat(draw, " ", DRAWLEN-strlen(draw)); mvprintw(21, 24, "%s", draw); snprintf(draw, DRAWLEN-1, "%.3f GB", (stats.tx_bytes + (stats.tx_over * SNMPMAXBYTES) - stats.tx_bytes_off) / 1073735680); strncat(draw, " ", DRAWLEN-strlen(draw)); mvprintw(21, 65, "%s", draw); break; } } } #ifdef WITH_LED /****************************************************************************** * * led_on() / led_off() * * blinkenlights(tm) * *****************************************************************************/ void led_on(unsigned int who) { int CHAR = 215; if(who == LED_RX) { attrset(COLOR_PAIR(PAIR_RX) | ((unsigned long)(t.rx_attrib==COL_BOLD)?A_BOLD:A_NORMAL)); move(14, 37); hline(CHAR, 2); } else if(who == LED_TX) { attrset(COLOR_PAIR(PAIR_TX) | ((unsigned long) (t.tx_attrib==COL_BOLD)?A_BOLD:A_NORMAL)); move(14, 41); hline(CHAR, 2); } } void led_off(unsigned int who) { if(who == LED_RX) { attrset(COLOR_PAIR(PAIR_VAR) | ((unsigned long) (t.var_attrib==COL_BOLD)?A_BOLD:A_NORMAL)); mvprintw(14, 37, "RX"); } else if(who == LED_TX) { attrset(COLOR_PAIR(PAIR_VAR) | ((unsigned long) (t.var_attrib==COL_BOLD)?A_BOLD:A_NORMAL)); mvprintw(14, 41, "TX"); } } #endif /****************************************************************************** * * update_stat_large() * * update the data array holding the needed information and redraw the graph * this mode shows two large graphs, one for each direction * *****************************************************************************/ int update_stat_large(void) { float sumspeed; float rxspeed; float txspeed; int i=0,x,y; int rx_scalechanged = 0; /* traffic scale changed? */ int tx_scalechanged = 0; float tmp_maxspeed = 0; /* needed for max speed calc in graph */ int tmp_maxspeedpos = 1; /* same here */ char draw[DRAWLEN+1]; /* what we draw on the screen */ /* in case of REINIT we want to keep the rx and tx values as we can * recalculate the graph for the new mode based on them. * recalculation is done automatically as ??_maxspeed equals 0 after * initilization. */ if (db_status == DB_STATUS_REINIT || db_status == DB_STATUS_STARTUP) { rx_maxspeed = 0; rx_overallmax = 0; tx_maxspeed = 0; tx_overallmax = 0; /* fill the graph array with zeros */ for (x = 0; x < GRAPH_WIDTH; x++) { for (y = 0; y < GRAPH_HEIGHT; y++) { rx_graph[x][y] = 0; tx_graph[x][y] = 0; } } if (db_status == DB_STATUS_STARTUP) { stats.rx_bytes_comp = stats.rx_bytes; stats.tx_bytes_comp = stats.tx_bytes; for (x = 0; x < GRAPH_WIDTH; x++) { rx_speedarray[x] = 0; tx_speedarray[x] = 0; } db_status = DB_STATUS_RUNNING; return 1; } db_status = DB_STATUS_RUNNING; } /* * current speed in bits/s * * in case of the expected u_long overflow in stats.?x_bytes * we will calculate a negative number as {sum|tx|rx}speed. * to prevent this we have to check if the _comp value is larger * than the current value. If true, we set _comp to 0 */ if (stats.rx_bytes_comp > stats.rx_bytes) stats.rx_bytes_comp = 0; if (stats.tx_bytes_comp > stats.tx_bytes) stats.tx_bytes_comp = 0; sumspeed = ((stats.rx_bytes - stats.rx_bytes_comp) + (stats.tx_bytes - stats.tx_bytes_comp)) / refreshdelay; rxspeed = (stats.rx_bytes - stats.rx_bytes_comp) / refreshdelay; txspeed = (stats.tx_bytes - stats.tx_bytes_comp) / refreshdelay; /* print current speed */ snprintf(draw, DRAWLEN-1, "%.2f KB/s", (float) rxspeed/1024); strncat(draw, " ", DRAWLEN-strlen(draw)); mvprintw(21, 24, "%s", draw); snprintf(draw, DRAWLEN-1, "%.2f KB/s", (float) txspeed/1024); strncat(draw, " ", DRAWLEN-strlen(draw)); mvprintw(21, 65, "%s", draw); stats.rx_bytes_comp = stats.rx_bytes; stats.tx_bytes_comp = stats.tx_bytes; /* set new max speed for graph if reached */ if (rxspeed > rx_maxspeed) { rx_maxspeed = rxspeed; rx_maxspeedpos = 0; rx_scalechanged++; if (rxspeed > rx_overallmax) rx_overallmax = rxspeed; } /* set new max speed for graph if reached */ if (txspeed > tx_maxspeed) { tx_maxspeed = txspeed; tx_maxspeedpos = 0; tx_scalechanged++; if (txspeed > tx_overallmax) tx_overallmax = txspeed; } /* * update the Graph Top Speed field * as it might be shorter than before just be sure to not leave * trailing garbage by printing spaces */ if (rx_scalechanged) { snprintf(draw, DRAWLEN-1, "%.2f KB/s", (float) rx_maxspeed/1024); strncat(draw, " ", DRAWLEN-strlen(draw)); mvprintw(22, 24, "%s", draw); } if (tx_scalechanged) { snprintf(draw, DRAWLEN-1, "%.2f KB/s", (float) tx_maxspeed/1024); strncat(draw, " ", DRAWLEN-strlen(draw)); mvprintw(22, 65, "%s", draw); } /* increment position of max speed as we move the graph */ rx_maxspeedpos++; tx_maxspeedpos++; /* check if max speed has to be lowered for the graph as the max speed * was reached too long ago */ tmp_maxspeed = 0; tmp_maxspeedpos = 1; if (rx_maxspeedpos >= GRAPH_WIDTH) { /* max speed calculation has to be redone */ for (i=0; i < GRAPH_WIDTH; i++) { if (rx_speedarray[i] > tmp_maxspeed) { tmp_maxspeed = rx_speedarray[1]; tmp_maxspeedpos = i; } } /* set new values */ rx_maxspeed = tmp_maxspeed; rx_maxspeedpos = tmp_maxspeedpos; } tmp_maxspeed = 0; tmp_maxspeedpos = 1; if (tx_maxspeedpos >= GRAPH_WIDTH) { /* max speed calculation has to be redone */ for (i=0; i < GRAPH_WIDTH; i++) { if (tx_speedarray[i] > tmp_maxspeed) { tmp_maxspeed = tx_speedarray[1]; tmp_maxspeedpos = i; } } /* set new values */ tx_maxspeed = tmp_maxspeed; tx_maxspeedpos = tmp_maxspeedpos; } /* prepare the graph array * * shift the graph to the left and then add the last entry * in addition move the traffic stats left */ /* move */ for (x = GRAPH_WIDTH-1; x >= 0; x--) { rx_speedarray[x] = rx_speedarray[x-1]; tx_speedarray[x] = tx_speedarray[x-1]; for (y = 0; y < GRAPHLARGE_HEIGHT; y++) { rx_graph[x][y] = rx_graph[x-1][y]; tx_graph[x][y] = tx_graph[x-1][y]; } } /* add the last column */ if(rx_maxspeed > 0) i = (int) ((rxspeed / rx_maxspeed) * GRAPHLARGE_HEIGHT); for (y = 0; y <= GRAPHLARGE_HEIGHT; y++) { if (i > y) rx_graph[0][y] = 1; else rx_graph[0][y] = 0; } if (0 != (int) rxspeed) rx_graph[0][1] = 1; rx_speedarray[0] = rxspeed; if(tx_maxspeed > 0) i = (int) ((txspeed / tx_maxspeed) * GRAPHLARGE_HEIGHT); for (y = 0; y <= GRAPHLARGE_HEIGHT; y++) { if (i > y) tx_graph[0][y] = 1; else tx_graph[0][y] = 0; } if (0 != (int) txspeed) tx_graph[0][1] = 1; tx_speedarray[0] = txspeed; /* * rescale graph * * in case the maxspeed for the shown graph changed we need to * recalculate the whole graph * */ if (rx_scalechanged) { /* for each line rewrite the graph */ for (x = GRAPH_WIDTH-1; x >= 0; x--) { i = (int) ((rx_speedarray[x] / rx_maxspeed) * GRAPHLARGE_HEIGHT); for (y = 0; y <= GRAPHLARGE_HEIGHT; y++) { if (i > y) rx_graph[x][y] = 1; else rx_graph[x][y] = 0; } if (rx_speedarray[x] != 0) rx_graph[x][1] = 1; } } if (tx_scalechanged) { /* for each line rewrite the graph */ for (x = GRAPH_WIDTH-1; x >= 0; x--) { i = (int) ((tx_speedarray[x] / tx_maxspeed) * GRAPHLARGE_HEIGHT); for (y = 0; y <= GRAPHLARGE_HEIGHT; y++) { if (i > y) tx_graph[x][y] = 1; else tx_graph[x][y] = 0; } if (tx_speedarray[x] != 0) tx_graph[x][1] = 1; } } /* * finally draw the two graphs line by line * * the rx graphs grows to the bottom */ for (y = GRAPHLARGE_HEIGHT-1; y > 0; y--) { for (x = 0; x <= GRAPH_WIDTH; x++) { /* RX graph */ if (rx_graph[x][y] == 1) { attrset(COLOR_PAIR(PAIR_RX) | ((unsigned long)(t.rx_attrib==COL_BOLD)?A_BOLD:A_NORMAL)); mvprintw(11-y, x+1, SYMBOL_TRAFFIC); } else mvprintw(11-y, x+1, SYMBOL_NOTRAFFIC); /* TX graph */ if (tx_graph[x][y] == 1) { attrset(COLOR_PAIR(PAIR_TX) | ((unsigned long)(t.tx_attrib==COL_BOLD)?A_BOLD:A_NORMAL)); mvprintw(10+y, x+1, SYMBOL_TRAFFIC); } else mvprintw(10+y, x+1, SYMBOL_NOTRAFFIC); } } return 0; } /****************************************************************************** * * update_stat_split() * * updates the array holding information about the graph and redraw * the graph. * *****************************************************************************/ int update_stat_split(void) { float sumspeed; float rxspeed; float txspeed; int i=0,x,y; int rx_scalechanged = 0; /* traffic scale changed? */ int tx_scalechanged = 0; float tmp_maxspeed = 0; /* needed for max speed calc in graph */ int tmp_maxspeedpos = 1; /* same here */ char draw[DRAWLEN+1]; /* what we draw on the screen */ /* in case of REINIT we want to keep the rx and tx values as we can * recalculate the graph for the new mode based on them. * recalculation is done automatically as ??_maxspeed equals 0 after * initilization. */ if (db_status != DB_STATUS_RUNNING) { rx_maxspeed = 0; rx_overallmax = 0; tx_maxspeed = 0; tx_overallmax = 0; /* fill the graph array with zeros */ for (x = 0; x < GRAPH_WIDTH; x++) { for (y = 0; y < GRAPH_HEIGHT; y++) { rx_graph[x][y] = 0; tx_graph[x][y] = 0; } } if (db_status == DB_STATUS_STARTUP) { stats.rx_bytes_comp = stats.rx_bytes; stats.tx_bytes_comp = stats.tx_bytes; for (x = 0; x < GRAPH_WIDTH; x++) { rx_speedarray[x] = 0; tx_speedarray[x] = 0; } db_status = DB_STATUS_RUNNING; return 1; } db_status = DB_STATUS_RUNNING; } /* * current speed in bits/s * * in case of the expected u_long overflow in stats.?x_bytes * we will calculate a negative number as {sum|tx|rx}speed. * to prevent this we have to check if the _comp value is larger * than the current value. If true, we set _comp to to 2^32 - _comp */ if (stats.rx_bytes_comp > stats.rx_bytes) stats.rx_bytes_comp = SNMPMAXBYTES - stats.rx_bytes_comp; if (stats.tx_bytes_comp > stats.tx_bytes) stats.tx_bytes_comp = SNMPMAXBYTES - stats.tx_bytes_comp; sumspeed = ((stats.rx_bytes - stats.rx_bytes_comp) + (stats.tx_bytes - stats.tx_bytes_comp)) / refreshdelay; rxspeed = (stats.rx_bytes - stats.rx_bytes_comp) / refreshdelay; txspeed = (stats.tx_bytes - stats.tx_bytes_comp) / refreshdelay; /* print current speed * instead of directly printing the string we first clear the draw string * and then fill in the speed. This way we prevent garbage from being * left on the screen. */ attrset(COLOR_PAIR(PAIR_VAR) | ((unsigned long) (t.var_attrib==COL_BOLD)?A_BOLD:A_NORMAL)); snprintf(draw, DRAWLEN-1, "%.2f KB/s ", rxspeed / 1024); strncat(draw, " ", DRAWLEN-strlen(draw)); mvprintw(17, 24, "%s", draw); snprintf(draw, DRAWLEN-1, "%.2f KB/s ", txspeed / 1024); strncat(draw, " ", DRAWLEN-strlen(draw)); mvprintw(17, 65, "%s", draw); stats.rx_bytes_comp = stats.rx_bytes; stats.tx_bytes_comp = stats.tx_bytes; /* set new max speed for graph if reached */ if (rxspeed > rx_maxspeed) { rx_maxspeed = rxspeed; rx_maxspeedpos = 0; rx_scalechanged++; if (rxspeed > rx_overallmax) { rx_overallmax = rxspeed; snprintf(draw, DRAWLEN-1, "%.2f KB/s", (float) rxspeed/1024); strncat(draw, " ", DRAWLEN-strlen(draw)); mvprintw(19, 24, "%s", draw); } } /* set new max speed for graph if reached */ if (txspeed > tx_maxspeed) { tx_maxspeed = txspeed; tx_maxspeedpos = 0; tx_scalechanged++; if (txspeed > tx_overallmax) { tx_overallmax = txspeed; snprintf(draw, DRAWLEN-1, "%.2f KB/s", (float) txspeed/1024); strncat(draw, " ", DRAWLEN-strlen(draw)); mvprintw(19, 65, "%s", draw); } } /* * update the Graph Top Speed field * as it might be shorter than before just be sure to not leave * trailing garbage by printing spaces */ if (rx_scalechanged) { snprintf(draw, DRAWLEN-1, "%.2f KB/s", rx_maxspeed/1024); strncat(draw, " ", DRAWLEN-strlen(draw)); mvprintw(18, 24, "%s", draw); } if (tx_scalechanged) { snprintf(draw, DRAWLEN-1, "%.2f KB/s", tx_maxspeed/1024); strncat(draw, " ", DRAWLEN-strlen(draw)); mvprintw(18, 65, "%s", draw); } /* increment position of max speed as we move the graph */ rx_maxspeedpos++; tx_maxspeedpos++; /* check if max speed has to be lowered for the graph as the max speed * was reached too long ago */ tmp_maxspeed = 0; tmp_maxspeedpos = 1; if (rx_maxspeedpos >= GRAPHSPLIT_WIDTH) { /* max speed calculation has to be redone */ for (i=0; i < GRAPHSPLIT_WIDTH; i++) { if (rx_speedarray[i] > tmp_maxspeed) { tmp_maxspeed = rx_speedarray[1]; tmp_maxspeedpos = i; } } /* set new values */ rx_maxspeed = tmp_maxspeed; rx_maxspeedpos = tmp_maxspeedpos; } tmp_maxspeed = 0; tmp_maxspeedpos = 1; if (tx_maxspeedpos >= GRAPHSPLIT_WIDTH) { /* max speed calculation has to be redone */ for (i=0; i < GRAPHSPLIT_WIDTH; i++) { if (tx_speedarray[i] > tmp_maxspeed) { tmp_maxspeed = tx_speedarray[1]; tmp_maxspeedpos = i; } } /* set new values */ tx_maxspeed = tmp_maxspeed; tx_maxspeedpos = tmp_maxspeedpos; } /* prepare the graph array * * shift the graph to the left and then add the last entry * in addition move the traffic stats left */ /* move */ for (x = GRAPHSPLIT_WIDTH-1; x >= 0; x--) { rx_speedarray[x] = rx_speedarray[x-1]; tx_speedarray[x] = tx_speedarray[x-1]; for (y = 0; y < GRAPHSPLIT_HEIGHT; y++) { rx_graph[x][y] = rx_graph[x-1][y]; tx_graph[x][y] = tx_graph[x-1][y]; } } /* add the last column */ if(rx_maxspeed > 0) i = (int) ((rxspeed / rx_maxspeed) * GRAPHSPLIT_HEIGHT); for (y = 0; y <= GRAPHSPLIT_HEIGHT; y++) { if (i > y) rx_graph[0][y] = 1; else rx_graph[0][y] = 0; } if (0 != (int) rxspeed) rx_graph[0][1] = 1; rx_speedarray[0] = rxspeed; if(tx_maxspeed > 0) i = (int) ((txspeed / tx_maxspeed) * GRAPHSPLIT_HEIGHT); for (y = 0; y <= GRAPHSPLIT_HEIGHT; y++) { if (i > y) tx_graph[0][y] = 1; else tx_graph[0][y] = 0; } if (0 != (int) txspeed) tx_graph[0][1] = 1; tx_speedarray[0] = txspeed; /* * rescale graph * * in case the maxspeed for the shown graph changed we need to * recalculate the whole graph * */ if (rx_scalechanged) { /* for each line rewrite the graph */ for (x = GRAPHSPLIT_WIDTH-1; x >= 0; x--) { i = (int) ((rx_speedarray[x] / rx_maxspeed) * GRAPHSPLIT_HEIGHT); for (y = 0; y <= GRAPHSPLIT_HEIGHT; y++) { if (i > y) rx_graph[x][y] = 1; else rx_graph[x][y] = 0; } if (rx_speedarray[x] != 0) rx_graph[x][1] = 1; } } if (tx_scalechanged) { /* for each line rewrite the graph */ for (x = GRAPHSPLIT_WIDTH-1; x >= 0; x--) { i = (int) ((tx_speedarray[x] / tx_maxspeed) * GRAPHSPLIT_HEIGHT); for (y = 0; y <= GRAPHSPLIT_HEIGHT; y++) { if (i > y) tx_graph[x][y] = 1; else tx_graph[x][y] = 0; } if (tx_speedarray[x] != 0) tx_graph[x][1] = 1; } } /* * finally draw the two graphs line by line * * the rx graphs grows to the bottom */ for (y = GRAPHSPLIT_HEIGHT-1; y > 0; y--) { for (x = 0; x <= GRAPHSPLIT_WIDTH; x++) { /* RX graph */ if (rx_graph[x][y] == 1) { attrset(COLOR_PAIR(PAIR_RX) | ((unsigned long)(t.rx_attrib==COL_BOLD)?A_BOLD:A_NORMAL)); mvprintw(7-y, x+1, SYMBOL_TRAFFIC); } else mvprintw(7-y, x+1, SYMBOL_NOTRAFFIC); /* TX graph */ if (tx_graph[x][y] == 1) { attrset(COLOR_PAIR(PAIR_TX) | ((unsigned long)(t.tx_attrib==COL_BOLD)?A_BOLD:A_NORMAL)); mvprintw(6+y, x+1, SYMBOL_TRAFFIC); } else mvprintw(6+y, x+1, SYMBOL_NOTRAFFIC); } } return 0; } /****************************************************************************** * * update_stat_combined() * * this is the classic view for the graph known from 0.0.3 * *****************************************************************************/ int update_stat_combined(void) { float sumspeed; float rxspeed; float txspeed; int i=0,x,y; int rx_scalechanged = 0; /* traffic scale changed? */ float tmp_maxspeed = 0; /* needed for max speed calc in graph */ int tmp_maxspeedpos = 1; /* same here */ char draw[DRAWLEN+1]; /* what we draw on the screen */ /* in case of REINIT we want to keep the rx and tx values as we can * recalculate the graph for the new mode based on them. */ if (db_status == DB_STATUS_REINIT || db_status == DB_STATUS_STARTUP) { tx_maxspeed = 0; tx_overallmax = 0; rx_maxspeed = 0; rx_overallmax = 0; comb_maxspeed = 0; comb_overallmax = 0; /* fill the graph array with zeros */ for (x = 0; x < GRAPH_WIDTH; x++) { for (y = 0; y < GRAPH_HEIGHT; y++) { rx_graph[x][y] = 0; tx_graph[x][y] = 0; } } /* force graph recalculation */ rx_scalechanged++; if (db_status == DB_STATUS_STARTUP) { stats.rx_bytes_comp = stats.rx_bytes; stats.tx_bytes_comp = stats.tx_bytes; for (x = 0; x < GRAPH_WIDTH; x++) { rx_speedarray[x] = 0; tx_speedarray[x] = 0; } db_status = DB_STATUS_RUNNING; return 1; } db_status = DB_STATUS_RUNNING; } /* * current speed in bits/s * * in case of the expected u_long overflow in stats.?x_bytes * we will calculate a negative number as {sum|tx|rx}speed. * to prevent this we have to check if the _comp value is larger * than the current value. If true, we set _comp to 0 */ if (stats.rx_bytes_comp > stats.rx_bytes) stats.rx_bytes_comp = 0; if (stats.tx_bytes_comp > stats.tx_bytes) stats.tx_bytes_comp = 0; sumspeed = ((stats.rx_bytes - stats.rx_bytes_comp) + (stats.tx_bytes - stats.tx_bytes_comp)) / refreshdelay; rxspeed = (stats.rx_bytes - stats.rx_bytes_comp) / refreshdelay; txspeed = (stats.tx_bytes - stats.tx_bytes_comp) / refreshdelay; /* print current speed */ snprintf(draw, DRAWLEN-1, "%.2f KB/s", sumspeed / 1024); strncat(draw, " ", DRAWLEN-strlen(draw)); mvprintw(18, 24, "%s", draw); stats.rx_bytes_comp = stats.rx_bytes; stats.tx_bytes_comp = stats.tx_bytes; /* set new max speed for graph if reached */ if (sumspeed > comb_maxspeed) { comb_maxspeed = sumspeed; rx_maxspeedpos = 0; rx_scalechanged++; if (sumspeed > comb_overallmax) { comb_overallmax = sumspeed; snprintf(draw, DRAWLEN-1, "%.2f KB/s", (float) sumspeed / 1024); strncat(draw, " ", DRAWLEN-strlen(draw)); mvprintw(19, 65, "%s", draw); } } /* * update the Graph Top Speed field * as it might be shorter than before just be sure to not leave * trailing garbage by printing spaces */ if (rx_scalechanged) { snprintf(draw, DRAWLEN-1, "%.2f KB/s", comb_maxspeed / 1024); strncat(draw, " ", DRAWLEN-strlen(draw)); mvprintw(19, 24, "%s", draw); } /* increment position of max speed as we move the graph */ rx_maxspeedpos++; /* check if max speed has to be lowered for the graph as the max speed * was reached too long ago */ tmp_maxspeed = 0; tmp_maxspeedpos = 1; if (rx_maxspeedpos >= GRAPHCOMBINED_WIDTH) { /* max speed calculation has to be redone */ for (i=0; i < GRAPHCOMBINED_WIDTH; i++) { if (rx_speedarray[i] > tmp_maxspeed) { tmp_maxspeed = rx_speedarray[1]; tmp_maxspeedpos = i; } } /* set new values */ comb_maxspeed = tmp_maxspeed; rx_maxspeedpos = tmp_maxspeedpos; } /* prepare the graph array * * shift the graph to the left and then add the last entry * in addition move the traffic stats left * * there seems to be some redundancy in here regarding the rx/tx values * but we need it for seamless mode switching * */ /* move */ for (x = GRAPHCOMBINED_WIDTH-1; x >= 0; x--) { rx_speedarray[x] = rx_speedarray[x-1]; tx_speedarray[x] = tx_speedarray[x-1]; for (y = 0; y < GRAPHCOMBINED_HEIGHT; y++) { rx_graph[x][y] = rx_graph[x-1][y]; tx_graph[x][y] = tx_graph[x-1][y]; } } /* add the last column */ if(comb_maxspeed > 0) i = (int) ((sumspeed / comb_maxspeed) * GRAPHCOMBINED_HEIGHT); for (y = 0; y <= GRAPHCOMBINED_HEIGHT; y++) { if (i > y) rx_graph[0][y] = 1; else rx_graph[0][y] = 0; } if (0 != (int) sumspeed) rx_graph[0][1] = 1; rx_speedarray[0] = rxspeed; tx_speedarray[0] = txspeed; /* * rescale graph * * in case the maxspeed for the shown graph changed we need to * recalculate the whole graph * */ if (rx_scalechanged) { /* for each line rewrite the graph */ for (x = GRAPHCOMBINED_WIDTH-1; x >= 0; x--) { i = (int) ((rx_speedarray[x] / comb_maxspeed) * GRAPHSPLIT_HEIGHT); for (y = 0; y <= GRAPHCOMBINED_HEIGHT; y++) { if (i > y) rx_graph[x][y] = 1; else rx_graph[x][y] = 0; } if (rx_speedarray[x] != 0) rx_graph[x][1] = 1; } } /* * finally draw the two graphs line by line * * the rx graphs grows to the bottom */ for (y = GRAPHCOMBINED_HEIGHT-1; y > 0; y--) { for (x = 0; x <= GRAPHCOMBINED_WIDTH; x++) { /* RX graph */ if (rx_graph[x][y] == 1) { attrset(COLOR_PAIR(PAIR_RX) | ((unsigned long)(t.rx_attrib==COL_BOLD)?A_BOLD:A_NORMAL)); mvprintw(13-y, x+1, SYMBOL_TRAFFIC); } else mvprintw(13-y, x+1, SYMBOL_NOTRAFFIC); } } return 0; } /****************************************************************************** * * usage() * * print usage and die * *****************************************************************************/ void usage (int code, char **argv) { fprintf(stderr, "slurm %s - Hendrik Scholz \n\n" "usage: %s [-hHz] [-csl] [-d delay] [-t theme] -i interface\n\n", PACKAGE_VERSION, argv[0]); fprintf(stderr, " -h print help\n" " -z zero counters at startup\n" " -d delay delay between refreshs in seconds" " (%d < delay < %d)\n" " -c old classic/combined view\n" " -s split window mode with stats\n" " -l large split window mode\n" " -L enable TX/RX 'leds'\n" " -i interface select network interface\n" " -t theme select a theme\n\n", REFRESH_MIN, REFRESH_MAX); _exit(code); } /****************************************************************************** * * draw_face() * * draw the static parts of the screen * *****************************************************************************/ void draw_face(int displaymode, char *hostname) { int x, y; attrset(COLOR_PAIR(PAIR_TEXT) | ((unsigned long)(t.text_attrib==COL_BOLD)?A_BOLD:A_NORMAL)); for(x = 0; x <= 24; x++) { for(y = 0; y <= 80; y++) { mvprintw(x, y, " "); } } refresh(); if (displaymode != MODE_LARGE) { mvprintw(20, 6, "Received Packets:"); mvprintw(22, 3, "Errors on Receiving:"); mvprintw(20, 44,"Transmitted Packets:"); switch(data_type) { case TYPE_MEGA: mvprintw(21, 7, "MBytes Received:"); mvprintw(21, 45, "MBytes Transmitted:"); break; case TYPE_GIGA: mvprintw(21, 7, "GBytes Received:"); mvprintw(21, 45, "GBytes Transmitted:"); break; } } if (displaymode == MODE_SPLIT) { mvprintw(22, 41, "Errors on Transmission:"); #ifdef WITH_LED if (ledenabled) { mvprintw(14, 37, "RX"); mvprintw(14, 41, "TX"); } #endif mvprintw(17, 6, "Current RX Speed:"); mvprintw(19, 2, "Overall Top RX Speed:"); mvprintw(18, 4, "Graph Top RX Speed:"); mvprintw(17, 47, "Current TX Speed:"); mvprintw(19, 43, "Overall Top TX Speed:"); mvprintw(18, 45, "Graph Top TX Speed:"); mvprintw(15, 6, "Active Interface:"); mvprintw(15, 48, "Interface Speed:"); } else if (displaymode == MODE_COMBINED) { mvprintw(22, 41, "Errors on Transmission:"); #ifdef WITH_LED if (ledenabled) { mvprintw(14, 37, "RX"); mvprintw(14, 41, "TX"); } #endif mvprintw(18, 9, "Current Speed:"); mvprintw(19, 46, "Overall Top Speed:"); mvprintw(19, 7, "Graph Top Speed:"); mvprintw(16, 6, "Active Interface:"); mvprintw(16, 48, "Interface Speed:"); } else { /* large split mode */ mvprintw(21, 6, "Current RX Speed:"); mvprintw(21, 47, "Current TX Speed:"); mvprintw(22, 4, "Graph Top RX Speed:"); mvprintw(22, 45, "Graph Top TX Speed:"); } attrset(COLOR_PAIR(PAIR_TITLE) | ((unsigned long)(t.title_attrib==COL_BOLD)?A_BOLD:A_NORMAL)); if (hostname[0] != '\0') center(00, "-= slurm %s on %s =-", VERSION, hostname); else center(00, "-= slurm %s =-", VERSION); attrset(COLOR_PAIR(PAIR_VAR) | ((unsigned long)(t.var_attrib==COL_BOLD)?A_BOLD:A_NORMAL)); if (displaymode == MODE_SPLIT) { mvprintw(15, 24, "%s", ifdata.if_name); mvprintw(15, 65, "%s", (char *) ifdata.if_speedstring); } else if (displaymode == MODE_COMBINED) { mvprintw(16, 24, "%s", ifdata.if_name); mvprintw(16, 65, "%s", (char *) ifdata.if_speedstring); } refresh(); } /***************************************************************************** * * main() * * this is where the nightmare starts * ****************************************************************************/ int main(int argc, char *argv[]) { short int key_pressed; long now, old[2]; int sec_value = 0; int min_value = 0; int reload = FALSE; int validinterface = 0; int displaymode = MODE_SPLIT; int modechange = 0; unsigned short int first = 1; unsigned short int disconnected = 0; char hostname[MAXHOSTNAMELEN+1]; extern long refreshdelay; extern int ledenabled; float tmpdelay; int op; int z_option = FALSE; char *themep = NULL; hostname[0] = '\0'; /* HP-UX related as of now but could become standard */ ifdata.if_valid = 0; ifdata.if_id = 0; ifdata.if_amount = 0; ledenabled = 0; /* determine hostname */ if (gethostname(hostname, MAXHOSTNAMELEN) != 0) hostname[0] = '\0'; /* handle command line options */ while ((op = getopt(argc, argv, "Lhzd:clsi:t:")) != EOF) { switch (op) { case 'i': /* interface */ snprintf((char *)ifdata.if_name, (size_t) sizeof(ifdata.if_name), "%s", optarg); /* check if interface really exists */ #ifdef _HAVE_CHECKINTERFACE validinterface = checkinterface(); #else /* just trust the user for now */ validinterface++; #endif break; case 'h': /* print help and exit peacefully */ usage(0, argv); break; case 'z': /* virtually reset all counters by adding an offset */ z_option = TRUE; break; case 'd': /* delay between updates */ tmpdelay = atof(optarg); if ((tmpdelay < REFRESH_MIN) || (tmpdelay > REFRESH_MAX)) { fprintf(stderr, "delay has to be between %d and %d seconds!\n", REFRESH_MIN, REFRESH_MAX); return 1; } else refreshdelay = tmpdelay; break; case 'c': /* use old classic/combined view */ displaymode = MODE_COMBINED; break; case 'l': /* use large split window mode */ displaymode = MODE_LARGE; break; case 'L': /* enable TX/RX led */ ledenabled = 1; break; case 's': /* use default split window mode */ displaymode = MODE_SPLIT; break; case 't': /* theme */ themep = optarg; break; default: usage(1, argv); break; } } if (strlen(ifdata.if_name) == 0) usage(1, argv); if (!validinterface) { fprintf(stderr, "specified device does not exist or cannot " "be monitored!\n\nIf you think this is an error please report " "it to . Thanks!\n"); exit(1); } /* Initialize some info variables */ stats.tx_packets = 0; stats.tx_bytes = 0; stats.tx_errors = 0; stats.rx_packets = 0; stats.rx_bytes = 0; stats.rx_errors = 0; stats.tx_bytes_comp = 0; stats.tx_bytes_comp = 0; /* overruns */ stats.rx_over = 0; stats.tx_over = 0; /* * run get_stat() once so watchif gets set and we get offsets in case * -z cli option was given. */ get_stat(); if (z_option == TRUE) zero_stats(); else { /* set all counters to zero */ stats.rx_packets_off = stats.rx_errors_off = 0; stats.rx_over_off = stats.tx_packets_off = 0; stats.tx_errors_off = stats.tx_over_off = 0; stats.rx_bytes_off = stats.tx_bytes_off = 0; stats.rx_bytes_comp_off = stats.tx_bytes_comp_off = 0; } /* determine interface speed * not all systems have this nice feature we display "unknown" * if the speed could not determined due to errors or lack of * this feature on the host operating system */ #if defined(_HAVE_BSD) || defined(__HPUX__) || defined(__Solaris__) || defined(__APPLE__) ifdata.if_speed = get_if_speed(ifdata.if_name); /* if ERR_IFACE_NO_SPEED we could not determine the interface speed * if ERR_IFACE_DOWN the interface was down * as we cannot monitor an interface which is down we exit quit */ if (ifdata.if_speed == ERR_IFACE_DOWN) { fprintf(stderr, "interface '%s' is down\n", (char *) ifdata.if_name); return 1; } /* ifdata.if_speed is in kbit/s */ if (ifdata.if_speed >= 1000) snprintf((char *) ifdata.if_speedstring, sizeof(ifdata.if_speedstring), "%d Mbit/s", (int) ifdata.if_speed/1000); else if ((ifdata.if_speed == 0) || (ifdata.if_speed == ERR_IFACE_NO_SPEED)) snprintf((char *) ifdata.if_speedstring, sizeof(ifdata.if_speedstring), "unknown"); else snprintf((char *) ifdata.if_speedstring, sizeof(ifdata.if_speedstring), "%d kbit/s", (int) ifdata.if_speed/100); #else snprintf((char *) ifdata.if_speedstring, sizeof(ifdata.if_speedstring), "unknown"); #endif #if MEDIADEBUG return 0; #endif #ifndef NO_CURSES_E printf("\e(U"); #endif if (themep == NULL) theme_setdefault(&t); else theme_readfile(&t, themep); if (t.complete != E_ALL) error(ERR_FATAL, "broken theme"); initscr(); intrflush(stdscr, FALSE); start_color(); curs_set(0); /* Toggle the cursor off */ nonl(); noecho(); cbreak(); nodelay(stdscr, TRUE); #ifdef _HAVE_NCURSES if (use_default_colors() == OK) /* need ncurses for transparency */ t.background = -1; #endif init_pair(PAIR_TEXT, t.text, t.background); init_pair(PAIR_RX, t.rx, t.background); init_pair(PAIR_TX, t.tx, t.background); init_pair(PAIR_VAR, t.var, t.background); init_pair(PAIR_TITLE, t.title, t.background); attrset(COLOR_PAIR(PAIR_TEXT) | ((unsigned long)(t.text_attrib==COL_BOLD)?A_BOLD:A_NORMAL)); /* curses is set up so make sure to shut it down correctly when * receiving termination signals by calling slurm_shutdown() */ signal(SIGHUP, slurm_shutdown); signal(SIGINT, slurm_shutdown); signal(SIGQUIT, slurm_shutdown); signal(SIGKILL, slurm_shutdown); signal(SIGTERM, slurm_shutdown); draw_face(displaymode, hostname); update_info(displaymode); now = time(NULL); old[0] = old[1] = time(NULL) - 3; for (;;) { get_stat(); #ifdef WITH_LED if (ledenabled) { if (displaymode != MODE_LARGE) { /* In case of a new RX Packet... the RX Led Turn on * Else... Turn off */ if (stats.rx_packets != stats.rx_packets_led) led_on(LED_RX); else led_off(LED_RX); /* In case of a new TX Packet... the TX Led Turn on * Else... Turn off */ if (stats.tx_packets != stats.tx_packets_led) led_on(LED_TX); else led_off(LED_TX); } } /* end ledenabled */ #endif stats.rx_packets_led = stats.rx_packets; stats.tx_packets_led = stats.tx_packets; get_time(); /* check if we have to switch to Gbytes mode */ if (data_type != TYPE_GIGA && ((stats.tx_bytes > 1073735680) || (stats.rx_bytes > 1073735680))) { data_type = TYPE_GIGA; draw_face(displaymode, hostname); } update_info(displaymode); if((!sec_value && first) || disconnected) { sec_value = stats.online_sec; min_value = stats.online_min; update_stat(displaymode); first = 0; disconnected = 0; } now = time(NULL); if(stats.online_sec != sec_value) { update_stat(displaymode); sec_value = stats.online_sec; } /* move cursor to upper left corner */ move (0, 0); tmpdelay = refreshdelay * 10; do { usleep(100*1000); /* 10th of a second */ tmpdelay--; key_pressed = getch(); if (key_pressed != ERR) break; } while (tmpdelay > 0); if (key_pressed != ERR && tolower(key_pressed) == 'q') break; else if (key_pressed != ERR && tolower(key_pressed) == 'c') { displaymode = MODE_COMBINED; modechange++; } else if (key_pressed != ERR && tolower(key_pressed) == 'l') { displaymode = MODE_LARGE; modechange++; } else if (key_pressed != ERR && tolower(key_pressed) == 's') { displaymode = MODE_SPLIT; modechange++; } else if (key_pressed != ERR && tolower(key_pressed) == 'm') { if (displaymode == MODE_COMBINED) displaymode = MODE_SPLIT; else if (displaymode == MODE_SPLIT) displaymode = MODE_LARGE; else displaymode = MODE_COMBINED; modechange++; } else if (key_pressed != ERR && tolower(key_pressed) == 'r') { draw_face(displaymode, hostname); update_stat(displaymode); reload = TRUE; } else if (key_pressed != ERR && tolower(key_pressed) == 'z') { zero_stats(); update_stat(displaymode); reload = TRUE; } /* if the display mode change we need to redraw the face and * reinitialize the graph arrays * draw_face() clears the screen */ if (modechange) { db_status = DB_STATUS_REINIT; modechange = 0; draw_face(displaymode, hostname); } } slurm_shutdown(1); /* needs a bogus parameter :) */ return 0; } /****************************************************************************** * * update_stat() * * graph update dispatcher, just calls the right function * *****************************************************************************/ int update_stat(int displaymode) { switch (displaymode) { case MODE_COMBINED: return update_stat_combined(); break; case MODE_SPLIT: return update_stat_split(); break; case MODE_LARGE: return update_stat_large(); break; default: return 1; } } /****************************************************************************** * * zero_stats() * * redefine the offsets for all counters so we can virtually reset * the counters on the display * *****************************************************************************/ void zero_stats(void) { stats.rx_packets_off = stats.rx_packets; stats.rx_errors_off = stats.rx_errors; stats.rx_over_off = stats.rx_over; stats.tx_packets_off = stats.tx_packets; stats.tx_errors_off = stats.tx_errors; stats.tx_over_off = stats.tx_over; stats.rx_bytes_off = stats.rx_bytes; stats.tx_bytes_off = stats.tx_bytes; stats.rx_bytes_comp_off = stats.rx_bytes_comp; stats.tx_bytes_comp_off = stats.tx_bytes_comp; } /****************************************************************************** * * slurm_shutdown() * * shutdown curses so we get a clean terminal. * *****************************************************************************/ void slurm_shutdown (int sig) { endwin(); system("clear"); curs_set(1); fprintf(stdout, "slurm %s by Hendrik Scholz - " "http://www.wormulon.net/slurm/\n", VERSION); /* close dev if running Linux */ #ifdef __linux__ fclose(proc_net_dev); #endif exit (0); } slurm-0.4.0/slurm.h000066400000000000000000000121401163133444000141650ustar00rootroot00000000000000/****************************************************************************** * * slurm config file, heavily based on the pppstatus version * see README file or slurm.c for more information * * $Id: slurm.h,v 1.42 2004/02/13 05:41:30 hscholz Exp $ * * 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. * ***************************************************************************/ #define LED_RX 1 #define LED_TX 2 #ifndef TRUE #define TRUE 1 #endif #ifndef FALSE #define FALSE 0 #endif #define SYMBOL_TRAFFIC "x" #define SYMBOL_NOTRAFFIC " " #ifdef __linux__ #define PATH_NET_DEV "/proc/net/dev" #endif #define MODE_COMBINED 1 #define MODE_SPLIT 2 #define MODE_LARGE 3 /* slap HPUX with a large trout * HPUX 10.xx cannot handle 2^32 int constants, so we have to "tweak" it */ #ifdef __HPUX__ #define SNMPMAXBYTES (4294967295 + 1) #else #define SNMPMAXBYTES (4294967296ULL) #endif #undef MAXHOSTNAMELEN #define MAXHOSTNAMELEN 64 #define DRAWLEN 16 /* 10th of a second */ #define REFRESH_DEFAULT 1 #define REFRESH_MIN 1 #define REFRESH_MAX 300 #ifndef BUFSIZ #define BUFSIZ 1024 #warning "setting buf size to 1024" #endif typedef struct statvline { int hline[76]; /* This will be the horzontal lines */ } statvline[10]; /* ... and this will be vertical lines */ statvline graph; /* This structure stays the INFO variables */ typedef struct DataStats { unsigned long rx_packets; unsigned long rx_errors; int rx_over; unsigned long tx_packets; unsigned long tx_errors; int tx_over; double rx_bytes; double tx_bytes; double rx_bytes_comp; double tx_bytes_comp; double rx_packets_led; double tx_packets_led; unsigned long connect_time; unsigned long current_time; float top_speed; int online_days; int online_hour; int online_min; int online_sec; unsigned long rx_packets_off; unsigned long rx_errors_off; int rx_over_off; unsigned long tx_packets_off; unsigned long tx_errors_off; int tx_over_off; double rx_bytes_off; double tx_bytes_off; double rx_bytes_comp_off; double tx_bytes_comp_off; } DataStats; DataStats stats; typedef struct IfData{ char if_name[10]; /* The device name given as start parameter*/ int if_speed; /* The Interface speed */ char if_speedstring[12]; /* the measuring unit like Mbit, kbit */ int if_id; /* The ID which the interface inside the OS has */ int if_amount; /* The amount of all interfaces available */ int if_valid; /* 1 = selected interface exists * 0 = interfaces does not exists */ } IfData; IfData ifdata; /* Prototypes */ void center(short int line, char *strg, ...); void chcolor(int x, int y); int update_stat_combined(void); int update_stat_split(void); int update_stat_large(void); int update_stat(int); void update_info(int); void led_on(unsigned int who); void led_off(unsigned int who); int is_online(void); int get_stat(void); void clear_info(void); void ip_address(int display); void get_time (void); void do_exit (int, char *, short int); void usage (int, char **); void draw_face (int, char *); void zero_stats (void); void slurm_shutdown (int); /* Variables Declarations */ #define TYPE_MEGA 0 #define TYPE_GIGA 1 int data_type = TYPE_MEGA; long refreshdelay = REFRESH_DEFAULT; /* internal database status */ /* possible modes are: */ #define DB_STATUS_STARTUP 1 #define DB_STATUS_RUNNING 2 #define DB_STATUS_REINIT 3 int db_status = DB_STATUS_STARTUP; #ifdef __linux static FILE *proc_net_dev; #endif /* End of Variables Declarations */ /* max speed in graph */ #define GRAPHSINGLE_WIDTH 77 #define GRAPHSINGLE_HEIGHT 10 /* define graph height for split screen graphs */ #define GRAPHSPLIT_HEIGHT 6 #define GRAPHSPLIT_WIDTH 77 #define GRAPHCOMBINED_WIDTH 77 #define GRAPHCOMBINED_HEIGHT 12 /* new max height */ #define GRAPH_HEIGHT 12 #define GRAPH_WIDTH 77 /* large split mode graph height */ #define GRAPHLARGE_HEIGHT 11 /* rx is higher than need as we use it for the combined view */ int rx_graph[GRAPHSPLIT_WIDTH][GRAPHCOMBINED_HEIGHT]; float rx_speedarray[GRAPHSPLIT_WIDTH]; static float rx_maxspeed; static int rx_maxspeedpos; int rx_overallmax; int tx_graph[GRAPHSPLIT_WIDTH][GRAPHCOMBINED_HEIGHT]; float tx_speedarray[GRAPHSPLIT_WIDTH]; static float tx_maxspeed; static int tx_maxspeedpos; int tx_overallmax; /* combined view */ static float comb_maxspeed; int comb_overallmax; int solcount; int ledenabled; /* TX/RX led enabled */ slurm-0.4.0/slurm.spec000066400000000000000000000024761163133444000147030ustar00rootroot00000000000000%define name slurm %define version 0.2.3 %define release 1 Summary: A realtime network traffic statistic tool Name: %{name} Version: %{version} Release: %{release} Source0: %{name}-%{version}.tar.gz License: GPL Group: Applications/Multimedia BuildRoot: %{_tmppath}/%{name}-buildroot Requires: ncurses BuildRequires: ncurses-devel Packager: Ralf Ertzinger URL: http://www.wormulon.net/projects/slurm %description slurm started as a pppstatus port to FreeBSD. Features: * realtime traffic statistics divided into incoming and outgoing * optional combined view * can monitor any kind of network interface (testers welcome!) * shows detailed statistics about the interface. * contact me if you need anything else. %prep %setup %build %configure %{__make} %install [ $RPM_BUILD_ROOT != "/" ] && rm -rf $RPM_BUILD_ROOT %{__mkdir} -p $RPM_BUILD_ROOT %{__install} -d %{buildroot}/%{_bindir} %{__install} -d %{buildroot}/%{_mandir}/man1 %{__install} slurm %{buildroot}/%{_bindir} %{__install} slurm.1 %{buildroot}/%{_mandir}/man1 %clean [ $RPM_BUILD_ROOT != "/" ] && rm -rf $RPM_BUILD_ROOT %files %defattr(-,root,root) %doc Changelog README KEYS TODO THANKS COPYRIGHT %{_bindir}/slurm %{_mandir}/man1/slurm.1.gz %changelog * Thu May 15 2003 Ralf Ertzinger - Initial RPM build # end of file slurm-0.4.0/src/000077500000000000000000000000001163133444000134435ustar00rootroot00000000000000slurm-0.4.0/src/freebsd.c000066400000000000000000000066161163133444000152320ustar00rootroot00000000000000/* $Id: freebsd.c,v 1.8 2003/02/23 17:26:02 hscholz Exp $ */ /***************************************************************************** * * checkinterface() * * check if a given interface exists and is up. * return TRUE if it does and FALSE if not * ****************************************************************************/ int checkinterface(void) { int validinterface = FALSE; int i, num_iface; size_t len; int name[6]; struct ifmibdata ifmd; len = sizeof(num_iface); sysctlbyname("net.link.generic.system.ifcount", &num_iface, &len, NULL, 0); for (i=1; i <= num_iface; i++) { name[0] = CTL_NET; name[1] = PF_LINK; name[2] = NETLINK_GENERIC; name[3] = IFMIB_IFDATA; name[4] = i; name[5] = IFDATA_GENERAL; len = sizeof(ifmd); sysctl(name, 6, &ifmd, &len, NULL, 0); if (strcmp(ifmd.ifmd_name, (char *)ifdata.if_name) == 0) { /* * now we have an interface and just have to see if it's up * in case we just want to debug media types we disable * IFF_UP flags */ #ifndef MEDIADEBUG if (ifmd.ifmd_flags & IFF_UP) #endif validinterface = TRUE; break; /* in any case we can stop searching here */ } } return validinterface; } /****************************************************************************** * * get_stat() * * use sysctl() to read the statistics and fill statistics struct * ****************************************************************************/ int get_stat(void) { /* * use sysctl() to get the right interface number if !dev_opened * then read the data directly from the ifmd_data struct */ static int watchif = -1; int i, num_iface; size_t len; int name[6]; struct ifmibdata ifmd; static int dev_opened = 0; unsigned long rx_o, tx_o; if (!dev_opened) { len = sizeof(num_iface); sysctlbyname("net.link.generic.system.ifcount", &num_iface, &len, NULL, 0); for (i=1; i <= num_iface; i++) { name[0] = CTL_NET; name[1] = PF_LINK; name[2] = NETLINK_GENERIC; name[3] = IFMIB_IFDATA; name[4] = i; name[5] = IFDATA_GENERAL; len = sizeof(ifmd); sysctl(name, 6, &ifmd, &len, NULL, 0); if (strcmp(ifmd.ifmd_name, (char *)ifdata.if_name) == 0) { /* got the right interface */ watchif = i; dev_opened++; } } } /* in any case read the struct and record statistics */ name[0] = CTL_NET; name[1] = PF_LINK; name[2] = NETLINK_GENERIC; name[3] = IFMIB_IFDATA; name[4] = watchif; name[5] = IFDATA_GENERAL; len = sizeof(ifmd); sysctl(name, 6, &ifmd, &len, NULL, 0); rx_o = stats.rx_bytes; tx_o = stats.tx_bytes; stats.tx_packets = ifmd.ifmd_data.ifi_opackets; stats.rx_packets = ifmd.ifmd_data.ifi_ipackets; stats.rx_bytes = ifmd.ifmd_data.ifi_ibytes; stats.tx_bytes = ifmd.ifmd_data.ifi_obytes; stats.rx_errors = ifmd.ifmd_data.ifi_ierrors; stats.tx_errors = ifmd.ifmd_data.ifi_oerrors; if (rx_o > stats.rx_bytes) stats.rx_over++; if (tx_o > stats.tx_bytes) stats.tx_over++; return (0); } slurm-0.4.0/src/freebsd.h000066400000000000000000000000561163133444000152270ustar00rootroot00000000000000int get_stat(void); int checkinterface(void); slurm-0.4.0/src/hpux.c000066400000000000000000000132761163133444000146040ustar00rootroot00000000000000#include #define WAIT_PCKS_COUNTER 15 /* $Id: hpux.c,v 1.7 2003/02/23 17:26:02 hscholz Exp $ */ /***************************************************************************** * * _countinterfaces() * * count all network interfaces in the system. This function is intended to * use it only in hpux.c * ****************************************************************************/ int _countinterfaces(void) { int val, num_iface=-1, sd; if ((sd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) return (-1); if (ioctl(sd, SIOCGIFNUM, &val) != -1) num_iface = val; close(sd); return num_iface; } /***************************************************************************** * * _getifdata() * * get the Interface-ID, the Interface-Speed, and over all, check if the * given interface really exists. This function is intended to use it only in * hpux.c * ****************************************************************************/ void _getifdata() { int buffer, fd, val, ret = -1; unsigned int len, i; char tmpinterfacestring[sizeof(ifdata.if_name)+1],*strstrmatch; struct nmparms params; mib_ifEntry * if_buf; /* * The interface description is more then the pure devicename. * Let's do some formating to allow a propper pattern matching */ strcpy(tmpinterfacestring,ifdata.if_name); strcat(tmpinterfacestring," "); for (i=0; i <= ifdata.if_amount; i++) { if ((fd = open_mib("/dev/lan", O_RDWR, i, 0)) >= 0) { if ((if_buf = (mib_ifEntry *) malloc (sizeof(mib_ifEntry))) != 0) { params.objid = ID_ifEntry; params.buffer = if_buf; len = sizeof(mib_ifEntry); params.len = &len; if_buf->ifIndex = i+1; if ((ret = get_mib_info(fd, ¶ms)) == 0) { /* * The interface given by the user must start at the * beginning of if_buf->ifDescr. If that's the case, * strstrmatch is equal to if_buf->ifDescr. If not, * strstrmatch might be a subset of if_buf->ifDescr, * or NULL */ strstrmatch = strstr(if_buf->ifDescr, (char *)tmpinterfacestring); if ( strstrmatch && (strcmp(strstrmatch,if_buf->ifDescr)== 0)) { ifdata.if_valid = 1; ifdata.if_id = i+1; break; } } } } free(if_buf); close_mib(fd); } return; } /***************************************************************************** * * checkinterface() * * check if a given interface exists, return 1 if it does and 0 if not (This * function is a wrapper function for _countinterfaces && _getifdata.) * ****************************************************************************/ int checkinterface(void) { /* == 0 no network interfaces, -1 sth. went wrong */ if ((ifdata.if_amount =_countinterfaces()) > 0) _getifdata(); return ifdata.if_valid; } /****************************************************************************** * * get_stat() * * stub function for all unsupported operating systems * *****************************************************************************/ int get_stat(void) { int i,fd, ret=-1; static int wait_pcks_counter=WAIT_PCKS_COUNTER+1; unsigned int len; unsigned long rx_o, tx_o; struct nmparms params, params2; mib_ifEntry *if_buf; static nmapi_logstat *if_ptr = (nmapi_logstat *) 0; if (ifdata.if_valid == 1 && (fd = open_mib("/dev/lan", O_RDWR, 0, 0)) >= 0) { if ((if_buf = (mib_ifEntry *) malloc (sizeof(mib_ifEntry))) != 0) { if_buf->ifIndex = ifdata.if_id; params.objid = ID_ifEntry; params.buffer = if_buf; len = (unsigned int) sizeof(mib_ifEntry); params.len = &len; if ((ret = get_mib_info(fd, ¶ms)) == 0) { rx_o = stats.rx_bytes; tx_o = stats.tx_bytes; stats.tx_bytes = if_buf->ifOutOctets; stats.rx_bytes = if_buf->ifInOctets; stats.tx_errors = if_buf->ifOutErrors; stats.rx_errors = if_buf->ifInErrors; if (rx_o > stats.rx_bytes) stats.rx_over++; if (tx_o > stats.tx_bytes) stats.tx_over++; } } free(if_buf); /* * Getting the tx/rx packets every run often hurts to much performance * With WAIT_PCKS_COUNTER=15 i save on my system 43% cpu usage.instead of * WAIT_PCKS_COUNTER=0 */ if( wait_pcks_counter > WAIT_PCKS_COUNTER ) { if ((if_ptr = (nmapi_logstat *) malloc(sizeof(nmapi_logstat) * ifdata.if_amount)) != 0 ) { len = (unsigned int) ifdata.if_amount *sizeof(nmapi_logstat); if ((ret = get_logical_stat(if_ptr, &len)) == 0) { for (i=0; i <= ifdata.if_amount; i++) { if(if_ptr[i].ifindex == ifdata.if_id) { stats.tx_packets = if_ptr[i].out_packets; stats.rx_packets = if_ptr[i].in_packets; } } } } free(if_ptr); wait_pcks_counter=0; } else { wait_pcks_counter++; } } close_mib(fd); return(0); } slurm-0.4.0/src/hpux.h000066400000000000000000000001451163133444000146000ustar00rootroot00000000000000#ifndef _HPUX_H_ #define _HPUX_H_ extern int checkinterface(void); extern int get_stat(void); #endif slurm-0.4.0/src/if_media.c000066400000000000000000000213311163133444000153440ustar00rootroot00000000000000/****************************************************************************** * * src/if_media.h - part of slurm * * this file handles basic network information functions for all * operating systems. * ***************************************************************************** * $Id: if_media.c,v 1.35 2004/09/27 13:08:59 hscholz Exp $ *****************************************************************************/ #if defined (__FreeBSD__) || (__OpenBSD__) || (__NetBSD__) || (__MicroBSD__) || (__APPLE__) # define MEDIA_H_SUPPORTED #endif #if defined (__OpenBSD__) || (__NetBSD__) || (__MicroBSD__) || (__APPLE__) # define NON_FreeBSD 1 # define WIRELESS 1 #else # if defined(__FreeBSD__) # if (__FreeBSD_version >= 450000) # define WIRELESS 1 # endif # else # define WIRELESS 0 # endif #endif /****************************************************************************** * * get_if_speed() * * determine current interface speed, needs interface name as argument * return the interface speed as an integer. unit: kbit/s * in case of error return ERR_IFACE_NO_SPEED * * tested/supported operating systems: * * - FreeBSD * - OpenBSD * - NetBSD * - MicroBSD (99% OpenBSD) * *****************************************************************************/ #ifdef MEDIA_H_SUPPORTED int get_if_speed (char *ifstring) { int speed=ERR_IFACE_NO_SPEED; int s; /* socket */ struct ifmediareq ifmr; int *media_list; int type, physical; if ((s = socket(AF_INET, SOCK_DGRAM, 0)) == -1) { fprintf(stderr, "cannot create socket!\n"); return ERR_IFACE_NO_SPEED; } memset(&ifmr, 0, sizeof(ifmr)); strncpy(ifmr.ifm_name, (char *)ifstring, sizeof(ifmr.ifm_name)); if (ioctl(s, SIOCGIFMEDIA, (caddr_t)&ifmr) < 0) { fprintf(stderr, "interface does not support SIOCGIFMEDIA ioctl()\n"); return ERR_IFACE_NO_SPEED; } if (ifmr.ifm_count == 0) { fprintf(stderr, "%s: no media types?\n", (char *)ifstring); return ERR_IFACE_NO_SPEED; } media_list = (int *)malloc(ifmr.ifm_count * sizeof(int)); if (media_list == NULL) fprintf(stderr, "malloc() error in if_media.c\n"); ifmr.ifm_ulist = media_list; if (ioctl(s, SIOCGIFMEDIA, (caddr_t)&ifmr) < 0) { fprintf(stderr, "ioctl(SIOCGIFMEDIA) failed\n"); return -1; } /* * define type and physical * * bits: * 0-4 Media variant * 5-7 Media type * */ type = ifmr.ifm_active & 0xf0; physical = ifmr.ifm_active & 0x0f; #ifdef MEDIADEBUG printf(" all: %6d\n", ifmr.ifm_current); printf(" active: %6d\n", ifmr.ifm_active); printf(" status: %6d\n", ifmr.ifm_status); printf(" type: %6d\n", type); printf(" phys: %6d\n", physical); printf("if active: %6d\n", ifmr.ifm_active & IFM_ACTIVE); #ifdef __APPLE__ printf(" count: %6d\n", ifmr.ifm_count); #endif /* Apple debugging */ #endif /* switch type */ switch (type) { /* Ethernet */ case IFM_ETHER: switch (physical) { #ifdef __FreeBSD__ #if __FreeBSD__ <= 4 case IFM_1000_FX: case IFM_1000_TX: #endif #endif case IFM_1000_SX: case IFM_1000_LX: case IFM_1000_CX: #ifdef IFM_1000_T case IFM_1000_T: #endif speed = 1000 * 1000; break; case IFM_100_TX: case IFM_100_FX: case IFM_100_T4: case IFM_100_VG: case IFM_100_T2: speed = 100 * 1000; break; case IFM_10_T: case IFM_10_2: case IFM_10_5: case IFM_10_FL: case IFM_10_STP: speed = 10 * 1000; break; #if defined(__OpenBSD__) || (__MicroBSD__) || (__NetBSD__) || (__APPLE__) case IFM_HPNA_1: #else #if __FreeBSD__ <= 4 case IFM_homePNA: #endif #endif speed = 1 * 1000; break; default: speed = ERR_IFACE_NO_SPEED; break; } /* end switch physical */ break; /* FDDI interfaces */ /* fpa doesn't seem to support SIOCGIFMEDIA on FreeBSD * so we won't get here but anyway ... */ case IFM_FDDI: switch (physical) { case IFM_FDDI_SMF: case IFM_FDDI_MMF: case IFM_FDDI_UTP: speed = 100 * 1000; break; default: speed = ERR_IFACE_NO_SPEED; } break; #if WIRELESS /* IEEE 802.11 wireless interfaces */ case IFM_IEEE80211: switch (physical) { case IFM_IEEE80211_FH1: case IFM_IEEE80211_DS1: speed = 1 * 1000; break; case IFM_IEEE80211_FH2: case IFM_IEEE80211_DS2: speed = 2 * 1000; break; case IFM_IEEE80211_DS5: speed = (int) 5.5 * 1000; break; case IFM_IEEE80211_DS11: speed = 11 * 1000; break; #if WIRELESS && defined(__FreeBSD__) && (__FreeBSD_version >= 460102) case IFM_IEEE80211_DS22: speed = 22 * 1000; break; #endif #if WIRELESS && \ (defined(__FreeBSD__) && (__FreeBSD_version >= 500111)) || \ (defined(__NetBSD__) && (__NetBSD_Version_ > 106020000)) case IFM_IEEE80211_OFDM6: speed = 6 * 1000; break; case IFM_IEEE80211_OFDM9: speed = 9 * 1000; break; case IFM_IEEE80211_OFDM12: speed = 12 * 1000; break; case IFM_IEEE80211_OFDM18: speed = 18 * 1000; break; case IFM_IEEE80211_OFDM24: speed = 24 * 1000; break; case IFM_IEEE80211_OFDM36: speed = 36 * 1000; break; case IFM_IEEE80211_OFDM48: speed = 48 * 1000; break; case IFM_IEEE80211_OFDM54: speed = 54 * 1000; break; case IFM_IEEE80211_OFDM72: speed = 72 * 1000; break; #endif default: speed = ERR_IFACE_NO_SPEED; break; } break; #endif default: speed = ERR_IFACE_NO_SPEED; } /* end switch type */ #ifdef MEDIADEBUG printf(" speed: %6d\n", speed); #endif return speed; } #elif __HPUX__ int get_if_speed(char *ifstring) { int speed=ERR_IFACE_NO_SPEED, buffer, fd, val, ret = -1; unsigned int len, i; struct nmparms params; mib_ifEntry * if_buf; for (i=0; i <= ifdata.if_amount; i++) { if ((fd = open_mib("/dev/lan", O_RDWR, i, 0)) >= 0) { if ((if_buf = (mib_ifEntry *) malloc (sizeof(mib_ifEntry))) != 0) { params.objid = ID_ifEntry; params.buffer = if_buf; len = sizeof(mib_ifEntry); params.len = &len; if_buf->ifIndex = i+1; if ((ret = get_mib_info(fd, ¶ms)) == 0) { if ( i+1 == ifdata.if_id) if (if_buf->ifOper == 1) speed = if_buf->ifSpeed/1000; else speed ERR_IFACE_DOWN; } } } free(if_buf); close_mib(fd); } return speed; } #elif defined (__Solaris__) /****************************************************************************** * * Solaris interface speed detection * *****************************************************************************/ int get_if_speed(char *ifstring) { int speed=ERR_IFACE_NO_SPEED; kstat_t *ksp; kstat_named_t *knp; kstat_ctl_t *kc; if ((kc = kstat_open()) == NULL) return ERR_IFACE_NO_SPEED; ksp = kstat_lookup(kc, NULL, -1, ifstring); if (ksp && kstat_read(kc, ksp, NULL) >= 0) { knp = (kstat_named_t *)kstat_data_lookup(ksp, "ifspeed"); if (knp) speed = (int) knp->value.ui64 / 1000; } kstat_close(kc); return speed; } #else int get_if_speed(char *ifstring) { ifstring++; /* ugly hack to prevent compiler warning on Linux */ return ERR_IFACE_NO_SPEED; } #endif slurm-0.4.0/src/if_media.h000066400000000000000000000001721163133444000153510ustar00rootroot00000000000000/* interface speed detection errors */ #define ERR_IFACE_NO_SPEED -1 #define ERR_IFACE_DOWN -2 int get_if_speed(char *); slurm-0.4.0/src/linux.c000066400000000000000000000055301163133444000147510ustar00rootroot00000000000000/* $Id: linux.c,v 1.12 2003/09/06 10:44:50 hscholz Exp $ */ /***************************************************************************** * * checkinterface() * * check if a given interface exists and is up. * return TRUE if found, FALSE if not * ****************************************************************************/ int checkinterface(void) { int interfacefound = FALSE; unsigned int i; struct if_nameindex *ifs; if ((ifs = if_nameindex()) == NULL) return FALSE; for (i = 0; ifs[i].if_index; i++) { if (strcmp(ifs[i].if_name, ifdata.if_name) == 0) { interfacefound = TRUE; break; } } return interfacefound; } /****************************************************************************** * * get_stat() * * read the network statistics from /proc/net/dev (PATH_NET_DEV) * if the file is not open open it. fseek() to the beginning and parse * each line until we've found the right interface * * returns 0 if successful, 1 in case of error * *****************************************************************************/ int get_stat(void) { static int opened = 0; char buffer[BUFSIZE]; char *ptr; char *devname; unsigned long dump; int interfacefound; unsigned long rx_o, tx_o; if (opened != 1) { if ((proc_net_dev = fopen(PATH_NET_DEV, "r")) == NULL) { fprintf(stderr, "cannot open %s!\nnot running Linux?\n", PATH_NET_DEV); exit(1); } opened++; } /* backup old rx/tx values */ rx_o = stats.rx_bytes; tx_o = stats.tx_bytes; /* do not parse the first two lines as they only contain static garbage */ fseek(proc_net_dev, 0, SEEK_SET); fgets(buffer, BUFSIZ-1, proc_net_dev); fgets(buffer, BUFSIZ-1, proc_net_dev); interfacefound = 0; while (fgets(buffer, BUFSIZ-1, proc_net_dev) != NULL) { /* find the device name and substitute ':' with '\0' */ ptr = buffer; while (*ptr == ' ') ptr++; devname = ptr; while (*ptr != ':') ptr++; *ptr = '\0'; ptr++; if (!strcmp(devname, (char *) ifdata.if_name)) { /* read stats and fill struct */ sscanf(ptr, "%lg %lu %lu %lu %lu %lu %lu %lu %lg %lu %lu %lu %lu %lu %lu %lu", &stats.rx_bytes, &stats.rx_packets, &stats.rx_errors, &dump, &dump, &dump, &dump, &dump, &stats.tx_bytes, &stats.tx_packets, &stats.tx_errors, &dump, &dump, &dump, &dump, &dump); interfacefound = 1; continue; /* break, as we won't get any new information */ } } if (interfacefound) { if (rx_o > stats.rx_bytes) stats.rx_over++; if (tx_o > stats.tx_bytes) stats.tx_over++; } return (interfacefound == 1)? 0 : 1; } slurm-0.4.0/src/linux.h000066400000000000000000000001321163133444000147470ustar00rootroot00000000000000int checkinterface(void); int get_stat(void); #ifdef __linux__ #define BUFSIZE 256 #endif slurm-0.4.0/src/macos.c000066400000000000000000000102201163133444000147040ustar00rootroot00000000000000/* $Id: macos.c,v 1.1 2003/09/10 19:07:32 hscholz Exp $ */ /***************************************************************************** * * checkinterface() * * check if a given interface exists, return TRUE if it does and FALSE if not * ****************************************************************************/ int checkinterface() { int validinterface = FALSE; static int mib_name[] = { CTL_NET, PF_ROUTE, 0, 0, NET_RT_IFLIST, 0 }; static char *buf; static int alloc; char *lim, *next; struct if_msghdr *ifm, *nextifm; struct sockaddr_dl *sdl; size_t needed; char s[32]; if (sysctl(mib_name, 6, NULL, &needed, NULL, 0) < 0) return FALSE; if (alloc < (signed long) needed) { if (buf != NULL) free (buf); buf = malloc(needed); if (buf == NULL) return FALSE; alloc = needed; } if (sysctl(mib_name, 6, buf, &needed, NULL, 0) < 0) return FALSE; lim = buf + needed; next = buf; while ((next < lim) && (validinterface == 0)) { ifm = (struct if_msghdr *)next; if (ifm->ifm_type != RTM_IFINFO) return FALSE; next += ifm->ifm_msglen; while (next < lim) { nextifm = (struct if_msghdr *)next; if (nextifm->ifm_type != RTM_NEWADDR) break; next += nextifm->ifm_msglen; } if (ifm->ifm_flags & IFF_UP) { sdl = (struct sockaddr_dl *)(ifm + 1); strncpy(s, sdl->sdl_data, sdl->sdl_nlen); s[sdl->sdl_nlen] = '\0'; /* search for the right network interface */ if (sdl->sdl_family != AF_LINK) continue; if (strcmp(s, ifdata.if_name) != 0) continue; else { validinterface = TRUE; break; /* stop searching */ } } } return validinterface; } /****************************************************************************** * * get_stat() * * this code is based on gkrellm code (thanks guys!) * ****************************************************************************/ int get_stat(void) { static int mib_name[] = { CTL_NET, PF_ROUTE, 0, 0, NET_RT_IFLIST, 0 }; static char *buf; static int alloc; char *lim, *next; struct if_msghdr *ifm, *nextifm; struct sockaddr_dl *sdl; char s[32]; size_t needed; unsigned long rx_o, tx_o; if (sysctl(mib_name, 6, NULL, &needed, NULL, 0) < 0) return 1; if (alloc < (signed long) needed) { if (buf != NULL) free (buf); buf = malloc(needed); if (buf == NULL) return 1; alloc = needed; } if (sysctl(mib_name, 6, buf, &needed, NULL, 0) < 0) return 1; lim = buf + needed; next = buf; while (next < lim) { ifm = (struct if_msghdr *)next; if (ifm->ifm_type != RTM_IFINFO) return 1; next += ifm->ifm_msglen; while (next < lim) { nextifm = (struct if_msghdr *)next; if (nextifm->ifm_type != RTM_NEWADDR) break; next += nextifm->ifm_msglen; } if (ifm->ifm_flags & IFF_UP) { sdl = (struct sockaddr_dl *)(ifm + 1); strncpy(s, sdl->sdl_data, sdl->sdl_nlen); s[sdl->sdl_nlen] = '\0'; /* search for the right network interface */ if (strcmp(s, ifdata.if_name) != 0) continue; rx_o = stats.rx_bytes; tx_o = stats.tx_bytes; /* write stats */ stats.tx_packets = ifm->ifm_data.ifi_opackets; stats.rx_packets = ifm->ifm_data.ifi_ipackets; stats.rx_bytes = ifm->ifm_data.ifi_ibytes; stats.tx_bytes = ifm->ifm_data.ifi_obytes; stats.rx_errors = ifm->ifm_data.ifi_ierrors; stats.tx_errors = ifm->ifm_data.ifi_oerrors; if (rx_o > stats.rx_bytes) stats.rx_over++; if (tx_o > stats.tx_bytes) stats.tx_over++; } } return 0; } slurm-0.4.0/src/macos.h000066400000000000000000000000561163133444000147170ustar00rootroot00000000000000int get_stat(void); int checkinterface(void); slurm-0.4.0/src/netbsd.c000066400000000000000000000102211163133444000150620ustar00rootroot00000000000000/* $Id: netbsd.c,v 1.5 2003/02/23 17:26:02 hscholz Exp $ */ /***************************************************************************** * * checkinterface() * * check if a given interface exists, return TRUE if it does and FALSE if not * ****************************************************************************/ int checkinterface() { int validinterface = FALSE; static int mib_name[] = { CTL_NET, PF_ROUTE, 0, 0, NET_RT_IFLIST, 0 }; static char *buf; static int alloc; char *lim, *next; struct if_msghdr *ifm, *nextifm; struct sockaddr_dl *sdl; size_t needed; char s[32]; if (sysctl(mib_name, 6, NULL, &needed, NULL, 0) < 0) return FALSE; if (alloc < (signed long) needed) { if (buf != NULL) free (buf); buf = malloc(needed); if (buf == NULL) return FALSE; alloc = needed; } if (sysctl(mib_name, 6, buf, &needed, NULL, 0) < 0) return FALSE; lim = buf + needed; next = buf; while ((next < lim) && (validinterface == 0)) { ifm = (struct if_msghdr *)next; if (ifm->ifm_type != RTM_IFINFO) return FALSE; next += ifm->ifm_msglen; while (next < lim) { nextifm = (struct if_msghdr *)next; if (nextifm->ifm_type != RTM_NEWADDR) break; next += nextifm->ifm_msglen; } if (ifm->ifm_flags & IFF_UP) { sdl = (struct sockaddr_dl *)(ifm + 1); strncpy(s, sdl->sdl_data, sdl->sdl_nlen); s[sdl->sdl_nlen] = '\0'; /* search for the right network interface */ if (sdl->sdl_family != AF_LINK) continue; if (strcmp(s, ifdata.if_name) != 0) continue; else { validinterface = TRUE; break; /* stop searching */ } } } return validinterface; } /****************************************************************************** * * get_stat() * * this code is based on gkrellm code (thanks guys!) * ****************************************************************************/ int get_stat(void) { static int mib_name[] = { CTL_NET, PF_ROUTE, 0, 0, NET_RT_IFLIST, 0 }; static char *buf; static int alloc; char *lim, *next; struct if_msghdr *ifm, *nextifm; struct sockaddr_dl *sdl; char s[32]; size_t needed; unsigned long rx_o, tx_o; if (sysctl(mib_name, 6, NULL, &needed, NULL, 0) < 0) return 1; if (alloc < (signed long) needed) { if (buf != NULL) free (buf); buf = malloc(needed); if (buf == NULL) return 1; alloc = needed; } if (sysctl(mib_name, 6, buf, &needed, NULL, 0) < 0) return 1; lim = buf + needed; next = buf; while (next < lim) { ifm = (struct if_msghdr *)next; if (ifm->ifm_type != RTM_IFINFO) return 1; next += ifm->ifm_msglen; while (next < lim) { nextifm = (struct if_msghdr *)next; if (nextifm->ifm_type != RTM_NEWADDR) break; next += nextifm->ifm_msglen; } if (ifm->ifm_flags & IFF_UP) { sdl = (struct sockaddr_dl *)(ifm + 1); strncpy(s, sdl->sdl_data, sdl->sdl_nlen); s[sdl->sdl_nlen] = '\0'; /* search for the right network interface */ if (strcmp(s, ifdata.if_name) != 0) continue; rx_o = stats.rx_bytes; tx_o = stats.tx_bytes; /* write stats */ stats.tx_packets = ifm->ifm_data.ifi_opackets; stats.rx_packets = ifm->ifm_data.ifi_ipackets; stats.rx_bytes = ifm->ifm_data.ifi_ibytes; stats.tx_bytes = ifm->ifm_data.ifi_obytes; stats.rx_errors = ifm->ifm_data.ifi_ierrors; stats.tx_errors = ifm->ifm_data.ifi_oerrors; if (rx_o > stats.rx_bytes) stats.rx_over++; if (tx_o > stats.tx_bytes) stats.tx_over++; } } return 0; } slurm-0.4.0/src/netbsd.h000066400000000000000000000000561163133444000150740ustar00rootroot00000000000000int get_stat(void); int checkinterface(void); slurm-0.4.0/src/openbsd.c000066400000000000000000000103241163133444000152410ustar00rootroot00000000000000/* $Id: openbsd.c,v 1.7 2003/02/23 17:26:02 hscholz Exp $ */ /***************************************************************************** * * checkinterface() * * check if a given interface exists, return TRUE if it does and FALSE if not * ****************************************************************************/ int checkinterface() { int validinterface = FALSE; static int mib_name[] = { CTL_NET, PF_ROUTE, 0, 0, NET_RT_IFLIST, 0 }; static char *buf; static int alloc; char *lim, *next; struct if_msghdr *ifm, *nextifm; struct sockaddr_dl *sdl; size_t needed; char s[32]; if (sysctl(mib_name, 6, NULL, &needed, NULL, 0) < 0) return FALSE; if (alloc < (signed long) needed) { if (buf != NULL) free (buf); buf = malloc(needed); if (buf == NULL) return FALSE; alloc = needed; } if (sysctl(mib_name, 6, buf, &needed, NULL, 0) < 0) return FALSE; lim = buf + needed; next = buf; while ((next < lim) && (validinterface == 0)) { ifm = (struct if_msghdr *)next; if (ifm->ifm_type != RTM_IFINFO) return FALSE; next += ifm->ifm_msglen; while (next < lim) { nextifm = (struct if_msghdr *)next; if (nextifm->ifm_type != RTM_NEWADDR) break; next += nextifm->ifm_msglen; } if (ifm->ifm_flags & IFF_UP) { sdl = (struct sockaddr_dl *)(ifm + 1); strncpy(s, sdl->sdl_data, sdl->sdl_nlen); s[sdl->sdl_nlen] = '\0'; /* search for the right network interface */ if (sdl->sdl_family != AF_LINK) continue; if (strcmp(s, ifdata.if_name) != 0) continue; else { validinterface = TRUE; break; /* stop searching */ } } } return validinterface; } /***************************************************************************** * * get_stat() * * this code is based on gkrellm code (thanks guys!) * ****************************************************************************/ int get_stat(void) { static int mib_name[] = { CTL_NET, PF_ROUTE, 0, 0, NET_RT_IFLIST, 0 }; static char *buf; static int alloc; char *lim, *next; struct if_msghdr *ifm, *nextifm; struct sockaddr_dl *sdl; char s[32]; size_t needed; unsigned long rx_o, tx_o; if (sysctl(mib_name, 6, NULL, &needed, NULL, 0) < 0) return 1; if (alloc < (signed long) needed) { if (buf != NULL) free (buf); buf = malloc(needed); if (buf == NULL) return 1; alloc = needed; } if (sysctl(mib_name, 6, buf, &needed, NULL, 0) < 0) return 1; lim = buf + needed; next = buf; while (next < lim) { ifm = (struct if_msghdr *)next; if (ifm->ifm_type != RTM_IFINFO) return 1; next += ifm->ifm_msglen; while (next < lim) { nextifm = (struct if_msghdr *)next; if (nextifm->ifm_type != RTM_NEWADDR) break; next += nextifm->ifm_msglen; } if (ifm->ifm_flags & IFF_UP) { sdl = (struct sockaddr_dl *)(ifm + 1); /* search for the right network interface */ if (sdl->sdl_family != AF_LINK) continue; if (strcmp(sdl->sdl_data, ifdata.if_name) != 0) continue; strncpy(s, sdl->sdl_data, sdl->sdl_nlen); s[sdl->sdl_nlen] = '\0'; rx_o = stats.rx_bytes; tx_o = stats.tx_bytes; /* write stats */ stats.tx_packets = ifm->ifm_data.ifi_opackets; stats.rx_packets = ifm->ifm_data.ifi_ipackets; stats.rx_bytes = ifm->ifm_data.ifi_ibytes; stats.tx_bytes = ifm->ifm_data.ifi_obytes; stats.rx_errors = ifm->ifm_data.ifi_ierrors; stats.tx_errors = ifm->ifm_data.ifi_oerrors; if (rx_o > stats.rx_bytes) stats.rx_over++; if (tx_o > stats.tx_bytes) stats.tx_over++; } } return 0; } slurm-0.4.0/src/openbsd.h000066400000000000000000000000561163133444000152470ustar00rootroot00000000000000int get_stat(void); int checkinterface(void); slurm-0.4.0/src/solaris.c000066400000000000000000000067401163133444000152720ustar00rootroot00000000000000/* $Id: solaris.c,v 1.6 2003/09/11 12:08:17 hscholz Exp $ */ /***************************************************************************** * * checkinterface() * * check if a given interface exists, return TRUE if it does and FALSE if not * ****************************************************************************/ int checkinterface() { int validinterface = FALSE; int sockfd, i, numifs, numifreqs; size_t bufsize; char *buf; struct ifreq ifr, *ifrp; struct ifconf ifc; if((sockfd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) { perror("socket"); return FALSE; } if (ioctl(sockfd, SIOCGIFNUM, (char *) &numifs) < 0) { perror("SIOCGIFNUM"); close(sockfd); return FALSE; } bufsize = ((size_t) numifs) * sizeof(struct ifreq); buf = (char *) malloc(bufsize); if (!buf) { perror("malloc"); close(sockfd); return FALSE; } ifc.ifc_len = bufsize; ifc.ifc_buf = buf; if (ioctl(sockfd, SIOCGIFCONF, (char *) &ifc) < 0) { perror("SIOCGIFCONF"); close(sockfd); free(buf); return FALSE; } ifrp = ifc.ifc_req; numifreqs = ifc.ifc_len / sizeof(struct ifreq); for (i = 0; i < numifreqs; i++, ifrp++) { memset((char *)&ifr, 0, sizeof(ifr)); strncpy(ifr.ifr_name, ifrp->ifr_name, sizeof(ifr.ifr_name)); /* do not check for loopback device as it cannot be monitored */ if (!strncmp(ifr.ifr_name, "lo", 2)) continue; if (ioctl(sockfd, SIOCGIFFLAGS, &ifr) < 0) { perror("SIOCGIFFLAGS"); continue; } if (!strcmp(ifdata.if_name, ifr.ifr_name) && (ifr.ifr_flags & IFF_UP)) { validinterface = TRUE; break; } } free(buf); close(sockfd); return validinterface; } /***************************************************************************** * * get_stat() * * use the Solaris kstat_*() interface to gather statistics * We have to open/close *kc each time :( * ****************************************************************************/ int get_stat(void) { kstat_t *ksp; kstat_named_t *knp; kstat_ctl_t *kc; unsigned long rx_o, tx_o; if ((kc = kstat_open()) == NULL) { perror("kstat_open()"); return 1; } rx_o = stats.rx_bytes; tx_o = stats.tx_bytes; ksp = kstat_lookup(kc, NULL, -1, ifdata.if_name); if (ksp && kstat_read(kc, ksp, NULL) >= 0) { knp = (kstat_named_t *)kstat_data_lookup(ksp, "opackets"); if (knp) stats.tx_packets = knp->value.ui32; knp = (kstat_named_t *)kstat_data_lookup(ksp, "ipackets"); if (knp) stats.rx_packets = knp->value.ui32; knp = (kstat_named_t *)kstat_data_lookup(ksp, "obytes"); if (knp) stats.tx_bytes = knp->value.ui32; knp = (kstat_named_t *)kstat_data_lookup(ksp, "rbytes"); if (knp) stats.rx_bytes = knp->value.ui32; knp = (kstat_named_t *)kstat_data_lookup(ksp, "oerrors"); if (knp) stats.tx_errors = knp->value.ui32; knp = (kstat_named_t *)kstat_data_lookup(ksp, "ierrors"); if (knp) stats.rx_errors = knp->value.ui32; } kstat_close(kc); /* check for overflows */ if (rx_o > stats.rx_bytes) stats.rx_over++; if (tx_o > stats.tx_bytes) stats.tx_over++; return 0; } slurm-0.4.0/src/solaris.h000066400000000000000000000000561163133444000152710ustar00rootroot00000000000000int get_stat(void); int checkinterface(void); slurm-0.4.0/src/unsupported.c000066400000000000000000000005261163133444000162020ustar00rootroot00000000000000/* $Id: unsupported.c,v 1.2 2003/02/23 17:26:02 hscholz Exp $ */ /****************************************************************************** * * get_stat() * * stub function for all unsupported operating systems * *****************************************************************************/ int get_stat(void) { return 0; } slurm-0.4.0/src/unsupported.h000066400000000000000000000000241163133444000162000ustar00rootroot00000000000000int get_stat(void); slurm-0.4.0/theme.c000066400000000000000000000160261163133444000141270ustar00rootroot00000000000000/****************************************************************************** * * theme.c - slurm theme engine * ****************************************************************************** * $Id: theme.c,v 1.5 2004/09/28 14:23:02 hscholz Exp $ *****************************************************************************/ #ifndef _THEME_C #define _THEME_C /****************************************************************************** * * theme_setdefault() * * set default theme * *****************************************************************************/ void theme_setdefault(theme *t) { if (t == NULL) error(ERR_FATAL, "theme_setdefault() received NULL pointer"); t->background = COLOR_TRANSPARENT; t->rx = COLOR_GREEN; t->tx = COLOR_RED; t->text = COLOR_WHITE; t->var = COLOR_WHITE; t->title = COLOR_WHITE; t->rx_attrib = COL_BOLD; t->tx_attrib = COL_BOLD; t->text_attrib = COL_NORMAL; t->var_attrib = COL_BOLD; t->title_attrib = COL_BOLD; t->complete = E_ALL; } /****************************************************************************** * * theme_readfile() * * read color definitions from the given file and store in theme struct * *****************************************************************************/ int theme_readfile(theme *t, char *name) { FILE *f; char buf[BUFSIZ+1]; char filename[BUFSIZ+1]; char *p, *val, *key; t->complete = E_NULL; /* search for the theme: * - in the local directory * - in ~/.slurm * - in /usr/local/share/slurm * (make this /usr/share/slurm for Debian systems by specifing * -D__Debian__) */ bzero(&filename, BUFSIZ); snprintf(filename, BUFSIZ, "%s.theme", name); if ((f = fopen(filename, "r")) == NULL) { bzero(&filename, BUFSIZ); snprintf(filename, BUFSIZ, "%s/.slurm/%s.theme", getenv("HOME"), name); if ((f = fopen(filename, "r")) == NULL) { bzero(&filename, BUFSIZ); #ifdef __NetBSD__ snprintf(filename, BUFSIZ, "/usr/pkg/share/slurm/%s.theme", name); #elif __Debian__ snprintf(filename, BUFSIZ, "/usr/share/slurm/%s.theme", name); #else snprintf(filename, BUFSIZ, "/usr/local/share/slurm/%s.theme", name); #endif if ((f = fopen(filename, "r")) == NULL) error(ERR_FATAL, "cannot find theme '%s'", name); } } while (fgets(buf, BUFSIZ, f) != NULL) { if (!strncmp(buf,"#",1)) continue; /* comment */ p = buf; while (isspace((int) *p) && (*p+1 != '\0')) p++; key = p; while (isalpha((int) *p) && (*p+1 != '\0')) p++; if (isspace((int) *p)) { *p++ = '\0'; while (isspace((int) *p) && (*p+1 != '\0')) p++; if (*p != '=') continue; p++; while (isspace((int) *p) && (*p+1 != '\0')) p++; } else if (*p == '=') { *p++ = '\0'; while (isspace((int) *p) && (*p+1 != '\0')) p++; } else continue; val = p; while (isalpha((int) *p) && (*p+1 != '\0')) p++; *p++ = '\0'; switch (theme_mapkey(key)) { case E_BACKGROUND: t->background = theme_mapcolor(val); t->complete |= E_BACKGROUND; break; case E_RX: t->rx = theme_mapcolor(val); t->complete |= E_RX; break; case E_TX: t->tx = theme_mapcolor(val); t->complete |= E_TX; break; case E_TEXT: t->text = theme_mapcolor(val); t->complete |= E_TEXT; break; case E_TITLE: t->title = theme_mapcolor(val); t->complete |= E_TITLE; break; case E_TEXTVAR: t->var = theme_mapcolor(val); t->complete |= E_TEXTVAR; break; case E_RXATTR: t->rx_attrib = theme_mapattrib(val); t->complete |= E_RXATTR; break; case E_TXATTR: t->tx_attrib = theme_mapattrib(val); t->complete |= E_TXATTR; break; case E_TEXTATTR: t->text_attrib = theme_mapattrib(val); t->complete |= E_TEXTATTR; break; case E_TEXTVARATTR: t->var_attrib = theme_mapattrib(val); t->complete |= E_TEXTVARATTR; break; case E_TITLEATTR: t->title_attrib = theme_mapattrib(val); t->complete |= E_TITLEATTR; break; default: error(ERR_WARNING, "unknown key '%s' in theme '%s'", key, filename); } } fclose(f); return (t->complete == E_ALL)? 1 : 0; } /****************************************************************************** * * theme_mapattrib() * * map entity attribute to coresponding curses attribute * *****************************************************************************/ int theme_mapattrib(char *str) { int val = COL_BOLD; char buf[32]; int i; if (strlen(str) > 31) return val; bzero(&buf, 31); for (i = 0; i < strlen(str); i++) buf[i] = toupper((int) str[i]); buf[i+1] = '\0'; if (!strcmp(buf, "BOLD")) val = COL_BOLD; else if (!strcmp(buf, "NORMAL")) val = COL_NORMAL; else if (!strcmp(buf, "DIM")) val = COL_DIM; return val; } /****************************************************************************** * * theme_mapcolor() * * map color name to coresponding curses color name * *****************************************************************************/ int theme_mapcolor(char *str) { int val = COLOR_GREEN; char buf[32]; int i; if (strlen(str) > 31) return val; bzero(&buf, 31); for (i = 0; i < strlen(str); i++) buf[i] = toupper((int) str[i]); buf[i+1] = '\0'; if (!strcmp(buf, "BLACK")) val = COLOR_BLACK; else if (!strcmp(buf, "RED")) val = COLOR_RED; else if (!strcmp(buf, "GREEN")) val = COLOR_GREEN; else if (!strcmp(buf, "YELLOW")) val = COLOR_YELLOW; else if (!strcmp(buf, "BLUE")) val = COLOR_BLUE; else if (!strcmp(buf, "MAGENTA")) val = COLOR_MAGENTA; else if (!strcmp(buf, "CYAN")) val = COLOR_CYAN; else if (!strcmp(buf, "WHITE")) val = COLOR_WHITE; else if (!strcmp(buf, "TRANSPARENT")) val = COLOR_TRANSPARENT; return val; } /****************************************************************************** * * theme_mapkey() * * map entity name to internal name * *****************************************************************************/ int theme_mapkey(char *str) { int e = 0; char buf[32]; int i; if (strlen(str) > 31) return e; bzero(&buf, 31); for (i = 0; i < strlen(str); i++) buf[i] = toupper((int) str[i]); buf[i+1] = '\0'; if (!strcmp(buf, "BACKGROUND")) e = E_BACKGROUND; else if (!strcmp(buf, "RX")) e = E_RX; else if (!strcmp(buf, "TX")) e = E_TX; else if (!strcmp(buf, "TEXT")) e = E_TEXT; else if (!strcmp(buf, "TITLE")) e = E_TITLE; else if (!strcmp(buf, "TEXTVAR")) e = E_TEXTVAR; else if (!strcmp(buf, "RXATTR")) e = E_RXATTR; else if (!strcmp(buf, "TXATTR")) e = E_TXATTR; else if (!strcmp(buf, "TEXTATTR")) e = E_TEXTATTR; else if (!strcmp(buf, "TEXTVARATTR")) e = E_TEXTVARATTR; else if (!strcmp(buf, "TITLEATTR")) e = E_TITLEATTR; return e; } #endif slurm-0.4.0/theme.h000066400000000000000000000031231163133444000141260ustar00rootroot00000000000000/****************************************************************************** * * theme.h - slurm theme engine definitions * ****************************************************************************** * $Id: theme.h,v 1.2 2003/07/09 16:45:37 hscholz Exp $ *****************************************************************************/ #ifndef _THEME_H #define _THEME_H /* prototypes */ int theme_mapcolor(char *); int theme_mapattrib(char *); int theme_mapkey(char *); typedef struct { int complete; int background; int rx; int rx_attrib; int tx; int tx_attrib; int text; int text_attrib; int var; int var_attrib; int title; int title_attrib; } theme; theme t; /* possible entities */ #define E_BACKGROUND 0x0101 #define E_RX 0x0102 #define E_TX 0x0104 #define E_TEXT 0x0108 #define E_TEXTVAR 0x0110 #define E_TITLE 0x0120 #define E_RXATTR 0x0201 #define E_TXATTR 0x0202 #define E_TEXTATTR 0x0204 #define E_TEXTVARATTR 0x0208 #define E_TITLEATTR 0x0210 #define E_ALL (E_BACKGROUND | E_RX | E_TX | E_TEXT | E_TEXTVAR | \ E_RXATTR | E_TXATTR | E_TEXTATTR | E_TEXTVARATTR | \ E_TITLE | E_TITLEATTR) #define E_NULL 0 /* color definitions */ #ifndef COLOR_BLACK #define COLOR_BLACK 0 #define COLOR_RED 1 #define COLOR_GREEN 2 #define COLOR_YELLOW 3 #define COLOR_BLUE 4 #define COLOR_MAGENTA 5 #define COLOR_CYAN 6 #define COLOR_WHITE 7 #endif #define COLOR_TRANSPARENT -1 #define COL_NORMAL 0 #define COL_BOLD 1 #define COL_DIM 2 /* internal color pairs */ #define PAIR_TEXT 1 #define PAIR_RX 2 #define PAIR_TX 3 #define PAIR_VAR 4 #define PAIR_TITLE 5 #endif slurm-0.4.0/themes/000077500000000000000000000000001163133444000141415ustar00rootroot00000000000000slurm-0.4.0/themes/black.theme000066400000000000000000000003461163133444000162440ustar00rootroot00000000000000# # black.theme # # $Id: black.theme,v 1.1 2004/09/28 13:44:35 hscholz Exp $ # BACKGROUND=TRANSPARENT RX=GREEN TX=RED TEXT=BLACK TEXTVAR=BLACK TEXTATTR=NORMAL RXATTR=NORMAL TXATTR=BOLD TEXTVARATTR=BOLD TITLE=BLACK TITLEATTR=BOLD slurm-0.4.0/themes/blue.theme000066400000000000000000000003411163133444000161120ustar00rootroot00000000000000# # blue.theme # # $Id: blue.theme,v 1.1 2003/05/25 14:45:23 hscholz Exp $ # BACKGROUND=TRANSPARENT RX=BLUE RXATTR=NORMAL TX=BLUE TXATTR=BOLD TEXT=BLUE TEXTVAR=BLUE TEXTATTR=NORMAL TEXTVARATTR=BOLD TITLE=BLUE TITLEATTR=BOLD slurm-0.4.0/themes/cyan.theme000066400000000000000000000003441163133444000161200ustar00rootroot00000000000000# # cyan.theme # # $Id: cyan.theme,v 1.1 2003/07/09 16:45:38 hscholz Exp $ # BACKGROUND=TRANSPARENT RX=CYAN RXATTR=normal TX=CYAN TXATTR=BOLD TEXT=BLUE TEXTVAR=CYAN TEXTATTR=NORMAL TEXTVARATTR=normal TITLE=WHITE TITLEATTR=BOLD slurm-0.4.0/themes/foo.theme000066400000000000000000000003441163133444000157510ustar00rootroot00000000000000# # bright.theme # # $Id: foo.theme,v 1.1 2003/05/25 14:45:23 hscholz Exp $ # BACKGROUND=TRANSPARENT RX=GREEN TX=RED TEXT=WHITE TEXTVAR=CYAN TEXTATTR=NORMAL RXATTR=NORMAL TXATTR=BOLD TEXTVARATTR=BOLD TITLE=WHITE TITLEATTR=BOLD