]> The Tcpdump Group git mirrors - tcpdump/blob - print-bootp.c
From Francois-Xavier Le Bail: suport for the DHCP Classless Static Route
[tcpdump] / print-bootp.c
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
24 static const char rcsid[] _U_ =
25 "@(#) $Header: /tcpdump/master/tcpdump/print-bootp.c,v 1.86 2007-07-24 17:28:56 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
43 static void rfc1048_print(const u_char *);
44 static void cmu_print(const u_char *);
45 static char *client_fqdn_flags(u_int flags);
46
47 static char tstr[] = " [|bootp]";
48
49 static const struct tok bootp_flag_values[] = {
50 { 0x8000, "Broadcast" },
51 { 0, NULL}
52 };
53
54 static const struct tok bootp_op_values[] = {
55 { BOOTPREQUEST, "Request" },
56 { BOOTPREPLY, "Reply" },
57 { 0, NULL}
58 };
59
60 /*
61 * Print bootp requests
62 */
63 void
64 bootp_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;
173 trunc:
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 */
190 static 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 /* http://www.iana.org/assignments/bootp-dhcp-extensions/index.htm */
284 { TAG_USER_CLASS, "aCLASS" },
285 { TAG_SLP_NAMING_AUTH, "aSLP-NA" },
286 { TAG_CLIENT_FQDN, "$FQDN" },
287 { TAG_AGENT_CIRCUIT, "$Agent-Information" },
288 { TAG_AGENT_REMOTE, "bARMT" },
289 { TAG_AGENT_MASK, "bAMSK" },
290 { TAG_TZ_STRING, "aTZSTR" },
291 { TAG_FQDN_OPTION, "bFQDNS" }, /* XXX 'b' */
292 { TAG_AUTH, "bAUTH" }, /* XXX 'b' */
293 { TAG_VINES_SERVERS, "iVINES" },
294 { TAG_SERVER_RANK, "sRANK" },
295 { TAG_CLIENT_ARCH, "sARCH" },
296 { TAG_CLIENT_NDI, "bNDI" }, /* XXX 'b' */
297 { TAG_CLIENT_GUID, "bGUID" }, /* XXX 'b' */
298 { TAG_LDAP_URL, "aLDAP" },
299 { TAG_6OVER4, "i6o4" },
300 { TAG_PRINTER_NAME, "aPRTR" },
301 { TAG_MDHCP_SERVER, "bMDHCP" }, /* XXX 'b' */
302 { TAG_IPX_COMPAT, "bIPX" }, /* XXX 'b' */
303 { TAG_NETINFO_PARENT, "iNI" },
304 { TAG_NETINFO_PARENT_TAG, "aNITAG" },
305 { TAG_URL, "aURL" },
306 { TAG_FAILOVER, "bFAIL" }, /* XXX 'b' */
307 { 0, NULL }
308 };
309 /* 2-byte extended tags */
310 static struct tok xtag2str[] = {
311 { 0, NULL }
312 };
313
314 /* DHCP "options overload" types */
315 static struct tok oo2str[] = {
316 { 1, "file" },
317 { 2, "sname" },
318 { 3, "file+sname" },
319 { 0, NULL }
320 };
321
322 /* NETBIOS over TCP/IP node type options */
323 static struct tok nbo2str[] = {
324 { 0x1, "b-node" },
325 { 0x2, "p-node" },
326 { 0x4, "m-node" },
327 { 0x8, "h-node" },
328 { 0, NULL }
329 };
330
331 /* ARP Hardware types, for Client-ID option */
332 static struct tok arp2str[] = {
333 { 0x1, "ether" },
334 { 0x6, "ieee802" },
335 { 0x7, "arcnet" },
336 { 0xf, "frelay" },
337 { 0x17, "strip" },
338 { 0x18, "ieee1394" },
339 { 0, NULL }
340 };
341
342 static struct tok dhcp_msg_values[] = {
343 { DHCPDISCOVER, "Discover" },
344 { DHCPOFFER, "Offer" },
345 { DHCPREQUEST, "Request" },
346 { DHCPDECLINE, "Decline" },
347 { DHCPACK, "ACK" },
348 { DHCPNAK, "NACK" },
349 { DHCPRELEASE, "Release" },
350 { DHCPINFORM, "Inform" },
351 { 0, NULL }
352 };
353
354 #define AGENT_SUBOPTION_CIRCUIT_ID 1
355 static struct tok agent_suboption_values[] = {
356 { AGENT_SUBOPTION_CIRCUIT_ID, "Circuit-ID" },
357 { 0, NULL }
358 };
359
360
361 static void
362 rfc1048_print(register const u_char *bp)
363 {
364 register u_int16_t tag;
365 register u_int len;
366 register const char *cp;
367 register char c;
368 int first, idx;
369 u_int32_t ul;
370 u_int16_t us;
371 u_int8_t uc, subopt, suboptlen;
372
373 printf("\n\t Vendor-rfc1048 Extensions");
374
375 /* Step over magic cookie */
376 printf("\n\t Magic Cookie 0x%08x", EXTRACT_32BITS(bp));
377 bp += sizeof(int32_t);
378
379 /* Loop while we there is a tag left in the buffer */
380 while (TTEST2(*bp, 1)) {
381 tag = *bp++;
382 if (tag == TAG_PAD && vflag < 3)
383 continue;
384 if (tag == TAG_END && vflag < 3)
385 return;
386 if (tag == TAG_EXTENDED_OPTION) {
387 TCHECK2(*(bp + 1), 2);
388 tag = EXTRACT_16BITS(bp + 1);
389 /* XXX we don't know yet if the IANA will
390 * preclude overlap of 1-byte and 2-byte spaces.
391 * If not, we need to offset tag after this step.
392 */
393 cp = tok2str(xtag2str, "?xT%u", tag);
394 } else
395 cp = tok2str(tag2str, "?T%u", tag);
396 c = *cp++;
397
398 if (tag == TAG_PAD || tag == TAG_END)
399 len = 0;
400 else {
401 /* Get the length; check for truncation */
402 TCHECK2(*bp, 1);
403 len = *bp++;
404 }
405
406 printf("\n\t %s Option %u, length %u%s", cp, tag, len,
407 len > 0 ? ": " : "");
408
409 if (tag == TAG_PAD && vflag > 2) {
410 u_int ntag = 1;
411 while (TTEST2(*bp, 1) && *bp == TAG_PAD) {
412 bp++;
413 ntag++;
414 }
415 if (ntag > 1)
416 printf(", occurs %u", ntag);
417 }
418
419 if (!TTEST2(*bp, len)) {
420 printf("[|rfc1048 %u]", len);
421 return;
422 }
423
424 if (tag == TAG_DHCP_MESSAGE && len == 1) {
425 uc = *bp++;
426 printf("%s", tok2str(dhcp_msg_values, "Unknown (%u)", uc));
427 continue;
428 }
429
430 if (tag == TAG_PARM_REQUEST) {
431 idx = 0;
432 while (len-- > 0) {
433 uc = *bp++;
434 cp = tok2str(tag2str, "?Option %u", uc);
435 if (idx % 4 == 0)
436 printf("\n\t ");
437 else
438 printf(", ");
439 printf("%s", cp + 1);
440 idx++;
441 }
442 continue;
443 }
444
445 if (tag == TAG_EXTENDED_REQUEST) {
446 first = 1;
447 while (len > 1) {
448 len -= 2;
449 us = EXTRACT_16BITS(bp);
450 bp += 2;
451 cp = tok2str(xtag2str, "?xT%u", us);
452 if (!first)
453 putchar('+');
454 printf("%s", cp + 1);
455 first = 0;
456 }
457 continue;
458 }
459
460 /* Print data */
461 if (c == '?') {
462 /* Base default formats for unknown tags on data size */
463 if (len & 1)
464 c = 'b';
465 else if (len & 2)
466 c = 's';
467 else
468 c = 'l';
469 }
470 first = 1;
471 switch (c) {
472
473 case 'a':
474 /* ascii strings */
475 putchar('"');
476 if (fn_printn(bp, len, snapend)) {
477 putchar('"');
478 goto trunc;
479 }
480 putchar('"');
481 bp += len;
482 len = 0;
483 break;
484
485 case 'i':
486 case 'l':
487 case 'L':
488 /* ip addresses/32-bit words */
489 while (len >= sizeof(ul)) {
490 if (!first)
491 putchar(',');
492 ul = EXTRACT_32BITS(bp);
493 if (c == 'i') {
494 ul = htonl(ul);
495 printf("%s", ipaddr_string(&ul));
496 } else if (c == 'L')
497 printf("%d", ul);
498 else
499 printf("%u", ul);
500 bp += sizeof(ul);
501 len -= sizeof(ul);
502 first = 0;
503 }
504 break;
505
506 case 'p':
507 /* IP address pairs */
508 while (len >= 2*sizeof(ul)) {
509 if (!first)
510 putchar(',');
511 memcpy((char *)&ul, (const char *)bp, sizeof(ul));
512 printf("(%s:", ipaddr_string(&ul));
513 bp += sizeof(ul);
514 memcpy((char *)&ul, (const char *)bp, sizeof(ul));
515 printf("%s)", ipaddr_string(&ul));
516 bp += sizeof(ul);
517 len -= 2*sizeof(ul);
518 first = 0;
519 }
520 break;
521
522 case 's':
523 /* shorts */
524 while (len >= sizeof(us)) {
525 if (!first)
526 putchar(',');
527 us = EXTRACT_16BITS(bp);
528 printf("%u", us);
529 bp += sizeof(us);
530 len -= sizeof(us);
531 first = 0;
532 }
533 break;
534
535 case 'B':
536 /* boolean */
537 while (len > 0) {
538 if (!first)
539 putchar(',');
540 switch (*bp) {
541 case 0:
542 putchar('N');
543 break;
544 case 1:
545 putchar('Y');
546 break;
547 default:
548 printf("%u?", *bp);
549 break;
550 }
551 ++bp;
552 --len;
553 first = 0;
554 }
555 break;
556
557 case 'b':
558 case 'x':
559 default:
560 /* Bytes */
561 while (len > 0) {
562 if (!first)
563 putchar(c == 'x' ? ':' : '.');
564 if (c == 'x')
565 printf("%02x", *bp);
566 else
567 printf("%u", *bp);
568 ++bp;
569 --len;
570 first = 0;
571 }
572 break;
573
574 case '$':
575 /* Guys we can't handle with one of the usual cases */
576 switch (tag) {
577
578 case TAG_NETBIOS_NODE:
579 /* this option should be at least 1 byte long */
580 if (len < 1) {
581 printf("ERROR: option %u len %u < 1 bytes",
582 TAG_NETBIOS_NODE, len);
583 bp += len;
584 len = 0;
585 break;
586 }
587 tag = *bp++;
588 --len;
589 fputs(tok2str(nbo2str, NULL, tag), stdout);
590 break;
591
592 case TAG_OPT_OVERLOAD:
593 /* this option should be at least 1 byte long */
594 if (len < 1) {
595 printf("ERROR: option %u len %u < 1 bytes",
596 TAG_OPT_OVERLOAD, len);
597 bp += len;
598 len = 0;
599 break;
600 }
601 tag = *bp++;
602 --len;
603 fputs(tok2str(oo2str, NULL, tag), stdout);
604 break;
605
606 case TAG_CLIENT_FQDN:
607 /* this option should be at least 3 bytes long */
608 if (len < 3) {
609 printf("ERROR: option %u len %u < 3 bytes",
610 TAG_CLIENT_FQDN, len);
611 bp += len;
612 len = 0;
613 break;
614 }
615 if (*bp)
616 printf("[%s] ", client_fqdn_flags(*bp));
617 bp++;
618 if (*bp || *(bp+1))
619 printf("%u/%u ", *bp, *(bp+1));
620 bp += 2;
621 putchar('"');
622 if (fn_printn(bp, len - 3, snapend)) {
623 putchar('"');
624 goto trunc;
625 }
626 putchar('"');
627 bp += len - 3;
628 len = 0;
629 break;
630
631 case TAG_CLIENT_ID:
632 { int type;
633
634 /* this option should be at least 1 byte long */
635 if (len < 1) {
636 printf("ERROR: option %u len %u < 1 bytes",
637 TAG_CLIENT_ID, len);
638 bp += len;
639 len = 0;
640 break;
641 }
642 type = *bp++;
643 len--;
644 if (type == 0) {
645 putchar('"');
646 if (fn_printn(bp, len, snapend)) {
647 putchar('"');
648 goto trunc;
649 }
650 putchar('"');
651 bp += len;
652 len = 0;
653 break;
654 } else {
655 printf("%s ", tok2str(arp2str, "hardware-type %u,", type));
656 while (len > 0) {
657 if (!first)
658 putchar(':');
659 printf("%02x", *bp);
660 ++bp;
661 --len;
662 first = 0;
663 }
664 }
665 break;
666 }
667
668 case TAG_AGENT_CIRCUIT:
669 while (len >= 2) {
670 subopt = *bp++;
671 suboptlen = *bp++;
672 len -= 2;
673 if (suboptlen > len) {
674 printf("\n\t %s SubOption %u, length %u: length goes past end of option",
675 tok2str(agent_suboption_values, "Unknown", subopt),
676 subopt,
677 suboptlen);
678 bp += len;
679 len = 0;
680 break;
681 }
682 printf("\n\t %s SubOption %u, length %u: ",
683 tok2str(agent_suboption_values, "Unknown", subopt),
684 subopt,
685 suboptlen);
686 switch (subopt) {
687
688 case AGENT_SUBOPTION_CIRCUIT_ID:
689 fn_printn(bp, suboptlen, NULL);
690 break;
691
692 default:
693 print_unknown_data(bp, "\n\t\t", suboptlen);
694 }
695
696 len -= suboptlen;
697 bp += suboptlen;
698 }
699 break;
700
701 case TAG_CLASSLESS_STATIC_RT:
702 {
703 u_int mask_width, significant_octets, i;
704
705 /* this option should be at least 5 bytes long */
706 if (len < 5) {
707 printf("ERROR: option %u len %u < 5 bytes",
708 TAG_CLASSLESS_STATIC_RT, len);
709 bp += len;
710 len = 0;
711 break;
712 }
713 while (len > 0) {
714 if (!first)
715 putchar(',');
716 mask_width = *bp++;
717 len--;
718 /* mask_width <= 32 */
719 if (mask_width > 32) {
720 printf("[ERROR: Mask width (%d) > 32]", mask_width);
721 bp += len;
722 len = 0;
723 break;
724 }
725 significant_octets = (mask_width + 7) / 8;
726 /* significant octets + router(4) */
727 if (len < significant_octets + 4) {
728 printf("[ERROR: Remaining length (%u) < %u bytes]", len, significant_octets + 4);
729 bp += len;
730 len = 0;
731 break;
732 }
733 putchar('(');
734 if (mask_width == 0)
735 printf("default");
736 else {
737 for (i = 0; i < significant_octets ; i++) {
738 if (i > 0)
739 putchar('.');
740 printf("%d", *bp++);
741 }
742 for (i = significant_octets ; i < 4 ; i++)
743 printf(".0");
744 printf("/%d", mask_width);
745 }
746 memcpy((char *)&ul, (const char *)bp, sizeof(ul));
747 printf(":%s)", ipaddr_string(&ul));
748 bp += sizeof(ul);
749 len -= (significant_octets + 4);
750 first = 0;
751 }
752 }
753 break;
754
755 default:
756 printf("[unknown special tag %u, size %u]",
757 tag, len);
758 bp += len;
759 len = 0;
760 break;
761 }
762 break;
763 }
764 /* Data left over? */
765 if (len) {
766 printf("\n\t trailing data length %u", len);
767 bp += len;
768 }
769 }
770 return;
771 trunc:
772 printf("|[rfc1048]");
773 }
774
775 static void
776 cmu_print(register const u_char *bp)
777 {
778 register const struct cmu_vend *cmu;
779
780 #define PRINTCMUADDR(m, s) { TCHECK(cmu->m); \
781 if (cmu->m.s_addr != 0) \
782 printf(" %s:%s", s, ipaddr_string(&cmu->m.s_addr)); }
783
784 printf(" vend-cmu");
785 cmu = (const struct cmu_vend *)bp;
786
787 /* Only print if there are unknown bits */
788 TCHECK(cmu->v_flags);
789 if ((cmu->v_flags & ~(VF_SMASK)) != 0)
790 printf(" F:0x%x", cmu->v_flags);
791 PRINTCMUADDR(v_dgate, "DG");
792 PRINTCMUADDR(v_smask, cmu->v_flags & VF_SMASK ? "SM" : "SM*");
793 PRINTCMUADDR(v_dns1, "NS1");
794 PRINTCMUADDR(v_dns2, "NS2");
795 PRINTCMUADDR(v_ins1, "IEN1");
796 PRINTCMUADDR(v_ins2, "IEN2");
797 PRINTCMUADDR(v_ts1, "TS1");
798 PRINTCMUADDR(v_ts2, "TS2");
799 return;
800
801 trunc:
802 fputs(tstr, stdout);
803 #undef PRINTCMUADDR
804 }
805
806 static char *
807 client_fqdn_flags(u_int flags)
808 {
809 static char buf[8+1];
810 int i = 0;
811
812 if (flags & CLIENT_FQDN_FLAGS_S)
813 buf[i++] = 'S';
814 if (flags & CLIENT_FQDN_FLAGS_O)
815 buf[i++] = 'O';
816 if (flags & CLIENT_FQDN_FLAGS_E)
817 buf[i++] = 'E';
818 if (flags & CLIENT_FQDN_FLAGS_N)
819 buf[i++] = 'N';
820 buf[i] = '\0';
821
822 return buf;
823 }