Print this page
4587 snoop misdecodes DHCPv6 DHCPV6_DUID_LL identifiers
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/cmd/cmd-inet/usr.sbin/snoop/snoop_arp.c
+++ new/usr/src/cmd/cmd-inet/usr.sbin/snoop/snoop_arp.c
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
↓ open down ↓ |
15 lines elided |
↑ open up ↑ |
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21 /*
22 22 * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
23 23 * Use is subject to license terms.
24 24 */
25 25
26 -#pragma ident "%Z%%M% %I% %E% SMI"
27 -
28 26 #include <sys/types.h>
29 27 #include <sys/errno.h>
30 28 #include <setjmp.h>
29 +#include <stdio.h>
30 +#include <stdlib.h>
31 +#include <string.h>
31 32 #include <sys/socket.h>
32 33 #include <net/if.h>
33 34 #include <net/if_arp.h>
34 35 #include <netinet/in_systm.h>
35 36 #include <netinet/in.h>
36 37 #include <netinet/ip.h>
37 38 #include <netinet/if_ether.h>
38 39 #include <netdb.h>
39 40 #include <net/if_types.h>
41 +#include <arpa/inet.h>
40 42
41 43 #include "snoop.h"
42 44
43 45 extern char *dlc_header;
44 46 extern jmp_buf xdr_err;
45 47
46 48 static char *printip(unsigned char *);
47 49 static char *addrtoname_align(unsigned char *);
48 50
49 51 static char unarp_addr[] = "Unknown";
50 52 char *opname[] = {
51 53 "",
52 54 "ARP Request",
53 55 "ARP Reply",
54 56 "REVARP Request",
55 57 "REVARP Reply",
56 58 };
57 59
58 60 void
59 61 interpret_arp(int flags, struct arphdr *ap, int alen)
60 62 {
61 63 char *line;
62 64 extern char *src_name, *dst_name;
63 65 unsigned char *sip, *tip, *sha, *tha;
64 66 char *smacbuf = NULL, *dmacbuf = NULL;
65 67 int maclen;
66 68 ushort_t arpop;
67 69 boolean_t is_ip = B_FALSE;
68 70
69 71 /*
70 72 * Check that at least the generic ARP header was received.
71 73 */
72 74 if (sizeof (struct arphdr) > alen)
73 75 goto short_packet;
74 76
75 77 arpop = ntohs(ap->ar_op);
76 78 maclen = ap->ar_hln;
77 79 if (ntohs(ap->ar_pro) == ETHERTYPE_IP)
78 80 is_ip = B_TRUE;
79 81
80 82 sha = (unsigned char *)(ap + 1);
81 83 sip = sha + maclen;
82 84 tha = sip + ap->ar_pln;
83 85 tip = tha + maclen;
84 86
85 87 /*
86 88 * Check that the protocol/hardware addresses were received.
87 89 */
88 90 if ((tip + ap->ar_pln) > ((unsigned char *)ap + alen))
89 91 goto short_packet;
90 92
91 93 if (maclen == 0) {
92 94 smacbuf = dmacbuf = unarp_addr;
93 95 } else {
94 96 if (((flags & F_DTAIL) && is_ip) || (arpop == ARPOP_REPLY)) {
95 97 smacbuf = _link_ntoa(sha, NULL, maclen, IFT_OTHER);
96 98 if (smacbuf == NULL)
97 99 pr_err("Warning: malloc failure");
98 100 }
99 101
100 102 if (((flags & F_DTAIL) && is_ip) || (arpop ==
101 103 REVARP_REQUEST) || (arpop == REVARP_REPLY)) {
102 104 dmacbuf = _link_ntoa(tha, NULL, maclen, IFT_OTHER);
103 105 if (dmacbuf == NULL)
104 106 pr_err("Warning: malloc failure");
105 107 }
106 108 }
107 109
108 110 src_name = addrtoname_align(sip);
109 111
110 112 if (flags & F_SUM) {
111 113
112 114 line = get_sum_line();
113 115
114 116 switch (arpop) {
115 117 case ARPOP_REQUEST:
116 118 (void) snprintf(line, MAXLINE, "ARP C Who is %s ?",
117 119 printip(tip));
118 120 break;
119 121 case ARPOP_REPLY:
120 122 (void) snprintf(line, MAXLINE, "ARP R %s is %s",
121 123 printip(sip), smacbuf);
122 124 dst_name = addrtoname_align(tip);
123 125 break;
124 126 case REVARP_REQUEST:
125 127 (void) snprintf(line, MAXLINE, "RARP C Who is %s ?",
126 128 dmacbuf);
127 129 break;
128 130 case REVARP_REPLY:
129 131 (void) snprintf(line, MAXLINE, "RARP R %s is %s",
130 132 dmacbuf, printip(tip));
131 133 dst_name = addrtoname_align(tip);
132 134 break;
133 135 }
134 136 }
135 137
136 138 if (flags & F_DTAIL) {
137 139 show_header("ARP: ", "ARP/RARP Frame", alen);
138 140 show_space();
139 141 (void) snprintf(get_line(0, 0), get_line_remain(),
140 142 "Hardware type = %d (%s)", ntohs(ap->ar_hrd),
141 143 arp_htype(ntohs(ap->ar_hrd)));
142 144 (void) snprintf(get_line(0, 0), get_line_remain(),
143 145 "Protocol type = %04x (%s)", ntohs(ap->ar_pro),
144 146 print_ethertype(ntohs(ap->ar_pro)));
145 147 (void) snprintf(get_line(0, 0), get_line_remain(),
146 148 "Length of hardware address = %d bytes", ap->ar_hln);
147 149 (void) snprintf(get_line(0, 0), get_line_remain(),
148 150 "Length of protocol address = %d bytes", ap->ar_pln);
149 151 (void) snprintf(get_line(0, 0), get_line_remain(),
150 152 "Opcode %d (%s)", arpop,
151 153 (arpop > REVARP_REPLY) ? opname[0] : opname[arpop]);
152 154
153 155 if (is_ip) {
154 156 (void) snprintf(get_line(0, 0), get_line_remain(),
155 157 "Sender's hardware address = %s", smacbuf);
156 158 (void) snprintf(get_line(0, 0), get_line_remain(),
157 159 "Sender's protocol address = %s",
158 160 printip(sip));
159 161 (void) snprintf(get_line(0, 0), get_line_remain(),
160 162 "Target hardware address = %s",
161 163 arpop == ARPOP_REQUEST ? "?" : dmacbuf);
162 164 (void) snprintf(get_line(0, 0), get_line_remain(),
163 165 "Target protocol address = %s",
164 166 arpop == REVARP_REQUEST ? "?" :
165 167 printip(tip));
166 168 }
167 169 show_trailer();
168 170 }
169 171
170 172 if (maclen != 0) {
171 173 free(smacbuf);
172 174 free(dmacbuf);
173 175 }
174 176 return;
175 177
176 178 short_packet:
177 179 if (flags & F_SUM) {
178 180 (void) snprintf(get_sum_line(), MAXLINE,
179 181 "ARP (short packet)");
180 182 } else if (flags & F_DTAIL) {
181 183 show_header("ARP: ", "ARP/RARP Frame", alen);
182 184 show_space();
183 185 (void) snprintf(get_line(0, 0), get_line_remain(),
184 186 "ARP (short packet)");
185 187 }
186 188 }
187 189
188 190 char *
189 191 printip(unsigned char *p)
190 192 {
191 193 static char buff[MAXHOSTNAMELEN + 32];
192 194 char *ap, *np;
193 195 struct in_addr a;
194 196
195 197 memcpy(&a, p, 4);
196 198 ap = (char *)inet_ntoa(a);
197 199 np = (char *)addrtoname(AF_INET, &a);
198 200 (void) snprintf(buff, MAXHOSTNAMELEN, "%s, %s", ap, np);
199 201 return (buff);
200 202 }
201 203
202 204 char *
203 205 addrtoname_align(unsigned char *p)
204 206 {
205 207 struct in_addr a;
206 208
207 209 memcpy(&a, p, 4);
208 210 return ((char *)addrtoname(AF_INET, &a));
209 211 }
210 212
211 213 /*
↓ open down ↓ |
162 lines elided |
↑ open up ↑ |
212 214 * These numbers are assigned by the IANA. See the arp-parameters registry.
213 215 * Only those values that are used within Solaris have #defines.
214 216 */
215 217 const char *
216 218 arp_htype(int t)
217 219 {
218 220 switch (t) {
219 221 case ARPHRD_ETHER:
220 222 return ("Ethernet (10Mb)");
221 223 case 2:
222 - return ("Experimental Ethernet (3MB)");
224 + return ("Experimental Ethernet (3Mb)");
223 225 case 3:
224 226 return ("Amateur Radio AX.25");
225 227 case 4:
226 228 return ("Proteon ProNET Token Ring");
227 229 case 5:
228 230 return ("Chaos");
229 231 case ARPHRD_IEEE802:
230 232 return ("IEEE 802");
231 233 case 7:
232 234 return ("ARCNET");
233 235 case 8:
234 236 return ("Hyperchannel");
235 237 case 9:
236 238 return ("Lanstar");
237 239 case 10:
238 240 return ("Autonet");
239 241 case 11:
240 242 return ("LocalTalk");
241 243 case 12:
242 244 return ("LocalNet");
243 245 case 13:
244 246 return ("Ultra Link");
245 247 case 14:
246 248 return ("SMDS");
↓ open down ↓ |
14 lines elided |
↑ open up ↑ |
247 249 case ARPHRD_FRAME:
248 250 return ("Frame Relay");
249 251 case ARPHRD_ATM:
250 252 return ("ATM");
251 253 case ARPHRD_HDLC:
252 254 return ("HDLC");
253 255 case ARPHRD_FC:
254 256 return ("Fibre Channel");
255 257 case ARPHRD_IPATM:
256 258 return ("IP-ATM");
259 + case ARPHRD_METRICOM:
260 + return ("Metricom");
257 261 case ARPHRD_TUNNEL:
258 262 return ("Tunnel");
259 263 case ARPHRD_IB:
260 264 return ("IPIB");
261 265 };
262 266 return ("UNKNOWN");
263 267 }
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX