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