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