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