From 13959d11ec74c762a55c7f2ca26ca0ab4245d58e Mon Sep 17 00:00:00 2001 From: reinelt <> Date: Sun, 21 May 2000 06:20:35 +0000 Subject: [lcd4linux @ 2000-05-21 06:20:35 by reinelt] added ppp throughput token is '%t[iomt]' at the moment, but this will change in the near future --- system.c | 50 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) (limited to 'system.c') diff --git a/system.c b/system.c index 5db5c1b..5d9f3d3 100644 --- a/system.c +++ b/system.c @@ -1,4 +1,4 @@ -/* $Id: system.c,v 1.11 2000/04/15 11:56:35 reinelt Exp $ +/* $Id: system.c,v 1.12 2000/05/21 06:20:35 reinelt Exp $ * * system status retreivement * @@ -20,6 +20,11 @@ * * * $Log: system.c,v $ + * Revision 1.12 2000/05/21 06:20:35 reinelt + * + * added ppp throughput + * token is '%t[iomt]' at the moment, but this will change in the near future + * * Revision 1.11 2000/04/15 11:56:35 reinelt * * more debug messages @@ -110,6 +115,10 @@ * sets number of packets received and transmitted * returns 0 if ok, -1 on error * + * int PPP (int unit, int *rx, int *tx); + * sets number of packets received and transmitted + * returns 0 if ok, -1 on error + * * int Sensor (int index, double *val, double *min, double *max) * sets the current value of the index'th sensor and * the minimum and maximum values from the config file @@ -129,6 +138,9 @@ #include #include #include +#include +#include +#include #include "debug.h" #include "cfg.h" @@ -548,6 +560,42 @@ int Net (int *rx, int *tx) return 0; } +int PPP (int unit, int *rx, int *tx) +{ + static int fd=-2; + struct ifpppstatsreq req; + char buffer[16]; + + *rx=0; + *tx=0; + + if (fd==-1) return -1; + + if (fd==-2) { + fd = socket(AF_INET, SOCK_DGRAM, 0); + if (fd==-1) { + perror ("socket() failed"); + return -1; + } + debug ("socket()=%d\n", fd); + } + + memset (&req, 0, sizeof (req)); + req.stats_ptr = (caddr_t) &req.stats; + snprintf (req.ifr__name, sizeof(req.ifr__name), "ppp%d", unit); + + if (ioctl(fd, SIOCGPPPSTATS, &req) < 0) + return 0; + + snprintf (buffer, sizeof(buffer), "ppp%d_rx", unit); + *rx=smooth(buffer, 500, req.stats.p.ppp_ibytes); + + snprintf (buffer, sizeof(buffer), "ppp%d_tx", unit); + *tx=smooth(buffer, 500, req.stats.p.ppp_obytes); + + return 0; +} + int Sensor (int index, double *val, double *min, double *max) { char buffer[32]; -- cgit v1.2.3