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 538c589b6Skcpoon * Common Development and Distribution License (the "License"). 638c589b6Skcpoon * You may not use this file except in compliance with the License. 77c478bd9Sstevel@tonic-gate * 87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 117c478bd9Sstevel@tonic-gate * and limitations under the License. 127c478bd9Sstevel@tonic-gate * 137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 187c478bd9Sstevel@tonic-gate * 197c478bd9Sstevel@tonic-gate * CDDL HEADER END 207c478bd9Sstevel@tonic-gate */ 2138c589b6Skcpoon 227c478bd9Sstevel@tonic-gate /* 23*20f2cb7bSVasumathi Sundaram - Sun Microsystems * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 247c478bd9Sstevel@tonic-gate * Use is subject to license terms. 257c478bd9Sstevel@tonic-gate */ 267c478bd9Sstevel@tonic-gate 277c478bd9Sstevel@tonic-gate #include <ctype.h> 287c478bd9Sstevel@tonic-gate #include <stdio.h> 297c478bd9Sstevel@tonic-gate #include <stdlib.h> 307c478bd9Sstevel@tonic-gate #include <fcntl.h> 317c478bd9Sstevel@tonic-gate #include <string.h> 327c478bd9Sstevel@tonic-gate #include <sys/types.h> 337c478bd9Sstevel@tonic-gate #include <sys/socket.h> 347c478bd9Sstevel@tonic-gate #include <sys/sysmacros.h> 357c478bd9Sstevel@tonic-gate #include <netinet/in.h> 367c478bd9Sstevel@tonic-gate #include <netinet/dhcp.h> 377c478bd9Sstevel@tonic-gate #include <arpa/inet.h> 387c478bd9Sstevel@tonic-gate #include <dhcp_inittab.h> 397c478bd9Sstevel@tonic-gate #include <dhcp_symbol.h> 407c478bd9Sstevel@tonic-gate #include "snoop.h" 417c478bd9Sstevel@tonic-gate 427c478bd9Sstevel@tonic-gate static const char *show_msgtype(unsigned char); 437c478bd9Sstevel@tonic-gate static int show_options(unsigned char *, int); 447c478bd9Sstevel@tonic-gate static void display_ip(int, char *, char *, unsigned char **); 457c478bd9Sstevel@tonic-gate static void display_ascii(char *, char *, unsigned char **); 467c478bd9Sstevel@tonic-gate static void display_number(char *, char *, unsigned char **); 477c478bd9Sstevel@tonic-gate static void display_ascii_hex(char *, unsigned char **); 487c478bd9Sstevel@tonic-gate static unsigned char bootmagic[] = BOOTMAGIC; /* rfc 1048 */ 497c478bd9Sstevel@tonic-gate 507c478bd9Sstevel@tonic-gate static char *option_types[] = { 517c478bd9Sstevel@tonic-gate "", /* 0 */ 527c478bd9Sstevel@tonic-gate "Subnet Mask", /* 1 */ 537c478bd9Sstevel@tonic-gate "UTC Time Offset", /* 2 */ 547c478bd9Sstevel@tonic-gate "Router", /* 3 */ 557c478bd9Sstevel@tonic-gate "RFC868 Time Servers", /* 4 */ 567c478bd9Sstevel@tonic-gate "IEN 116 Name Servers", /* 5 */ 577c478bd9Sstevel@tonic-gate "DNS Servers", /* 6 */ 587c478bd9Sstevel@tonic-gate "UDP LOG Servers", /* 7 */ 597c478bd9Sstevel@tonic-gate "RFC 865 Cookie Servers", /* 8 */ 607c478bd9Sstevel@tonic-gate "RFC 1179 Line Printer Servers (LPR)", /* 9 */ 617c478bd9Sstevel@tonic-gate "Impress Servers", /* 10 */ 627c478bd9Sstevel@tonic-gate "RFC 887 Resource Location Servers", /* 11 */ 637c478bd9Sstevel@tonic-gate "Client Hostname", /* 12 */ 647c478bd9Sstevel@tonic-gate "Boot File size in 512 byte Blocks", /* 13 */ 657c478bd9Sstevel@tonic-gate "Merit Dump File", /* 14 */ 667c478bd9Sstevel@tonic-gate "DNS Domain Name", /* 15 */ 677c478bd9Sstevel@tonic-gate "SWAP Server", /* 16 */ 687c478bd9Sstevel@tonic-gate "Client Root Path", /* 17 */ 697c478bd9Sstevel@tonic-gate "BOOTP options extensions path", /* 18 */ 707c478bd9Sstevel@tonic-gate "IP Forwarding Flag", /* 19 */ 717c478bd9Sstevel@tonic-gate "NonLocal Source Routing Flag", /* 20 */ 727c478bd9Sstevel@tonic-gate "Policy Filters for NonLocal Routing", /* 21 */ 737c478bd9Sstevel@tonic-gate "Maximum Datagram Reassembly Size", /* 22 */ 747c478bd9Sstevel@tonic-gate "Default IP Time To Live", /* 23 */ 757c478bd9Sstevel@tonic-gate "Path MTU Aging Timeout", /* 24 */ 767c478bd9Sstevel@tonic-gate "Path MTU Size Plateau Table", /* 25 */ 777c478bd9Sstevel@tonic-gate "Interface MTU Size", /* 26 */ 787c478bd9Sstevel@tonic-gate "All Subnets are Local Flag", /* 27 */ 797c478bd9Sstevel@tonic-gate "Broadcast Address", /* 28 */ 807c478bd9Sstevel@tonic-gate "Perform Mask Discovery Flag", /* 29 */ 817c478bd9Sstevel@tonic-gate "Mask Supplier Flag", /* 30 */ 827c478bd9Sstevel@tonic-gate "Perform Router Discovery Flag", /* 31 */ 837c478bd9Sstevel@tonic-gate "Router Solicitation Address", /* 32 */ 847c478bd9Sstevel@tonic-gate "Static Routes", /* 33 */ 857c478bd9Sstevel@tonic-gate "Trailer Encapsulation Flag", /* 34 */ 867c478bd9Sstevel@tonic-gate "ARP Cache Timeout Seconds", /* 35 */ 877c478bd9Sstevel@tonic-gate "Ethernet Encapsulation Flag", /* 36 */ 887c478bd9Sstevel@tonic-gate "TCP Default Time To Live", /* 37 */ 897c478bd9Sstevel@tonic-gate "TCP Keepalive Interval Seconds", /* 38 */ 907c478bd9Sstevel@tonic-gate "TCP Keepalive Garbage Flag", /* 39 */ 917c478bd9Sstevel@tonic-gate "NIS Domainname", /* 40 */ 927c478bd9Sstevel@tonic-gate "NIS Servers", /* 41 */ 937c478bd9Sstevel@tonic-gate "Network Time Protocol Servers", /* 42 */ 947c478bd9Sstevel@tonic-gate "Vendor Specific Options", /* 43 */ 957c478bd9Sstevel@tonic-gate "NetBIOS RFC 1001/1002 Name Servers", /* 44 */ 967c478bd9Sstevel@tonic-gate "NetBIOS Datagram Dist. Servers", /* 45 */ 977c478bd9Sstevel@tonic-gate "NetBIOS Node Type", /* 46 */ 987c478bd9Sstevel@tonic-gate "NetBIOS Scope", /* 47 */ 997c478bd9Sstevel@tonic-gate "X Window Font Servers", /* 48 */ 1007c478bd9Sstevel@tonic-gate "X Window Display Manager Servers", /* 49 */ 1017c478bd9Sstevel@tonic-gate "Requested IP Address", /* 50 */ 1027c478bd9Sstevel@tonic-gate "IP Address Lease Time", /* 51 */ 1037c478bd9Sstevel@tonic-gate "Option Field Overload Flag", /* 52 */ 1047c478bd9Sstevel@tonic-gate "DHCP Message Type", /* 53 */ 1057c478bd9Sstevel@tonic-gate "DHCP Server Identifier", /* 54 */ 1067c478bd9Sstevel@tonic-gate "Option Request List", /* 55 */ 1077c478bd9Sstevel@tonic-gate "Error Message", /* 56 */ 1087c478bd9Sstevel@tonic-gate "Maximum DHCP Message Size", /* 57 */ 1097c478bd9Sstevel@tonic-gate "Renewal (T1) Time Value", /* 58 */ 1107c478bd9Sstevel@tonic-gate "Rebinding (T2) Time Value", /* 59 */ 1117c478bd9Sstevel@tonic-gate "Client Class Identifier =", /* 60 */ 1127c478bd9Sstevel@tonic-gate "Client Identifier =", /* 61 */ 1137c478bd9Sstevel@tonic-gate "Netware IP Domain =", /* 62 */ 1147c478bd9Sstevel@tonic-gate "Netware IP Options =", /* 63 */ 1157c478bd9Sstevel@tonic-gate "NISPLUS Domainname", /* 64 */ 1167c478bd9Sstevel@tonic-gate "NISPLUS Servers", /* 65 */ 1177c478bd9Sstevel@tonic-gate "TFTP Server Name", /* 66 */ 1187c478bd9Sstevel@tonic-gate "Option BootFile Name", /* 67 */ 1197c478bd9Sstevel@tonic-gate "Mobile IP Agents", /* 68 */ 1207c478bd9Sstevel@tonic-gate "Simple Mail (SMTP) Servers", /* 69 */ 1217c478bd9Sstevel@tonic-gate "Post Office (POP3) Servers", /* 70 */ 1227c478bd9Sstevel@tonic-gate "Net News (NNTP) Servers", /* 71 */ 1237c478bd9Sstevel@tonic-gate "WorldWideWeb Servers", /* 72 */ 1247c478bd9Sstevel@tonic-gate "Finger Servers", /* 73 */ 1257c478bd9Sstevel@tonic-gate "Internet Relay Chat (IRC) Servers", /* 74 */ 1267c478bd9Sstevel@tonic-gate "StreetTalk Servers", /* 75 */ 1277c478bd9Sstevel@tonic-gate "StreetTalk Directory Assist. Servers", /* 76 */ 1287c478bd9Sstevel@tonic-gate "User Class Identifier", /* 77 */ 1297c478bd9Sstevel@tonic-gate }; 1307c478bd9Sstevel@tonic-gate 1317c478bd9Sstevel@tonic-gate #define OPTIONS_ARRAY_SIZE 78 1327c478bd9Sstevel@tonic-gate 1337c478bd9Sstevel@tonic-gate int 13445916cd2Sjpk interpret_dhcp(int flags, struct dhcp *dp, int len) 1357c478bd9Sstevel@tonic-gate { 1367c478bd9Sstevel@tonic-gate if (flags & F_SUM) { 1377c478bd9Sstevel@tonic-gate if ((memcmp(dp->cookie, bootmagic, sizeof (bootmagic)) == 0) && 1387c478bd9Sstevel@tonic-gate (len >= BASE_PKT_SIZE + 3) && 1397c478bd9Sstevel@tonic-gate dp->options[0] == CD_DHCP_TYPE) { 1407c478bd9Sstevel@tonic-gate (void) sprintf(get_sum_line(), 1417c478bd9Sstevel@tonic-gate "DHCP/BOOTP %s", show_msgtype(dp->options[2])); 1427c478bd9Sstevel@tonic-gate } else { 1437c478bd9Sstevel@tonic-gate switch (ntohs(dp->op)) { 1447c478bd9Sstevel@tonic-gate case BOOTREQUEST: 1457c478bd9Sstevel@tonic-gate (void) sprintf(get_sum_line(), 1467c478bd9Sstevel@tonic-gate "DHCP/BOOTP BOOTREQUEST"); 1477c478bd9Sstevel@tonic-gate break; 1487c478bd9Sstevel@tonic-gate case BOOTREPLY: 1497c478bd9Sstevel@tonic-gate (void) sprintf(get_sum_line(), 1507c478bd9Sstevel@tonic-gate "DHCP/BOOTP BOOTREPLY"); 1517c478bd9Sstevel@tonic-gate break; 1527c478bd9Sstevel@tonic-gate } 1537c478bd9Sstevel@tonic-gate } 1547c478bd9Sstevel@tonic-gate } 1557c478bd9Sstevel@tonic-gate if (flags & F_DTAIL) { 1567c478bd9Sstevel@tonic-gate show_header("DHCP: ", "Dynamic Host Configuration Protocol", 1577c478bd9Sstevel@tonic-gate len); 1587c478bd9Sstevel@tonic-gate show_space(); 1592e3b6467Skcpoon (void) sprintf(get_line((char *)(uintptr_t)dp->htype - 1602e3b6467Skcpoon dlc_header, 1), 1617c478bd9Sstevel@tonic-gate "Hardware address type (htype) = %d (%s)", dp->htype, 162d04ccbb3Scarlsonj arp_htype(dp->htype)); 1632e3b6467Skcpoon (void) sprintf(get_line((char *)(uintptr_t)dp->hlen - 1642e3b6467Skcpoon dlc_header, 1), 1657c478bd9Sstevel@tonic-gate "Hardware address length (hlen) = %d octets", dp->hlen); 1662e3b6467Skcpoon (void) sprintf(get_line((char *)(uintptr_t)dp->hops - 1672e3b6467Skcpoon dlc_header, 1), 1687c478bd9Sstevel@tonic-gate "Relay agent hops = %d", dp->hops); 1692e3b6467Skcpoon (void) sprintf(get_line((char *)(uintptr_t)dp->xid - 1702e3b6467Skcpoon dlc_header, 4), 1717c478bd9Sstevel@tonic-gate "Transaction ID = 0x%x", ntohl(dp->xid)); 1722e3b6467Skcpoon (void) sprintf(get_line((char *)(uintptr_t)dp->secs - 1732e3b6467Skcpoon dlc_header, 2), 1747c478bd9Sstevel@tonic-gate "Time since boot = %d seconds", ntohs(dp->secs)); 1752e3b6467Skcpoon (void) sprintf(get_line((char *)(uintptr_t)dp->flags - 1762e3b6467Skcpoon dlc_header, 2), 1777c478bd9Sstevel@tonic-gate "Flags = 0x%.4x", ntohs(dp->flags)); 1787c478bd9Sstevel@tonic-gate (void) sprintf(get_line((char *)&dp->ciaddr - dlc_header, 4), 1797c478bd9Sstevel@tonic-gate "Client address (ciaddr) = %s", inet_ntoa(dp->ciaddr)); 1807c478bd9Sstevel@tonic-gate (void) sprintf(get_line((char *)&dp->yiaddr - dlc_header, 4), 1817c478bd9Sstevel@tonic-gate "Your client address (yiaddr) = %s", 1827c478bd9Sstevel@tonic-gate inet_ntoa(dp->yiaddr)); 1837c478bd9Sstevel@tonic-gate (void) sprintf(get_line((char *)&dp->siaddr - dlc_header, 4), 1847c478bd9Sstevel@tonic-gate "Next server address (siaddr) = %s", 1857c478bd9Sstevel@tonic-gate inet_ntoa(dp->siaddr)); 1867c478bd9Sstevel@tonic-gate (void) sprintf(get_line((char *)&dp->giaddr - dlc_header, 4), 1877c478bd9Sstevel@tonic-gate "Relay agent address (giaddr) = %s", 1887c478bd9Sstevel@tonic-gate inet_ntoa(dp->giaddr)); 1897c478bd9Sstevel@tonic-gate if (dp->htype == 1) { 1907c478bd9Sstevel@tonic-gate (void) sprintf(get_line((char *)dp->chaddr - 1917c478bd9Sstevel@tonic-gate dlc_header, dp->hlen), 1927c478bd9Sstevel@tonic-gate "Client hardware address (chaddr) = %.2X:%.2X:%.2X:%.2X:%.2X:%.2X", 1937c478bd9Sstevel@tonic-gate dp->chaddr[0], 1947c478bd9Sstevel@tonic-gate dp->chaddr[1], 1957c478bd9Sstevel@tonic-gate dp->chaddr[2], 1967c478bd9Sstevel@tonic-gate dp->chaddr[3], 1977c478bd9Sstevel@tonic-gate dp->chaddr[4], 1987c478bd9Sstevel@tonic-gate dp->chaddr[5]); 1997c478bd9Sstevel@tonic-gate } 2007c478bd9Sstevel@tonic-gate /* 2017c478bd9Sstevel@tonic-gate * Check cookie, process options 2027c478bd9Sstevel@tonic-gate */ 2037c478bd9Sstevel@tonic-gate if (memcmp(dp->cookie, bootmagic, sizeof (bootmagic)) != 0) { 2047c478bd9Sstevel@tonic-gate (void) sprintf(get_line(0, 0), 2057c478bd9Sstevel@tonic-gate "Unrecognized cookie: 0x%.2X%.2X%.2X%.2X\n", 2067c478bd9Sstevel@tonic-gate dp->cookie[0], 2077c478bd9Sstevel@tonic-gate dp->cookie[1], 2087c478bd9Sstevel@tonic-gate dp->cookie[2], 2097c478bd9Sstevel@tonic-gate dp->cookie[3]); 2107c478bd9Sstevel@tonic-gate return (0); 2117c478bd9Sstevel@tonic-gate } 2127c478bd9Sstevel@tonic-gate show_space(); 2137c478bd9Sstevel@tonic-gate show_header("DHCP: ", "(Options) field options", len); 2147c478bd9Sstevel@tonic-gate show_space(); 2157c478bd9Sstevel@tonic-gate switch (show_options(dp->options, (len - BASE_PKT_SIZE))) { 2167c478bd9Sstevel@tonic-gate case 0: 2177c478bd9Sstevel@tonic-gate /* No option overloading */ 2187c478bd9Sstevel@tonic-gate if (*(unsigned char *)(dp->sname) != '\0') { 2197c478bd9Sstevel@tonic-gate (void) sprintf(get_line(0, 0), 2207c478bd9Sstevel@tonic-gate "Server Name = %s", dp->sname); 2217c478bd9Sstevel@tonic-gate } 2227c478bd9Sstevel@tonic-gate if (*(unsigned char *)(dp->file) != '\0') { 2237c478bd9Sstevel@tonic-gate (void) sprintf(get_line(0, 0), 2247c478bd9Sstevel@tonic-gate "Boot File Name = %s", dp->file); 2257c478bd9Sstevel@tonic-gate } 2267c478bd9Sstevel@tonic-gate break; 2277c478bd9Sstevel@tonic-gate case 1: 2287c478bd9Sstevel@tonic-gate /* file field used */ 2297c478bd9Sstevel@tonic-gate if (*(unsigned char *)(dp->sname) != '\0') { 2307c478bd9Sstevel@tonic-gate (void) sprintf(get_line(0, 0), 2317c478bd9Sstevel@tonic-gate "Server Name = %s", dp->sname); 2327c478bd9Sstevel@tonic-gate } 2337c478bd9Sstevel@tonic-gate show_space(); 2347c478bd9Sstevel@tonic-gate show_header("DHCP: ", "(File) field options", len); 2357c478bd9Sstevel@tonic-gate show_space(); 2367c478bd9Sstevel@tonic-gate (void) show_options(dp->file, 128); 2377c478bd9Sstevel@tonic-gate break; 2387c478bd9Sstevel@tonic-gate case 2: 2397c478bd9Sstevel@tonic-gate /* sname field used for options */ 2407c478bd9Sstevel@tonic-gate if (*(unsigned char *)(dp->file) != '\0') { 2417c478bd9Sstevel@tonic-gate (void) sprintf(get_line(0, 0), 2427c478bd9Sstevel@tonic-gate "Boot File Name = %s", dp->file); 2437c478bd9Sstevel@tonic-gate } 2447c478bd9Sstevel@tonic-gate show_space(); 2457c478bd9Sstevel@tonic-gate show_header("DHCP: ", "(Sname) field options", len); 2467c478bd9Sstevel@tonic-gate show_space(); 2477c478bd9Sstevel@tonic-gate (void) show_options(dp->sname, 64); 2487c478bd9Sstevel@tonic-gate break; 2497c478bd9Sstevel@tonic-gate case 3: 2507c478bd9Sstevel@tonic-gate show_space(); 2517c478bd9Sstevel@tonic-gate show_header("DHCP: ", "(File) field options", len); 2527c478bd9Sstevel@tonic-gate show_space(); 2537c478bd9Sstevel@tonic-gate (void) show_options(dp->file, 128); 2547c478bd9Sstevel@tonic-gate show_space(); 2557c478bd9Sstevel@tonic-gate show_header("DHCP: ", "(Sname) field options", len); 2567c478bd9Sstevel@tonic-gate show_space(); 2577c478bd9Sstevel@tonic-gate (void) show_options(dp->sname, 64); 2587c478bd9Sstevel@tonic-gate break; 2597c478bd9Sstevel@tonic-gate }; 2607c478bd9Sstevel@tonic-gate } 2617c478bd9Sstevel@tonic-gate return (len); 2627c478bd9Sstevel@tonic-gate } 263d04ccbb3Scarlsonj 2647c478bd9Sstevel@tonic-gate static int 2657c478bd9Sstevel@tonic-gate show_options(unsigned char *cp, int len) 2667c478bd9Sstevel@tonic-gate { 2677c478bd9Sstevel@tonic-gate char *prmpt; 2687c478bd9Sstevel@tonic-gate unsigned char *end, *vend; 2697c478bd9Sstevel@tonic-gate unsigned char *start, save; 2707c478bd9Sstevel@tonic-gate int items, i; 2717c478bd9Sstevel@tonic-gate int nooverload = 0; 2727c478bd9Sstevel@tonic-gate ushort_t s_buf; 2737c478bd9Sstevel@tonic-gate struct in_addr tmp; 2747c478bd9Sstevel@tonic-gate char scratch[128]; 2757c478bd9Sstevel@tonic-gate dhcp_symbol_t *entry; 2767c478bd9Sstevel@tonic-gate char *decoded_opt; 2777c478bd9Sstevel@tonic-gate int opt_len; 2787c478bd9Sstevel@tonic-gate 2797c478bd9Sstevel@tonic-gate start = cp; 2807c478bd9Sstevel@tonic-gate end = (unsigned char *)cp + len; 2817c478bd9Sstevel@tonic-gate 2827c478bd9Sstevel@tonic-gate while (start < end) { 2837c478bd9Sstevel@tonic-gate if (*start == CD_PAD) { 2847c478bd9Sstevel@tonic-gate start++; 2857c478bd9Sstevel@tonic-gate continue; 2867c478bd9Sstevel@tonic-gate } 2877c478bd9Sstevel@tonic-gate if (*start == CD_END) 2887c478bd9Sstevel@tonic-gate break; /* done */ 2897c478bd9Sstevel@tonic-gate 2907c478bd9Sstevel@tonic-gate save = *start++; 2917c478bd9Sstevel@tonic-gate switch (save) { 2927c478bd9Sstevel@tonic-gate /* Network order IP address(es) */ 2937c478bd9Sstevel@tonic-gate case CD_SUBNETMASK: 2947c478bd9Sstevel@tonic-gate case CD_ROUTER_SOLICIT_SERV: 2957c478bd9Sstevel@tonic-gate case CD_BROADCASTADDR: 2967c478bd9Sstevel@tonic-gate case CD_REQUESTED_IP_ADDR: 2977c478bd9Sstevel@tonic-gate case CD_SERVER_ID: 2987c478bd9Sstevel@tonic-gate /* Single IP address */ 2997c478bd9Sstevel@tonic-gate if (*start != 4) { 3007c478bd9Sstevel@tonic-gate (void) sprintf(get_line(0, 0), 3017c478bd9Sstevel@tonic-gate "Error: Bad %s", option_types[save]); 3027c478bd9Sstevel@tonic-gate } else { 3037c478bd9Sstevel@tonic-gate start++; 3047c478bd9Sstevel@tonic-gate display_ip(1, "%s = %s", option_types[save], 3057c478bd9Sstevel@tonic-gate &start); 3067c478bd9Sstevel@tonic-gate } 3077c478bd9Sstevel@tonic-gate break; 3087c478bd9Sstevel@tonic-gate case CD_ROUTER: 3097c478bd9Sstevel@tonic-gate case CD_TIMESERV: 3107c478bd9Sstevel@tonic-gate case CD_IEN116_NAME_SERV: 3117c478bd9Sstevel@tonic-gate case CD_DNSSERV: 3127c478bd9Sstevel@tonic-gate case CD_LOG_SERV: 3137c478bd9Sstevel@tonic-gate case CD_COOKIE_SERV: 3147c478bd9Sstevel@tonic-gate case CD_LPR_SERV: 3157c478bd9Sstevel@tonic-gate case CD_IMPRESS_SERV: 3167c478bd9Sstevel@tonic-gate case CD_RESOURCE_SERV: 3177c478bd9Sstevel@tonic-gate case CD_SWAP_SERV: 3187c478bd9Sstevel@tonic-gate case CD_NIS_SERV: 3197c478bd9Sstevel@tonic-gate case CD_NTP_SERV: 3207c478bd9Sstevel@tonic-gate case CD_NETBIOS_NAME_SERV: 3217c478bd9Sstevel@tonic-gate case CD_NETBIOS_DIST_SERV: 3227c478bd9Sstevel@tonic-gate case CD_XWIN_FONT_SERV: 3237c478bd9Sstevel@tonic-gate case CD_XWIN_DISP_SERV: 3247c478bd9Sstevel@tonic-gate case CD_NISPLUS_SERVS: 3257c478bd9Sstevel@tonic-gate case CD_MOBILE_IP_AGENT: 3267c478bd9Sstevel@tonic-gate case CD_SMTP_SERVS: 3277c478bd9Sstevel@tonic-gate case CD_POP3_SERVS: 3287c478bd9Sstevel@tonic-gate case CD_NNTP_SERVS: 3297c478bd9Sstevel@tonic-gate case CD_WWW_SERVS: 3307c478bd9Sstevel@tonic-gate case CD_FINGER_SERVS: 3317c478bd9Sstevel@tonic-gate case CD_IRC_SERVS: 3327c478bd9Sstevel@tonic-gate case CD_STREETTALK_SERVS: 3337c478bd9Sstevel@tonic-gate case CD_STREETTALK_DA_SERVS: 3347c478bd9Sstevel@tonic-gate /* Multiple IP addresses */ 3357c478bd9Sstevel@tonic-gate if ((*start % 4) != 0) { 3367c478bd9Sstevel@tonic-gate (void) sprintf(get_line(0, 0), 3377c478bd9Sstevel@tonic-gate "Error: Bad %s address", 3387c478bd9Sstevel@tonic-gate option_types[save]); 3397c478bd9Sstevel@tonic-gate } else { 34038c589b6Skcpoon items = *start++ / 4; 34138c589b6Skcpoon display_ip(items, "%s at = %s", 3427c478bd9Sstevel@tonic-gate option_types[save], &start); 3437c478bd9Sstevel@tonic-gate } 3447c478bd9Sstevel@tonic-gate break; 3457c478bd9Sstevel@tonic-gate case CD_TFTP_SERV_NAME: 3467c478bd9Sstevel@tonic-gate case CD_HOSTNAME: 3477c478bd9Sstevel@tonic-gate case CD_DUMP_FILE: 3487c478bd9Sstevel@tonic-gate case CD_DNSDOMAIN: 3497c478bd9Sstevel@tonic-gate case CD_ROOT_PATH: 3507c478bd9Sstevel@tonic-gate case CD_NIS_DOMAIN: 3517c478bd9Sstevel@tonic-gate case CD_NETBIOS_SCOPE: 3527c478bd9Sstevel@tonic-gate case CD_MESSAGE: 3537c478bd9Sstevel@tonic-gate case CD_NISPLUS_DMAIN: 3547c478bd9Sstevel@tonic-gate case CD_OPT_BOOTFILE_NAME: 3557c478bd9Sstevel@tonic-gate case CD_USER_CLASS_ID: 3567c478bd9Sstevel@tonic-gate /* Ascii strings */ 3577c478bd9Sstevel@tonic-gate display_ascii("%s = %s", option_types[save], &start); 3587c478bd9Sstevel@tonic-gate break; 3597c478bd9Sstevel@tonic-gate case CD_TIMEOFFSET: 3607c478bd9Sstevel@tonic-gate case CD_IPTTL: 3617c478bd9Sstevel@tonic-gate case CD_PATH_MTU_TIMEOUT: 3627c478bd9Sstevel@tonic-gate case CD_ARP_TIMEOUT: 3637c478bd9Sstevel@tonic-gate case CD_TCP_TTL: 3647c478bd9Sstevel@tonic-gate case CD_TCP_KALIVE_INTVL: 3657c478bd9Sstevel@tonic-gate case CD_T1_TIME: 3667c478bd9Sstevel@tonic-gate case CD_T2_TIME: 3677c478bd9Sstevel@tonic-gate case CD_LEASE_TIME: 3687c478bd9Sstevel@tonic-gate /* Number: seconds */ 3697c478bd9Sstevel@tonic-gate display_number("%s = %d seconds", option_types[save], 3707c478bd9Sstevel@tonic-gate &start); 3717c478bd9Sstevel@tonic-gate break; 3727c478bd9Sstevel@tonic-gate case CD_IP_FORWARDING_ON: 3737c478bd9Sstevel@tonic-gate case CD_NON_LCL_ROUTE_ON: 3747c478bd9Sstevel@tonic-gate case CD_ALL_SUBNETS_LCL_ON: 3757c478bd9Sstevel@tonic-gate case CD_MASK_DISCVRY_ON: 3767c478bd9Sstevel@tonic-gate case CD_MASK_SUPPLIER_ON: 3777c478bd9Sstevel@tonic-gate case CD_ROUTER_DISCVRY_ON: 3787c478bd9Sstevel@tonic-gate case CD_TRAILER_ENCAPS_ON: 3797c478bd9Sstevel@tonic-gate case CD_ETHERNET_ENCAPS_ON: 3807c478bd9Sstevel@tonic-gate case CD_TCP_KALIVE_GRBG_ON: 3817c478bd9Sstevel@tonic-gate /* Number: hex flag */ 3827c478bd9Sstevel@tonic-gate display_number("%s flag = 0x%x", option_types[save], 3837c478bd9Sstevel@tonic-gate &start); 3847c478bd9Sstevel@tonic-gate break; 3857c478bd9Sstevel@tonic-gate case CD_MAXIPSIZE: 3867c478bd9Sstevel@tonic-gate case CD_MTU: 3877c478bd9Sstevel@tonic-gate case CD_MAX_DHCP_SIZE: 3887c478bd9Sstevel@tonic-gate /* Number: bytes */ 3897c478bd9Sstevel@tonic-gate display_number("%s = %d bytes", option_types[save], 3907c478bd9Sstevel@tonic-gate &start); 3917c478bd9Sstevel@tonic-gate break; 3927c478bd9Sstevel@tonic-gate case CD_CLASS_ID: 3937c478bd9Sstevel@tonic-gate case CD_CLIENT_ID: 3947c478bd9Sstevel@tonic-gate case CD_NW_IP_DOMAIN: 3957c478bd9Sstevel@tonic-gate case CD_NW_IP_OPTIONS: 3967c478bd9Sstevel@tonic-gate /* Hex ascii strings */ 3977c478bd9Sstevel@tonic-gate display_ascii_hex(option_types[save], &start); 3987c478bd9Sstevel@tonic-gate break; 3997c478bd9Sstevel@tonic-gate case CD_BOOT_SIZE: 4007c478bd9Sstevel@tonic-gate display_number("%s = %d 512 byte blocks", 4017c478bd9Sstevel@tonic-gate "Boot file size", &start); 4027c478bd9Sstevel@tonic-gate break; 4037c478bd9Sstevel@tonic-gate case CD_POLICY_FILTER: 4047c478bd9Sstevel@tonic-gate if ((*start % 8) != 0) { 4057c478bd9Sstevel@tonic-gate (void) sprintf(get_line(0, 0), 4067c478bd9Sstevel@tonic-gate "Error: Bad Policy Filter option"); 4077c478bd9Sstevel@tonic-gate } else { 4087c478bd9Sstevel@tonic-gate items = *start++ / 8; 4097c478bd9Sstevel@tonic-gate for (i = 0; i < items; i++) { 4107c478bd9Sstevel@tonic-gate display_ip(1, 4117c478bd9Sstevel@tonic-gate "%s = %s", 4127c478bd9Sstevel@tonic-gate "Policy Destination", 4137c478bd9Sstevel@tonic-gate &start); 4147c478bd9Sstevel@tonic-gate display_ip(1, "%s = %s", "Mask", 4157c478bd9Sstevel@tonic-gate &start); 4167c478bd9Sstevel@tonic-gate } 4177c478bd9Sstevel@tonic-gate } 4187c478bd9Sstevel@tonic-gate break; 4197c478bd9Sstevel@tonic-gate case CD_PATH_MTU_TABLE_SZ: 4207c478bd9Sstevel@tonic-gate if (*start % 2 != 0) { 4217c478bd9Sstevel@tonic-gate (void) sprintf(get_line(0, 0), 4227c478bd9Sstevel@tonic-gate "Error: Bad Path MTU Table"); 4237c478bd9Sstevel@tonic-gate } else { 4247c478bd9Sstevel@tonic-gate (void) sprintf(get_line(0, 0), 4257c478bd9Sstevel@tonic-gate "\tPath MTU Plateau Table:"); 4267c478bd9Sstevel@tonic-gate (void) sprintf(get_line(0, 0), 4277c478bd9Sstevel@tonic-gate "\t======================="); 4287c478bd9Sstevel@tonic-gate items = *start / sizeof (ushort_t); 4297c478bd9Sstevel@tonic-gate ++start; 4307c478bd9Sstevel@tonic-gate for (i = 0; i < items; i++) { 4317c478bd9Sstevel@tonic-gate if (IS_P2ALIGNED(start, 432*20f2cb7bSVasumathi Sundaram - Sun Microsystems sizeof (ushort_t))) { 4337c478bd9Sstevel@tonic-gate /* LINTED: improper alignment */ 4347c478bd9Sstevel@tonic-gate s_buf = *(ushort_t *)start; 4357c478bd9Sstevel@tonic-gate } else { 4367c478bd9Sstevel@tonic-gate memcpy((char *)&s_buf, 4377c478bd9Sstevel@tonic-gate start, sizeof (short)); 4387c478bd9Sstevel@tonic-gate } 4397c478bd9Sstevel@tonic-gate (void) sprintf(get_line(0, 0), 4407c478bd9Sstevel@tonic-gate "\t\tEntry %d:\t\t%d", i, 4417c478bd9Sstevel@tonic-gate ntohs(s_buf)); 4427c478bd9Sstevel@tonic-gate start += sizeof (ushort_t); 4437c478bd9Sstevel@tonic-gate } 4447c478bd9Sstevel@tonic-gate } 4457c478bd9Sstevel@tonic-gate break; 4467c478bd9Sstevel@tonic-gate case CD_STATIC_ROUTE: 4477c478bd9Sstevel@tonic-gate if ((*start % 8) != 0) { 4487c478bd9Sstevel@tonic-gate (void) sprintf(get_line(0, 0), 4497c478bd9Sstevel@tonic-gate "Error: Bad Static Route option: %d", 4507c478bd9Sstevel@tonic-gate *start); 4517c478bd9Sstevel@tonic-gate } else { 4527c478bd9Sstevel@tonic-gate items = *start++ / 8; 4537c478bd9Sstevel@tonic-gate for (i = 0; i < items; i++) { 4547c478bd9Sstevel@tonic-gate memcpy((char *)&tmp, start, 4557c478bd9Sstevel@tonic-gate sizeof (struct in_addr)); 4567c478bd9Sstevel@tonic-gate (void) strcpy(scratch, inet_ntoa(tmp)); 4577c478bd9Sstevel@tonic-gate start += sizeof (ulong_t); 4587c478bd9Sstevel@tonic-gate memcpy((char *)&tmp, start, 4597c478bd9Sstevel@tonic-gate sizeof (struct in_addr)); 4607c478bd9Sstevel@tonic-gate (void) sprintf(get_line(0, 0), 4617c478bd9Sstevel@tonic-gate "Static route from %s to %s", 4627c478bd9Sstevel@tonic-gate scratch, inet_ntoa(tmp)); 4637c478bd9Sstevel@tonic-gate start += sizeof (ulong_t); 4647c478bd9Sstevel@tonic-gate } 4657c478bd9Sstevel@tonic-gate } 4667c478bd9Sstevel@tonic-gate break; 4677c478bd9Sstevel@tonic-gate case CD_VENDOR_SPEC: 4687c478bd9Sstevel@tonic-gate i = *start++; 4697c478bd9Sstevel@tonic-gate (void) sprintf(get_line(0, 0), 4707c478bd9Sstevel@tonic-gate "Vendor-specific Options (%d total octets):", i); 4717c478bd9Sstevel@tonic-gate /* 4727c478bd9Sstevel@tonic-gate * We don't know what these things are, so just 4737c478bd9Sstevel@tonic-gate * display the option number, length, and value 4747c478bd9Sstevel@tonic-gate * (hex). 4757c478bd9Sstevel@tonic-gate */ 4767c478bd9Sstevel@tonic-gate vend = (uchar_t *)((uchar_t *)start + i); 4777c478bd9Sstevel@tonic-gate while (start < vend && *start != CD_END) { 4787c478bd9Sstevel@tonic-gate if (*start == CD_PAD) { 4797c478bd9Sstevel@tonic-gate start++; 4807c478bd9Sstevel@tonic-gate continue; 4817c478bd9Sstevel@tonic-gate } 4827c478bd9Sstevel@tonic-gate (void) sprintf(scratch, 4837c478bd9Sstevel@tonic-gate "\t(%.2d) %.2d octets", *start, 4847c478bd9Sstevel@tonic-gate *(uchar_t *)((uchar_t *)start + 1)); 4857c478bd9Sstevel@tonic-gate start++; 4867c478bd9Sstevel@tonic-gate display_ascii_hex(scratch, &start); 4877c478bd9Sstevel@tonic-gate } 4887c478bd9Sstevel@tonic-gate start = vend; /* in case CD_END found */ 4897c478bd9Sstevel@tonic-gate break; 4907c478bd9Sstevel@tonic-gate case CD_NETBIOS_NODE_TYPE: 4917c478bd9Sstevel@tonic-gate if (*start != 1) { 4927c478bd9Sstevel@tonic-gate (void) sprintf(get_line(0, 0), 4937c478bd9Sstevel@tonic-gate "Error: Bad '%s' parameter", 4947c478bd9Sstevel@tonic-gate option_types[CD_NETBIOS_NODE_TYPE]); 4957c478bd9Sstevel@tonic-gate } else { 4967c478bd9Sstevel@tonic-gate char *type; 4977c478bd9Sstevel@tonic-gate start++; 4987c478bd9Sstevel@tonic-gate switch (*start) { 4997c478bd9Sstevel@tonic-gate case 0x1: 5007c478bd9Sstevel@tonic-gate type = "Broadcast Node"; 5017c478bd9Sstevel@tonic-gate break; 5027c478bd9Sstevel@tonic-gate case 0x2: 5037c478bd9Sstevel@tonic-gate type = "Point To Point Node"; 5047c478bd9Sstevel@tonic-gate break; 5057c478bd9Sstevel@tonic-gate case 0x4: 5067c478bd9Sstevel@tonic-gate type = "Mixed Mode Node"; 5077c478bd9Sstevel@tonic-gate break; 5087c478bd9Sstevel@tonic-gate case 0x8: 5097c478bd9Sstevel@tonic-gate type = "Hybrid Node"; 5107c478bd9Sstevel@tonic-gate break; 5117c478bd9Sstevel@tonic-gate default: 5127c478bd9Sstevel@tonic-gate type = "??? Node"; 5137c478bd9Sstevel@tonic-gate break; 5147c478bd9Sstevel@tonic-gate }; 5157c478bd9Sstevel@tonic-gate (void) sprintf(get_line(0, 0), 5167c478bd9Sstevel@tonic-gate "%s = %s (%d)", 5177c478bd9Sstevel@tonic-gate option_types[CD_NETBIOS_NODE_TYPE], 5187c478bd9Sstevel@tonic-gate type, *start); 5197c478bd9Sstevel@tonic-gate start++; 5207c478bd9Sstevel@tonic-gate } 5217c478bd9Sstevel@tonic-gate break; 5227c478bd9Sstevel@tonic-gate case CD_OPTION_OVERLOAD: 5237c478bd9Sstevel@tonic-gate if (*start != 1) { 5247c478bd9Sstevel@tonic-gate (void) sprintf(get_line(0, 0), 5257c478bd9Sstevel@tonic-gate "Bad Option Overload value."); 5267c478bd9Sstevel@tonic-gate } else { 5277c478bd9Sstevel@tonic-gate start++; 5287c478bd9Sstevel@tonic-gate nooverload = *start++; 5297c478bd9Sstevel@tonic-gate } 5307c478bd9Sstevel@tonic-gate break; 5317c478bd9Sstevel@tonic-gate case CD_DHCP_TYPE: 5327c478bd9Sstevel@tonic-gate if (*start < 1 || *start > 7) { 5337c478bd9Sstevel@tonic-gate (void) sprintf(get_line(0, 0), 5347c478bd9Sstevel@tonic-gate "Bad DHCP Message Type."); 5357c478bd9Sstevel@tonic-gate } else { 5367c478bd9Sstevel@tonic-gate start++; 5377c478bd9Sstevel@tonic-gate (void) sprintf(get_line(0, 0), 5387c478bd9Sstevel@tonic-gate "Message type = %s", 5397c478bd9Sstevel@tonic-gate show_msgtype(*start)); 5407c478bd9Sstevel@tonic-gate start++; 5417c478bd9Sstevel@tonic-gate } 5427c478bd9Sstevel@tonic-gate break; 5437c478bd9Sstevel@tonic-gate case CD_REQUEST_LIST: 5447c478bd9Sstevel@tonic-gate opt_len = *start++; 5457c478bd9Sstevel@tonic-gate (void) sprintf(get_line(0, 0), 5467c478bd9Sstevel@tonic-gate "Requested Options:"); 5477c478bd9Sstevel@tonic-gate for (i = 0; i < opt_len; i++) { 5487c478bd9Sstevel@tonic-gate entry = NULL; 5497c478bd9Sstevel@tonic-gate if (*start < OPTIONS_ARRAY_SIZE) { 5507c478bd9Sstevel@tonic-gate prmpt = option_types[*start]; 5517c478bd9Sstevel@tonic-gate } else { 5527c478bd9Sstevel@tonic-gate entry = inittab_getbycode( 553*20f2cb7bSVasumathi Sundaram - Sun Microsystems ITAB_CAT_STANDARD|ITAB_CAT_SITE, 554*20f2cb7bSVasumathi Sundaram - Sun Microsystems ITAB_CONS_SNOOP, *start); 5557c478bd9Sstevel@tonic-gate if (entry == NULL) { 5567c478bd9Sstevel@tonic-gate if (*start >= DHCP_SITE_OPT && 5577c478bd9Sstevel@tonic-gate *start <= DHCP_END_SITE) { 5587c478bd9Sstevel@tonic-gate prmpt = "Site Option"; 5597c478bd9Sstevel@tonic-gate } else { 5607c478bd9Sstevel@tonic-gate prmpt = "Unrecognized " 561*20f2cb7bSVasumathi Sundaram - Sun Microsystems "Option"; 5627c478bd9Sstevel@tonic-gate } 5637c478bd9Sstevel@tonic-gate } else { 5647c478bd9Sstevel@tonic-gate prmpt = entry->ds_name; 5657c478bd9Sstevel@tonic-gate } 5667c478bd9Sstevel@tonic-gate } 5677c478bd9Sstevel@tonic-gate (void) sprintf(get_line(0, 0), 5687c478bd9Sstevel@tonic-gate "\t%2d (%s)", *start, prmpt); 5697c478bd9Sstevel@tonic-gate start++; 5707c478bd9Sstevel@tonic-gate free(entry); 5717c478bd9Sstevel@tonic-gate } 5727c478bd9Sstevel@tonic-gate break; 5737c478bd9Sstevel@tonic-gate default: 5747c478bd9Sstevel@tonic-gate opt_len = *start++; 5757c478bd9Sstevel@tonic-gate entry = inittab_getbycode( 576*20f2cb7bSVasumathi Sundaram - Sun Microsystems ITAB_CAT_STANDARD|ITAB_CAT_SITE, 577*20f2cb7bSVasumathi Sundaram - Sun Microsystems ITAB_CONS_SNOOP, save); 5787c478bd9Sstevel@tonic-gate if (entry == NULL) { 5797c478bd9Sstevel@tonic-gate if (save >= DHCP_SITE_OPT && 5807c478bd9Sstevel@tonic-gate save <= DHCP_END_SITE) 5817c478bd9Sstevel@tonic-gate prmpt = "Site"; 5827c478bd9Sstevel@tonic-gate else 5837c478bd9Sstevel@tonic-gate prmpt = "Unrecognized"; 5847c478bd9Sstevel@tonic-gate decoded_opt = NULL; 5857c478bd9Sstevel@tonic-gate } else { 5867c478bd9Sstevel@tonic-gate if (save < OPTIONS_ARRAY_SIZE) { 5877c478bd9Sstevel@tonic-gate prmpt = option_types[save]; 5887c478bd9Sstevel@tonic-gate } else { 5897c478bd9Sstevel@tonic-gate prmpt = entry->ds_name; 5907c478bd9Sstevel@tonic-gate } 5917c478bd9Sstevel@tonic-gate decoded_opt = inittab_decode(entry, start, 592*20f2cb7bSVasumathi Sundaram - Sun Microsystems opt_len, B_TRUE); 5937c478bd9Sstevel@tonic-gate } 5947c478bd9Sstevel@tonic-gate if (decoded_opt == NULL) { 5957c478bd9Sstevel@tonic-gate (void) sprintf(get_line(0, 0), 5967c478bd9Sstevel@tonic-gate "%s Option = %d, length = %d octets", 5977c478bd9Sstevel@tonic-gate prmpt, save, opt_len); 5987c478bd9Sstevel@tonic-gate start--; 5997c478bd9Sstevel@tonic-gate display_ascii_hex("\tValue =", &start); 6007c478bd9Sstevel@tonic-gate } else { 6017c478bd9Sstevel@tonic-gate (void) sprintf(get_line(0, 0), "%s = %s", prmpt, 602*20f2cb7bSVasumathi Sundaram - Sun Microsystems decoded_opt); 6037c478bd9Sstevel@tonic-gate start += opt_len; 6047c478bd9Sstevel@tonic-gate free(decoded_opt); 6057c478bd9Sstevel@tonic-gate } 6067c478bd9Sstevel@tonic-gate free(entry); 6077c478bd9Sstevel@tonic-gate break; 6087c478bd9Sstevel@tonic-gate }; 6097c478bd9Sstevel@tonic-gate } 6107c478bd9Sstevel@tonic-gate return (nooverload); 6117c478bd9Sstevel@tonic-gate } 612d04ccbb3Scarlsonj 6137c478bd9Sstevel@tonic-gate static const char * 6147c478bd9Sstevel@tonic-gate show_msgtype(unsigned char type) 6157c478bd9Sstevel@tonic-gate { 6167c478bd9Sstevel@tonic-gate /* 6177c478bd9Sstevel@tonic-gate * note: the ordering here allows direct indexing of the table 6187c478bd9Sstevel@tonic-gate * based on the RFC2131 packet type value passed in. 6197c478bd9Sstevel@tonic-gate */ 6207c478bd9Sstevel@tonic-gate 6217c478bd9Sstevel@tonic-gate static const char *types[] = { 6227c478bd9Sstevel@tonic-gate "BOOTP", 6237c478bd9Sstevel@tonic-gate "DHCPDISCOVER", "DHCPOFFER", "DHCPREQUEST", "DHCPDECLINE", 6247c478bd9Sstevel@tonic-gate "DHCPACK", "DHCPNAK", "DHCPRELEASE", "DHCPINFORM" 6257c478bd9Sstevel@tonic-gate }; 6267c478bd9Sstevel@tonic-gate 627*20f2cb7bSVasumathi Sundaram - Sun Microsystems if (type >= (sizeof (types) / sizeof (*types)) || types[type] == NULL) 6287c478bd9Sstevel@tonic-gate return ("UNKNOWN"); 6297c478bd9Sstevel@tonic-gate 6307c478bd9Sstevel@tonic-gate return (types[type]); 6317c478bd9Sstevel@tonic-gate } 632d04ccbb3Scarlsonj 6337c478bd9Sstevel@tonic-gate static void 6347c478bd9Sstevel@tonic-gate display_ip(int items, char *fmt, char *msg, unsigned char **opt) 6357c478bd9Sstevel@tonic-gate { 6367c478bd9Sstevel@tonic-gate struct in_addr tmp; 6377c478bd9Sstevel@tonic-gate int i; 6387c478bd9Sstevel@tonic-gate 6397c478bd9Sstevel@tonic-gate for (i = 0; i < items; i++) { 6407c478bd9Sstevel@tonic-gate memcpy((char *)&tmp, *opt, sizeof (struct in_addr)); 6417c478bd9Sstevel@tonic-gate (void) sprintf(get_line(0, 0), fmt, msg, inet_ntoa(tmp)); 6427c478bd9Sstevel@tonic-gate *opt += 4; 6437c478bd9Sstevel@tonic-gate } 6447c478bd9Sstevel@tonic-gate } 645d04ccbb3Scarlsonj 6467c478bd9Sstevel@tonic-gate static void 6477c478bd9Sstevel@tonic-gate display_ascii(char *fmt, char *msg, unsigned char **opt) 6487c478bd9Sstevel@tonic-gate { 6497c478bd9Sstevel@tonic-gate static unsigned char buf[256]; 6502e3b6467Skcpoon int len = **opt; 6517c478bd9Sstevel@tonic-gate unsigned char slen = len; 6527c478bd9Sstevel@tonic-gate 6537c478bd9Sstevel@tonic-gate if (len >= sizeof (buf)) 6547c478bd9Sstevel@tonic-gate len = sizeof (buf) - 1; 6557c478bd9Sstevel@tonic-gate (*opt)++; 6567c478bd9Sstevel@tonic-gate memcpy(buf, *opt, len); 6577c478bd9Sstevel@tonic-gate *(unsigned char *)(buf + len) = '\0'; 6587c478bd9Sstevel@tonic-gate (void) sprintf(get_line(0, 0), fmt, msg, buf); 6597c478bd9Sstevel@tonic-gate (*opt) += slen; 6607c478bd9Sstevel@tonic-gate } 661d04ccbb3Scarlsonj 6627c478bd9Sstevel@tonic-gate static void 6637c478bd9Sstevel@tonic-gate display_number(char *fmt, char *msg, unsigned char **opt) 6647c478bd9Sstevel@tonic-gate { 6657c478bd9Sstevel@tonic-gate int len = **opt; 6667c478bd9Sstevel@tonic-gate unsigned long l_buf = 0; 6677c478bd9Sstevel@tonic-gate unsigned short s_buf = 0; 6687c478bd9Sstevel@tonic-gate 6697c478bd9Sstevel@tonic-gate if (len > 4) { 6707c478bd9Sstevel@tonic-gate (*opt)++; 6717c478bd9Sstevel@tonic-gate (void) sprintf(get_line(0, 0), fmt, msg, 0xdeadbeef); 6727c478bd9Sstevel@tonic-gate return; 6737c478bd9Sstevel@tonic-gate } 6747c478bd9Sstevel@tonic-gate switch (len) { 6757c478bd9Sstevel@tonic-gate case sizeof (uchar_t): 6767c478bd9Sstevel@tonic-gate (*opt)++; 6777c478bd9Sstevel@tonic-gate (void) sprintf(get_line(0, 0), fmt, msg, **opt); 6787c478bd9Sstevel@tonic-gate break; 6797c478bd9Sstevel@tonic-gate case sizeof (ushort_t): 6807c478bd9Sstevel@tonic-gate (*opt)++; 6817c478bd9Sstevel@tonic-gate if (IS_P2ALIGNED(*opt, sizeof (ushort_t))) 6827c478bd9Sstevel@tonic-gate /* LINTED: improper alignment */ 6837c478bd9Sstevel@tonic-gate s_buf = *(unsigned short *)*opt; 6847c478bd9Sstevel@tonic-gate else 6857c478bd9Sstevel@tonic-gate memcpy((char *)&s_buf, *opt, len); 6867c478bd9Sstevel@tonic-gate (void) sprintf(get_line(0, 0), fmt, msg, ntohs(s_buf)); 6877c478bd9Sstevel@tonic-gate break; 6887c478bd9Sstevel@tonic-gate case sizeof (ulong_t): 6897c478bd9Sstevel@tonic-gate (*opt)++; 6907c478bd9Sstevel@tonic-gate if (IS_P2ALIGNED(*opt, sizeof (ulong_t))) 6917c478bd9Sstevel@tonic-gate /* LINTED: improper alignment */ 6927c478bd9Sstevel@tonic-gate l_buf = *(unsigned long *)*opt; 6937c478bd9Sstevel@tonic-gate else 6947c478bd9Sstevel@tonic-gate memcpy((char *)&l_buf, *opt, len); 6957c478bd9Sstevel@tonic-gate (void) sprintf(get_line(0, 0), fmt, msg, ntohl(l_buf)); 6967c478bd9Sstevel@tonic-gate break; 6977c478bd9Sstevel@tonic-gate } 6987c478bd9Sstevel@tonic-gate (*opt) += len; 6997c478bd9Sstevel@tonic-gate } 700d04ccbb3Scarlsonj 7017c478bd9Sstevel@tonic-gate static void 7027c478bd9Sstevel@tonic-gate display_ascii_hex(char *msg, unsigned char **opt) 7037c478bd9Sstevel@tonic-gate { 7047c478bd9Sstevel@tonic-gate int printable; 7057c478bd9Sstevel@tonic-gate char buffer[512]; 7067c478bd9Sstevel@tonic-gate char *line, *tmp, *ap, *fmt; 707*20f2cb7bSVasumathi Sundaram - Sun Microsystems int i, len = **opt; 7087c478bd9Sstevel@tonic-gate 7097c478bd9Sstevel@tonic-gate line = get_line(0, 0); 7107c478bd9Sstevel@tonic-gate 7117c478bd9Sstevel@tonic-gate (*opt)++; 7127c478bd9Sstevel@tonic-gate 7137c478bd9Sstevel@tonic-gate if (len >= 255) { 7147c478bd9Sstevel@tonic-gate (void) sprintf(line, "\t%s <TOO LONG>", msg); 7157c478bd9Sstevel@tonic-gate return; 7167c478bd9Sstevel@tonic-gate } 7177c478bd9Sstevel@tonic-gate 7187c478bd9Sstevel@tonic-gate for (printable = 1, tmp = (char *)(*opt), ap = buffer; 7197c478bd9Sstevel@tonic-gate tmp < (char *)&((*opt)[len]); tmp++) { 7207c478bd9Sstevel@tonic-gate if (isprint(*tmp)) 7217c478bd9Sstevel@tonic-gate *ap++ = *tmp; 7227c478bd9Sstevel@tonic-gate else { 7237c478bd9Sstevel@tonic-gate *ap++ = '.'; 7247c478bd9Sstevel@tonic-gate printable = 0; 7257c478bd9Sstevel@tonic-gate } 7267c478bd9Sstevel@tonic-gate } 7277c478bd9Sstevel@tonic-gate *ap = '\0'; 7287c478bd9Sstevel@tonic-gate 7297c478bd9Sstevel@tonic-gate if (!printable) { 7307c478bd9Sstevel@tonic-gate for (tmp = (char *)(*opt), ap = buffer; 731*20f2cb7bSVasumathi Sundaram - Sun Microsystems (tmp < (char *)&((*opt)[len])) && ((ap + 5) < &buffer[512]); 7327c478bd9Sstevel@tonic-gate tmp++) { 7337c478bd9Sstevel@tonic-gate ap += sprintf(ap, "0x%02X ", *(uchar_t *)(tmp)); 7347c478bd9Sstevel@tonic-gate } 735*20f2cb7bSVasumathi Sundaram - Sun Microsystems /* Truncate the trailing space */ 7367c478bd9Sstevel@tonic-gate *(--ap) = '\0'; 737*20f2cb7bSVasumathi Sundaram - Sun Microsystems /* More bytes to print in hex but no space in buffer */ 738*20f2cb7bSVasumathi Sundaram - Sun Microsystems if (tmp < (char *)&((*opt)[len])) { 739*20f2cb7bSVasumathi Sundaram - Sun Microsystems i = ap - buffer; 740*20f2cb7bSVasumathi Sundaram - Sun Microsystems buffer[i - 1] = '.'; 741*20f2cb7bSVasumathi Sundaram - Sun Microsystems buffer[i - 2] = '.'; 742*20f2cb7bSVasumathi Sundaram - Sun Microsystems buffer[i - 3] = '.'; 743*20f2cb7bSVasumathi Sundaram - Sun Microsystems } 7447c478bd9Sstevel@tonic-gate fmt = "%s\t%s (unprintable)"; 7457c478bd9Sstevel@tonic-gate } else { 7467c478bd9Sstevel@tonic-gate fmt = "%s\t\"%s\""; 7477c478bd9Sstevel@tonic-gate } 7487c478bd9Sstevel@tonic-gate (*opt) += len; 7497c478bd9Sstevel@tonic-gate (void) sprintf(line, fmt, msg, buffer); 7507c478bd9Sstevel@tonic-gate } 751