summaryrefslogtreecommitdiff
path: root/usr/src/cmd/cmd-inet/usr.sbin/snoop/snoop_dhcp.c
blob: b94c8246cb3d9394c2b684170c8654ca042025f5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
/*
 * CDDL HEADER START
 *
 * The contents of this file are subject to the terms of the
 * Common Development and Distribution License (the "License").
 * You may not use this file except in compliance with the License.
 *
 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
 * or http://www.opensolaris.org/os/licensing.
 * See the License for the specific language governing permissions
 * and limitations under the License.
 *
 * When distributing Covered Code, include this CDDL HEADER in each
 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
 * If applicable, add the following below this CDDL HEADER, with the
 * fields enclosed by brackets "[]" replaced with your own identifying
 * information: Portions Copyright [yyyy] [name of copyright owner]
 *
 * CDDL HEADER END
 */

/*
 * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
 * Use is subject to license terms.
 */

#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/sysmacros.h>
#include <netinet/in.h>
#include <netinet/dhcp.h>
#include <arpa/inet.h>
#include <dhcp_inittab.h>
#include <dhcp_symbol.h>
#include "snoop.h"

static const char *show_msgtype(unsigned char);
static int show_options(unsigned char *, int);
static void display_ip(int, char *, char *, unsigned char **);
static void display_ascii(char *, char *, unsigned char **);
static void display_number(char *, char *, unsigned char **);
static void display_ascii_hex(char *, unsigned char **);
static unsigned char bootmagic[] = BOOTMAGIC;	/* rfc 1048 */

static char *option_types[] = {
"",					/* 0 */
"Subnet Mask",				/* 1 */
"UTC Time Offset",			/* 2 */
"Router",				/* 3 */
"RFC868 Time Servers",			/* 4 */
"IEN 116 Name Servers",			/* 5 */
"DNS Servers",				/* 6 */
"UDP LOG Servers",			/* 7 */
"RFC 865 Cookie Servers",		/* 8 */
"RFC 1179 Line Printer Servers (LPR)",	/* 9 */
"Impress Servers",			/* 10 */
"RFC 887 Resource Location Servers",	/* 11 */
"Client Hostname",			/* 12 */
"Boot File size in 512 byte Blocks",	/* 13 */
"Merit Dump File",			/* 14 */
"DNS Domain Name",			/* 15 */
"SWAP Server",				/* 16 */
"Client Root Path",			/* 17 */
"BOOTP options extensions path",	/* 18 */
"IP Forwarding Flag",			/* 19 */
"NonLocal Source Routing Flag",		/* 20 */
"Policy Filters for NonLocal Routing",	/* 21 */
"Maximum Datagram Reassembly Size",	/* 22 */
"Default IP Time To Live",		/* 23 */
"Path MTU Aging Timeout",		/* 24 */
"Path MTU Size Plateau Table",		/* 25 */
"Interface MTU Size",			/* 26 */
"All Subnets are Local Flag",		/* 27 */
"Broadcast Address",			/* 28 */
"Perform Mask Discovery Flag",		/* 29 */
"Mask Supplier Flag",			/* 30 */
"Perform Router Discovery Flag",	/* 31 */
"Router Solicitation Address",		/* 32 */
"Static Routes",			/* 33 */
"Trailer Encapsulation Flag",		/* 34 */
"ARP Cache Timeout Seconds",		/* 35 */
"Ethernet Encapsulation Flag",		/* 36 */
"TCP Default Time To Live",		/* 37 */
"TCP Keepalive Interval Seconds",	/* 38 */
"TCP Keepalive Garbage Flag",		/* 39 */
"NIS Domainname",			/* 40 */
"NIS Servers",				/* 41 */
"Network Time Protocol Servers",	/* 42 */
"Vendor Specific Options",		/* 43 */
"NetBIOS RFC 1001/1002 Name Servers",	/* 44 */
"NetBIOS Datagram Dist. Servers",	/* 45 */
"NetBIOS Node Type",			/* 46 */
"NetBIOS Scope",			/* 47 */
"X Window Font Servers",		/* 48 */
"X Window Display Manager Servers",	/* 49 */
"Requested IP Address",			/* 50 */
"IP Address Lease Time",		/* 51 */
"Option Field Overload Flag",		/* 52 */
"DHCP Message Type",			/* 53 */
"DHCP Server Identifier",		/* 54 */
"Option Request List",			/* 55 */
"Error Message",			/* 56 */
"Maximum DHCP Message Size",		/* 57 */
"Renewal (T1) Time Value",		/* 58 */
"Rebinding (T2) Time Value",		/* 59 */
"Client Class Identifier =",		/* 60 */
"Client Identifier =",			/* 61 */
"Netware IP Domain =",			/* 62 */
"Netware IP Options =",			/* 63 */
"NIS+ v3 Client Domain Name =",		/* 64 */
"NIS+ v3 Server Addresses =",		/* 65 */
"TFTP Server Name",			/* 66 */
"Option BootFile Name",			/* 67 */
"Mobile IP Agents",			/* 68 */
"Simple Mail (SMTP) Servers",		/* 69 */
"Post Office (POP3) Servers",		/* 70 */
"Net News (NNTP) Servers",		/* 71 */
"WorldWideWeb Servers",			/* 72 */
"Finger Servers",			/* 73 */
"Internet Relay Chat (IRC) Servers",	/* 74 */
"StreetTalk Servers",			/* 75 */
"StreetTalk Directory Assist. Servers",	/* 76 */
"User Class Identifier",		/* 77 */
};

#define	OPTIONS_ARRAY_SIZE	78

int
interpret_dhcp(int flags, struct dhcp *dp, int len)
{
	if (flags & F_SUM) {
		if ((memcmp(dp->cookie, bootmagic, sizeof (bootmagic)) == 0) &&
		    (len >= BASE_PKT_SIZE + 3) &&
		    dp->options[0] == CD_DHCP_TYPE) {
			(void) sprintf(get_sum_line(),
			    "DHCP/BOOTP %s", show_msgtype(dp->options[2]));
		} else {
			switch (ntohs(dp->op)) {
			case BOOTREQUEST:
				(void) sprintf(get_sum_line(),
				    "DHCP/BOOTP BOOTREQUEST");
				break;
			case BOOTREPLY:
				(void) sprintf(get_sum_line(),
				    "DHCP/BOOTP BOOTREPLY");
				break;
			}
		}
	}
	if (flags & F_DTAIL) {
		show_header("DHCP: ", "Dynamic Host Configuration Protocol",
		    len);
		show_space();
		(void) sprintf(get_line((char *)(uintptr_t)dp->htype -
		    dlc_header, 1),
		    "Hardware address type (htype) =  %d (%s)", dp->htype,
		    arp_htype(dp->htype));
		(void) sprintf(get_line((char *)(uintptr_t)dp->hlen -
		    dlc_header, 1),
		    "Hardware address length (hlen) = %d octets", dp->hlen);
		(void) sprintf(get_line((char *)(uintptr_t)dp->hops -
		    dlc_header, 1),
		    "Relay agent hops = %d", dp->hops);
		(void) sprintf(get_line((char *)(uintptr_t)dp->xid -
		    dlc_header, 4),
		    "Transaction ID = 0x%x", ntohl(dp->xid));
		(void) sprintf(get_line((char *)(uintptr_t)dp->secs -
		    dlc_header, 2),
		    "Time since boot = %d seconds", ntohs(dp->secs));
		(void) sprintf(get_line((char *)(uintptr_t)dp->flags -
		    dlc_header, 2),
		    "Flags = 0x%.4x", ntohs(dp->flags));
		(void) sprintf(get_line((char *)&dp->ciaddr - dlc_header, 4),
		    "Client address (ciaddr) = %s", inet_ntoa(dp->ciaddr));
		(void) sprintf(get_line((char *)&dp->yiaddr - dlc_header, 4),
		    "Your client address (yiaddr) = %s",
		    inet_ntoa(dp->yiaddr));
		(void) sprintf(get_line((char *)&dp->siaddr - dlc_header, 4),
		    "Next server address (siaddr) = %s",
		    inet_ntoa(dp->siaddr));
		(void) sprintf(get_line((char *)&dp->giaddr - dlc_header, 4),
		    "Relay agent address (giaddr) = %s",
		    inet_ntoa(dp->giaddr));
		if (dp->htype == 1) {
			(void) sprintf(get_line((char *)dp->chaddr -
			    dlc_header, dp->hlen),
	"Client hardware address (chaddr) = %.2X:%.2X:%.2X:%.2X:%.2X:%.2X",
			    dp->chaddr[0],
			    dp->chaddr[1],
			    dp->chaddr[2],
			    dp->chaddr[3],
			    dp->chaddr[4],
			    dp->chaddr[5]);
		}
		/*
		 * Check cookie, process options
		 */
		if (memcmp(dp->cookie, bootmagic, sizeof (bootmagic)) != 0) {
			(void) sprintf(get_line(0, 0),
			    "Unrecognized cookie: 0x%.2X%.2X%.2X%.2X\n",
			    dp->cookie[0],
			    dp->cookie[1],
			    dp->cookie[2],
			    dp->cookie[3]);
			return (0);
		}
		show_space();
		show_header("DHCP: ", "(Options) field options", len);
		show_space();
		switch (show_options(dp->options, (len - BASE_PKT_SIZE))) {
		case 0:
			/* No option overloading */
			if (*(unsigned char *)(dp->sname) != '\0') {
				(void) sprintf(get_line(0, 0),
				    "Server Name = %s", dp->sname);
			}
			if (*(unsigned char *)(dp->file) != '\0') {
				(void) sprintf(get_line(0, 0),
				    "Boot File Name = %s", dp->file);
			}
			break;
		case 1:
			/* file field used */
			if (*(unsigned char *)(dp->sname) != '\0') {
				(void) sprintf(get_line(0, 0),
				    "Server Name = %s", dp->sname);
			}
			show_space();
			show_header("DHCP: ", "(File) field options", len);
			show_space();
			(void) show_options(dp->file, 128);
			break;
		case 2:
			/* sname field used for options */
			if (*(unsigned char *)(dp->file) != '\0') {
				(void) sprintf(get_line(0, 0),
				    "Boot File Name = %s", dp->file);
			}
			show_space();
			show_header("DHCP: ", "(Sname) field options", len);
			show_space();
			(void) show_options(dp->sname, 64);
			break;
		case 3:
			show_space();
			show_header("DHCP: ", "(File) field options", len);
			show_space();
			(void) show_options(dp->file, 128);
			show_space();
			show_header("DHCP: ", "(Sname) field options", len);
			show_space();
			(void) show_options(dp->sname, 64);
			break;
		};
	}
	return (len);
}

static int
show_options(unsigned char  *cp, int len)
{
	char *prmpt;
	unsigned char *end, *vend;
	unsigned char *start, save;
	int items, i;
	int nooverload = 0;
	ushort_t	s_buf;
	struct in_addr	tmp;
	char scratch[128];
	dhcp_symbol_t *entry;
	char *decoded_opt;
	int opt_len;

	start = cp;
	end = (unsigned char *)cp + len;

	while (start < end) {
		if (*start == CD_PAD) {
			start++;
			continue;
		}
		if (*start == CD_END)
			break;	/* done */

		save = *start++;
		switch (save) {
		/* Network order IP address(es) */
		case CD_SUBNETMASK:
		case CD_ROUTER_SOLICIT_SERV:
		case CD_BROADCASTADDR:
		case CD_REQUESTED_IP_ADDR:
		case CD_SERVER_ID:
			/* Single IP address */
			if (*start != 4) {
				(void) sprintf(get_line(0, 0),
				    "Error: Bad %s", option_types[save]);
			} else {
				start++;
				display_ip(1, "%s = %s", option_types[save],
				    &start);
			}
			break;
		case CD_ROUTER:
		case CD_TIMESERV:
		case CD_IEN116_NAME_SERV:
		case CD_DNSSERV:
		case CD_LOG_SERV:
		case CD_COOKIE_SERV:
		case CD_LPR_SERV:
		case CD_IMPRESS_SERV:
		case CD_RESOURCE_SERV:
		case CD_SWAP_SERV:
		case CD_NIS_SERV:
		case CD_NTP_SERV:
		case CD_NETBIOS_NAME_SERV:
		case CD_NETBIOS_DIST_SERV:
		case CD_XWIN_FONT_SERV:
		case CD_XWIN_DISP_SERV:
		case CD_MOBILE_IP_AGENT:
		case CD_SMTP_SERVS:
		case CD_POP3_SERVS:
		case CD_NNTP_SERVS:
		case CD_WWW_SERVS:
		case CD_FINGER_SERVS:
		case CD_IRC_SERVS:
		case CD_STREETTALK_SERVS:
		case CD_STREETTALK_DA_SERVS:
			/* Multiple IP addresses */
			if ((*start % 4) != 0) {
				(void) sprintf(get_line(0, 0),
				    "Error: Bad %s address",
				    option_types[save]);
			} else {
				items = *start++ / 4;
				display_ip(items, "%s at = %s",
				    option_types[save], &start);
			}
			break;
		case CD_TFTP_SERV_NAME:
		case CD_HOSTNAME:
		case CD_DUMP_FILE:
		case CD_DNSDOMAIN:
		case CD_ROOT_PATH:
		case CD_NIS_DOMAIN:
		case CD_NETBIOS_SCOPE:
		case CD_MESSAGE:
		case CD_OPT_BOOTFILE_NAME:
		case CD_USER_CLASS_ID:
			/* Ascii strings */
			display_ascii("%s = %s", option_types[save], &start);
			break;
		case CD_TIMEOFFSET:
		case CD_IPTTL:
		case CD_PATH_MTU_TIMEOUT:
		case CD_ARP_TIMEOUT:
		case CD_TCP_TTL:
		case CD_TCP_KALIVE_INTVL:
		case CD_T1_TIME:
		case CD_T2_TIME:
		case CD_LEASE_TIME:
			/* Number: seconds */
			display_number("%s = %d seconds", option_types[save],
			    &start);
			break;
		case CD_IP_FORWARDING_ON:
		case CD_NON_LCL_ROUTE_ON:
		case CD_ALL_SUBNETS_LCL_ON:
		case CD_MASK_DISCVRY_ON:
		case CD_MASK_SUPPLIER_ON:
		case CD_ROUTER_DISCVRY_ON:
		case CD_TRAILER_ENCAPS_ON:
		case CD_ETHERNET_ENCAPS_ON:
		case CD_TCP_KALIVE_GRBG_ON:
			/* Number:  hex flag */
			display_number("%s flag = 0x%x", option_types[save],
			    &start);
			break;
		case CD_MAXIPSIZE:
		case CD_MTU:
		case CD_MAX_DHCP_SIZE:
			/* Number: bytes */
			display_number("%s = %d bytes", option_types[save],
			    &start);
			break;
		case CD_CLASS_ID:
		case CD_CLIENT_ID:
		case CD_NW_IP_DOMAIN:
		case CD_NW_IP_OPTIONS:
			/* Hex ascii strings */
			display_ascii_hex(option_types[save], &start);
			break;
		case CD_BOOT_SIZE:
			display_number("%s = %d 512 byte blocks",
			    "Boot file size", &start);
			break;
		case CD_POLICY_FILTER:
			if ((*start % 8) != 0) {
				(void) sprintf(get_line(0, 0),
				    "Error: Bad Policy Filter option");
			} else {
				items = *start++ / 8;
				for (i = 0; i < items; i++) {
					display_ip(1,
					    "%s = %s",
					    "Policy Destination",
					    &start);
					display_ip(1, "%s = %s", "Mask",
					    &start);
				}
			}
			break;
		case CD_PATH_MTU_TABLE_SZ:
			if (*start % 2 != 0) {
				(void) sprintf(get_line(0, 0),
				    "Error: Bad Path MTU Table");
			} else {
				(void) sprintf(get_line(0, 0),
				    "\tPath MTU Plateau Table:");
				(void) sprintf(get_line(0, 0),
				    "\t=======================");
				items = *start / sizeof (ushort_t);
				++start;
				for (i = 0; i < items; i++) {
					if (IS_P2ALIGNED(start,
					    sizeof (ushort_t))) {
						/* LINTED: improper alignment */
						s_buf = *(ushort_t *)start;
					} else {
						memcpy((char *)&s_buf,
						    start, sizeof (short));
					}
					(void) sprintf(get_line(0, 0),
					    "\t\tEntry %d:\t\t%d", i,
					    ntohs(s_buf));
					start += sizeof (ushort_t);
				}
			}
			break;
		case CD_STATIC_ROUTE:
			if ((*start % 8) != 0) {
				(void) sprintf(get_line(0, 0),
				    "Error: Bad Static Route option: %d",
				    *start);
			} else {
				items = *start++ / 8;
				for (i = 0; i < items; i++) {
					memcpy((char *)&tmp, start,
					    sizeof (struct in_addr));
					(void) strcpy(scratch, inet_ntoa(tmp));
					start += sizeof (ulong_t);
					memcpy((char *)&tmp, start,
					    sizeof (struct in_addr));
					(void) sprintf(get_line(0, 0),
					    "Static route from %s to %s",
					    scratch, inet_ntoa(tmp));
					start += sizeof (ulong_t);
				}
			}
			break;
		case CD_VENDOR_SPEC:
			i = *start++;
			(void) sprintf(get_line(0, 0),
			    "Vendor-specific Options (%d total octets):", i);
			/*
			 * We don't know what these things are, so just
			 * display the option number, length, and value
			 * (hex).
			 */
			vend = (uchar_t *)((uchar_t *)start + i);
			while (start < vend && *start != CD_END) {
				if (*start == CD_PAD) {
					start++;
					continue;
				}
				(void) sprintf(scratch,
				    "\t(%.2d) %.2d octets", *start,
				    *(uchar_t *)((uchar_t *)start + 1));
				start++;
				display_ascii_hex(scratch, &start);
			}
			start = vend;	/* in case CD_END found */
			break;
		case CD_NETBIOS_NODE_TYPE:
			if (*start != 1) {
				(void) sprintf(get_line(0, 0),
				    "Error: Bad '%s' parameter",
				    option_types[CD_NETBIOS_NODE_TYPE]);
			} else {
				char *type;
				start++;
				switch (*start) {
				case 0x1:
					type = "Broadcast Node";
					break;
				case 0x2:
					type = "Point To Point Node";
					break;
				case 0x4:
					type = "Mixed Mode Node";
					break;
				case 0x8:
					type = "Hybrid Node";
					break;
				default:
					type = "??? Node";
					break;
				};
				(void) sprintf(get_line(0, 0),
				    "%s = %s (%d)",
				    option_types[CD_NETBIOS_NODE_TYPE],
				    type, *start);
				start++;
			}
			break;
		case CD_OPTION_OVERLOAD:
			if (*start != 1) {
				(void) sprintf(get_line(0, 0),
				    "Bad Option Overload value.");
			} else {
				start++;
				nooverload = *start++;
			}
			break;
		case CD_DHCP_TYPE:
			if (*start < 1 || *start > 7) {
				(void) sprintf(get_line(0, 0),
				    "Bad DHCP Message Type.");
			} else {
				start++;
				(void) sprintf(get_line(0, 0),
				    "Message type = %s",
				    show_msgtype(*start));
				start++;
			}
			break;
		case CD_REQUEST_LIST:
			opt_len = *start++;
			(void) sprintf(get_line(0, 0),
			    "Requested Options:");
			for (i = 0; i < opt_len; i++) {
				entry = NULL;
				if (*start < OPTIONS_ARRAY_SIZE) {
					prmpt = option_types[*start];
				} else {
					entry = inittab_getbycode(
					    ITAB_CAT_STANDARD|ITAB_CAT_SITE,
					    ITAB_CONS_SNOOP, *start);
					if (entry == NULL) {
						if (*start >= DHCP_SITE_OPT &&
						    *start <= DHCP_END_SITE) {
							prmpt = "Site Option";
						} else {
							prmpt = "Unrecognized "
							    "Option";
						}
					} else {
						prmpt = entry->ds_name;
					}
				}
				(void) sprintf(get_line(0, 0),
				    "\t%2d (%s)", *start, prmpt);
				start++;
				free(entry);
			}
			break;
		default:
			opt_len = *start++;
			entry = inittab_getbycode(
			    ITAB_CAT_STANDARD|ITAB_CAT_SITE,
			    ITAB_CONS_SNOOP, save);
			if (entry == NULL) {
				if (save >= DHCP_SITE_OPT &&
				    save <= DHCP_END_SITE)
					prmpt = "Site";
				else
					prmpt = "Unrecognized";
				decoded_opt = NULL;
			} else {
				if (save < OPTIONS_ARRAY_SIZE) {
					prmpt = option_types[save];
				} else {
					prmpt = entry->ds_name;
				}
				decoded_opt = inittab_decode(entry, start,
				    opt_len, B_TRUE);
			}
			if (decoded_opt == NULL) {
				(void) sprintf(get_line(0, 0),
				    "%s Option = %d, length = %d octets",
				    prmpt, save, opt_len);
				start--;
				display_ascii_hex("\tValue =", &start);
			} else {
				(void) sprintf(get_line(0, 0), "%s = %s", prmpt,
				    decoded_opt);
				start += opt_len;
				free(decoded_opt);
			}
			free(entry);
			break;
		};
	}
	return (nooverload);
}

static const char *
show_msgtype(unsigned char type)
{
	/*
	 * note: the ordering here allows direct indexing of the table
	 *	 based on the RFC2131 packet type value passed in.
	 */

	static const char *types[] = {
		"BOOTP",
		"DHCPDISCOVER", "DHCPOFFER",   "DHCPREQUEST", "DHCPDECLINE",
		"DHCPACK",    "DHCPNAK",      "DHCPRELEASE", "DHCPINFORM"
	};

	if (type >= (sizeof (types) / sizeof (*types)) || types[type] == NULL)
		return ("UNKNOWN");

	return (types[type]);
}

static void
display_ip(int items, char *fmt, char *msg, unsigned char **opt)
{
	struct in_addr tmp;
	int i;

	for (i = 0; i < items; i++) {
		memcpy((char *)&tmp, *opt, sizeof (struct in_addr));
		(void) sprintf(get_line(0, 0), fmt, msg, inet_ntoa(tmp));
		*opt += 4;
	}
}

static void
display_ascii(char *fmt, char *msg, unsigned char **opt)
{
	static unsigned char buf[256];
	int len = **opt;
	unsigned char slen = len;

	if (len >= sizeof (buf))
		len = sizeof (buf) - 1;
	(*opt)++;
	memcpy(buf, *opt, len);
	*(unsigned char *)(buf + len) = '\0';
	(void) sprintf(get_line(0, 0), fmt, msg, buf);
	(*opt) += slen;
}

static void
display_number(char *fmt, char *msg, unsigned char **opt)
{
	int len = **opt;
	unsigned long l_buf = 0;
	unsigned short s_buf = 0;

	if (len > 4) {
		(*opt)++;
		(void) sprintf(get_line(0, 0), fmt, msg, 0xdeadbeef);
		return;
	}
	switch (len) {
	case sizeof (uchar_t):
		(*opt)++;
		(void) sprintf(get_line(0, 0), fmt, msg, **opt);
		break;
	case sizeof (ushort_t):
		(*opt)++;
		if (IS_P2ALIGNED(*opt, sizeof (ushort_t)))
			/* LINTED: improper alignment */
			s_buf = *(unsigned short *)*opt;
		else
			memcpy((char *)&s_buf, *opt, len);
		(void) sprintf(get_line(0, 0), fmt, msg, ntohs(s_buf));
		break;
	case sizeof (ulong_t):
		(*opt)++;
		if (IS_P2ALIGNED(*opt, sizeof (ulong_t)))
			/* LINTED: improper alignment */
			l_buf = *(unsigned long *)*opt;
		else
			memcpy((char *)&l_buf, *opt, len);
		(void) sprintf(get_line(0, 0), fmt, msg, ntohl(l_buf));
		break;
	}
	(*opt) += len;
}

static void
display_ascii_hex(char *msg, unsigned char **opt)
{
	int printable;
	char	buffer[512];
	char  *line, *tmp, *ap, *fmt;
	int	i, len = **opt;

	line = get_line(0, 0);

	(*opt)++;

	if (len >= 255) {
		(void) sprintf(line, "\t%s <TOO LONG>", msg);
		return;
	}

	for (printable = 1, tmp = (char *)(*opt), ap = buffer;
	    tmp < (char *)&((*opt)[len]); tmp++) {
		if (isprint(*tmp))
			*ap++ = *tmp;
		else {
			*ap++ = '.';
			printable = 0;
		}
	}
	*ap = '\0';

	if (!printable) {
		for (tmp = (char *)(*opt), ap = buffer;
		    (tmp < (char *)&((*opt)[len])) && ((ap + 5) < &buffer[512]);
		    tmp++) {
			ap += sprintf(ap, "0x%02X ", *(uchar_t *)(tmp));
		}
		/* Truncate the trailing space */
		*(--ap) = '\0';
		/* More bytes to print in hex but no space in buffer */
		if (tmp < (char *)&((*opt)[len])) {
			i = ap - buffer;
			buffer[i - 1] = '.';
			buffer[i - 2] = '.';
			buffer[i - 3] = '.';
		}
		fmt = "%s\t%s (unprintable)";
	} else {
		fmt = "%s\t\"%s\"";
	}
	(*opt) += len;
	(void) sprintf(line, fmt, msg, buffer);
}