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