1*0Sstevel@tonic-gate /* 2*0Sstevel@tonic-gate * CDDL HEADER START 3*0Sstevel@tonic-gate * 4*0Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*0Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*0Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*0Sstevel@tonic-gate * with the License. 8*0Sstevel@tonic-gate * 9*0Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*0Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*0Sstevel@tonic-gate * See the License for the specific language governing permissions 12*0Sstevel@tonic-gate * and limitations under the License. 13*0Sstevel@tonic-gate * 14*0Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*0Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*0Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*0Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*0Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*0Sstevel@tonic-gate * 20*0Sstevel@tonic-gate * CDDL HEADER END 21*0Sstevel@tonic-gate */ 22*0Sstevel@tonic-gate /* 23*0Sstevel@tonic-gate * Copyright (c) 2001 by Sun Microsystems, Inc. 24*0Sstevel@tonic-gate * All rights reserved. 25*0Sstevel@tonic-gate */ 26*0Sstevel@tonic-gate 27*0Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 28*0Sstevel@tonic-gate 29*0Sstevel@tonic-gate #include <stdio.h> 30*0Sstevel@tonic-gate #include <sys/types.h> 31*0Sstevel@tonic-gate #include <netinet/in.h> 32*0Sstevel@tonic-gate #include <at.h> 33*0Sstevel@tonic-gate #include <snoop.h> 34*0Sstevel@tonic-gate 35*0Sstevel@tonic-gate extern char *src_name, *dst_name; 36*0Sstevel@tonic-gate 37*0Sstevel@tonic-gate static struct socktable { 38*0Sstevel@tonic-gate int pt_num; 39*0Sstevel@tonic-gate char *pt_short; 40*0Sstevel@tonic-gate }; 41*0Sstevel@tonic-gate 42*0Sstevel@tonic-gate static struct socktable pt_ddp[] = { 43*0Sstevel@tonic-gate {1, "RTMP"}, 44*0Sstevel@tonic-gate {2, "NIS"}, 45*0Sstevel@tonic-gate {4, "Echoer"}, 46*0Sstevel@tonic-gate {6, "ZIS"}, 47*0Sstevel@tonic-gate {0, NULL}, 48*0Sstevel@tonic-gate }; 49*0Sstevel@tonic-gate 50*0Sstevel@tonic-gate static struct socktable pt_ddp_types[] = { 51*0Sstevel@tonic-gate {1, "RTMP Resp"}, 52*0Sstevel@tonic-gate {2, "NBP"}, 53*0Sstevel@tonic-gate {3, "ATP"}, 54*0Sstevel@tonic-gate {4, "AEP"}, 55*0Sstevel@tonic-gate {5, "RTMP Req"}, 56*0Sstevel@tonic-gate {6, "ZIP"}, 57*0Sstevel@tonic-gate {7, "ADSP"}, 58*0Sstevel@tonic-gate {0, NULL}, 59*0Sstevel@tonic-gate }; 60*0Sstevel@tonic-gate 61*0Sstevel@tonic-gate static char * 62*0Sstevel@tonic-gate apple_ddp_type(struct socktable *p, uint16_t port) 63*0Sstevel@tonic-gate { 64*0Sstevel@tonic-gate for (; p->pt_num != 0; p++) { 65*0Sstevel@tonic-gate if (port == p->pt_num) 66*0Sstevel@tonic-gate return (p->pt_short); 67*0Sstevel@tonic-gate } 68*0Sstevel@tonic-gate return (NULL); 69*0Sstevel@tonic-gate } 70*0Sstevel@tonic-gate 71*0Sstevel@tonic-gate /* 72*0Sstevel@tonic-gate * return the short at p, regardless of alignment 73*0Sstevel@tonic-gate */ 74*0Sstevel@tonic-gate 75*0Sstevel@tonic-gate uint16_t 76*0Sstevel@tonic-gate get_short(uint8_t *p) 77*0Sstevel@tonic-gate { 78*0Sstevel@tonic-gate return (p[0] << 8 | p[1]); 79*0Sstevel@tonic-gate } 80*0Sstevel@tonic-gate 81*0Sstevel@tonic-gate /* 82*0Sstevel@tonic-gate * return the long at p, regardless of alignment 83*0Sstevel@tonic-gate */ 84*0Sstevel@tonic-gate uint32_t 85*0Sstevel@tonic-gate get_long(uint8_t *p) 86*0Sstevel@tonic-gate { 87*0Sstevel@tonic-gate return (p[0] << 24 | p[1] << 16 | p[2] << 8 | p[3]); 88*0Sstevel@tonic-gate } 89*0Sstevel@tonic-gate 90*0Sstevel@tonic-gate /* 91*0Sstevel@tonic-gate * format a MAC address 92*0Sstevel@tonic-gate */ 93*0Sstevel@tonic-gate 94*0Sstevel@tonic-gate char * 95*0Sstevel@tonic-gate print_macaddr(uint8_t *ha, int len) 96*0Sstevel@tonic-gate { 97*0Sstevel@tonic-gate static char buf[128]; 98*0Sstevel@tonic-gate char *p = buf; 99*0Sstevel@tonic-gate 100*0Sstevel@tonic-gate while (len-- != 0) { 101*0Sstevel@tonic-gate p += snprintf(p, sizeof (buf) - (p - buf), 102*0Sstevel@tonic-gate len > 0 ? "%x:" : "%x", *ha++); 103*0Sstevel@tonic-gate } 104*0Sstevel@tonic-gate return (buf); 105*0Sstevel@tonic-gate } 106*0Sstevel@tonic-gate 107*0Sstevel@tonic-gate /* ARGSUSED */ 108*0Sstevel@tonic-gate void 109*0Sstevel@tonic-gate interpret_at(int flags, struct ddp_hdr *ddp, int len) 110*0Sstevel@tonic-gate { 111*0Sstevel@tonic-gate int ddplen; 112*0Sstevel@tonic-gate char *pname; 113*0Sstevel@tonic-gate char buff [32]; 114*0Sstevel@tonic-gate static char src_buf[16]; 115*0Sstevel@tonic-gate static char dst_buf[16]; 116*0Sstevel@tonic-gate 117*0Sstevel@tonic-gate if (ddp_pad(ddp) != 0) 118*0Sstevel@tonic-gate return; /* unknown AppleTalk proto */ 119*0Sstevel@tonic-gate 120*0Sstevel@tonic-gate ddplen = ddp_len(ddp); 121*0Sstevel@tonic-gate 122*0Sstevel@tonic-gate (void) snprintf(src_buf, sizeof (src_buf), 123*0Sstevel@tonic-gate "%u.%u", ntohs(ddp->ddp_src_net), ddp->ddp_src_id); 124*0Sstevel@tonic-gate src_name = src_buf; 125*0Sstevel@tonic-gate 126*0Sstevel@tonic-gate (void) snprintf(dst_buf, sizeof (dst_buf), 127*0Sstevel@tonic-gate "%u.%u", ntohs(ddp->ddp_dest_net), ddp->ddp_dest_id); 128*0Sstevel@tonic-gate if (ddp->ddp_dest_id == NODE_ID_BROADCAST) 129*0Sstevel@tonic-gate dst_name = "(broadcast)"; 130*0Sstevel@tonic-gate else 131*0Sstevel@tonic-gate dst_name = dst_buf; 132*0Sstevel@tonic-gate 133*0Sstevel@tonic-gate if (flags & F_SUM) { 134*0Sstevel@tonic-gate (void) snprintf(get_sum_line(), MAXLINE, 135*0Sstevel@tonic-gate "DDP S=%u.%u:%u D=%u.%u:%u LEN=%d", 136*0Sstevel@tonic-gate ntohs(ddp->ddp_src_net), 137*0Sstevel@tonic-gate ddp->ddp_src_id, 138*0Sstevel@tonic-gate ddp->ddp_src_sock, 139*0Sstevel@tonic-gate ntohs(ddp->ddp_dest_net), 140*0Sstevel@tonic-gate ddp->ddp_dest_id, 141*0Sstevel@tonic-gate ddp->ddp_dest_sock, 142*0Sstevel@tonic-gate ddp_len(ddp)); 143*0Sstevel@tonic-gate } 144*0Sstevel@tonic-gate 145*0Sstevel@tonic-gate if (flags & F_DTAIL) { 146*0Sstevel@tonic-gate show_header("DDP: ", "DDP Header", ddplen - DDPHDR_SIZE); 147*0Sstevel@tonic-gate show_space(); 148*0Sstevel@tonic-gate pname = apple_ddp_type(pt_ddp, ddp->ddp_src_sock); 149*0Sstevel@tonic-gate if (pname == NULL) { 150*0Sstevel@tonic-gate pname = ""; 151*0Sstevel@tonic-gate } else { 152*0Sstevel@tonic-gate (void) snprintf(buff, sizeof (buff), "(%s)", pname); 153*0Sstevel@tonic-gate pname = buff; 154*0Sstevel@tonic-gate } 155*0Sstevel@tonic-gate 156*0Sstevel@tonic-gate (void) snprintf(get_line(0, 0), get_line_remain(), 157*0Sstevel@tonic-gate "Source = %s, Socket = %u %s", 158*0Sstevel@tonic-gate src_name, ddp->ddp_src_sock, pname); 159*0Sstevel@tonic-gate pname = apple_ddp_type(pt_ddp, ddp->ddp_dest_sock); 160*0Sstevel@tonic-gate if (pname == NULL) { 161*0Sstevel@tonic-gate pname = ""; 162*0Sstevel@tonic-gate } else { 163*0Sstevel@tonic-gate (void) snprintf(buff, sizeof (buff), "(%s)", pname); 164*0Sstevel@tonic-gate pname = buff; 165*0Sstevel@tonic-gate } 166*0Sstevel@tonic-gate (void) snprintf(get_line(0, 0), get_line_remain(), 167*0Sstevel@tonic-gate "Destination = %s, Socket = %u %s", 168*0Sstevel@tonic-gate dst_name, ddp->ddp_dest_sock, pname); 169*0Sstevel@tonic-gate (void) snprintf(get_line(0, 0), get_line_remain(), 170*0Sstevel@tonic-gate "Hop count = %d", 171*0Sstevel@tonic-gate ddp_hop(ddp)); 172*0Sstevel@tonic-gate (void) snprintf(get_line(0, 0), get_line_remain(), 173*0Sstevel@tonic-gate "Length = %d", 174*0Sstevel@tonic-gate ddp_len(ddp)); 175*0Sstevel@tonic-gate (void) snprintf(get_line(0, 0), get_line_remain(), 176*0Sstevel@tonic-gate "Checksum = %04x %s", 177*0Sstevel@tonic-gate ntohs(ddp->ddp_cksum), 178*0Sstevel@tonic-gate ddp->ddp_cksum == 0 ? "(no checksum)" : ""); 179*0Sstevel@tonic-gate (void) snprintf(get_line(0, 0), get_line_remain(), 180*0Sstevel@tonic-gate "DDP type = %d (%s)", 181*0Sstevel@tonic-gate ddp->ddp_type, 182*0Sstevel@tonic-gate apple_ddp_type(pt_ddp_types, ddp->ddp_type)); 183*0Sstevel@tonic-gate show_space(); 184*0Sstevel@tonic-gate } 185*0Sstevel@tonic-gate 186*0Sstevel@tonic-gate 187*0Sstevel@tonic-gate /* go to the next protocol layer */ 188*0Sstevel@tonic-gate 189*0Sstevel@tonic-gate switch (ddp->ddp_type) { 190*0Sstevel@tonic-gate case DDP_TYPE_NBP: 191*0Sstevel@tonic-gate interpret_nbp(flags, (struct nbp_hdr *)ddp, ddplen); 192*0Sstevel@tonic-gate break; 193*0Sstevel@tonic-gate case DDP_TYPE_AEP: 194*0Sstevel@tonic-gate interpret_aecho(flags, ddp, ddplen); 195*0Sstevel@tonic-gate break; 196*0Sstevel@tonic-gate case DDP_TYPE_ATP: 197*0Sstevel@tonic-gate interpret_atp(flags, ddp, ddplen); 198*0Sstevel@tonic-gate break; 199*0Sstevel@tonic-gate case DDP_TYPE_ZIP: 200*0Sstevel@tonic-gate interpret_ddp_zip(flags, (struct zip_hdr *)ddp, ddplen); 201*0Sstevel@tonic-gate break; 202*0Sstevel@tonic-gate case DDP_TYPE_ADSP: 203*0Sstevel@tonic-gate interpret_adsp(flags, (struct ddp_adsphdr *)ddp, ddplen); 204*0Sstevel@tonic-gate break; 205*0Sstevel@tonic-gate case DDP_TYPE_RTMPRQ: 206*0Sstevel@tonic-gate case DDP_TYPE_RTMPRESP: 207*0Sstevel@tonic-gate interpret_rtmp(flags, ddp, ddplen); 208*0Sstevel@tonic-gate break; 209*0Sstevel@tonic-gate } 210*0Sstevel@tonic-gate } 211