156893Sfenner/*
256893Sfenner * Copyright (c) 1990, 1991, 1993, 1994, 1995, 1996, 1997
356893Sfenner *	The Regents of the University of California.  All rights reserved.
456893Sfenner *
556893Sfenner * Redistribution and use in source and binary forms, with or without
656893Sfenner * modification, are permitted provided that: (1) source code distributions
756893Sfenner * retain the above copyright notice and this paragraph in its entirety, (2)
856893Sfenner * distributions including binary code include the above copyright notice and
956893Sfenner * this paragraph in its entirety in the documentation or other materials
1056893Sfenner * provided with the distribution, and (3) all advertising materials mentioning
1156893Sfenner * features or use of this software display the following acknowledgement:
1256893Sfenner * ``This product includes software developed by the University of California,
1356893Sfenner * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
1456893Sfenner * the University nor the names of its contributors may be used to endorse
1556893Sfenner * or promote products derived from this software without specific prior
1656893Sfenner * written permission.
1756893Sfenner * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
1856893Sfenner * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
1956893Sfenner * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
2056893Sfenner */
2156893Sfenner
22276788Sdelphij#define NETDISSECT_REWORKED
2356893Sfenner#ifdef HAVE_CONFIG_H
2456893Sfenner#include "config.h"
2556893Sfenner#endif
2656893Sfenner
27127668Sbms#include <tcpdump-stdinc.h>
2856893Sfenner
2956893Sfenner#include "interface.h"
3075115Sfenner#include "slcompress.h"
3175115Sfenner#include "ppp.h"
3275115Sfenner
33127668Sbms/*
34127668Sbms * XXX - for BSD/OS PPP, what packets get supplied with a PPP header type
35127668Sbms * of PPP_VJC and what packets get supplied with a PPP header type of
36127668Sbms * PPP_VJNC?  PPP_VJNC is for "UNCOMPRESSED_TCP" packets, and PPP_VJC
37127668Sbms * is for COMPRESSED_TCP packets (PPP_IP is used for TYPE_IP packets).
38127668Sbms *
39127668Sbms * RFC 1144 implies that, on the wire, the packet type is *not* needed
40127668Sbms * for PPP, as different PPP protocol types can be used; it only needs
41127668Sbms * to be put on the wire for SLIP.
42127668Sbms *
43127668Sbms * It also indicates that, for compressed SLIP:
44127668Sbms *
45127668Sbms *	If the COMPRESSED_TCP bit is set in the first byte, it's
46127668Sbms *	a COMPRESSED_TCP packet; that byte is the change byte, and
47127668Sbms *	the COMPRESSED_TCP bit, 0x80, isn't used in the change byte.
48127668Sbms *
49127668Sbms *	If the upper 4 bits of the first byte are 7, it's an
50127668Sbms *	UNCOMPRESSED_TCP packet; that byte is the first byte of
51127668Sbms *	the UNCOMPRESSED_TCP modified IP header, with a connection
52127668Sbms *	number in the protocol field, and with the version field
53127668Sbms *	being 7, not 4.
54127668Sbms *
55127668Sbms *	Otherwise, the packet is an IPv4 packet (where the upper 4 bits
56127668Sbms *	of the packet are 4).
57127668Sbms *
58127668Sbms * So this routine looks as if it's sort-of intended to handle
59127668Sbms * compressed SLIP, although it doesn't handle UNCOMPRESSED_TCP
60127668Sbms * correctly for that (it doesn't fix the version number and doesn't
61127668Sbms * do anything to the protocol field), and doesn't check for COMPRESSED_TCP
62127668Sbms * packets correctly for that (you only check the first bit - see
63127668Sbms * B.1 in RFC 1144).
64127668Sbms *
65127668Sbms * But it's called for BSD/OS PPP, not SLIP - perhaps BSD/OS does weird
66127668Sbms * things with the headers?
67127668Sbms *
68127668Sbms * Without a BSD/OS VJC-compressed PPP trace, or knowledge of what the
69127668Sbms * BSD/OS VJC code does, we can't say what's the case.
70127668Sbms *
71127668Sbms * We therefore leave "proto" - which is the PPP protocol type - in place,
72127668Sbms * *not* marked as unused, for now, so that GCC warnings about the
73127668Sbms * unused argument remind us that we should fix this some day.
74127668Sbms */
7556893Sfennerint
76276788Sdelphijvjc_print(netdissect_options *ndo, register const char *bp, u_short proto _U_)
7756893Sfenner{
7856893Sfenner	int i;
7956893Sfenner
8056893Sfenner	switch (bp[0] & 0xf0) {
8156893Sfenner	case TYPE_IP:
82276788Sdelphij		if (ndo->ndo_eflag)
83276788Sdelphij			ND_PRINT((ndo, "(vjc type=IP) "));
8456893Sfenner		return PPP_IP;
8556893Sfenner	case TYPE_UNCOMPRESSED_TCP:
86276788Sdelphij		if (ndo->ndo_eflag)
87276788Sdelphij			ND_PRINT((ndo, "(vjc type=raw TCP) "));
8856893Sfenner		return PPP_IP;
8956893Sfenner	case TYPE_COMPRESSED_TCP:
90276788Sdelphij		if (ndo->ndo_eflag)
91276788Sdelphij			ND_PRINT((ndo, "(vjc type=compressed TCP) "));
9256893Sfenner		for (i = 0; i < 8; i++) {
9356893Sfenner			if (bp[1] & (0x80 >> i))
94276788Sdelphij				ND_PRINT((ndo, "%c", "?CI?SAWU"[i]));
9556893Sfenner		}
9656893Sfenner		if (bp[1])
97276788Sdelphij			ND_PRINT((ndo, " "));
98276788Sdelphij		ND_PRINT((ndo, "C=0x%02x ", bp[2]));
99276788Sdelphij		ND_PRINT((ndo, "sum=0x%04x ", *(u_short *)&bp[3]));
10056893Sfenner		return -1;
10156893Sfenner	case TYPE_ERROR:
102276788Sdelphij		if (ndo->ndo_eflag)
103276788Sdelphij			ND_PRINT((ndo, "(vjc type=error) "));
10456893Sfenner		return -1;
10556893Sfenner	default:
106276788Sdelphij		if (ndo->ndo_eflag)
107276788Sdelphij			ND_PRINT((ndo, "(vjc type=0x%02x) ", bp[0] & 0xf0));
10856893Sfenner		return -1;
10956893Sfenner	}
11056893Sfenner}
111