Deleted Added
full compact
print-arp.c (111729) print-arp.c (127675)
1/*
2 * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997
3 * The Regents of the University of California. All rights reserved.
4 *
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

--- 4 unchanged lines hidden (view full) ---

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
16 * written permission.
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.
20 *
1/*
2 * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997
3 * The Regents of the University of California. All rights reserved.
4 *
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

--- 4 unchanged lines hidden (view full) ---

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
16 * written permission.
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.
20 *
21 * $FreeBSD: head/contrib/tcpdump/print-arp.c 111729 2003-03-02 08:25:48Z fenner $
21 * $FreeBSD: head/contrib/tcpdump/print-arp.c 127675 2004-03-31 14:57:24Z bms $
22 */
23
24#ifndef lint
22 */
23
24#ifndef lint
25static const char rcsid[] =
26 "@(#) $Header: /tcpdump/master/tcpdump/print-arp.c,v 1.51.4.2 2002/07/10 07:09:53 guy Exp $ (LBL)";
25static const char rcsid[] _U_ =
26 "@(#) $Header: /tcpdump/master/tcpdump/print-arp.c,v 1.61.2.2 2003/11/16 08:51:10 guy Exp $ (LBL)";
27#endif
28
29#ifdef HAVE_CONFIG_H
30#include "config.h"
31#endif
32
27#endif
28
29#ifdef HAVE_CONFIG_H
30#include "config.h"
31#endif
32
33#include <sys/param.h>
34#include <sys/time.h>
33#include <tcpdump-stdinc.h>
35
34
36#include <netinet/in.h>
37
38#include <stdio.h>
39#include <string.h>
40
41#include "interface.h"
42#include "addrtoname.h"
43#include "ether.h"
44#include "ethertype.h"
45#include "extract.h" /* must come after interface.h */

--- 39 unchanged lines hidden (view full) ---

85#define ar_sha(ap) (((const u_char *)((ap)+1))+0)
86#define ar_spa(ap) (((const u_char *)((ap)+1))+ (ap)->ar_hln)
87#define ar_tha(ap) (((const u_char *)((ap)+1))+ (ap)->ar_hln+(ap)->ar_pln)
88#define ar_tpa(ap) (((const u_char *)((ap)+1))+2*(ap)->ar_hln+(ap)->ar_pln)
89};
90
91#define ARP_HDRLEN 8
92
35#include <stdio.h>
36#include <string.h>
37
38#include "interface.h"
39#include "addrtoname.h"
40#include "ether.h"
41#include "ethertype.h"
42#include "extract.h" /* must come after interface.h */

--- 39 unchanged lines hidden (view full) ---

82#define ar_sha(ap) (((const u_char *)((ap)+1))+0)
83#define ar_spa(ap) (((const u_char *)((ap)+1))+ (ap)->ar_hln)
84#define ar_tha(ap) (((const u_char *)((ap)+1))+ (ap)->ar_hln+(ap)->ar_pln)
85#define ar_tpa(ap) (((const u_char *)((ap)+1))+2*(ap)->ar_hln+(ap)->ar_pln)
86};
87
88#define ARP_HDRLEN 8
89
93#define HRD(ap) ((ap)->ar_hrd)
90#define HRD(ap) EXTRACT_16BITS(&(ap)->ar_hrd)
94#define HLN(ap) ((ap)->ar_hln)
95#define PLN(ap) ((ap)->ar_pln)
91#define HLN(ap) ((ap)->ar_hln)
92#define PLN(ap) ((ap)->ar_pln)
96#define OP(ap) ((ap)->ar_op)
97#define PRO(ap) ((ap)->ar_pro)
93#define OP(ap) EXTRACT_16BITS(&(ap)->ar_op)
94#define PRO(ap) EXTRACT_16BITS(&(ap)->ar_pro)
98#define SHA(ap) (ar_sha(ap))
99#define SPA(ap) (ar_spa(ap))
100#define THA(ap) (ar_tha(ap))
101#define TPA(ap) (ar_tpa(ap))
102
95#define SHA(ap) (ar_sha(ap))
96#define SPA(ap) (ar_spa(ap))
97#define THA(ap) (ar_tha(ap))
98#define TPA(ap) (ar_tpa(ap))
99
100/*
101 * ATM Address Resolution Protocol.
102 *
103 * See RFC 2225 for protocol description. ATMARP packets are similar
104 * to ARP packets, except that there are no length fields for the
105 * protocol address - instead, there are type/length fields for
106 * the ATM number and subaddress - and the hardware addresses consist
107 * of an ATM number and an ATM subaddress.
108 */
109struct atmarp_pkthdr {
110 u_short aar_hrd; /* format of hardware address */
111#define ARPHRD_ATM2225 19 /* ATM (RFC 2225) */
112 u_short aar_pro; /* format of protocol address */
113 u_char aar_shtl; /* length of source ATM number */
114 u_char aar_sstl; /* length of source ATM subaddress */
115#define ATMARP_IS_E164 0x40 /* bit in type/length for E.164 format */
116#define ATMARP_LEN_MASK 0x3F /* length of {sub}address in type/length */
117 u_short aar_op; /* same as regular ARP */
118#define ATMARPOP_NAK 10 /* NAK */
119 u_char aar_spln; /* length of source protocol address */
120 u_char aar_thtl; /* length of target ATM number */
121 u_char aar_tstl; /* length of target ATM subaddress */
122 u_char aar_tpln; /* length of target protocol address */
123/*
124 * The remaining fields are variable in size,
125 * according to the sizes above.
126 */
127#ifdef COMMENT_ONLY
128 u_char aar_sha[]; /* source ATM number */
129 u_char aar_ssa[]; /* source ATM subaddress */
130 u_char aar_spa[]; /* sender protocol address */
131 u_char aar_tha[]; /* target ATM number */
132 u_char aar_tsa[]; /* target ATM subaddress */
133 u_char aar_tpa[]; /* target protocol address */
134#endif
135
136#define ATMHRD(ap) EXTRACT_16BITS(&(ap)->aar_hrd)
137#define ATMSHLN(ap) ((ap)->aar_shtl & ATMARP_LEN_MASK)
138#define ATMSSLN(ap) ((ap)->aar_sstl & ATMARP_LEN_MASK)
139#define ATMSPLN(ap) ((ap)->aar_spln)
140#define ATMOP(ap) EXTRACT_16BITS(&(ap)->aar_op)
141#define ATMPRO(ap) EXTRACT_16BITS(&(ap)->aar_pro)
142#define ATMTHLN(ap) ((ap)->aar_thtl & ATMARP_LEN_MASK)
143#define ATMTSLN(ap) ((ap)->aar_tstl & ATMARP_LEN_MASK)
144#define ATMTPLN(ap) ((ap)->aar_tpln)
145#define aar_sha(ap) ((const u_char *)((ap)+1))
146#define aar_ssa(ap) (aar_sha(ap) + ATMSHLN(ap))
147#define aar_spa(ap) (aar_ssa(ap) + ATMSSLN(ap))
148#define aar_tha(ap) (aar_spa(ap) + ATMSPLN(ap))
149#define aar_tsa(ap) (aar_tha(ap) + ATMTHLN(ap))
150#define aar_tpa(ap) (aar_tsa(ap) + ATMTSLN(ap))
151};
152
153#define ATMSHA(ap) (aar_sha(ap))
154#define ATMSSA(ap) (aar_ssa(ap))
155#define ATMSPA(ap) (aar_spa(ap))
156#define ATMTHA(ap) (aar_tha(ap))
157#define ATMTSA(ap) (aar_tsa(ap))
158#define ATMTPA(ap) (aar_tpa(ap))
159
103static u_char ezero[6];
104
160static u_char ezero[6];
161
162static void
163atmarp_addr_print(const u_char *ha, u_int ha_len, const u_char *srca,
164 u_int srca_len)
165{
166 if (ha_len == 0)
167 (void)printf("<No address>");
168 else {
169 (void)printf("%s", linkaddr_string(ha, ha_len));
170 if (srca_len != 0)
171 (void)printf(",%s", linkaddr_string(srca, srca_len));
172 }
173}
174
175static void
176atmarp_print(const u_char *bp, u_int length, u_int caplen)
177{
178 const struct atmarp_pkthdr *ap;
179 u_short pro, hrd, op;
180
181 ap = (const struct atmarp_pkthdr *)bp;
182 TCHECK(*ap);
183
184 hrd = ATMHRD(ap);
185 pro = ATMPRO(ap);
186 op = ATMOP(ap);
187
188 if (!TTEST2(*aar_tpa(ap), ATMTPLN(ap))) {
189 (void)printf("truncated-atmarp");
190 default_print((const u_char *)ap, length);
191 return;
192 }
193
194 if ((pro != ETHERTYPE_IP && pro != ETHERTYPE_TRAIL) ||
195 ATMSPLN(ap) != 4 || ATMTPLN(ap) != 4) {
196 (void)printf("atmarp-#%d for proto #%d (%d/%d) hardware #%d",
197 op, pro, ATMSPLN(ap), ATMTPLN(ap), hrd);
198 return;
199 }
200 if (pro == ETHERTYPE_TRAIL)
201 (void)printf("trailer-");
202 switch (op) {
203
204 case ARPOP_REQUEST:
205 (void)printf("arp who-has %s", ipaddr_string(ATMTPA(ap)));
206 if (ATMTHLN(ap) != 0) {
207 (void)printf(" (");
208 atmarp_addr_print(ATMTHA(ap), ATMTHLN(ap),
209 ATMTSA(ap), ATMTSLN(ap));
210 (void)printf(")");
211 }
212 (void)printf(" tell %s", ipaddr_string(ATMSPA(ap)));
213 break;
214
215 case ARPOP_REPLY:
216 (void)printf("arp reply %s", ipaddr_string(ATMSPA(ap)));
217 (void)printf(" is-at ");
218 atmarp_addr_print(ATMSHA(ap), ATMSHLN(ap), ATMSSA(ap),
219 ATMSSLN(ap));
220 break;
221
222 case ARPOP_INVREQUEST:
223 (void)printf("invarp who-is ");
224 atmarp_addr_print(ATMTHA(ap), ATMTHLN(ap), ATMTSA(ap),
225 ATMTSLN(ap));
226 (void)printf(" tell ");
227 atmarp_addr_print(ATMSHA(ap), ATMSHLN(ap), ATMSSA(ap),
228 ATMSSLN(ap));
229 break;
230
231 case ARPOP_INVREPLY:
232 (void)printf("invarp reply ");
233 atmarp_addr_print(ATMSHA(ap), ATMSHLN(ap), ATMSSA(ap),
234 ATMSSLN(ap));
235 (void)printf(" at %s", ipaddr_string(ATMSPA(ap)));
236 break;
237
238 case ATMARPOP_NAK:
239 (void)printf("nak reply for %s",
240 ipaddr_string(ATMSPA(ap)));
241 break;
242
243 default:
244 (void)printf("atmarp-#%d", op);
245 default_print((const u_char *)ap, caplen);
246 return;
247 }
248 return;
249trunc:
250 (void)printf("[|atmarp]");
251}
252
105void
106arp_print(const u_char *bp, u_int length, u_int caplen)
107{
108 const struct arp_pkthdr *ap;
109 u_short pro, hrd, op;
110
111 ap = (const struct arp_pkthdr *)bp;
112 TCHECK(*ap);
253void
254arp_print(const u_char *bp, u_int length, u_int caplen)
255{
256 const struct arp_pkthdr *ap;
257 u_short pro, hrd, op;
258
259 ap = (const struct arp_pkthdr *)bp;
260 TCHECK(*ap);
113 if ((const u_char *)(ar_tpa(ap) + PLN(ap)) > snapend) {
261 hrd = HRD(ap);
262 if (hrd == ARPHRD_ATM2225) {
263 atmarp_print(bp, length, caplen);
264 return;
265 }
266 pro = PRO(ap);
267 op = OP(ap);
268
269 if (!TTEST2(*ar_tpa(ap), PLN(ap))) {
114 (void)printf("truncated-arp");
115 default_print((const u_char *)ap, length);
116 return;
117 }
118
270 (void)printf("truncated-arp");
271 default_print((const u_char *)ap, length);
272 return;
273 }
274
119 pro = EXTRACT_16BITS(&PRO(ap));
120 hrd = EXTRACT_16BITS(&HRD(ap));
121 op = EXTRACT_16BITS(&OP(ap));
122
123 if (pro != ETHERTYPE_IP && pro != ETHERTYPE_TRAIL) {
275 if ((pro != ETHERTYPE_IP && pro != ETHERTYPE_TRAIL) ||
276 PLN(ap) != 4 || HLN(ap) == 0) {
124 (void)printf("arp-#%d for proto #%d (%d) hardware #%d (%d)",
125 op, pro, PLN(ap), hrd, HLN(ap));
126 return;
127 }
128 if (pro == ETHERTYPE_TRAIL)
129 (void)printf("trailer-");
130 switch (op) {
131

--- 17 unchanged lines hidden (view full) ---

149 break;
150
151 case ARPOP_REVREPLY:
152 (void)printf("rarp reply %s at %s",
153 linkaddr_string(THA(ap), HLN(ap)),
154 ipaddr_string(TPA(ap)));
155 break;
156
277 (void)printf("arp-#%d for proto #%d (%d) hardware #%d (%d)",
278 op, pro, PLN(ap), hrd, HLN(ap));
279 return;
280 }
281 if (pro == ETHERTYPE_TRAIL)
282 (void)printf("trailer-");
283 switch (op) {
284

--- 17 unchanged lines hidden (view full) ---

302 break;
303
304 case ARPOP_REVREPLY:
305 (void)printf("rarp reply %s at %s",
306 linkaddr_string(THA(ap), HLN(ap)),
307 ipaddr_string(TPA(ap)));
308 break;
309
310 case ARPOP_INVREQUEST:
311 (void)printf("invarp who-is %s tell %s",
312 linkaddr_string(THA(ap), HLN(ap)),
313 linkaddr_string(SHA(ap), HLN(ap)));
314 break;
315
316 case ARPOP_INVREPLY:
317 (void)printf("invarp reply %s at %s",
318 linkaddr_string(THA(ap), HLN(ap)),
319 ipaddr_string(TPA(ap)));
320 break;
321
157 default:
158 (void)printf("arp-#%d", op);
159 default_print((const u_char *)ap, caplen);
160 return;
161 }
162 if (hrd != ARPHRD_ETHER)
163 printf(" hardware #%d", hrd);
164 return;
165trunc:
166 (void)printf("[|arp]");
167}
322 default:
323 (void)printf("arp-#%d", op);
324 default_print((const u_char *)ap, caplen);
325 return;
326 }
327 if (hrd != ARPHRD_ETHER)
328 printf(" hardware #%d", hrd);
329 return;
330trunc:
331 (void)printf("[|arp]");
332}