📄 dig.c
字号:
} } 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);}/* * print the greeting message when the program first starts up. */static voidprintgreeting(int argc, char **argv, dig_lookup_t *lookup) { int i; int remaining; static isc_boolean_t first = ISC_TRUE; char append[MXNAME]; if (printcmd) { lookup->cmdline[sizeof(lookup->cmdline) - 1] = 0; snprintf(lookup->cmdline, sizeof(lookup->cmdline), "%s; <<>> DiG " VERSION " <<>>", first?"\n":""); i = 1; while (i < argc) { snprintf(append, sizeof(append), " %s", argv[i++]); remaining = sizeof(lookup->cmdline) - strlen(lookup->cmdline) - 1; strncat(lookup->cmdline, append, remaining); } remaining = sizeof(lookup->cmdline) - strlen(lookup->cmdline) - 1; strncat(lookup->cmdline, "\n", remaining); if (first) { snprintf(append, sizeof(append), ";; global options: %s %s\n", short_form ? "short_form" : "", printcmd ? "printcmd" : ""); first = ISC_FALSE; remaining = sizeof(lookup->cmdline) - strlen(lookup->cmdline) - 1; strncat(lookup->cmdline, append, remaining); } }}/* * Reorder an argument list so that server names all come at the end. * This is a bit of a hack, to allow batch-mode processing to properly * handle the server options. */static voidreorder_args(int argc, char *argv[]) { int i, j; char *ptr; int end; debug("reorder_args()"); end = argc - 1; while (argv[end][0] == '@') { end--; if (end == 0) return; } debug("arg[end]=%s", argv[end]); for (i = 1; i < end - 1; i++) { if (argv[i][0] == '@') { debug("arg[%d]=%s", i, argv[i]); ptr = argv[i]; for (j = i + 1; j < end; j++) { debug("Moving %s to %d", argv[j], j - 1); argv[j - 1] = argv[j]; } debug("moving %s to end, %d", ptr, end - 1); argv[end - 1] = ptr; end--; if (end < 1) return; } }}static isc_uint32_tparse_uint(char *arg, const char *desc, isc_uint32_t max) { isc_result_t result; isc_uint32_t tmp; result = isc_parse_uint32(&tmp, arg, 10); if (result == ISC_R_SUCCESS && tmp > max) result = ISC_R_RANGE; if (result != ISC_R_SUCCESS) fatal("%s '%s': %s", desc, arg, isc_result_totext(result)); return (tmp);}/* * We're not using isc_commandline_parse() here since the command line * syntax of dig is quite a bit different from that which can be described * by that routine. * XXX doc options */static voidplus_option(char *option, isc_boolean_t is_batchfile, dig_lookup_t *lookup){ char option_store[256]; char *cmd, *value, *ptr; isc_boolean_t state = ISC_TRUE;#ifdef DIG_SIGCHASE size_t n;#endif strncpy(option_store, option, sizeof(option_store)); option_store[sizeof(option_store)-1]=0; ptr = option_store; cmd = next_token(&ptr,"="); if (cmd == NULL) { printf(";; Invalid option %s\n", option_store); return; } value = ptr; if (strncasecmp(cmd, "no", 2)==0) { cmd += 2; state = ISC_FALSE; }#define FULLCHECK(A) \ do { \ size_t _l = strlen(cmd); \ if (_l >= sizeof(A) || strncasecmp(cmd, A, _l) != 0) \ goto invalid_option; \ } while (0)#define FULLCHECK2(A, B) \ do { \ size_t _l = strlen(cmd); \ if ((_l >= sizeof(A) || strncasecmp(cmd, A, _l) != 0) && \ (_l >= sizeof(B) || strncasecmp(cmd, B, _l) != 0)) \ goto invalid_option; \ } while (0) switch (cmd[0]) { case 'a': switch (cmd[1]) { case 'a': /* aaonly / aaflag */ FULLCHECK2("aaonly", "aaflag"); lookup->aaonly = state; break; case 'd': switch (cmd[2]) { case 'd': /* additional */ FULLCHECK("additional"); lookup->section_additional = state; break; case 'f': /* adflag */ FULLCHECK("adflag"); lookup->adflag = state; break; default: goto invalid_option; } break; case 'l': /* all */ FULLCHECK("all"); lookup->section_question = state; lookup->section_authority = state; lookup->section_answer = state; lookup->section_additional = state; lookup->comments = state; lookup->stats = state; printcmd = state; break; case 'n': /* answer */ FULLCHECK("answer"); lookup->section_answer = state; break; case 'u': /* authority */ FULLCHECK("authority"); lookup->section_authority = state; break; default: goto invalid_option; } break; case 'b': switch (cmd[1]) { case 'e':/* besteffort */ FULLCHECK("besteffort"); lookup->besteffort = state; break; case 'u':/* bufsize */ FULLCHECK("bufsize"); if (value == NULL) goto need_value; if (!state) goto invalid_option; lookup->udpsize = (isc_uint16_t) parse_uint(value, "buffer size", COMMSIZE); break; default: goto invalid_option; } break; case 'c': switch (cmd[1]) { case 'd':/* cdflag */ FULLCHECK("cdflag"); lookup->cdflag = state; break; case 'l': /* cl */ FULLCHECK("cl"); noclass = !state; break; case 'm': /* cmd */ FULLCHECK("cmd"); printcmd = state; break; case 'o': /* comments */ FULLCHECK("comments"); lookup->comments = state; if (lookup == default_lookup) pluscomm = state; break; default: goto invalid_option; } break; case 'd': switch (cmd[1]) { case 'e': /* defname */ FULLCHECK("defname"); usesearch = state; break; case 'n': /* dnssec */ FULLCHECK("dnssec"); lookup->dnssec = state; break; case 'o': /* domain */ FULLCHECK("domain"); if (value == NULL) goto need_value; if (!state) goto invalid_option; strncpy(domainopt, value, sizeof(domainopt)); domainopt[sizeof(domainopt)-1] = '\0'; break; default: goto invalid_option; } break; case 'f': /* fail */ FULLCHECK("fail"); lookup->servfail_stops = state; break; case 'i': switch (cmd[1]) { case 'd': /* identify */ FULLCHECK("identify"); lookup->identify = state; break; case 'g': /* ignore */ default: /* Inherets default for compatibility */ FULLCHECK("ignore"); lookup->ignore = ISC_TRUE; } break; case 'm': /* multiline */ FULLCHECK("multiline"); multiline = state; break; case 'n': switch (cmd[1]) { case 'd': /* ndots */ FULLCHECK("ndots"); if (value == NULL) goto need_value; if (!state) goto invalid_option; ndots = parse_uint(value, "ndots", MAXNDOTS); break; case 's': /* nssearch */ FULLCHECK("nssearch"); lookup->ns_search_only = state; if (state) { lookup->trace_root = ISC_TRUE; lookup->recurse = ISC_FALSE; lookup->identify = ISC_TRUE; lookup->stats = ISC_FALSE; lookup->comments = ISC_FALSE; lookup->section_additional = ISC_FALSE; lookup->section_authority = ISC_FALSE; lookup->section_question = ISC_FALSE; lookup->rdtype = dns_rdatatype_ns; lookup->rdtypeset = ISC_TRUE; short_form = ISC_TRUE; } break; default: goto invalid_option; } break; case 'q': switch (cmd[1]) { case 'r': /* qr */ FULLCHECK("qr"); qr = state; break; case 'u': /* question */ FULLCHECK("question"); lookup->section_question = state; if (lookup == default_lookup) plusquest = state; break; default: goto invalid_option; } break; case 'r': switch (cmd[1]) { case 'e': switch (cmd[2]) { case 'c': /* recurse */ FULLCHECK("recurse"); lookup->recurse = state; break; case 't': /* retry / retries */ FULLCHECK2("retry", "retries"); if (value == NULL) goto need_value; if (!state) goto invalid_option; lookup->retries = parse_uint(value, "retries", MAXTRIES - 1); lookup->retries++; break; default: goto invalid_option; } break; default: goto invalid_option; } break; case 's': switch (cmd[1]) { case 'e': /* search */ FULLCHECK("search"); usesearch = state; break; case 'h': /* short */ FULLCHECK("short"); short_form = state; if (state) { printcmd = ISC_FALSE; lookup->section_additional = ISC_FALSE; lookup->section_answer = ISC_TRUE; lookup->section_authority = ISC_FALSE; lookup->section_question = ISC_FALSE; lookup->comments = ISC_FALSE; lookup->stats = ISC_FALSE; } break;#ifdef DIG_SIGCHASE case 'i': /* sigchase */ FULLCHECK("sigchase"); lookup->sigchase = state; if (lookup->sigchase) lookup->dnssec = ISC_TRUE; break; #endif case 't': /* stats */ FULLCHECK("stats"); lookup->stats = state; break; default: goto invalid_option; } break; case 't': switch (cmd[1]) { case 'c': /* tcp */ FULLCHECK("tcp"); if (!is_batchfile) lookup->tcp_mode = state; break; case 'i': /* timeout */ FULLCHECK("timeout"); if (value == NULL) goto need_value; if (!state) goto invalid_option; timeout = parse_uint(value, "timeout", MAXTIMEOUT); if (timeout == 0) timeout = 1; break;#if DIG_SIGCHASE_TD case 'o': /* topdown */ FULLCHECK("topdown"); lookup->do_topdown = state; break;#endif case 'r': switch (cmd[2]) { case 'a': /* trace */ FULLCHECK("trace"); lookup->trace = state; lookup->trace_root = state; if (state) { lookup->recurse = ISC_FALSE; lookup->identify = ISC_TRUE; lookup->comments = ISC_FALSE; lookup->stats = ISC_FALSE; lookup->section_additional = ISC_FALSE; lookup->section_authority = ISC_TRUE; lookup->section_question = ISC_FALSE; } break; case 'i': /* tries */ FULLCHECK("tries"); if (value == NULL) goto need_value; if (!state) goto invalid_option; lookup->retries = parse_uint(value, "tries", MAXTRIES); if (lookup->retries == 0) lookup->retries = 1; break;#ifdef DIG_SIGCHASE case 'u': /* trusted-key */ if (value == NULL) goto need_value; if (!state) goto invalid_option; n = strlcpy(trustedkey, ptr, sizeof(trustedkey)); if (n >= sizeof(trustedkey)) fatal("trusted key too large"); break;#endif default: goto invalid_option; } break; case 't': /* ttlid */ FULLCHECK("ttlid"); nottl = !state; break; default: goto invalid_option; } break; case 'v': FULLCHECK("vc"); if (!is_batchfile) lookup->tcp_mode = state; break; default: invalid_option: need_value: fprintf(stderr, "Invalid option: +%s\n", option); usage(); } return;}/* * ISC_TRUE returned if value was used */static const char *single_dash_opts = "46dhimnv";static const char *dash_opts = "46bcdfhikmnptvyx";static isc_boolean_tdash_option(char *option, char *next, dig_lookup_t **lookup, isc_boolean_t *open_type_class, isc_boolean_t *firstarg, int argc, char **argv){ char opt, *value, *ptr; isc_result_t result; isc_boolean_t value_from_next; isc_textregion_t tr; dns_rdatatype_t rdtype; dns_rdataclass_t rdclass; char textname[MXNAME]; struct in_addr in4; struct in6_addr in6; in_port_t srcport; char *hash, *cmd; while (strpbrk(option, single_dash_opts) == &option[0]) { /* * Since the -[46dhimnv] options do not take an argument, * account for them (in any number and/or combination) * if they appear as the first character(s) of a q-opt. */ opt = option[0]; switch (opt) { case '4': if (have_ipv4) { isc_net_disableipv6(); have_ipv6 = ISC_FALSE; } else { fatal("can't find IPv4 networking"); return (ISC_FALSE); } break; case '6': if (have_ipv6) { isc_net_disableipv4(); have_ipv4 = ISC_FALSE; } else { fatal("can't find IPv6 networking"); return (ISC_FALSE); } break; case 'd': ptr = strpbrk(&option[1], dash_opts); if (ptr != &option[1]) { cmd = option; FULLCHECK("debug");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -