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
2256893Sfenner#ifdef HAVE_CONFIG_H
2356893Sfenner#include "config.h"
2456893Sfenner#endif
2556893Sfenner
2656893Sfenner#ifndef lint
27127668Sbmsstatic const char rcsid[] _U_ =
28190207Srpaulo    "@(#) $Header: /tcpdump/master/tcpdump/print-vjc.c,v 1.15 2004-03-25 03:31:17 mcr Exp $ (LBL)";
2956893Sfenner#endif
3056893Sfenner
31127668Sbms#include <tcpdump-stdinc.h>
3256893Sfenner
3356893Sfenner#include <pcap.h>
3456893Sfenner#include <stdio.h>
3556893Sfenner
3656893Sfenner#include "interface.h"
3756893Sfenner#include "addrtoname.h"
3856893Sfenner
3975115Sfenner#include "slcompress.h"
4075115Sfenner#include "ppp.h"
4175115Sfenner
42127668Sbms/*
43127668Sbms * XXX - for BSD/OS PPP, what packets get supplied with a PPP header type
44127668Sbms * of PPP_VJC and what packets get supplied with a PPP header type of
45127668Sbms * PPP_VJNC?  PPP_VJNC is for "UNCOMPRESSED_TCP" packets, and PPP_VJC
46127668Sbms * is for COMPRESSED_TCP packets (PPP_IP is used for TYPE_IP packets).
47127668Sbms *
48127668Sbms * RFC 1144 implies that, on the wire, the packet type is *not* needed
49127668Sbms * for PPP, as different PPP protocol types can be used; it only needs
50127668Sbms * to be put on the wire for SLIP.
51127668Sbms *
52127668Sbms * It also indicates that, for compressed SLIP:
53127668Sbms *
54127668Sbms *	If the COMPRESSED_TCP bit is set in the first byte, it's
55127668Sbms *	a COMPRESSED_TCP packet; that byte is the change byte, and
56127668Sbms *	the COMPRESSED_TCP bit, 0x80, isn't used in the change byte.
57127668Sbms *
58127668Sbms *	If the upper 4 bits of the first byte are 7, it's an
59127668Sbms *	UNCOMPRESSED_TCP packet; that byte is the first byte of
60127668Sbms *	the UNCOMPRESSED_TCP modified IP header, with a connection
61127668Sbms *	number in the protocol field, and with the version field
62127668Sbms *	being 7, not 4.
63127668Sbms *
64127668Sbms *	Otherwise, the packet is an IPv4 packet (where the upper 4 bits
65127668Sbms *	of the packet are 4).
66127668Sbms *
67127668Sbms * So this routine looks as if it's sort-of intended to handle
68127668Sbms * compressed SLIP, although it doesn't handle UNCOMPRESSED_TCP
69127668Sbms * correctly for that (it doesn't fix the version number and doesn't
70127668Sbms * do anything to the protocol field), and doesn't check for COMPRESSED_TCP
71127668Sbms * packets correctly for that (you only check the first bit - see
72127668Sbms * B.1 in RFC 1144).
73127668Sbms *
74127668Sbms * But it's called for BSD/OS PPP, not SLIP - perhaps BSD/OS does weird
75127668Sbms * things with the headers?
76127668Sbms *
77127668Sbms * Without a BSD/OS VJC-compressed PPP trace, or knowledge of what the
78127668Sbms * BSD/OS VJC code does, we can't say what's the case.
79127668Sbms *
80127668Sbms * We therefore leave "proto" - which is the PPP protocol type - in place,
81127668Sbms * *not* marked as unused, for now, so that GCC warnings about the
82127668Sbms * unused argument remind us that we should fix this some day.
83127668Sbms */
8456893Sfennerint
85146773Ssamvjc_print(register const char *bp, u_short proto _U_)
8656893Sfenner{
8756893Sfenner	int i;
8856893Sfenner
8956893Sfenner	switch (bp[0] & 0xf0) {
9056893Sfenner	case TYPE_IP:
9156893Sfenner		if (eflag)
9256893Sfenner			printf("(vjc type=IP) ");
9356893Sfenner		return PPP_IP;
9456893Sfenner	case TYPE_UNCOMPRESSED_TCP:
9556893Sfenner		if (eflag)
9656893Sfenner			printf("(vjc type=raw TCP) ");
9756893Sfenner		return PPP_IP;
9856893Sfenner	case TYPE_COMPRESSED_TCP:
9956893Sfenner		if (eflag)
10056893Sfenner			printf("(vjc type=compressed TCP) ");
10156893Sfenner		for (i = 0; i < 8; i++) {
10256893Sfenner			if (bp[1] & (0x80 >> i))
10356893Sfenner				printf("%c", "?CI?SAWU"[i]);
10456893Sfenner		}
10556893Sfenner		if (bp[1])
10656893Sfenner			printf(" ");
10756893Sfenner		printf("C=0x%02x ", bp[2]);
10856893Sfenner		printf("sum=0x%04x ", *(u_short *)&bp[3]);
10956893Sfenner		return -1;
11056893Sfenner	case TYPE_ERROR:
11156893Sfenner		if (eflag)
11256893Sfenner			printf("(vjc type=error) ");
11356893Sfenner		return -1;
11456893Sfenner	default:
11556893Sfenner		if (eflag)
11656893Sfenner			printf("(vjc type=0x%02x) ", bp[0] & 0xf0);
11756893Sfenner		return -1;
11856893Sfenner	}
11956893Sfenner}
120