Import of tcpdump 3.8.3
[dragonfly.git] / contrib / tcpdump-3.8.3 / print-domain.c
1 /*
2  * Copyright (c) 1988, 1989, 1990, 1991, 1992, 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
22 #ifndef lint
23 static const char rcsid[] _U_ =
24     "@(#) $Header: /tcpdump/master/tcpdump/print-domain.c,v 1.86.2.3 2004/03/28 20:54:00 fenner Exp $ (LBL)";
25 #endif
26
27 #ifdef HAVE_CONFIG_H
28 #include "config.h"
29 #endif
30
31 #include <tcpdump-stdinc.h>
32
33 #include "nameser.h"
34
35 #include <stdio.h>
36 #include <string.h>
37
38 #include "interface.h"
39 #include "addrtoname.h"
40 #include "extract.h"                    /* must come after interface.h */
41
42 static const char *ns_ops[] = {
43         "", " inv_q", " stat", " op3", " notify", " update", " op6", " op7",
44         " op8", " updataA", " updateD", " updateDA",
45         " updateM", " updateMA", " zoneInit", " zoneRef",
46 };
47
48 static const char *ns_resp[] = {
49         "", " FormErr", " ServFail", " NXDomain",
50         " NotImp", " Refused", " YXDomain", " YXRRSet",
51         " NXRRSet", " NotAuth", " NotZone", " Resp11",
52         " Resp12", " Resp13", " Resp14", " NoChange",
53 };
54
55 /* skip over a domain name */
56 static const u_char *
57 ns_nskip(register const u_char *cp)
58 {
59         register u_char i;
60
61         if (!TTEST2(*cp, 1))
62                 return (NULL);
63         i = *cp++;
64         while (i) {
65                 if ((i & INDIR_MASK) == INDIR_MASK)
66                         return (cp + 1);
67                 if ((i & INDIR_MASK) == EDNS0_MASK) {
68                         int bitlen, bytelen;
69
70                         if ((i & ~INDIR_MASK) != EDNS0_ELT_BITLABEL)
71                                 return(NULL); /* unknown ELT */
72                         if (!TTEST2(*cp, 1))
73                                 return (NULL);
74                         if ((bitlen = *cp++) == 0)
75                                 bitlen = 256;
76                         bytelen = (bitlen + 7) / 8;
77                         cp += bytelen;
78                 } else
79                         cp += i;
80                 if (!TTEST2(*cp, 1))
81                         return (NULL);
82                 i = *cp++;
83         }
84         return (cp);
85 }
86
87 /* print a <domain-name> */
88 static const u_char *
89 blabel_print(const u_char *cp)
90 {
91         int bitlen, slen, b;
92         const u_char *bitp, *lim;
93         char tc;
94
95         if (!TTEST2(*cp, 1))
96                 return(NULL);
97         if ((bitlen = *cp) == 0)
98                 bitlen = 256;
99         slen = (bitlen + 3) / 4;
100         lim = cp + 1 + slen;
101
102         /* print the bit string as a hex string */
103         printf("\\[x");
104         for (bitp = cp + 1, b = bitlen; bitp < lim && b > 7; b -= 8, bitp++) {
105                 TCHECK(*bitp);
106                 printf("%02x", *bitp);
107         }
108         if (b > 4) {
109                 TCHECK(*bitp);
110                 tc = *bitp++;
111                 printf("%02x", tc & (0xff << (8 - b)));
112         } else if (b > 0) {
113                 TCHECK(*bitp);
114                 tc = *bitp++;
115                 printf("%1x", ((tc >> 4) & 0x0f) & (0x0f << (4 - b)));
116         }
117         printf("/%d]", bitlen);
118         return lim;
119 trunc:
120         printf(".../%d]", bitlen);
121         return NULL;
122 }
123
124 static int
125 labellen(const u_char *cp)
126 {
127         register u_int i;
128
129         if (!TTEST2(*cp, 1))
130                 return(-1);
131         i = *cp;
132         if ((i & INDIR_MASK) == EDNS0_MASK) {
133                 int bitlen, elt;
134
135                 if ((elt = (i & ~INDIR_MASK)) != EDNS0_ELT_BITLABEL)
136                         return(-1);
137                 if (!TTEST2(*(cp + 1), 1))
138                         return(-1);
139                 if ((bitlen = *(cp + 1)) == 0)
140                         bitlen = 256;
141                 return(((bitlen + 7) / 8) + 1);
142         } else
143                 return(i);
144 }
145
146 static const u_char *
147 ns_nprint(register const u_char *cp, register const u_char *bp)
148 {
149         register u_int i, l;
150         register const u_char *rp = NULL;
151         register int compress = 0;
152         int chars_processed;
153         int elt;
154         int data_size = snapend - bp;
155
156         if ((l = labellen(cp)) == (u_int)-1)
157                 return(NULL);
158         if (!TTEST2(*cp, 1))
159                 return(NULL);
160         chars_processed = 1;
161         if (((i = *cp++) & INDIR_MASK) != INDIR_MASK) {
162                 compress = 0;
163                 rp = cp + l;
164         }
165
166         if (i != 0)
167                 while (i && cp < snapend) {
168                         if ((i & INDIR_MASK) == INDIR_MASK) {
169                                 if (!compress) {
170                                         rp = cp + 1;
171                                         compress = 1;
172                                 }
173                                 if (!TTEST2(*cp, 1))
174                                         return(NULL);
175                                 cp = bp + (((i << 8) | *cp) & 0x3fff);
176                                 if ((l = labellen(cp)) == (u_int)-1)
177                                         return(NULL);
178                                 if (!TTEST2(*cp, 1))
179                                         return(NULL);
180                                 i = *cp++;
181                                 chars_processed++;
182
183                                 /*
184                                  * If we've looked at every character in
185                                  * the message, this pointer will make
186                                  * us look at some character again,
187                                  * which means we're looping.
188                                  */
189                                 if (chars_processed >= data_size) {
190                                         printf("<LOOP>");
191                                         return (NULL);
192                                 }
193                                 continue;
194                         }
195                         if ((i & INDIR_MASK) == EDNS0_MASK) {
196                                 elt = (i & ~INDIR_MASK);
197                                 switch(elt) {
198                                 case EDNS0_ELT_BITLABEL:
199                                         if (blabel_print(cp) == NULL)
200                                                 return (NULL);
201                                         break;
202                                 default:
203                                         /* unknown ELT */
204                                         printf("<ELT %d>", elt);
205                                         return(NULL);
206                                 }
207                         } else {
208                                 if (fn_printn(cp, l, snapend))
209                                         return(NULL);
210                         }
211
212                         cp += l;
213                         chars_processed += l;
214                         putchar('.');
215                         if ((l = labellen(cp)) == (u_int)-1)
216                                 return(NULL);
217                         if (!TTEST2(*cp, 1))
218                                 return(NULL);
219                         i = *cp++;
220                         chars_processed++;
221                         if (!compress)
222                                 rp += l + 1;
223                 }
224         else
225                 putchar('.');
226         return (rp);
227 }
228
229 /* print a <character-string> */
230 static const u_char *
231 ns_cprint(register const u_char *cp)
232 {
233         register u_int i;
234
235         if (!TTEST2(*cp, 1))
236                 return (NULL);
237         i = *cp++;
238         if (fn_printn(cp, i, snapend))
239                 return (NULL);
240         return (cp + i);
241 }
242
243 /* http://www.iana.org/assignments/dns-parameters */
244 struct tok ns_type2str[] = {
245         { T_A,          "A" },                  /* RFC 1035 */
246         { T_NS,         "NS" },                 /* RFC 1035 */
247         { T_MD,         "MD" },                 /* RFC 1035 */
248         { T_MF,         "MF" },                 /* RFC 1035 */
249         { T_CNAME,      "CNAME" },              /* RFC 1035 */
250         { T_SOA,        "SOA" },                /* RFC 1035 */
251         { T_MB,         "MB" },                 /* RFC 1035 */
252         { T_MG,         "MG" },                 /* RFC 1035 */
253         { T_MR,         "MR" },                 /* RFC 1035 */
254         { T_NULL,       "NULL" },               /* RFC 1035 */
255         { T_WKS,        "WKS" },                /* RFC 1035 */
256         { T_PTR,        "PTR" },                /* RFC 1035 */
257         { T_HINFO,      "HINFO" },              /* RFC 1035 */
258         { T_MINFO,      "MINFO" },              /* RFC 1035 */
259         { T_MX,         "MX" },                 /* RFC 1035 */
260         { T_TXT,        "TXT" },                /* RFC 1035 */
261         { T_RP,         "RP" },                 /* RFC 1183 */
262         { T_AFSDB,      "AFSDB" },              /* RFC 1183 */
263         { T_X25,        "X25" },                /* RFC 1183 */
264         { T_ISDN,       "ISDN" },               /* RFC 1183 */
265         { T_RT,         "RT" },                 /* RFC 1183 */
266         { T_NSAP,       "NSAP" },               /* RFC 1706 */
267         { T_NSAP_PTR,   "NSAP_PTR" },
268         { T_SIG,        "SIG" },                /* RFC 2535 */
269         { T_KEY,        "KEY" },                /* RFC 2535 */
270         { T_PX,         "PX" },                 /* RFC 2163 */
271         { T_GPOS,       "GPOS" },               /* RFC 1712 */
272         { T_AAAA,       "AAAA" },               /* RFC 1886 */
273         { T_LOC,        "LOC" },                /* RFC 1876 */
274         { T_NXT,        "NXT" },                /* RFC 2535 */
275         { T_EID,        "EID" },                /* Nimrod */
276         { T_NIMLOC,     "NIMLOC" },             /* Nimrod */
277         { T_SRV,        "SRV" },                /* RFC 2782 */
278         { T_ATMA,       "ATMA" },               /* ATM Forum */
279         { T_NAPTR,      "NAPTR" },              /* RFC 2168, RFC 2915 */
280         { T_A6,         "A6" },                 /* RFC 2874 */
281         { T_DNAME,      "DNAME" },              /* RFC 2672 */
282         { T_OPT,        "OPT" },                /* RFC 2671 */
283         { T_UINFO,      "UINFO" },
284         { T_UID,        "UID" },
285         { T_GID,        "GID" },
286         { T_UNSPEC,     "UNSPEC" },
287         { T_UNSPECA,    "UNSPECA" },
288         { T_TKEY,       "TKEY" },               /* RFC 2930 */
289         { T_TSIG,       "TSIG" },               /* RFC 2845 */
290         { T_IXFR,       "IXFR" },               /* RFC 1995 */
291         { T_AXFR,       "AXFR" },               /* RFC 1035 */
292         { T_MAILB,      "MAILB" },              /* RFC 1035 */
293         { T_MAILA,      "MAILA" },              /* RFC 1035 */
294         { T_ANY,        "ANY" },
295         { 0,            NULL }
296 };
297
298 struct tok ns_class2str[] = {
299         { C_IN,         "IN" },         /* Not used */
300         { C_CHAOS,      "CHAOS" },
301         { C_HS,         "HS" },
302         { C_ANY,        "ANY" },
303         { 0,            NULL }
304 };
305
306 /* print a query */
307 static const u_char *
308 ns_qprint(register const u_char *cp, register const u_char *bp, int is_mdns)
309 {
310         register const u_char *np = cp;
311         register u_int i;
312
313         cp = ns_nskip(cp);
314
315         if (cp == NULL || !TTEST2(*cp, 4))
316                 return(NULL);
317
318         /* print the qtype and qclass (if it's not IN) */
319         i = EXTRACT_16BITS(cp);
320         cp += 2;
321         printf(" %s", tok2str(ns_type2str, "Type%d", i));
322         i = EXTRACT_16BITS(cp);
323         cp += 2;
324         if (is_mdns && i == (C_IN|C_CACHE_FLUSH))
325                 printf(" (Cache flush)");
326         else if (i != C_IN)
327                 printf(" %s", tok2str(ns_class2str, "(Class %d)", i));
328
329         fputs("? ", stdout);
330         cp = ns_nprint(np, bp);
331         return(cp ? cp + 4 : NULL);
332 }
333
334 /* print a reply */
335 static const u_char *
336 ns_rprint(register const u_char *cp, register const u_char *bp, int is_mdns)
337 {
338         register u_int class;
339         register u_short typ, len;
340         register const u_char *rp;
341
342         if (vflag) {
343                 putchar(' ');
344                 if ((cp = ns_nprint(cp, bp)) == NULL)
345                         return NULL;
346         } else
347                 cp = ns_nskip(cp);
348
349         if (cp == NULL || !TTEST2(*cp, 10))
350                 return (snapend);
351
352         /* print the type/qtype and class (if it's not IN) */
353         typ = EXTRACT_16BITS(cp);
354         cp += 2;
355         class = EXTRACT_16BITS(cp);
356         cp += 2;
357         if (is_mdns && class == (C_IN|C_CACHE_FLUSH))
358                 printf(" (Cache flush)");
359         else if (class != C_IN && typ != T_OPT)
360                 printf(" %s", tok2str(ns_class2str, "(Class %d)", class));
361
362         /* ignore ttl */
363         cp += 4;
364
365         len = EXTRACT_16BITS(cp);
366         cp += 2;
367
368         rp = cp + len;
369
370         printf(" %s", tok2str(ns_type2str, "Type%d", typ));
371         if (rp > snapend)
372                 return(NULL);
373
374         switch (typ) {
375         case T_A:
376                 if (!TTEST2(*cp, sizeof(struct in_addr)))
377                         return(NULL);
378                 printf(" %s", ipaddr_string(cp));
379                 break;
380
381         case T_NS:
382         case T_CNAME:
383         case T_PTR:
384 #ifdef T_DNAME
385         case T_DNAME:
386 #endif
387                 putchar(' ');
388                 if (ns_nprint(cp, bp) == NULL)
389                         return(NULL);
390                 break;
391
392         case T_SOA:
393                 if (!vflag)
394                         break;
395                 putchar(' ');
396                 if ((cp = ns_nprint(cp, bp)) == NULL)
397                         return(NULL);
398                 putchar(' ');
399                 if ((cp = ns_nprint(cp, bp)) == NULL)
400                         return(NULL);
401                 if (!TTEST2(*cp, 5 * 4))
402                         return(NULL);
403                 printf(" %u", EXTRACT_32BITS(cp));
404                 cp += 4;
405                 printf(" %u", EXTRACT_32BITS(cp));
406                 cp += 4;
407                 printf(" %u", EXTRACT_32BITS(cp));
408                 cp += 4;
409                 printf(" %u", EXTRACT_32BITS(cp));
410                 cp += 4;
411                 printf(" %u", EXTRACT_32BITS(cp));
412                 cp += 4;
413                 break;
414         case T_MX:
415                 putchar(' ');
416                 if (!TTEST2(*cp, 2))
417                         return(NULL);
418                 if (ns_nprint(cp + 2, bp) == NULL)
419                         return(NULL);
420                 printf(" %d", EXTRACT_16BITS(cp));
421                 break;
422
423         case T_TXT:
424                 while (cp < rp) {
425                         printf(" \"");
426                         cp = ns_cprint(cp);
427                         if (cp == NULL)
428                                 return(NULL);
429                         putchar('"');
430                 }
431                 break;
432
433         case T_SRV:
434                 putchar(' ');
435                 if (!TTEST2(*cp, 6))
436                         return(NULL);
437                 if (ns_nprint(cp + 6, bp) == NULL)
438                         return(NULL);
439                 printf(":%d %d %d", EXTRACT_16BITS(cp + 4),
440                         EXTRACT_16BITS(cp), EXTRACT_16BITS(cp + 2));
441                 break;
442
443 #ifdef INET6
444         case T_AAAA:
445                 if (!TTEST2(*cp, sizeof(struct in6_addr)))
446                         return(NULL);
447                 printf(" %s", ip6addr_string(cp));
448                 break;
449
450         case T_A6:
451             {
452                 struct in6_addr a;
453                 int pbit, pbyte;
454
455                 if (!TTEST2(*cp, 1))
456                         return(NULL);
457                 pbit = *cp;
458                 pbyte = (pbit & ~7) / 8;
459                 if (pbit > 128) {
460                         printf(" %u(bad plen)", pbit);
461                         break;
462                 } else if (pbit < 128) {
463                         if (!TTEST2(*(cp + 1), sizeof(a) - pbyte))
464                                 return(NULL);
465                         memset(&a, 0, sizeof(a));
466                         memcpy(&a.s6_addr[pbyte], cp + 1, sizeof(a) - pbyte);
467                         printf(" %u %s", pbit, ip6addr_string(&a));
468                 }
469                 if (pbit > 0) {
470                         putchar(' ');
471                         if (ns_nprint(cp + 1 + sizeof(a) - pbyte, bp) == NULL)
472                                 return(NULL);
473                 }
474                 break;
475             }
476 #endif /*INET6*/
477
478         case T_OPT:
479                 printf(" UDPsize=%u", class);
480                 break;
481
482         case T_UNSPECA:         /* One long string */
483                 if (!TTEST2(*cp, len))
484                         return(NULL);
485                 if (fn_printn(cp, len, snapend))
486                         return(NULL);
487                 break;
488
489         case T_TSIG:
490             {
491                 if (cp + len > snapend)
492                         return(NULL);
493                 if (!vflag)
494                         break;
495                 putchar(' ');
496                 if ((cp = ns_nprint(cp, bp)) == NULL)
497                         return(NULL);
498                 cp += 6;
499                 if (!TTEST2(*cp, 2))
500                         return(NULL);
501                 printf(" fudge=%u", EXTRACT_16BITS(cp));
502                 cp += 2;
503                 if (!TTEST2(*cp, 2))
504                         return(NULL);
505                 printf(" maclen=%u", EXTRACT_16BITS(cp));
506                 cp += 2 + EXTRACT_16BITS(cp);
507                 if (!TTEST2(*cp, 2))
508                         return(NULL);
509                 printf(" origid=%u", EXTRACT_16BITS(cp));
510                 cp += 2;
511                 if (!TTEST2(*cp, 2))
512                         return(NULL);
513                 printf(" error=%u", EXTRACT_16BITS(cp));
514                 cp += 2;
515                 if (!TTEST2(*cp, 2))
516                         return(NULL);
517                 printf(" otherlen=%u", EXTRACT_16BITS(cp));
518                 cp += 2;
519             }
520         }
521         return (rp);            /* XXX This isn't always right */
522 }
523
524 void
525 ns_print(register const u_char *bp, u_int length, int is_mdns)
526 {
527         register const HEADER *np;
528         register int qdcount, ancount, nscount, arcount;
529         register const u_char *cp;
530         u_int16_t b2;
531
532         np = (const HEADER *)bp;
533         TCHECK(*np);
534         /* get the byte-order right */
535         qdcount = EXTRACT_16BITS(&np->qdcount);
536         ancount = EXTRACT_16BITS(&np->ancount);
537         nscount = EXTRACT_16BITS(&np->nscount);
538         arcount = EXTRACT_16BITS(&np->arcount);
539
540         if (DNS_QR(np)) {
541                 /* this is a response */
542                 printf(" %d%s%s%s%s%s%s",
543                         EXTRACT_16BITS(&np->id),
544                         ns_ops[DNS_OPCODE(np)],
545                         ns_resp[DNS_RCODE(np)],
546                         DNS_AA(np)? "*" : "",
547                         DNS_RA(np)? "" : "-",
548                         DNS_TC(np)? "|" : "",
549                         DNS_AD(np)? "$" : "");
550
551                 if (qdcount != 1)
552                         printf(" [%dq]", qdcount);
553                 /* Print QUESTION section on -vv */
554                 cp = (const u_char *)(np + 1);
555                 while (qdcount--) {
556                         if (qdcount < EXTRACT_16BITS(&np->qdcount) - 1)
557                                 putchar(',');
558                         if (vflag > 1) {
559                                 fputs(" q:", stdout);
560                                 if ((cp = ns_qprint(cp, bp, is_mdns)) == NULL)
561                                         goto trunc;
562                         } else {
563                                 if ((cp = ns_nskip(cp)) == NULL)
564                                         goto trunc;
565                                 cp += 4;        /* skip QTYPE and QCLASS */
566                         }
567                 }
568                 printf(" %d/%d/%d", ancount, nscount, arcount);
569                 if (ancount--) {
570                         if ((cp = ns_rprint(cp, bp, is_mdns)) == NULL)
571                                 goto trunc;
572                         while (cp < snapend && ancount--) {
573                                 putchar(',');
574                                 if ((cp = ns_rprint(cp, bp, is_mdns)) == NULL)
575                                         goto trunc;
576                         }
577                 }
578                 if (ancount > 0)
579                         goto trunc;
580                 /* Print NS and AR sections on -vv */
581                 if (vflag > 1) {
582                         if (cp < snapend && nscount--) {
583                                 fputs(" ns:", stdout);
584                                 if ((cp = ns_rprint(cp, bp, is_mdns)) == NULL)
585                                         goto trunc;
586                                 while (cp < snapend && nscount--) {
587                                         putchar(',');
588                                         if ((cp = ns_rprint(cp, bp, is_mdns)) == NULL)
589                                                 goto trunc;
590                                 }
591                         }
592                         if (nscount > 0)
593                                 goto trunc;
594                         if (cp < snapend && arcount--) {
595                                 fputs(" ar:", stdout);
596                                 if ((cp = ns_rprint(cp, bp, is_mdns)) == NULL)
597                                         goto trunc;
598                                 while (cp < snapend && arcount--) {
599                                         putchar(',');
600                                         if ((cp = ns_rprint(cp, bp, is_mdns)) == NULL)
601                                                 goto trunc;
602                                 }
603                         }
604                         if (arcount > 0)
605                                 goto trunc;
606                 }
607         }
608         else {
609                 /* this is a request */
610                 printf(" %d%s%s%s", EXTRACT_16BITS(&np->id), ns_ops[DNS_OPCODE(np)],
611                     DNS_RD(np) ? "+" : "",
612                     DNS_CD(np) ? "%" : "");
613
614                 /* any weirdness? */
615                 b2 = EXTRACT_16BITS(((u_short *)np)+1);
616                 if (b2 & 0x6cf)
617                         printf(" [b2&3=0x%x]", b2);
618
619                 if (DNS_OPCODE(np) == IQUERY) {
620                         if (qdcount)
621                                 printf(" [%dq]", qdcount);
622                         if (ancount != 1)
623                                 printf(" [%da]", ancount);
624                 }
625                 else {
626                         if (ancount)
627                                 printf(" [%da]", ancount);
628                         if (qdcount != 1)
629                                 printf(" [%dq]", qdcount);
630                 }
631                 if (nscount)
632                         printf(" [%dn]", nscount);
633                 if (arcount)
634                         printf(" [%dau]", arcount);
635
636                 cp = (const u_char *)(np + 1);
637                 if (qdcount--) {
638                         cp = ns_qprint(cp, (const u_char *)np, is_mdns);
639                         if (!cp)
640                                 goto trunc;
641                         while (cp < snapend && qdcount--) {
642                                 cp = ns_qprint((const u_char *)cp,
643                                                (const u_char *)np,
644                                                is_mdns);
645                                 if (!cp)
646                                         goto trunc;
647                         }
648                 }
649                 if (qdcount > 0)
650                         goto trunc;
651
652                 /* Print remaining sections on -vv */
653                 if (vflag > 1) {
654                         if (ancount--) {
655                                 if ((cp = ns_rprint(cp, bp, is_mdns)) == NULL)
656                                         goto trunc;
657                                 while (cp < snapend && ancount--) {
658                                         putchar(',');
659                                         if ((cp = ns_rprint(cp, bp, is_mdns)) == NULL)
660                                                 goto trunc;
661                                 }
662                         }
663                         if (ancount > 0)
664                                 goto trunc;
665                         if (cp < snapend && nscount--) {
666                                 fputs(" ns:", stdout);
667                                 if ((cp = ns_rprint(cp, bp, is_mdns)) == NULL)
668                                         goto trunc;
669                                 while (nscount-- && cp < snapend) {
670                                         putchar(',');
671                                         if ((cp = ns_rprint(cp, bp, is_mdns)) == NULL)
672                                                 goto trunc;
673                                 }
674                         }
675                         if (nscount > 0)
676                                 goto trunc;
677                         if (cp < snapend && arcount--) {
678                                 fputs(" ar:", stdout);
679                                 if ((cp = ns_rprint(cp, bp, is_mdns)) == NULL)
680                                         goto trunc;
681                                 while (cp < snapend && arcount--) {
682                                         putchar(',');
683                                         if ((cp = ns_rprint(cp, bp, is_mdns)) == NULL)
684                                                 goto trunc;
685                                 }
686                         }
687                         if (arcount > 0)
688                                 goto trunc;
689                 }
690         }
691         printf(" (%d)", length);
692         return;
693
694   trunc:
695         printf("[|domain]");
696         return;
697 }