]> The Tcpdump Group git mirrors - tcpdump/blob - print-bootp.c
Merge branch 'master' of git+ssh://bpf.tcpdump.org/tcpdump/master/git/tcpdump
[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
24 #ifdef HAVE_CONFIG_H
25 #include "config.h"
26 #endif
27
28 #include <tcpdump-stdinc.h>
29
30 #include <stdio.h>
31 #include <string.h>
32
33 #include "interface.h"
34 #include "addrtoname.h"
35 #include "extract.h"
36 #include "ether.h"
37 #include "bootp.h"
38
39 static const char tstr[] = " [|bootp]";
40
41 static void rfc1048_print(const u_char *);
42 static void cmu_print(const u_char *);
43 static char *client_fqdn_flags(u_int flags);
44
45 static const struct tok bootp_flag_values[] = {
46 { 0x8000, "Broadcast" },
47 { 0, NULL}
48 };
49
50 static const struct tok bootp_op_values[] = {
51 { BOOTPREQUEST, "Request" },
52 { BOOTPREPLY, "Reply" },
53 { 0, NULL}
54 };
55
56 /*
57 * Print bootp requests
58 */
59 void
60 bootp_print(register const u_char *cp, u_int length)
61 {
62 register const struct bootp *bp;
63 static const u_char vm_cmu[4] = VM_CMU;
64 static const u_char vm_rfc1048[4] = VM_RFC1048;
65
66 bp = (const struct bootp *)cp;
67 TCHECK(bp->bp_op);
68
69 printf("BOOTP/DHCP, %s",
70 tok2str(bootp_op_values, "unknown (0x%02x)", bp->bp_op));
71
72 if (bp->bp_htype == 1 && bp->bp_hlen == 6 && bp->bp_op == BOOTPREQUEST) {
73 TCHECK2(bp->bp_chaddr[0], 6);
74 printf(" from %s", etheraddr_string(bp->bp_chaddr));
75 }
76
77 printf(", length %u", length);
78
79 if (!vflag)
80 return;
81
82 TCHECK(bp->bp_secs);
83
84 /* The usual hardware address type is 1 (10Mb Ethernet) */
85 if (bp->bp_htype != 1)
86 printf(", htype %d", bp->bp_htype);
87
88 /* The usual length for 10Mb Ethernet address is 6 bytes */
89 if (bp->bp_htype != 1 || bp->bp_hlen != 6)
90 printf(", hlen %d", bp->bp_hlen);
91
92 /* Only print interesting fields */
93 if (bp->bp_hops)
94 printf(", hops %d", bp->bp_hops);
95 if (bp->bp_xid)
96 printf(", xid 0x%x", EXTRACT_32BITS(&bp->bp_xid));
97 if (bp->bp_secs)
98 printf(", secs %d", EXTRACT_16BITS(&bp->bp_secs));
99
100 printf(", Flags [%s]",
101 bittok2str(bootp_flag_values, "none", EXTRACT_16BITS(&bp->bp_flags)));
102 if (vflag > 1)
103 printf(" (0x%04x)", EXTRACT_16BITS(&bp->bp_flags));
104
105 /* Client's ip address */
106 TCHECK(bp->bp_ciaddr);
107 if (bp->bp_ciaddr.s_addr)
108 printf("\n\t Client-IP %s", ipaddr_string(&bp->bp_ciaddr));
109
110 /* 'your' ip address (bootp client) */
111 TCHECK(bp->bp_yiaddr);
112 if (bp->bp_yiaddr.s_addr)
113 printf("\n\t Your-IP %s", ipaddr_string(&bp->bp_yiaddr));
114
115 /* Server's ip address */
116 TCHECK(bp->bp_siaddr);
117 if (bp->bp_siaddr.s_addr)
118 printf("\n\t Server-IP %s", ipaddr_string(&bp->bp_siaddr));
119
120 /* Gateway's ip address */
121 TCHECK(bp->bp_giaddr);
122 if (bp->bp_giaddr.s_addr)
123 printf("\n\t Gateway-IP %s", ipaddr_string(&bp->bp_giaddr));
124
125 /* Client's Ethernet address */
126 if (bp->bp_htype == 1 && bp->bp_hlen == 6) {
127 TCHECK2(bp->bp_chaddr[0], 6);
128 printf("\n\t Client-Ethernet-Address %s", etheraddr_string(bp->bp_chaddr));
129 }
130
131 TCHECK2(bp->bp_sname[0], 1); /* check first char only */
132 if (*bp->bp_sname) {
133 printf("\n\t sname \"");
134 if (fn_print(bp->bp_sname, snapend)) {
135 putchar('"');
136 fputs(tstr + 1, stdout);
137 return;
138 }
139 putchar('"');
140 }
141 TCHECK2(bp->bp_file[0], 1); /* check first char only */
142 if (*bp->bp_file) {
143 printf("\n\t file \"");
144 if (fn_print(bp->bp_file, snapend)) {
145 putchar('"');
146 fputs(tstr + 1, stdout);
147 return;
148 }
149 putchar('"');
150 }
151
152 /* Decode the vendor buffer */
153 TCHECK(bp->bp_vend[0]);
154 if (memcmp((const char *)bp->bp_vend, vm_rfc1048,
155 sizeof(u_int32_t)) == 0)
156 rfc1048_print(bp->bp_vend);
157 else if (memcmp((const char *)bp->bp_vend, vm_cmu,
158 sizeof(u_int32_t)) == 0)
159 cmu_print(bp->bp_vend);
160 else {
161 u_int32_t ul;
162
163 ul = EXTRACT_32BITS(&bp->bp_vend);
164 if (ul != 0)
165 printf("\n\t Vendor-#0x%x", ul);
166 }
167
168 return;
169 trunc:
170 fputs(tstr, stdout);
171 }
172
173 /*
174 * The first character specifies the format to print:
175 * i - ip address (32 bits)
176 * p - ip address pairs (32 bits + 32 bits)
177 * l - long (32 bits)
178 * L - unsigned long (32 bits)
179 * s - short (16 bits)
180 * b - period-seperated decimal bytes (variable length)
181 * x - colon-seperated hex bytes (variable length)
182 * a - ascii string (variable length)
183 * B - on/off (8 bits)
184 * $ - special (explicit code to handle)
185 */
186 static const struct tok tag2str[] = {
187 /* RFC1048 tags */
188 { TAG_PAD, " PAD" },
189 { TAG_SUBNET_MASK, "iSubnet-Mask" }, /* subnet mask (RFC950) */
190 { TAG_TIME_OFFSET, "LTime-Zone" }, /* seconds from UTC */
191 { TAG_GATEWAY, "iDefault-Gateway" }, /* default gateway */
192 { TAG_TIME_SERVER, "iTime-Server" }, /* time servers (RFC868) */
193 { TAG_NAME_SERVER, "iIEN-Name-Server" }, /* IEN name servers (IEN116) */
194 { TAG_DOMAIN_SERVER, "iDomain-Name-Server" }, /* domain name (RFC1035) */
195 { TAG_LOG_SERVER, "iLOG" }, /* MIT log servers */
196 { TAG_COOKIE_SERVER, "iCS" }, /* cookie servers (RFC865) */
197 { TAG_LPR_SERVER, "iLPR-Server" }, /* lpr server (RFC1179) */
198 { TAG_IMPRESS_SERVER, "iIM" }, /* impress servers (Imagen) */
199 { TAG_RLP_SERVER, "iRL" }, /* resource location (RFC887) */
200 { TAG_HOSTNAME, "aHostname" }, /* ascii hostname */
201 { TAG_BOOTSIZE, "sBS" }, /* 512 byte blocks */
202 { TAG_END, " END" },
203 /* RFC1497 tags */
204 { TAG_DUMPPATH, "aDP" },
205 { TAG_DOMAINNAME, "aDomain-Name" },
206 { TAG_SWAP_SERVER, "iSS" },
207 { TAG_ROOTPATH, "aRP" },
208 { TAG_EXTPATH, "aEP" },
209 /* RFC2132 tags */
210 { TAG_IP_FORWARD, "BIPF" },
211 { TAG_NL_SRCRT, "BSRT" },
212 { TAG_PFILTERS, "pPF" },
213 { TAG_REASS_SIZE, "sRSZ" },
214 { TAG_DEF_TTL, "bTTL" },
215 { TAG_MTU_TIMEOUT, "lMTU-Timeout" },
216 { TAG_MTU_TABLE, "sMTU-Table" },
217 { TAG_INT_MTU, "sMTU" },
218 { TAG_LOCAL_SUBNETS, "BLSN" },
219 { TAG_BROAD_ADDR, "iBR" },
220 { TAG_DO_MASK_DISC, "BMD" },
221 { TAG_SUPPLY_MASK, "BMS" },
222 { TAG_DO_RDISC, "BRouter-Discovery" },
223 { TAG_RTR_SOL_ADDR, "iRSA" },
224 { TAG_STATIC_ROUTE, "pStatic-Route" },
225 { TAG_USE_TRAILERS, "BUT" },
226 { TAG_ARP_TIMEOUT, "lAT" },
227 { TAG_ETH_ENCAP, "BIE" },
228 { TAG_TCP_TTL, "bTT" },
229 { TAG_TCP_KEEPALIVE, "lKI" },
230 { TAG_KEEPALIVE_GO, "BKG" },
231 { TAG_NIS_DOMAIN, "aYD" },
232 { TAG_NIS_SERVERS, "iYS" },
233 { TAG_NTP_SERVERS, "iNTP" },
234 { TAG_VENDOR_OPTS, "bVendor-Option" },
235 { TAG_NETBIOS_NS, "iNetbios-Name-Server" },
236 { TAG_NETBIOS_DDS, "iWDD" },
237 { TAG_NETBIOS_NODE, "$Netbios-Node" },
238 { TAG_NETBIOS_SCOPE, "aNetbios-Scope" },
239 { TAG_XWIN_FS, "iXFS" },
240 { TAG_XWIN_DM, "iXDM" },
241 { TAG_NIS_P_DOMAIN, "sN+D" },
242 { TAG_NIS_P_SERVERS, "iN+S" },
243 { TAG_MOBILE_HOME, "iMH" },
244 { TAG_SMPT_SERVER, "iSMTP" },
245 { TAG_POP3_SERVER, "iPOP3" },
246 { TAG_NNTP_SERVER, "iNNTP" },
247 { TAG_WWW_SERVER, "iWWW" },
248 { TAG_FINGER_SERVER, "iFG" },
249 { TAG_IRC_SERVER, "iIRC" },
250 { TAG_STREETTALK_SRVR, "iSTS" },
251 { TAG_STREETTALK_STDA, "iSTDA" },
252 { TAG_REQUESTED_IP, "iRequested-IP" },
253 { TAG_IP_LEASE, "lLease-Time" },
254 { TAG_OPT_OVERLOAD, "$OO" },
255 { TAG_TFTP_SERVER, "aTFTP" },
256 { TAG_BOOTFILENAME, "aBF" },
257 { TAG_DHCP_MESSAGE, " DHCP-Message" },
258 { TAG_SERVER_ID, "iServer-ID" },
259 { TAG_PARM_REQUEST, "bParameter-Request" },
260 { TAG_MESSAGE, "aMSG" },
261 { TAG_MAX_MSG_SIZE, "sMSZ" },
262 { TAG_RENEWAL_TIME, "lRN" },
263 { TAG_REBIND_TIME, "lRB" },
264 { TAG_VENDOR_CLASS, "aVendor-Class" },
265 { TAG_CLIENT_ID, "$Client-ID" },
266 /* RFC 2485 */
267 { TAG_OPEN_GROUP_UAP, "aUAP" },
268 /* RFC 2563 */
269 { TAG_DISABLE_AUTOCONF, "BNOAUTO" },
270 /* RFC 2610 */
271 { TAG_SLP_DA, "bSLP-DA" }, /*"b" is a little wrong */
272 { TAG_SLP_SCOPE, "bSLP-SCOPE" }, /*"b" is a little wrong */
273 /* RFC 2937 */
274 { TAG_NS_SEARCH, "sNSSEARCH" }, /* XXX 's' */
275 /* RFC 3011 */
276 { TAG_IP4_SUBNET_SELECT, "iSUBNET" },
277 /* RFC 3442 */
278 { TAG_CLASSLESS_STATIC_RT, "$Classless-Static-Route" },
279 { TAG_CLASSLESS_STA_RT_MS, "$Classless-Static-Route-Microsoft" },
280 /* http://www.iana.org/assignments/bootp-dhcp-extensions/index.htm */
281 { TAG_USER_CLASS, "aCLASS" },
282 { TAG_SLP_NAMING_AUTH, "aSLP-NA" },
283 { TAG_CLIENT_FQDN, "$FQDN" },
284 { TAG_AGENT_CIRCUIT, "$Agent-Information" },
285 { TAG_AGENT_REMOTE, "bARMT" },
286 { TAG_AGENT_MASK, "bAMSK" },
287 { TAG_TZ_STRING, "aTZSTR" },
288 { TAG_FQDN_OPTION, "bFQDNS" }, /* XXX 'b' */
289 { TAG_AUTH, "bAUTH" }, /* XXX 'b' */
290 { TAG_VINES_SERVERS, "iVINES" },
291 { TAG_SERVER_RANK, "sRANK" },
292 { TAG_CLIENT_ARCH, "sARCH" },
293 { TAG_CLIENT_NDI, "bNDI" }, /* XXX 'b' */
294 { TAG_CLIENT_GUID, "bGUID" }, /* XXX 'b' */
295 { TAG_LDAP_URL, "aLDAP" },
296 { TAG_6OVER4, "i6o4" },
297 { TAG_PRINTER_NAME, "aPRTR" },
298 { TAG_MDHCP_SERVER, "bMDHCP" }, /* XXX 'b' */
299 { TAG_IPX_COMPAT, "bIPX" }, /* XXX 'b' */
300 { TAG_NETINFO_PARENT, "iNI" },
301 { TAG_NETINFO_PARENT_TAG, "aNITAG" },
302 { TAG_URL, "aURL" },
303 { TAG_FAILOVER, "bFAIL" }, /* XXX 'b' */
304 { 0, NULL }
305 };
306 /* 2-byte extended tags */
307 static const struct tok xtag2str[] = {
308 { 0, NULL }
309 };
310
311 /* DHCP "options overload" types */
312 static const struct tok oo2str[] = {
313 { 1, "file" },
314 { 2, "sname" },
315 { 3, "file+sname" },
316 { 0, NULL }
317 };
318
319 /* NETBIOS over TCP/IP node type options */
320 static const struct tok nbo2str[] = {
321 { 0x1, "b-node" },
322 { 0x2, "p-node" },
323 { 0x4, "m-node" },
324 { 0x8, "h-node" },
325 { 0, NULL }
326 };
327
328 /* ARP Hardware types, for Client-ID option */
329 static const struct tok arp2str[] = {
330 { 0x1, "ether" },
331 { 0x6, "ieee802" },
332 { 0x7, "arcnet" },
333 { 0xf, "frelay" },
334 { 0x17, "strip" },
335 { 0x18, "ieee1394" },
336 { 0, NULL }
337 };
338
339 static const struct tok dhcp_msg_values[] = {
340 { DHCPDISCOVER, "Discover" },
341 { DHCPOFFER, "Offer" },
342 { DHCPREQUEST, "Request" },
343 { DHCPDECLINE, "Decline" },
344 { DHCPACK, "ACK" },
345 { DHCPNAK, "NACK" },
346 { DHCPRELEASE, "Release" },
347 { DHCPINFORM, "Inform" },
348 { 0, NULL }
349 };
350
351 #define AGENT_SUBOPTION_CIRCUIT_ID 1 /* RFC 3046 */
352 #define AGENT_SUBOPTION_REMOTE_ID 2 /* RFC 3046 */
353 #define AGENT_SUBOPTION_SUBSCRIBER_ID 6 /* RFC 3993 */
354 static const struct tok agent_suboption_values[] = {
355 { AGENT_SUBOPTION_CIRCUIT_ID, "Circuit-ID" },
356 { AGENT_SUBOPTION_REMOTE_ID, "Remote-ID" },
357 { AGENT_SUBOPTION_SUBSCRIBER_ID, "Subscriber-ID" },
358 { 0, NULL }
359 };
360
361
362 static void
363 rfc1048_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 break;
585 }
586 tag = *bp++;
587 --len;
588 fputs(tok2str(nbo2str, NULL, tag), stdout);
589 break;
590
591 case TAG_OPT_OVERLOAD:
592 /* this option should be at least 1 byte long */
593 if (len < 1) {
594 printf("ERROR: option %u len %u < 1 bytes",
595 TAG_OPT_OVERLOAD, len);
596 break;
597 }
598 tag = *bp++;
599 --len;
600 fputs(tok2str(oo2str, NULL, tag), stdout);
601 break;
602
603 case TAG_CLIENT_FQDN:
604 /* this option should be at least 3 bytes long */
605 if (len < 3) {
606 printf("ERROR: option %u len %u < 3 bytes",
607 TAG_CLIENT_FQDN, len);
608 bp += len;
609 len = 0;
610 break;
611 }
612 if (*bp)
613 printf("[%s] ", client_fqdn_flags(*bp));
614 bp++;
615 if (*bp || *(bp+1))
616 printf("%u/%u ", *bp, *(bp+1));
617 bp += 2;
618 putchar('"');
619 if (fn_printn(bp, len - 3, snapend)) {
620 putchar('"');
621 goto trunc;
622 }
623 putchar('"');
624 bp += len - 3;
625 len = 0;
626 break;
627
628 case TAG_CLIENT_ID:
629 { int type;
630
631 /* this option should be at least 1 byte long */
632 if (len < 1) {
633 printf("ERROR: option %u len %u < 1 bytes",
634 TAG_CLIENT_ID, len);
635 break;
636 }
637 type = *bp++;
638 len--;
639 if (type == 0) {
640 putchar('"');
641 if (fn_printn(bp, len, snapend)) {
642 putchar('"');
643 goto trunc;
644 }
645 putchar('"');
646 bp += len;
647 len = 0;
648 break;
649 } else {
650 printf("%s ", tok2str(arp2str, "hardware-type %u,", type));
651 while (len > 0) {
652 if (!first)
653 putchar(':');
654 printf("%02x", *bp);
655 ++bp;
656 --len;
657 first = 0;
658 }
659 }
660 break;
661 }
662
663 case TAG_AGENT_CIRCUIT:
664 while (len >= 2) {
665 subopt = *bp++;
666 suboptlen = *bp++;
667 len -= 2;
668 if (suboptlen > len) {
669 printf("\n\t %s SubOption %u, length %u: length goes past end of option",
670 tok2str(agent_suboption_values, "Unknown", subopt),
671 subopt,
672 suboptlen);
673 bp += len;
674 len = 0;
675 break;
676 }
677 printf("\n\t %s SubOption %u, length %u: ",
678 tok2str(agent_suboption_values, "Unknown", subopt),
679 subopt,
680 suboptlen);
681 switch (subopt) {
682
683 case AGENT_SUBOPTION_CIRCUIT_ID: /* fall through */
684 case AGENT_SUBOPTION_REMOTE_ID:
685 case AGENT_SUBOPTION_SUBSCRIBER_ID:
686 fn_printn(bp, suboptlen, NULL);
687 break;
688
689 default:
690 print_unknown_data(gndo,bp, "\n\t\t", suboptlen);
691 }
692
693 len -= suboptlen;
694 bp += suboptlen;
695 }
696 break;
697
698 case TAG_CLASSLESS_STATIC_RT:
699 case TAG_CLASSLESS_STA_RT_MS:
700 {
701 u_int mask_width, significant_octets, i;
702
703 /* this option should be at least 5 bytes long */
704 if (len < 5) {
705 printf("ERROR: option %u len %u < 5 bytes",
706 TAG_CLASSLESS_STATIC_RT, len);
707 bp += len;
708 len = 0;
709 break;
710 }
711 while (len > 0) {
712 if (!first)
713 putchar(',');
714 mask_width = *bp++;
715 len--;
716 /* mask_width <= 32 */
717 if (mask_width > 32) {
718 printf("[ERROR: Mask width (%d) > 32]", mask_width);
719 bp += len;
720 len = 0;
721 break;
722 }
723 significant_octets = (mask_width + 7) / 8;
724 /* significant octets + router(4) */
725 if (len < significant_octets + 4) {
726 printf("[ERROR: Remaining length (%u) < %u bytes]", len, significant_octets + 4);
727 bp += len;
728 len = 0;
729 break;
730 }
731 putchar('(');
732 if (mask_width == 0)
733 printf("default");
734 else {
735 for (i = 0; i < significant_octets ; i++) {
736 if (i > 0)
737 putchar('.');
738 printf("%d", *bp++);
739 }
740 for (i = significant_octets ; i < 4 ; i++)
741 printf(".0");
742 printf("/%d", mask_width);
743 }
744 memcpy((char *)&ul, (const char *)bp, sizeof(ul));
745 printf(":%s)", ipaddr_string(&ul));
746 bp += sizeof(ul);
747 len -= (significant_octets + 4);
748 first = 0;
749 }
750 }
751 break;
752
753 default:
754 printf("[unknown special tag %u, size %u]",
755 tag, len);
756 bp += len;
757 len = 0;
758 break;
759 }
760 break;
761 }
762 /* Data left over? */
763 if (len) {
764 printf("\n\t trailing data length %u", len);
765 bp += len;
766 }
767 }
768 return;
769 trunc:
770 printf("|[rfc1048]");
771 }
772
773 static void
774 cmu_print(register const u_char *bp)
775 {
776 register const struct cmu_vend *cmu;
777
778 #define PRINTCMUADDR(m, s) { TCHECK(cmu->m); \
779 if (cmu->m.s_addr != 0) \
780 printf(" %s:%s", s, ipaddr_string(&cmu->m.s_addr)); }
781
782 printf(" vend-cmu");
783 cmu = (const struct cmu_vend *)bp;
784
785 /* Only print if there are unknown bits */
786 TCHECK(cmu->v_flags);
787 if ((cmu->v_flags & ~(VF_SMASK)) != 0)
788 printf(" F:0x%x", cmu->v_flags);
789 PRINTCMUADDR(v_dgate, "DG");
790 PRINTCMUADDR(v_smask, cmu->v_flags & VF_SMASK ? "SM" : "SM*");
791 PRINTCMUADDR(v_dns1, "NS1");
792 PRINTCMUADDR(v_dns2, "NS2");
793 PRINTCMUADDR(v_ins1, "IEN1");
794 PRINTCMUADDR(v_ins2, "IEN2");
795 PRINTCMUADDR(v_ts1, "TS1");
796 PRINTCMUADDR(v_ts2, "TS2");
797 return;
798
799 trunc:
800 fputs(tstr, stdout);
801 #undef PRINTCMUADDR
802 }
803
804 static char *
805 client_fqdn_flags(u_int flags)
806 {
807 static char buf[8+1];
808 int i = 0;
809
810 if (flags & CLIENT_FQDN_FLAGS_S)
811 buf[i++] = 'S';
812 if (flags & CLIENT_FQDN_FLAGS_O)
813 buf[i++] = 'O';
814 if (flags & CLIENT_FQDN_FLAGS_E)
815 buf[i++] = 'E';
816 if (flags & CLIENT_FQDN_FLAGS_N)
817 buf[i++] = 'N';
818 buf[i] = '\0';
819
820 return buf;
821 }