]> git.ozlabs.org Git - ppp.git/blobdiff - pppstats/pppstats.c
fixed module description string
[ppp.git] / pppstats / pppstats.c
index 8dcdb03fbaf2601f65f64cbd087098ea028bd96c..9863f32ced1fa4755f99f01564f1b041eb2a0656 100644 (file)
@@ -6,6 +6,7 @@
  *   -v Verbose mode for default display
  *   -r Show compression ratio in default display
  *   -c Show Compression statistics instead of default display
+ *   -a Do not show relative values. Show absolute values at all times.
  *
  *
  * History:
@@ -36,7 +37,7 @@
  */
 
 #ifndef lint
-static char rcsid[] = "$Id: pppstats.c,v 1.9 1995/06/01 02:23:39 paulus Exp $";
+static char rcsid[] = "$Id: pppstats.c,v 1.12 1995/12/11 05:18:59 paulus Exp $";
 #endif
 
 #include <ctype.h>
@@ -69,7 +70,7 @@ static char rcsid[] = "$Id: pppstats.c,v 1.9 1995/06/01 02:23:39 paulus Exp $";
 #endif
 #endif
 
-int    vflag, rflag, cflag;
+int    vflag, rflag, cflag, aflag;
 unsigned interval = 5;
 int    unit;
 int    s;                      /* socket file descriptor */
@@ -84,6 +85,11 @@ main(argc, argv)
 {
     --argc; ++argv;
     while (argc > 0) {
+       if (strcmp(argv[0], "-a") == 0) {
+           ++aflag;
+           ++argv, --argc;
+           continue;
+       }
        if (strcmp(argv[0], "-v") == 0) {
            ++vflag;
            ++argv, --argc;
@@ -268,8 +274,11 @@ intpr()
        sigprocmask(SIG_SETMASK, &oldmask, NULL);
        signalled = 0;
        (void)alarm(interval);
-       old = cur;
-       ocs = ccs;
+
+       if (aflag==0) {
+           old = cur;
+           ocs = ccs;
+       }
     }
 }
 
@@ -289,6 +298,14 @@ get_ppp_stats(curp)
 {
     struct ifpppstatsreq req;
 
+    memset (&req, 0, sizeof (req));
+
+#ifdef _linux_
+    req.stats_ptr = (caddr_t) &req.stats;
+#undef ifr_name
+#define ifr_name ifr__name
+#endif
+
     sprintf(req.ifr_name, "ppp%d", unit);
     if (ioctl(s, SIOCGPPPSTATS, &req) < 0) {
        if (errno == ENOTTY)
@@ -305,6 +322,14 @@ get_ppp_cstats(csp)
 {
     struct ifpppcstatsreq creq;
 
+    memset (&creq, 0, sizeof (creq));
+
+#ifdef _linux_
+    creq.stats_ptr = (caddr_t) &creq.stats;
+#undef  ifr_name
+#define ifr_name ifr__name
+#endif
+
     sprintf(creq.ifr_name, "ppp%d", unit);
     if (ioctl(s, SIOCGPPPCSTATS, &creq) < 0) {
        if (errno == ENOTTY) {
@@ -317,6 +342,21 @@ get_ppp_cstats(csp)
            exit(1);
        }
     }
+
+#ifdef _linux_
+    if (creq.stats.c.bytes_out == 0)
+       creq.stats.c.ratio = 0.0;
+    else
+       creq.stats.c.ratio = (double) creq.stats.c.in_count /
+                            (double) creq.stats.c.bytes_out;
+
+    if (creq.stats.d.bytes_out == 0)
+       creq.stats.d.ratio = 0.0;
+    else
+       creq.stats.d.ratio = (double) creq.stats.d.in_count /
+                            (double) creq.stats.d.bytes_out;
+#endif
+
     *csp = creq.stats;
 }