isc_result_t printmessage(dig_query_t *query, dns_message_t *msg, isc_boolean_t headers) { char servtext[ISC_SOCKADDR_FORMATSIZE]; /* I've we've gotten this far, we've reached a server. */ query_error = 0; debug("printmessage()"); isc_sockaddr_format(&query->sockaddr, servtext, sizeof(servtext)); printf("Server:\t\t%s\n", query->userarg); printf("Address:\t%s\n", servtext); puts(""); if (!short_form) { isc_boolean_t headers = ISC_TRUE; puts("------------"); /* detailheader(query, msg);*/ detailsection(query, msg, headers, DNS_SECTION_QUESTION); detailsection(query, msg, headers, DNS_SECTION_ANSWER); detailsection(query, msg, headers, DNS_SECTION_AUTHORITY); detailsection(query, msg, headers, DNS_SECTION_ADDITIONAL); puts("------------"); } if (msg->rcode != 0) { char nametext[DNS_NAME_FORMATSIZE]; dns_name_format(query->lookup->name, nametext, sizeof(nametext)); printf("** server can't find %s: %s\n", nametext, rcode_totext(msg->rcode)); debug("returning with rcode == 0"); /* the lookup failed */ print_error |= 1; return (ISC_R_SUCCESS); } if ((msg->flags & DNS_MESSAGEFLAG_AA) == 0) puts("Non-authoritative answer:"); if (!ISC_LIST_EMPTY(msg->sections[DNS_SECTION_ANSWER])) printsection(query, msg, headers, DNS_SECTION_ANSWER); else printf("*** Can't find %s: No answer\n", query->lookup->textname); if (((msg->flags & DNS_MESSAGEFLAG_AA) == 0) && (query->lookup->rdtype != dns_rdatatype_a)) { puts("\nAuthoritative answers can be found from:"); printsection(query, msg, headers, DNS_SECTION_AUTHORITY); printsection(query, msg, headers, DNS_SECTION_ADDITIONAL); } return (ISC_R_SUCCESS); }
/* * Callback from dighost.c to print the reply from a server */ isc_result_t printmessage(dig_query_t *query, dns_message_t *msg, isc_boolean_t headers) { isc_result_t result; dns_messagetextflag_t flags; isc_buffer_t *buf = NULL; unsigned int len = OUTPUTBUF; dns_master_style_t *style = NULL; unsigned int styleflags = 0; styleflags |= DNS_STYLEFLAG_REL_OWNER; if (query->lookup->comments) styleflags |= DNS_STYLEFLAG_COMMENT; if (rrcomments) styleflags |= DNS_STYLEFLAG_RRCOMMENT; if (nottl) styleflags |= DNS_STYLEFLAG_NO_TTL; if (noclass) styleflags |= DNS_STYLEFLAG_NO_CLASS; if (multiline) { styleflags |= DNS_STYLEFLAG_OMIT_OWNER; styleflags |= DNS_STYLEFLAG_OMIT_CLASS; styleflags |= DNS_STYLEFLAG_REL_DATA; styleflags |= DNS_STYLEFLAG_OMIT_TTL; styleflags |= DNS_STYLEFLAG_TTL; styleflags |= DNS_STYLEFLAG_MULTILINE; styleflags |= DNS_STYLEFLAG_RRCOMMENT; } if (multiline || (nottl && noclass)) result = dns_master_stylecreate2(&style, styleflags, 24, 24, 24, 32, 80, 8, splitwidth, mctx); else if (nottl || noclass) result = dns_master_stylecreate2(&style, styleflags, 24, 24, 32, 40, 80, 8, splitwidth, mctx); else result = dns_master_stylecreate2(&style, styleflags, 24, 32, 40, 48, 80, 8, splitwidth, mctx); check_result(result, "dns_master_stylecreate"); if (query->lookup->cmdline[0] != 0) { if (!short_form) fputs(query->lookup->cmdline, stdout); query->lookup->cmdline[0]=0; } debug("printmessage(%s %s %s)", headers ? "headers" : "noheaders", query->lookup->comments ? "comments" : "nocomments", short_form ? "short_form" : "long_form"); flags = 0; if (!headers) { flags |= DNS_MESSAGETEXTFLAG_NOHEADERS; flags |= DNS_MESSAGETEXTFLAG_NOCOMMENTS; } if (onesoa && query->lookup->rdtype == dns_rdatatype_axfr) flags |= (query->msg_count == 0) ? DNS_MESSAGETEXTFLAG_ONESOA : DNS_MESSAGETEXTFLAG_OMITSOA; if (!query->lookup->comments) flags |= DNS_MESSAGETEXTFLAG_NOCOMMENTS; result = isc_buffer_allocate(mctx, &buf, len); check_result(result, "isc_buffer_allocate"); if (query->lookup->comments && !short_form) { if (query->lookup->cmdline[0] != 0) printf("; %s\n", query->lookup->cmdline); if (msg == query->lookup->sendmsg) printf(";; Sending:\n"); else printf(";; Got answer:\n"); if (headers) { printf(";; ->>HEADER<<- opcode: %s, status: %s, " "id: %u\n", opcodetext[msg->opcode], rcode_totext(msg->rcode), msg->id); printf(";; flags:"); if ((msg->flags & DNS_MESSAGEFLAG_QR) != 0) printf(" qr"); if ((msg->flags & DNS_MESSAGEFLAG_AA) != 0) printf(" aa"); if ((msg->flags & DNS_MESSAGEFLAG_TC) != 0) printf(" tc"); if ((msg->flags & DNS_MESSAGEFLAG_RD) != 0) printf(" rd"); if ((msg->flags & DNS_MESSAGEFLAG_RA) != 0) printf(" ra"); if ((msg->flags & DNS_MESSAGEFLAG_AD) != 0) printf(" ad"); if ((msg->flags & DNS_MESSAGEFLAG_CD) != 0) printf(" cd"); if ((msg->flags & 0x0040U) != 0) printf("; MBZ: 0x4"); printf("; QUERY: %u, ANSWER: %u, " "AUTHORITY: %u, ADDITIONAL: %u\n", msg->counts[DNS_SECTION_QUESTION], msg->counts[DNS_SECTION_ANSWER], msg->counts[DNS_SECTION_AUTHORITY], msg->counts[DNS_SECTION_ADDITIONAL]); if (msg != query->lookup->sendmsg && (msg->flags & DNS_MESSAGEFLAG_RD) != 0 && (msg->flags & DNS_MESSAGEFLAG_RA) == 0) printf(";; WARNING: recursion requested " "but not available\n"); } if (msg != query->lookup->sendmsg && query->lookup->edns != -1 && msg->opt == NULL && (msg->rcode == dns_rcode_formerr || msg->rcode == dns_rcode_notimp)) printf("\n;; WARNING: EDNS query returned status " "%s - retry with '+noedns'\n", rcode_totext(msg->rcode)); if (msg != query->lookup->sendmsg && extrabytes != 0U) printf(";; WARNING: Messages has %u extra byte%s at " "end\n", extrabytes, extrabytes != 0 ? "s" : ""); } repopulate_buffer: if (query->lookup->comments && headers && !short_form) { result = dns_message_pseudosectiontotext(msg, DNS_PSEUDOSECTION_OPT, style, flags, buf); if (result == ISC_R_NOSPACE) { buftoosmall: len += OUTPUTBUF; isc_buffer_free(&buf); result = isc_buffer_allocate(mctx, &buf, len); if (result == ISC_R_SUCCESS) goto repopulate_buffer; else goto cleanup; } check_result(result, "dns_message_pseudosectiontotext"); } if (query->lookup->section_question && headers) { if (!short_form) { result = dns_message_sectiontotext(msg, DNS_SECTION_QUESTION, style, flags, buf); if (result == ISC_R_NOSPACE) goto buftoosmall; check_result(result, "dns_message_sectiontotext"); } } if (query->lookup->section_answer) { if (!short_form) { result = dns_message_sectiontotext(msg, DNS_SECTION_ANSWER, style, flags, buf); if (result == ISC_R_NOSPACE) goto buftoosmall; check_result(result, "dns_message_sectiontotext"); } else { result = short_answer(msg, flags, buf, query); if (result == ISC_R_NOSPACE) goto buftoosmall; check_result(result, "short_answer"); } } if (query->lookup->section_authority) { if (!short_form) { result = dns_message_sectiontotext(msg, DNS_SECTION_AUTHORITY, style, flags, buf); if (result == ISC_R_NOSPACE) goto buftoosmall; check_result(result, "dns_message_sectiontotext"); } } if (query->lookup->section_additional) { if (!short_form) { result = dns_message_sectiontotext(msg, DNS_SECTION_ADDITIONAL, style, flags, buf); if (result == ISC_R_NOSPACE) goto buftoosmall; check_result(result, "dns_message_sectiontotext"); /* * Only print the signature on the first record. */ if (headers) { result = dns_message_pseudosectiontotext( msg, DNS_PSEUDOSECTION_TSIG, style, flags, buf); if (result == ISC_R_NOSPACE) goto buftoosmall; check_result(result, "dns_message_pseudosectiontotext"); result = dns_message_pseudosectiontotext( msg, DNS_PSEUDOSECTION_SIG0, style, flags, buf); if (result == ISC_R_NOSPACE) goto buftoosmall; check_result(result, "dns_message_pseudosectiontotext"); } } } if (headers && query->lookup->comments && !short_form) printf("\n"); printf("%.*s", (int)isc_buffer_usedlength(buf), (char *)isc_buffer_base(buf)); isc_buffer_free(&buf); cleanup: if (style != NULL) dns_master_styledestroy(&style, mctx); return (result); }
isc_result_t printmessage(dig_query_t *query, dns_message_t *msg, isc_boolean_t headers) { char servtext[ISC_SOCKADDR_FORMATSIZE]; /* I've we've gotten this far, we've reached a server. */ query_error = 0; debug("printmessage()"); if(!default_lookups || query->lookup->rdtype == dns_rdatatype_a) { isc_sockaddr_format(&query->sockaddr, servtext, sizeof(servtext)); printf("Server:\t\t%s\n", query->userarg); printf("Address:\t%s\n", servtext); puts(""); } if (!short_form) { puts("------------"); /* detailheader(query, msg);*/ detailsection(query, msg, ISC_TRUE, DNS_SECTION_QUESTION); detailsection(query, msg, ISC_TRUE, DNS_SECTION_ANSWER); detailsection(query, msg, ISC_TRUE, DNS_SECTION_AUTHORITY); detailsection(query, msg, ISC_TRUE, DNS_SECTION_ADDITIONAL); puts("------------"); } if (msg->rcode != 0) { char nametext[DNS_NAME_FORMATSIZE]; dns_name_format(query->lookup->name, nametext, sizeof(nametext)); printf("** server can't find %s: %s\n", nametext, rcode_totext(msg->rcode)); debug("returning with rcode == 0"); /* the lookup failed */ print_error |= 1; return (ISC_R_SUCCESS); } if ( default_lookups && query->lookup->rdtype == dns_rdatatype_a) { char namestr[DNS_NAME_FORMATSIZE]; dig_lookup_t *lookup; dns_fixedname_t fixed; dns_name_t *name; /* Add AAAA lookup. */ dns_fixedname_init(&fixed); name = dns_fixedname_name(&fixed); dns_name_copy(query->lookup->name, name, NULL); chase_cnamechain(msg, name); dns_name_format(name, namestr, sizeof(namestr)); lookup = clone_lookup(query->lookup, ISC_FALSE); if (lookup != NULL) { strncpy(lookup->textname, namestr, sizeof(lookup->textname)); lookup->textname[sizeof(lookup->textname)-1] = 0; lookup->rdtype = dns_rdatatype_aaaa; lookup->rdtypeset = ISC_TRUE; lookup->origin = NULL; lookup->retries = tries; ISC_LIST_APPEND(lookup_list, lookup, link); } } if ((msg->flags & DNS_MESSAGEFLAG_AA) == 0 && ( !default_lookups || query->lookup->rdtype == dns_rdatatype_a) ) puts("Non-authoritative answer:"); if (!ISC_LIST_EMPTY(msg->sections[DNS_SECTION_ANSWER])) printsection(query, msg, headers, DNS_SECTION_ANSWER); else { if (default_lookups && query->lookup->rdtype == dns_rdatatype_a) a_noanswer = ISC_TRUE; else if (!default_lookups || (query->lookup->rdtype == dns_rdatatype_aaaa && a_noanswer ) ) printf("*** Can't find %s: No answer\n", query->lookup->textname); } if (((msg->flags & DNS_MESSAGEFLAG_AA) == 0) && (query->lookup->rdtype != dns_rdatatype_a) && (query->lookup->rdtype != dns_rdatatype_aaaa) ) { puts("\nAuthoritative answers can be found from:"); printsection(query, msg, headers, DNS_SECTION_AUTHORITY); printsection(query, msg, headers, DNS_SECTION_ADDITIONAL); } return (ISC_R_SUCCESS); }