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