Deleted Added
full compact
print-arp.c (127675) print-arp.c (146778)
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 127675 2004-03-31 14:57:24Z bms $
21 * $FreeBSD: head/contrib/tcpdump/print-arp.c 146778 2005-05-29 19:09:28Z sam $
22 */
23
24#ifndef lint
25static const char rcsid[] _U_ =
22 */
23
24#ifndef lint
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)";
26 "@(#) $Header: /tcpdump/master/tcpdump/print-arp.c,v 1.64 2004/04/30 16:42:14 mcr Exp $ (LBL)";
27#endif
28
29#ifdef HAVE_CONFIG_H
30#include "config.h"
31#endif
32
33#include <tcpdump-stdinc.h>
34
35#include <stdio.h>
36#include <string.h>
37
27#endif
28
29#ifdef HAVE_CONFIG_H
30#include "config.h"
31#endif
32
33#include <tcpdump-stdinc.h>
34
35#include <stdio.h>
36#include <string.h>
37
38#include "interface.h"
38#include "netdissect.h"
39#include "addrtoname.h"
40#include "ether.h"
41#include "ethertype.h"
42#include "extract.h" /* must come after interface.h */
43
44/*
45 * Address Resolution Protocol.
46 *

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

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
160static u_char ezero[6];
161
162static void
39#include "addrtoname.h"
40#include "ether.h"
41#include "ethertype.h"
42#include "extract.h" /* must come after interface.h */
43
44/*
45 * Address Resolution Protocol.
46 *

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

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
160static u_char ezero[6];
161
162static void
163atmarp_addr_print(const u_char *ha, u_int ha_len, const u_char *srca,
163atmarp_addr_print(netdissect_options *ndo,
164 const u_char *ha, u_int ha_len, const u_char *srca,
164 u_int srca_len)
165{
166 if (ha_len == 0)
165 u_int srca_len)
166{
167 if (ha_len == 0)
167 (void)printf("<No address>");
168 ND_PRINT((ndo, "<No address>"));
168 else {
169 else {
169 (void)printf("%s", linkaddr_string(ha, ha_len));
170 if (srca_len != 0)
171 (void)printf(",%s", linkaddr_string(srca, srca_len));
170 ND_PRINT((ndo, "%s", linkaddr_string(ha, ha_len)));
171 if (srca_len != 0)
172 ND_PRINT((ndo, ",%s",
173 linkaddr_string(srca, srca_len)));
172 }
173}
174
175static void
174 }
175}
176
177static void
176atmarp_print(const u_char *bp, u_int length, u_int caplen)
178atmarp_print(netdissect_options *ndo,
179 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;
180{
181 const struct atmarp_pkthdr *ap;
182 u_short pro, hrd, op;
183
184 ap = (const struct atmarp_pkthdr *)bp;
182 TCHECK(*ap);
185 ND_TCHECK(*ap);
183
184 hrd = ATMHRD(ap);
185 pro = ATMPRO(ap);
186 op = ATMOP(ap);
187
186
187 hrd = ATMHRD(ap);
188 pro = ATMPRO(ap);
189 op = ATMOP(ap);
190
188 if (!TTEST2(*aar_tpa(ap), ATMTPLN(ap))) {
189 (void)printf("truncated-atmarp");
190 default_print((const u_char *)ap, length);
191 if (!ND_TTEST2(*aar_tpa(ap), ATMTPLN(ap))) {
192 ND_PRINT((ndo, "truncated-atmarp"));
193 ND_DEFAULTPRINT((const u_char *)ap, length);
191 return;
192 }
193
194 if ((pro != ETHERTYPE_IP && pro != ETHERTYPE_TRAIL) ||
195 ATMSPLN(ap) != 4 || ATMTPLN(ap) != 4) {
194 return;
195 }
196
197 if ((pro != ETHERTYPE_IP && pro != ETHERTYPE_TRAIL) ||
198 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);
199 ND_PRINT((ndo, "atmarp-#%d for proto #%d (%d/%d) hardware #%d",
200 op, pro, ATMSPLN(ap), ATMTPLN(ap), hrd));
198 return;
199 }
200 if (pro == ETHERTYPE_TRAIL)
201 return;
202 }
203 if (pro == ETHERTYPE_TRAIL)
201 (void)printf("trailer-");
204 ND_PRINT((ndo, "trailer-"));
202 switch (op) {
203
204 case ARPOP_REQUEST:
205 switch (op) {
206
207 case ARPOP_REQUEST:
205 (void)printf("arp who-has %s", ipaddr_string(ATMTPA(ap)));
208 ND_PRINT((ndo, "arp who-has %s", ipaddr_string(ATMTPA(ap))));
206 if (ATMTHLN(ap) != 0) {
209 if (ATMTHLN(ap) != 0) {
207 (void)printf(" (");
208 atmarp_addr_print(ATMTHA(ap), ATMTHLN(ap),
210 ND_PRINT((ndo, " ("));
211 atmarp_addr_print(ndo, ATMTHA(ap), ATMTHLN(ap),
209 ATMTSA(ap), ATMTSLN(ap));
212 ATMTSA(ap), ATMTSLN(ap));
210 (void)printf(")");
213 ND_PRINT((ndo, ")"));
211 }
214 }
212 (void)printf(" tell %s", ipaddr_string(ATMSPA(ap)));
215 ND_PRINT((ndo, " tell %s", ipaddr_string(ATMSPA(ap))));
213 break;
214
215 case ARPOP_REPLY:
216 break;
217
218 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 ND_PRINT((ndo, "arp reply %s", ipaddr_string(ATMSPA(ap))));
220 ND_PRINT((ndo, " is-at "));
221 atmarp_addr_print(ndo, ATMSHA(ap), ATMSHLN(ap), ATMSSA(ap),
219 ATMSSLN(ap));
220 break;
221
222 case ARPOP_INVREQUEST:
222 ATMSSLN(ap));
223 break;
224
225 case ARPOP_INVREQUEST:
223 (void)printf("invarp who-is ");
224 atmarp_addr_print(ATMTHA(ap), ATMTHLN(ap), ATMTSA(ap),
226 ND_PRINT((ndo, "invarp who-is "));
227 atmarp_addr_print(ndo, ATMTHA(ap), ATMTHLN(ap), ATMTSA(ap),
225 ATMTSLN(ap));
228 ATMTSLN(ap));
226 (void)printf(" tell ");
227 atmarp_addr_print(ATMSHA(ap), ATMSHLN(ap), ATMSSA(ap),
229 ND_PRINT((ndo, " tell "));
230 atmarp_addr_print(ndo, ATMSHA(ap), ATMSHLN(ap), ATMSSA(ap),
228 ATMSSLN(ap));
229 break;
230
231 case ARPOP_INVREPLY:
231 ATMSSLN(ap));
232 break;
233
234 case ARPOP_INVREPLY:
232 (void)printf("invarp reply ");
233 atmarp_addr_print(ATMSHA(ap), ATMSHLN(ap), ATMSSA(ap),
235 ND_PRINT((ndo, "invarp reply "));
236 atmarp_addr_print(ndo, ATMSHA(ap), ATMSHLN(ap), ATMSSA(ap),
234 ATMSSLN(ap));
237 ATMSSLN(ap));
235 (void)printf(" at %s", ipaddr_string(ATMSPA(ap)));
238 ND_PRINT((ndo, " at %s", ipaddr_string(ATMSPA(ap))));
236 break;
237
238 case ATMARPOP_NAK:
239 break;
240
241 case ATMARPOP_NAK:
239 (void)printf("nak reply for %s",
240 ipaddr_string(ATMSPA(ap)));
242 ND_PRINT((ndo, "nak reply for %s",
243 ipaddr_string(ATMSPA(ap))));
241 break;
242
243 default:
244 break;
245
246 default:
244 (void)printf("atmarp-#%d", op);
245 default_print((const u_char *)ap, caplen);
247 ND_PRINT((ndo, "atmarp-#%d", op));
248 ND_DEFAULTPRINT((const u_char *)ap, caplen);
246 return;
247 }
248 return;
249trunc:
249 return;
250 }
251 return;
252trunc:
250 (void)printf("[|atmarp]");
253 ND_PRINT((ndo, "[|atmarp]"));
251}
252
253void
254}
255
256void
254arp_print(const u_char *bp, u_int length, u_int caplen)
257arp_print(netdissect_options *ndo,
258 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;
259{
260 const struct arp_pkthdr *ap;
261 u_short pro, hrd, op;
262
263 ap = (const struct arp_pkthdr *)bp;
260 TCHECK(*ap);
264 ND_TCHECK(*ap);
261 hrd = HRD(ap);
262 if (hrd == ARPHRD_ATM2225) {
265 hrd = HRD(ap);
266 if (hrd == ARPHRD_ATM2225) {
263 atmarp_print(bp, length, caplen);
267 atmarp_print(ndo, bp, length, caplen);
264 return;
265 }
266 pro = PRO(ap);
267 op = OP(ap);
268
268 return;
269 }
270 pro = PRO(ap);
271 op = OP(ap);
272
269 if (!TTEST2(*ar_tpa(ap), PLN(ap))) {
270 (void)printf("truncated-arp");
271 default_print((const u_char *)ap, length);
273 if (!ND_TTEST2(*ar_tpa(ap), PLN(ap))) {
274 ND_PRINT((ndo, "truncated-arp"));
275 ND_DEFAULTPRINT((const u_char *)ap, length);
272 return;
273 }
274
275 if ((pro != ETHERTYPE_IP && pro != ETHERTYPE_TRAIL) ||
276 PLN(ap) != 4 || HLN(ap) == 0) {
276 return;
277 }
278
279 if ((pro != ETHERTYPE_IP && pro != ETHERTYPE_TRAIL) ||
280 PLN(ap) != 4 || HLN(ap) == 0) {
277 (void)printf("arp-#%d for proto #%d (%d) hardware #%d (%d)",
278 op, pro, PLN(ap), hrd, HLN(ap));
281 ND_PRINT((ndo, "arp-#%d for proto #%d (%d) hardware #%d (%d)",
282 op, pro, PLN(ap), hrd, HLN(ap)));
279 return;
280 }
281 if (pro == ETHERTYPE_TRAIL)
283 return;
284 }
285 if (pro == ETHERTYPE_TRAIL)
282 (void)printf("trailer-");
286 ND_PRINT((ndo, "trailer-"));
283 switch (op) {
284
285 case ARPOP_REQUEST:
287 switch (op) {
288
289 case ARPOP_REQUEST:
286 (void)printf("arp who-has %s", ipaddr_string(TPA(ap)));
290 ND_PRINT((ndo, "arp who-has %s", ipaddr_string(TPA(ap))));
287 if (memcmp((const char *)ezero, (const char *)THA(ap), HLN(ap)) != 0)
291 if (memcmp((const char *)ezero, (const char *)THA(ap), HLN(ap)) != 0)
288 (void)printf(" (%s)",
289 linkaddr_string(THA(ap), HLN(ap)));
290 (void)printf(" tell %s", ipaddr_string(SPA(ap)));
292 ND_PRINT((ndo, " (%s)",
293 linkaddr_string(THA(ap), HLN(ap))));
294 ND_PRINT((ndo, " tell %s", ipaddr_string(SPA(ap))));
291 break;
292
293 case ARPOP_REPLY:
295 break;
296
297 case ARPOP_REPLY:
294 (void)printf("arp reply %s", ipaddr_string(SPA(ap)));
295 (void)printf(" is-at %s", linkaddr_string(SHA(ap), HLN(ap)));
298 ND_PRINT((ndo, "arp reply %s", ipaddr_string(SPA(ap))));
299 ND_PRINT((ndo, " is-at %s", linkaddr_string(SHA(ap), HLN(ap))));
296 break;
297
298 case ARPOP_REVREQUEST:
300 break;
301
302 case ARPOP_REVREQUEST:
299 (void)printf("rarp who-is %s tell %s",
300 linkaddr_string(THA(ap), HLN(ap)),
301 linkaddr_string(SHA(ap), HLN(ap)));
303 ND_PRINT((ndo, "rarp who-is %s tell %s",
304 linkaddr_string(THA(ap), HLN(ap)),
305 linkaddr_string(SHA(ap), HLN(ap))));
302 break;
303
304 case ARPOP_REVREPLY:
306 break;
307
308 case ARPOP_REVREPLY:
305 (void)printf("rarp reply %s at %s",
306 linkaddr_string(THA(ap), HLN(ap)),
307 ipaddr_string(TPA(ap)));
309 ND_PRINT((ndo, "rarp reply %s at %s",
310 linkaddr_string(THA(ap), HLN(ap)),
311 ipaddr_string(TPA(ap))));
308 break;
309
310 case ARPOP_INVREQUEST:
312 break;
313
314 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)));
315 ND_PRINT((ndo, "invarp who-is %s tell %s",
316 linkaddr_string(THA(ap), HLN(ap)),
317 linkaddr_string(SHA(ap), HLN(ap))));
314 break;
315
316 case ARPOP_INVREPLY:
318 break;
319
320 case ARPOP_INVREPLY:
317 (void)printf("invarp reply %s at %s",
318 linkaddr_string(THA(ap), HLN(ap)),
319 ipaddr_string(TPA(ap)));
321 ND_PRINT((ndo,"invarp reply %s at %s",
322 linkaddr_string(THA(ap), HLN(ap)),
323 ipaddr_string(TPA(ap))));
320 break;
321
322 default:
324 break;
325
326 default:
323 (void)printf("arp-#%d", op);
324 default_print((const u_char *)ap, caplen);
327 ND_PRINT((ndo, "arp-#%d", op));
328 ND_DEFAULTPRINT((const u_char *)ap, caplen);
325 return;
326 }
327 if (hrd != ARPHRD_ETHER)
329 return;
330 }
331 if (hrd != ARPHRD_ETHER)
328 printf(" hardware #%d", hrd);
332 ND_PRINT((ndo, " hardware #%d", hrd));
329 return;
330trunc:
333 return;
334trunc:
331 (void)printf("[|arp]");
335 ND_PRINT((ndo, "[|arp]"));
332}
336}
337
338/*
339 * Local Variables:
340 * c-style: bsd
341 * End:
342 */
343