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.3 2000-01-09 09:59:15 assar Exp $ (LBL)";
32 #include <sys/param.h>
34 #include <sys/types.h>
35 #include <sys/socket.h>
39 #include <netinet/in.h>
40 #include <netinet/if_ether.h>
41 #include <netinet/in_systm.h>
42 #include <netinet/ip.h>
43 #include <netinet/ip_var.h>
44 #include <netinet/udp.h>
45 #include <netinet/udp_var.h>
46 #include <netinet/tcp.h>
51 #include "interface.h"
52 #include "addrtoname.h"
54 const u_char
*packetp
;
55 const u_char
*snapend
;
57 #define RFC1483LLC_LEN 8
59 static unsigned char rfcllc
[] = {
60 0xaa, /* DSAP: non-ISO */
61 0xaa, /* SSAP: non-ISO */
62 0x03, /* Ctrl: Unnumbered Information Command PDU */
63 0x00, /* OUI: EtherType */
68 cip_print(register const u_char
*bp
, int length
)
72 if (memcmp(rfcllc
, bp
, sizeof(rfcllc
))) {
74 for(i
=0;i
<RFC1483LLC_LEN
;i
++)
75 (void)printf("%2.2x ",bp
[i
]);
77 for(i
=0;i
<RFC1483LLC_LEN
-2;i
++)
78 (void)printf("%2.2x ",bp
[i
]);
79 etherproto_string(((u_short
*)bp
)[3]);
83 (void)printf("(null encapsulation)");
85 (void)printf("(null encap)");
86 etherproto_string(ETHERTYPE_IP
);
92 * This is the top level routine of the printer. 'p' is the points
93 * to the raw header of the packet, 'tvp' is the timestamp,
94 * 'length' is the length of the packet off the wire, and 'caplen'
95 * is the number of bytes actually captured.
98 cip_if_print(u_char
*user
, const struct pcap_pkthdr
*h
, const u_char
*p
)
100 int caplen
= h
->caplen
;
103 u_short extracted_ethertype
;
108 if (memcmp(rfcllc
, p
, sizeof(rfcllc
))==0 && caplen
< RFC1483LLC_LEN
) {
114 cip_print(p
, length
);
117 * Some printers want to get back at the ethernet addresses,
118 * and/or check that they're not walking off the end of the packet.
119 * Rather than pass them all the way down, we set these globals.
122 snapend
= p
+ caplen
;
124 if (memcmp(rfcllc
, p
, sizeof(rfcllc
))==0) {
125 length
-= RFC1483LLC_LEN
;
126 caplen
-= RFC1483LLC_LEN
;
129 ether_type
= ntohs(bp
[3]);
131 ether_type
= ETHERTYPE_IP
;
134 * Is it (gag) an 802.3 encapsulation?
136 extracted_ethertype
= 0;
137 if (ether_type
< ETHERMTU
) {
138 /* Try to print the LLC-layer header & higher layers */
139 if (llc_print(p
, length
, caplen
, NULL
, NULL
)==0) {
140 /* ether_type not known, print raw packet */
142 cip_print((u_char
*)bp
, length
);
143 if (extracted_ethertype
) {
145 etherproto_string(htons(extracted_ethertype
)));
147 if (!xflag
&& !qflag
)
148 default_print(p
, caplen
);
150 } else if (ether_encap_print(ether_type
, p
, length
, caplen
) == 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
);