Fix markup. Fix backslashes to surive roff.
[netbsd-mini2440.git] / dist / tcpdump / print-cip.c
blobfa07cdbb0e357fbb1acc5e5b121e786fa1e09dd9
1 /* $NetBSD$ */
3 /*
4 * Marko Kiiskila carnil@cs.tut.fi
6 * Tampere University of Technology - Telecommunications Laboratory
8 * Permission to use, copy, modify and distribute this
9 * software and its documentation is hereby granted,
10 * provided that both the copyright notice and this
11 * permission notice appear in all copies of the software,
12 * derivative works or modified versions, and any portions
13 * thereof, that both notices appear in supporting
14 * documentation, and that the use of this software is
15 * acknowledged in any publications resulting from using
16 * the software.
18 * TUT ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
19 * CONDITION AND DISCLAIMS ANY LIABILITY OF ANY KIND FOR
20 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS
21 * SOFTWARE.
25 #include <sys/cdefs.h>
26 #ifndef lint
27 #if 0
28 static const char rcsid[] _U_ =
29 "@(#) Header: /tcpdump/master/tcpdump/print-cip.c,v 1.25.2.1 2005/07/07 01:24:34 guy Exp (LBL)";
30 #else
31 __RCSID("$NetBSD: tcpdump2rcsid.ex,v 1.1 2001/06/25 20:09:58 itojun Exp $");
32 #endif
33 #endif
35 #ifdef HAVE_CONFIG_H
36 #include "config.h"
37 #endif
39 #include <string.h>
41 #include <tcpdump-stdinc.h>
43 #include <stdio.h>
44 #include <pcap.h>
46 #include "interface.h"
47 #include "addrtoname.h"
48 #include "ethertype.h"
49 #include "ether.h"
51 #define RFC1483LLC_LEN 8
53 static unsigned char rfcllc[] = {
54 0xaa, /* DSAP: non-ISO */
55 0xaa, /* SSAP: non-ISO */
56 0x03, /* Ctrl: Unnumbered Information Command PDU */
57 0x00, /* OUI: EtherType */
58 0x00,
59 0x00 };
61 static inline void
62 cip_print(int length)
65 * There is no MAC-layer header, so just print the length.
67 printf("%d: ", length);
71 * This is the top level routine of the printer. 'p' points
72 * to the LLC/SNAP or raw header of the packet, 'h->ts' is the timestamp,
73 * 'h->len' is the length of the packet off the wire, and 'h->caplen'
74 * is the number of bytes actually captured.
76 u_int
77 cip_if_print(const struct pcap_pkthdr *h, const u_char *p)
79 u_int caplen = h->caplen;
80 u_int length = h->len;
81 u_short extracted_ethertype;
83 if (memcmp(rfcllc, p, sizeof(rfcllc))==0 && caplen < RFC1483LLC_LEN) {
84 printf("[|cip]");
85 return (0);
88 if (eflag)
89 cip_print(length);
91 if (memcmp(rfcllc, p, sizeof(rfcllc)) == 0) {
93 * LLC header is present. Try to print it & higher layers.
95 if (llc_print(p, length, caplen, NULL, NULL,
96 &extracted_ethertype) == 0) {
97 /* ether_type not known, print raw packet */
98 if (!eflag)
99 cip_print(length);
100 if (extracted_ethertype) {
101 printf("(LLC %s) ",
102 etherproto_string(htons(extracted_ethertype)));
104 if (!suppress_default_print)
105 default_print(p, caplen);
107 } else {
109 * LLC header is absent; treat it as just IP.
111 ip_print(gndo, p, length);
114 return (0);
119 * Local Variables:
120 * c-style: whitesmith
121 * c-basic-offset: 8
122 * End: