2 * Marko Kiiskila carnil@cs.tut.fi
4 * Tampere University of Technology - Telecommunications Laboratory
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
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
24 static const char rcsid[] =
25 "@(#) $Header: /tcpdump/master/tcpdump/print-cip.c,v 1.11 2000/12/22 22:45:10 guy Exp $ (LBL)";
32 #include <sys/param.h>
34 #include <sys/types.h>
35 #include <sys/socket.h>
38 #include <netinet/in.h>
43 #include "interface.h"
44 #include "addrtoname.h"
45 #include "ethertype.h"
48 const u_char *packetp;
49 const u_char *snapend;
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 */
62 cip_print(register const u_char *bp, int length)
66 if (memcmp(rfcllc, bp, sizeof(rfcllc))) {
68 for (i = 0;i < RFC1483LLC_LEN; i++)
69 (void)printf("%2.2x ",bp[i]);
71 for (i = 0;i < RFC1483LLC_LEN - 2; i++)
72 (void)printf("%2.2x ",bp[i]);
73 etherproto_string(((u_short*)bp)[3]);
77 (void)printf("(null encapsulation)");
79 (void)printf("(null encap)");
80 etherproto_string(ETHERTYPE_IP);
86 * This is the top level routine of the printer. 'p' is the points
87 * to the raw header of the packet, 'tvp' is the timestamp,
88 * 'length' is the length of the packet off the wire, and 'caplen'
89 * is the number of bytes actually captured.
92 cip_if_print(u_char *user, const struct pcap_pkthdr *h, const u_char *p)
94 int caplen = h->caplen;
97 u_short extracted_ethertype;
102 if (memcmp(rfcllc, p, sizeof(rfcllc))==0 && caplen < RFC1483LLC_LEN) {
108 cip_print(p, length);
111 * Some printers want to get back at the ethernet addresses,
112 * and/or check that they're not walking off the end of the packet.
113 * Rather than pass them all the way down, we set these globals.
116 snapend = p + caplen;
118 if (memcmp(rfcllc, p, sizeof(rfcllc))==0) {
119 length -= RFC1483LLC_LEN;
120 caplen -= RFC1483LLC_LEN;
123 ether_type = ntohs(bp[3]);
125 ether_type = ETHERTYPE_IP;
130 * Is it (gag) an 802.3 encapsulation?
132 extracted_ethertype = 0;
133 if (ether_type < ETHERMTU) {
134 /* Try to print the LLC-layer header & higher layers */
135 if (llc_print(p, length, caplen, NULL, NULL,
136 &extracted_ethertype)==0) {
137 /* ether_type not known, print raw packet */
139 cip_print((u_char *)bp, length + RFC1483LLC_LEN);
140 if (extracted_ethertype) {
142 etherproto_string(htons(extracted_ethertype)));
144 if (!xflag && !qflag)
145 default_print(p, caplen);
147 } else if (ether_encap_print(ether_type, p, length, caplen,
148 &extracted_ethertype) == 0) {
149 /* ether_type not known, print raw packet */
151 cip_print((u_char *)bp, length + RFC1483LLC_LEN);
152 if (!xflag && !qflag)
153 default_print(p, caplen);
156 default_print(p, caplen);