/*
* print PPP statistics:
* pppstats [-a|-d] [-v|-r|-z] [-c count] [-w wait] [interface]
*
* -a Show absolute values rather than deltas
* -d Show data rate (kB/s) rather than bytes
* -v Show more stats for VJ TCP header compression
* -r Show compression ratio
* -z Show compression statistics instead of default display
*
* History:
* perkins@cps.msu.edu: Added compression statistics and alternate
* display. 11/94
* Brad Parker (brad@cayman.com) 6/92
*
* from the original "slstats" by Van Jacobson
*
* Copyright (c) 2000-2001 by Sun Microsystems, Inc.
* All rights reserved.
*
* Copyright (c) 1989 Regents of the University of California.
* All rights reserved.
*
* Redistribution and use in source and binary forms are permitted
* provided that the above copyright notice and this paragraph are
* duplicated in all such forms and that any documentation,
* advertising materials, and other materials related to such
* distribution and use acknowledge that the software was developed
* by the University of California, Berkeley. The name of the
* University may not be used to endorse or promote products derived
* from this software without specific prior written permission.
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/
#ifndef __STDC__
#define const
#endif
#pragma ident "%Z%%M% %I% %E% SMI"
#ifndef lint
#endif
#include <stdio.h>
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <errno.h>
#include <signal.h>
#include <fcntl.h>
#include <unistd.h>
#ifndef STREAMS
#if defined(_linux_) && defined(__powerpc__) \
/* kludge alert! */
#endif
#ifndef _linux_
#include <net/ppp_defs.h>
#else
/* Linux */
#if __GLIBC__ >= 2
#else
#endif
#include <linux/ppp_defs.h>
#endif /* _linux_ */
#else /* STREAMS */
#include <net/ppp_defs.h>
#ifdef PPPIO_GETSTAT64
#endif
#endif /* STREAMS */
#ifndef ppp_stats64
#endif
static int infinite;
static int unit;
static char *progname;
static char *interface;
extern int optind;
extern char *optarg;
#endif
/*
* If PPP_DRV_NAME is not defined, use the legacy "ppp" as the
* device name.
*/
#if !defined(PPP_DRV_NAME)
#endif /* !defined(PPP_DRV_NAME) */
static void catchalarm __P((int));
static void
usage()
{
"Usage: %s [-a|-d] [-v|-r|-z] [-c count] [-w wait] [interface]\n",
progname);
exit(1);
}
/*
* Called if an interval expires before intpr has completed a loop.
* Sets a flag to not wait for the alarm.
*/
/* ARGSUSED */
static void
int arg;
{
signalled = 1;
}
#ifndef STREAMS
static void
struct ppp_stats64 *curp;
{
#ifdef _linux_
#endif
else
perror("couldn't get PPP statistics");
exit(1);
}
}
static void
struct ppp_comp_stats *csp;
{
#ifdef _linux_
#endif
if (zflag)
exit(1);
rflag = 0;
} else {
perror("couldn't get PPP compression stats");
exit(1);
}
}
#ifdef _linux_
}
else
}
else
#endif
}
#else /* STREAMS */
static int
char *ptr;
{
return -1;
"strioctl: expected %d bytes, got %d for cmd %x\n",
return 0;
}
static void
struct ppp_stats64 *curp;
{
#ifdef PPPIO_GETSTAT64
return;
return;
}
#else
return;
#endif
else
perror("couldn't get PPP statistics");
exit(1);
}
static void
struct ppp_comp_stats *csp;
{
if (zflag)
exit(1);
rflag = 0;
} else {
perror("couldn't get PPP compression statistics");
exit(1);
}
}
}
#endif /* STREAMS */
#define MAX0(a) ((int)(a) > 0? (a): 0)
/*
* Print a running summary of interface statistics.
* Repeat display every interval seconds, showing statistics
* collected over that interval. Assumes that interval is non-zero.
* First line printed is cumulative.
*/
static void
intpr()
{
register int line = 0;
char *bunit;
int ratef = 0;
for (;;) {
get_ppp_stats(&cur);
signalled = 0;
if ((line % 20) == 0) {
if (zflag) {
(void) printf("IN: COMPRESSED INCOMPRESSIBLE COMP | ");
(void) printf("OUT: COMPRESSED INCOMPRESSIBLE COMP\n");
bunit);
bunit);
} else {
(void) printf("%8.8s %6.6s %6.6s",
"IN", "PACK", "VJCOMP");
if (!rflag)
if (vflag)
if (rflag)
(void) printf(" | %8.8s %6.6s %6.6s",
"OUT", "PACK", "VJCOMP");
if (!rflag)
if (vflag)
if (rflag)
}
(void) putchar('\n');
}
if (zflag) {
if (ratef) {
(void) printf("%8.3f %6u %8.3f %6u %6.2f",
KBPS(W(d.comp_bytes)),
W(d.comp_packets),
W(d.inc_packets),
(void) printf(" | %8.3f %6u %8.3f %6u %6.2f",
KBPS(W(c.comp_bytes)),
W(c.comp_packets),
W(c.inc_packets),
} else {
(void) printf("%8u %6u %8u %6u %6.2f",
W(d.comp_bytes),
W(d.comp_packets),
W(d.inc_bytes),
W(d.inc_packets),
(void) printf(" | %8u %6u %8u %6u %6.2f",
W(c.comp_bytes),
W(c.comp_packets),
W(c.inc_bytes),
W(c.inc_packets),
}
} else {
if (ratef)
else
V(p.ppp_ipackets),
V(vj.vjs_compressedin));
if (!rflag)
(void) printf(" %6u %6u",
V(vj.vjs_uncompressedin),
V(vj.vjs_errorin));
if (vflag)
V(vj.vjs_tossed),
if (rflag) {
if (ratef)
else
}
if (ratef)
else
V(p.ppp_opackets),
V(vj.vjs_compressed));
if (!rflag)
if (vflag)
(void) printf(" %6u %6u",
V(vj.vjs_searches),
V(vj.vjs_misses));
if (rflag) {
if (ratef)
else
}
}
(void) putchar('\n');
line++;
count--;
break;
(void) sigemptyset(&mask);
if (!signalled) {
(void) sigemptyset(&mask);
(void) sigsuspend(&mask);
}
signalled = 0;
if (!aflag) {
}
}
}
int
int argc;
char *argv[];
{
int c;
#ifdef STREAMS
char *dev;
#endif
else
++progname;
switch (c) {
case 'a':
++aflag;
break;
case 'd':
++dflag;
break;
case 'v':
++vflag;
break;
case 'r':
++rflag;
break;
case 'z':
++zflag;
break;
case 'c':
if (count <= 0)
usage();
break;
case 'w':
if (interval <= 0)
usage();
break;
default:
usage();
}
}
interval = 5;
infinite = 1;
count = 1;
if (aflag)
dflag = 0;
if (argc > 1)
usage();
if (argc > 0)
}
#ifndef STREAMS
{
if (s < 0) {
perror("couldn't create IP socket");
exit(1);
}
#ifdef _linux_
#endif
exit(1);
}
}
#else /* STREAMS */
#ifdef __osf__
#else
#endif
exit(1);
}
exit(1);
}
#endif /* STREAMS */
intpr();
return (0);
}