]>
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.55 2002-08-01 08:53:00 risso Exp $ (LBL)";
31 #include <tcpdump-stdinc.h>
36 #include "interface.h"
37 #include "addrtoname.h"
39 #include "ethertype.h"
40 #include "extract.h" /* must come after interface.h */
43 * Address Resolution Protocol.
45 * See RFC 826 for protocol description. ARP packets are variable
46 * in size; the arphdr structure defines the fixed-length portion.
47 * Protocol type values are the same as those for 10 Mb/s Ethernet.
48 * It is followed by the variable-sized fields ar_sha, arp_spa,
49 * arp_tha and arp_tpa in that order, according to the lengths
50 * specified. Field names used correspond to RFC 826.
53 u_short ar_hrd
; /* format of hardware address */
54 #define ARPHRD_ETHER 1 /* ethernet hardware format */
55 #define ARPHRD_IEEE802 6 /* token-ring hardware format */
56 #define ARPHRD_ARCNET 7 /* arcnet hardware format */
57 #define ARPHRD_FRELAY 15 /* frame relay hardware format */
58 #define ARPHRD_STRIP 23 /* Ricochet Starmode Radio hardware format */
59 #define ARPHRD_IEEE1394 24 /* IEEE 1394 (FireWire) hardware format */
60 u_short ar_pro
; /* format of protocol address */
61 u_char ar_hln
; /* length of hardware address */
62 u_char ar_pln
; /* length of protocol address */
63 u_short ar_op
; /* one of: */
64 #define ARPOP_REQUEST 1 /* request to resolve address */
65 #define ARPOP_REPLY 2 /* response to previous request */
66 #define ARPOP_REVREQUEST 3 /* request protocol address given hardware */
67 #define ARPOP_REVREPLY 4 /* response giving protocol address */
68 #define ARPOP_INVREQUEST 8 /* request to identify peer */
69 #define ARPOP_INVREPLY 9 /* response identifying peer */
71 * The remaining fields are variable in size,
72 * according to the sizes above.
75 u_char ar_sha
[]; /* sender hardware address */
76 u_char ar_spa
[]; /* sender protocol address */
77 u_char ar_tha
[]; /* target hardware address */
78 u_char ar_tpa
[]; /* target protocol address */
80 #define ar_sha(ap) (((const u_char *)((ap)+1))+0)
81 #define ar_spa(ap) (((const u_char *)((ap)+1))+ (ap)->ar_hln)
82 #define ar_tha(ap) (((const u_char *)((ap)+1))+ (ap)->ar_hln+(ap)->ar_pln)
83 #define ar_tpa(ap) (((const u_char *)((ap)+1))+2*(ap)->ar_hln+(ap)->ar_pln)
88 #define HRD(ap) ((ap)->ar_hrd)
89 #define HLN(ap) ((ap)->ar_hln)
90 #define PLN(ap) ((ap)->ar_pln)
91 #define OP(ap) ((ap)->ar_op)
92 #define PRO(ap) ((ap)->ar_pro)
93 #define SHA(ap) (ar_sha(ap))
94 #define SPA(ap) (ar_spa(ap))
95 #define THA(ap) (ar_tha(ap))
96 #define TPA(ap) (ar_tpa(ap))
99 * ATM Address Resolution Protocol.
101 * See RFC 2225 for protocol description. ARP packets are variable
102 * in size; the arphdr structure defines the fixed-length portion.
103 * Protocol type values are the same as those for 10 Mb/s Ethernet.
104 * It is followed by the variable-sized fields ar_sha, arp_spa,
105 * arp_tha and arp_tpa in that order, according to the lengths
106 * specified. Field names used correspond to RFC 826.
108 struct atmarp_pkthdr
{
109 u_short ar_hrd
; /* format of hardware address */
110 #define ARPHRD_ATM2225 19 /* ATM (RFC 2225) */
111 u_short ar_pro
; /* format of protocol address */
112 u_char ar_shtl
; /* length of hardware address */
113 u_char ar_sstl
; /* length of hardware address */
114 u_short ar_op
; /* same as regular ARP */
120 * The remaining fields are variable in size,
121 * according to the sizes above.
124 u_char ar_sha
[]; /* sender hardware address */
125 u_char ar_spa
[]; /* sender protocol address */
126 u_char ar_tha
[]; /* target hardware address */
127 u_char ar_tpa
[]; /* target protocol address */
129 #define ar_sha(ap) (((const u_char *)((ap)+1))+0)
130 #define ar_spa(ap) (((const u_char *)((ap)+1))+ (ap)->ar_hln)
131 #define ar_tha(ap) (((const u_char *)((ap)+1))+ (ap)->ar_hln+(ap)->ar_pln)
132 #define ar_tpa(ap) (((const u_char *)((ap)+1))+2*(ap)->ar_hln+(ap)->ar_pln)
135 static u_char ezero
[6];
138 atmarp_print(const u_char
*bp
, u_int length
, u_int caplen
)
140 const struct arp_pkthdr
*ap
;
141 u_short pro
, hrd
, op
;
143 ap
= (const struct arp_pkthdr
*)bp
;
145 if ((const u_char
*)(ar_tpa(ap
) + PLN(ap
)) > snapend
) {
146 (void)printf("truncated-arp");
147 default_print((const u_char
*)ap
, length
);
151 hrd
= EXTRACT_16BITS(&HRD(ap
));
152 if (hrd
== ARPHRD_ATM2225
)
153 atmarp_print(bp
, length
, caplen
);
154 pro
= EXTRACT_16BITS(&PRO(ap
));
155 op
= EXTRACT_16BITS(&OP(ap
));
157 if (pro
!= ETHERTYPE_IP
&& pro
!= ETHERTYPE_TRAIL
) {
158 (void)printf("arp-#%d for proto #%d (%d) hardware #%d (%d)",
159 op
, pro
, PLN(ap
), hrd
, HLN(ap
));
162 if (pro
== ETHERTYPE_TRAIL
)
163 (void)printf("trailer-");
167 (void)printf("arp who-has %s", ipaddr_string(TPA(ap
)));
168 if (memcmp((const char *)ezero
, (const char *)THA(ap
), HLN(ap
)) != 0)
169 (void)printf(" (%s)",
170 linkaddr_string(THA(ap
), HLN(ap
)));
171 (void)printf(" tell %s", ipaddr_string(SPA(ap
)));
175 (void)printf("arp reply %s", ipaddr_string(SPA(ap
)));
176 (void)printf(" is-at %s", linkaddr_string(SHA(ap
), HLN(ap
)));
179 case ARPOP_REVREQUEST
:
180 (void)printf("rarp who-is %s tell %s",
181 linkaddr_string(THA(ap
), HLN(ap
)),
182 linkaddr_string(SHA(ap
), HLN(ap
)));
186 (void)printf("rarp reply %s at %s",
187 linkaddr_string(THA(ap
), HLN(ap
)),
188 ipaddr_string(TPA(ap
)));
191 case ARPOP_INVREQUEST
:
192 (void)printf("invarp who-is %s tell %s",
193 linkaddr_string(THA(ap
), HLN(ap
)),
194 linkaddr_string(SHA(ap
), HLN(ap
)));
198 (void)printf("invarp reply %s at %s",
199 linkaddr_string(THA(ap
), HLN(ap
)),
200 ipaddr_string(TPA(ap
)));
204 (void)printf("arp-#%d", op
);
205 default_print((const u_char
*)ap
, caplen
);
208 if (hrd
!= ARPHRD_ETHER
)
209 printf(" hardware #%d", hrd
);
212 (void)printf("[|arp]");
216 arp_print(const u_char
*bp
, u_int length
, u_int caplen
)
218 const struct arp_pkthdr
*ap
;
219 u_short pro
, hrd
, op
;
221 ap
= (const struct arp_pkthdr
*)bp
;
223 if ((const u_char
*)(ar_tpa(ap
) + PLN(ap
)) > snapend
) {
224 (void)printf("truncated-arp");
225 default_print((const u_char
*)ap
, length
);
229 hrd
= EXTRACT_16BITS(&HRD(ap
));
230 if (hrd
== ARPHRD_ATM2225
)
231 atmarp_print(bp
, length
, caplen
);
232 pro
= EXTRACT_16BITS(&PRO(ap
));
233 op
= EXTRACT_16BITS(&OP(ap
));
235 if (pro
!= ETHERTYPE_IP
&& pro
!= ETHERTYPE_TRAIL
) {
236 (void)printf("arp-#%d for proto #%d (%d) hardware #%d (%d)",
237 op
, pro
, PLN(ap
), hrd
, HLN(ap
));
240 if (pro
== ETHERTYPE_TRAIL
)
241 (void)printf("trailer-");
245 (void)printf("arp who-has %s", ipaddr_string(TPA(ap
)));
246 if (memcmp((const char *)ezero
, (const char *)THA(ap
), HLN(ap
)) != 0)
247 (void)printf(" (%s)",
248 linkaddr_string(THA(ap
), HLN(ap
)));
249 (void)printf(" tell %s", ipaddr_string(SPA(ap
)));
253 (void)printf("arp reply %s", ipaddr_string(SPA(ap
)));
254 (void)printf(" is-at %s", linkaddr_string(SHA(ap
), HLN(ap
)));
257 case ARPOP_REVREQUEST
:
258 (void)printf("rarp who-is %s tell %s",
259 linkaddr_string(THA(ap
), HLN(ap
)),
260 linkaddr_string(SHA(ap
), HLN(ap
)));
264 (void)printf("rarp reply %s at %s",
265 linkaddr_string(THA(ap
), HLN(ap
)),
266 ipaddr_string(TPA(ap
)));
269 case ARPOP_INVREQUEST
:
270 (void)printf("invarp who-is %s tell %s",
271 linkaddr_string(THA(ap
), HLN(ap
)),
272 linkaddr_string(SHA(ap
), HLN(ap
)));
276 (void)printf("invarp reply %s at %s",
277 linkaddr_string(THA(ap
), HLN(ap
)),
278 ipaddr_string(TPA(ap
)));
282 (void)printf("arp-#%d", op
);
283 default_print((const u_char
*)ap
, caplen
);
286 if (hrd
!= ARPHRD_ETHER
)
287 printf(" hardware #%d", hrd
);
290 (void)printf("[|arp]");