]>
The Tcpdump Group git mirrors - tcpdump/blob - print-arp.c
2 * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997
3 * The Regents of the University of California. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that: (1) source code distributions
7 * retain the above copyright notice and this paragraph in its entirety, (2)
8 * distributions including binary code include the above copyright notice and
9 * this paragraph in its entirety in the documentation or other materials
10 * provided with the distribution, and (3) all advertising materials mentioning
11 * features or use of this software display the following acknowledgement:
12 * ``This product includes software developed by the University of California,
13 * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
14 * the University nor the names of its contributors may be used to endorse
15 * or promote products derived from this software without specific prior
17 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
18 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
19 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
23 static const char rcsid
[] =
24 "@(#) $Header: /tcpdump/master/tcpdump/print-arp.c,v 1.48 2000-10-09 03:24:25 guy Exp $ (LBL)";
31 #include <sys/param.h>
33 #include <sys/socket.h>
38 #include "interface.h"
39 #include "addrtoname.h"
41 #include "ethertype.h"
42 #include "extract.h" /* must come after interface.h */
45 * Address Resolution Protocol.
47 * See RFC 826 for protocol description. ARP packets are variable
48 * in size; the arphdr structure defines the fixed-length portion.
49 * Protocol type values are the same as those for 10 Mb/s Ethernet.
50 * It is followed by the variable-sized fields ar_sha, arp_spa,
51 * arp_tha and arp_tpa in that order, according to the lengths
52 * specified. Field names used correspond to RFC 826.
55 u_short ar_hrd
; /* format of hardware address */
56 #define ARPHRD_ETHER 1 /* ethernet hardware format */
57 #define ARPHRD_IEEE802 6 /* token-ring hardware format */
58 #define ARPHRD_FRELAY 15 /* frame relay hardware format */
59 u_short ar_pro
; /* format of protocol address */
60 u_char ar_hln
; /* length of hardware address */
61 u_char ar_pln
; /* length of protocol address */
62 u_short ar_op
; /* one of: */
63 #define ARPOP_REQUEST 1 /* request to resolve address */
64 #define ARPOP_REPLY 2 /* response to previous request */
65 #define ARPOP_REVREQUEST 3 /* request protocol address given hardware */
66 #define ARPOP_REVREPLY 4 /* response giving protocol address */
67 #define ARPOP_INVREQUEST 8 /* request to identify peer */
68 #define ARPOP_INVREPLY 9 /* response identifying peer */
70 * The remaining fields are variable in size,
71 * according to the sizes above.
74 u_char ar_sha
[]; /* sender hardware address */
75 u_char ar_spa
[]; /* sender protocol address */
76 u_char ar_tha
[]; /* target hardware address */
77 u_char ar_tpa
[]; /* target protocol address */
84 * Ethernet Address Resolution Protocol.
86 * See RFC 826 for protocol description. Structure below is adapted
87 * to resolving internet addresses. Field names used correspond to
91 struct arphdr ea_hdr
; /* fixed-size header */
92 u_char arp_sha
[6]; /* sender hardware address */
93 u_char arp_spa
[4]; /* sender protocol address */
94 u_char arp_tha
[6]; /* target hardware address */
95 u_char arp_tpa
[4]; /* target protocol address */
97 #define arp_hrd ea_hdr.ar_hrd
98 #define arp_pro ea_hdr.ar_pro
99 #define arp_hln ea_hdr.ar_hln
100 #define arp_pln ea_hdr.ar_pln
101 #define arp_op ea_hdr.ar_op
103 #define ETHER_ARP_HDRLEN (ARP_HDRLEN + 6 + 4 + 6 + 4)
105 #define SHA(ap) ((ap)->arp_sha)
106 #define THA(ap) ((ap)->arp_tha)
107 #define SPA(ap) ((ap)->arp_spa)
108 #define TPA(ap) ((ap)->arp_tpa)
111 #ifndef REVARP_REQUEST
112 #define REVARP_REQUEST 3
115 #define REVARP_REPLY 4
118 static u_char ezero
[6];
121 arp_print(register const u_char
*bp
, u_int length
, u_int caplen
)
123 register const struct ether_arp
*ap
;
124 register const struct ether_header
*eh
;
125 register u_short pro
, hrd
, op
;
127 ap
= (struct ether_arp
*)bp
;
128 if ((u_char
*)(ap
+ 1) > snapend
) {
132 if (length
< ETHER_ARP_HDRLEN
) {
133 (void)printf("truncated-arp");
134 default_print((u_char
*)ap
, length
);
138 pro
= EXTRACT_16BITS(&ap
->arp_pro
);
139 hrd
= EXTRACT_16BITS(&ap
->arp_hrd
);
140 op
= EXTRACT_16BITS(&ap
->arp_op
);
142 if ((pro
!= ETHERTYPE_IP
&& pro
!= ETHERTYPE_TRAIL
)
143 || ap
->arp_hln
!= sizeof(SHA(ap
))
144 || ap
->arp_pln
!= sizeof(SPA(ap
))) {
145 (void)printf("arp-#%d for proto #%d (%d) hardware #%d (%d)",
146 op
, pro
, ap
->arp_pln
,
150 if (pro
== ETHERTYPE_TRAIL
)
151 (void)printf("trailer-");
152 eh
= (struct ether_header
*)packetp
;
156 (void)printf("arp who-has %s", ipaddr_string(TPA(ap
)));
157 if (memcmp((char *)ezero
, (char *)THA(ap
), 6) != 0)
158 (void)printf(" (%s)", etheraddr_string(THA(ap
)));
159 (void)printf(" tell %s", ipaddr_string(SPA(ap
)));
160 if (memcmp((char *)ESRC(eh
), (char *)SHA(ap
), 6) != 0)
161 (void)printf(" (%s)", etheraddr_string(SHA(ap
)));
165 (void)printf("arp reply %s", ipaddr_string(SPA(ap
)));
166 if (memcmp((char *)ESRC(eh
), (char *)SHA(ap
), 6) != 0)
167 (void)printf(" (%s)", etheraddr_string(SHA(ap
)));
168 (void)printf(" is-at %s", etheraddr_string(SHA(ap
)));
169 if (memcmp((char *)EDST(eh
), (char *)THA(ap
), 6) != 0)
170 (void)printf(" (%s)", etheraddr_string(THA(ap
)));
174 (void)printf("rarp who-is %s tell %s",
175 etheraddr_string(THA(ap
)),
176 etheraddr_string(SHA(ap
)));
180 (void)printf("rarp reply %s at %s",
181 etheraddr_string(THA(ap
)),
182 ipaddr_string(TPA(ap
)));
186 (void)printf("arp-#%d", op
);
187 default_print((u_char
*)ap
, caplen
);
190 if (hrd
!= ARPHRD_ETHER
)
191 printf(" hardware #%d", hrd
);