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