/* $Id: plugin_ppp.c,v 1.10 2005/05/08 04:32:44 reinelt Exp $ * * plugin for ppp throughput * * Copyright (C) 2003 Michael Reinelt * Copyright (C) 2004 The LCD4Linux Team * * This file is part of LCD4Linux. * * LCD4Linux 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. * * LCD4Linux is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * * * $Log: plugin_ppp.c,v $ * Revision 1.10 2005/05/08 04:32:44 reinelt * CodingStyle added and applied * * Revision 1.9 2005/01/18 06:30:23 reinelt * added (C) to all copyright statements * * Revision 1.8 2004/06/26 12:05:00 reinelt * * uh-oh... the last CVS log message messed up things a lot... * * Revision 1.7 2004/06/26 09:27:21 reinelt * * added '-W' to CFLAGS * changed all C++ comments to C ones * cleaned up a lot of signed/unsigned mistakes * * Revision 1.6 2004/06/17 06:23:43 reinelt * * hash handling rewritten to solve performance issues * * Revision 1.5 2004/05/29 15:53:28 reinelt * * M50530: reset parport signals on exit * plugin_ppp: ppp() has two parameters, not three * lcd4linux.conf.sample: diskstats() corrected * * Revision 1.4 2004/03/03 04:44:16 reinelt * changes (cosmetics?) to the big patch from Martin * hash patch un-applied * * Revision 1.3 2004/03/03 03:47:04 reinelt * big patch from Martin Hejl: * - use qprintf() where appropriate * - save CPU cycles on gettimeofday() * - add quit() functions to free allocated memory * - fixed lots of memory leaks * * Revision 1.2 2004/01/28 06:43:31 reinelt * plugin_ppp finished. * * Revision 1.1 2004/01/27 08:13:39 reinelt * ported PPP token to plugin_ppp * */ /* * exported functions: * * int plugin_init_ppp (void) * adds ppp() function * */ #include "config.h" #include #include #include #include #include #ifdef HAVE_NET_IF_PPP_H #include #else #warning if_ppp.h not found. PPP support deactivated. #endif #include "debug.h" #include "plugin.h" #include "qprintf.h" #include "hash.h" #ifdef HAVE_NET_IF_PPP_H static HASH PPP; static int get_ppp_stats(void) { int age; int unit; unsigned ibytes, obytes; static int fd = -2; struct ifpppstatsreq req; char key[16], val[16]; /* reread every 10 msec only */ age = hash_age(&PPP, NULL); if (age > 0 && age <= 10) return 0; /* open socket only once */ if (fd == -2) { fd = socket(AF_INET, SOCK_DGRAM, 0); if (fd == -1) { error("socket() failed: %s", strerror(errno)); return -1; } } for (unit = 0; unit < 8; unit++) { memset(&req, 0, sizeof(req)); req.stats_ptr = (caddr_t) & req.stats; qprintf(req.ifr__name, sizeof(req.ifr__name), "ppp%d", unit); if (ioctl(fd, SIOCGPPPSTATS, &req) == 0) { ibytes = req.stats.p.ppp_ibytes; obytes = req.stats.p.ppp_obytes; } else { ibytes = obytes = 0; } qprintf(key, sizeof(key), "Rx:%d", unit); qprintf(val, sizeof(val), "%d", ibytes); hash_put_delta(&PPP, key, val); qprintf(key, sizeof(key), "Tx:%d", unit); qprintf(val, sizeof(val), "%d", obytes); hash_put_delta(&PPP, key, val); } return 0; } static void my_ppp(RESULT * result, RESULT * arg1, RESULT * arg2) { double value; if (get_ppp_stats() < 0) { SetResult(&result, R_STRING, ""); return; } value = hash_get_delta(&PPP, R2S(arg1), NULL, R2N(arg2)); SetResult(&result, R_NUMBER, &value); } #endif int plugin_init_ppp(void) { hash_create(&PPP); #ifdef HAVE_NET_IF_PPP_H AddFunction("ppp", 2, my_ppp); #endif return 0; } void plugin_exit_ppp(void) { hash_destroy(&PPP); } 2-08[lcd4linux @ 2002-12-08 07:36:06 by reinelt]reinelt11-315/+314 autoconf/automake cleanup git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@175 3ae390bd-cb1e-0410-b409-cd5a39f66f1f 2002-12-06[lcd4linux @ 2002-12-06 07:38:43 by reinelt]reinelt6-1305/+2559 libgd/libpng bugfix: removed '-lpng -lz' from LDFLAGS git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@174 3ae390bd-cb1e-0410-b409-cd5a39f66f1f 2002-12-05[lcd4linux @ 2002-12-05 19:23:01 by reinelt]reinelt3-7/+16 fixed undefined operations found by gcc3 git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@173 3ae390bd-cb1e-0410-b409-cd5a39f66f1f 2002-12-05[lcd4linux @ 2002-12-05 19:12:47 by reinelt]reinelt1-3/+15 sensors factor and offset patch from Petri Damsten <petri.damsten@raketti.net> git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@172 3ae390bd-cb1e-0410-b409-cd5a39f66f1f 2002-12-05[lcd4linux @ 2002-12-05 19:09:57 by reinelt]reinelt6-17/+29 patches for gcc-3.2 git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@171 3ae390bd-cb1e-0410-b409-cd5a39f66f1f 2002-09-12[lcd4linux @ 2002-09-12 05:24:54 by reinelt]reinelt1-478/+199 code cleanup, character defining for bars git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@170 3ae390bd-cb1e-0410-b409-cd5a39f66f1f 2002-09-11[lcd4linux @ 2002-09-11 05:32:35 by reinelt]reinelt1-255/+47 changed to use new bar functions git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@169 3ae390bd-cb1e-0410-b409-cd5a39f66f1f 2002-09-11[lcd4linux @ 2002-09-11 05:16:32 by reinelt]reinelt8-476/+1335 added Cwlinux driver git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@168 3ae390bd-cb1e-0410-b409-cd5a39f66f1f 2002-08-30[lcd4linux @ 2002-08-30 03:54:01 by reinelt]reinelt1-3/+8 bug in curses driver fixed git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@167 3ae390bd-cb1e-0410-b409-cd5a39f66f1f 2002-08-22[lcd4linux @ 2002-08-22 05:51:36 by reinelt]reinelt1-7/+4 cosmetic changes git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@166 3ae390bd-cb1e-0410-b409-cd5a39f66f1f 2002-08-21[lcd4linux @ 2002-08-21 06:09:53 by reinelt]reinelt2-10/+48 some T6963 fixes, ndelay wrap git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@165 3ae390bd-cb1e-0410-b409-cd5a39f66f1f 2002-08-19[lcd4linux @ 2002-08-19 10:51:06 by reinelt]reinelt2-259/+60 M50530 driver using new generic bar functions git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@164 3ae390bd-cb1e-0410-b409-cd5a39f66f1f 2002-08-19[lcd4linux @ 2002-08-19 09:43:43 by reinelt]reinelt1-261/+57 BeckmannEgle using new generic bar functions git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@163 3ae390bd-cb1e-0410-b409-cd5a39f66f1f 2002-08-19[lcd4linux @ 2002-08-19 09:30:18 by reinelt]reinelt1-256/+106 MatrixOrbital uses generic bar funnctions git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@162 3ae390bd-cb1e-0410-b409-cd5a39f66f1f 2002-08-19[lcd4linux @ 2002-08-19 09:11:34 by reinelt]reinelt2-257/+51 changed HD44780 to use generic bar functions git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@161 3ae390bd-cb1e-0410-b409-cd5a39f66f1f 2002-08-19[lcd4linux @ 2002-08-19 07:52:19 by reinelt]reinelt3-8/+17 corrected type declaration of (*defchar)() git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@160 3ae390bd-cb1e-0410-b409-cd5a39f66f1f 2002-08-19[lcd4linux @ 2002-08-19 07:36:29 by reinelt]reinelt7-359/+481 finished bar.c, USBLCD is the first driver that uses the generic bar functions git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@159 3ae390bd-cb1e-0410-b409-cd5a39f66f1f 2002-08-19[lcd4linux @ 2002-08-19 04:41:20 by reinelt]reinelt20-32/+166 introduced bar.c, moved bar stuff from display.h to bar.h git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@158 3ae390bd-cb1e-0410-b409-cd5a39f66f1f 2002-08-18[lcd4linux @ 2002-08-18 08:11:11 by reinelt]reinelt1-26/+28 USBLCD buffered I/O git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@157 3ae390bd-cb1e-0410-b409-cd5a39f66f1f 2002-08-17[lcd4linux @ 2002-08-17 14:14:21 by reinelt]reinelt3-67/+101 USBLCD fixes git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@156 3ae390bd-cb1e-0410-b409-cd5a39f66f1f 2002-08-17[lcd4linux @ 2002-08-17 13:10:22 by reinelt]reinelt9-182/+765 USBLCD driver added git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@155 3ae390bd-cb1e-0410-b409-cd5a39f66f1f 2002-08-17[lcd4linux @ 2002-08-17 12:54:08 by reinelt]reinelt1-7/+23 minor T6963 changes git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@154 3ae390bd-cb1e-0410-b409-cd5a39f66f1f 2002-04-30[lcd4linux @ 2002-04-30 07:20:15 by reinelt]reinelt2-173/+129 implemented the new ndelay(nanoseconds) in all parallel port drivers git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@153 3ae390bd-cb1e-0410-b409-cd5a39f66f1f 2002-04-29[lcd4linux @ 2002-04-29 11:00:25 by reinelt]reinelt14-2339/+5100 added Toshiba T6963 driver added ndelay() with nanosecond resolution git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@152 3ae390bd-cb1e-0410-b409-cd5a39f66f1f 2001-09-14[lcd4linux @ 2001-09-14 05:57:06 by reinelt]reinelt1-1/+5 git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@151 3ae390bd-cb1e-0410-b409-cd5a39f66f1f 2001-09-13[lcd4linux @ 2001-09-13 07:40:57 by reinelt]reinelt1-0/+6 TODO update git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@150 3ae390bd-cb1e-0410-b409-cd5a39f66f1f 2001-09-12[lcd4linux @ 2001-09-12 06:17:22 by reinelt]reinelt2-1/+8 git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@149 3ae390bd-cb1e-0410-b409-cd5a39f66f1f 2001-09-12[lcd4linux @ 2001-09-12 05:58:16 by reinelt]reinelt3-9/+27 fixed bug in mail2.c git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@148 3ae390bd-cb1e-0410-b409-cd5a39f66f1f 2001-09-12[lcd4linux @ 2001-09-12 05:37:22 by reinelt]reinelt4-23/+99 fixed a bug in seti.c (file was never closed, lcd4linux run out of fd's improved socket debugging git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@147 3ae390bd-cb1e-0410-b409-cd5a39f66f1f 2001-09-11[lcd4linux @ 2001-09-11 06:43:43 by reinelt]reinelt1-1/+10 TODO items git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@146 3ae390bd-cb1e-0410-b409-cd5a39f66f1f