2 * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
7 * Reserved. This file contains Original Code and/or Modifications of
8 * Original Code as defined in and that are subject to the Apple Public
9 * Source License Version 1.0 (the 'License'). You may not use this file
10 * except in compliance with the License. Please obtain a copy of the
11 * License at http://www.apple.com/publicsource and read it before using
14 * The Original Code and all software distributed under the License are
15 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
16 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
17 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
19 * License for the specific language governing rights and limitations
22 * @APPLE_LICENSE_HEADER_END@
25 * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996
26 * The Regents of the University of California. All rights reserved.
28 * Redistribution and use in source and binary forms, with or without
29 * modification, are permitted provided that: (1) source code distributions
30 * retain the above copyright notice and this paragraph in its entirety, (2)
31 * distributions including binary code include the above copyright notice and
32 * this paragraph in its entirety in the documentation or other materials
33 * provided with the distribution, and (3) all advertising materials mentioning
34 * features or use of this software display the following acknowledgement:
35 * ``This product includes software developed by the University of California,
36 * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
37 * the University nor the names of its contributors may be used to endorse
38 * or promote products derived from this software without specific prior
40 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
41 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
42 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
45 static const char rcsid
[] =
46 "@(#) $Header: /cvs/Darwin/Commands/NeXT/network_cmds/tcpdump.tproj/print-ether.c,v 1.1.1.1 1999/05/02 03:58:33 wsanchez Exp $ (LBL)";
49 #include <sys/param.h>
51 #include <sys/socket.h>
59 #include <netinet/in.h>
60 #include <netinet/if_ether.h>
61 #include <netinet/in_systm.h>
62 #include <netinet/ip.h>
63 #include <netinet/ip_var.h>
64 #include <netinet/udp.h>
65 #include <netinet/udp_var.h>
66 #include <netinet/tcp.h>
67 #include <netinet/tcpip.h>
72 #include "interface.h"
73 #include "addrtoname.h"
74 #include "ethertype.h"
76 const u_char
*packetp
;
77 const u_char
*snapend
;
80 ether_print(register const u_char
*bp
, u_int length
)
82 register const struct ether_header
*ep
;
84 ep
= (const struct ether_header
*)bp
;
86 (void)printf("%s %s %d: ",
87 etheraddr_string(ESRC(ep
)),
88 etheraddr_string(EDST(ep
)),
91 (void)printf("%s %s %s %d: ",
92 etheraddr_string(ESRC(ep
)),
93 etheraddr_string(EDST(ep
)),
94 etherproto_string(ep
->ether_type
),
99 * This is the top level routine of the printer. 'p' is the points
100 * to the ether header of the packet, 'tvp' is the timestamp,
101 * 'length' is the length of the packet off the wire, and 'caplen'
102 * is the number of bytes actually captured.
105 ether_if_print(u_char
*user
, const struct pcap_pkthdr
*h
, const u_char
*p
)
107 u_int caplen
= h
->caplen
;
108 u_int length
= h
->len
;
109 struct ether_header
*ep
;
111 extern u_short extracted_ethertype
;
115 if (caplen
< sizeof(struct ether_header
)) {
121 ether_print(p
, length
);
124 * Some printers want to get back at the ethernet addresses,
125 * and/or check that they're not walking off the end of the packet.
126 * Rather than pass them all the way down, we set these globals.
129 snapend
= p
+ caplen
;
131 length
-= sizeof(struct ether_header
);
132 caplen
-= sizeof(struct ether_header
);
133 ep
= (struct ether_header
*)p
;
134 p
+= sizeof(struct ether_header
);
136 ether_type
= ntohs(ep
->ether_type
);
139 * Is it (gag) an 802.3 encapsulation?
141 extracted_ethertype
= 0;
142 if (ether_type
< ETHERMTU
) {
143 /* Try to print the LLC-layer header & higher layers */
144 if (llc_print(p
, length
, caplen
, ESRC(ep
), EDST(ep
)) == 0) {
145 /* ether_type not known, print raw packet */
147 ether_print((u_char
*)ep
, length
);
148 if (extracted_ethertype
) {
150 etherproto_string(htons(extracted_ethertype
)));
152 if (!xflag
&& !qflag
)
153 default_print(p
, caplen
);
155 } else if (ether_encap_print(ether_type
, p
, length
, caplen
) == 0) {
156 /* ether_type not known, print raw packet */
158 ether_print((u_char
*)ep
, length
+ sizeof(*ep
));
159 if (!xflag
&& !qflag
)
160 default_print(p
, caplen
);
163 default_print(p
, caplen
);
169 * Prints the packet encapsulated in an Ethernet data segment
170 * (or an equivalent encapsulation), given the Ethernet type code.
172 * Returns non-zero if it can do so, zero if the ethertype is unknown.
174 * Stuffs the ether type into a global for the benefit of lower layers
175 * that might want to know what it is.
178 u_short extracted_ethertype
;
181 ether_encap_print(u_short ethertype
, const u_char
*p
,
182 u_int length
, u_int caplen
)
184 extracted_ethertype
= ethertype
;
193 case ETHERTYPE_REVARP
:
194 arp_print(p
, length
, caplen
);
198 decnet_print(p
, length
, caplen
);
201 case ETHERTYPE_ATALK
:
203 fputs("et1 ", stdout
);
204 atalk_print(p
, length
);
208 aarp_print(p
, length
);
213 case ETHERTYPE_MOPRC
:
214 case ETHERTYPE_MOPDL
:
215 /* default_print for now */