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