Move tcpdump-3.9/ to tcpdump/. No need for a versioned dir.
[dragonfly.git] / contrib / tcpdump / print-bootp.c
... / ...
CommitLineData
1/*
2 * Copyright (c) 1990, 1991, 1993, 1994, 1995, 1996, 1997
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that: (1) source code distributions
7 * retain the above copyright notice and this paragraph in its entirety, (2)
8 * distributions including binary code include the above copyright notice and
9 * this paragraph in its entirety in the documentation or other materials
10 * provided with the distribution, and (3) all advertising materials mentioning
11 * features or use of this software display the following acknowledgement:
12 * ``This product includes software developed by the University of California,
13 * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
14 * the University nor the names of its contributors may be used to endorse
15 * or promote products derived from this software without specific prior
16 * written permission.
17 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
18 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
19 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
20 *
21 * Format and print bootp packets.
22 */
23#ifndef lint
24static const char rcsid[] _U_ =
25 "@(#) $Header: /tcpdump/master/tcpdump/print-bootp.c,v 1.78.2.9 2007/08/21 22:02:08 guy Exp $ (LBL)";
26#endif
27
28#ifdef HAVE_CONFIG_H
29#include "config.h"
30#endif
31
32#include <tcpdump-stdinc.h>
33
34#include <stdio.h>
35#include <string.h>
36
37#include "interface.h"
38#include "addrtoname.h"
39#include "extract.h"
40#include "ether.h"
41#include "bootp.h"
42
43static void rfc1048_print(const u_char *);
44static void cmu_print(const u_char *);
45static char *client_fqdn_flags(u_int flags);
46
47static char tstr[] = " [|bootp]";
48
49static const struct tok bootp_flag_values[] = {
50 { 0x8000, "Broadcast" },
51 { 0, NULL}
52};
53
54static const struct tok bootp_op_values[] = {
55 { BOOTPREQUEST, "Request" },
56 { BOOTPREPLY, "Reply" },
57 { 0, NULL}
58};
59
60/*
61 * Print bootp requests
62 */
63void
64bootp_print(register const u_char *cp, u_int length)
65{
66 register const struct bootp *bp;
67 static const u_char vm_cmu[4] = VM_CMU;
68 static const u_char vm_rfc1048[4] = VM_RFC1048;
69
70 bp = (const struct bootp *)cp;
71 TCHECK(bp->bp_op);
72
73 printf("BOOTP/DHCP, %s",
74 tok2str(bootp_op_values, "unknown (0x%02x)", bp->bp_op));
75
76 if (bp->bp_htype == 1 && bp->bp_hlen == 6 && bp->bp_op == BOOTPREQUEST) {
77 TCHECK2(bp->bp_chaddr[0], 6);
78 printf(" from %s", etheraddr_string(bp->bp_chaddr));
79 }
80
81 printf(", length %u", length);
82
83 if (!vflag)
84 return;
85
86 TCHECK(bp->bp_secs);
87
88 /* The usual hardware address type is 1 (10Mb Ethernet) */
89 if (bp->bp_htype != 1)
90 printf(", htype %d", bp->bp_htype);
91
92 /* The usual length for 10Mb Ethernet address is 6 bytes */
93 if (bp->bp_htype != 1 || bp->bp_hlen != 6)
94 printf(", hlen %d", bp->bp_hlen);
95
96 /* Only print interesting fields */
97 if (bp->bp_hops)
98 printf(", hops %d", bp->bp_hops);
99 if (bp->bp_xid)
100 printf(", xid 0x%x", EXTRACT_32BITS(&bp->bp_xid));
101 if (bp->bp_secs)
102 printf(", secs %d", EXTRACT_16BITS(&bp->bp_secs));
103
104 printf(", Flags [%s]",
105 bittok2str(bootp_flag_values, "none", EXTRACT_16BITS(&bp->bp_flags)));
106 if (vflag > 1)
107 printf(" (0x%04x)", EXTRACT_16BITS(&bp->bp_flags));
108
109 /* Client's ip address */
110 TCHECK(bp->bp_ciaddr);
111 if (bp->bp_ciaddr.s_addr)
112 printf("\n\t Client-IP %s", ipaddr_string(&bp->bp_ciaddr));
113
114 /* 'your' ip address (bootp client) */
115 TCHECK(bp->bp_yiaddr);
116 if (bp->bp_yiaddr.s_addr)
117 printf("\n\t Your-IP %s", ipaddr_string(&bp->bp_yiaddr));
118
119 /* Server's ip address */
120 TCHECK(bp->bp_siaddr);
121 if (bp->bp_siaddr.s_addr)
122 printf("\n\t Server-IP %s", ipaddr_string(&bp->bp_siaddr));
123
124 /* Gateway's ip address */
125 TCHECK(bp->bp_giaddr);
126 if (bp->bp_giaddr.s_addr)
127 printf("\n\t Gateway-IP %s", ipaddr_string(&bp->bp_giaddr));
128
129 /* Client's Ethernet address */
130 if (bp->bp_htype == 1 && bp->bp_hlen == 6) {
131 TCHECK2(bp->bp_chaddr[0], 6);
132 printf("\n\t Client-Ethernet-Address %s", etheraddr_string(bp->bp_chaddr));
133 }
134
135 TCHECK2(bp->bp_sname[0], 1); /* check first char only */
136 if (*bp->bp_sname) {
137 printf("\n\t sname \"");
138 if (fn_print(bp->bp_sname, snapend)) {
139 putchar('"');
140 fputs(tstr + 1, stdout);
141 return;
142 }
143 putchar('"');
144 }
145 TCHECK2(bp->bp_file[0], 1); /* check first char only */
146 if (*bp->bp_file) {
147 printf("\n\t file \"");
148 if (fn_print(bp->bp_file, snapend)) {
149 putchar('"');
150 fputs(tstr + 1, stdout);
151 return;
152 }
153 putchar('"');
154 }
155
156 /* Decode the vendor buffer */
157 TCHECK(bp->bp_vend[0]);
158 if (memcmp((const char *)bp->bp_vend, vm_rfc1048,
159 sizeof(u_int32_t)) == 0)
160 rfc1048_print(bp->bp_vend);
161 else if (memcmp((const char *)bp->bp_vend, vm_cmu,
162 sizeof(u_int32_t)) == 0)
163 cmu_print(bp->bp_vend);
164 else {
165 u_int32_t ul;
166
167 ul = EXTRACT_32BITS(&bp->bp_vend);
168 if (ul != 0)
169 printf("\n\t Vendor-#0x%x", ul);
170 }
171
172 return;
173trunc:
174 fputs(tstr, stdout);
175}
176
177/*
178 * The first character specifies the format to print:
179 * i - ip address (32 bits)
180 * p - ip address pairs (32 bits + 32 bits)
181 * l - long (32 bits)
182 * L - unsigned long (32 bits)
183 * s - short (16 bits)
184 * b - period-seperated decimal bytes (variable length)
185 * x - colon-seperated hex bytes (variable length)
186 * a - ascii string (variable length)
187 * B - on/off (8 bits)
188 * $ - special (explicit code to handle)
189 */
190static struct tok tag2str[] = {
191/* RFC1048 tags */
192 { TAG_PAD, " PAD" },
193 { TAG_SUBNET_MASK, "iSubnet-Mask" }, /* subnet mask (RFC950) */
194 { TAG_TIME_OFFSET, "LTime-Zone" }, /* seconds from UTC */
195 { TAG_GATEWAY, "iDefault-Gateway" }, /* default gateway */
196 { TAG_TIME_SERVER, "iTime-Server" }, /* time servers (RFC868) */
197 { TAG_NAME_SERVER, "iIEN-Name-Server" }, /* IEN name servers (IEN116) */
198 { TAG_DOMAIN_SERVER, "iDomain-Name-Server" }, /* domain name (RFC1035) */
199 { TAG_LOG_SERVER, "iLOG" }, /* MIT log servers */
200 { TAG_COOKIE_SERVER, "iCS" }, /* cookie servers (RFC865) */
201 { TAG_LPR_SERVER, "iLPR-Server" }, /* lpr server (RFC1179) */
202 { TAG_IMPRESS_SERVER, "iIM" }, /* impress servers (Imagen) */
203 { TAG_RLP_SERVER, "iRL" }, /* resource location (RFC887) */
204 { TAG_HOSTNAME, "aHostname" }, /* ascii hostname */
205 { TAG_BOOTSIZE, "sBS" }, /* 512 byte blocks */
206 { TAG_END, " END" },
207/* RFC1497 tags */
208 { TAG_DUMPPATH, "aDP" },
209 { TAG_DOMAINNAME, "aDomain-Name" },
210 { TAG_SWAP_SERVER, "iSS" },
211 { TAG_ROOTPATH, "aRP" },
212 { TAG_EXTPATH, "aEP" },
213/* RFC2132 tags */
214 { TAG_IP_FORWARD, "BIPF" },
215 { TAG_NL_SRCRT, "BSRT" },
216 { TAG_PFILTERS, "pPF" },
217 { TAG_REASS_SIZE, "sRSZ" },
218 { TAG_DEF_TTL, "bTTL" },
219 { TAG_MTU_TIMEOUT, "lMTU-Timeout" },
220 { TAG_MTU_TABLE, "sMTU-Table" },
221 { TAG_INT_MTU, "sMTU" },
222 { TAG_LOCAL_SUBNETS, "BLSN" },
223 { TAG_BROAD_ADDR, "iBR" },
224 { TAG_DO_MASK_DISC, "BMD" },
225 { TAG_SUPPLY_MASK, "BMS" },
226 { TAG_DO_RDISC, "BRouter-Discovery" },
227 { TAG_RTR_SOL_ADDR, "iRSA" },
228 { TAG_STATIC_ROUTE, "pStatic-Route" },
229 { TAG_USE_TRAILERS, "BUT" },
230 { TAG_ARP_TIMEOUT, "lAT" },
231 { TAG_ETH_ENCAP, "BIE" },
232 { TAG_TCP_TTL, "bTT" },
233 { TAG_TCP_KEEPALIVE, "lKI" },
234 { TAG_KEEPALIVE_GO, "BKG" },
235 { TAG_NIS_DOMAIN, "aYD" },
236 { TAG_NIS_SERVERS, "iYS" },
237 { TAG_NTP_SERVERS, "iNTP" },
238 { TAG_VENDOR_OPTS, "bVendor-Option" },
239 { TAG_NETBIOS_NS, "iNetbios-Name-Server" },
240 { TAG_NETBIOS_DDS, "iWDD" },
241 { TAG_NETBIOS_NODE, "$Netbios-Node" },
242 { TAG_NETBIOS_SCOPE, "aNetbios-Scope" },
243 { TAG_XWIN_FS, "iXFS" },
244 { TAG_XWIN_DM, "iXDM" },
245 { TAG_NIS_P_DOMAIN, "sN+D" },
246 { TAG_NIS_P_SERVERS, "iN+S" },
247 { TAG_MOBILE_HOME, "iMH" },
248 { TAG_SMPT_SERVER, "iSMTP" },
249 { TAG_POP3_SERVER, "iPOP3" },
250 { TAG_NNTP_SERVER, "iNNTP" },
251 { TAG_WWW_SERVER, "iWWW" },
252 { TAG_FINGER_SERVER, "iFG" },
253 { TAG_IRC_SERVER, "iIRC" },
254 { TAG_STREETTALK_SRVR, "iSTS" },
255 { TAG_STREETTALK_STDA, "iSTDA" },
256 { TAG_REQUESTED_IP, "iRequested-IP" },
257 { TAG_IP_LEASE, "lLease-Time" },
258 { TAG_OPT_OVERLOAD, "$OO" },
259 { TAG_TFTP_SERVER, "aTFTP" },
260 { TAG_BOOTFILENAME, "aBF" },
261 { TAG_DHCP_MESSAGE, " DHCP-Message" },
262 { TAG_SERVER_ID, "iServer-ID" },
263 { TAG_PARM_REQUEST, "bParameter-Request" },
264 { TAG_MESSAGE, "aMSG" },
265 { TAG_MAX_MSG_SIZE, "sMSZ" },
266 { TAG_RENEWAL_TIME, "lRN" },
267 { TAG_REBIND_TIME, "lRB" },
268 { TAG_VENDOR_CLASS, "aVendor-Class" },
269 { TAG_CLIENT_ID, "$Client-ID" },
270/* RFC 2485 */
271 { TAG_OPEN_GROUP_UAP, "aUAP" },
272/* RFC 2563 */
273 { TAG_DISABLE_AUTOCONF, "BNOAUTO" },
274/* RFC 2610 */
275 { TAG_SLP_DA, "bSLP-DA" }, /*"b" is a little wrong */
276 { TAG_SLP_SCOPE, "bSLP-SCOPE" }, /*"b" is a little wrong */
277/* RFC 2937 */
278 { TAG_NS_SEARCH, "sNSSEARCH" }, /* XXX 's' */
279/* RFC 3011 */
280 { TAG_IP4_SUBNET_SELECT, "iSUBNET" },
281/* RFC 3442 */
282 { TAG_CLASSLESS_STATIC_RT, "$Classless-Static-Route" },
283 { TAG_CLASSLESS_STA_RT_MS, "$Classless-Static-Route-Microsoft" },
284/* http://www.iana.org/assignments/bootp-dhcp-extensions/index.htm */
285 { TAG_USER_CLASS, "aCLASS" },
286 { TAG_SLP_NAMING_AUTH, "aSLP-NA" },
287 { TAG_CLIENT_FQDN, "$FQDN" },
288 { TAG_AGENT_CIRCUIT, "$Agent-Information" },
289 { TAG_AGENT_REMOTE, "bARMT" },
290 { TAG_AGENT_MASK, "bAMSK" },
291 { TAG_TZ_STRING, "aTZSTR" },
292 { TAG_FQDN_OPTION, "bFQDNS" }, /* XXX 'b' */
293 { TAG_AUTH, "bAUTH" }, /* XXX 'b' */
294 { TAG_VINES_SERVERS, "iVINES" },
295 { TAG_SERVER_RANK, "sRANK" },
296 { TAG_CLIENT_ARCH, "sARCH" },
297 { TAG_CLIENT_NDI, "bNDI" }, /* XXX 'b' */
298 { TAG_CLIENT_GUID, "bGUID" }, /* XXX 'b' */
299 { TAG_LDAP_URL, "aLDAP" },
300 { TAG_6OVER4, "i6o4" },
301 { TAG_PRINTER_NAME, "aPRTR" },
302 { TAG_MDHCP_SERVER, "bMDHCP" }, /* XXX 'b' */
303 { TAG_IPX_COMPAT, "bIPX" }, /* XXX 'b' */
304 { TAG_NETINFO_PARENT, "iNI" },
305 { TAG_NETINFO_PARENT_TAG, "aNITAG" },
306 { TAG_URL, "aURL" },
307 { TAG_FAILOVER, "bFAIL" }, /* XXX 'b' */
308 { 0, NULL }
309};
310/* 2-byte extended tags */
311static struct tok xtag2str[] = {
312 { 0, NULL }
313};
314
315/* DHCP "options overload" types */
316static struct tok oo2str[] = {
317 { 1, "file" },
318 { 2, "sname" },
319 { 3, "file+sname" },
320 { 0, NULL }
321};
322
323/* NETBIOS over TCP/IP node type options */
324static struct tok nbo2str[] = {
325 { 0x1, "b-node" },
326 { 0x2, "p-node" },
327 { 0x4, "m-node" },
328 { 0x8, "h-node" },
329 { 0, NULL }
330};
331
332/* ARP Hardware types, for Client-ID option */
333static struct tok arp2str[] = {
334 { 0x1, "ether" },
335 { 0x6, "ieee802" },
336 { 0x7, "arcnet" },
337 { 0xf, "frelay" },
338 { 0x17, "strip" },
339 { 0x18, "ieee1394" },
340 { 0, NULL }
341};
342
343static struct tok dhcp_msg_values[] = {
344 { DHCPDISCOVER, "Discover" },
345 { DHCPOFFER, "Offer" },
346 { DHCPREQUEST, "Request" },
347 { DHCPDECLINE, "Decline" },
348 { DHCPACK, "ACK" },
349 { DHCPNAK, "NACK" },
350 { DHCPRELEASE, "Release" },
351 { DHCPINFORM, "Inform" },
352 { 0, NULL }
353};
354
355#define AGENT_SUBOPTION_CIRCUIT_ID 1
356static struct tok agent_suboption_values[] = {
357 { AGENT_SUBOPTION_CIRCUIT_ID, "Circuit-ID" },
358 { 0, NULL }
359};
360
361
362static void
363rfc1048_print(register const u_char *bp)
364{
365 register u_int16_t tag;
366 register u_int len;
367 register const char *cp;
368 register char c;
369 int first, idx;
370 u_int32_t ul;
371 u_int16_t us;
372 u_int8_t uc, subopt, suboptlen;
373
374 printf("\n\t Vendor-rfc1048 Extensions");
375
376 /* Step over magic cookie */
377 printf("\n\t Magic Cookie 0x%08x", EXTRACT_32BITS(bp));
378 bp += sizeof(int32_t);
379
380 /* Loop while we there is a tag left in the buffer */
381 while (TTEST2(*bp, 1)) {
382 tag = *bp++;
383 if (tag == TAG_PAD && vflag < 3)
384 continue;
385 if (tag == TAG_END && vflag < 3)
386 return;
387 if (tag == TAG_EXTENDED_OPTION) {
388 TCHECK2(*(bp + 1), 2);
389 tag = EXTRACT_16BITS(bp + 1);
390 /* XXX we don't know yet if the IANA will
391 * preclude overlap of 1-byte and 2-byte spaces.
392 * If not, we need to offset tag after this step.
393 */
394 cp = tok2str(xtag2str, "?xT%u", tag);
395 } else
396 cp = tok2str(tag2str, "?T%u", tag);
397 c = *cp++;
398
399 if (tag == TAG_PAD || tag == TAG_END)
400 len = 0;
401 else {
402 /* Get the length; check for truncation */
403 TCHECK2(*bp, 1);
404 len = *bp++;
405 }
406
407 printf("\n\t %s Option %u, length %u%s", cp, tag, len,
408 len > 0 ? ": " : "");
409
410 if (tag == TAG_PAD && vflag > 2) {
411 u_int ntag = 1;
412 while (TTEST2(*bp, 1) && *bp == TAG_PAD) {
413 bp++;
414 ntag++;
415 }
416 if (ntag > 1)
417 printf(", occurs %u", ntag);
418 }
419
420 if (!TTEST2(*bp, len)) {
421 printf("[|rfc1048 %u]", len);
422 return;
423 }
424
425 if (tag == TAG_DHCP_MESSAGE && len == 1) {
426 uc = *bp++;
427 printf("%s", tok2str(dhcp_msg_values, "Unknown (%u)", uc));
428 continue;
429 }
430
431 if (tag == TAG_PARM_REQUEST) {
432 idx = 0;
433 while (len-- > 0) {
434 uc = *bp++;
435 cp = tok2str(tag2str, "?Option %u", uc);
436 if (idx % 4 == 0)
437 printf("\n\t ");
438 else
439 printf(", ");
440 printf("%s", cp + 1);
441 idx++;
442 }
443 continue;
444 }
445
446 if (tag == TAG_EXTENDED_REQUEST) {
447 first = 1;
448 while (len > 1) {
449 len -= 2;
450 us = EXTRACT_16BITS(bp);
451 bp += 2;
452 cp = tok2str(xtag2str, "?xT%u", us);
453 if (!first)
454 putchar('+');
455 printf("%s", cp + 1);
456 first = 0;
457 }
458 continue;
459 }
460
461 /* Print data */
462 if (c == '?') {
463 /* Base default formats for unknown tags on data size */
464 if (len & 1)
465 c = 'b';
466 else if (len & 2)
467 c = 's';
468 else
469 c = 'l';
470 }
471 first = 1;
472 switch (c) {
473
474 case 'a':
475 /* ascii strings */
476 putchar('"');
477 if (fn_printn(bp, len, snapend)) {
478 putchar('"');
479 goto trunc;
480 }
481 putchar('"');
482 bp += len;
483 len = 0;
484 break;
485
486 case 'i':
487 case 'l':
488 case 'L':
489 /* ip addresses/32-bit words */
490 while (len >= sizeof(ul)) {
491 if (!first)
492 putchar(',');
493 ul = EXTRACT_32BITS(bp);
494 if (c == 'i') {
495 ul = htonl(ul);
496 printf("%s", ipaddr_string(&ul));
497 } else if (c == 'L')
498 printf("%d", ul);
499 else
500 printf("%u", ul);
501 bp += sizeof(ul);
502 len -= sizeof(ul);
503 first = 0;
504 }
505 break;
506
507 case 'p':
508 /* IP address pairs */
509 while (len >= 2*sizeof(ul)) {
510 if (!first)
511 putchar(',');
512 memcpy((char *)&ul, (const char *)bp, sizeof(ul));
513 printf("(%s:", ipaddr_string(&ul));
514 bp += sizeof(ul);
515 memcpy((char *)&ul, (const char *)bp, sizeof(ul));
516 printf("%s)", ipaddr_string(&ul));
517 bp += sizeof(ul);
518 len -= 2*sizeof(ul);
519 first = 0;
520 }
521 break;
522
523 case 's':
524 /* shorts */
525 while (len >= sizeof(us)) {
526 if (!first)
527 putchar(',');
528 us = EXTRACT_16BITS(bp);
529 printf("%u", us);
530 bp += sizeof(us);
531 len -= sizeof(us);
532 first = 0;
533 }
534 break;
535
536 case 'B':
537 /* boolean */
538 while (len > 0) {
539 if (!first)
540 putchar(',');
541 switch (*bp) {
542 case 0:
543 putchar('N');
544 break;
545 case 1:
546 putchar('Y');
547 break;
548 default:
549 printf("%u?", *bp);
550 break;
551 }
552 ++bp;
553 --len;
554 first = 0;
555 }
556 break;
557
558 case 'b':
559 case 'x':
560 default:
561 /* Bytes */
562 while (len > 0) {
563 if (!first)
564 putchar(c == 'x' ? ':' : '.');
565 if (c == 'x')
566 printf("%02x", *bp);
567 else
568 printf("%u", *bp);
569 ++bp;
570 --len;
571 first = 0;
572 }
573 break;
574
575 case '$':
576 /* Guys we can't handle with one of the usual cases */
577 switch (tag) {
578
579 case TAG_NETBIOS_NODE:
580 /* this option should be at least 1 byte long */
581 if (len < 1) {
582 printf("ERROR: option %u len %u < 1 bytes",
583 TAG_NETBIOS_NODE, len);
584 bp += len;
585 len = 0;
586 break;
587 }
588 tag = *bp++;
589 --len;
590 fputs(tok2str(nbo2str, NULL, tag), stdout);
591 break;
592
593 case TAG_OPT_OVERLOAD:
594 /* this option should be at least 1 byte long */
595 if (len < 1) {
596 printf("ERROR: option %u len %u < 1 bytes",
597 TAG_OPT_OVERLOAD, len);
598 bp += len;
599 len = 0;
600 break;
601 }
602 tag = *bp++;
603 --len;
604 fputs(tok2str(oo2str, NULL, tag), stdout);
605 break;
606
607 case TAG_CLIENT_FQDN:
608 /* this option should be at least 3 bytes long */
609 if (len < 3) {
610 printf("ERROR: option %u len %u < 3 bytes",
611 TAG_CLIENT_FQDN, len);
612 bp += len;
613 len = 0;
614 break;
615 }
616 if (*bp)
617 printf("[%s] ", client_fqdn_flags(*bp));
618 bp++;
619 if (*bp || *(bp+1))
620 printf("%u/%u ", *bp, *(bp+1));
621 bp += 2;
622 putchar('"');
623 if (fn_printn(bp, len - 3, snapend)) {
624 putchar('"');
625 goto trunc;
626 }
627 putchar('"');
628 bp += len - 3;
629 len = 0;
630 break;
631
632 case TAG_CLIENT_ID:
633 { int type;
634
635 /* this option should be at least 1 byte long */
636 if (len < 1) {
637 printf("ERROR: option %u len %u < 1 bytes",
638 TAG_CLIENT_ID, len);
639 bp += len;
640 len = 0;
641 break;
642 }
643 type = *bp++;
644 len--;
645 if (type == 0) {
646 putchar('"');
647 if (fn_printn(bp, len, snapend)) {
648 putchar('"');
649 goto trunc;
650 }
651 putchar('"');
652 bp += len;
653 len = 0;
654 break;
655 } else {
656 printf("%s ", tok2str(arp2str, "hardware-type %u,", type));
657 while (len > 0) {
658 if (!first)
659 putchar(':');
660 printf("%02x", *bp);
661 ++bp;
662 --len;
663 first = 0;
664 }
665 }
666 break;
667 }
668
669 case TAG_AGENT_CIRCUIT:
670 while (len >= 2) {
671 subopt = *bp++;
672 suboptlen = *bp++;
673 len -= 2;
674 if (suboptlen > len) {
675 printf("\n\t %s SubOption %u, length %u: length goes past end of option",
676 tok2str(agent_suboption_values, "Unknown", subopt),
677 subopt,
678 suboptlen);
679 bp += len;
680 len = 0;
681 break;
682 }
683 printf("\n\t %s SubOption %u, length %u: ",
684 tok2str(agent_suboption_values, "Unknown", subopt),
685 subopt,
686 suboptlen);
687 switch (subopt) {
688
689 case AGENT_SUBOPTION_CIRCUIT_ID:
690 fn_printn(bp, suboptlen, NULL);
691 break;
692
693 default:
694 print_unknown_data(bp, "\n\t\t", suboptlen);
695 }
696
697 len -= suboptlen;
698 bp += suboptlen;
699 }
700 break;
701
702 case TAG_CLASSLESS_STATIC_RT:
703 case TAG_CLASSLESS_STA_RT_MS:
704 {
705 u_int mask_width, significant_octets, i;
706
707 /* this option should be at least 5 bytes long */
708 if (len < 5) {
709 printf("ERROR: option %u len %u < 5 bytes",
710 TAG_CLASSLESS_STATIC_RT, len);
711 bp += len;
712 len = 0;
713 break;
714 }
715 while (len > 0) {
716 if (!first)
717 putchar(',');
718 mask_width = *bp++;
719 len--;
720 /* mask_width <= 32 */
721 if (mask_width > 32) {
722 printf("[ERROR: Mask width (%d) > 32]", mask_width);
723 bp += len;
724 len = 0;
725 break;
726 }
727 significant_octets = (mask_width + 7) / 8;
728 /* significant octets + router(4) */
729 if (len < significant_octets + 4) {
730 printf("[ERROR: Remaining length (%u) < %u bytes]", len, significant_octets + 4);
731 bp += len;
732 len = 0;
733 break;
734 }
735 putchar('(');
736 if (mask_width == 0)
737 printf("default");
738 else {
739 for (i = 0; i < significant_octets ; i++) {
740 if (i > 0)
741 putchar('.');
742 printf("%d", *bp++);
743 }
744 for (i = significant_octets ; i < 4 ; i++)
745 printf(".0");
746 printf("/%d", mask_width);
747 }
748 memcpy((char *)&ul, (const char *)bp, sizeof(ul));
749 printf(":%s)", ipaddr_string(&ul));
750 bp += sizeof(ul);
751 len -= (significant_octets + 4);
752 first = 0;
753 }
754 }
755 break;
756
757 default:
758 printf("[unknown special tag %u, size %u]",
759 tag, len);
760 bp += len;
761 len = 0;
762 break;
763 }
764 break;
765 }
766 /* Data left over? */
767 if (len) {
768 printf("\n\t trailing data length %u", len);
769 bp += len;
770 }
771 }
772 return;
773trunc:
774 printf("|[rfc1048]");
775}
776
777static void
778cmu_print(register const u_char *bp)
779{
780 register const struct cmu_vend *cmu;
781
782#define PRINTCMUADDR(m, s) { TCHECK(cmu->m); \
783 if (cmu->m.s_addr != 0) \
784 printf(" %s:%s", s, ipaddr_string(&cmu->m.s_addr)); }
785
786 printf(" vend-cmu");
787 cmu = (const struct cmu_vend *)bp;
788
789 /* Only print if there are unknown bits */
790 TCHECK(cmu->v_flags);
791 if ((cmu->v_flags & ~(VF_SMASK)) != 0)
792 printf(" F:0x%x", cmu->v_flags);
793 PRINTCMUADDR(v_dgate, "DG");
794 PRINTCMUADDR(v_smask, cmu->v_flags & VF_SMASK ? "SM" : "SM*");
795 PRINTCMUADDR(v_dns1, "NS1");
796 PRINTCMUADDR(v_dns2, "NS2");
797 PRINTCMUADDR(v_ins1, "IEN1");
798 PRINTCMUADDR(v_ins2, "IEN2");
799 PRINTCMUADDR(v_ts1, "TS1");
800 PRINTCMUADDR(v_ts2, "TS2");
801 return;
802
803trunc:
804 fputs(tstr, stdout);
805#undef PRINTCMUADDR
806}
807
808static char *
809client_fqdn_flags(u_int flags)
810{
811 static char buf[8+1];
812 int i = 0;
813
814 if (flags & CLIENT_FQDN_FLAGS_S)
815 buf[i++] = 'S';
816 if (flags & CLIENT_FQDN_FLAGS_O)
817 buf[i++] = 'O';
818 if (flags & CLIENT_FQDN_FLAGS_E)
819 buf[i++] = 'E';
820 if (flags & CLIENT_FQDN_FLAGS_N)
821 buf[i++] = 'N';
822 buf[i] = '\0';
823
824 return buf;
825}