-#define V(offset) (line % 20? cur.offset - old.offset: cur.offset)
-#define W(offset) (line % 20? ccs.offset - ocs.offset: ccs.offset)
-
-#define CRATE(comp, inc, unc) ((unc) == 0? 0.0: \
- 1.0 - (double)((comp) + (inc)) / (unc))
-
-/*
- * 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 at top of screen is always cumulative.
- */
-intpr()
-{
- register int line = 0;
- sigset_t oldmask, mask;
- struct ppp_stats cur, old;
- struct ppp_comp_stats ccs, ocs;
-
- memset(&old, 0, sizeof(old));
- memset(&ocs, 0, sizeof(ocs));
-
- while (1) {
- get_ppp_stats(&cur);
- if (cflag || rflag)
- get_ppp_cstats(&ccs);
-
- (void)signal(SIGALRM, catchalarm);
- signalled = 0;
- (void)alarm(interval);
-
- if ((line % 20) == 0) {
- if (line > 0)
- putchar('\n');
- if (cflag) {
-
- printf("%6.6s %6.6s %6.6s %6.6s %6.6s %6.6s %6.6s",
- "ubyte", "upack", "cbyte", "cpack", "ibyte", "ipack", "ratio");
- printf(" | %6.6s %6.6s %6.6s %6.6s %6.6s %6.6s %6.6s",
- "ubyte", "upack", "cbyte", "cpack", "ibyte", "ipack", "ratio");
- putchar('\n');
- } else {
-
- printf("%6.6s %6.6s %6.6s %6.6s %6.6s",
- "in", "pack", "comp", "uncomp", "err");
- if (vflag)
- printf(" %6.6s %6.6s", "toss", "ip");
- if (rflag)
- printf(" %6.6s %6.6s", "ratio", "ubyte");
- printf(" | %6.6s %6.6s %6.6s %6.6s %6.6s",
- "out", "pack", "comp", "uncomp", "ip");
- if (vflag)
- printf(" %6.6s %6.6s", "search", "miss");
- if(rflag)
- printf(" %6.6s %6.6s", "ratio", "ubyte");
- putchar('\n');
- }
- memset(&old, 0, sizeof(old));
- memset(&ocs, 0, sizeof(ocs));
- }
-
- if (cflag) {
- printf("%6d %6d %6d %6d %6d %6d %6.2f",
- W(d.unc_bytes),
- W(d.unc_packets),
- W(d.comp_bytes),
- W(d.comp_packets),
- W(d.inc_bytes),
- W(d.inc_packets),
- W(d.ratio) == 0? 0.0: 1 - 1.0 / W(d.ratio) * 256.0);
-
- printf(" | %6d %6d %6d %6d %6d %6d %6.2f",
- W(c.unc_bytes),
- W(c.unc_packets),
- W(c.comp_bytes),
- W(c.comp_packets),
- W(c.inc_bytes),
- W(c.inc_packets),
- W(d.ratio) == 0? 0.0: 1 - 1.0 / W(d.ratio) * 256.0);
-
- putchar('\n');
- } else {
-
- printf("%6d %6d %6d %6d %6d",
- V(p.ppp_ibytes),
- V(p.ppp_ipackets), V(vj.vjs_compressedin),
- V(vj.vjs_uncompressedin), V(vj.vjs_errorin));
- if (vflag)
- printf(" %6d %6d", V(vj.vjs_tossed),
- V(p.ppp_ipackets) - V(vj.vjs_compressedin) -
- V(vj.vjs_uncompressedin) - V(vj.vjs_errorin));
- if (rflag)
- printf(" %6.2f %6d",
- CRATE(W(d.comp_bytes), W(d.unc_bytes), W(d.unc_bytes)),
- W(d.unc_bytes));
- printf(" | %6d %6d %6d %6d %6d", V(p.ppp_obytes),
- V(p.ppp_opackets), V(vj.vjs_compressed),
- V(vj.vjs_packets) - V(vj.vjs_compressed),
- V(p.ppp_opackets) - V(vj.vjs_packets));
- if (vflag)
- printf(" %6d %6d", V(vj.vjs_searches), V(vj.vjs_misses));
-
- if (rflag)
- printf(" %6.2f %6d",
- CRATE(W(d.comp_bytes), W(d.unc_bytes), W(d.unc_bytes)),
- W(c.unc_bytes));
-
- putchar('\n');
- }
-
- fflush(stdout);
- line++;
- if (interval == 0)
- exit(0);
-
- sigemptyset(&mask);
- sigaddset(&mask, SIGALRM);
- sigprocmask(SIG_BLOCK, &mask, &oldmask);
- if (! signalled) {
- sigemptyset(&mask);
- sigsuspend(&mask);
- }
- sigprocmask(SIG_SETMASK, &oldmask, NULL);
- signalled = 0;
- (void)alarm(interval);
-
- if (aflag==0) {
- old = cur;
- ocs = ccs;
- }
- }
-}
-