10Sstevel@tonic-gate /* 20Sstevel@tonic-gate * CDDL HEADER START 30Sstevel@tonic-gate * 40Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*1481Skcpoon * Common Development and Distribution License (the "License"). 6*1481Skcpoon * You may not use this file except in compliance with the License. 70Sstevel@tonic-gate * 80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 100Sstevel@tonic-gate * See the License for the specific language governing permissions 110Sstevel@tonic-gate * and limitations under the License. 120Sstevel@tonic-gate * 130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 180Sstevel@tonic-gate * 190Sstevel@tonic-gate * CDDL HEADER END 200Sstevel@tonic-gate */ 21*1481Skcpoon 220Sstevel@tonic-gate /* 23*1481Skcpoon * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 240Sstevel@tonic-gate * Use is subject to license terms. 250Sstevel@tonic-gate */ 260Sstevel@tonic-gate 270Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 280Sstevel@tonic-gate 290Sstevel@tonic-gate #include <ctype.h> 300Sstevel@tonic-gate #include <stdio.h> 310Sstevel@tonic-gate #include <stdlib.h> 320Sstevel@tonic-gate #include <fcntl.h> 330Sstevel@tonic-gate #include <string.h> 340Sstevel@tonic-gate #include <sys/types.h> 350Sstevel@tonic-gate #include <sys/socket.h> 360Sstevel@tonic-gate #include <sys/sysmacros.h> 370Sstevel@tonic-gate #include <netinet/in.h> 380Sstevel@tonic-gate #include <netinet/dhcp.h> 390Sstevel@tonic-gate #include <arpa/inet.h> 400Sstevel@tonic-gate #include <dhcp_inittab.h> 410Sstevel@tonic-gate #include <dhcp_symbol.h> 420Sstevel@tonic-gate #include "snoop.h" 430Sstevel@tonic-gate 440Sstevel@tonic-gate extern char *dlc_header; 450Sstevel@tonic-gate static char *show_htype(int); 460Sstevel@tonic-gate static const char *show_msgtype(unsigned char); 470Sstevel@tonic-gate static int show_options(unsigned char *, int); 480Sstevel@tonic-gate static void display_ip(int, char *, char *, unsigned char **); 490Sstevel@tonic-gate static void display_ascii(char *, char *, unsigned char **); 500Sstevel@tonic-gate static void display_number(char *, char *, unsigned char **); 510Sstevel@tonic-gate static void display_ascii_hex(char *, unsigned char **); 520Sstevel@tonic-gate static unsigned char bootmagic[] = BOOTMAGIC; /* rfc 1048 */ 530Sstevel@tonic-gate 540Sstevel@tonic-gate static char *option_types[] = { 550Sstevel@tonic-gate "", /* 0 */ 560Sstevel@tonic-gate "Subnet Mask", /* 1 */ 570Sstevel@tonic-gate "UTC Time Offset", /* 2 */ 580Sstevel@tonic-gate "Router", /* 3 */ 590Sstevel@tonic-gate "RFC868 Time Servers", /* 4 */ 600Sstevel@tonic-gate "IEN 116 Name Servers", /* 5 */ 610Sstevel@tonic-gate "DNS Servers", /* 6 */ 620Sstevel@tonic-gate "UDP LOG Servers", /* 7 */ 630Sstevel@tonic-gate "RFC 865 Cookie Servers", /* 8 */ 640Sstevel@tonic-gate "RFC 1179 Line Printer Servers (LPR)", /* 9 */ 650Sstevel@tonic-gate "Impress Servers", /* 10 */ 660Sstevel@tonic-gate "RFC 887 Resource Location Servers", /* 11 */ 670Sstevel@tonic-gate "Client Hostname", /* 12 */ 680Sstevel@tonic-gate "Boot File size in 512 byte Blocks", /* 13 */ 690Sstevel@tonic-gate "Merit Dump File", /* 14 */ 700Sstevel@tonic-gate "DNS Domain Name", /* 15 */ 710Sstevel@tonic-gate "SWAP Server", /* 16 */ 720Sstevel@tonic-gate "Client Root Path", /* 17 */ 730Sstevel@tonic-gate "BOOTP options extensions path", /* 18 */ 740Sstevel@tonic-gate "IP Forwarding Flag", /* 19 */ 750Sstevel@tonic-gate "NonLocal Source Routing Flag", /* 20 */ 760Sstevel@tonic-gate "Policy Filters for NonLocal Routing", /* 21 */ 770Sstevel@tonic-gate "Maximum Datagram Reassembly Size", /* 22 */ 780Sstevel@tonic-gate "Default IP Time To Live", /* 23 */ 790Sstevel@tonic-gate "Path MTU Aging Timeout", /* 24 */ 800Sstevel@tonic-gate "Path MTU Size Plateau Table", /* 25 */ 810Sstevel@tonic-gate "Interface MTU Size", /* 26 */ 820Sstevel@tonic-gate "All Subnets are Local Flag", /* 27 */ 830Sstevel@tonic-gate "Broadcast Address", /* 28 */ 840Sstevel@tonic-gate "Perform Mask Discovery Flag", /* 29 */ 850Sstevel@tonic-gate "Mask Supplier Flag", /* 30 */ 860Sstevel@tonic-gate "Perform Router Discovery Flag", /* 31 */ 870Sstevel@tonic-gate "Router Solicitation Address", /* 32 */ 880Sstevel@tonic-gate "Static Routes", /* 33 */ 890Sstevel@tonic-gate "Trailer Encapsulation Flag", /* 34 */ 900Sstevel@tonic-gate "ARP Cache Timeout Seconds", /* 35 */ 910Sstevel@tonic-gate "Ethernet Encapsulation Flag", /* 36 */ 920Sstevel@tonic-gate "TCP Default Time To Live", /* 37 */ 930Sstevel@tonic-gate "TCP Keepalive Interval Seconds", /* 38 */ 940Sstevel@tonic-gate "TCP Keepalive Garbage Flag", /* 39 */ 950Sstevel@tonic-gate "NIS Domainname", /* 40 */ 960Sstevel@tonic-gate "NIS Servers", /* 41 */ 970Sstevel@tonic-gate "Network Time Protocol Servers", /* 42 */ 980Sstevel@tonic-gate "Vendor Specific Options", /* 43 */ 990Sstevel@tonic-gate "NetBIOS RFC 1001/1002 Name Servers", /* 44 */ 1000Sstevel@tonic-gate "NetBIOS Datagram Dist. Servers", /* 45 */ 1010Sstevel@tonic-gate "NetBIOS Node Type", /* 46 */ 1020Sstevel@tonic-gate "NetBIOS Scope", /* 47 */ 1030Sstevel@tonic-gate "X Window Font Servers", /* 48 */ 1040Sstevel@tonic-gate "X Window Display Manager Servers", /* 49 */ 1050Sstevel@tonic-gate "Requested IP Address", /* 50 */ 1060Sstevel@tonic-gate "IP Address Lease Time", /* 51 */ 1070Sstevel@tonic-gate "Option Field Overload Flag", /* 52 */ 1080Sstevel@tonic-gate "DHCP Message Type", /* 53 */ 1090Sstevel@tonic-gate "DHCP Server Identifier", /* 54 */ 1100Sstevel@tonic-gate "Option Request List", /* 55 */ 1110Sstevel@tonic-gate "Error Message", /* 56 */ 1120Sstevel@tonic-gate "Maximum DHCP Message Size", /* 57 */ 1130Sstevel@tonic-gate "Renewal (T1) Time Value", /* 58 */ 1140Sstevel@tonic-gate "Rebinding (T2) Time Value", /* 59 */ 1150Sstevel@tonic-gate "Client Class Identifier =", /* 60 */ 1160Sstevel@tonic-gate "Client Identifier =", /* 61 */ 1170Sstevel@tonic-gate "Netware IP Domain =", /* 62 */ 1180Sstevel@tonic-gate "Netware IP Options =", /* 63 */ 1190Sstevel@tonic-gate "NISPLUS Domainname", /* 64 */ 1200Sstevel@tonic-gate "NISPLUS Servers", /* 65 */ 1210Sstevel@tonic-gate "TFTP Server Name", /* 66 */ 1220Sstevel@tonic-gate "Option BootFile Name", /* 67 */ 1230Sstevel@tonic-gate "Mobile IP Agents", /* 68 */ 1240Sstevel@tonic-gate "Simple Mail (SMTP) Servers", /* 69 */ 1250Sstevel@tonic-gate "Post Office (POP3) Servers", /* 70 */ 1260Sstevel@tonic-gate "Net News (NNTP) Servers", /* 71 */ 1270Sstevel@tonic-gate "WorldWideWeb Servers", /* 72 */ 1280Sstevel@tonic-gate "Finger Servers", /* 73 */ 1290Sstevel@tonic-gate "Internet Relay Chat (IRC) Servers", /* 74 */ 1300Sstevel@tonic-gate "StreetTalk Servers", /* 75 */ 1310Sstevel@tonic-gate "StreetTalk Directory Assist. Servers", /* 76 */ 1320Sstevel@tonic-gate "User Class Identifier", /* 77 */ 1330Sstevel@tonic-gate }; 1340Sstevel@tonic-gate 1350Sstevel@tonic-gate #define OPTIONS_ARRAY_SIZE 78 1360Sstevel@tonic-gate 1370Sstevel@tonic-gate int 1380Sstevel@tonic-gate interpret_dhcp(int flags, PKT *dp, int len) 1390Sstevel@tonic-gate { 1400Sstevel@tonic-gate if (flags & F_SUM) { 1410Sstevel@tonic-gate if ((memcmp(dp->cookie, bootmagic, sizeof (bootmagic)) == 0) && 1420Sstevel@tonic-gate (len >= BASE_PKT_SIZE + 3) && 1430Sstevel@tonic-gate dp->options[0] == CD_DHCP_TYPE) { 1440Sstevel@tonic-gate (void) sprintf(get_sum_line(), 1450Sstevel@tonic-gate "DHCP/BOOTP %s", show_msgtype(dp->options[2])); 1460Sstevel@tonic-gate } else { 1470Sstevel@tonic-gate switch (ntohs(dp->op)) { 1480Sstevel@tonic-gate case BOOTREQUEST: 1490Sstevel@tonic-gate (void) sprintf(get_sum_line(), 1500Sstevel@tonic-gate "DHCP/BOOTP BOOTREQUEST"); 1510Sstevel@tonic-gate break; 1520Sstevel@tonic-gate case BOOTREPLY: 1530Sstevel@tonic-gate (void) sprintf(get_sum_line(), 1540Sstevel@tonic-gate "DHCP/BOOTP BOOTREPLY"); 1550Sstevel@tonic-gate break; 1560Sstevel@tonic-gate } 1570Sstevel@tonic-gate } 1580Sstevel@tonic-gate } 1590Sstevel@tonic-gate if (flags & F_DTAIL) { 1600Sstevel@tonic-gate show_header("DHCP: ", "Dynamic Host Configuration Protocol", 1610Sstevel@tonic-gate len); 1620Sstevel@tonic-gate show_space(); 163410Skcpoon (void) sprintf(get_line((char *)(uintptr_t)dp->htype - 164410Skcpoon dlc_header, 1), 1650Sstevel@tonic-gate "Hardware address type (htype) = %d (%s)", dp->htype, 1660Sstevel@tonic-gate show_htype(dp->htype)); 167410Skcpoon (void) sprintf(get_line((char *)(uintptr_t)dp->hlen - 168410Skcpoon dlc_header, 1), 1690Sstevel@tonic-gate "Hardware address length (hlen) = %d octets", dp->hlen); 170410Skcpoon (void) sprintf(get_line((char *)(uintptr_t)dp->hops - 171410Skcpoon dlc_header, 1), 1720Sstevel@tonic-gate "Relay agent hops = %d", dp->hops); 173410Skcpoon (void) sprintf(get_line((char *)(uintptr_t)dp->xid - 174410Skcpoon dlc_header, 4), 1750Sstevel@tonic-gate "Transaction ID = 0x%x", ntohl(dp->xid)); 176410Skcpoon (void) sprintf(get_line((char *)(uintptr_t)dp->secs - 177410Skcpoon dlc_header, 2), 1780Sstevel@tonic-gate "Time since boot = %d seconds", ntohs(dp->secs)); 179410Skcpoon (void) sprintf(get_line((char *)(uintptr_t)dp->flags - 180410Skcpoon dlc_header, 2), 1810Sstevel@tonic-gate "Flags = 0x%.4x", ntohs(dp->flags)); 1820Sstevel@tonic-gate (void) sprintf(get_line((char *)&dp->ciaddr - dlc_header, 4), 1830Sstevel@tonic-gate "Client address (ciaddr) = %s", inet_ntoa(dp->ciaddr)); 1840Sstevel@tonic-gate (void) sprintf(get_line((char *)&dp->yiaddr - dlc_header, 4), 1850Sstevel@tonic-gate "Your client address (yiaddr) = %s", 1860Sstevel@tonic-gate inet_ntoa(dp->yiaddr)); 1870Sstevel@tonic-gate (void) sprintf(get_line((char *)&dp->siaddr - dlc_header, 4), 1880Sstevel@tonic-gate "Next server address (siaddr) = %s", 1890Sstevel@tonic-gate inet_ntoa(dp->siaddr)); 1900Sstevel@tonic-gate (void) sprintf(get_line((char *)&dp->giaddr - dlc_header, 4), 1910Sstevel@tonic-gate "Relay agent address (giaddr) = %s", 1920Sstevel@tonic-gate inet_ntoa(dp->giaddr)); 1930Sstevel@tonic-gate if (dp->htype == 1) { 1940Sstevel@tonic-gate (void) sprintf(get_line((char *)dp->chaddr - 1950Sstevel@tonic-gate dlc_header, dp->hlen), 1960Sstevel@tonic-gate "Client hardware address (chaddr) = %.2X:%.2X:%.2X:%.2X:%.2X:%.2X", 1970Sstevel@tonic-gate dp->chaddr[0], 1980Sstevel@tonic-gate dp->chaddr[1], 1990Sstevel@tonic-gate dp->chaddr[2], 2000Sstevel@tonic-gate dp->chaddr[3], 2010Sstevel@tonic-gate dp->chaddr[4], 2020Sstevel@tonic-gate dp->chaddr[5]); 2030Sstevel@tonic-gate } 2040Sstevel@tonic-gate /* 2050Sstevel@tonic-gate * Check cookie, process options 2060Sstevel@tonic-gate */ 2070Sstevel@tonic-gate if (memcmp(dp->cookie, bootmagic, sizeof (bootmagic)) != 0) { 2080Sstevel@tonic-gate (void) sprintf(get_line(0, 0), 2090Sstevel@tonic-gate "Unrecognized cookie: 0x%.2X%.2X%.2X%.2X\n", 2100Sstevel@tonic-gate dp->cookie[0], 2110Sstevel@tonic-gate dp->cookie[1], 2120Sstevel@tonic-gate dp->cookie[2], 2130Sstevel@tonic-gate dp->cookie[3]); 2140Sstevel@tonic-gate return (0); 2150Sstevel@tonic-gate } 2160Sstevel@tonic-gate show_space(); 2170Sstevel@tonic-gate show_header("DHCP: ", "(Options) field options", len); 2180Sstevel@tonic-gate show_space(); 2190Sstevel@tonic-gate switch (show_options(dp->options, (len - BASE_PKT_SIZE))) { 2200Sstevel@tonic-gate case 0: 2210Sstevel@tonic-gate /* No option overloading */ 2220Sstevel@tonic-gate if (*(unsigned char *)(dp->sname) != '\0') { 2230Sstevel@tonic-gate (void) sprintf(get_line(0, 0), 2240Sstevel@tonic-gate "Server Name = %s", dp->sname); 2250Sstevel@tonic-gate } 2260Sstevel@tonic-gate if (*(unsigned char *)(dp->file) != '\0') { 2270Sstevel@tonic-gate (void) sprintf(get_line(0, 0), 2280Sstevel@tonic-gate "Boot File Name = %s", dp->file); 2290Sstevel@tonic-gate } 2300Sstevel@tonic-gate break; 2310Sstevel@tonic-gate case 1: 2320Sstevel@tonic-gate /* file field used */ 2330Sstevel@tonic-gate if (*(unsigned char *)(dp->sname) != '\0') { 2340Sstevel@tonic-gate (void) sprintf(get_line(0, 0), 2350Sstevel@tonic-gate "Server Name = %s", dp->sname); 2360Sstevel@tonic-gate } 2370Sstevel@tonic-gate show_space(); 2380Sstevel@tonic-gate show_header("DHCP: ", "(File) field options", len); 2390Sstevel@tonic-gate show_space(); 2400Sstevel@tonic-gate (void) show_options(dp->file, 128); 2410Sstevel@tonic-gate break; 2420Sstevel@tonic-gate case 2: 2430Sstevel@tonic-gate /* sname field used for options */ 2440Sstevel@tonic-gate if (*(unsigned char *)(dp->file) != '\0') { 2450Sstevel@tonic-gate (void) sprintf(get_line(0, 0), 2460Sstevel@tonic-gate "Boot File Name = %s", dp->file); 2470Sstevel@tonic-gate } 2480Sstevel@tonic-gate show_space(); 2490Sstevel@tonic-gate show_header("DHCP: ", "(Sname) field options", len); 2500Sstevel@tonic-gate show_space(); 2510Sstevel@tonic-gate (void) show_options(dp->sname, 64); 2520Sstevel@tonic-gate break; 2530Sstevel@tonic-gate case 3: 2540Sstevel@tonic-gate show_space(); 2550Sstevel@tonic-gate show_header("DHCP: ", "(File) field options", len); 2560Sstevel@tonic-gate show_space(); 2570Sstevel@tonic-gate (void) show_options(dp->file, 128); 2580Sstevel@tonic-gate show_space(); 2590Sstevel@tonic-gate show_header("DHCP: ", "(Sname) field options", len); 2600Sstevel@tonic-gate show_space(); 2610Sstevel@tonic-gate (void) show_options(dp->sname, 64); 2620Sstevel@tonic-gate break; 2630Sstevel@tonic-gate }; 2640Sstevel@tonic-gate } 2650Sstevel@tonic-gate return (len); 2660Sstevel@tonic-gate } 2670Sstevel@tonic-gate static int 2680Sstevel@tonic-gate show_options(unsigned char *cp, int len) 2690Sstevel@tonic-gate { 2700Sstevel@tonic-gate char *prmpt; 2710Sstevel@tonic-gate unsigned char *end, *vend; 2720Sstevel@tonic-gate unsigned char *start, save; 2730Sstevel@tonic-gate int items, i; 2740Sstevel@tonic-gate int nooverload = 0; 2750Sstevel@tonic-gate ushort_t s_buf; 2760Sstevel@tonic-gate struct in_addr tmp; 2770Sstevel@tonic-gate char scratch[128]; 2780Sstevel@tonic-gate dhcp_symbol_t *entry; 2790Sstevel@tonic-gate char *decoded_opt; 2800Sstevel@tonic-gate int opt_len; 2810Sstevel@tonic-gate 2820Sstevel@tonic-gate start = cp; 2830Sstevel@tonic-gate end = (unsigned char *)cp + len; 2840Sstevel@tonic-gate 2850Sstevel@tonic-gate while (start < end) { 2860Sstevel@tonic-gate if (*start == CD_PAD) { 2870Sstevel@tonic-gate start++; 2880Sstevel@tonic-gate continue; 2890Sstevel@tonic-gate } 2900Sstevel@tonic-gate if (*start == CD_END) 2910Sstevel@tonic-gate break; /* done */ 2920Sstevel@tonic-gate 2930Sstevel@tonic-gate save = *start++; 2940Sstevel@tonic-gate switch (save) { 2950Sstevel@tonic-gate /* Network order IP address(es) */ 2960Sstevel@tonic-gate case CD_SUBNETMASK: 2970Sstevel@tonic-gate case CD_ROUTER_SOLICIT_SERV: 2980Sstevel@tonic-gate case CD_BROADCASTADDR: 2990Sstevel@tonic-gate case CD_REQUESTED_IP_ADDR: 3000Sstevel@tonic-gate case CD_SERVER_ID: 3010Sstevel@tonic-gate /* Single IP address */ 3020Sstevel@tonic-gate if (*start != 4) { 3030Sstevel@tonic-gate (void) sprintf(get_line(0, 0), 3040Sstevel@tonic-gate "Error: Bad %s", option_types[save]); 3050Sstevel@tonic-gate } else { 3060Sstevel@tonic-gate start++; 3070Sstevel@tonic-gate display_ip(1, "%s = %s", option_types[save], 3080Sstevel@tonic-gate &start); 3090Sstevel@tonic-gate } 3100Sstevel@tonic-gate break; 3110Sstevel@tonic-gate case CD_ROUTER: 3120Sstevel@tonic-gate case CD_TIMESERV: 3130Sstevel@tonic-gate case CD_IEN116_NAME_SERV: 3140Sstevel@tonic-gate case CD_DNSSERV: 3150Sstevel@tonic-gate case CD_LOG_SERV: 3160Sstevel@tonic-gate case CD_COOKIE_SERV: 3170Sstevel@tonic-gate case CD_LPR_SERV: 3180Sstevel@tonic-gate case CD_IMPRESS_SERV: 3190Sstevel@tonic-gate case CD_RESOURCE_SERV: 3200Sstevel@tonic-gate case CD_SWAP_SERV: 3210Sstevel@tonic-gate case CD_NIS_SERV: 3220Sstevel@tonic-gate case CD_NTP_SERV: 3230Sstevel@tonic-gate case CD_NETBIOS_NAME_SERV: 3240Sstevel@tonic-gate case CD_NETBIOS_DIST_SERV: 3250Sstevel@tonic-gate case CD_XWIN_FONT_SERV: 3260Sstevel@tonic-gate case CD_XWIN_DISP_SERV: 3270Sstevel@tonic-gate case CD_NISPLUS_SERVS: 3280Sstevel@tonic-gate case CD_MOBILE_IP_AGENT: 3290Sstevel@tonic-gate case CD_SMTP_SERVS: 3300Sstevel@tonic-gate case CD_POP3_SERVS: 3310Sstevel@tonic-gate case CD_NNTP_SERVS: 3320Sstevel@tonic-gate case CD_WWW_SERVS: 3330Sstevel@tonic-gate case CD_FINGER_SERVS: 3340Sstevel@tonic-gate case CD_IRC_SERVS: 3350Sstevel@tonic-gate case CD_STREETTALK_SERVS: 3360Sstevel@tonic-gate case CD_STREETTALK_DA_SERVS: 3370Sstevel@tonic-gate /* Multiple IP addresses */ 3380Sstevel@tonic-gate if ((*start % 4) != 0) { 3390Sstevel@tonic-gate (void) sprintf(get_line(0, 0), 3400Sstevel@tonic-gate "Error: Bad %s address", 3410Sstevel@tonic-gate option_types[save]); 3420Sstevel@tonic-gate } else { 343*1481Skcpoon items = *start++ / 4; 344*1481Skcpoon display_ip(items, "%s at = %s", 3450Sstevel@tonic-gate option_types[save], &start); 3460Sstevel@tonic-gate } 3470Sstevel@tonic-gate break; 3480Sstevel@tonic-gate case CD_TFTP_SERV_NAME: 3490Sstevel@tonic-gate case CD_HOSTNAME: 3500Sstevel@tonic-gate case CD_DUMP_FILE: 3510Sstevel@tonic-gate case CD_DNSDOMAIN: 3520Sstevel@tonic-gate case CD_ROOT_PATH: 3530Sstevel@tonic-gate case CD_NIS_DOMAIN: 3540Sstevel@tonic-gate case CD_NETBIOS_SCOPE: 3550Sstevel@tonic-gate case CD_MESSAGE: 3560Sstevel@tonic-gate case CD_NISPLUS_DMAIN: 3570Sstevel@tonic-gate case CD_OPT_BOOTFILE_NAME: 3580Sstevel@tonic-gate case CD_USER_CLASS_ID: 3590Sstevel@tonic-gate /* Ascii strings */ 3600Sstevel@tonic-gate display_ascii("%s = %s", option_types[save], &start); 3610Sstevel@tonic-gate break; 3620Sstevel@tonic-gate case CD_TIMEOFFSET: 3630Sstevel@tonic-gate case CD_IPTTL: 3640Sstevel@tonic-gate case CD_PATH_MTU_TIMEOUT: 3650Sstevel@tonic-gate case CD_ARP_TIMEOUT: 3660Sstevel@tonic-gate case CD_TCP_TTL: 3670Sstevel@tonic-gate case CD_TCP_KALIVE_INTVL: 3680Sstevel@tonic-gate case CD_T1_TIME: 3690Sstevel@tonic-gate case CD_T2_TIME: 3700Sstevel@tonic-gate case CD_LEASE_TIME: 3710Sstevel@tonic-gate /* Number: seconds */ 3720Sstevel@tonic-gate display_number("%s = %d seconds", option_types[save], 3730Sstevel@tonic-gate &start); 3740Sstevel@tonic-gate break; 3750Sstevel@tonic-gate case CD_IP_FORWARDING_ON: 3760Sstevel@tonic-gate case CD_NON_LCL_ROUTE_ON: 3770Sstevel@tonic-gate case CD_ALL_SUBNETS_LCL_ON: 3780Sstevel@tonic-gate case CD_MASK_DISCVRY_ON: 3790Sstevel@tonic-gate case CD_MASK_SUPPLIER_ON: 3800Sstevel@tonic-gate case CD_ROUTER_DISCVRY_ON: 3810Sstevel@tonic-gate case CD_TRAILER_ENCAPS_ON: 3820Sstevel@tonic-gate case CD_ETHERNET_ENCAPS_ON: 3830Sstevel@tonic-gate case CD_TCP_KALIVE_GRBG_ON: 3840Sstevel@tonic-gate /* Number: hex flag */ 3850Sstevel@tonic-gate display_number("%s flag = 0x%x", option_types[save], 3860Sstevel@tonic-gate &start); 3870Sstevel@tonic-gate break; 3880Sstevel@tonic-gate case CD_MAXIPSIZE: 3890Sstevel@tonic-gate case CD_MTU: 3900Sstevel@tonic-gate case CD_MAX_DHCP_SIZE: 3910Sstevel@tonic-gate /* Number: bytes */ 3920Sstevel@tonic-gate display_number("%s = %d bytes", option_types[save], 3930Sstevel@tonic-gate &start); 3940Sstevel@tonic-gate break; 3950Sstevel@tonic-gate case CD_CLASS_ID: 3960Sstevel@tonic-gate case CD_CLIENT_ID: 3970Sstevel@tonic-gate case CD_NW_IP_DOMAIN: 3980Sstevel@tonic-gate case CD_NW_IP_OPTIONS: 3990Sstevel@tonic-gate /* Hex ascii strings */ 4000Sstevel@tonic-gate display_ascii_hex(option_types[save], &start); 4010Sstevel@tonic-gate break; 4020Sstevel@tonic-gate case CD_BOOT_SIZE: 4030Sstevel@tonic-gate display_number("%s = %d 512 byte blocks", 4040Sstevel@tonic-gate "Boot file size", &start); 4050Sstevel@tonic-gate break; 4060Sstevel@tonic-gate case CD_POLICY_FILTER: 4070Sstevel@tonic-gate if ((*start % 8) != 0) { 4080Sstevel@tonic-gate (void) sprintf(get_line(0, 0), 4090Sstevel@tonic-gate "Error: Bad Policy Filter option"); 4100Sstevel@tonic-gate } else { 4110Sstevel@tonic-gate items = *start++ / 8; 4120Sstevel@tonic-gate for (i = 0; i < items; i++) { 4130Sstevel@tonic-gate display_ip(1, 4140Sstevel@tonic-gate "%s = %s", 4150Sstevel@tonic-gate "Policy Destination", 4160Sstevel@tonic-gate &start); 4170Sstevel@tonic-gate display_ip(1, "%s = %s", "Mask", 4180Sstevel@tonic-gate &start); 4190Sstevel@tonic-gate } 4200Sstevel@tonic-gate } 4210Sstevel@tonic-gate break; 4220Sstevel@tonic-gate case CD_PATH_MTU_TABLE_SZ: 4230Sstevel@tonic-gate if (*start % 2 != 0) { 4240Sstevel@tonic-gate (void) sprintf(get_line(0, 0), 4250Sstevel@tonic-gate "Error: Bad Path MTU Table"); 4260Sstevel@tonic-gate } else { 4270Sstevel@tonic-gate (void) sprintf(get_line(0, 0), 4280Sstevel@tonic-gate "\tPath MTU Plateau Table:"); 4290Sstevel@tonic-gate (void) sprintf(get_line(0, 0), 4300Sstevel@tonic-gate "\t======================="); 4310Sstevel@tonic-gate items = *start / sizeof (ushort_t); 4320Sstevel@tonic-gate ++start; 4330Sstevel@tonic-gate for (i = 0; i < items; i++) { 4340Sstevel@tonic-gate if (IS_P2ALIGNED(start, 4350Sstevel@tonic-gate sizeof (ushort_t))) { 4360Sstevel@tonic-gate /* LINTED: improper alignment */ 4370Sstevel@tonic-gate s_buf = *(ushort_t *)start; 4380Sstevel@tonic-gate } else { 4390Sstevel@tonic-gate memcpy((char *)&s_buf, 4400Sstevel@tonic-gate start, sizeof (short)); 4410Sstevel@tonic-gate } 4420Sstevel@tonic-gate (void) sprintf(get_line(0, 0), 4430Sstevel@tonic-gate "\t\tEntry %d:\t\t%d", i, 4440Sstevel@tonic-gate ntohs(s_buf)); 4450Sstevel@tonic-gate start += sizeof (ushort_t); 4460Sstevel@tonic-gate } 4470Sstevel@tonic-gate } 4480Sstevel@tonic-gate break; 4490Sstevel@tonic-gate case CD_STATIC_ROUTE: 4500Sstevel@tonic-gate if ((*start % 8) != 0) { 4510Sstevel@tonic-gate (void) sprintf(get_line(0, 0), 4520Sstevel@tonic-gate "Error: Bad Static Route option: %d", 4530Sstevel@tonic-gate *start); 4540Sstevel@tonic-gate } else { 4550Sstevel@tonic-gate items = *start++ / 8; 4560Sstevel@tonic-gate for (i = 0; i < items; i++) { 4570Sstevel@tonic-gate memcpy((char *)&tmp, start, 4580Sstevel@tonic-gate sizeof (struct in_addr)); 4590Sstevel@tonic-gate (void) strcpy(scratch, inet_ntoa(tmp)); 4600Sstevel@tonic-gate start += sizeof (ulong_t); 4610Sstevel@tonic-gate memcpy((char *)&tmp, start, 4620Sstevel@tonic-gate sizeof (struct in_addr)); 4630Sstevel@tonic-gate (void) sprintf(get_line(0, 0), 4640Sstevel@tonic-gate "Static route from %s to %s", 4650Sstevel@tonic-gate scratch, inet_ntoa(tmp)); 4660Sstevel@tonic-gate start += sizeof (ulong_t); 4670Sstevel@tonic-gate } 4680Sstevel@tonic-gate } 4690Sstevel@tonic-gate break; 4700Sstevel@tonic-gate case CD_VENDOR_SPEC: 4710Sstevel@tonic-gate i = *start++; 4720Sstevel@tonic-gate (void) sprintf(get_line(0, 0), 4730Sstevel@tonic-gate "Vendor-specific Options (%d total octets):", i); 4740Sstevel@tonic-gate /* 4750Sstevel@tonic-gate * We don't know what these things are, so just 4760Sstevel@tonic-gate * display the option number, length, and value 4770Sstevel@tonic-gate * (hex). 4780Sstevel@tonic-gate */ 4790Sstevel@tonic-gate vend = (uchar_t *)((uchar_t *)start + i); 4800Sstevel@tonic-gate while (start < vend && *start != CD_END) { 4810Sstevel@tonic-gate if (*start == CD_PAD) { 4820Sstevel@tonic-gate start++; 4830Sstevel@tonic-gate continue; 4840Sstevel@tonic-gate } 4850Sstevel@tonic-gate (void) sprintf(scratch, 4860Sstevel@tonic-gate "\t(%.2d) %.2d octets", *start, 4870Sstevel@tonic-gate *(uchar_t *)((uchar_t *)start + 1)); 4880Sstevel@tonic-gate start++; 4890Sstevel@tonic-gate display_ascii_hex(scratch, &start); 4900Sstevel@tonic-gate } 4910Sstevel@tonic-gate start = vend; /* in case CD_END found */ 4920Sstevel@tonic-gate break; 4930Sstevel@tonic-gate case CD_NETBIOS_NODE_TYPE: 4940Sstevel@tonic-gate if (*start != 1) { 4950Sstevel@tonic-gate (void) sprintf(get_line(0, 0), 4960Sstevel@tonic-gate "Error: Bad '%s' parameter", 4970Sstevel@tonic-gate option_types[CD_NETBIOS_NODE_TYPE]); 4980Sstevel@tonic-gate } else { 4990Sstevel@tonic-gate char *type; 5000Sstevel@tonic-gate start++; 5010Sstevel@tonic-gate switch (*start) { 5020Sstevel@tonic-gate case 0x1: 5030Sstevel@tonic-gate type = "Broadcast Node"; 5040Sstevel@tonic-gate break; 5050Sstevel@tonic-gate case 0x2: 5060Sstevel@tonic-gate type = "Point To Point Node"; 5070Sstevel@tonic-gate break; 5080Sstevel@tonic-gate case 0x4: 5090Sstevel@tonic-gate type = "Mixed Mode Node"; 5100Sstevel@tonic-gate break; 5110Sstevel@tonic-gate case 0x8: 5120Sstevel@tonic-gate type = "Hybrid Node"; 5130Sstevel@tonic-gate break; 5140Sstevel@tonic-gate default: 5150Sstevel@tonic-gate type = "??? Node"; 5160Sstevel@tonic-gate break; 5170Sstevel@tonic-gate }; 5180Sstevel@tonic-gate (void) sprintf(get_line(0, 0), 5190Sstevel@tonic-gate "%s = %s (%d)", 5200Sstevel@tonic-gate option_types[CD_NETBIOS_NODE_TYPE], 5210Sstevel@tonic-gate type, *start); 5220Sstevel@tonic-gate start++; 5230Sstevel@tonic-gate } 5240Sstevel@tonic-gate break; 5250Sstevel@tonic-gate case CD_OPTION_OVERLOAD: 5260Sstevel@tonic-gate if (*start != 1) { 5270Sstevel@tonic-gate (void) sprintf(get_line(0, 0), 5280Sstevel@tonic-gate "Bad Option Overload value."); 5290Sstevel@tonic-gate } else { 5300Sstevel@tonic-gate start++; 5310Sstevel@tonic-gate nooverload = *start++; 5320Sstevel@tonic-gate } 5330Sstevel@tonic-gate break; 5340Sstevel@tonic-gate case CD_DHCP_TYPE: 5350Sstevel@tonic-gate if (*start < 1 || *start > 7) { 5360Sstevel@tonic-gate (void) sprintf(get_line(0, 0), 5370Sstevel@tonic-gate "Bad DHCP Message Type."); 5380Sstevel@tonic-gate } else { 5390Sstevel@tonic-gate start++; 5400Sstevel@tonic-gate (void) sprintf(get_line(0, 0), 5410Sstevel@tonic-gate "Message type = %s", 5420Sstevel@tonic-gate show_msgtype(*start)); 5430Sstevel@tonic-gate start++; 5440Sstevel@tonic-gate } 5450Sstevel@tonic-gate break; 5460Sstevel@tonic-gate case CD_REQUEST_LIST: 5470Sstevel@tonic-gate opt_len = *start++; 5480Sstevel@tonic-gate (void) sprintf(get_line(0, 0), 5490Sstevel@tonic-gate "Requested Options:"); 5500Sstevel@tonic-gate for (i = 0; i < opt_len; i++) { 5510Sstevel@tonic-gate entry = NULL; 5520Sstevel@tonic-gate if (*start < OPTIONS_ARRAY_SIZE) { 5530Sstevel@tonic-gate prmpt = option_types[*start]; 5540Sstevel@tonic-gate } else { 5550Sstevel@tonic-gate entry = inittab_getbycode( 5560Sstevel@tonic-gate ITAB_CAT_STANDARD|ITAB_CAT_SITE, 5570Sstevel@tonic-gate ITAB_CONS_SNOOP, *start); 5580Sstevel@tonic-gate if (entry == NULL) { 5590Sstevel@tonic-gate if (*start >= DHCP_SITE_OPT && 5600Sstevel@tonic-gate *start <= DHCP_END_SITE) { 5610Sstevel@tonic-gate prmpt = "Site Option"; 5620Sstevel@tonic-gate } else { 5630Sstevel@tonic-gate prmpt = "Unrecognized " 5640Sstevel@tonic-gate "Option"; 5650Sstevel@tonic-gate } 5660Sstevel@tonic-gate } else { 5670Sstevel@tonic-gate prmpt = entry->ds_name; 5680Sstevel@tonic-gate } 5690Sstevel@tonic-gate } 5700Sstevel@tonic-gate (void) sprintf(get_line(0, 0), 5710Sstevel@tonic-gate "\t%2d (%s)", *start, prmpt); 5720Sstevel@tonic-gate start++; 5730Sstevel@tonic-gate free(entry); 5740Sstevel@tonic-gate } 5750Sstevel@tonic-gate break; 5760Sstevel@tonic-gate default: 5770Sstevel@tonic-gate opt_len = *start++; 5780Sstevel@tonic-gate entry = inittab_getbycode( 5790Sstevel@tonic-gate ITAB_CAT_STANDARD|ITAB_CAT_SITE, 5800Sstevel@tonic-gate ITAB_CONS_SNOOP, save); 5810Sstevel@tonic-gate if (entry == NULL) { 5820Sstevel@tonic-gate if (save >= DHCP_SITE_OPT && 5830Sstevel@tonic-gate save <= DHCP_END_SITE) 5840Sstevel@tonic-gate prmpt = "Site"; 5850Sstevel@tonic-gate else 5860Sstevel@tonic-gate prmpt = "Unrecognized"; 5870Sstevel@tonic-gate decoded_opt = NULL; 5880Sstevel@tonic-gate } else { 5890Sstevel@tonic-gate if (save < OPTIONS_ARRAY_SIZE) { 5900Sstevel@tonic-gate prmpt = option_types[save]; 5910Sstevel@tonic-gate } else { 5920Sstevel@tonic-gate prmpt = entry->ds_name; 5930Sstevel@tonic-gate } 5940Sstevel@tonic-gate decoded_opt = inittab_decode(entry, start, 5950Sstevel@tonic-gate opt_len, B_TRUE); 5960Sstevel@tonic-gate } 5970Sstevel@tonic-gate if (decoded_opt == NULL) { 5980Sstevel@tonic-gate (void) sprintf(get_line(0, 0), 5990Sstevel@tonic-gate "%s Option = %d, length = %d octets", 6000Sstevel@tonic-gate prmpt, save, opt_len); 6010Sstevel@tonic-gate start--; 6020Sstevel@tonic-gate display_ascii_hex("\tValue =", &start); 6030Sstevel@tonic-gate } else { 6040Sstevel@tonic-gate (void) sprintf(get_line(0, 0), "%s = %s", prmpt, 6050Sstevel@tonic-gate decoded_opt); 6060Sstevel@tonic-gate start += opt_len; 6070Sstevel@tonic-gate free(decoded_opt); 6080Sstevel@tonic-gate } 6090Sstevel@tonic-gate free(entry); 6100Sstevel@tonic-gate break; 6110Sstevel@tonic-gate }; 6120Sstevel@tonic-gate } 6130Sstevel@tonic-gate return (nooverload); 6140Sstevel@tonic-gate } 6150Sstevel@tonic-gate static char * 6160Sstevel@tonic-gate show_htype(int t) 6170Sstevel@tonic-gate { 6180Sstevel@tonic-gate switch (t) { 6190Sstevel@tonic-gate case 1: 6200Sstevel@tonic-gate return ("Ethernet (10Mb)"); 6210Sstevel@tonic-gate case 2: 6220Sstevel@tonic-gate return ("Experimental Ethernet (3MB)"); 6230Sstevel@tonic-gate case 3: 6240Sstevel@tonic-gate return ("Amateur Radio AX.25"); 6250Sstevel@tonic-gate case 4: 6260Sstevel@tonic-gate return ("Proteon ProNET Token Ring"); 6270Sstevel@tonic-gate case 5: 6280Sstevel@tonic-gate return ("Chaos"); 6290Sstevel@tonic-gate case 6: 6300Sstevel@tonic-gate return ("IEEE 802"); 6310Sstevel@tonic-gate case 7: 6320Sstevel@tonic-gate return ("ARCNET"); 6330Sstevel@tonic-gate case 8: 6340Sstevel@tonic-gate return ("Hyperchannel"); 6350Sstevel@tonic-gate case 9: 6360Sstevel@tonic-gate return ("Lanstar"); 6370Sstevel@tonic-gate case 10: 6380Sstevel@tonic-gate return ("Autonet"); 6390Sstevel@tonic-gate case 11: 6400Sstevel@tonic-gate return ("LocalTalk"); 6410Sstevel@tonic-gate case 12: 6420Sstevel@tonic-gate return ("LocalNet"); 6430Sstevel@tonic-gate case 13: 6440Sstevel@tonic-gate return ("Ultra Link"); 6450Sstevel@tonic-gate case 14: 6460Sstevel@tonic-gate return ("SMDS"); 6470Sstevel@tonic-gate case 15: 6480Sstevel@tonic-gate return ("Frame Relay"); 6490Sstevel@tonic-gate case 16: 6500Sstevel@tonic-gate return ("ATM"); 6510Sstevel@tonic-gate case ARPHRD_IB: 6520Sstevel@tonic-gate return ("IPIB"); 6530Sstevel@tonic-gate }; 6540Sstevel@tonic-gate return ("UNKNOWN"); 6550Sstevel@tonic-gate } 6560Sstevel@tonic-gate static const char * 6570Sstevel@tonic-gate show_msgtype(unsigned char type) 6580Sstevel@tonic-gate { 6590Sstevel@tonic-gate /* 6600Sstevel@tonic-gate * note: the ordering here allows direct indexing of the table 6610Sstevel@tonic-gate * based on the RFC2131 packet type value passed in. 6620Sstevel@tonic-gate */ 6630Sstevel@tonic-gate 6640Sstevel@tonic-gate static const char *types[] = { 6650Sstevel@tonic-gate "BOOTP", 6660Sstevel@tonic-gate "DHCPDISCOVER", "DHCPOFFER", "DHCPREQUEST", "DHCPDECLINE", 6670Sstevel@tonic-gate "DHCPACK", "DHCPNAK", "DHCPRELEASE", "DHCPINFORM" 6680Sstevel@tonic-gate }; 6690Sstevel@tonic-gate 6700Sstevel@tonic-gate if (type > (sizeof (types) / sizeof (*types)) || types[type] == NULL) 6710Sstevel@tonic-gate return ("UNKNOWN"); 6720Sstevel@tonic-gate 6730Sstevel@tonic-gate return (types[type]); 6740Sstevel@tonic-gate } 6750Sstevel@tonic-gate static void 6760Sstevel@tonic-gate display_ip(int items, char *fmt, char *msg, unsigned char **opt) 6770Sstevel@tonic-gate { 6780Sstevel@tonic-gate struct in_addr tmp; 6790Sstevel@tonic-gate int i; 6800Sstevel@tonic-gate 6810Sstevel@tonic-gate for (i = 0; i < items; i++) { 6820Sstevel@tonic-gate memcpy((char *)&tmp, *opt, sizeof (struct in_addr)); 6830Sstevel@tonic-gate (void) sprintf(get_line(0, 0), fmt, msg, inet_ntoa(tmp)); 6840Sstevel@tonic-gate *opt += 4; 6850Sstevel@tonic-gate } 6860Sstevel@tonic-gate } 6870Sstevel@tonic-gate static void 6880Sstevel@tonic-gate display_ascii(char *fmt, char *msg, unsigned char **opt) 6890Sstevel@tonic-gate { 6900Sstevel@tonic-gate static unsigned char buf[256]; 691410Skcpoon int len = **opt; 6920Sstevel@tonic-gate unsigned char slen = len; 6930Sstevel@tonic-gate 6940Sstevel@tonic-gate if (len >= sizeof (buf)) 6950Sstevel@tonic-gate len = sizeof (buf) - 1; 6960Sstevel@tonic-gate (*opt)++; 6970Sstevel@tonic-gate memcpy(buf, *opt, len); 6980Sstevel@tonic-gate *(unsigned char *)(buf + len) = '\0'; 6990Sstevel@tonic-gate (void) sprintf(get_line(0, 0), fmt, msg, buf); 7000Sstevel@tonic-gate (*opt) += slen; 7010Sstevel@tonic-gate } 7020Sstevel@tonic-gate static void 7030Sstevel@tonic-gate display_number(char *fmt, char *msg, unsigned char **opt) 7040Sstevel@tonic-gate { 7050Sstevel@tonic-gate int len = **opt; 7060Sstevel@tonic-gate unsigned long l_buf = 0; 7070Sstevel@tonic-gate unsigned short s_buf = 0; 7080Sstevel@tonic-gate 7090Sstevel@tonic-gate if (len > 4) { 7100Sstevel@tonic-gate (*opt)++; 7110Sstevel@tonic-gate (void) sprintf(get_line(0, 0), fmt, msg, 0xdeadbeef); 7120Sstevel@tonic-gate return; 7130Sstevel@tonic-gate } 7140Sstevel@tonic-gate switch (len) { 7150Sstevel@tonic-gate case sizeof (uchar_t): 7160Sstevel@tonic-gate (*opt)++; 7170Sstevel@tonic-gate (void) sprintf(get_line(0, 0), fmt, msg, **opt); 7180Sstevel@tonic-gate break; 7190Sstevel@tonic-gate case sizeof (ushort_t): 7200Sstevel@tonic-gate (*opt)++; 7210Sstevel@tonic-gate if (IS_P2ALIGNED(*opt, sizeof (ushort_t))) 7220Sstevel@tonic-gate /* LINTED: improper alignment */ 7230Sstevel@tonic-gate s_buf = *(unsigned short *)*opt; 7240Sstevel@tonic-gate else 7250Sstevel@tonic-gate memcpy((char *)&s_buf, *opt, len); 7260Sstevel@tonic-gate (void) sprintf(get_line(0, 0), fmt, msg, ntohs(s_buf)); 7270Sstevel@tonic-gate break; 7280Sstevel@tonic-gate case sizeof (ulong_t): 7290Sstevel@tonic-gate (*opt)++; 7300Sstevel@tonic-gate if (IS_P2ALIGNED(*opt, sizeof (ulong_t))) 7310Sstevel@tonic-gate /* LINTED: improper alignment */ 7320Sstevel@tonic-gate l_buf = *(unsigned long *)*opt; 7330Sstevel@tonic-gate else 7340Sstevel@tonic-gate memcpy((char *)&l_buf, *opt, len); 7350Sstevel@tonic-gate (void) sprintf(get_line(0, 0), fmt, msg, ntohl(l_buf)); 7360Sstevel@tonic-gate break; 7370Sstevel@tonic-gate } 7380Sstevel@tonic-gate (*opt) += len; 7390Sstevel@tonic-gate } 7400Sstevel@tonic-gate static void 7410Sstevel@tonic-gate display_ascii_hex(char *msg, unsigned char **opt) 7420Sstevel@tonic-gate { 7430Sstevel@tonic-gate int printable; 7440Sstevel@tonic-gate char buffer[512]; 7450Sstevel@tonic-gate char *line, *tmp, *ap, *fmt; 7460Sstevel@tonic-gate int i, j, len = **opt; 7470Sstevel@tonic-gate 7480Sstevel@tonic-gate line = get_line(0, 0); 7490Sstevel@tonic-gate 7500Sstevel@tonic-gate (*opt)++; 7510Sstevel@tonic-gate 7520Sstevel@tonic-gate if (len >= 255) { 7530Sstevel@tonic-gate (void) sprintf(line, "\t%s <TOO LONG>", msg); 7540Sstevel@tonic-gate return; 7550Sstevel@tonic-gate } 7560Sstevel@tonic-gate 7570Sstevel@tonic-gate for (printable = 1, tmp = (char *)(*opt), ap = buffer; 7580Sstevel@tonic-gate tmp < (char *)&((*opt)[len]); tmp++) { 7590Sstevel@tonic-gate if (isprint(*tmp)) 7600Sstevel@tonic-gate *ap++ = *tmp; 7610Sstevel@tonic-gate else { 7620Sstevel@tonic-gate *ap++ = '.'; 7630Sstevel@tonic-gate printable = 0; 7640Sstevel@tonic-gate } 7650Sstevel@tonic-gate } 7660Sstevel@tonic-gate *ap = '\0'; 7670Sstevel@tonic-gate 7680Sstevel@tonic-gate if (!printable) { 7690Sstevel@tonic-gate for (tmp = (char *)(*opt), ap = buffer; 7700Sstevel@tonic-gate (tmp < (char *)&((*opt)[len])) && (ap < &buffer[512]); 7710Sstevel@tonic-gate tmp++) { 7720Sstevel@tonic-gate ap += sprintf(ap, "0x%02X ", *(uchar_t *)(tmp)); 7730Sstevel@tonic-gate } 7740Sstevel@tonic-gate *(--ap) = '\0'; 7750Sstevel@tonic-gate i = ap - buffer; 7760Sstevel@tonic-gate fmt = "%s\t%s (unprintable)"; 7770Sstevel@tonic-gate } else { 7780Sstevel@tonic-gate i = strlen(buffer); 7790Sstevel@tonic-gate fmt = "%s\t\"%s\""; 7800Sstevel@tonic-gate } 7810Sstevel@tonic-gate (*opt) += len; 7820Sstevel@tonic-gate j = strlen(msg) + (MAXLINE / 2) - 30; 7830Sstevel@tonic-gate if (i > j) { 7840Sstevel@tonic-gate buffer[j - 1] = '.'; 7850Sstevel@tonic-gate buffer[j - 2] = '.'; 7860Sstevel@tonic-gate buffer[j - 3] = '.'; 7870Sstevel@tonic-gate buffer[j] = '\0'; 7880Sstevel@tonic-gate } 7890Sstevel@tonic-gate (void) sprintf(line, fmt, msg, buffer); 7900Sstevel@tonic-gate } 791