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