1 /*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
7 * with the License.
8 *
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
13 *
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
19 *
20 * CDDL HEADER END
21 */
22 /*
23 * Copyright (c) 1991-2001 by Sun Microsystems, Inc.
24 * All rights reserved.
25 */
26
27 #include <stdio.h>
28 #include <sys/types.h>
29 #include <sys/socket.h>
30 #include <net/if.h>
31 #include <net/if_arp.h>
32 #include <netinet/in_systm.h>
33 #include <netinet/in.h>
34 #include <netinet/if_ether.h>
35
36 #include <at.h>
37 #include <snoop.h>
38
39 static char *printat(uint8_t *);
40
41 static char *aarp_opname[] = {
42 "",
43 "AARP Request",
44 "AARP Reply",
45 "AARP Probe",
46 };
47
48 void
interpret_aarp(int flags,char * data,int alen)49 interpret_aarp(int flags, char *data, int alen)
50 {
51 /* LINTED */
52 struct ether_arp *ap = (struct ether_arp *)data;
53
54 extern char *dst_name;
55
56 if (flags & F_SUM) {
57 if (alen < sizeof (struct ether_arp)) {
58 (void) snprintf(get_sum_line(), MAXLINE,
59 "AARP (short packet)");
60 return;
61 }
62
63 switch (ntohs(ap->arp_op)) {
64 case AARP_REQ:
65 (void) snprintf(get_sum_line(), MAXLINE,
66 "AARP C Who is %s ?",
67 printat(ap->arp_tpa));
68 break;
69 case AARP_RESP:
70 (void) snprintf(get_sum_line(), MAXLINE,
71 "AARP R %s is %s",
72 printat(ap->arp_spa),
73 printether((struct ether_addr *)&ap->arp_sha));
74 dst_name = printat(ap->arp_tpa);
75 break;
76 case AARP_PROBE:
77 (void) snprintf(get_sum_line(), MAXLINE,
78 "AARP Probe %s ?",
79 printat(ap->arp_tpa));
80 break;
81 }
82 }
83
84 if (flags & F_DTAIL) {
85 show_header("AARP: ", "AARP Frame", alen);
86 show_space();
87
88 if (alen < sizeof (struct ether_arp)) {
89 (void) snprintf(get_line(0, 0), get_line_remain(),
90 "AARP (short packet)");
91 return;
92 }
93
94 (void) snprintf(get_line(0, 0), get_line_remain(),
95 "Hardware type = %d",
96 ntohs(ap->arp_hrd));
97 (void) snprintf(get_line(0, 0), get_line_remain(),
98 "Protocol type = %04X (%s)",
99 ntohs(ap->arp_pro),
100 print_ethertype(ntohs(ap->arp_pro)));
101 (void) snprintf(get_line(0, 0), get_line_remain(),
102 "Length of hardware address = %d bytes",
103 ap->arp_hln);
104 (void) snprintf(get_line(0, 0), get_line_remain(),
105 "Length of protocol address = %d bytes",
106 ap->arp_pln);
107 (void) snprintf(get_line(0, 0), get_line_remain(),
108 "Opcode %d (%s)",
109 ntohs(ap->arp_op),
110 aarp_opname[ntohs(ap->arp_op)]);
111
112 if (ntohs(ap->arp_hrd) == ARPHRD_ETHER &&
113 ntohs(ap->arp_pro) == ETHERTYPE_AT) {
114 (void) snprintf(get_line(0, 0), get_line_remain(),
115 "Sender's hardware address = %s",
116 printether((struct ether_addr *)&ap->arp_sha));
117 (void) snprintf(get_line(0, 0), get_line_remain(),
118 "Sender's protocol address = %s",
119 printat(ap->arp_spa));
120 (void) snprintf(get_line(0, 0), get_line_remain(),
121 "Target hardware address = %s",
122 (ntohs(ap->arp_op) == AARP_REQ ||
123 ntohs(ap->arp_op) == AARP_PROBE) ? "?" :
124 printether((struct ether_addr *)&ap->arp_tha));
125 (void) snprintf(get_line(0, 0), get_line_remain(),
126 "Target protocol address = %s",
127 ntohs(ap->arp_op) == REVARP_REQUEST ? "?" :
128 printat(ap->arp_tpa));
129 }
130 show_trailer();
131 }
132 }
133
134 static char *
printat(uint8_t * p)135 printat(uint8_t *p)
136 {
137 static char buf[16];
138
139 (void) snprintf(buf, sizeof (buf), "%d.%d", get_short(&p[1]), p[3]);
140 return (buf);
141 }
142