X-Git-Url: https://git.ozlabs.org/?a=blobdiff_plain;f=pppdump%2Fpppdump.c;h=130300a17d348046dbc4a81100f8fbfcf3d9f0a5;hb=HEAD;hp=a65a152a917bef424fc74b89591b1763923da995;hpb=d1506f182ba87dd019a9d5594f6acea17a77577f;p=ppp.git diff --git a/pppdump/pppdump.c b/pppdump/pppdump.c index a65a152..c24208a 100644 --- a/pppdump/pppdump.c +++ b/pppdump/pppdump.c @@ -2,7 +2,7 @@ * pppdump - print out the contents of a record file generated by * pppd in readable form. * - * Copyright (c) 1999 Paul Mackerras. All rights reserved. + * Copyright (c) 1999-2024 Paul Mackerras. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -16,15 +16,6 @@ * the documentation and/or other materials provided with the * distribution. * - * 3. The name(s) of the authors of this software must not be used to - * endorse or promote products derived from this software without - * prior written permission. - * - * 4. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by Paul Mackerras - * ". - * * THE AUTHORS OF THIS SOFTWARE DISCLAIM ALL WARRANTIES WITH REGARD TO * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY * AND FITNESS, IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY @@ -35,15 +26,13 @@ */ #include #include +#include #include #include -#include "ppp_defs.h" -#include "ppp-comp.h" int hexmode; int pppmode; int reverse; -int decompress; int mru = 1500; int abs_times; time_t start_time; @@ -53,6 +42,11 @@ int tot_sent, tot_rcvd; extern int optind; extern char *optarg; +void dumplog(); +void dumpppp(); +void show_time(); + +int main(ac, av) int ac; char **av; @@ -72,9 +66,6 @@ main(ac, av) case 'r': reverse = 1; break; - case 'd': - decompress = 1; - break; case 'm': mru = atoi(optarg); break; @@ -105,6 +96,7 @@ main(ac, av) exit(0); } +void dumplog(f) FILE *f; { @@ -183,7 +175,7 @@ dumplog(f) show_time(f, c); break; default: - printf("?%.2x\n"); + printf("?%.2x\n", c); } } } @@ -225,6 +217,10 @@ static u_short fcstab[256] = { 0xf78f, 0xe606, 0xd49d, 0xc514, 0xb1ab, 0xa022, 0x92b9, 0x8330, 0x7bc7, 0x6a4e, 0x58d5, 0x495c, 0x3de3, 0x2c6a, 0x1ef1, 0x0f78 }; +#define PPP_FCS(fcs, c) (((fcs) >> 8) ^ fcstab[((fcs) ^ (c)) & 0xff]) + +#define PPP_INITFCS 0xffff /* Initial FCS value */ +#define PPP_GOODFCS 0xf0b8 /* Good final FCS value */ struct pkt { int cnt; @@ -244,6 +240,7 @@ struct pkt { unsigned char dbuf[8192]; +void dumpppp(f) FILE *f; { @@ -287,6 +284,10 @@ dumpppp(f) printf("%s aborted packet:\n ", dir); q = " "; } + if (pkt->cnt >= sizeof(pkt->buf)) { + printf("%s over-long packet truncated:\n ", dir); + q = " "; + } nb = pkt->cnt; p = pkt->buf; pkt->cnt = 0; @@ -311,53 +312,8 @@ dumpppp(f) ++r; ++r; if (endp - r > mru) - printf(" ERROR: length (%d) > MRU (%d)\n", + printf(" ERROR: length (%zd) > MRU (%d)\n", endp - r, mru); - if (decompress && fcs == PPP_GOODFCS) { - /* See if this is a CCP or compressed packet */ - d = dbuf; - r = p; - if (r[0] == 0xff && r[1] == 3) { - *d++ = *r++; - *d++ = *r++; - } - proto = r[0]; - if ((proto & 1) == 0) - proto = (proto << 8) + r[1]; - if (proto == PPP_CCP) { - handle_ccp(pkt, r + 2, endp - r - 2); - } else if (proto == PPP_COMP) { - if ((pkt->flags & CCP_ISUP) - && (pkt->flags & CCP_DECOMP_RUN) - && pkt->state - && (pkt->flags & CCP_ERR) == 0) { - rv = pkt->comp->decompress(pkt->state, r, - endp - r, d, &dn); - switch (rv) { - case DECOMP_OK: - p = dbuf; - nb = d + dn - p; - if ((d[0] & 1) == 0) - --dn; - --dn; - if (dn > mru) - printf(" ERROR: decompressed length (%d) > MRU (%d)\n", dn, mru); - break; - case DECOMP_ERROR: - printf(" DECOMPRESSION ERROR\n"); - pkt->flags |= CCP_ERROR; - break; - case DECOMP_FATALERROR: - printf(" FATAL DECOMPRESSION ERROR\n"); - pkt->flags |= CCP_FATALERROR; - break; - } - } - } else if (pkt->state - && (pkt->flags & CCP_DECOMP_RUN)) { - pkt->comp->incomp(pkt->state, r, endp - r); - } - } do { nl = nb < 16? nb: 16; printf("%s ", q); @@ -390,7 +346,8 @@ dumpppp(f) c ^= 0x20; pkt->esc = 0; } - pkt->buf[pkt->cnt++] = c; + if (pkt->cnt < sizeof(pkt->buf)) + pkt->buf[pkt->cnt++] = c; break; } } @@ -412,79 +369,12 @@ dumpppp(f) show_time(f, c); break; default: - printf("?%.2x\n"); - } - } -} - -extern struct compressor ppp_bsd_compress, ppp_deflate; - -struct compressor *compressors[] = { -#if DO_BSD_COMPRESS - &ppp_bsd_compress, -#endif -#if DO_DEFLATE - &ppp_deflate, -#endif - NULL -}; - -handle_ccp(cp, dp, len) - struct pkt *cp; - u_char *dp; - int len; -{ - int clen; - struct compressor **comp; - - if (len < CCP_HDRLEN) - return; - clen = CCP_LENGTH(dp); - if (clen > len) - return; - - switch (CCP_CODE(dp)) { - case CCP_CONFACK: - cp->flags &= ~(CCP_DECOMP_RUN | CCP_ISUP); - if (clen < CCP_HDRLEN + CCP_OPT_MINLEN - || clen < CCP_HDRLEN + CCP_OPT_LENGTH(dp + CCP_HDRLEN)) - break; - dp += CCP_HDRLEN; - clen -= CCP_HDRLEN; - for (comp = compressors; *comp != NULL; ++comp) { - if ((*comp)->compress_proto == dp[0]) { - if (cp->state != NULL) { - (*cp->comp->decomp_free)(cp->state); - cp->state = NULL; - } - cp->comp = *comp; - cp->state = (*comp)->decomp_alloc(dp, CCP_OPT_LENGTH(dp)); - cp->flags |= CCP_ISUP; - if (cp->state != NULL - && (*cp->comp->decomp_init) - (cp->state, dp, clen, 0, 0, 8192, 1)) - cp->flags = (cp->flags & ~CCP_ERR) | CCP_DECOMP_RUN; - break; - } - } - break; - - case CCP_CONFNAK: - case CCP_CONFREJ: - cp->flags &= ~(CCP_DECOMP_RUN | CCP_ISUP); - break; - - case CCP_RESETACK: - if (cp->flags & CCP_ISUP) { - if (cp->state && (cp->flags & CCP_DECOMP_RUN)) { - (*cp->comp->decomp_reset)(cp->state); - cp->flags &= ~CCP_ERROR; - } + printf("?%.2x\n", c); } - break; } } +void show_time(f, c) FILE *f; int c;