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