Add trunc and truncf.
[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.3 2006/02/13 19:02:05 hannes 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
46 static char tstr[] = " [|bootp]";
47
48 static const struct tok bootp_flag_values[] = {
49     { 0x8000,                   "Broadcast" },
50     { 0, NULL}
51 };
52
53 static const struct tok bootp_op_values[] = {
54     { BOOTPREQUEST,             "Request" },
55     { BOOTPREPLY,               "Reply" },
56     { 0, NULL}
57 };
58
59 /*
60  * Print bootp requests
61  */
62 void
63 bootp_print(register const u_char *cp, u_int length)
64 {
65         register const struct bootp *bp;
66         static const u_char vm_cmu[4] = VM_CMU;
67         static const u_char vm_rfc1048[4] = VM_RFC1048;
68
69         bp = (const struct bootp *)cp;
70         TCHECK(bp->bp_op);
71
72         printf("BOOTP/DHCP, %s",
73                tok2str(bootp_op_values, "unknown (0x%02x)", bp->bp_op));
74
75         if (bp->bp_htype == 1 && bp->bp_hlen == 6 && bp->bp_op == BOOTPREQUEST) {
76                 TCHECK2(bp->bp_chaddr[0], 6);
77                 printf(" from %s", etheraddr_string(bp->bp_chaddr));
78         }
79
80         printf(", length %u", length);
81
82         if (!vflag)
83             return;
84
85         TCHECK(bp->bp_secs);
86
87         /* The usual hardware address type is 1 (10Mb Ethernet) */
88         if (bp->bp_htype != 1)
89                 printf(", htype %d", bp->bp_htype);
90
91         /* The usual length for 10Mb Ethernet address is 6 bytes */
92         if (bp->bp_htype != 1 || bp->bp_hlen != 6)
93                 printf(", hlen %d", bp->bp_hlen);
94
95         /* Only print interesting fields */
96         if (bp->bp_hops)
97                 printf(", hops %d", bp->bp_hops);
98         if (bp->bp_xid)
99                 printf(", xid 0x%x", EXTRACT_32BITS(&bp->bp_xid));
100         if (bp->bp_secs)
101                 printf(", secs %d", EXTRACT_16BITS(&bp->bp_secs));
102
103         printf(", Flags [ %s ]",
104                bittok2str(bootp_flag_values, "none", EXTRACT_16BITS(&bp->bp_flags)));
105         if (vflag>1)
106           printf( " (0x%04x)", EXTRACT_16BITS(&bp->bp_flags));
107
108         /* Client's ip address */
109         TCHECK(bp->bp_ciaddr);
110         if (bp->bp_ciaddr.s_addr)
111                 printf("\n\t  Client-IP %s", ipaddr_string(&bp->bp_ciaddr));
112
113         /* 'your' ip address (bootp client) */
114         TCHECK(bp->bp_yiaddr);
115         if (bp->bp_yiaddr.s_addr)
116                 printf("\n\t  Your-IP %s", ipaddr_string(&bp->bp_yiaddr));
117
118         /* Server's ip address */
119         TCHECK(bp->bp_siaddr);
120         if (bp->bp_siaddr.s_addr)
121                 printf("\n\t  Server-IP %s", ipaddr_string(&bp->bp_siaddr));
122
123         /* Gateway's ip address */
124         TCHECK(bp->bp_giaddr);
125         if (bp->bp_giaddr.s_addr)
126                 printf("\n\t  Gateway-IP %s", ipaddr_string(&bp->bp_giaddr));
127
128         /* Client's Ethernet address */
129         if (bp->bp_htype == 1 && bp->bp_hlen == 6) {
130                 TCHECK2(bp->bp_chaddr[0], 6);
131                 printf("\n\t  Client-Ethernet-Address %s", etheraddr_string(bp->bp_chaddr));
132         }
133
134         TCHECK2(bp->bp_sname[0], 1);            /* check first char only */
135         if (*bp->bp_sname) {
136                 printf("\n\t  sname \"");
137                 if (fn_print(bp->bp_sname, snapend)) {
138                         putchar('"');
139                         fputs(tstr + 1, stdout);
140                         return;
141                 }
142                 putchar('"');
143         }
144         TCHECK2(bp->bp_file[0], 1);             /* check first char only */
145         if (*bp->bp_file) {
146                 printf("\n\t  file \"");
147                 if (fn_print(bp->bp_file, snapend)) {
148                         putchar('"');
149                         fputs(tstr + 1, stdout);
150                         return;
151                 }
152                 putchar('"');
153         }
154
155         /* Decode the vendor buffer */
156         TCHECK(bp->bp_vend[0]);
157         if (memcmp((const char *)bp->bp_vend, vm_rfc1048,
158                  sizeof(u_int32_t)) == 0)
159                 rfc1048_print(bp->bp_vend);
160         else if (memcmp((const char *)bp->bp_vend, vm_cmu,
161                       sizeof(u_int32_t)) == 0)
162                 cmu_print(bp->bp_vend);
163         else {
164                 u_int32_t ul;
165
166                 ul = EXTRACT_32BITS(&bp->bp_vend);
167                 if (ul != 0)
168                         printf("\n\t  Vendor-#0x%x", ul);
169         }
170
171         return;
172 trunc:
173         fputs(tstr, stdout);
174 }
175
176 /*
177  * The first character specifies the format to print:
178  *     i - ip address (32 bits)
179  *     p - ip address pairs (32 bits + 32 bits)
180  *     l - long (32 bits)
181  *     L - unsigned long (32 bits)
182  *     s - short (16 bits)
183  *     b - period-seperated decimal bytes (variable length)
184  *     x - colon-seperated hex bytes (variable length)
185  *     a - ascii string (variable length)
186  *     B - on/off (8 bits)
187  *     $ - special (explicit code to handle)
188  */
189 static struct tok tag2str[] = {
190 /* RFC1048 tags */
191         { TAG_PAD,              " PAD" },
192         { TAG_SUBNET_MASK,      "iSubnet-Mask" },       /* subnet mask (RFC950) */
193         { TAG_TIME_OFFSET,      "LTime-Zone" }, /* seconds from UTC */
194         { TAG_GATEWAY,          "iDefault-Gateway" },   /* default gateway */
195         { TAG_TIME_SERVER,      "iTime-Server" },       /* time servers (RFC868) */
196         { TAG_NAME_SERVER,      "iIEN-Name-Server" },   /* IEN name servers (IEN116) */
197         { TAG_DOMAIN_SERVER,    "iDomain-Name-Server" },        /* domain name (RFC1035) */
198         { TAG_LOG_SERVER,       "iLOG" },       /* MIT log servers */
199         { TAG_COOKIE_SERVER,    "iCS" },        /* cookie servers (RFC865) */
200         { TAG_LPR_SERVER,       "iLPR-Server" },        /* lpr server (RFC1179) */
201         { TAG_IMPRESS_SERVER,   "iIM" },        /* impress servers (Imagen) */
202         { TAG_RLP_SERVER,       "iRL" },        /* resource location (RFC887) */
203         { TAG_HOSTNAME,         "aHostname" },  /* ascii hostname */
204         { TAG_BOOTSIZE,         "sBS" },        /* 512 byte blocks */
205         { TAG_END,              " END" },
206 /* RFC1497 tags */
207         { TAG_DUMPPATH,         "aDP" },
208         { TAG_DOMAINNAME,       "aDomain-Name" },
209         { TAG_SWAP_SERVER,      "iSS" },
210         { TAG_ROOTPATH,         "aRP" },
211         { TAG_EXTPATH,          "aEP" },
212 /* RFC2132 tags */
213         { TAG_IP_FORWARD,       "BIPF" },
214         { TAG_NL_SRCRT,         "BSRT" },
215         { TAG_PFILTERS,         "pPF" },
216         { TAG_REASS_SIZE,       "sRSZ" },
217         { TAG_DEF_TTL,          "bTTL" },
218         { TAG_MTU_TIMEOUT,      "lMTU-Timeout" },
219         { TAG_MTU_TABLE,        "sMTU-Table" },
220         { TAG_INT_MTU,          "sMTU" },
221         { TAG_LOCAL_SUBNETS,    "BLSN" },
222         { TAG_BROAD_ADDR,       "iBR" },
223         { TAG_DO_MASK_DISC,     "BMD" },
224         { TAG_SUPPLY_MASK,      "BMS" },
225         { TAG_DO_RDISC,         "BRouter-Discovery" },
226         { TAG_RTR_SOL_ADDR,     "iRSA" },
227         { TAG_STATIC_ROUTE,     "pStatic-Route" },
228         { TAG_USE_TRAILERS,     "BUT" },
229         { TAG_ARP_TIMEOUT,      "lAT" },
230         { TAG_ETH_ENCAP,        "BIE" },
231         { TAG_TCP_TTL,          "bTT" },
232         { TAG_TCP_KEEPALIVE,    "lKI" },
233         { TAG_KEEPALIVE_GO,     "BKG" },
234         { TAG_NIS_DOMAIN,       "aYD" },
235         { TAG_NIS_SERVERS,      "iYS" },
236         { TAG_NTP_SERVERS,      "iNTP" },
237         { TAG_VENDOR_OPTS,      "bVendor-Option" },
238         { TAG_NETBIOS_NS,       "iNetbios-Name-Server" },
239         { TAG_NETBIOS_DDS,      "iWDD" },
240         { TAG_NETBIOS_NODE,     "$Netbios-Node" },
241         { TAG_NETBIOS_SCOPE,    "aNetbios-Scope" },
242         { TAG_XWIN_FS,          "iXFS" },
243         { TAG_XWIN_DM,          "iXDM" },
244         { TAG_NIS_P_DOMAIN,     "sN+D" },
245         { TAG_NIS_P_SERVERS,    "iN+S" },
246         { TAG_MOBILE_HOME,      "iMH" },
247         { TAG_SMPT_SERVER,      "iSMTP" },
248         { TAG_POP3_SERVER,      "iPOP3" },
249         { TAG_NNTP_SERVER,      "iNNTP" },
250         { TAG_WWW_SERVER,       "iWWW" },
251         { TAG_FINGER_SERVER,    "iFG" },
252         { TAG_IRC_SERVER,       "iIRC" },
253         { TAG_STREETTALK_SRVR,  "iSTS" },
254         { TAG_STREETTALK_STDA,  "iSTDA" },
255         { TAG_REQUESTED_IP,     "iRequested-IP" },
256         { TAG_IP_LEASE,         "lLease-Time" },
257         { TAG_OPT_OVERLOAD,     "$OO" },
258         { TAG_TFTP_SERVER,      "aTFTP" },
259         { TAG_BOOTFILENAME,     "aBF" },
260         { TAG_DHCP_MESSAGE,     " DHCP-Message" },
261         { TAG_SERVER_ID,        "iServer-ID" },
262         { TAG_PARM_REQUEST,     "bParameter-Request" },
263         { TAG_MESSAGE,          "aMSG" },
264         { TAG_MAX_MSG_SIZE,     "sMSZ" },
265         { TAG_RENEWAL_TIME,     "lRN" },
266         { TAG_REBIND_TIME,      "lRB" },
267         { TAG_VENDOR_CLASS,     "aVendor-Class" },
268         { TAG_CLIENT_ID,        "$Client-ID" },
269 /* RFC 2485 */
270         { TAG_OPEN_GROUP_UAP,   "aUAP" },
271 /* RFC 2563 */
272         { TAG_DISABLE_AUTOCONF, "BNOAUTO" },
273 /* RFC 2610 */
274         { TAG_SLP_DA,           "bSLP-DA" },    /*"b" is a little wrong */
275         { TAG_SLP_SCOPE,        "bSLP-SCOPE" }, /*"b" is a little wrong */
276 /* RFC 2937 */
277         { TAG_NS_SEARCH,        "sNSSEARCH" },  /* XXX 's' */
278 /* RFC 3011 */
279         { TAG_IP4_SUBNET_SELECT, "iSUBNET" },
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 struct tok xtag2str[] = {
308         { 0,                    NULL }
309 };
310
311 /* DHCP "options overload" types */
312 static 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 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 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 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
352 static struct tok agent_suboption_values[] = {
353         { AGENT_SUBOPTION_CIRCUIT_ID, "Circuit-ID" },
354         { 0,                    NULL }
355 };
356
357
358 static void
359 rfc1048_print(register const u_char *bp)
360 {
361         register u_int16_t tag;
362         register u_int len, size;
363         register const char *cp;
364         register char c;
365         int first, idx;
366         u_int32_t ul;
367         u_int16_t us;
368         u_int8_t uc, subopt, suboptlen;
369
370         printf("\n\t  Vendor-rfc1048 Extensions");
371
372         /* Step over magic cookie */
373         printf("\n\t    Magic Cookie 0x%08x", EXTRACT_32BITS(bp));
374         bp += sizeof(int32_t);
375
376         /* Loop while we there is a tag left in the buffer */
377         while (bp + 1 < snapend) {
378                 tag = *bp++;
379                 if (tag == TAG_PAD)
380                         continue;
381                 if (tag == TAG_END)
382                         return;
383                 if (tag == TAG_EXTENDED_OPTION) {
384                         TCHECK2(*(bp + 1), 2);
385                         tag = EXTRACT_16BITS(bp + 1);
386                         /* XXX we don't know yet if the IANA will
387                          * preclude overlap of 1-byte and 2-byte spaces.
388                          * If not, we need to offset tag after this step.
389                          */
390                         cp = tok2str(xtag2str, "?xT%u", tag);
391                 } else
392                         cp = tok2str(tag2str, "?T%u", tag);
393                 c = *cp++;
394
395                 /* Get the length; check for truncation */
396                 if (bp + 1 >= snapend) {
397                         fputs(tstr, stdout);
398                         return;
399                 }
400                 len = *bp++;
401
402                 printf("\n\t    %s Option %u, length %u: ", cp, tag, len);
403
404                 if (bp + len >= snapend) {
405                         printf("[|bootp %u]", len);
406                         return;
407                 }
408
409                 if (tag == TAG_DHCP_MESSAGE && len == 1) {
410                         uc = *bp++;
411                         printf("%s", tok2str(dhcp_msg_values, "Unknown (%u)", uc));
412                         continue;
413                 }
414
415                 if (tag == TAG_PARM_REQUEST) {
416                         first = 1;
417                         idx = 0;
418                         printf("\n\t      ");
419                         while (len-- > 0) {
420                                 uc = *bp++;
421                                 cp = tok2str(tag2str, "?Option %u", uc);
422                                 printf("%s%s", (first || (!(idx %4))) ? "" : ", ", cp + 1);
423
424                                 if ((idx %4) == 3) {
425                                     printf("\n\t      ");
426                                 }
427                                 first = 0;
428                                 idx ++;
429                         }
430                         continue;
431                 }
432                 if (tag == TAG_EXTENDED_REQUEST) {
433                         first = 1;
434                         while (len > 1) {
435                                 len -= 2;
436                                 us = EXTRACT_16BITS(bp);
437                                 bp += 2;
438                                 cp = tok2str(xtag2str, "?xT%u", us);
439                                 if (!first)
440                                         putchar('+');
441                                 printf("%s", cp + 1);
442                                 first = 0;
443                         }
444                         continue;
445                 }
446
447                 /* Print data */
448                 size = len;
449                 if (c == '?') {
450                         /* Base default formats for unknown tags on data size */
451                         if (size & 1)
452                                 c = 'b';
453                         else if (size & 2)
454                                 c = 's';
455                         else
456                                 c = 'l';
457                 }
458                 first = 1;
459                 switch (c) {
460
461                 case 'a':
462                         /* ascii strings */
463                         putchar('"');
464                         if (fn_printn(bp, size, snapend)) {
465                                 putchar('"');
466                                 goto trunc;
467                         }
468                         putchar('"');
469                         bp += size;
470                         size = 0;
471                         break;
472
473                 case 'i':
474                 case 'l':
475                 case 'L':
476                         /* ip addresses/32-bit words */
477                         while (size >= sizeof(ul)) {
478                                 if (!first)
479                                         putchar(',');
480                                 ul = EXTRACT_32BITS(bp);
481                                 if (c == 'i') {
482                                         ul = htonl(ul);
483                                         printf("%s", ipaddr_string(&ul));
484                                 } else if (c == 'L')
485                                         printf("%d", ul);
486                                 else
487                                         printf("%u", ul);
488                                 bp += sizeof(ul);
489                                 size -= sizeof(ul);
490                                 first = 0;
491                         }
492                         break;
493
494                 case 'p':
495                         /* IP address pairs */
496                         while (size >= 2*sizeof(ul)) {
497                                 if (!first)
498                                         putchar(',');
499                                 memcpy((char *)&ul, (const char *)bp, sizeof(ul));
500                                 printf("(%s:", ipaddr_string(&ul));
501                                 bp += sizeof(ul);
502                                 memcpy((char *)&ul, (const char *)bp, sizeof(ul));
503                                 printf("%s)", ipaddr_string(&ul));
504                                 bp += sizeof(ul);
505                                 size -= 2*sizeof(ul);
506                                 first = 0;
507                         }
508                         break;
509
510                 case 's':
511                         /* shorts */
512                         while (size >= sizeof(us)) {
513                                 if (!first)
514                                         putchar(',');
515                                 us = EXTRACT_16BITS(bp);
516                                 printf("%u", us);
517                                 bp += sizeof(us);
518                                 size -= sizeof(us);
519                                 first = 0;
520                         }
521                         break;
522
523                 case 'B':
524                         /* boolean */
525                         while (size > 0) {
526                                 if (!first)
527                                         putchar(',');
528                                 switch (*bp) {
529                                 case 0:
530                                         putchar('N');
531                                         break;
532                                 case 1:
533                                         putchar('Y');
534                                         break;
535                                 default:
536                                         printf("%u?", *bp);
537                                         break;
538                                 }
539                                 ++bp;
540                                 --size;
541                                 first = 0;
542                         }
543                         break;
544
545                 case 'b':
546                 case 'x':
547                 default:
548                         /* Bytes */
549                         while (size > 0) {
550                                 if (!first)
551                                         putchar(c == 'x' ? ':' : '.');
552                                 if (c == 'x')
553                                         printf("%02x", *bp);
554                                 else
555                                         printf("%u", *bp);
556                                 ++bp;
557                                 --size;
558                                 first = 0;
559                         }
560                         break;
561
562                 case '$':
563                         /* Guys we can't handle with one of the usual cases */
564                         switch (tag) {
565
566                         case TAG_NETBIOS_NODE:
567                                 tag = *bp++;
568                                 --size;
569                                 fputs(tok2str(nbo2str, NULL, tag), stdout);
570                                 break;
571
572                         case TAG_OPT_OVERLOAD:
573                                 tag = *bp++;
574                                 --size;
575                                 fputs(tok2str(oo2str, NULL, tag), stdout);
576                                 break;
577
578                         case TAG_CLIENT_FQDN:
579                                 /* option 81 should be at least 4 bytes long */
580                                 if (len < 4)  {
581                                         printf("ERROR: options 81 len %u < 4 bytes", len);
582                                         break;
583                                 }
584                                 if (*bp++)
585                                         printf("[svrreg]");
586                                 if (*bp)
587                                         printf("%u/%u/", *bp, *(bp+1));
588                                 bp += 2;
589                                 putchar('"');
590                                 if (fn_printn(bp, size - 3, snapend)) {
591                                         putchar('"');
592                                         goto trunc;
593                                 }
594                                 putchar('"');
595                                 bp += size - 3;
596                                 size = 0;
597                                 break;
598
599                         case TAG_CLIENT_ID:
600                             {   int type = *bp++;
601                                 size--;
602                                 if (type == 0) {
603                                         putchar('"');
604                                         if (fn_printn(bp, size, snapend)) {
605                                                 putchar('"');
606                                                 goto trunc;
607                                         }
608                                         putchar('"');
609                                         bp += size;
610                                         size = 0;
611                                         break;
612                                 } else {
613                                         printf("%s ", tok2str(arp2str, "hardware-type %u,", type));
614                                 }
615                                 while (size > 0) {
616                                         if (!first)
617                                                 putchar(':');
618                                         printf("%02x", *bp);
619                                         ++bp;
620                                         --size;
621                                         first = 0;
622                                 }
623                                 break;
624                             }
625
626                         case TAG_AGENT_CIRCUIT:
627                         {
628                             while (size > 0 ) {
629                             subopt = *bp++;
630                             suboptlen = *bp++;
631                             size -= 2;
632                             printf("\n\t      %s SubOption %u, length %u: ",
633                                    tok2str(agent_suboption_values, "Unknown", subopt),
634                                    subopt,
635                                    suboptlen);
636
637                             if (subopt == 0 || suboptlen == 0) {
638                                 break;
639                             }
640
641                             switch(subopt) {
642                             case AGENT_SUBOPTION_CIRCUIT_ID:
643                                 for (idx = 0; idx < suboptlen; idx++) {
644                                     safeputchar(*(bp+idx));
645                                 }
646                                 break;
647                             default:
648                                 print_unknown_data(bp, "\n\t\t", suboptlen);
649                             }
650
651                             size -= suboptlen;
652                             bp += suboptlen;
653                             }
654                         }
655                             break;
656
657                         default:
658                                 printf("[unknown special tag %u, size %u]",
659                                     tag, size);
660                                 bp += size;
661                                 size = 0;
662                                 break;
663                         }
664                         break;
665                 }
666                 /* Data left over? */
667                 if (size) {
668                         printf("\n\t  trailing data length %u", len);
669                         bp += size;
670                 }
671         }
672         return;
673 trunc:
674         printf("|[rfc1048]");
675 }
676
677 static void
678 cmu_print(register const u_char *bp)
679 {
680         register const struct cmu_vend *cmu;
681
682 #define PRINTCMUADDR(m, s) { TCHECK(cmu->m); \
683     if (cmu->m.s_addr != 0) \
684         printf(" %s:%s", s, ipaddr_string(&cmu->m.s_addr)); }
685
686         printf(" vend-cmu");
687         cmu = (const struct cmu_vend *)bp;
688
689         /* Only print if there are unknown bits */
690         TCHECK(cmu->v_flags);
691         if ((cmu->v_flags & ~(VF_SMASK)) != 0)
692                 printf(" F:0x%x", cmu->v_flags);
693         PRINTCMUADDR(v_dgate, "DG");
694         PRINTCMUADDR(v_smask, cmu->v_flags & VF_SMASK ? "SM" : "SM*");
695         PRINTCMUADDR(v_dns1, "NS1");
696         PRINTCMUADDR(v_dns2, "NS2");
697         PRINTCMUADDR(v_ins1, "IEN1");
698         PRINTCMUADDR(v_ins2, "IEN2");
699         PRINTCMUADDR(v_ts1, "TS1");
700         PRINTCMUADDR(v_ts2, "TS2");
701         return;
702
703 trunc:
704         fputs(tstr, stdout);
705 #undef PRINTCMUADDR
706 }