Print this page
7120 mDNS resync was not wsdiff safe

Split Close
Expand all
Collapse all
          --- old/usr/src/cmd/cmd-inet/usr.bin/dns-sd/dns-sd.c
          +++ new/usr/src/cmd/cmd-inet/usr.bin/dns-sd/dns-sd.c
↓ open down ↓ 192 lines elided ↑ open up ↑
 193  193  #define kDNSServiceFlagsReturnIntermediates 0
 194  194  #endif
 195  195  
 196  196  //*************************************************************************************************************
 197  197  // Globals
 198  198  
 199  199  #define DS_FIXED_SIZE   4
 200  200  typedef struct
 201  201  {
 202  202      unsigned short keyTag;
 203      -    unsigned char alg; 
      203 +    unsigned char alg;
 204  204      unsigned char digestType;
 205  205      unsigned char  *digest;
 206  206  } rdataDS;
 207  207  
 208  208  #define DNSKEY_FIXED_SIZE    4
 209  209  typedef struct
 210  210  {
 211  211      unsigned short flags;
 212  212      unsigned char proto;
 213  213      unsigned char alg;
 214  214      unsigned char *data;
 215  215  } rdataDNSKey;
 216  216  
 217      -//size of rdataRRSIG excluding signerName and signature (which are variable fields) 
      217 +//size of rdataRRSIG excluding signerName and signature (which are variable fields)
 218  218  #define RRSIG_FIXED_SIZE      18
 219  219  typedef struct
 220  220  {
 221  221      unsigned short typeCovered;
 222      -    unsigned char alg; 
      222 +    unsigned char alg;
 223  223      unsigned char labels;
 224  224      unsigned int origTTL;
 225  225      unsigned int sigExpireTime;
 226  226      unsigned int sigInceptTime;
 227  227      unsigned short keyTag;
 228  228      char signerName[256];
 229  229      //unsigned char *signature
 230  230  } rdataRRSig;
 231  231  
 232  232  #define RR_TYPE_SIZE 16
↓ open down ↓ 27 lines elided ↑ open up ↑
 260  260  
 261  261  #if _DNS_SD_LIBDISPATCH
 262  262  #define EXIT_IF_LIBDISPATCH_FATAL_ERROR(E) \
 263  263      if (main_queue && (E) == kDNSServiceErr_ServiceNotRunning) { fprintf(stderr, "Error code %d\n", (E)); exit(0); }
 264  264  #else
 265  265  #define EXIT_IF_LIBDISPATCH_FATAL_ERROR(E)
 266  266  #endif
 267  267  
 268  268  //*************************************************************************************************************
 269  269  // Supporting Utility Functions
 270      -static uint16_t GetRRClass(const char *s)   
      270 +static uint16_t GetRRClass(const char *s)
 271  271  {
 272      -    if (!strcasecmp(s, "IN")) 
      272 +    if (!strcasecmp(s, "IN"))
 273  273          return kDNSServiceClass_IN;
 274  274      else
 275  275          return(atoi(s));
 276      -}     
      276 +}
 277  277  
 278  278  static uint16_t GetRRType(const char *s)
 279  279  {
 280  280      if      (!strcasecmp(s, "A"       )) return(kDNSServiceType_A);
 281  281      else if (!strcasecmp(s, "NS"      )) return(kDNSServiceType_NS);
 282  282      else if (!strcasecmp(s, "MD"      )) return(kDNSServiceType_MD);
 283  283      else if (!strcasecmp(s, "MF"      )) return(kDNSServiceType_MF);
 284  284      else if (!strcasecmp(s, "CNAME"   )) return(kDNSServiceType_CNAME);
 285  285      else if (!strcasecmp(s, "SOA"     )) return(kDNSServiceType_SOA);
 286  286      else if (!strcasecmp(s, "MB"      )) return(kDNSServiceType_MB);
↓ open down ↓ 54 lines elided ↑ open up ↑
 341  341          case kDNSServiceType_MX:        return("MX");
 342  342          case kDNSServiceType_CNAME:     return("CNAME");
 343  343          case kDNSServiceType_SOA:       return("SOA");
 344  344          case kDNSServiceType_PTR:       return("PTR");
 345  345          case kDNSServiceType_AAAA:      return("AAAA");
 346  346          case kDNSServiceType_NSEC:      return("NSEC");
 347  347          case kDNSServiceType_TSIG:      return("TSIG");
 348  348          case kDNSServiceType_RRSIG:     return("RRSIG");
 349  349          case kDNSServiceType_DNSKEY:    return("DNSKEY");
 350  350          case kDNSServiceType_DS:        return("DS");
 351      -        default:            
      351 +        default:
 352  352          {
 353  353              static char buffer[RR_TYPE_SIZE];
 354  354              snprintf(buffer, sizeof(buffer), "TYPE%d", rr_type);
 355  355              return(buffer);
 356  356          }
 357  357      }
 358  358  }
 359  359  
 360  360  static unsigned short swap16(unsigned short x)
 361  361  {
 362  362      unsigned char *ptr = (unsigned char *)&x;
 363  363      return (unsigned short)((unsigned short)ptr[0] << 8 | ptr[1]);
 364  364  }
 365  365  
 366      -static unsigned int swap32(unsigned int x) 
      366 +static unsigned int swap32(unsigned int x)
 367  367  {
 368  368      unsigned char *ptr = (unsigned char *)&x;
 369  369      return (unsigned int)((unsigned int)ptr[0] << 24 | (unsigned int)ptr[1] << 16 | (unsigned int)ptr[2] << 8 | ptr[3]);
 370  370  }
 371      -static unsigned int keytag(unsigned char *key, unsigned int keysize)  
      371 +static unsigned int keytag(unsigned char *key, unsigned int keysize)
 372  372  {
 373  373      unsigned long ac;
 374  374      unsigned int i;
 375  375  
 376  376      for (ac = 0, i = 0; i < keysize; ++i)
 377  377          ac += (i & 1) ? key[i] : key[i] << 8;
 378  378      ac += (ac >> 16) & 0xFFFF;
 379  379      return ac & 0xFFFF;
 380  380  }
 381  381  
↓ open down ↓ 8 lines elided ↑ open up ↑
 390  390      if (!src_data)
 391  391          goto done;
 392  392  
 393  393      dest_data = dispatch_data_create_with_transform(src_data, DISPATCH_DATA_FORMAT_TYPE_NONE, DISPATCH_DATA_FORMAT_TYPE_BASE64);
 394  394      if (!dest_data)
 395  395          goto done;
 396  396  
 397  397      null_str = dispatch_data_create("", 1, dispatch_get_global_queue(0, 0), ^{});
 398  398      if (!null_str)
 399  399          goto done;
 400      - 
      400 +
 401  401      data = dispatch_data_create_concat(dest_data, null_str);
 402  402      if (!data)
 403      -        goto done;    
      403 +        goto done;
 404  404  
 405      -    map = dispatch_data_create_map(data, &result, &size);    
      405 +    map = dispatch_data_create_map(data, &result, &size);
 406  406      if (!map)
 407  407          goto done;
 408  408  
 409  409      snprintf(buffer, buflen, " %s", (char *)result);
 410      -    
      410 +
 411  411  done:
 412  412      if (src_data) dispatch_release(src_data);
 413  413      if (dest_data) dispatch_release(dest_data);
 414  414      if (data)     dispatch_release(data);
 415  415      if (null_str) dispatch_release(null_str);
 416  416      if (map)      dispatch_release(map);
 417  417      return;
 418  418  #else  //_DNS_SD_LIBDISPATCH
 419  419      snprintf(buffer, buflen, " %s", ".");
 420  420      return;
 421      -#endif //_DNS_SD_LIBDISPATCH 
      421 +#endif //_DNS_SD_LIBDISPATCH
 422  422  }
 423  423  
 424  424  #if HAS_NAT_PMP_API | HAS_ADDRINFO_API
 425  425  static DNSServiceProtocol GetProtocol(const char *s)
 426  426  {
 427  427      if      (!strcasecmp(s, "v4"      )) return(kDNSServiceProtocol_IPv4);
 428  428      else if (!strcasecmp(s, "v6"      )) return(kDNSServiceProtocol_IPv6);
 429  429      else if (!strcasecmp(s, "v4v6"    )) return(kDNSServiceProtocol_IPv4 | kDNSServiceProtocol_IPv6);
 430  430      else if (!strcasecmp(s, "v6v4"    )) return(kDNSServiceProtocol_IPv4 | kDNSServiceProtocol_IPv6);
 431  431      else if (!strcasecmp(s, "udp"     )) return(kDNSServiceProtocol_UDP);
↓ open down ↓ 29 lines elided ↑ open up ↑
 461  461      strftime(new_date, sizeof(new_date), "%a %d %b %Y", &tm);
 462  462      if (strncmp(date, new_date, sizeof(new_date)))
 463  463      {
 464  464          printf("DATE: ---%s---\n", new_date); //display date only if it has changed
 465  465          strncpy(date, new_date, sizeof(date));
 466  466      }
 467  467      printf("%2d:%02d:%02d.%03d  ", tm.tm_hour, tm.tm_min, tm.tm_sec, ms);
 468  468  }
 469  469  
 470  470  // formating time to RFC 4034 format
 471      -static void FormatTime(unsigned long te, unsigned char *buf, int bufsize) 
      471 +static void FormatTime(unsigned long te, unsigned char *buf, int bufsize)
 472  472  {
 473  473      struct tm tmTime;
 474  474  #ifdef _WIN32
 475  475          __time32_t t = (__time32_t) te;
 476  476          _gmtime32_s(&tmTime, &t);
 477  477  #else
 478  478      // Time since epoch : strftime takes "tm". Convert seconds to "tm" using
 479  479      // gmtime_r first and then use strftime
 480  480          time_t t = (time_t)te;
 481  481          gmtime_r(&t, &tmTime);
↓ open down ↓ 207 lines elided ↑ open up ↑
 689  689  static void DNSSD_API browse_reply(DNSServiceRef sdref, const DNSServiceFlags flags, uint32_t ifIndex, DNSServiceErrorType errorCode,
 690  690                                     const char *replyName, const char *replyType, const char *replyDomain, void *context)
 691  691  {
 692  692      char *op = (flags & kDNSServiceFlagsAdd) ? "Add" : "Rmv";
 693  693      (void)sdref;        // Unused
 694  694      (void)context;      // Unused
 695  695      EXIT_IF_LIBDISPATCH_FATAL_ERROR(errorCode);
 696  696  
 697  697      if (num_printed++ == 0) printf("Timestamp     A/R    Flags  if %-20s %-20s %s\n", "Domain", "Service Type", "Instance Name");
 698  698      printtimestamp();
 699      -    if (errorCode) 
      699 +    if (errorCode)
 700  700          printf("Error code %d\n", errorCode);
 701      -    else 
 702      -        printf("%s %8X %3d %-20s %-20s %s\n", 
      701 +    else
      702 +        printf("%s %8X %3d %-20s %-20s %s\n",
 703  703                  op, flags, ifIndex, replyDomain, replyType, replyName);
 704  704      if (!(flags & kDNSServiceFlagsMoreComing)) fflush(stdout);
 705  705  
 706  706      // To test selective cancellation of operations of shared sockets,
 707  707      // cancel the current operation when we've got a multiple of five results
 708  708      //if (operation == 'S' && num_printed % 5 == 0) DNSServiceRefDeallocate(sdref);
 709  709  }
 710  710  
 711  711  static void ShowTXTRecord(uint16_t txtLen, const unsigned char *txtRecord)
 712  712  {
↓ open down ↓ 149 lines elided ↑ open up ↑
 862  862          printf("Error %d\n", errorCode);
 863  863  
 864  864      if (!(flags & kDNSServiceFlagsMoreComing)) fflush(stdout);
 865  865  }
 866  866  
 867  867  // Output the wire-format domainname pointed to by rd
 868  868  static int snprintd(char *p, int max, const unsigned char **rd)
 869  869  {
 870  870      const char *const buf = p;
 871  871      const char *const end = p + max;
 872      -    while (**rd) 
 873      -    { 
 874      -        p += snprintf(p, end-p, "%.*s.", **rd, *rd+1); 
 875      -        *rd += 1 + **rd; 
      872 +    while (**rd)
      873 +    {
      874 +        p += snprintf(p, end-p, "%.*s.", **rd, *rd+1);
      875 +        *rd += 1 + **rd;
 876  876      }
 877  877      *rd += 1;   // Advance over the final zero byte
 878  878      return(p-buf);
 879  879  }
 880  880  
 881  881  static void ParseDNSSECRecords(uint16_t rrtype, char *rdb, char *p, unsigned const char *rd, uint16_t rdlen)
 882  882  {
 883  883      int rdb_size = 1000;
 884      -    switch (rrtype) 
      884 +    switch (rrtype)
 885  885      {
 886  886          case kDNSServiceType_DS:
 887  887          {
 888  888              unsigned char *ptr;
 889  889              int i;
 890  890              rdataDS *rrds = (rdataDS *)rd;
 891  891              p += snprintf(p, rdb + rdb_size - p, "%d  %d  %d  ",
 892  892                            rrds->alg, swap16(rrds->keyTag), rrds->digestType);
 893  893              ptr = (unsigned char *)(rd + DS_FIXED_SIZE);
 894  894              for (i = 0; i < (rdlen - DS_FIXED_SIZE); i++)
 895      -                p += snprintf(p, rdb + rdb_size - p, "%x", ptr[i]);   
 896      -            break; 
 897      -        } 
 898      -            
      895 +                p += snprintf(p, rdb + rdb_size - p, "%x", ptr[i]);
      896 +            break;
      897 +        }
      898 +
 899  899          case kDNSServiceType_DNSKEY:
 900  900          {
 901  901              rdataDNSKey *rrkey = (rdataDNSKey *)rd;
 902  902              p += snprintf(p, rdb + rdb_size - p, "%d  %d  %d  %u", swap16(rrkey->flags), rrkey->proto,
 903  903                            rrkey->alg, (unsigned int)keytag((unsigned char *)rrkey, rdlen));
 904  904              base64Encode(p, rdb + rdb_size - p, (unsigned char *)(rd + DNSKEY_FIXED_SIZE), rdlen - DNSKEY_FIXED_SIZE);
 905  905              break;
 906  906          }
 907      -            
 908      -        case kDNSServiceType_NSEC: 
      907 +
      908 +        case kDNSServiceType_NSEC:
 909  909          {
 910  910              unsigned char *next = (unsigned char *)rd;
 911  911              int len, bitmaplen;
 912  912              int win, wlen, type;
 913  913              unsigned char *bmap;
 914  914              char *l = NULL;
 915      -            
      915 +
 916  916              l = p;
 917  917              p += snprintd(p, rdb + rdb_size - p, &rd);
 918  918              len = p - l + 1;
 919      -            
      919 +
 920  920              bitmaplen = rdlen - len;
 921  921              bmap = (unsigned char *)((unsigned char *)next + len);
 922      -            
      922 +
 923  923              while (bitmaplen > 0)
 924  924              {
 925  925                  int i;
 926      -                
      926 +
 927  927                  if (bitmaplen < 3)
 928  928                  {
 929  929                      printf("Case NSEC: malformed nsec, bitmaplen %d short\n", bitmaplen);
 930  930                      break;
 931      -                }   
 932      -                
      931 +                }
      932 +
 933  933                  win = *bmap++;
 934  934                  wlen = *bmap++;
 935  935                  bitmaplen -= 2;
 936  936                  if (bitmaplen < wlen || wlen < 1 || wlen > 32)
 937  937                  {
 938  938                      printf("Case NSEC: malformed nsec, bitmaplen %d wlen %d\n", bitmaplen, wlen);
 939  939                      break;
 940  940                  }
 941  941                  if (win < 0 || win >= 256)
 942  942                  {
↓ open down ↓ 4 lines elided ↑ open up ↑
 947  947                  for (i = 0; i < wlen * 8; i++)
 948  948                  {
 949  949                      if (bmap[i>>3] & (128 >> (i&7)))
 950  950                          p += snprintf(p, rdb + rdb_size - p, " %s ", DNSTypeName(type + i));
 951  951                  }
 952  952                  bmap += wlen;
 953  953                  bitmaplen -= wlen;
 954  954              }
 955  955              break;
 956  956          }
 957      -            
 958      -        case kDNSServiceType_RRSIG:    
      957 +
      958 +        case kDNSServiceType_RRSIG:
 959  959          {
 960  960              rdataRRSig *rrsig = (rdataRRSig *)rd;
 961  961              unsigned char expTimeBuf[64];
 962  962              unsigned char inceptTimeBuf[64];
 963  963              unsigned long inceptClock;
 964  964              unsigned long expClock;
 965  965              const unsigned char *q = NULL;
 966  966              char *k = NULL;
 967  967              int len;
 968      -            
      968 +
 969  969              expClock = (unsigned long)swap32(rrsig->sigExpireTime);
 970  970              FormatTime(expClock, expTimeBuf, sizeof(expTimeBuf));
 971      -            
      971 +
 972  972              inceptClock = (unsigned long)swap32(rrsig->sigInceptTime);
 973  973              FormatTime(inceptClock, inceptTimeBuf, sizeof(inceptTimeBuf));
 974      -            
      974 +
 975  975              p += snprintf(p, rdb + rdb_size - p, " %-7s  %d  %d  %d  %s  %s  %7d  ",
 976  976                            DNSTypeName(swap16(rrsig->typeCovered)), rrsig->alg, rrsig->labels, swap32(rrsig->origTTL),
 977  977                            expTimeBuf, inceptTimeBuf, swap16(rrsig->keyTag));
 978      -            
      978 +
 979  979              q = (const unsigned char *)&rrsig->signerName;
 980  980              k = p;
 981  981              p += snprintd(p, rdb + rdb_size - p, &q);
 982  982              len = p - k + 1;
 983      -            
      983 +
 984  984              base64Encode(p, rdb + rdb_size - p, (unsigned char *)(rd + len + RRSIG_FIXED_SIZE), rdlen - (len + RRSIG_FIXED_SIZE));
 985  985              break;
 986  986          }
 987  987      }
 988      -    return;                           
      988 +    return;
 989  989  }
 990  990  
 991  991  static void DNSSD_API qr_reply(DNSServiceRef sdref, const DNSServiceFlags flags, uint32_t ifIndex, DNSServiceErrorType errorCode,
 992  992                                 const char *fullname, uint16_t rrtype, uint16_t rrclass, uint16_t rdlen, const void *rdata, uint32_t ttl, void *context)
 993  993  {
 994  994      char *op = (flags & kDNSServiceFlagsAdd) ? "Add" : "Rmv";
 995  995      const unsigned char *rd  = rdata;
 996  996      const unsigned char *end = (const unsigned char *) rdata + rdlen;
 997  997      char rdb[1000] = "0.0.0.0", *p = rdb;
 998  998      int unknowntype = 0;
↓ open down ↓ 3 lines elided ↑ open up ↑
1002 1002      DNSServiceFlags check_flags = flags;//local flags for dnssec status checking
1003 1003  
1004 1004      (void)sdref;    // Unused
1005 1005      (void)ifIndex;  // Unused
1006 1006      (void)ttl;      // Unused
1007 1007      (void)context;  // Unused
1008 1008      EXIT_IF_LIBDISPATCH_FATAL_ERROR(errorCode);
1009 1009  
1010 1010      if (num_printed++ == 0)
1011 1011      {
1012      -        if (operation == 'D') 
1013      -            printf("Timestamp     A/R if %-30s%-6s%-7s%-18s Rdata\n", "Name", "Type", "Class", "DNSSECStatus"); 
1014      -        else     
     1012 +        if (operation == 'D')
     1013 +            printf("Timestamp     A/R if %-30s%-6s%-7s%-18s Rdata\n", "Name", "Type", "Class", "DNSSECStatus");
     1014 +        else
1015 1015              printf("Timestamp     A/R Flags if %-30s%-6s%-7s Rdata\n", "Name", "Type", "Class");
1016 1016      }
1017 1017      printtimestamp();
1018 1018  
1019 1019      switch (rrclass)
1020 1020      {
1021 1021          case kDNSServiceClass_IN:
1022 1022              strncpy(rr_class, "IN", sizeof(rr_class));
1023 1023              break;
1024 1024          default:
↓ open down ↓ 4 lines elided ↑ open up ↑
1029 1029  
1030 1030      if (!errorCode) //to avoid printing garbage in rdata
1031 1031      {
1032 1032          if (!(check_flags & (kDNSServiceFlagsValidate | kDNSServiceFlagsValidateOptional)))
1033 1033          {
1034 1034              switch (rrtype)
1035 1035              {
1036 1036                  case kDNSServiceType_A:
1037 1037                      snprintf(rdb, sizeof(rdb), "%d.%d.%d.%d", rd[0], rd[1], rd[2], rd[3]);
1038 1038                      break;
1039      -    
     1039 +
1040 1040                  case kDNSServiceType_NS:
1041 1041                  case kDNSServiceType_CNAME:
1042 1042                  case kDNSServiceType_PTR:
1043 1043                  case kDNSServiceType_DNAME:
1044 1044                      p += snprintd(p, sizeof(rdb), &rd);
1045 1045                      break;
1046 1046  
1047 1047                  case kDNSServiceType_SOA:
1048 1048                      p += snprintd(p, rdb + sizeof(rdb) - p, &rd);           // mname
1049 1049                      p += snprintf(p, rdb + sizeof(rdb) - p, " ");
↓ open down ↓ 15 lines elided ↑ open up ↑
1065 1065                      p += snprintd(p, rdb + sizeof(rdb) - p, &rd);               // target host
1066 1066                      break;
1067 1067  
1068 1068                  case kDNSServiceType_DS:
1069 1069                  case kDNSServiceType_DNSKEY:
1070 1070                  case kDNSServiceType_NSEC:
1071 1071                  case kDNSServiceType_RRSIG:
1072 1072                      ParseDNSSECRecords(rrtype, rdb, p, rd, rdlen);
1073 1073                      break;
1074 1074  
1075      -                default: 
1076      -                    snprintf(rdb, sizeof(rdb), "%d bytes%s", rdlen, rdlen ? ":" : ""); 
     1075 +                default:
     1076 +                    snprintf(rdb, sizeof(rdb), "%d bytes%s", rdlen, rdlen ? ":" : "");
1077 1077                      unknowntype = 1;
1078 1078                      break;
1079      -            }   
1080      -        }   
1081      -        else 
     1079 +            }
     1080 +        }
     1081 +        else
1082 1082          {
1083 1083              strncpy(rdb, "----", sizeof(rdb));
1084 1084              //Clear all o/p bits, and then check for dnssec status
1085 1085              check_flags &= ~kDNSServiceOutputFlags;
1086 1086              if (check_flags & kDNSServiceFlagsSecure)
1087 1087                  strncpy(dnssec_status, "Secure", sizeof(dnssec_status));
1088 1088              else if (check_flags & kDNSServiceFlagsInsecure)
1089 1089                  strncpy(dnssec_status, "Insecure", sizeof(dnssec_status));
1090 1090              else if (check_flags & kDNSServiceFlagsIndeterminate)
1091 1091                  strncpy(dnssec_status, "Indeterminate", sizeof(dnssec_status));
1092      -            else if (check_flags & kDNSServiceFlagsBogus) 
     1092 +            else if (check_flags & kDNSServiceFlagsBogus)
1093 1093                  strncpy(dnssec_status, "Bogus", sizeof(dnssec_status));
1094 1094          }
1095 1095      }
1096 1096  
1097 1097      if (operation == 'D')
1098 1098          printf("%s%3d %-30s%-6s%-7s%-18s %s", op, ifIndex, fullname, rr_type, rr_class, dnssec_status, rdb);
1099 1099      else
1100 1100          printf("%s%6X%3d %-30s%-7s%-6s %s", op, flags, ifIndex, fullname, rr_type, rr_class, rdb);
1101 1101      if (unknowntype)
1102      -    { 
1103      -        while (rd < end) 
     1102 +    {
     1103 +        while (rd < end)
1104 1104              printf(" %02X", *rd++);
1105 1105      }
1106 1106      if (errorCode)
1107 1107      {
1108      -        if (errorCode == kDNSServiceErr_NoSuchRecord) 
     1108 +        if (errorCode == kDNSServiceErr_NoSuchRecord)
1109 1109              printf("    No Such Record");
1110 1110          else if (errorCode == kDNSServiceErr_Timeout)
1111 1111          {
1112 1112              printf("    No Such Record\n");
1113 1113              printf("Query Timed Out\n");
1114 1114              exit(1);
1115 1115          }
1116 1116      }
1117 1117      printf("\n");
1118 1118  
1119 1119      if (operation == 'C')
1120 1120          if (flags & kDNSServiceFlagsAdd)
1121 1121              DNSServiceReconfirmRecord(flags, ifIndex, fullname, rrtype, rrclass, rdlen, rdata);
1122 1122  
1123      -    if (!(flags & kDNSServiceFlagsMoreComing)) 
     1123 +    if (!(flags & kDNSServiceFlagsMoreComing))
1124 1124          fflush(stdout);
1125 1125  }
1126 1126  
1127 1127  #if HAS_NAT_PMP_API
1128 1128  static void DNSSD_API port_mapping_create_reply(DNSServiceRef sdref, DNSServiceFlags flags, uint32_t ifIndex, DNSServiceErrorType errorCode, uint32_t publicAddress, uint32_t protocol, uint16_t privatePort, uint16_t publicPort, uint32_t ttl, void *context)
1129 1129  {
1130 1130      (void)sdref;       // Unused
1131 1131      (void)flags;       // Unused
1132 1132      (void)context;     // Unused
1133 1133      EXIT_IF_LIBDISPATCH_FATAL_ERROR(errorCode);
↓ open down ↓ 12 lines elided ↑ open up ↑
1146 1146  
1147 1147      if (!(flags & kDNSServiceFlagsMoreComing)) fflush(stdout);
1148 1148  }
1149 1149  #endif
1150 1150  
1151 1151  #if HAS_ADDRINFO_API
1152 1152  static void DNSSD_API addrinfo_reply(DNSServiceRef sdref, const DNSServiceFlags flags, uint32_t interfaceIndex, DNSServiceErrorType errorCode, const char *hostname, const struct sockaddr *address, uint32_t ttl, void *context)
1153 1153  {
1154 1154      char *op = (flags & kDNSServiceFlagsAdd) ? "Add" : "Rmv";
1155 1155      char addr[256] = "";
1156      -    char dnssec_status[15] = "Unknown"; 
     1156 +    char dnssec_status[15] = "Unknown";
1157 1157      DNSServiceFlags check_flags = flags;
1158 1158          (void) sdref;
1159 1159          (void) context;
1160 1160  
1161 1161      EXIT_IF_LIBDISPATCH_FATAL_ERROR(errorCode);
1162 1162  
1163 1163      if (num_printed++ == 0)
1164 1164      {
1165      -        if (operation == 'g') 
     1165 +        if (operation == 'g')
1166 1166              printf("Timestamp     A/R if %-25s %-44s %-18s\n", "Hostname", "Address", "DNSSECStatus");
1167      -        else  
     1167 +        else
1168 1168              printf("Timestamp     A/R Flags if %-38s %-44s %s\n", "Hostname", "Address", "TTL");
1169 1169      }
1170 1170      printtimestamp();
1171      -   
     1171 +
1172 1172      if (address && address->sa_family == AF_INET)
1173 1173      {
1174 1174          const unsigned char *b = (const unsigned char *) &((struct sockaddr_in *)address)->sin_addr;
1175 1175          snprintf(addr, sizeof(addr), "%d.%d.%d.%d", b[0], b[1], b[2], b[3]);
1176 1176      }
1177 1177      else if (address && address->sa_family == AF_INET6)
1178 1178      {
1179 1179          char if_name[IFNAMSIZ];     // Older Linux distributions don't define IF_NAMESIZE
1180 1180          const struct sockaddr_in6 *s6 = (const struct sockaddr_in6 *)address;
1181 1181          const unsigned char       *b  = (const unsigned char *      )&s6->sin6_addr;
↓ open down ↓ 9 lines elided ↑ open up ↑
1191 1191      {
1192 1192          strncpy(addr, "----", sizeof(addr));
1193 1193          //Clear all o/p bits, and then check for dnssec status
1194 1194          check_flags &= ~kDNSServiceOutputFlags;
1195 1195          if (check_flags & kDNSServiceFlagsSecure)
1196 1196              strncpy(dnssec_status, "Secure", sizeof(dnssec_status));
1197 1197          else if (check_flags & kDNSServiceFlagsInsecure)
1198 1198              strncpy(dnssec_status, "Insecure", sizeof(dnssec_status));
1199 1199          else if (check_flags & kDNSServiceFlagsIndeterminate)
1200 1200              strncpy(dnssec_status, "Indeterminate", sizeof(dnssec_status));
1201      -        else if (check_flags & kDNSServiceFlagsBogus) 
     1201 +        else if (check_flags & kDNSServiceFlagsBogus)
1202 1202              strncpy(dnssec_status, "Bogus", sizeof(dnssec_status));
1203 1203      }
1204      -    
     1204 +
1205 1205      if (operation == 'g')
1206 1206          printf("%s%3d %-25s %-44s %-18s", op, interfaceIndex, hostname, addr, dnssec_status);
1207 1207      else
1208 1208          printf("%s%6X%3d %-38s %-44s %d", op, flags, interfaceIndex, hostname, addr, ttl);
1209 1209      if (errorCode)
1210 1210      {
1211      -        if (errorCode == kDNSServiceErr_NoSuchRecord) 
     1211 +        if (errorCode == kDNSServiceErr_NoSuchRecord)
1212 1212              printf("   No Such Record");
1213      -        else 
     1213 +        else
1214 1214              printf("   Error code %d", errorCode);
1215 1215      }
1216 1216      printf("\n");
1217 1217  
1218      -    if (!(flags & kDNSServiceFlagsMoreComing)) 
     1218 +    if (!(flags & kDNSServiceFlagsMoreComing))
1219 1219          fflush(stdout);
1220 1220  }
1221 1221  #endif
1222 1222  
1223 1223  //*************************************************************************************************************
1224 1224  // The main test function
1225 1225  
1226 1226  static void HandleEvents(void)
1227 1227  #if _DNS_SD_LIBDISPATCH
1228 1228  {
↓ open down ↓ 398 lines elided ↑ open up ↑
1627 1627          break;
1628 1628  
1629 1629      case 'D':
1630 1630      case 'q':
1631 1631      case 'Q':
1632 1632      case 'C':   {
1633 1633          uint16_t rrtype, rrclass;
1634 1634          flags |= kDNSServiceFlagsReturnIntermediates;
1635 1635          if (operation == 'q')
1636 1636              flags |= kDNSServiceFlagsSuppressUnusable;
1637      -        if (argc < opi+1) 
     1637 +        if (argc < opi+1)
1638 1638              goto Fail;
1639 1639          rrtype = (argc <= opi+1) ? kDNSServiceType_A  : GetRRType(argv[opi+1]);
1640 1640          rrclass = (argc <= opi+2) ? kDNSServiceClass_IN : GetRRClass(argv[opi+2]);
1641 1641          if (rrtype == kDNSServiceType_TXT || rrtype == kDNSServiceType_PTR)
1642 1642              flags |= kDNSServiceFlagsLongLivedQuery;
1643 1643          if (operation == 'D')
1644 1644          {
1645 1645              flags |= kDNSServiceFlagsSuppressUnusable;
1646 1646              if (optional)
1647 1647                  flags |= kDNSServiceFlagsValidateOptional;
↓ open down ↓ 70 lines elided ↑ open up ↑
1718 1718      case 'G':   {
1719 1719          flags |= kDNSServiceFlagsReturnIntermediates;
1720 1720          if (operation == 'g')
1721 1721          {
1722 1722              flags |= kDNSServiceFlagsSuppressUnusable;
1723 1723              if (optional)
1724 1724                  flags |= kDNSServiceFlagsValidateOptional;
1725 1725              else
1726 1726                  flags |= kDNSServiceFlagsValidate;
1727 1727          }
1728      -        if (argc != opi+2) 
     1728 +        if (argc != opi+2)
1729 1729              goto Fail;
1730      -        else 
     1730 +        else
1731 1731              err = DNSServiceGetAddrInfo(&client, flags, opinterface, GetProtocol(argv[opi+0]), argv[opi+1], addrinfo_reply, NULL);
1732 1732          break;
1733 1733      }
1734 1734  #endif
1735 1735  
1736 1736      case 'S':   {
1737 1737          Opaque16 registerPort = { { 0x23, 0x45 } };                 // 9029 decimal
1738 1738          unsigned char txtrec[16] = "\xF" "/path=test.html";
1739 1739          DNSRecordRef rec;
1740 1740          unsigned char nulrec[4] = "1234";
↓ open down ↓ 63 lines elided ↑ open up ↑
1804 1804  }
1805 1805  
1806 1806  // Note: The C preprocessor stringify operator ('#') makes a string from its argument, without macro expansion
1807 1807  // e.g. If "version" is #define'd to be "4", then STRINGIFY_AWE(version) will return the string "version", not "4"
1808 1808  // To expand "version" to its value before making the string, use STRINGIFY(version) instead
1809 1809  #define STRINGIFY_ARGUMENT_WITHOUT_EXPANSION(s) # s
1810 1810  #define STRINGIFY(s) STRINGIFY_ARGUMENT_WITHOUT_EXPANSION(s)
1811 1811  
1812 1812  // NOT static -- otherwise the compiler may optimize it out
1813 1813  // The "@(#) " pattern is a special prefix the "what" command looks for
     1814 +#ifndef MDNS_VERSIONSTR_NODTS
1814 1815  const char VersionString_SCCS[] = "@(#) dns-sd " STRINGIFY(mDNSResponderVersion) " (" __DATE__ " " __TIME__ ")";
     1816 +#else
     1817 +const char VersionString_SCCS[] = "@(#) dns-sd " STRINGIFY(mDNSResponderVersion);
     1818 +#endif
1815 1819  
1816 1820  #if _BUILDING_XCODE_PROJECT_
1817 1821  // If the process crashes, then this string will be magically included in the automatically-generated crash log
1818 1822  const char *__crashreporter_info__ = VersionString_SCCS + 5;
1819 1823  asm (".desc ___crashreporter_info__, 0x10");
1820 1824  #endif
    
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX