static const char * print_query(const struct query *q, char *buf, size_t max) { char b[256]; snprintf(buf, max, "%s %s %s", print_dname(q->q_dname, b, sizeof b), __p_class(q->q_class), __p_type(q->q_type)); return (buf); }
/* * Print resource record fields in human readable form. */ static char * p_rr(char *cp, char *msg, FILE *file) { int type, class, dlen, n, c; struct in_addr inaddr; char *cp1, *cp2; if ((cp = p_cdname(cp, msg, file)) == NULL) return (NULL); /* compression error */ fprintf(file,"\n\ttype = %s", __p_type(type = _getshort(cp))); cp += sizeof(u_short); fprintf(file,", class = %s", __p_class(class = _getshort(cp))); cp += sizeof(u_short); fprintf(file,", ttl = %s", __p_time(_getlong(cp))); cp += sizeof(u_long); fprintf(file,", dlen = %d\n", dlen = _getshort(cp)); cp += sizeof(u_short); cp1 = cp; /* * Print type specific data, if appropriate */ switch (type) { case T_A: switch (class) { case C_IN: case C_HS: bcopy(cp, (char *)&inaddr, sizeof(inaddr)); if (dlen == 4) { fprintf(file,"\tinternet address = %s\n", inet_ntoa(inaddr)); cp += dlen; } else if (dlen == 7) { fprintf(file,"\tinternet address = %s", inet_ntoa(inaddr)); fprintf(file,", protocol = %d", cp[4]); fprintf(file,", port = %d\n", (cp[5] << 8) + cp[6]); cp += dlen; } break; default: cp += dlen; } break; case T_CNAME: case T_MB: case T_MG: case T_MR: case T_NS: case T_PTR: fprintf(file,"\tdomain name = "); cp = p_cdname(cp, msg, file); fprintf(file,"\n"); break; case T_HINFO: if (n = *cp++) { fprintf(file,"\tCPU=%.*s\n", n, cp); cp += n; } if (n = *cp++) { fprintf(file,"\tOS=%.*s\n", n, cp); cp += n; } break; case T_SOA: fprintf(file,"\torigin = "); cp = p_cdname(cp, msg, file); fprintf(file,"\n\tmail addr = "); cp = p_cdname(cp, msg, file); fprintf(file,"\n\tserial = %ld", _getlong(cp)); cp += sizeof(u_long); fprintf(file,"\n\trefresh = %s", __p_time(_getlong(cp))); cp += sizeof(u_long); fprintf(file,"\n\tretry = %s", __p_time(_getlong(cp))); cp += sizeof(u_long); fprintf(file,"\n\texpire = %s", __p_time(_getlong(cp))); cp += sizeof(u_long); fprintf(file,"\n\tmin = %s\n", __p_time(_getlong(cp))); cp += sizeof(u_long); break; case T_MX: fprintf(file,"\tpreference = %ld,",_getshort(cp)); cp += sizeof(u_short); fprintf(file," name = "); cp = p_cdname(cp, msg, file); break; case T_TXT: (void) fputs("\t\"", file); cp2 = cp1 + dlen; while (cp < cp2) { if (n = (unsigned char) *cp++) { for (c = n; c > 0 && cp < cp2; c--) if (*cp == '\n') { (void) putc('\\', file); (void) putc(*cp++, file); } else (void) putc(*cp++, file); } } (void) fputs("\"\n", file); break; case T_MINFO: fprintf(file,"\trequests = "); cp = p_cdname(cp, msg, file); fprintf(file,"\n\terrors = "); cp = p_cdname(cp, msg, file); break; case T_UINFO: fprintf(file,"\t%s\n", cp); cp += dlen; break; case T_UID: case T_GID: if (dlen == 4) { fprintf(file,"\t%ld\n", _getlong(cp)); cp += sizeof(int); } break; case T_WKS: if (dlen < sizeof(u_long) + 1) break; bcopy(cp, (char *)&inaddr, sizeof(inaddr)); cp += sizeof(u_long); fprintf(file,"\tinternet address = %s, protocol = %d\n\t", inet_ntoa(inaddr), *cp++); n = 0; while (cp < cp1 + dlen) { c = *cp++; do { if (c & 0200) fprintf(file," %d", n); c <<= 1; } while (++n & 07); } putc('\n',file); break; #ifdef ALLOW_T_UNSPEC case T_UNSPEC: { int NumBytes = 8; char *DataPtr; int i; if (dlen < NumBytes) NumBytes = dlen; fprintf(file, "\tFirst %d bytes of hex data:", NumBytes); for (i = 0, DataPtr = cp; i < NumBytes; i++, DataPtr++) fprintf(file, " %x", *DataPtr); fputs("\n", file); cp += dlen; } break; #endif /* ALLOW_T_UNSPEC */ default: fprintf(file,"\t???\n"); cp += dlen; } if (cp != cp1 + dlen) { fprintf(file,"packet size error (%#x != %#x)\n", cp, cp1+dlen); cp = NULL; } fprintf(file,"\n"); return (cp); }
/* * Print the contents of a query. * This is intended to be primarily a debugging routine. */ void __fp_query(char *msg, FILE *file) { register char *cp; register HEADER *hp; register int n; /* * Print header fields. */ hp = (HEADER *)msg; cp = msg + sizeof(HEADER); fprintf(file,"HEADER:\n"); fprintf(file,"\topcode = %s", _res_opcodes[hp->opcode]); fprintf(file,", id = %d", ntohs(hp->id)); fprintf(file,", rcode = %s\n", _res_resultcodes[hp->rcode]); fprintf(file,"\theader flags: "); if (hp->qr) fprintf(file," qr"); if (hp->aa) fprintf(file," aa"); if (hp->tc) fprintf(file," tc"); if (hp->rd) fprintf(file," rd"); if (hp->ra) fprintf(file," ra"); if (hp->pr) fprintf(file," pr"); fprintf(file,"\n\tqdcount = %d", ntohs(hp->qdcount)); fprintf(file,", ancount = %d", ntohs(hp->ancount)); fprintf(file,", nscount = %d", ntohs(hp->nscount)); fprintf(file,", arcount = %d\n\n", ntohs(hp->arcount)); /* * Print question records. */ if (n = ntohs(hp->qdcount)) { fprintf(file,"QUESTIONS:\n"); while (--n >= 0) { fprintf(file,"\t"); cp = p_cdname(cp, msg, file); if (cp == NULL) return; fprintf(file,", type = %s", __p_type(_getshort(cp))); cp += sizeof(u_short); fprintf(file, ", class = %s\n\n", __p_class(_getshort(cp))); cp += sizeof(u_short); } } /* * Print authoritative answer records */ if (n = ntohs(hp->ancount)) { fprintf(file,"ANSWERS:\n"); while (--n >= 0) { fprintf(file,"\t"); cp = p_rr(cp, msg, file); if (cp == NULL) return; } } /* * print name server records */ if (n = ntohs(hp->nscount)) { fprintf(file,"NAME SERVERS:\n"); while (--n >= 0) { fprintf(file,"\t"); cp = p_rr(cp, msg, file); if (cp == NULL) return; } } /* * print additional records */ if (n = ntohs(hp->arcount)) { fprintf(file,"ADDITIONAL RECORDS:\n"); while (--n >= 0) { fprintf(file,"\t"); cp = p_rr(cp, msg, file); if (cp == NULL) return; } } }
static const char * print_rr(const struct rr *rr, char *buf, size_t max) { char *res; char tmp[256]; char tmp2[256]; int r; res = buf; r = snprintf(buf, max, "%s %u %s %s ", print_dname(rr->rr_dname, tmp, sizeof tmp), rr->rr_ttl, __p_class(rr->rr_class), __p_type(rr->rr_type)); if (r == -1) { buf[0] = '\0'; return (buf); } if ((size_t)r >= max) return (buf); max -= r; buf += r; switch (rr->rr_type) { case T_CNAME: print_dname(rr->rr.cname.cname, buf, max); break; case T_MX: snprintf(buf, max, "%lu %s", (unsigned long)rr->rr.mx.preference, print_dname(rr->rr.mx.exchange, tmp, sizeof tmp)); break; case T_NS: print_dname(rr->rr.ns.nsname, buf, max); break; case T_PTR: print_dname(rr->rr.ptr.ptrname, buf, max); break; case T_SOA: snprintf(buf, max, "%s %s %lu %lu %lu %lu %lu", print_dname(rr->rr.soa.rname, tmp, sizeof tmp), print_dname(rr->rr.soa.mname, tmp2, sizeof tmp2), (unsigned long)rr->rr.soa.serial, (unsigned long)rr->rr.soa.refresh, (unsigned long)rr->rr.soa.retry, (unsigned long)rr->rr.soa.expire, (unsigned long)rr->rr.soa.minimum); break; case T_A: if (rr->rr_class != C_IN) goto other; snprintf(buf, max, "%s", inet_ntop(AF_INET, &rr->rr.in_a.addr, tmp, sizeof tmp)); break; case T_AAAA: if (rr->rr_class != C_IN) goto other; snprintf(buf, max, "%s", inet_ntop(AF_INET6, &rr->rr.in_aaaa.addr6, tmp, sizeof tmp)); break; default: other: snprintf(buf, max, "(rdlen=%i)", (int)rr->rr.other.rdlen); break; } return (res); }