xref: /onnv-gate/usr/src/cmd/cmd-inet/usr.bin/pppdump/pppdump.c (revision 192:a40f1d8e19e3)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * pppdump - print out the contents of a record file generated by
30Sstevel@tonic-gate  * pppd in readable form.
40Sstevel@tonic-gate  *
50Sstevel@tonic-gate  * Copyright (C) 1999  Paul Mackerras.  All rights reserved.
60Sstevel@tonic-gate  *
70Sstevel@tonic-gate  *  This program is free software; you can redistribute it and/or
80Sstevel@tonic-gate  *  modify it under the terms of the GNU General Public License
90Sstevel@tonic-gate  *  as published by the Free Software Foundation; either version
100Sstevel@tonic-gate  *  2 of the License, or (at your option) any later version.
110Sstevel@tonic-gate  */
120Sstevel@tonic-gate 
130Sstevel@tonic-gate #include <stdio.h>
140Sstevel@tonic-gate #include <unistd.h>
15*192Scarlsonj #include <stdlib.h>
160Sstevel@tonic-gate #include <time.h>
170Sstevel@tonic-gate #include <sys/types.h>
180Sstevel@tonic-gate #ifdef PPP_DEFS_IN_NET
190Sstevel@tonic-gate #include <net/ppp_defs.h>
200Sstevel@tonic-gate #else
210Sstevel@tonic-gate #include "ppp_defs.h"
220Sstevel@tonic-gate #endif
230Sstevel@tonic-gate #include "ppp-comp.h"
240Sstevel@tonic-gate 
250Sstevel@tonic-gate int hexmode;
260Sstevel@tonic-gate int pppmode;
270Sstevel@tonic-gate int reverse;
280Sstevel@tonic-gate int decompress;
290Sstevel@tonic-gate int mru = 1500;
300Sstevel@tonic-gate int abs_times;
310Sstevel@tonic-gate time_t start_time;
320Sstevel@tonic-gate int start_time_tenths;
330Sstevel@tonic-gate int tot_sent, tot_rcvd;
340Sstevel@tonic-gate 
350Sstevel@tonic-gate extern int optind;
360Sstevel@tonic-gate extern char *optarg;
370Sstevel@tonic-gate 
38*192Scarlsonj void dumplog();
39*192Scarlsonj void dumpppp();
40*192Scarlsonj void show_time();
41*192Scarlsonj void handle_ccp();
42*192Scarlsonj 
43*192Scarlsonj int
main(ac,av)440Sstevel@tonic-gate main(ac, av)
450Sstevel@tonic-gate     int ac;
460Sstevel@tonic-gate     char **av;
470Sstevel@tonic-gate {
480Sstevel@tonic-gate     int i;
490Sstevel@tonic-gate     char *p;
500Sstevel@tonic-gate     FILE *f;
510Sstevel@tonic-gate 
520Sstevel@tonic-gate     while ((i = getopt(ac, av, "hprdm:a")) != -1) {
530Sstevel@tonic-gate 	switch (i) {
540Sstevel@tonic-gate 	case 'h':
550Sstevel@tonic-gate 	    hexmode = 1;
560Sstevel@tonic-gate 	    break;
570Sstevel@tonic-gate 	case 'p':
580Sstevel@tonic-gate 	    pppmode = 1;
590Sstevel@tonic-gate 	    break;
600Sstevel@tonic-gate 	case 'r':
610Sstevel@tonic-gate 	    reverse = 1;
620Sstevel@tonic-gate 	    break;
630Sstevel@tonic-gate 	case 'd':
640Sstevel@tonic-gate 	    decompress = 1;
650Sstevel@tonic-gate 	    break;
660Sstevel@tonic-gate 	case 'm':
670Sstevel@tonic-gate 	    mru = atoi(optarg);
680Sstevel@tonic-gate 	    break;
690Sstevel@tonic-gate 	case 'a':
700Sstevel@tonic-gate 	    abs_times = 1;
710Sstevel@tonic-gate 	    break;
720Sstevel@tonic-gate 	default:
730Sstevel@tonic-gate 	    fprintf(stderr, "Usage: %s [-h | -p[d]] [-r] [-m mru] [-a] [file ...]\n", av[0]);
740Sstevel@tonic-gate 	    exit(1);
750Sstevel@tonic-gate 	}
760Sstevel@tonic-gate     }
770Sstevel@tonic-gate     if (optind >= ac)
780Sstevel@tonic-gate 	dumplog(stdin);
790Sstevel@tonic-gate     else {
800Sstevel@tonic-gate 	for (i = optind; i < ac; ++i) {
810Sstevel@tonic-gate 	    p = av[i];
820Sstevel@tonic-gate 	    if ((f = fopen(p, "r")) == NULL) {
830Sstevel@tonic-gate 		perror(p);
840Sstevel@tonic-gate 		exit(1);
850Sstevel@tonic-gate 	    }
860Sstevel@tonic-gate 	    if (pppmode)
870Sstevel@tonic-gate 		dumpppp(f);
880Sstevel@tonic-gate 	    else
890Sstevel@tonic-gate 		dumplog(f);
900Sstevel@tonic-gate 	    fclose(f);
910Sstevel@tonic-gate 	}
920Sstevel@tonic-gate     }
930Sstevel@tonic-gate     exit(0);
940Sstevel@tonic-gate }
950Sstevel@tonic-gate 
96*192Scarlsonj void
dumplog(f)970Sstevel@tonic-gate dumplog(f)
980Sstevel@tonic-gate     FILE *f;
990Sstevel@tonic-gate {
1000Sstevel@tonic-gate     int c, n, k, col;
1010Sstevel@tonic-gate     int nb, c2;
1020Sstevel@tonic-gate     unsigned char buf[16];
1030Sstevel@tonic-gate 
1040Sstevel@tonic-gate     while ((c = getc(f)) != EOF) {
1050Sstevel@tonic-gate 	switch (c) {
1060Sstevel@tonic-gate 	case RECMARK_STARTSEND:
1070Sstevel@tonic-gate 	case RECMARK_STARTRECV:
1080Sstevel@tonic-gate 	    if (reverse)
1090Sstevel@tonic-gate 		c = c==RECMARK_STARTSEND ? RECMARK_STARTRECV :
1100Sstevel@tonic-gate 		    RECMARK_STARTSEND;
1110Sstevel@tonic-gate 	    printf("%s %c", c==RECMARK_STARTSEND? "sent": "rcvd",
1120Sstevel@tonic-gate 		hexmode? ' ': '"');
1130Sstevel@tonic-gate 	    col = 6;
1140Sstevel@tonic-gate 	    n = getc(f);
1150Sstevel@tonic-gate 	    n = (n << 8) + getc(f);
1160Sstevel@tonic-gate 	    *(c==1? &tot_sent: &tot_rcvd) += n;
1170Sstevel@tonic-gate 	    nb = 0;
1180Sstevel@tonic-gate 	    for (; n > 0; --n) {
1190Sstevel@tonic-gate 		c = getc(f);
1200Sstevel@tonic-gate 		if (c == EOF) {
1210Sstevel@tonic-gate 		    printf("\nEOF\n");
1220Sstevel@tonic-gate 		    exit(0);
1230Sstevel@tonic-gate 		}
1240Sstevel@tonic-gate 		if (hexmode) {
1250Sstevel@tonic-gate 		    if (nb >= 16) {
1260Sstevel@tonic-gate 			printf("  ");
1270Sstevel@tonic-gate 			for (k = 0; k < nb; ++k) {
1280Sstevel@tonic-gate 			    c2 = buf[k];
1290Sstevel@tonic-gate 			    putchar((' ' <= c2 && c2 <= '~')? c2: '.');
1300Sstevel@tonic-gate 			}
1310Sstevel@tonic-gate 			printf("\n      ");
1320Sstevel@tonic-gate 			nb = 0;
1330Sstevel@tonic-gate 		    }
1340Sstevel@tonic-gate 		    buf[nb++] = c;
1350Sstevel@tonic-gate 		    printf(" %.2x", c);
1360Sstevel@tonic-gate 		} else {
1370Sstevel@tonic-gate 		    k = (' ' <= c && c <= '~')? (c != '\\' && c != '"')? 1: 2: 3;
1380Sstevel@tonic-gate 		    if ((col += k) >= 78) {
1390Sstevel@tonic-gate 			printf("\n      ");
1400Sstevel@tonic-gate 			col = 6 + k;
1410Sstevel@tonic-gate 		    }
1420Sstevel@tonic-gate 		    switch (k) {
1430Sstevel@tonic-gate 		    case 1:
1440Sstevel@tonic-gate 			putchar(c);
1450Sstevel@tonic-gate 			break;
1460Sstevel@tonic-gate 		    case 2:
1470Sstevel@tonic-gate 			printf("\\%c", c);
1480Sstevel@tonic-gate 			break;
1490Sstevel@tonic-gate 		    case 3:
1500Sstevel@tonic-gate 			printf("\\%.2x", c);
1510Sstevel@tonic-gate 			break;
1520Sstevel@tonic-gate 		    }
1530Sstevel@tonic-gate 		}
1540Sstevel@tonic-gate 	    }
1550Sstevel@tonic-gate 	    if (hexmode) {
1560Sstevel@tonic-gate 		for (k = nb; k < 16; ++k)
1570Sstevel@tonic-gate 		    printf("   ");
1580Sstevel@tonic-gate 		printf("  ");
1590Sstevel@tonic-gate 		for (k = 0; k < nb; ++k) {
1600Sstevel@tonic-gate 		    c2 = buf[k];
1610Sstevel@tonic-gate 		    putchar((' ' <= c2 && c2 <= '~')? c2: '.');
1620Sstevel@tonic-gate 		}
1630Sstevel@tonic-gate 	    } else
1640Sstevel@tonic-gate 		putchar('"');
1650Sstevel@tonic-gate 	    printf("\n");
1660Sstevel@tonic-gate 	    break;
1670Sstevel@tonic-gate 	case RECMARK_ENDSEND:
1680Sstevel@tonic-gate 	case RECMARK_ENDRECV:
1690Sstevel@tonic-gate 	    if (reverse)
1700Sstevel@tonic-gate 		c = c==RECMARK_ENDSEND ? RECMARK_ENDRECV : RECMARK_ENDSEND;
1710Sstevel@tonic-gate 	    printf("end %s\n", c==RECMARK_ENDSEND? "send": "recv");
1720Sstevel@tonic-gate 	    break;
1730Sstevel@tonic-gate 	case RECMARK_TIMEDELTA32:
1740Sstevel@tonic-gate 	case RECMARK_TIMEDELTA8:
1750Sstevel@tonic-gate 	case RECMARK_TIMESTART:
1760Sstevel@tonic-gate 	    show_time(f, c);
1770Sstevel@tonic-gate 	    break;
1780Sstevel@tonic-gate 	default:
1790Sstevel@tonic-gate 	    printf("?%.2x\n");
1800Sstevel@tonic-gate 	}
1810Sstevel@tonic-gate     }
1820Sstevel@tonic-gate }
1830Sstevel@tonic-gate 
1840Sstevel@tonic-gate /*
1850Sstevel@tonic-gate  * FCS lookup table as calculated by genfcstab.
1860Sstevel@tonic-gate  */
1870Sstevel@tonic-gate static u_short fcstab[256] = {
1880Sstevel@tonic-gate 	0x0000,	0x1189,	0x2312,	0x329b,	0x4624,	0x57ad,	0x6536,	0x74bf,
1890Sstevel@tonic-gate 	0x8c48,	0x9dc1,	0xaf5a,	0xbed3,	0xca6c,	0xdbe5,	0xe97e,	0xf8f7,
1900Sstevel@tonic-gate 	0x1081,	0x0108,	0x3393,	0x221a,	0x56a5,	0x472c,	0x75b7,	0x643e,
1910Sstevel@tonic-gate 	0x9cc9,	0x8d40,	0xbfdb,	0xae52,	0xdaed,	0xcb64,	0xf9ff,	0xe876,
1920Sstevel@tonic-gate 	0x2102,	0x308b,	0x0210,	0x1399,	0x6726,	0x76af,	0x4434,	0x55bd,
1930Sstevel@tonic-gate 	0xad4a,	0xbcc3,	0x8e58,	0x9fd1,	0xeb6e,	0xfae7,	0xc87c,	0xd9f5,
1940Sstevel@tonic-gate 	0x3183,	0x200a,	0x1291,	0x0318,	0x77a7,	0x662e,	0x54b5,	0x453c,
1950Sstevel@tonic-gate 	0xbdcb,	0xac42,	0x9ed9,	0x8f50,	0xfbef,	0xea66,	0xd8fd,	0xc974,
1960Sstevel@tonic-gate 	0x4204,	0x538d,	0x6116,	0x709f,	0x0420,	0x15a9,	0x2732,	0x36bb,
1970Sstevel@tonic-gate 	0xce4c,	0xdfc5,	0xed5e,	0xfcd7,	0x8868,	0x99e1,	0xab7a,	0xbaf3,
1980Sstevel@tonic-gate 	0x5285,	0x430c,	0x7197,	0x601e,	0x14a1,	0x0528,	0x37b3,	0x263a,
1990Sstevel@tonic-gate 	0xdecd,	0xcf44,	0xfddf,	0xec56,	0x98e9,	0x8960,	0xbbfb,	0xaa72,
2000Sstevel@tonic-gate 	0x6306,	0x728f,	0x4014,	0x519d,	0x2522,	0x34ab,	0x0630,	0x17b9,
2010Sstevel@tonic-gate 	0xef4e,	0xfec7,	0xcc5c,	0xddd5,	0xa96a,	0xb8e3,	0x8a78,	0x9bf1,
2020Sstevel@tonic-gate 	0x7387,	0x620e,	0x5095,	0x411c,	0x35a3,	0x242a,	0x16b1,	0x0738,
2030Sstevel@tonic-gate 	0xffcf,	0xee46,	0xdcdd,	0xcd54,	0xb9eb,	0xa862,	0x9af9,	0x8b70,
2040Sstevel@tonic-gate 	0x8408,	0x9581,	0xa71a,	0xb693,	0xc22c,	0xd3a5,	0xe13e,	0xf0b7,
2050Sstevel@tonic-gate 	0x0840,	0x19c9,	0x2b52,	0x3adb,	0x4e64,	0x5fed,	0x6d76,	0x7cff,
2060Sstevel@tonic-gate 	0x9489,	0x8500,	0xb79b,	0xa612,	0xd2ad,	0xc324,	0xf1bf,	0xe036,
2070Sstevel@tonic-gate 	0x18c1,	0x0948,	0x3bd3,	0x2a5a,	0x5ee5,	0x4f6c,	0x7df7,	0x6c7e,
2080Sstevel@tonic-gate 	0xa50a,	0xb483,	0x8618,	0x9791,	0xe32e,	0xf2a7,	0xc03c,	0xd1b5,
2090Sstevel@tonic-gate 	0x2942,	0x38cb,	0x0a50,	0x1bd9,	0x6f66,	0x7eef,	0x4c74,	0x5dfd,
2100Sstevel@tonic-gate 	0xb58b,	0xa402,	0x9699,	0x8710,	0xf3af,	0xe226,	0xd0bd,	0xc134,
2110Sstevel@tonic-gate 	0x39c3,	0x284a,	0x1ad1,	0x0b58,	0x7fe7,	0x6e6e,	0x5cf5,	0x4d7c,
2120Sstevel@tonic-gate 	0xc60c,	0xd785,	0xe51e,	0xf497,	0x8028,	0x91a1,	0xa33a,	0xb2b3,
2130Sstevel@tonic-gate 	0x4a44,	0x5bcd,	0x6956,	0x78df,	0x0c60,	0x1de9,	0x2f72,	0x3efb,
2140Sstevel@tonic-gate 	0xd68d,	0xc704,	0xf59f,	0xe416,	0x90a9,	0x8120,	0xb3bb,	0xa232,
2150Sstevel@tonic-gate 	0x5ac5,	0x4b4c,	0x79d7,	0x685e,	0x1ce1,	0x0d68,	0x3ff3,	0x2e7a,
2160Sstevel@tonic-gate 	0xe70e,	0xf687,	0xc41c,	0xd595,	0xa12a,	0xb0a3,	0x8238,	0x93b1,
2170Sstevel@tonic-gate 	0x6b46,	0x7acf,	0x4854,	0x59dd,	0x2d62,	0x3ceb,	0x0e70,	0x1ff9,
2180Sstevel@tonic-gate 	0xf78f,	0xe606,	0xd49d,	0xc514,	0xb1ab,	0xa022,	0x92b9,	0x8330,
2190Sstevel@tonic-gate 	0x7bc7,	0x6a4e,	0x58d5,	0x495c,	0x3de3,	0x2c6a,	0x1ef1,	0x0f78
2200Sstevel@tonic-gate };
2210Sstevel@tonic-gate 
2220Sstevel@tonic-gate struct pkt {
2230Sstevel@tonic-gate     int	cnt;
2240Sstevel@tonic-gate     int	esc;
2250Sstevel@tonic-gate     int	flags;
2260Sstevel@tonic-gate     struct compressor *comp;
2270Sstevel@tonic-gate     void *state;
2280Sstevel@tonic-gate     unsigned char buf[8192];
2290Sstevel@tonic-gate } spkt, rpkt;
2300Sstevel@tonic-gate 
2310Sstevel@tonic-gate /* Values for flags */
2320Sstevel@tonic-gate #define CCP_ISUP	1
2330Sstevel@tonic-gate #define CCP_ERROR	2
2340Sstevel@tonic-gate #define CCP_FATALERROR	4
2350Sstevel@tonic-gate #define CCP_ERR		(CCP_ERROR | CCP_FATALERROR)
2360Sstevel@tonic-gate #define CCP_DECOMP_RUN	8
2370Sstevel@tonic-gate 
2380Sstevel@tonic-gate unsigned char dbuf[8192];
2390Sstevel@tonic-gate 
240*192Scarlsonj void
dumpppp(f)2410Sstevel@tonic-gate dumpppp(f)
2420Sstevel@tonic-gate     FILE *f;
2430Sstevel@tonic-gate {
2440Sstevel@tonic-gate     int c, n, k;
2450Sstevel@tonic-gate     int nb, nl, dn, proto, rv;
2460Sstevel@tonic-gate     char *dir, *q;
2470Sstevel@tonic-gate     unsigned char *p, *r, *endp;
2480Sstevel@tonic-gate     unsigned char *d;
2490Sstevel@tonic-gate     unsigned short fcs;
2500Sstevel@tonic-gate     struct pkt *pkt;
2510Sstevel@tonic-gate 
2520Sstevel@tonic-gate     spkt.cnt = rpkt.cnt = 0;
2530Sstevel@tonic-gate     spkt.esc = rpkt.esc = 0;
2540Sstevel@tonic-gate     while ((c = getc(f)) != EOF) {
2550Sstevel@tonic-gate 	switch (c) {
2560Sstevel@tonic-gate 	case RECMARK_STARTSEND:
2570Sstevel@tonic-gate 	case RECMARK_STARTRECV:
2580Sstevel@tonic-gate 	    if (reverse)
2590Sstevel@tonic-gate 		c = c==RECMARK_STARTSEND ? RECMARK_STARTRECV :
2600Sstevel@tonic-gate 		    RECMARK_STARTSEND;
2610Sstevel@tonic-gate 	    dir = c==RECMARK_STARTSEND? "sent": "rcvd";
2620Sstevel@tonic-gate 	    pkt = c==RECMARK_STARTSEND? &spkt: &rpkt;
2630Sstevel@tonic-gate 	    n = getc(f);
2640Sstevel@tonic-gate 	    n = (n << 8) + getc(f);
2650Sstevel@tonic-gate 	    *(c==1? &tot_sent: &tot_rcvd) += n;
2660Sstevel@tonic-gate 	    for (; n > 0; --n) {
2670Sstevel@tonic-gate 		c = getc(f);
2680Sstevel@tonic-gate 		switch (c) {
2690Sstevel@tonic-gate 		case EOF:
2700Sstevel@tonic-gate 		    printf("\nEOF\n");
2710Sstevel@tonic-gate 		    if (spkt.cnt > 0)
2720Sstevel@tonic-gate 			printf("[%d bytes in incomplete send packet]\n",
2730Sstevel@tonic-gate 			       spkt.cnt);
2740Sstevel@tonic-gate 		    if (rpkt.cnt > 0)
2750Sstevel@tonic-gate 			printf("[%d bytes in incomplete recv packet]\n",
2760Sstevel@tonic-gate 			       rpkt.cnt);
2770Sstevel@tonic-gate 		    exit(0);
2780Sstevel@tonic-gate 		case '~':
2790Sstevel@tonic-gate 		    if (pkt->cnt > 0) {
2800Sstevel@tonic-gate 			q = dir;
2810Sstevel@tonic-gate 			if (pkt->esc) {
2820Sstevel@tonic-gate 			    printf("%s aborted packet:\n     ", dir);
2830Sstevel@tonic-gate 			    q = "    ";
2840Sstevel@tonic-gate 			}
2850Sstevel@tonic-gate 			nb = pkt->cnt;
2860Sstevel@tonic-gate 			p = pkt->buf;
2870Sstevel@tonic-gate 			pkt->cnt = 0;
2880Sstevel@tonic-gate 			pkt->esc = 0;
2890Sstevel@tonic-gate 			if (nb <= 2) {
2900Sstevel@tonic-gate 			    printf("%s short packet [%d bytes]:", q, nb);
2910Sstevel@tonic-gate 			    for (k = 0; k < nb; ++k)
2920Sstevel@tonic-gate 				printf(" %.2x", p[k]);
2930Sstevel@tonic-gate 			    printf("\n");
2940Sstevel@tonic-gate 			    break;
2950Sstevel@tonic-gate 			}
2960Sstevel@tonic-gate 			fcs = PPP_INITFCS;
2970Sstevel@tonic-gate 			for (k = 0; k < nb; ++k)
2980Sstevel@tonic-gate 			    fcs = PPP_FCS(fcs, p[k]);
2990Sstevel@tonic-gate 			fcs &= 0xFFFF;
3000Sstevel@tonic-gate 			nb -= 2;
3010Sstevel@tonic-gate 			endp = p + nb;
3020Sstevel@tonic-gate 			r = p;
3030Sstevel@tonic-gate 			if (r[0] == 0xff && r[1] == 3)
3040Sstevel@tonic-gate 			    r += 2;
3050Sstevel@tonic-gate 			if ((r[0] & 1) == 0)
3060Sstevel@tonic-gate 			    ++r;
3070Sstevel@tonic-gate 			++r;
3080Sstevel@tonic-gate 			if (endp - r > mru)
3090Sstevel@tonic-gate 			    printf("     ERROR: length (%d) > MRU (%d)\n",
3100Sstevel@tonic-gate 				   endp - r, mru);
3110Sstevel@tonic-gate 			if (decompress && fcs == PPP_GOODFCS) {
3120Sstevel@tonic-gate 			    /* See if this is a CCP or compressed packet */
3130Sstevel@tonic-gate 			    d = dbuf;
3140Sstevel@tonic-gate 			    r = p;
3150Sstevel@tonic-gate 			    if (r[0] == 0xff && r[1] == 3) {
3160Sstevel@tonic-gate 				*d++ = *r++;
3170Sstevel@tonic-gate 				*d++ = *r++;
3180Sstevel@tonic-gate 			    }
3190Sstevel@tonic-gate 			    proto = r[0];
3200Sstevel@tonic-gate 			    if ((proto & 1) == 0)
3210Sstevel@tonic-gate 				proto = (proto << 8) + r[1];
3220Sstevel@tonic-gate 			    if (proto == PPP_CCP) {
3230Sstevel@tonic-gate 				handle_ccp(pkt, r + 2, endp - r - 2);
3240Sstevel@tonic-gate 			    } else if (proto == PPP_COMP) {
3250Sstevel@tonic-gate 				if ((pkt->flags & CCP_ISUP)
3260Sstevel@tonic-gate 				    && (pkt->flags & CCP_DECOMP_RUN)
3270Sstevel@tonic-gate 				    && pkt->state
3280Sstevel@tonic-gate 				    && (pkt->flags & CCP_ERR) == 0) {
3290Sstevel@tonic-gate 				    rv = pkt->comp->decompress(pkt->state, r,
3300Sstevel@tonic-gate 							endp - r, d, &dn);
3310Sstevel@tonic-gate 				    switch (rv) {
3320Sstevel@tonic-gate 				    case DECOMP_OK:
3330Sstevel@tonic-gate 					p = dbuf;
3340Sstevel@tonic-gate 					nb = d + dn - p;
3350Sstevel@tonic-gate 					if ((d[0] & 1) == 0)
3360Sstevel@tonic-gate 					    --dn;
3370Sstevel@tonic-gate 					--dn;
3380Sstevel@tonic-gate 					if (dn > mru)
3390Sstevel@tonic-gate 					    printf("     ERROR: decompressed length (%d) > MRU (%d)\n", dn, mru);
3400Sstevel@tonic-gate 					break;
3410Sstevel@tonic-gate 				    case DECOMP_ERROR:
3420Sstevel@tonic-gate 					printf("     DECOMPRESSION ERROR\n");
3430Sstevel@tonic-gate 					pkt->flags |= CCP_ERROR;
3440Sstevel@tonic-gate 					break;
3450Sstevel@tonic-gate 				    case DECOMP_FATALERROR:
3460Sstevel@tonic-gate 					printf("     FATAL DECOMPRESSION ERROR\n");
3470Sstevel@tonic-gate 					pkt->flags |= CCP_FATALERROR;
3480Sstevel@tonic-gate 					break;
3490Sstevel@tonic-gate 				    }
3500Sstevel@tonic-gate 				}
3510Sstevel@tonic-gate 			    } else if (pkt->state
3520Sstevel@tonic-gate 				       && (pkt->flags & CCP_DECOMP_RUN)) {
3530Sstevel@tonic-gate 				pkt->comp->incomp(pkt->state, r, endp - r);
3540Sstevel@tonic-gate 			    }
3550Sstevel@tonic-gate 			}
3560Sstevel@tonic-gate 			do {
3570Sstevel@tonic-gate 			    nl = nb < 16? nb: 16;
3580Sstevel@tonic-gate 			    printf("%s ", q);
3590Sstevel@tonic-gate 			    for (k = 0; k < nl; ++k)
3600Sstevel@tonic-gate 				printf(" %.2x", p[k]);
3610Sstevel@tonic-gate 			    for (; k < 16; ++k)
3620Sstevel@tonic-gate 				printf("   ");
3630Sstevel@tonic-gate 			    printf("  ");
3640Sstevel@tonic-gate 			    for (k = 0; k < nl; ++k) {
3650Sstevel@tonic-gate 				c = p[k];
3660Sstevel@tonic-gate 				putchar((' ' <= c && c <= '~')? c: '.');
3670Sstevel@tonic-gate 			    }
3680Sstevel@tonic-gate 			    printf("\n");
3690Sstevel@tonic-gate 			    q = "    ";
3700Sstevel@tonic-gate 			    p += nl;
3710Sstevel@tonic-gate 			    nb -= nl;
3720Sstevel@tonic-gate 			} while (nb > 0);
3730Sstevel@tonic-gate 			if (fcs != PPP_GOODFCS)
3740Sstevel@tonic-gate 			    printf("     BAD FCS: (residue = %x)\n", fcs);
3750Sstevel@tonic-gate 		    }
3760Sstevel@tonic-gate 		    break;
3770Sstevel@tonic-gate 		case '}':
3780Sstevel@tonic-gate 		    if (!pkt->esc) {
3790Sstevel@tonic-gate 			pkt->esc = 1;
3800Sstevel@tonic-gate 			break;
3810Sstevel@tonic-gate 		    }
3820Sstevel@tonic-gate 		    /* else fall through */
3830Sstevel@tonic-gate 		default:
3840Sstevel@tonic-gate 		    if (pkt->esc) {
3850Sstevel@tonic-gate 			c ^= 0x20;
3860Sstevel@tonic-gate 			pkt->esc = 0;
3870Sstevel@tonic-gate 		    }
3880Sstevel@tonic-gate 		    pkt->buf[pkt->cnt++] = c;
3890Sstevel@tonic-gate 		    break;
3900Sstevel@tonic-gate 		}
3910Sstevel@tonic-gate 	    }
3920Sstevel@tonic-gate 	    break;
3930Sstevel@tonic-gate 	case RECMARK_ENDSEND:
3940Sstevel@tonic-gate 	case RECMARK_ENDRECV:
3950Sstevel@tonic-gate 	    if (reverse)
3960Sstevel@tonic-gate 		c = c==RECMARK_ENDSEND ? RECMARK_ENDRECV : RECMARK_ENDSEND;
3970Sstevel@tonic-gate 	    dir = c==RECMARK_ENDSEND ? "send": "recv";
3980Sstevel@tonic-gate 	    pkt = c==RECMARK_ENDSEND ? &spkt: &rpkt;
3990Sstevel@tonic-gate 	    printf("end %s", dir);
4000Sstevel@tonic-gate 	    if (pkt->cnt > 0)
4010Sstevel@tonic-gate 		printf("  [%d bytes in incomplete packet]", pkt->cnt);
4020Sstevel@tonic-gate 	    printf("\n");
4030Sstevel@tonic-gate 	    break;
4040Sstevel@tonic-gate 	case RECMARK_TIMEDELTA32:
4050Sstevel@tonic-gate 	case RECMARK_TIMEDELTA8:
4060Sstevel@tonic-gate 	case RECMARK_TIMESTART:
4070Sstevel@tonic-gate 	    show_time(f, c);
4080Sstevel@tonic-gate 	    break;
4090Sstevel@tonic-gate 	default:
4100Sstevel@tonic-gate 	    printf("?%.2x\n");
4110Sstevel@tonic-gate 	}
4120Sstevel@tonic-gate     }
4130Sstevel@tonic-gate }
4140Sstevel@tonic-gate 
4150Sstevel@tonic-gate extern struct compressor ppp_bsd_compress, ppp_deflate;
4160Sstevel@tonic-gate 
4170Sstevel@tonic-gate struct compressor *compressors[] = {
4180Sstevel@tonic-gate #if DO_BSD_COMPRESS
4190Sstevel@tonic-gate     &ppp_bsd_compress,
4200Sstevel@tonic-gate #endif
4210Sstevel@tonic-gate #if DO_DEFLATE
4220Sstevel@tonic-gate     &ppp_deflate,
4230Sstevel@tonic-gate #endif
4240Sstevel@tonic-gate     NULL
4250Sstevel@tonic-gate };
4260Sstevel@tonic-gate 
427*192Scarlsonj void
handle_ccp(cp,dp,len)4280Sstevel@tonic-gate handle_ccp(cp, dp, len)
4290Sstevel@tonic-gate     struct pkt *cp;
4300Sstevel@tonic-gate     u_char *dp;
4310Sstevel@tonic-gate     int len;
4320Sstevel@tonic-gate {
4330Sstevel@tonic-gate     int clen;
4340Sstevel@tonic-gate     struct compressor **comp;
4350Sstevel@tonic-gate 
4360Sstevel@tonic-gate     if (len < CCP_HDRLEN)
4370Sstevel@tonic-gate 	return;
4380Sstevel@tonic-gate     clen = CCP_LENGTH(dp);
4390Sstevel@tonic-gate     if (clen > len)
4400Sstevel@tonic-gate 	return;
4410Sstevel@tonic-gate 
4420Sstevel@tonic-gate     switch (CCP_CODE(dp)) {
4430Sstevel@tonic-gate     case CCP_CONFACK:
4440Sstevel@tonic-gate 	cp->flags &= ~(CCP_DECOMP_RUN | CCP_ISUP);
4450Sstevel@tonic-gate 	if (clen < CCP_HDRLEN + CCP_OPT_MINLEN
4460Sstevel@tonic-gate 	    || clen < CCP_HDRLEN + CCP_OPT_LENGTH(dp + CCP_HDRLEN))
4470Sstevel@tonic-gate 	    break;
4480Sstevel@tonic-gate 	dp += CCP_HDRLEN;
4490Sstevel@tonic-gate 	clen -= CCP_HDRLEN;
4500Sstevel@tonic-gate 	for (comp = compressors; *comp != NULL; ++comp) {
4510Sstevel@tonic-gate 	    if ((*comp)->compress_proto == dp[0]) {
4520Sstevel@tonic-gate 		if (cp->state != NULL) {
4530Sstevel@tonic-gate 		    (*cp->comp->decomp_free)(cp->state);
4540Sstevel@tonic-gate 		    cp->state = NULL;
4550Sstevel@tonic-gate 		}
4560Sstevel@tonic-gate 		cp->comp = *comp;
4570Sstevel@tonic-gate 		cp->state = (*comp)->decomp_alloc(dp, CCP_OPT_LENGTH(dp));
4580Sstevel@tonic-gate 		cp->flags |= CCP_ISUP;
4590Sstevel@tonic-gate 		if (cp->state != NULL
4600Sstevel@tonic-gate 		    && (*cp->comp->decomp_init)
4610Sstevel@tonic-gate 		        (cp->state, dp, clen, 0, 0, 8192, 1))
4620Sstevel@tonic-gate 		    cp->flags = (cp->flags & ~CCP_ERR) | CCP_DECOMP_RUN;
4630Sstevel@tonic-gate 		break;
4640Sstevel@tonic-gate 	    }
4650Sstevel@tonic-gate 	}
4660Sstevel@tonic-gate 	break;
4670Sstevel@tonic-gate 
4680Sstevel@tonic-gate     case CCP_CONFNAK:
4690Sstevel@tonic-gate     case CCP_CONFREJ:
4700Sstevel@tonic-gate 	cp->flags &= ~(CCP_DECOMP_RUN | CCP_ISUP);
4710Sstevel@tonic-gate 	break;
4720Sstevel@tonic-gate 
4730Sstevel@tonic-gate     case CCP_RESETACK:
4740Sstevel@tonic-gate 	if (cp->flags & CCP_ISUP) {
4750Sstevel@tonic-gate 	    if (cp->state && (cp->flags & CCP_DECOMP_RUN)) {
4760Sstevel@tonic-gate 		(*cp->comp->decomp_reset)(cp->state);
4770Sstevel@tonic-gate 		cp->flags &= ~CCP_ERROR;
4780Sstevel@tonic-gate 	    }
4790Sstevel@tonic-gate 	}
4800Sstevel@tonic-gate 	break;
4810Sstevel@tonic-gate     }
4820Sstevel@tonic-gate }
4830Sstevel@tonic-gate 
484*192Scarlsonj void
show_time(f,c)4850Sstevel@tonic-gate show_time(f, c)
4860Sstevel@tonic-gate     FILE *f;
4870Sstevel@tonic-gate     int c;
4880Sstevel@tonic-gate {
4890Sstevel@tonic-gate     time_t t;
4900Sstevel@tonic-gate     int n;
4910Sstevel@tonic-gate     struct tm *tm;
4920Sstevel@tonic-gate 
4930Sstevel@tonic-gate     if (c == RECMARK_TIMESTART) {
4940Sstevel@tonic-gate 	t = getc(f);
4950Sstevel@tonic-gate 	t = (t << 8) + getc(f);
4960Sstevel@tonic-gate 	t = (t << 8) + getc(f);
4970Sstevel@tonic-gate 	t = (t << 8) + getc(f);
4980Sstevel@tonic-gate 	printf("start %s", ctime(&t));
4990Sstevel@tonic-gate 	start_time = t;
5000Sstevel@tonic-gate 	start_time_tenths = 0;
5010Sstevel@tonic-gate 	tot_sent = tot_rcvd = 0;
5020Sstevel@tonic-gate     } else {
5030Sstevel@tonic-gate 	n = getc(f);
5040Sstevel@tonic-gate 	if (c == RECMARK_TIMEDELTA32) {
5050Sstevel@tonic-gate 	    for (c = 3; c > 0; --c)
5060Sstevel@tonic-gate 		n = (n << 8) + getc(f);
5070Sstevel@tonic-gate 	}
5080Sstevel@tonic-gate 	if (abs_times) {
5090Sstevel@tonic-gate 	    n += start_time_tenths;
5100Sstevel@tonic-gate 	    start_time += n / 10;
5110Sstevel@tonic-gate 	    start_time_tenths = n % 10;
5120Sstevel@tonic-gate 	    tm = localtime(&start_time);
5130Sstevel@tonic-gate 	    printf("time  %.2d:%.2d:%.2d.%d", tm->tm_hour, tm->tm_min,
5140Sstevel@tonic-gate 		   tm->tm_sec, start_time_tenths);
5150Sstevel@tonic-gate 	    printf("  (sent %d, rcvd %d)\n", tot_sent, tot_rcvd);
5160Sstevel@tonic-gate 	} else
5170Sstevel@tonic-gate 	    printf("time  %.1fs\n", (double) n / 10);
5180Sstevel@tonic-gate     }
5190Sstevel@tonic-gate }
520