X-Git-Url: https://git.ozlabs.org/?a=blobdiff_plain;f=pppdump%2Fpppdump.c;h=3d3ad1971e1d57404df3c2114e91124cfc9fd6ab;hb=b87d00d8a7fb49857175ee79f0327f382386901b;hp=25efafb28514dfe0ff948ec46fff93e8a6a10cae;hpb=f905a2633b5676a35078bcdcb392e66c943ead66;p=ppp.git diff --git a/pppdump/pppdump.c b/pppdump/pppdump.c index 25efafb..3d3ad19 100644 --- a/pppdump/pppdump.c +++ b/pppdump/pppdump.c @@ -11,6 +11,7 @@ */ #include #include +#include #include #include "ppp_defs.h" #include "ppp-comp.h" @@ -20,8 +21,13 @@ int pppmode; int reverse; int decompress; int mru = 1500; +int abs_times; +time_t start_time; +int start_time_tenths; +int tot_sent, tot_rcvd; extern int optind; +extern char *optarg; main(ac, av) int ac; @@ -31,7 +37,7 @@ main(ac, av) char *p; FILE *f; - while ((i = getopt(ac, av, "hprdm:")) != -1) { + while ((i = getopt(ac, av, "hprdm:a")) != -1) { switch (i) { case 'h': hexmode = 1; @@ -48,8 +54,11 @@ main(ac, av) case 'm': mru = atoi(optarg); break; + case 'a': + abs_times = 1; + break; default: - fprintf(stderr, "Usage: %s [-h | -p[d]] [-r] [-m mru] [file ...]\n", av[0]); + fprintf(stderr, "Usage: %s [-h | -p[d]] [-r] [-m mru] [-a] [file ...]\n", av[0]); exit(1); } } @@ -62,14 +71,16 @@ main(ac, av) perror(p); exit(1); } - dumplog(f); + if (pppmode) + dumpppp(f); + else + dumplog(f); fclose(f); } } exit(0); } - dumplog(f) FILE *f; { @@ -77,18 +88,17 @@ dumplog(f) int nb, c2; unsigned char buf[16]; - if (pppmode) { - dumpppp(f); - return; - } while ((c = getc(f)) != EOF) { - if (c == 1 || c == 2) { + switch (c) { + case 1: + case 2: if (reverse) c = 3 - c; printf("%s %c", c==1? "sent": "rcvd", hexmode? ' ': '"'); col = 6; n = getc(f); n = (n << 8) + getc(f); + *(c==1? &tot_sent: &tot_rcvd) += n; nb = 0; for (; n > 0; --n) { c = getc(f); @@ -138,20 +148,20 @@ dumplog(f) } else putchar('"'); printf("\n"); - } else if (c == 3 || c == 4) { + break; + case 3: + case 4: printf("end %s\n", c==3? "send": "recv"); - } else if (c == 5 || c == 6) { - n = getc(f); - if (c == 5) { - for (c = 3; c > 0; --c) - n = (n << 8) + getc(f); - } - printf("time %.1fs\n", (double) n / 10); - } else { + break; + case 5: + case 6: + case 7: + show_time(f, c); + break; + default: printf("?%.2x\n"); } } - exit(0); } /* @@ -224,13 +234,16 @@ dumpppp(f) spkt.cnt = rpkt.cnt = 0; spkt.esc = rpkt.esc = 0; while ((c = getc(f)) != EOF) { - if (c == 1 || c == 2) { + switch (c) { + case 1: + case 2: if (reverse) c = 3 - c; dir = c==1? "sent": "rcvd"; pkt = c==1? &spkt: &rpkt; n = getc(f); n = (n << 8) + getc(f); + *(c==1? &tot_sent: &tot_rcvd) += n; for (; n > 0; --n) { c = getc(f); switch (c) { @@ -357,7 +370,9 @@ dumpppp(f) break; } } - } else if (c == 3 || c == 4) { + break; + case 3: + case 4: if (reverse) c = 7 - c; dir = c==3? "send": "recv"; @@ -366,14 +381,13 @@ dumpppp(f) if (pkt->cnt > 0) printf(" [%d bytes in incomplete packet]", pkt->cnt); printf("\n"); - } else if (c == 5 || c == 6) { - n = getc(f); - if (c == 5) { - for (c = 3; c > 0; --c) - n = (n << 8) + getc(f); - } - printf("time %.1fs\n", (double) n / 10); - } else { + break; + case 5: + case 6: + case 7: + show_time(f, c); + break; + default: printf("?%.2x\n"); } } @@ -446,3 +460,39 @@ handle_ccp(cp, dp, len) break; } } + +show_time(f, c) + FILE *f; + int c; +{ + time_t t; + int n; + struct tm *tm; + + if (c == 7) { + t = getc(f); + t = (t << 8) + getc(f); + t = (t << 8) + getc(f); + t = (t << 8) + getc(f); + printf("start %s", ctime(&t)); + start_time = t; + start_time_tenths = 0; + tot_sent = tot_rcvd = 0; + } else { + n = getc(f); + if (c == 5) { + for (c = 3; c > 0; --c) + n = (n << 8) + getc(f); + } + if (abs_times) { + n += start_time_tenths; + start_time += n / 10; + start_time_tenths = n % 10; + tm = localtime(&start_time); + printf("time %.2d:%.2d:%.2d.%d", tm->tm_hour, tm->tm_min, + tm->tm_sec, start_time_tenths); + printf(" (sent %d, rcvd %d)\n", tot_sent, tot_rcvd); + } else + printf("time %.1fs\n", (double) n / 10); + } +}