1
/* $Id: plugin_ppp.c 840 2007-09-09 12:17:42Z michael $
2
* $URL: https://ssl.bulix.org/svn/lcd4linux/trunk/plugin_ppp.c $
4
* plugin for ppp throughput
6
* Copyright (C) 2003 Michael Reinelt <michael@reinelt.co.at>
7
* Copyright (C) 2004 The LCD4Linux Team <lcd4linux-devel@users.sourceforge.net>
9
* This file is part of LCD4Linux.
11
* LCD4Linux is free software; you can redistribute it and/or modify
12
* it under the terms of the GNU General Public License as published by
13
* the Free Software Foundation; either version 2, or (at your option)
16
* LCD4Linux is distributed in the hope that it will be useful,
17
* but WITHOUT ANY WARRANTY; without even the implied warranty of
18
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19
* GNU General Public License for more details.
21
* You should have received a copy of the GNU General Public License
22
* along with this program; if not, write to the Free Software
23
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
30
* int plugin_init_ppp (void)
41
#include <sys/ioctl.h>
43
#ifdef HAVE_NET_IF_PPP_H
44
#include <net/if_ppp.h>
46
#warning if_ppp.h not found. PPP support deactivated.
54
#ifdef HAVE_NET_IF_PPP_H
58
static int get_ppp_stats(void)
62
unsigned ibytes, obytes;
64
struct ifpppstatsreq req;
65
char key[16], val[16];
67
/* reread every 10 msec only */
68
age = hash_age(&PPP, NULL);
69
if (age > 0 && age <= 10)
72
/* open socket only once */
74
fd = socket(AF_INET, SOCK_DGRAM, 0);
76
error("socket() failed: %s", strerror(errno));
81
for (unit = 0; unit < 8; unit++) {
82
memset(&req, 0, sizeof(req));
83
req.stats_ptr = (caddr_t) & req.stats;
84
qprintf(req.ifr__name, sizeof(req.ifr__name), "ppp%d", unit);
86
if (ioctl(fd, SIOCGPPPSTATS, &req) == 0) {
87
ibytes = req.stats.p.ppp_ibytes;
88
obytes = req.stats.p.ppp_obytes;
92
qprintf(key, sizeof(key), "Rx:%d", unit);
93
qprintf(val, sizeof(val), "%d", ibytes);
94
hash_put_delta(&PPP, key, val);
95
qprintf(key, sizeof(key), "Tx:%d", unit);
96
qprintf(val, sizeof(val), "%d", obytes);
97
hash_put_delta(&PPP, key, val);
104
static void my_ppp(RESULT * result, RESULT * arg1, RESULT * arg2)
108
if (get_ppp_stats() < 0) {
109
SetResult(&result, R_STRING, "");
112
value = hash_get_delta(&PPP, R2S(arg1), NULL, R2N(arg2));
113
SetResult(&result, R_NUMBER, &value);
119
int plugin_init_ppp(void)
122
#ifdef HAVE_NET_IF_PPP_H
123
AddFunction("ppp", 2, my_ppp);
128
void plugin_exit_ppp(void)