d63ae51ba337165172a9b50fd5d84805ffe50044Tinderbox User * Copyright (C) 2000-2017 Internet Systems Consortium, Inc. ("ISC")
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * This Source Code Form is subject to the terms of the Mozilla Public
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * License, v. 2.0. If a copy of the MPL was not distributed with this
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * file, You can obtain one at http://mozilla.org/MPL/2.0/.
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer comments = ISC_TRUE, section_question = ISC_TRUE,
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer section_answer = ISC_TRUE, section_authority = ISC_TRUE,
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer section_additional = ISC_TRUE, recurse = ISC_TRUE,
529d8a7cf1960f96a78d1b2b004aa63aff80b16bMark Andrews default_lookups = ISC_TRUE, a_noanswer = ISC_FALSE;
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer "RESERVED11",
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer "RESERVED12",
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer "RESERVED13",
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer "RESERVED14",
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer "RESERVED15",
066cb385cd8f801dd3757db2922c9b1f343e65edAndreas Gustafsson#define N_KNOWN_RRTYPES (sizeof(rtypetext) / sizeof(rtypetext[0]))
b266f8fc42702debc6bd89365273223fa89cd8ddBrian Wellingtonstatic void flush_lookup_list(void);
b266f8fc42702debc6bd89365273223fa89cd8ddBrian Wellingtonstatic void getinput(isc_task_t *task, isc_event_t *event);
d302a620e0d49811874b9555ac2e4c6e05861a6bFrancis Dupont if (rcode >= (sizeof(rcodetext)/sizeof(rcodetext[0]))) {
e56101fa6876c876d9957c23784b6493cdb05e09Brian Wellington result = dns_rdata_tostruct(rdata, &soa, NULL);
e56101fa6876c876d9957c23784b6493cdb05e09Brian Wellington check_result(result, "dns_rdata_tostruct");
e56101fa6876c876d9957c23784b6493cdb05e09Brian Wellington dns_name_format(&soa.origin, namebuf, sizeof(namebuf));
c38b92000c0f1a95daaad5468777e165b8047de9Mark Andrews dns_name_format(&soa.contact, namebuf, sizeof(namebuf));
529d8a7cf1960f96a78d1b2b004aa63aff80b16bMark Andrews char text[sizeof("ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255")];
e56101fa6876c876d9957c23784b6493cdb05e09Brian Wellington result = dns_rdata_totext(rdata, NULL, &b);
e56101fa6876c876d9957c23784b6493cdb05e09Brian Wellington printf("Address: %.*s\n", (int)isc_buffer_usedlength(&b),
1ae75c1024eb0475c2be352b8707772e16332ad0Mark Andrews/* Just for compatibility : not use in host program */
1ae75c1024eb0475c2be352b8707772e16332ad0Mark Andrewsprintrdataset(dns_name_t *owner_name, dns_rdataset_t *rdataset,
e56101fa6876c876d9957c23784b6493cdb05e09Brian Wellington result = isc_buffer_allocate(mctx, &b, size);
e56101fa6876c876d9957c23784b6493cdb05e09Brian Wellington check_result(result, "isc_buffer_allocate");
e56101fa6876c876d9957c23784b6493cdb05e09Brian Wellington printf("%.*s\n", (int)isc_buffer_usedlength(b),
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyerprintsection(dig_query_t *query, dns_message_t *msg, isc_boolean_t headers,
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer result = dns_message_firstname(msg, section);
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyerdetailsection(dig_query_t *query, dns_message_t *msg, isc_boolean_t headers,
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer result = dns_message_firstname(msg, section);
b4876b6ddf706977153954507b498baf79a23442Andreas Gustafssonreceived(int bytes, isc_sockaddr_t *from, dig_query_t *query)
529d8a7cf1960f96a78d1b2b004aa63aff80b16bMark Andrewschase_cnamechain(dns_message_t *msg, dns_name_t *qname) {
529d8a7cf1960f96a78d1b2b004aa63aff80b16bMark Andrews unsigned int i = msg->counts[DNS_SECTION_ANSWER];
529d8a7cf1960f96a78d1b2b004aa63aff80b16bMark Andrews while (i-- > 0) {
529d8a7cf1960f96a78d1b2b004aa63aff80b16bMark Andrews result = dns_message_findname(msg, DNS_SECTION_ANSWER, qname,
529d8a7cf1960f96a78d1b2b004aa63aff80b16bMark Andrews result = dns_rdata_tostruct(&rdata, &cname, NULL);
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyerprintmessage(dig_query_t *query, dns_message_t *msg, isc_boolean_t headers) {
04e5f9812cb02d5d86b542dfa9a394f074ff5621Evan Hunt /* I've we've gotten this far, we've reached a server. */
529d8a7cf1960f96a78d1b2b004aa63aff80b16bMark Andrews if(!default_lookups || query->lookup->rdtype == dns_rdatatype_a) {
529d8a7cf1960f96a78d1b2b004aa63aff80b16bMark Andrews isc_sockaddr_format(&query->sockaddr, servtext, sizeof(servtext));
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer /* detailheader(query, msg);*/
11463c0ac24692e229ec87f307f5e7df3c0a7e10Evan Hunt detailsection(query, msg, ISC_TRUE, DNS_SECTION_QUESTION);
11463c0ac24692e229ec87f307f5e7df3c0a7e10Evan Hunt detailsection(query, msg, ISC_TRUE, DNS_SECTION_ANSWER);
11463c0ac24692e229ec87f307f5e7df3c0a7e10Evan Hunt detailsection(query, msg, ISC_TRUE, DNS_SECTION_AUTHORITY);
11463c0ac24692e229ec87f307f5e7df3c0a7e10Evan Hunt detailsection(query, msg, ISC_TRUE, DNS_SECTION_ADDITIONAL);
04e5f9812cb02d5d86b542dfa9a394f074ff5621Evan Hunt /* the lookup failed */
529d8a7cf1960f96a78d1b2b004aa63aff80b16bMark Andrews if ( default_lookups && query->lookup->rdtype == dns_rdatatype_a) {
529d8a7cf1960f96a78d1b2b004aa63aff80b16bMark Andrews /* Add AAAA lookup. */
529d8a7cf1960f96a78d1b2b004aa63aff80b16bMark Andrews dns_name_copy(query->lookup->name, name, NULL);
529d8a7cf1960f96a78d1b2b004aa63aff80b16bMark Andrews dns_name_format(name, namestr, sizeof(namestr));
529d8a7cf1960f96a78d1b2b004aa63aff80b16bMark Andrews lookup = clone_lookup(query->lookup, ISC_FALSE);
529d8a7cf1960f96a78d1b2b004aa63aff80b16bMark Andrews ( !default_lookups || query->lookup->rdtype == dns_rdatatype_a) )
e42c402595802edceafbd3e5338dda011fbbcdb6Michael Sawyer if (!ISC_LIST_EMPTY(msg->sections[DNS_SECTION_ANSWER]))
e42c402595802edceafbd3e5338dda011fbbcdb6Michael Sawyer printsection(query, msg, headers, DNS_SECTION_ANSWER);
529d8a7cf1960f96a78d1b2b004aa63aff80b16bMark Andrews if (default_lookups && query->lookup->rdtype == dns_rdatatype_a)
529d8a7cf1960f96a78d1b2b004aa63aff80b16bMark Andrews (query->lookup->rdtype == dns_rdatatype_aaaa &&
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer if (((msg->flags & DNS_MESSAGEFLAG_AA) == 0) &&
529d8a7cf1960f96a78d1b2b004aa63aff80b16bMark Andrews (query->lookup->rdtype != dns_rdatatype_aaaa) ) {
7804502532d6e2eee80083431a22eb5d957f52a0Michael Sawyer puts("\nAuthoritative answers can be found from:");
f900be21902d02418c2c71ffed754fb3f9f54cffMichael Sawyershow_settings(isc_boolean_t full, isc_boolean_t serv_only) {
7f658603910358db7ee27ffb9783096250afab62Tatuya JINMEI 神明達哉 result = get_address(srv->servername, port, &sockaddr);
46e349e515e0b992ecafdc9597f9d5ee0cf81b2aBrian Wellington isc_sockaddr_format(&sockaddr, sockstr, sizeof(sockstr));
46e349e515e0b992ecafdc9597f9d5ee0cf81b2aBrian Wellington printf("Default server: %s\nAddress: %s\n",
8afea636ab0c07399aa3e2410b2cfbd41099df98Mark Andrews printf(" timeout = %d\t\tretry = %d\tport = %d\tndots = %d\n",
688a4c50c2025a683d8d2bf5bb53a591556df4fcAndreas Gustafsson printf(" querytype = %-8s\tclass = %s\n", deftype, defclass);
688a4c50c2025a683d8d2bf5bb53a591556df4fcAndreas Gustafsson for (listent = ISC_LIST_HEAD(search_list);
688a4c50c2025a683d8d2bf5bb53a591556df4fcAndreas Gustafsson listent = ISC_LIST_NEXT(listent, link)) {
688a4c50c2025a683d8d2bf5bb53a591556df4fcAndreas Gustafsson if (ISC_LIST_NEXT(listent, link) != NULL)
aa6054ec74819f754bcf19442ca9b39d948171adMichael Sawyer result = dns_rdatatype_fromtext(&rdtype, &tr);
e42c402595802edceafbd3e5338dda011fbbcdb6Michael Sawyer printf("unknown query type: %s\n", typetext);
aa6054ec74819f754bcf19442ca9b39d948171adMichael Sawyer result = dns_rdataclass_fromtext(&rdclass, &tr);
e42c402595802edceafbd3e5338dda011fbbcdb6Michael Sawyer printf("unknown query class: %s\n", typetext);
242bba8991b030b7764f0bdca3922d75c34ea51eAndreas Gustafsson isc_result_t result = parse_uint(&n, value, 65535, "port");
242bba8991b030b7764f0bdca3922d75c34ea51eAndreas Gustafsson isc_result_t result = parse_uint(&n, value, UINT_MAX, "timeout");
242bba8991b030b7764f0bdca3922d75c34ea51eAndreas Gustafsson isc_result_t result = parse_uint(&n, value, INT_MAX, "tries");
8afea636ab0c07399aa3e2410b2cfbd41099df98Mark Andrews isc_result_t result = parse_uint(&n, value, 128, "ndots");
c76e8412f4ff4f5945157410312df2a8950f942dMark Andrews ((l >= N) && (l < sizeof(A)) && (strncasecmp(opt, A, l) == 0))
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer } else if (strncasecmp(opt, "class=", 6) == 0) {
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer } else if (strncasecmp(opt, "cl=", 3) == 0) {
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer } else if (strncasecmp(opt, "type=", 5) == 0) {
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer } else if (strncasecmp(opt, "ty=", 3) == 0) {
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer } else if (strncasecmp(opt, "querytype=", 10) == 0) {
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer } else if (strncasecmp(opt, "query=", 6) == 0) {
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer } else if (strncasecmp(opt, "qu=", 3) == 0) {
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer } else if (strncasecmp(opt, "domain=", 7) == 0) {
0a92db42c6be6a158cd41ff863831a8d2d257935Mark Andrews strlcpy(domainopt, &opt[7], sizeof(domainopt));
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer } else if (strncasecmp(opt, "do=", 3) == 0) {
0a92db42c6be6a158cd41ff863831a8d2d257935Mark Andrews strlcpy(domainopt, &opt[3], sizeof(domainopt));
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer } else if (strncasecmp(opt, "port=", 5) == 0) {
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer } else if (strncasecmp(opt, "po=", 3) == 0) {
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer } else if (strncasecmp(opt, "timeout=", 8) == 0) {
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer } else if (strncasecmp(opt, "retry=", 6) == 0) {
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer } else if (strncasecmp(opt, "ret=", 4) == 0) {
fb2c34419d268d36acb222e08e6f789b45a81306Mark Andrews /* deprecation_msg = ISC_FALSE; */
8afea636ab0c07399aa3e2410b2cfbd41099df98Mark Andrews } else if (strncasecmp(opt, "ndots=", 6) == 0) {
aa6054ec74819f754bcf19442ca9b39d948171adMichael Sawyer result = dns_rdatatype_fromtext(&rdtype, &tr);
32e783c745299f838dd7cf8ffe2032775a80f1d0Andreas Gustafsson printf("unknown query type: %s\n", deftype);
aa6054ec74819f754bcf19442ca9b39d948171adMichael Sawyer result = dns_rdataclass_fromtext(&rdclass, &tr);
32e783c745299f838dd7cf8ffe2032775a80f1d0Andreas Gustafsson printf("unknown query class: %s\n", defclass);
974f1d7b49442d65542ad3517dbd61146ee3b653Mark Andrews if (get_reverse(store, sizeof(store), opt, lookup->ip6_int, ISC_TRUE)
0a92db42c6be6a158cd41ff863831a8d2d257935Mark Andrews strlcpy(lookup->textname, store, sizeof(lookup->textname));
0a92db42c6be6a158cd41ff863831a8d2d257935Mark Andrews strlcpy(lookup->textname, opt, sizeof(lookup->textname));
3001a1b4e6298466882a4147307b4c28a3b08f91Mark Andrews if (lookup->rdtype == dns_rdatatype_any && !tcpmode_set)
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer lookup->section_authority = section_authority;
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer lookup->section_additional = section_additional;
5f01e77fc23fe9665fa2b8acd0a0c5bfbf61d61dBrian Wellington printf("The '%s' command is not yet implemented.\n", ptr);
5f01e77fc23fe9665fa2b8acd0a0c5bfbf61d61dBrian Wellington } else if (strcasecmp(ptr, "finger") == 0 ||
5f01e77fc23fe9665fa2b8acd0a0c5bfbf61d61dBrian Wellington printf("The '%s' command is not implemented.\n", ptr);
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer for (argc--, argv++; argc > 0; argc--, argv++) {
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer while (l != NULL) {
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer while (q != NULL) {
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer ISC_LIST_DEQUEUE(q->lengthlist, &q->lengthbuf,
e715e011788a529446b8013239c33599542ece32Michael Sawyer while (s != NULL) {
e715e011788a529446b8013239c33599542ece32Michael Sawyer ISC_LIST_DEQUEUE(l->my_server_list, sp, link);
b266f8fc42702debc6bd89365273223fa89cd8ddBrian Wellingtongetinput(isc_task_t *task, isc_event_t *event) {
2b0060b8ff20eab8b7b1c42a9b9ccedb85047887Evan Hunt /* setup dighost callbacks */
58e291cb8dd77656048d6d7727f2bc2388110785Evan Hunt if (keyfile[0] != 0)
58e291cb8dd77656048d6d7727f2bc2388110785Evan Hunt else if (keysecret[0] != 0)
b266f8fc42702debc6bd89365273223fa89cd8ddBrian Wellington result = isc_app_onrun(mctx, global_task, onrun_callback,
b266f8fc42702debc6bd89365273223fa89cd8ddBrian Wellington result = isc_app_onrun(mctx, global_task, getinput, NULL);
37e6e0ca1337351642798b1a6aa24ae40bf86399Andreas Gustafsson debug("done, and starting to shut down");