17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 57c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 67c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 77c478bd9Sstevel@tonic-gate * with the License. 87c478bd9Sstevel@tonic-gate * 97c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 107c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 117c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 127c478bd9Sstevel@tonic-gate * and limitations under the License. 137c478bd9Sstevel@tonic-gate * 147c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 157c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 167c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 177c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 187c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 197c478bd9Sstevel@tonic-gate * 207c478bd9Sstevel@tonic-gate * CDDL HEADER END 217c478bd9Sstevel@tonic-gate */ 227c478bd9Sstevel@tonic-gate /* 23*2e3b6467Skcpoon * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 24*2e3b6467Skcpoon * Use is subject to license terms. 257c478bd9Sstevel@tonic-gate */ 267c478bd9Sstevel@tonic-gate 277c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 287c478bd9Sstevel@tonic-gate 297c478bd9Sstevel@tonic-gate #include <stdio.h> 307c478bd9Sstevel@tonic-gate #include <sys/types.h> 317c478bd9Sstevel@tonic-gate #include <netinet/in.h> 327c478bd9Sstevel@tonic-gate #include <at.h> 337c478bd9Sstevel@tonic-gate #include <snoop.h> 347c478bd9Sstevel@tonic-gate 357c478bd9Sstevel@tonic-gate extern char *src_name, *dst_name; 367c478bd9Sstevel@tonic-gate 37*2e3b6467Skcpoon struct socktable { 387c478bd9Sstevel@tonic-gate int pt_num; 397c478bd9Sstevel@tonic-gate char *pt_short; 407c478bd9Sstevel@tonic-gate }; 417c478bd9Sstevel@tonic-gate 427c478bd9Sstevel@tonic-gate static struct socktable pt_ddp[] = { 437c478bd9Sstevel@tonic-gate {1, "RTMP"}, 447c478bd9Sstevel@tonic-gate {2, "NIS"}, 457c478bd9Sstevel@tonic-gate {4, "Echoer"}, 467c478bd9Sstevel@tonic-gate {6, "ZIS"}, 477c478bd9Sstevel@tonic-gate {0, NULL}, 487c478bd9Sstevel@tonic-gate }; 497c478bd9Sstevel@tonic-gate 507c478bd9Sstevel@tonic-gate static struct socktable pt_ddp_types[] = { 517c478bd9Sstevel@tonic-gate {1, "RTMP Resp"}, 527c478bd9Sstevel@tonic-gate {2, "NBP"}, 537c478bd9Sstevel@tonic-gate {3, "ATP"}, 547c478bd9Sstevel@tonic-gate {4, "AEP"}, 557c478bd9Sstevel@tonic-gate {5, "RTMP Req"}, 567c478bd9Sstevel@tonic-gate {6, "ZIP"}, 577c478bd9Sstevel@tonic-gate {7, "ADSP"}, 587c478bd9Sstevel@tonic-gate {0, NULL}, 597c478bd9Sstevel@tonic-gate }; 607c478bd9Sstevel@tonic-gate 617c478bd9Sstevel@tonic-gate static char * 627c478bd9Sstevel@tonic-gate apple_ddp_type(struct socktable *p, uint16_t port) 637c478bd9Sstevel@tonic-gate { 647c478bd9Sstevel@tonic-gate for (; p->pt_num != 0; p++) { 657c478bd9Sstevel@tonic-gate if (port == p->pt_num) 667c478bd9Sstevel@tonic-gate return (p->pt_short); 677c478bd9Sstevel@tonic-gate } 687c478bd9Sstevel@tonic-gate return (NULL); 697c478bd9Sstevel@tonic-gate } 707c478bd9Sstevel@tonic-gate 717c478bd9Sstevel@tonic-gate /* 727c478bd9Sstevel@tonic-gate * return the short at p, regardless of alignment 737c478bd9Sstevel@tonic-gate */ 747c478bd9Sstevel@tonic-gate 757c478bd9Sstevel@tonic-gate uint16_t 767c478bd9Sstevel@tonic-gate get_short(uint8_t *p) 777c478bd9Sstevel@tonic-gate { 787c478bd9Sstevel@tonic-gate return (p[0] << 8 | p[1]); 797c478bd9Sstevel@tonic-gate } 807c478bd9Sstevel@tonic-gate 817c478bd9Sstevel@tonic-gate /* 827c478bd9Sstevel@tonic-gate * return the long at p, regardless of alignment 837c478bd9Sstevel@tonic-gate */ 847c478bd9Sstevel@tonic-gate uint32_t 857c478bd9Sstevel@tonic-gate get_long(uint8_t *p) 867c478bd9Sstevel@tonic-gate { 877c478bd9Sstevel@tonic-gate return (p[0] << 24 | p[1] << 16 | p[2] << 8 | p[3]); 887c478bd9Sstevel@tonic-gate } 897c478bd9Sstevel@tonic-gate 907c478bd9Sstevel@tonic-gate /* 917c478bd9Sstevel@tonic-gate * format a MAC address 927c478bd9Sstevel@tonic-gate */ 937c478bd9Sstevel@tonic-gate 947c478bd9Sstevel@tonic-gate char * 957c478bd9Sstevel@tonic-gate print_macaddr(uint8_t *ha, int len) 967c478bd9Sstevel@tonic-gate { 977c478bd9Sstevel@tonic-gate static char buf[128]; 987c478bd9Sstevel@tonic-gate char *p = buf; 997c478bd9Sstevel@tonic-gate 1007c478bd9Sstevel@tonic-gate while (len-- != 0) { 1017c478bd9Sstevel@tonic-gate p += snprintf(p, sizeof (buf) - (p - buf), 1027c478bd9Sstevel@tonic-gate len > 0 ? "%x:" : "%x", *ha++); 1037c478bd9Sstevel@tonic-gate } 1047c478bd9Sstevel@tonic-gate return (buf); 1057c478bd9Sstevel@tonic-gate } 1067c478bd9Sstevel@tonic-gate 1077c478bd9Sstevel@tonic-gate /* ARGSUSED */ 1087c478bd9Sstevel@tonic-gate void 1097c478bd9Sstevel@tonic-gate interpret_at(int flags, struct ddp_hdr *ddp, int len) 1107c478bd9Sstevel@tonic-gate { 1117c478bd9Sstevel@tonic-gate int ddplen; 1127c478bd9Sstevel@tonic-gate char *pname; 1137c478bd9Sstevel@tonic-gate char buff [32]; 1147c478bd9Sstevel@tonic-gate static char src_buf[16]; 1157c478bd9Sstevel@tonic-gate static char dst_buf[16]; 1167c478bd9Sstevel@tonic-gate 1177c478bd9Sstevel@tonic-gate if (ddp_pad(ddp) != 0) 1187c478bd9Sstevel@tonic-gate return; /* unknown AppleTalk proto */ 1197c478bd9Sstevel@tonic-gate 1207c478bd9Sstevel@tonic-gate ddplen = ddp_len(ddp); 1217c478bd9Sstevel@tonic-gate 1227c478bd9Sstevel@tonic-gate (void) snprintf(src_buf, sizeof (src_buf), 1237c478bd9Sstevel@tonic-gate "%u.%u", ntohs(ddp->ddp_src_net), ddp->ddp_src_id); 1247c478bd9Sstevel@tonic-gate src_name = src_buf; 1257c478bd9Sstevel@tonic-gate 1267c478bd9Sstevel@tonic-gate (void) snprintf(dst_buf, sizeof (dst_buf), 1277c478bd9Sstevel@tonic-gate "%u.%u", ntohs(ddp->ddp_dest_net), ddp->ddp_dest_id); 1287c478bd9Sstevel@tonic-gate if (ddp->ddp_dest_id == NODE_ID_BROADCAST) 1297c478bd9Sstevel@tonic-gate dst_name = "(broadcast)"; 1307c478bd9Sstevel@tonic-gate else 1317c478bd9Sstevel@tonic-gate dst_name = dst_buf; 1327c478bd9Sstevel@tonic-gate 1337c478bd9Sstevel@tonic-gate if (flags & F_SUM) { 1347c478bd9Sstevel@tonic-gate (void) snprintf(get_sum_line(), MAXLINE, 1357c478bd9Sstevel@tonic-gate "DDP S=%u.%u:%u D=%u.%u:%u LEN=%d", 1367c478bd9Sstevel@tonic-gate ntohs(ddp->ddp_src_net), 1377c478bd9Sstevel@tonic-gate ddp->ddp_src_id, 1387c478bd9Sstevel@tonic-gate ddp->ddp_src_sock, 1397c478bd9Sstevel@tonic-gate ntohs(ddp->ddp_dest_net), 1407c478bd9Sstevel@tonic-gate ddp->ddp_dest_id, 1417c478bd9Sstevel@tonic-gate ddp->ddp_dest_sock, 1427c478bd9Sstevel@tonic-gate ddp_len(ddp)); 1437c478bd9Sstevel@tonic-gate } 1447c478bd9Sstevel@tonic-gate 1457c478bd9Sstevel@tonic-gate if (flags & F_DTAIL) { 1467c478bd9Sstevel@tonic-gate show_header("DDP: ", "DDP Header", ddplen - DDPHDR_SIZE); 1477c478bd9Sstevel@tonic-gate show_space(); 1487c478bd9Sstevel@tonic-gate pname = apple_ddp_type(pt_ddp, ddp->ddp_src_sock); 1497c478bd9Sstevel@tonic-gate if (pname == NULL) { 1507c478bd9Sstevel@tonic-gate pname = ""; 1517c478bd9Sstevel@tonic-gate } else { 1527c478bd9Sstevel@tonic-gate (void) snprintf(buff, sizeof (buff), "(%s)", pname); 1537c478bd9Sstevel@tonic-gate pname = buff; 1547c478bd9Sstevel@tonic-gate } 1557c478bd9Sstevel@tonic-gate 1567c478bd9Sstevel@tonic-gate (void) snprintf(get_line(0, 0), get_line_remain(), 1577c478bd9Sstevel@tonic-gate "Source = %s, Socket = %u %s", 1587c478bd9Sstevel@tonic-gate src_name, ddp->ddp_src_sock, pname); 1597c478bd9Sstevel@tonic-gate pname = apple_ddp_type(pt_ddp, ddp->ddp_dest_sock); 1607c478bd9Sstevel@tonic-gate if (pname == NULL) { 1617c478bd9Sstevel@tonic-gate pname = ""; 1627c478bd9Sstevel@tonic-gate } else { 1637c478bd9Sstevel@tonic-gate (void) snprintf(buff, sizeof (buff), "(%s)", pname); 1647c478bd9Sstevel@tonic-gate pname = buff; 1657c478bd9Sstevel@tonic-gate } 1667c478bd9Sstevel@tonic-gate (void) snprintf(get_line(0, 0), get_line_remain(), 1677c478bd9Sstevel@tonic-gate "Destination = %s, Socket = %u %s", 1687c478bd9Sstevel@tonic-gate dst_name, ddp->ddp_dest_sock, pname); 1697c478bd9Sstevel@tonic-gate (void) snprintf(get_line(0, 0), get_line_remain(), 1707c478bd9Sstevel@tonic-gate "Hop count = %d", 1717c478bd9Sstevel@tonic-gate ddp_hop(ddp)); 1727c478bd9Sstevel@tonic-gate (void) snprintf(get_line(0, 0), get_line_remain(), 1737c478bd9Sstevel@tonic-gate "Length = %d", 1747c478bd9Sstevel@tonic-gate ddp_len(ddp)); 1757c478bd9Sstevel@tonic-gate (void) snprintf(get_line(0, 0), get_line_remain(), 1767c478bd9Sstevel@tonic-gate "Checksum = %04x %s", 1777c478bd9Sstevel@tonic-gate ntohs(ddp->ddp_cksum), 1787c478bd9Sstevel@tonic-gate ddp->ddp_cksum == 0 ? "(no checksum)" : ""); 1797c478bd9Sstevel@tonic-gate (void) snprintf(get_line(0, 0), get_line_remain(), 1807c478bd9Sstevel@tonic-gate "DDP type = %d (%s)", 1817c478bd9Sstevel@tonic-gate ddp->ddp_type, 1827c478bd9Sstevel@tonic-gate apple_ddp_type(pt_ddp_types, ddp->ddp_type)); 1837c478bd9Sstevel@tonic-gate show_space(); 1847c478bd9Sstevel@tonic-gate } 1857c478bd9Sstevel@tonic-gate 1867c478bd9Sstevel@tonic-gate 1877c478bd9Sstevel@tonic-gate /* go to the next protocol layer */ 1887c478bd9Sstevel@tonic-gate 1897c478bd9Sstevel@tonic-gate switch (ddp->ddp_type) { 1907c478bd9Sstevel@tonic-gate case DDP_TYPE_NBP: 1917c478bd9Sstevel@tonic-gate interpret_nbp(flags, (struct nbp_hdr *)ddp, ddplen); 1927c478bd9Sstevel@tonic-gate break; 1937c478bd9Sstevel@tonic-gate case DDP_TYPE_AEP: 1947c478bd9Sstevel@tonic-gate interpret_aecho(flags, ddp, ddplen); 1957c478bd9Sstevel@tonic-gate break; 1967c478bd9Sstevel@tonic-gate case DDP_TYPE_ATP: 1977c478bd9Sstevel@tonic-gate interpret_atp(flags, ddp, ddplen); 1987c478bd9Sstevel@tonic-gate break; 1997c478bd9Sstevel@tonic-gate case DDP_TYPE_ZIP: 2007c478bd9Sstevel@tonic-gate interpret_ddp_zip(flags, (struct zip_hdr *)ddp, ddplen); 2017c478bd9Sstevel@tonic-gate break; 2027c478bd9Sstevel@tonic-gate case DDP_TYPE_ADSP: 2037c478bd9Sstevel@tonic-gate interpret_adsp(flags, (struct ddp_adsphdr *)ddp, ddplen); 2047c478bd9Sstevel@tonic-gate break; 2057c478bd9Sstevel@tonic-gate case DDP_TYPE_RTMPRQ: 2067c478bd9Sstevel@tonic-gate case DDP_TYPE_RTMPRESP: 2077c478bd9Sstevel@tonic-gate interpret_rtmp(flags, ddp, ddplen); 2087c478bd9Sstevel@tonic-gate break; 2097c478bd9Sstevel@tonic-gate } 2107c478bd9Sstevel@tonic-gate } 211