]> The Tcpdump Group git mirrors - tcpdump/blob - print-arp.c
Switch to config.h instead of passing defines in DEFS.
[tcpdump] / print-arp.c
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
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
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
22 #ifndef lint
23 static const char rcsid[] =
24 "@(#) $Header: /tcpdump/master/tcpdump/print-arp.c,v 1.44 1999-11-21 09:36:48 fenner Exp $ (LBL)";
25 #endif
26
27 #ifdef HAVE_CONFIG_H
28 #include "config.h"
29 #endif
30
31 #include <sys/param.h>
32 #include <sys/time.h>
33 #include <sys/socket.h>
34
35 #if __STDC__
36 struct mbuf;
37 struct rtentry;
38 #endif
39 #include <net/if.h>
40
41 #include <netinet/in.h>
42 #include <netinet/if_ether.h>
43
44 #ifdef HAVE_MEMORY_H
45 #include <memory.h>
46 #endif
47 #include <stdio.h>
48 #include <string.h>
49
50 #include "interface.h"
51 #include "addrtoname.h"
52 #include "ethertype.h"
53 #include "extract.h" /* must come after interface.h */
54
55 /* Compatibility */
56 #ifndef REVARP_REQUEST
57 #define REVARP_REQUEST 3
58 #endif
59 #ifndef REVARP_REPLY
60 #define REVARP_REPLY 4
61 #endif
62
63 static u_char ezero[6];
64
65 void
66 arp_print(register const u_char *bp, u_int length, u_int caplen)
67 {
68 register const struct ether_arp *ap;
69 register const struct ether_header *eh;
70 register u_short pro, hrd, op;
71
72 ap = (struct ether_arp *)bp;
73 if ((u_char *)(ap + 1) > snapend) {
74 printf("[|arp]");
75 return;
76 }
77 if (length < sizeof(struct ether_arp)) {
78 (void)printf("truncated-arp");
79 default_print((u_char *)ap, length);
80 return;
81 }
82
83 pro = EXTRACT_16BITS(&ap->arp_pro);
84 hrd = EXTRACT_16BITS(&ap->arp_hrd);
85 op = EXTRACT_16BITS(&ap->arp_op);
86
87 if ((pro != ETHERTYPE_IP && pro != ETHERTYPE_TRAIL)
88 || ap->arp_hln != sizeof(SHA(ap))
89 || ap->arp_pln != sizeof(SPA(ap))) {
90 (void)printf("arp-#%d for proto #%d (%d) hardware #%d (%d)",
91 op, pro, ap->arp_pln,
92 hrd, ap->arp_hln);
93 return;
94 }
95 if (pro == ETHERTYPE_TRAIL)
96 (void)printf("trailer-");
97 eh = (struct ether_header *)packetp;
98 switch (op) {
99
100 case ARPOP_REQUEST:
101 (void)printf("arp who-has %s", ipaddr_string(TPA(ap)));
102 if (memcmp((char *)ezero, (char *)THA(ap), 6) != 0)
103 (void)printf(" (%s)", etheraddr_string(THA(ap)));
104 (void)printf(" tell %s", ipaddr_string(SPA(ap)));
105 if (memcmp((char *)ESRC(eh), (char *)SHA(ap), 6) != 0)
106 (void)printf(" (%s)", etheraddr_string(SHA(ap)));
107 break;
108
109 case ARPOP_REPLY:
110 (void)printf("arp reply %s", ipaddr_string(SPA(ap)));
111 if (memcmp((char *)ESRC(eh), (char *)SHA(ap), 6) != 0)
112 (void)printf(" (%s)", etheraddr_string(SHA(ap)));
113 (void)printf(" is-at %s", etheraddr_string(SHA(ap)));
114 if (memcmp((char *)EDST(eh), (char *)THA(ap), 6) != 0)
115 (void)printf(" (%s)", etheraddr_string(THA(ap)));
116 break;
117
118 case REVARP_REQUEST:
119 (void)printf("rarp who-is %s tell %s",
120 etheraddr_string(THA(ap)),
121 etheraddr_string(SHA(ap)));
122 break;
123
124 case REVARP_REPLY:
125 (void)printf("rarp reply %s at %s",
126 etheraddr_string(THA(ap)),
127 ipaddr_string(TPA(ap)));
128 break;
129
130 default:
131 (void)printf("arp-#%d", op);
132 default_print((u_char *)ap, caplen);
133 return;
134 }
135 if (hrd != ARPHRD_ETHER)
136 printf(" hardware #%d", hrd);
137 }