xref: /freebsd/contrib/tcpdump/print-vjc.c (revision 5b0fe47811aa43b75fc69dbf7338cace232a4d48)
1b0453382SBill Fenner /*
2b0453382SBill Fenner  * Copyright (c) 1990, 1991, 1993, 1994, 1995, 1996, 1997
3b0453382SBill Fenner  *	The Regents of the University of California.  All rights reserved.
4b0453382SBill Fenner  *
5b0453382SBill Fenner  * Redistribution and use in source and binary forms, with or without
6b0453382SBill Fenner  * modification, are permitted provided that: (1) source code distributions
7b0453382SBill Fenner  * retain the above copyright notice and this paragraph in its entirety, (2)
8b0453382SBill Fenner  * distributions including binary code include the above copyright notice and
9b0453382SBill Fenner  * this paragraph in its entirety in the documentation or other materials
10b0453382SBill Fenner  * provided with the distribution, and (3) all advertising materials mentioning
11b0453382SBill Fenner  * features or use of this software display the following acknowledgement:
12b0453382SBill Fenner  * ``This product includes software developed by the University of California,
13b0453382SBill Fenner  * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
14b0453382SBill Fenner  * the University nor the names of its contributors may be used to endorse
15b0453382SBill Fenner  * or promote products derived from this software without specific prior
16b0453382SBill Fenner  * written permission.
17b0453382SBill Fenner  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
18b0453382SBill Fenner  * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
19b0453382SBill Fenner  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
20b0453382SBill Fenner  */
21b0453382SBill Fenner 
22b0453382SBill Fenner #ifdef HAVE_CONFIG_H
23b0453382SBill Fenner #include "config.h"
24b0453382SBill Fenner #endif
25b0453382SBill Fenner 
26b0453382SBill Fenner #ifndef lint
275b0fe478SBruce M Simpson static const char rcsid[] _U_ =
285b0fe478SBruce M Simpson     "@(#) $Header: /tcpdump/master/tcpdump/print-vjc.c,v 1.11.2.3 2003/11/19 01:09:12 guy Exp $ (LBL)";
29b0453382SBill Fenner #endif
30b0453382SBill Fenner 
315b0fe478SBruce M Simpson #include <tcpdump-stdinc.h>
32b0453382SBill Fenner 
33b0453382SBill Fenner #include <pcap.h>
34b0453382SBill Fenner #include <stdio.h>
35b0453382SBill Fenner 
36b0453382SBill Fenner #include "interface.h"
37b0453382SBill Fenner #include "addrtoname.h"
38b0453382SBill Fenner 
39685295f4SBill Fenner #include "slcompress.h"
40685295f4SBill Fenner #include "ppp.h"
41685295f4SBill Fenner 
425b0fe478SBruce M Simpson /*
435b0fe478SBruce M Simpson  * XXX - for BSD/OS PPP, what packets get supplied with a PPP header type
445b0fe478SBruce M Simpson  * of PPP_VJC and what packets get supplied with a PPP header type of
455b0fe478SBruce M Simpson  * PPP_VJNC?  PPP_VJNC is for "UNCOMPRESSED_TCP" packets, and PPP_VJC
465b0fe478SBruce M Simpson  * is for COMPRESSED_TCP packets (PPP_IP is used for TYPE_IP packets).
475b0fe478SBruce M Simpson  *
485b0fe478SBruce M Simpson  * RFC 1144 implies that, on the wire, the packet type is *not* needed
495b0fe478SBruce M Simpson  * for PPP, as different PPP protocol types can be used; it only needs
505b0fe478SBruce M Simpson  * to be put on the wire for SLIP.
515b0fe478SBruce M Simpson  *
525b0fe478SBruce M Simpson  * It also indicates that, for compressed SLIP:
535b0fe478SBruce M Simpson  *
545b0fe478SBruce M Simpson  *	If the COMPRESSED_TCP bit is set in the first byte, it's
555b0fe478SBruce M Simpson  *	a COMPRESSED_TCP packet; that byte is the change byte, and
565b0fe478SBruce M Simpson  *	the COMPRESSED_TCP bit, 0x80, isn't used in the change byte.
575b0fe478SBruce M Simpson  *
585b0fe478SBruce M Simpson  *	If the upper 4 bits of the first byte are 7, it's an
595b0fe478SBruce M Simpson  *	UNCOMPRESSED_TCP packet; that byte is the first byte of
605b0fe478SBruce M Simpson  *	the UNCOMPRESSED_TCP modified IP header, with a connection
615b0fe478SBruce M Simpson  *	number in the protocol field, and with the version field
625b0fe478SBruce M Simpson  *	being 7, not 4.
635b0fe478SBruce M Simpson  *
645b0fe478SBruce M Simpson  *	Otherwise, the packet is an IPv4 packet (where the upper 4 bits
655b0fe478SBruce M Simpson  *	of the packet are 4).
665b0fe478SBruce M Simpson  *
675b0fe478SBruce M Simpson  * So this routine looks as if it's sort-of intended to handle
685b0fe478SBruce M Simpson  * compressed SLIP, although it doesn't handle UNCOMPRESSED_TCP
695b0fe478SBruce M Simpson  * correctly for that (it doesn't fix the version number and doesn't
705b0fe478SBruce M Simpson  * do anything to the protocol field), and doesn't check for COMPRESSED_TCP
715b0fe478SBruce M Simpson  * packets correctly for that (you only check the first bit - see
725b0fe478SBruce M Simpson  * B.1 in RFC 1144).
735b0fe478SBruce M Simpson  *
745b0fe478SBruce M Simpson  * But it's called for BSD/OS PPP, not SLIP - perhaps BSD/OS does weird
755b0fe478SBruce M Simpson  * things with the headers?
765b0fe478SBruce M Simpson  *
775b0fe478SBruce M Simpson  * Without a BSD/OS VJC-compressed PPP trace, or knowledge of what the
785b0fe478SBruce M Simpson  * BSD/OS VJC code does, we can't say what's the case.
795b0fe478SBruce M Simpson  *
805b0fe478SBruce M Simpson  * We therefore leave "proto" - which is the PPP protocol type - in place,
815b0fe478SBruce M Simpson  * *not* marked as unused, for now, so that GCC warnings about the
825b0fe478SBruce M Simpson  * unused argument remind us that we should fix this some day.
835b0fe478SBruce M Simpson  */
84b0453382SBill Fenner int
855b0fe478SBruce M Simpson vjc_print(register const char *bp, u_short proto)
86b0453382SBill Fenner {
87b0453382SBill Fenner 	int i;
88b0453382SBill Fenner 
89b0453382SBill Fenner 	switch (bp[0] & 0xf0) {
90b0453382SBill Fenner 	case TYPE_IP:
91b0453382SBill Fenner 		if (eflag)
92b0453382SBill Fenner 			printf("(vjc type=IP) ");
93b0453382SBill Fenner 		return PPP_IP;
94b0453382SBill Fenner 	case TYPE_UNCOMPRESSED_TCP:
95b0453382SBill Fenner 		if (eflag)
96b0453382SBill Fenner 			printf("(vjc type=raw TCP) ");
97b0453382SBill Fenner 		return PPP_IP;
98b0453382SBill Fenner 	case TYPE_COMPRESSED_TCP:
99b0453382SBill Fenner 		if (eflag)
100b0453382SBill Fenner 			printf("(vjc type=compressed TCP) ");
101b0453382SBill Fenner 		for (i = 0; i < 8; i++) {
102b0453382SBill Fenner 			if (bp[1] & (0x80 >> i))
103b0453382SBill Fenner 				printf("%c", "?CI?SAWU"[i]);
104b0453382SBill Fenner 		}
105b0453382SBill Fenner 		if (bp[1])
106b0453382SBill Fenner 			printf(" ");
107b0453382SBill Fenner 		printf("C=0x%02x ", bp[2]);
108b0453382SBill Fenner 		printf("sum=0x%04x ", *(u_short *)&bp[3]);
109b0453382SBill Fenner 		return -1;
110b0453382SBill Fenner 	case TYPE_ERROR:
111b0453382SBill Fenner 		if (eflag)
112b0453382SBill Fenner 			printf("(vjc type=error) ");
113b0453382SBill Fenner 		return -1;
114b0453382SBill Fenner 	default:
115b0453382SBill Fenner 		if (eflag)
116b0453382SBill Fenner 			printf("(vjc type=0x%02x) ", bp[0] & 0xf0);
117b0453382SBill Fenner 		return -1;
118b0453382SBill Fenner 	}
119b0453382SBill Fenner }
120