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 #pragma ident "%Z%%M% %I% %E% SMI" 28*7c478bd9Sstevel@tonic-gate 29*7c478bd9Sstevel@tonic-gate #include <stdio.h> 30*7c478bd9Sstevel@tonic-gate #include <sys/types.h> 31*7c478bd9Sstevel@tonic-gate #include <sys/socket.h> 32*7c478bd9Sstevel@tonic-gate #include <net/if.h> 33*7c478bd9Sstevel@tonic-gate #include <net/if_arp.h> 34*7c478bd9Sstevel@tonic-gate #include <netinet/in_systm.h> 35*7c478bd9Sstevel@tonic-gate #include <netinet/in.h> 36*7c478bd9Sstevel@tonic-gate #include <netinet/if_ether.h> 37*7c478bd9Sstevel@tonic-gate 38*7c478bd9Sstevel@tonic-gate #include <at.h> 39*7c478bd9Sstevel@tonic-gate #include <snoop.h> 40*7c478bd9Sstevel@tonic-gate 41*7c478bd9Sstevel@tonic-gate static char *printat(uint8_t *); 42*7c478bd9Sstevel@tonic-gate 43*7c478bd9Sstevel@tonic-gate static char *aarp_opname[] = { 44*7c478bd9Sstevel@tonic-gate "", 45*7c478bd9Sstevel@tonic-gate "AARP Request", 46*7c478bd9Sstevel@tonic-gate "AARP Reply", 47*7c478bd9Sstevel@tonic-gate "AARP Probe", 48*7c478bd9Sstevel@tonic-gate }; 49*7c478bd9Sstevel@tonic-gate 50*7c478bd9Sstevel@tonic-gate void 51*7c478bd9Sstevel@tonic-gate interpret_aarp(int flags, char *data, int alen) 52*7c478bd9Sstevel@tonic-gate { 53*7c478bd9Sstevel@tonic-gate /* LINTED */ 54*7c478bd9Sstevel@tonic-gate struct ether_arp *ap = (struct ether_arp *)data; 55*7c478bd9Sstevel@tonic-gate 56*7c478bd9Sstevel@tonic-gate extern char *dst_name; 57*7c478bd9Sstevel@tonic-gate 58*7c478bd9Sstevel@tonic-gate if (flags & F_SUM) { 59*7c478bd9Sstevel@tonic-gate if (alen < sizeof (struct ether_arp)) { 60*7c478bd9Sstevel@tonic-gate (void) snprintf(get_sum_line(), MAXLINE, 61*7c478bd9Sstevel@tonic-gate "AARP (short packet)"); 62*7c478bd9Sstevel@tonic-gate return; 63*7c478bd9Sstevel@tonic-gate } 64*7c478bd9Sstevel@tonic-gate 65*7c478bd9Sstevel@tonic-gate switch (ntohs(ap->arp_op)) { 66*7c478bd9Sstevel@tonic-gate case AARP_REQ: 67*7c478bd9Sstevel@tonic-gate (void) snprintf(get_sum_line(), MAXLINE, 68*7c478bd9Sstevel@tonic-gate "AARP C Who is %s ?", 69*7c478bd9Sstevel@tonic-gate printat(ap->arp_tpa)); 70*7c478bd9Sstevel@tonic-gate break; 71*7c478bd9Sstevel@tonic-gate case AARP_RESP: 72*7c478bd9Sstevel@tonic-gate (void) snprintf(get_sum_line(), MAXLINE, 73*7c478bd9Sstevel@tonic-gate "AARP R %s is %s", 74*7c478bd9Sstevel@tonic-gate printat(ap->arp_spa), 75*7c478bd9Sstevel@tonic-gate printether((struct ether_addr *)&ap->arp_sha)); 76*7c478bd9Sstevel@tonic-gate dst_name = printat(ap->arp_tpa); 77*7c478bd9Sstevel@tonic-gate break; 78*7c478bd9Sstevel@tonic-gate case AARP_PROBE: 79*7c478bd9Sstevel@tonic-gate (void) snprintf(get_sum_line(), MAXLINE, 80*7c478bd9Sstevel@tonic-gate "AARP Probe %s ?", 81*7c478bd9Sstevel@tonic-gate printat(ap->arp_tpa)); 82*7c478bd9Sstevel@tonic-gate break; 83*7c478bd9Sstevel@tonic-gate } 84*7c478bd9Sstevel@tonic-gate } 85*7c478bd9Sstevel@tonic-gate 86*7c478bd9Sstevel@tonic-gate if (flags & F_DTAIL) { 87*7c478bd9Sstevel@tonic-gate show_header("AARP: ", "AARP Frame", alen); 88*7c478bd9Sstevel@tonic-gate show_space(); 89*7c478bd9Sstevel@tonic-gate 90*7c478bd9Sstevel@tonic-gate if (alen < sizeof (struct ether_arp)) { 91*7c478bd9Sstevel@tonic-gate (void) snprintf(get_line(0, 0), get_line_remain(), 92*7c478bd9Sstevel@tonic-gate "AARP (short packet)"); 93*7c478bd9Sstevel@tonic-gate return; 94*7c478bd9Sstevel@tonic-gate } 95*7c478bd9Sstevel@tonic-gate 96*7c478bd9Sstevel@tonic-gate (void) snprintf(get_line(0, 0), get_line_remain(), 97*7c478bd9Sstevel@tonic-gate "Hardware type = %d", 98*7c478bd9Sstevel@tonic-gate ntohs(ap->arp_hrd)); 99*7c478bd9Sstevel@tonic-gate (void) snprintf(get_line(0, 0), get_line_remain(), 100*7c478bd9Sstevel@tonic-gate "Protocol type = %04X (%s)", 101*7c478bd9Sstevel@tonic-gate ntohs(ap->arp_pro), 102*7c478bd9Sstevel@tonic-gate print_ethertype(ntohs(ap->arp_pro))); 103*7c478bd9Sstevel@tonic-gate (void) snprintf(get_line(0, 0), get_line_remain(), 104*7c478bd9Sstevel@tonic-gate "Length of hardware address = %d bytes", 105*7c478bd9Sstevel@tonic-gate ap->arp_hln); 106*7c478bd9Sstevel@tonic-gate (void) snprintf(get_line(0, 0), get_line_remain(), 107*7c478bd9Sstevel@tonic-gate "Length of protocol address = %d bytes", 108*7c478bd9Sstevel@tonic-gate ap->arp_pln); 109*7c478bd9Sstevel@tonic-gate (void) snprintf(get_line(0, 0), get_line_remain(), 110*7c478bd9Sstevel@tonic-gate "Opcode %d (%s)", 111*7c478bd9Sstevel@tonic-gate ntohs(ap->arp_op), 112*7c478bd9Sstevel@tonic-gate aarp_opname[ntohs(ap->arp_op)]); 113*7c478bd9Sstevel@tonic-gate 114*7c478bd9Sstevel@tonic-gate if (ntohs(ap->arp_hrd) == ARPHRD_ETHER && 115*7c478bd9Sstevel@tonic-gate ntohs(ap->arp_pro) == ETHERTYPE_AT) { 116*7c478bd9Sstevel@tonic-gate (void) snprintf(get_line(0, 0), get_line_remain(), 117*7c478bd9Sstevel@tonic-gate "Sender's hardware address = %s", 118*7c478bd9Sstevel@tonic-gate printether((struct ether_addr *)&ap->arp_sha)); 119*7c478bd9Sstevel@tonic-gate (void) snprintf(get_line(0, 0), get_line_remain(), 120*7c478bd9Sstevel@tonic-gate "Sender's protocol address = %s", 121*7c478bd9Sstevel@tonic-gate printat(ap->arp_spa)); 122*7c478bd9Sstevel@tonic-gate (void) snprintf(get_line(0, 0), get_line_remain(), 123*7c478bd9Sstevel@tonic-gate "Target hardware address = %s", 124*7c478bd9Sstevel@tonic-gate (ntohs(ap->arp_op) == AARP_REQ || 125*7c478bd9Sstevel@tonic-gate ntohs(ap->arp_op) == AARP_PROBE) ? "?" : 126*7c478bd9Sstevel@tonic-gate printether((struct ether_addr *)&ap->arp_tha)); 127*7c478bd9Sstevel@tonic-gate (void) snprintf(get_line(0, 0), get_line_remain(), 128*7c478bd9Sstevel@tonic-gate "Target protocol address = %s", 129*7c478bd9Sstevel@tonic-gate ntohs(ap->arp_op) == REVARP_REQUEST ? "?" : 130*7c478bd9Sstevel@tonic-gate printat(ap->arp_tpa)); 131*7c478bd9Sstevel@tonic-gate } 132*7c478bd9Sstevel@tonic-gate show_trailer(); 133*7c478bd9Sstevel@tonic-gate } 134*7c478bd9Sstevel@tonic-gate } 135*7c478bd9Sstevel@tonic-gate 136*7c478bd9Sstevel@tonic-gate static char * 137*7c478bd9Sstevel@tonic-gate printat(uint8_t *p) 138*7c478bd9Sstevel@tonic-gate { 139*7c478bd9Sstevel@tonic-gate static char buf[16]; 140*7c478bd9Sstevel@tonic-gate 141*7c478bd9Sstevel@tonic-gate (void) snprintf(buf, sizeof (buf), "%d.%d", get_short(&p[1]), p[3]); 142*7c478bd9Sstevel@tonic-gate return (buf); 143*7c478bd9Sstevel@tonic-gate } 144