]> The Tcpdump Group git mirrors - tcpdump/blob - print-cip.c
Include rpl.h in the tarball.
[tcpdump] / print-cip.c
1 /*
2 * Marko Kiiskila carnil@cs.tut.fi
3 *
4 * Tampere University of Technology - Telecommunications Laboratory
5 *
6 * Permission to use, copy, modify and distribute this
7 * software and its documentation is hereby granted,
8 * provided that both the copyright notice and this
9 * permission notice appear in all copies of the software,
10 * derivative works or modified versions, and any portions
11 * thereof, that both notices appear in supporting
12 * documentation, and that the use of this software is
13 * acknowledged in any publications resulting from using
14 * the software.
15 *
16 * TUT ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
17 * CONDITION AND DISCLAIMS ANY LIABILITY OF ANY KIND FOR
18 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS
19 * SOFTWARE.
20 *
21 */
22
23 #ifdef HAVE_CONFIG_H
24 #include "config.h"
25 #endif
26
27 #include <string.h>
28
29 #include <tcpdump-stdinc.h>
30
31 #include <stdio.h>
32 #include <pcap.h>
33
34 #include "interface.h"
35 #include "addrtoname.h"
36 #include "ethertype.h"
37 #include "ether.h"
38
39 #define RFC1483LLC_LEN 8
40
41 static const unsigned char rfcllc[] = {
42 0xaa, /* DSAP: non-ISO */
43 0xaa, /* SSAP: non-ISO */
44 0x03, /* Ctrl: Unnumbered Information Command PDU */
45 0x00, /* OUI: EtherType */
46 0x00,
47 0x00 };
48
49 static inline void
50 cip_print(int length)
51 {
52 /*
53 * There is no MAC-layer header, so just print the length.
54 */
55 printf("%d: ", length);
56 }
57
58 /*
59 * This is the top level routine of the printer. 'p' points
60 * to the LLC/SNAP or raw header of the packet, 'h->ts' is the timestamp,
61 * 'h->len' is the length of the packet off the wire, and 'h->caplen'
62 * is the number of bytes actually captured.
63 */
64 u_int
65 cip_if_print(const struct pcap_pkthdr *h, const u_char *p)
66 {
67 u_int caplen = h->caplen;
68 u_int length = h->len;
69 u_short extracted_ethertype;
70
71 if (memcmp(rfcllc, p, sizeof(rfcllc))==0 && caplen < RFC1483LLC_LEN) {
72 printf("[|cip]");
73 return (0);
74 }
75
76 if (eflag)
77 cip_print(length);
78
79 if (memcmp(rfcllc, p, sizeof(rfcllc)) == 0) {
80 /*
81 * LLC header is present. Try to print it & higher layers.
82 */
83 if (llc_print(p, length, caplen, NULL, NULL,
84 &extracted_ethertype) == 0) {
85 /* ether_type not known, print raw packet */
86 if (!eflag)
87 cip_print(length);
88 if (extracted_ethertype) {
89 printf("(LLC %s) ",
90 etherproto_string(htons(extracted_ethertype)));
91 }
92 if (!suppress_default_print)
93 default_print(p, caplen);
94 }
95 } else {
96 /*
97 * LLC header is absent; treat it as just IP.
98 */
99 ip_print(gndo, p, length);
100 }
101
102 return (0);
103 }
104
105
106 /*
107 * Local Variables:
108 * c-style: whitesmith
109 * c-basic-offset: 8
110 * End:
111 */