📄 dig.c
字号:
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); 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) { char *endp; isc_uint32_t tmp; tmp = strtoul(arg, &endp, 10); if (*endp != '\0') fatal("%s '%s' must be numeric", desc, arg); if (tmp > max) fatal("%s '%s' out of range", desc, arg); 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; 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; } switch (cmd[0]) { case 'a': switch (cmd[1]) { case 'a': /* aaflag */ lookup->aaonly = state; break; case 'd': switch (cmd[2]) { case 'd': /* additional */ lookup->section_additional = state; break; case 'f': /* adflag */ lookup->adflag = state; break; default: goto invalid_option; } break; case 'l': /* 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 */ lookup->section_answer = state; break; case 'u': /* authority */ lookup->section_authority = state; break; default: goto invalid_option; } break; case 'b': switch (cmd[1]) { case 'e':/* besteffort */ lookup->besteffort = state; break; case 'u':/* 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 */ lookup->cdflag = state; break; case 'm': /* cmd */ printcmd = state; break; case 'o': /* comments */ lookup->comments = state; if (lookup == default_lookup) pluscomm = state; break; default: goto invalid_option; } break; case 'd': switch (cmd[1]) { case 'e': /* defname */ usesearch = state; break; case 'n': /* dnssec */ lookup->dnssec = state; break; case 'o': /* 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 */ lookup->servfail_stops = state; break; case 'i': switch (cmd[1]) { case 'd': /* identify */ lookup->identify = state; break; case 'g': /* ignore */ default: /* Inherets default for compatibility */ lookup->ignore = ISC_TRUE; } break; case 'm': /* multiline */ multiline = state; break; case 'n': switch (cmd[1]) { case 'd': /* ndots */ if (value == NULL) goto need_value; if (!state) goto invalid_option; ndots = parse_uint(value, "ndots", MAXNDOTS); break; case 's': /* 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 */ qr = state; break; case 'u': /* question */ lookup->section_question = state; if (lookup == default_lookup) plusquest = state; break; default: goto invalid_option; } break; case 'r': /* recurse */ lookup->recurse = state; break; case 's': switch (cmd[1]) { case 'e': /* search */ usesearch = state; break; case 'h': /* 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; case 't': /* stats */ lookup->stats = state; break; default: goto invalid_option; } break; case 't': switch (cmd[1]) { case 'c': /* tcp */ if (!is_batchfile) lookup->tcp_mode = state; break; case 'i': /* timeout */ if (value == NULL) goto need_value; if (!state) goto invalid_option; timeout = parse_uint(value, "timeout", MAXTIMEOUT); if (timeout == 0) timeout = 1; break; case 'r': switch (cmd[2]) { case 'a': /* 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 */ if (value == NULL) goto need_value; if (!state) goto invalid_option; lookup->retries = parse_uint(value, "retries", MAXTRIES); if (lookup->retries == 0) lookup->retries = 1; break; default: goto invalid_option; } break; default: goto invalid_option; } break; case 'v': 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 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 cmd, *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; cmd = option[0]; if (strlen(option) > 1U) { value_from_next = ISC_FALSE; value = &option[1]; } else { value_from_next = ISC_TRUE; value = next; } switch (cmd) { case 'd': debugging = ISC_TRUE; return (ISC_FALSE); case 'h': help(); exit(0); break; case 'i': ip6_int = ISC_TRUE; return (ISC_FALSE); case 'm': /* memdebug */ /* memdebug is handled in preparse_args() */ return (ISC_FALSE); case 'n': /* deprecated */ return (ISC_FALSE); } if (value == NULL) goto invalid_option; switch (cmd) { case 'b': if (have_ipv6 && inet_pton(AF_INET6, value, &in6) == 1) isc_sockaddr_fromin6(&bind_address, &in6, 0); else if (have_ipv4 && inet_pton(AF_INET, value, &in4) == 1) isc_sockaddr_fromin(&bind_address, &in4, 0); else fatal("invalid address %s", value); specified_source = ISC_TRUE; return (value_from_next); case 'c': if ((*lookup)->rdclassset) { fprintf(stderr, ";; Warning, extra class option\n"); } *open_type_class = ISC_FALSE; tr.base = value; tr.length = strlen(value); result = dns_rdataclass_fromtext(&rdclass, (isc_textregion_t *)&tr); if (result == ISC_R_SUCCESS) { (*lookup)->rdclass = rdclass; (*lookup)->rdclassset = ISC_TRUE;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -