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.12 2001-03-19 03:58:10 guy Exp $ (LBL)";
34 #include <sys/param.h>
36 #include <sys/types.h>
37 #include <sys/socket.h>
40 #include <netinet/in.h>
45 #include "interface.h"
46 #include "addrtoname.h"
47 #include "ethertype.h"
50 const u_char
*packetp
;
51 const u_char
*snapend
;
53 #define RFC1483LLC_LEN 8
55 static unsigned char rfcllc
[] = {
56 0xaa, /* DSAP: non-ISO */
57 0xaa, /* SSAP: non-ISO */
58 0x03, /* Ctrl: Unnumbered Information Command PDU */
59 0x00, /* OUI: EtherType */
64 cip_print(register const u_char
*bp
, int length
)
68 if (memcmp(rfcllc
, bp
, sizeof(rfcllc
))) {
70 for (i
= 0;i
< RFC1483LLC_LEN
; i
++)
71 (void)printf("%2.2x ",bp
[i
]);
73 for (i
= 0;i
< RFC1483LLC_LEN
- 2; i
++)
74 (void)printf("%2.2x ",bp
[i
]);
75 etherproto_string(((u_short
*)bp
)[3]);
79 (void)printf("(null encapsulation)");
81 (void)printf("(null encap)");
82 etherproto_string(ETHERTYPE_IP
);
88 * This is the top level routine of the printer. 'p' is the points
89 * to the raw header of the packet, 'tvp' is the timestamp,
90 * 'length' is the length of the packet off the wire, and 'caplen'
91 * is the number of bytes actually captured.
94 cip_if_print(u_char
*user
, const struct pcap_pkthdr
*h
, const u_char
*p
)
96 int caplen
= h
->caplen
;
99 u_short extracted_ethertype
;
104 if (memcmp(rfcllc
, p
, sizeof(rfcllc
))==0 && caplen
< RFC1483LLC_LEN
) {
110 cip_print(p
, length
);
113 * Some printers want to get back at the ethernet addresses,
114 * and/or check that they're not walking off the end of the packet.
115 * Rather than pass them all the way down, we set these globals.
118 snapend
= p
+ caplen
;
120 if (memcmp(rfcllc
, p
, sizeof(rfcllc
))==0) {
121 length
-= RFC1483LLC_LEN
;
122 caplen
-= RFC1483LLC_LEN
;
125 ether_type
= ntohs(bp
[3]);
127 ether_type
= ETHERTYPE_IP
;
132 * Is it (gag) an 802.3 encapsulation?
134 extracted_ethertype
= 0;
135 if (ether_type
< ETHERMTU
) {
136 /* Try to print the LLC-layer header & higher layers */
137 if (llc_print(p
, length
, caplen
, NULL
, NULL
,
138 &extracted_ethertype
)==0) {
139 /* ether_type not known, print raw packet */
141 cip_print((u_char
*)bp
, length
+ RFC1483LLC_LEN
);
142 if (extracted_ethertype
) {
144 etherproto_string(htons(extracted_ethertype
)));
146 if (!xflag
&& !qflag
)
147 default_print(p
, caplen
);
149 } else if (ether_encap_print(ether_type
, p
, length
, caplen
,
150 &extracted_ethertype
) == 0) {
151 /* ether_type not known, print raw packet */
153 cip_print((u_char
*)bp
, length
+ RFC1483LLC_LEN
);
154 if (!xflag
&& !qflag
)
155 default_print(p
, caplen
);
158 default_print(p
, caplen
);