1/*
2 * Copyright (c) 1990, 1991, 1993, 1994, 1995, 1996, 1997
3 *	The Regents of the University of California.  All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that: (1) source code distributions
7 * retain the above copyright notice and this paragraph in its entirety, (2)
8 * distributions including binary code include the above copyright notice and
9 * this paragraph in its entirety in the documentation or other materials
10 * provided with the distribution, and (3) all advertising materials mentioning
11 * features or use of this software display the following acknowledgement:
12 * ``This product includes software developed by the University of California,
13 * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
14 * the University nor the names of its contributors may be used to endorse
15 * or promote products derived from this software without specific prior
16 * written permission.
17 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
18 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
19 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
20 */
21
22#ifdef HAVE_CONFIG_H
23#include "config.h"
24#endif
25
26#include <sys/cdefs.h>
27#ifndef lint
28#if 0
29static const char rcsid[] _U_ =
30    "@(#) Header: /tcpdump/master/tcpdump/print-vjc.c,v 1.15 2004-03-25 03:31:17 mcr Exp (LBL)";
31#else
32__RCSID("$NetBSD: print-vjc.c,v 1.2 2010/12/05 05:11:31 christos Exp $");
33#endif
34#endif
35
36#include <tcpdump-stdinc.h>
37
38#include <pcap.h>
39#include <stdio.h>
40
41#include "interface.h"
42#include "addrtoname.h"
43
44#include "slcompress.h"
45#include "ppp.h"
46
47/*
48 * XXX - for BSD/OS PPP, what packets get supplied with a PPP header type
49 * of PPP_VJC and what packets get supplied with a PPP header type of
50 * PPP_VJNC?  PPP_VJNC is for "UNCOMPRESSED_TCP" packets, and PPP_VJC
51 * is for COMPRESSED_TCP packets (PPP_IP is used for TYPE_IP packets).
52 *
53 * RFC 1144 implies that, on the wire, the packet type is *not* needed
54 * for PPP, as different PPP protocol types can be used; it only needs
55 * to be put on the wire for SLIP.
56 *
57 * It also indicates that, for compressed SLIP:
58 *
59 *	If the COMPRESSED_TCP bit is set in the first byte, it's
60 *	a COMPRESSED_TCP packet; that byte is the change byte, and
61 *	the COMPRESSED_TCP bit, 0x80, isn't used in the change byte.
62 *
63 *	If the upper 4 bits of the first byte are 7, it's an
64 *	UNCOMPRESSED_TCP packet; that byte is the first byte of
65 *	the UNCOMPRESSED_TCP modified IP header, with a connection
66 *	number in the protocol field, and with the version field
67 *	being 7, not 4.
68 *
69 *	Otherwise, the packet is an IPv4 packet (where the upper 4 bits
70 *	of the packet are 4).
71 *
72 * So this routine looks as if it's sort-of intended to handle
73 * compressed SLIP, although it doesn't handle UNCOMPRESSED_TCP
74 * correctly for that (it doesn't fix the version number and doesn't
75 * do anything to the protocol field), and doesn't check for COMPRESSED_TCP
76 * packets correctly for that (you only check the first bit - see
77 * B.1 in RFC 1144).
78 *
79 * But it's called for BSD/OS PPP, not SLIP - perhaps BSD/OS does weird
80 * things with the headers?
81 *
82 * Without a BSD/OS VJC-compressed PPP trace, or knowledge of what the
83 * BSD/OS VJC code does, we can't say what's the case.
84 *
85 * We therefore leave "proto" - which is the PPP protocol type - in place,
86 * *not* marked as unused, for now, so that GCC warnings about the
87 * unused argument remind us that we should fix this some day.
88 */
89int
90vjc_print(register const char *bp, u_short proto _U_)
91{
92	int i;
93
94	switch (bp[0] & 0xf0) {
95	case TYPE_IP:
96		if (eflag)
97			printf("(vjc type=IP) ");
98		return PPP_IP;
99	case TYPE_UNCOMPRESSED_TCP:
100		if (eflag)
101			printf("(vjc type=raw TCP) ");
102		return PPP_IP;
103	case TYPE_COMPRESSED_TCP:
104		if (eflag)
105			printf("(vjc type=compressed TCP) ");
106		for (i = 0; i < 8; i++) {
107			if (bp[1] & (0x80 >> i))
108				printf("%c", "?CI?SAWU"[i]);
109		}
110		if (bp[1])
111			printf(" ");
112		printf("C=0x%02x ", bp[2]);
113		printf("sum=0x%04x ", *(u_short *)&bp[3]);
114		return -1;
115	case TYPE_ERROR:
116		if (eflag)
117			printf("(vjc type=error) ");
118		return -1;
119	default:
120		if (eflag)
121			printf("(vjc type=0x%02x) ", bp[0] & 0xf0);
122		return -1;
123	}
124}
125