[BACK]Return to host.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / dig

Diff for /src/usr.bin/dig/host.c between version 1.15 and 1.16

version 1.15, 2020/09/14 08:37:09 version 1.16, 2020/09/14 08:40:43
Line 39 
Line 39 
   
 #include "dig.h"  #include "dig.h"
   
 static isc_boolean_t short_form = ISC_TRUE, listed_server = ISC_FALSE;  static int short_form = 1, listed_server = 0;
 static isc_boolean_t default_lookups = ISC_TRUE;  static int default_lookups = 1;
 static int seen_error = -1;  static int seen_error = -1;
 static isc_boolean_t list_addresses = ISC_TRUE;  static int list_addresses = 1;
 static dns_rdatatype_t list_type = dns_rdatatype_a;  static dns_rdatatype_t list_type = dns_rdatatype_a;
 static isc_boolean_t printed_server = ISC_FALSE;  static int printed_server = 0;
 static isc_boolean_t ipv4only = ISC_FALSE, ipv6only = ISC_FALSE;  static int ipv4only = 0, ipv6only = 0;
   
 static const char *opcodetext[] = {  static const char *opcodetext[] = {
         "QUERY",          "QUERY",
Line 199 
Line 199 
 }  }
 static isc_result_t  static isc_result_t
 printsection(dns_message_t *msg, dns_section_t sectionid,  printsection(dns_message_t *msg, dns_section_t sectionid,
              const char *section_name, isc_boolean_t headers,               const char *section_name, int headers,
              dig_query_t *query)               dig_query_t *query)
 {  {
         dns_name_t *name, *print_name;          dns_name_t *name, *print_name;
Line 210 
Line 210 
         isc_region_t r;          isc_region_t r;
         dns_name_t empty_name;          dns_name_t empty_name;
         char tbuf[4096];          char tbuf[4096];
         isc_boolean_t first;          int first;
         isc_boolean_t no_rdata;          int no_rdata;
   
         if (sectionid == DNS_SECTION_QUESTION)          if (sectionid == DNS_SECTION_QUESTION)
                 no_rdata = ISC_TRUE;                  no_rdata = 1;
         else          else
                 no_rdata = ISC_FALSE;                  no_rdata = 0;
   
         if (headers)          if (headers)
                 printf(";; %s SECTION:\n", section_name);                  printf(";; %s SECTION:\n", section_name);
Line 234 
Line 234 
                 dns_message_currentname(msg, sectionid, &name);                  dns_message_currentname(msg, sectionid, &name);
   
                 isc_buffer_init(&target, tbuf, sizeof(tbuf));                  isc_buffer_init(&target, tbuf, sizeof(tbuf));
                 first = ISC_TRUE;                  first = 1;
                 print_name = name;                  print_name = name;
   
                 for (rdataset = ISC_LIST_HEAD(name->list);                  for (rdataset = ISC_LIST_HEAD(name->list);
Line 253 
Line 253 
                         if (!short_form) {                          if (!short_form) {
                                 result = dns_rdataset_totext(rdataset,                                  result = dns_rdataset_totext(rdataset,
                                                              print_name,                                                               print_name,
                                                              ISC_FALSE,                                                               0,
                                                              no_rdata,                                                               no_rdata,
                                                              &target);                                                               &target);
                                 if (result != ISC_R_SUCCESS)                                  if (result != ISC_R_SUCCESS)
Line 312 
Line 312 
   
 static isc_result_t  static isc_result_t
 printrdata(dns_message_t *msg, dns_rdataset_t *rdataset, dns_name_t *owner,  printrdata(dns_message_t *msg, dns_rdataset_t *rdataset, dns_name_t *owner,
            const char *set_name, isc_boolean_t headers)             const char *set_name, int headers)
 {  {
         isc_buffer_t target;          isc_buffer_t target;
         isc_result_t result;          isc_result_t result;
Line 325 
Line 325 
   
         isc_buffer_init(&target, tbuf, sizeof(tbuf));          isc_buffer_init(&target, tbuf, sizeof(tbuf));
   
         result = dns_rdataset_totext(rdataset, owner, ISC_FALSE, ISC_FALSE,          result = dns_rdataset_totext(rdataset, owner, 0, 0,
                                      &target);                                       &target);
         if (result != ISC_R_SUCCESS)          if (result != ISC_R_SUCCESS)
                 return (result);                  return (result);
Line 362 
Line 362 
 }  }
   
 static isc_result_t  static isc_result_t
 printmessage(dig_query_t *query, dns_message_t *msg, isc_boolean_t headers) {  printmessage(dig_query_t *query, dns_message_t *msg, int headers) {
         isc_boolean_t did_flag = ISC_FALSE;          int did_flag = 0;
         dns_rdataset_t *opt, *tsig = NULL;          dns_rdataset_t *opt, *tsig = NULL;
         dns_name_t *tsigname;          dns_name_t *tsigname;
         isc_result_t result = ISC_R_SUCCESS;          isc_result_t result = ISC_R_SUCCESS;
Line 386 
Line 386 
                                     sizeof(sockstr));                                      sizeof(sockstr));
                 printf("Address: %s\n", sockstr);                  printf("Address: %s\n", sockstr);
                 printf("Aliases: \n\n");                  printf("Aliases: \n\n");
                 printed_server = ISC_TRUE;                  printed_server = 1;
         }          }
   
         if (msg->rcode != 0) {          if (msg->rcode != 0) {
Line 419 
Line 419 
                 dns_name_copy(query->lookup->name, name, NULL);                  dns_name_copy(query->lookup->name, name, NULL);
                 chase_cnamechain(msg, name);                  chase_cnamechain(msg, name);
                 dns_name_format(name, namestr, sizeof(namestr));                  dns_name_format(name, namestr, sizeof(namestr));
                 lookup = clone_lookup(query->lookup, ISC_FALSE);                  lookup = clone_lookup(query->lookup, 0);
                 if (lookup != NULL) {                  if (lookup != NULL) {
                         strlcpy(lookup->textname, namestr,                          strlcpy(lookup->textname, namestr,
                                 sizeof(lookup->textname));                                  sizeof(lookup->textname));
                         lookup->rdtype = dns_rdatatype_aaaa;                          lookup->rdtype = dns_rdatatype_aaaa;
                         lookup->rdtypeset = ISC_TRUE;                          lookup->rdtypeset = 1;
                         lookup->origin = NULL;                          lookup->origin = NULL;
                         lookup->retries = tries;                          lookup->retries = tries;
                         ISC_LIST_APPEND(lookup_list, lookup, link);                          ISC_LIST_APPEND(lookup_list, lookup, link);
                 }                  }
                 lookup = clone_lookup(query->lookup, ISC_FALSE);                  lookup = clone_lookup(query->lookup, 0);
                 if (lookup != NULL) {                  if (lookup != NULL) {
                         strlcpy(lookup->textname, namestr,                          strlcpy(lookup->textname, namestr,
                                 sizeof(lookup->textname));                                  sizeof(lookup->textname));
                         lookup->rdtype = dns_rdatatype_mx;                          lookup->rdtype = dns_rdatatype_mx;
                         lookup->rdtypeset = ISC_TRUE;                          lookup->rdtypeset = 1;
                         lookup->origin = NULL;                          lookup->origin = NULL;
                         lookup->retries = tries;                          lookup->retries = tries;
                         ISC_LIST_APPEND(lookup_list, lookup, link);                          ISC_LIST_APPEND(lookup_list, lookup, link);
Line 448 
Line 448 
                 printf(";; flags: ");                  printf(";; flags: ");
                 if ((msg->flags & DNS_MESSAGEFLAG_QR) != 0) {                  if ((msg->flags & DNS_MESSAGEFLAG_QR) != 0) {
                         printf("qr");                          printf("qr");
                         did_flag = ISC_TRUE;                          did_flag = 1;
                 }                  }
                 if ((msg->flags & DNS_MESSAGEFLAG_AA) != 0) {                  if ((msg->flags & DNS_MESSAGEFLAG_AA) != 0) {
                         printf("%saa", did_flag ? " " : "");                          printf("%saa", did_flag ? " " : "");
                         did_flag = ISC_TRUE;                          did_flag = 1;
                 }                  }
                 if ((msg->flags & DNS_MESSAGEFLAG_TC) != 0) {                  if ((msg->flags & DNS_MESSAGEFLAG_TC) != 0) {
                         printf("%stc", did_flag ? " " : "");                          printf("%stc", did_flag ? " " : "");
                         did_flag = ISC_TRUE;                          did_flag = 1;
                 }                  }
                 if ((msg->flags & DNS_MESSAGEFLAG_RD) != 0) {                  if ((msg->flags & DNS_MESSAGEFLAG_RD) != 0) {
                         printf("%srd", did_flag ? " " : "");                          printf("%srd", did_flag ? " " : "");
                         did_flag = ISC_TRUE;                          did_flag = 1;
                 }                  }
                 if ((msg->flags & DNS_MESSAGEFLAG_RA) != 0) {                  if ((msg->flags & DNS_MESSAGEFLAG_RA) != 0) {
                         printf("%sra", did_flag ? " " : "");                          printf("%sra", did_flag ? " " : "");
                         did_flag = ISC_TRUE;                          did_flag = 1;
                 }                  }
                 if ((msg->flags & DNS_MESSAGEFLAG_AD) != 0) {                  if ((msg->flags & DNS_MESSAGEFLAG_AD) != 0) {
                         printf("%sad", did_flag ? " " : "");                          printf("%sad", did_flag ? " " : "");
                         did_flag = ISC_TRUE;                          did_flag = 1;
                 }                  }
                 if ((msg->flags & DNS_MESSAGEFLAG_CD) != 0) {                  if ((msg->flags & DNS_MESSAGEFLAG_CD) != 0) {
                         printf("%scd", did_flag ? " " : "");                          printf("%scd", did_flag ? " " : "");
                         did_flag = ISC_TRUE;                          did_flag = 1;
                         POST(did_flag);                          POST(did_flag);
                 }                  }
                 printf("; QUERY: %u, ANSWER: %u, "                  printf("; QUERY: %u, ANSWER: %u, "
Line 495 
Line 495 
             !short_form) {              !short_form) {
                 printf("\n");                  printf("\n");
                 result = printsection(msg, DNS_SECTION_QUESTION, "QUESTION",                  result = printsection(msg, DNS_SECTION_QUESTION, "QUESTION",
                                       ISC_TRUE, query);                                        1, query);
                 if (result != ISC_R_SUCCESS)                  if (result != ISC_R_SUCCESS)
                         return (result);                          return (result);
         }          }
Line 503 
Line 503 
                 if (!short_form)                  if (!short_form)
                         printf("\n");                          printf("\n");
                 result = printsection(msg, DNS_SECTION_ANSWER, "ANSWER",                  result = printsection(msg, DNS_SECTION_ANSWER, "ANSWER",
                                       ISC_TF(!short_form), query);                                        !short_form, query);
                 if (result != ISC_R_SUCCESS)                  if (result != ISC_R_SUCCESS)
                         return (result);                          return (result);
         }          }
Line 512 
Line 512 
             !short_form) {              !short_form) {
                 printf("\n");                  printf("\n");
                 result = printsection(msg, DNS_SECTION_AUTHORITY, "AUTHORITY",                  result = printsection(msg, DNS_SECTION_AUTHORITY, "AUTHORITY",
                                       ISC_TRUE, query);                                        1, query);
                 if (result != ISC_R_SUCCESS)                  if (result != ISC_R_SUCCESS)
                         return (result);                          return (result);
         }          }
Line 520 
Line 520 
             !short_form) {              !short_form) {
                 printf("\n");                  printf("\n");
                 result = printsection(msg, DNS_SECTION_ADDITIONAL,                  result = printsection(msg, DNS_SECTION_ADDITIONAL,
                                       "ADDITIONAL", ISC_TRUE, query);                                        "ADDITIONAL", 1, query);
                 if (result != ISC_R_SUCCESS)                  if (result != ISC_R_SUCCESS)
                         return (result);                          return (result);
         }          }
         if ((tsig != NULL) && !short_form) {          if ((tsig != NULL) && !short_form) {
                 printf("\n");                  printf("\n");
                 result = printrdata(msg, tsig, tsigname,                  result = printrdata(msg, tsig, tsigname,
                                     "PSEUDOSECTION TSIG", ISC_TRUE);                                      "PSEUDOSECTION TSIG", 1);
                 if (result != ISC_R_SUCCESS)                  if (result != ISC_R_SUCCESS)
                         return (result);                          return (result);
         }          }
Line 564 
Line 564 
                 case '4':                  case '4':
                         if (ipv6only)                          if (ipv6only)
                                 fatal("only one of -4 and -6 allowed");                                  fatal("only one of -4 and -6 allowed");
                         ipv4only = ISC_TRUE;                          ipv4only = 1;
                         break;                          break;
                 case '6':                  case '6':
                         if (ipv4only)                          if (ipv4only)
                                 fatal("only one of -4 and -6 allowed");                                  fatal("only one of -4 and -6 allowed");
                         ipv6only = ISC_TRUE;                          ipv6only = 1;
                         break;                          break;
                 case 'a': break;                  case 'a': break;
                 case 'c': break;                  case 'c': break;
Line 589 
Line 589 
                 case 'C': break;                  case 'C': break;
                 case 'D':                  case 'D':
                         if (debugging)                          if (debugging)
                                 debugtiming = ISC_TRUE;                                  debugtiming = 1;
                         debugging = ISC_TRUE;                          debugging = 1;
                         break;                          break;
                 case 'N': break;                  case 'N': break;
                 case 'R': break;                  case 'R': break;
Line 619 
Line 619 
   
         lookup = make_empty_lookup();          lookup = make_empty_lookup();
   
         lookup->servfail_stops = ISC_FALSE;          lookup->servfail_stops = 0;
         lookup->comments = ISC_FALSE;          lookup->comments = 0;
   
         while ((c = getopt(argc, argv, optstring)) != -1) {          while ((c = getopt(argc, argv, optstring)) != -1) {
                 switch (c) {                  switch (c) {
                 case 'l':                  case 'l':
                         lookup->tcp_mode = ISC_TRUE;                          lookup->tcp_mode = 1;
                         lookup->rdtype = dns_rdatatype_axfr;                          lookup->rdtype = dns_rdatatype_axfr;
                         lookup->rdtypeset = ISC_TRUE;                          lookup->rdtypeset = 1;
                         fatalexit = 3;                          fatalexit = 3;
                         break;                          break;
                 case 'v':                  case 'v':
                 case 'd':                  case 'd':
                         short_form = ISC_FALSE;                          short_form = 0;
                         break;                          break;
                 case 'r':                  case 'r':
                         lookup->recurse = ISC_FALSE;                          lookup->recurse = 0;
                         break;                          break;
                 case 't':                  case 't':
                         if (strncasecmp(optarg, "ixfr=", 5) == 0) {                          if (strncasecmp(optarg, "ixfr=", 5) == 0) {
Line 658 
Line 658 
                         if (!lookup->rdtypeset ||                          if (!lookup->rdtypeset ||
                             lookup->rdtype != dns_rdatatype_axfr)                              lookup->rdtype != dns_rdatatype_axfr)
                                 lookup->rdtype = rdtype;                                  lookup->rdtype = rdtype;
                         lookup->rdtypeset = ISC_TRUE;                          lookup->rdtypeset = 1;
                         if (rdtype == dns_rdatatype_axfr) {                          if (rdtype == dns_rdatatype_axfr) {
                                 /* -l -t any -v */                                  /* -l -t any -v */
                                 list_type = dns_rdatatype_any;                                  list_type = dns_rdatatype_any;
                                 short_form = ISC_FALSE;                                  short_form = 0;
                                 lookup->tcp_mode = ISC_TRUE;                                  lookup->tcp_mode = 1;
                         } else if (rdtype == dns_rdatatype_ixfr) {                          } else if (rdtype == dns_rdatatype_ixfr) {
                                 lookup->ixfr_serial = serial;                                  lookup->ixfr_serial = serial;
                                 lookup->tcp_mode = ISC_TRUE;                                  lookup->tcp_mode = 1;
                                 list_type = rdtype;                                  list_type = rdtype;
                         } else                          } else
                                 list_type = rdtype;                                  list_type = rdtype;
                         list_addresses = ISC_FALSE;                          list_addresses = 0;
                         default_lookups = ISC_FALSE;                          default_lookups = 0;
                         break;                          break;
                 case 'c':                  case 'c':
                         tr.base = optarg;                          tr.base = optarg;
Line 684 
Line 684 
                                 fatal("invalid class: %s\n", optarg);                                  fatal("invalid class: %s\n", optarg);
                         } else {                          } else {
                                 lookup->rdclass = rdclass;                                  lookup->rdclass = rdclass;
                                 lookup->rdclassset = ISC_TRUE;                                  lookup->rdclassset = 1;
                         }                          }
                         default_lookups = ISC_FALSE;                          default_lookups = 0;
                         break;                          break;
                 case 'a':                  case 'a':
                         if (!lookup->rdtypeset ||                          if (!lookup->rdtypeset ||
                             lookup->rdtype != dns_rdatatype_axfr)                              lookup->rdtype != dns_rdatatype_axfr)
                                 lookup->rdtype = dns_rdatatype_any;                                  lookup->rdtype = dns_rdatatype_any;
                         list_type = dns_rdatatype_any;                          list_type = dns_rdatatype_any;
                         list_addresses = ISC_FALSE;                          list_addresses = 0;
                         lookup->rdtypeset = ISC_TRUE;                          lookup->rdtypeset = 1;
                         short_form = ISC_FALSE;                          short_form = 0;
                         default_lookups = ISC_FALSE;                          default_lookups = 0;
                         break;                          break;
                 case 'i':                  case 'i':
                         lookup->ip6_int = ISC_TRUE;                          lookup->ip6_int = 1;
                         break;                          break;
                 case 'n':                  case 'n':
                         /* deprecated */                          /* deprecated */
Line 730 
Line 730 
                                 tries = 2;                                  tries = 2;
                         break;                          break;
                 case 'T':                  case 'T':
                         lookup->tcp_mode = ISC_TRUE;                          lookup->tcp_mode = 1;
                         break;                          break;
                 case 'C':                  case 'C':
                         debug("showing all SOAs");                          debug("showing all SOAs");
                         lookup->rdtype = dns_rdatatype_ns;                          lookup->rdtype = dns_rdatatype_ns;
                         lookup->rdtypeset = ISC_TRUE;                          lookup->rdtypeset = 1;
                         lookup->rdclass = dns_rdataclass_in;                          lookup->rdclass = dns_rdataclass_in;
                         lookup->rdclassset = ISC_TRUE;                          lookup->rdclassset = 1;
                         lookup->ns_search_only = ISC_TRUE;                          lookup->ns_search_only = 1;
                         lookup->trace_root = ISC_TRUE;                          lookup->trace_root = 1;
                         lookup->identify_previous_line = ISC_TRUE;                          lookup->identify_previous_line = 1;
                         default_lookups = ISC_FALSE;                          default_lookups = 0;
                         break;                          break;
                 case 'N':                  case 'N':
                         debug("setting NDOTS to %s", optarg);                          debug("setting NDOTS to %s", optarg);
Line 759 
Line 759 
                         /* Handled by pre_parse_args(). */                          /* Handled by pre_parse_args(). */
                         break;                          break;
                 case 's':                  case 's':
                         lookup->servfail_stops = ISC_TRUE;                          lookup->servfail_stops = 1;
                         break;                          break;
                 default:                  default:
                         show_usage();                          show_usage();
Line 783 
Line 783 
                         fatal("couldn't get address for '%s': %s",                          fatal("couldn't get address for '%s': %s",
                             argv[1], isc_result_totext(res));                              argv[1], isc_result_totext(res));
                 debug("server is %s", *argv + 1);                  debug("server is %s", *argv + 1);
                 listed_server = ISC_TRUE;                  listed_server = 1;
         } else          } else
                 check_ra = ISC_TRUE;                  check_ra = 1;
   
         lookup->pending = ISC_FALSE;          lookup->pending = 0;
         if (get_reverse(store, sizeof(store), hostname,          if (get_reverse(store, sizeof(store), hostname,
                         lookup->ip6_int, ISC_TRUE) == ISC_R_SUCCESS) {                          lookup->ip6_int, 1) == ISC_R_SUCCESS) {
                 strlcpy(lookup->textname, store, sizeof(lookup->textname));                  strlcpy(lookup->textname, store, sizeof(lookup->textname));
                 lookup->rdtype = dns_rdatatype_ptr;                  lookup->rdtype = dns_rdatatype_ptr;
                 lookup->rdtypeset = ISC_TRUE;                  lookup->rdtypeset = 1;
                 default_lookups = ISC_FALSE;                  default_lookups = 0;
         } else {          } else {
                 strlcpy(lookup->textname, hostname, sizeof(lookup->textname));                  strlcpy(lookup->textname, hostname, sizeof(lookup->textname));
                 usesearch = ISC_TRUE;                  usesearch = 1;
         }          }
         lookup->new_search = ISC_TRUE;          lookup->new_search = 1;
         ISC_LIST_APPEND(lookup_list, lookup, link);          ISC_LIST_APPEND(lookup_list, lookup, link);
 }  }
   

Legend:
Removed from v.1.15  
changed lines
  Added in v.1.16