Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/external/apache2/mDNSResponder/dist Import mDNSResponder-258...



details:   https://anonhg.NetBSD.org/src/rev/9bd51f59dbe1
branches:  trunk
changeset: 328025:9bd51f59dbe1
user:      pettai <pettai%NetBSD.org@localhost>
date:      Mon Mar 24 00:31:13 2014 +0000

description:
Import mDNSResponder-258.14, merge, fix conflicts

diffstat:

 external/apache2/mDNSResponder/dist/Clients/dns-sd.c              |   160 +-
 external/apache2/mDNSResponder/dist/mDNSCore/DNSCommon.c          |   974 +-
 external/apache2/mDNSResponder/dist/mDNSCore/DNSDigest.c          |    99 +-
 external/apache2/mDNSResponder/dist/mDNSCore/mDNS.c               |  6031 +++++----
 external/apache2/mDNSResponder/dist/mDNSCore/mDNSEmbeddedAPI.h    |  1570 +-
 external/apache2/mDNSResponder/dist/mDNSPosix/PosixDaemon.c       |    92 +-
 external/apache2/mDNSResponder/dist/mDNSPosix/mDNSPosix.c         |   162 +-
 external/apache2/mDNSResponder/dist/mDNSPosix/mDNSUNP.c           |   145 +-
 external/apache2/mDNSResponder/dist/mDNSShared/dns-sd.1           |    21 -
 external/apache2/mDNSResponder/dist/mDNSShared/dns_sd.h           |   289 +-
 external/apache2/mDNSResponder/dist/mDNSShared/dnssd_clientlib.c  |    73 -
 external/apache2/mDNSResponder/dist/mDNSShared/dnssd_clientstub.c |   691 +-
 external/apache2/mDNSResponder/dist/mDNSShared/dnssd_ipc.h        |   138 +-
 external/apache2/mDNSResponder/dist/mDNSShared/uds_daemon.c       |  1699 +-
 14 files changed, 5302 insertions(+), 6842 deletions(-)

diffs (truncated from 16916 to 300 lines):

diff -r bbd918321302 -r 9bd51f59dbe1 external/apache2/mDNSResponder/dist/Clients/dns-sd.c
--- a/external/apache2/mDNSResponder/dist/Clients/dns-sd.c      Mon Mar 24 00:23:27 2014 +0000
+++ b/external/apache2/mDNSResponder/dist/Clients/dns-sd.c      Mon Mar 24 00:31:13 2014 +0000
@@ -70,6 +70,14 @@
 // aren't in the system's /usr/lib/libSystem.dylib.
 //#define TEST_NEW_CLIENTSTUB 1
 
+// When building mDNSResponder for Mac OS X 10.4 and earlier, /usr/lib/libSystem.dylib is built using its own private
+// copy of dnssd_clientstub.c, which is old and doesn't have all the entry points defined in the latest version, so
+// when we're building dns-sd.c on Mac OS X 10.4 or earlier, we automatically set TEST_NEW_CLIENTSTUB so that we'll
+// embed a copy of the latest dnssd_clientstub.c instead of trying to link to the incomplete version in libSystem.dylib
+#if defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ <= 1040
+#define TEST_NEW_CLIENTSTUB 1
+#endif
+
 #include <ctype.h>
 #include <stdio.h>                     // For stdout, stderr
 #include <stdlib.h>                    // For exit()
@@ -144,6 +152,15 @@
                return name;
                }
 
+       static size_t _sa_len(const struct sockaddr *addr)
+               {
+               if (addr->sa_family == AF_INET) return (sizeof(struct sockaddr_in));
+               else if (addr->sa_family == AF_INET6) return (sizeof(struct sockaddr_in6));
+               else return (sizeof(struct sockaddr));
+               }
+
+#   define SA_LEN(addr) (_sa_len(addr))
+
 #else
        #include <unistd.h>                     // For getopt() and optind
        #include <netdb.h>                      // For getaddrinfo()
@@ -153,14 +170,18 @@
        #include <arpa/inet.h>          // For inet_addr()
        #include <net/if.h>                     // For if_nametoindex()
        static const char kFilePathSep = '/';
+       #define SA_LEN(addr) ((addr)->sa_len)
 #endif
 
 #if (TEST_NEW_CLIENTSTUB && !defined(__APPLE_API_PRIVATE))
 #define __APPLE_API_PRIVATE 1
 #endif
 
+// DNSServiceSetDispatchQueue is not supported on 10.6 & prior
+#if ! TEST_NEW_CLIENTSTUB && defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && (__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ - (__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ % 10) <= 1060)
+#undef _DNS_SD_LIBDISPATCH
+#endif
 #include "dns_sd.h"
-
 #include "ClientCommon.h"
 
 #if TEST_NEW_CLIENTSTUB
@@ -196,12 +217,24 @@
 static char updatetest[3] = "\002AA";
 static char bigNULL[8192];     // 8K is maximum rdata we support
 
+#if _DNS_SD_LIBDISPATCH
+dispatch_queue_t main_queue;
+dispatch_source_t timer_source;
+#endif
+
 // Note: the select() implementation on Windows (Winsock2) fails with any timeout much larger than this
 #define LONG_TIME 100000000
 
 static volatile int stopNow = 0;
 static volatile int timeOut = LONG_TIME;
 
+#if _DNS_SD_LIBDISPATCH
+#define EXIT_IF_LIBDISPATCH_FATAL_ERROR(E) \
+       if (main_queue && (E) == kDNSServiceErr_ServiceNotRunning) { fprintf(stderr, "Error code %d\n", (E)); exit(0); }
+#else
+#define EXIT_IF_LIBDISPATCH_FATAL_ERROR(E)
+#endif
+
 //*************************************************************************************************************
 // Supporting Utility Functions
 
@@ -311,6 +344,7 @@
        (void)sdref;        // Unused
        (void)ifIndex;      // Unused
        (void)context;      // Unused
+       EXIT_IF_LIBDISPATCH_FATAL_ERROR(errorCode);
 
        // 1. Print the header
        if (num_printed++ == 0) printf("Timestamp     Recommended %s domain\n", operation == 'E' ? "Registration" : "Browsing");
@@ -443,6 +477,7 @@
 
        (void)sdref;        // Unused
        (void)context;      // Unused
+       EXIT_IF_LIBDISPATCH_FATAL_ERROR(errorCode);
 
        if (!(flags & kDNSServiceFlagsAdd)) return;
        if (errorCode) { printf("Error code %d\n", errorCode); return; }
@@ -458,6 +493,8 @@
        char *op = (flags & kDNSServiceFlagsAdd) ? "Add" : "Rmv";
        (void)sdref;        // Unused
        (void)context;      // Unused
+       EXIT_IF_LIBDISPATCH_FATAL_ERROR(errorCode);
+
        if (num_printed++ == 0) printf("Timestamp     A/R Flags if %-25s %-25s %s\n", "Domain", "Service Type", "Instance Name");
        printtimestamp();
        if (errorCode) printf("Error code %d\n", errorCode);
@@ -512,11 +549,13 @@
        (void)sdref;        // Unused
        (void)ifIndex;      // Unused
        (void)context;      // Unused
+       EXIT_IF_LIBDISPATCH_FATAL_ERROR(errorCode);
 
-       printtimestamp();
-       if (errorCode) printf("Error code %d\n", errorCode);
+       if (errorCode)
+               printf("Error code %d\n", errorCode);
        else
                {
+               printtimestamp();
                printf("%s can be reached at %s:%u (interface %d)", fullname, hosttarget, PortAsNumber, ifIndex);
                if (flags) printf(" Flags: %X", flags);
                // Don't show degenerate TXT records containing nothing but a single empty string
@@ -571,6 +610,11 @@
                        err = DNSServiceAddRecord(client, &record, 0, kDNSServiceType_NULL, sizeof(bigNULL), &bigNULL[0], 0);
                        if (err) printf("Failed: %d\n", err); else printf("Succeeded\n");
                        timeOut = LONG_TIME;
+#if _DNS_SD_LIBDISPATCH
+                       if (timer_source)
+                               dispatch_source_set_timer(timer_source, dispatch_time(DISPATCH_TIME_NOW, (uint64_t)timeOut * NSEC_PER_SEC),
+                                       (uint64_t)timeOut * NSEC_PER_SEC, 0);
+#endif
                        }
                        break;
                }
@@ -588,6 +632,7 @@
        (void)sdref;    // Unused
        (void)flags;    // Unused
        (void)context;  // Unused
+       EXIT_IF_LIBDISPATCH_FATAL_ERROR(errorCode);
 
        printtimestamp();
        printf("Got a reply for service %s.%s%s: ", name, regtype, domain);
@@ -596,7 +641,15 @@
                {
                if (flags & kDNSServiceFlagsAdd) printf("Name now registered and active\n"); 
                else printf("Name registration removed\n"); 
-               if (operation == 'A' || operation == 'U' || operation == 'N') timeOut = 5;
+               if (operation == 'A' || operation == 'U' || operation == 'N')
+                       {
+                       timeOut = 5;
+#if _DNS_SD_LIBDISPATCH
+                       if (timer_source)
+                               dispatch_source_set_timer(timer_source, dispatch_time(DISPATCH_TIME_NOW, (uint64_t)timeOut * NSEC_PER_SEC),
+                                       (uint64_t)timeOut * NSEC_PER_SEC, 0);
+#endif
+                       }
                }
        else if (errorCode == kDNSServiceErr_NameConflict)
                {
@@ -633,6 +686,7 @@
        (void)ifIndex;  // Unused
        (void)ttl;      // Unused
        (void)context;  // Unused
+       EXIT_IF_LIBDISPATCH_FATAL_ERROR(errorCode);
 
        if (num_printed++ == 0) printf("Timestamp     A/R Flags if %-30s%4s%4s Rdata\n", "Name", "T", "C");
        printtimestamp();
@@ -697,9 +751,10 @@
 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)
        {
        (void)sdref;       // Unused
+       (void)flags;       // Unused
        (void)context;     // Unused
-       (void)flags;       // Unused
-       
+       EXIT_IF_LIBDISPATCH_FATAL_ERROR(errorCode);
+
        if (num_printed++ == 0) printf("Timestamp     if   %-20s %-15s %-15s %-15s %-6s\n", "External Address", "Protocol", "Internal Port", "External Port", "TTL");
        printtimestamp();
        if (errorCode && errorCode != kDNSServiceErr_DoubleNAT) printf("Error code %d\n", errorCode);
@@ -711,7 +766,8 @@
                snprintf(addr, sizeof(addr), "%d.%d.%d.%d", digits[0], digits[1], digits[2], digits[3]);
                printf("%-4d %-20s %-15d %-15d %-15d %-6d%s\n", ifIndex, addr, protocol, ntohs(privatePort), ntohs(publicPort), ttl, errorCode == kDNSServiceErr_DoubleNAT ? " Double NAT" : "");
                }
-       fflush(stdout);
+
+       if (!(flags & kDNSServiceFlagsMoreComing)) fflush(stdout);
        }
 #endif
 
@@ -722,7 +778,8 @@
        char addr[256] = "";
        (void) sdref;
        (void) context;
-       
+       EXIT_IF_LIBDISPATCH_FATAL_ERROR(errorCode);
+
        if (num_printed++ == 0) printf("Timestamp     A/R Flags if %-25s %-44s %s\n", "Hostname", "Address", "TTL");
        printtimestamp();
 
@@ -759,6 +816,26 @@
 // The main test function
 
 static void HandleEvents(void)
+#if _DNS_SD_LIBDISPATCH
+       {
+       main_queue = dispatch_get_main_queue();
+       if (client)  DNSServiceSetDispatchQueue(client, main_queue);
+       if (client_pa)  DNSServiceSetDispatchQueue(client_pa, main_queue);
+       if (operation == 'A' || operation == 'U' || operation == 'N')
+               {
+               timer_source = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, main_queue);
+               if (timer_source)
+                       {
+                       // Start the timer "timeout" seconds into the future and repeat it every "timeout" seconds
+                       dispatch_source_set_timer(timer_source, dispatch_time(DISPATCH_TIME_NOW, (uint64_t)timeOut * NSEC_PER_SEC),
+                               (uint64_t)timeOut * NSEC_PER_SEC, 0);
+                       dispatch_source_set_event_handler(timer_source, ^{myTimerCallBack();});
+                       dispatch_resume(timer_source);
+                       }
+               }
+       dispatch_main();
+       }
+#else
        {
        int dns_sd_fd  = client    ? DNSServiceRefSockFD(client   ) : -1;
        int dns_sd_fd2 = client_pa ? DNSServiceRefSockFD(client_pa) : -1;
@@ -801,6 +878,7 @@
                        }
                }
        }
+#endif
 
 static int getfirstoption(int argc, char **argv, const char *optstr, int *pOptInd)
 // Return the recognized option in optstr and the option index of the next arg.
@@ -832,9 +910,10 @@
        char *name = (char *)context;
        
        (void)service;  // Unused
-       (void)rec;      // Unused
+       (void)rec;              // Unused
        (void)flags;    // Unused
-       
+       EXIT_IF_LIBDISPATCH_FATAL_ERROR(errorCode);
+
        printtimestamp();
        printf("Got a reply for record %s: ", name);
 
@@ -846,28 +925,26 @@
                }
        if (!(flags & kDNSServiceFlagsMoreComing)) fflush(stdout);
        // DNSServiceRemoveRecord(service, rec, 0); to test record removal
+
+#if 0  // To test updating of individual records registered via DNSServiceRegisterRecord
+       if (!errorCode)
+               {
+               int x = 0x11111111;
+               printf("Updating\n");
+               DNSServiceUpdateRecord(service, rec, 0, sizeof(x), &x, 0);
+               }
+#endif
+
+       if (!(flags & kDNSServiceFlagsMoreComing)) fflush(stdout);
        }
 
-static unsigned long getip(const char *const name)
+static void getip(const char *const name, struct sockaddr_storage *result)
        {
-       unsigned long ip = 0;
-       struct addrinfo hints;
        struct addrinfo *addrs = NULL;
-
-       memset(&hints, 0, sizeof(hints));
-       hints.ai_family = AF_INET;
-       
-       if (getaddrinfo(name, NULL, &hints, &addrs) == 0)
-               {
-               ip = ((struct sockaddr_in*) addrs->ai_addr)->sin_addr.s_addr;
-               }
-
-       if (addrs)
-               {
-               freeaddrinfo(addrs);
-               }
-
-       return(ip);
+       int err = getaddrinfo(name, NULL, NULL, &addrs);
+       if (err) fprintf(stderr, "getaddrinfo error %d for %s", err, name);
+       else memcpy(result, addrs->ai_addr, SA_LEN(addrs->ai_addr));
+       if (addrs) freeaddrinfo(addrs);
        }
 
 static DNSServiceErrorType RegisterProxyAddressRecord(DNSServiceRef sdref, const char *host, const char *ip)
@@ -876,10 +953,15 @@
        // On the Win32 platform, WinSock must be initialized for getip() to succeed.
        // Any DNSService* call will initialize WinSock for us, so we make sure
        // DNSServiceCreateConnection() is called before getip() is.
-       unsigned long addr = getip(ip);
-       return(DNSServiceRegisterRecord(sdref, &record, kDNSServiceFlagsUnique, opinterface, host,
-               kDNSServiceType_A, kDNSServiceClass_IN, sizeof(addr), &addr, 240, MyRegisterRecordCallback, (void*)host));
-       // Note, should probably add support for creating proxy AAAA records too, one day
+       struct sockaddr_storage hostaddr;



Home | Main Index | Thread Index | Old Index