source: rtems-libbsd/freebsd/contrib/tcpdump/print-vjc.c @ 8440506

4.1155-freebsd-126-freebsd-12freebsd-9.3
Last change on this file since 8440506 was 8440506, checked in by Chris Johns <chrisj@…>, on 06/15/15 at 07:42:23

Add tcpdump and libpcap.

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