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 latest



details:   https://anonhg.NetBSD.org/src/rev/0b842e6bfd63
branches:  trunk
changeset: 830098:0b842e6bfd63
user:      christos <christos%NetBSD.org@localhost>
date:      Sun Feb 25 19:25:33 2018 +0000

description:
import latest

diffstat:

 external/apache2/mDNSResponder/dist/.gitignore          |    7 +
 external/apache2/mDNSResponder/dist/Clients/dnssdutil.c |  363 ++++++++++++---
 2 files changed, 280 insertions(+), 90 deletions(-)

diffs (truncated from 614 to 300 lines):

diff -r 22808bd76d69 -r 0b842e6bfd63 external/apache2/mDNSResponder/dist/.gitignore
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/external/apache2/mDNSResponder/dist/.gitignore    Sun Feb 25 19:25:33 2018 +0000
@@ -0,0 +1,7 @@
+mDNSMacOSX/*.xcodeproj/project.xcworkspace
+mDNSMacOSX/*.xcodeproj/xcuserdata
+.svn
+build
+*~.m
+*~.c
+*~.h
diff -r 22808bd76d69 -r 0b842e6bfd63 external/apache2/mDNSResponder/dist/Clients/dnssdutil.c
--- a/external/apache2/mDNSResponder/dist/Clients/dnssdutil.c   Sun Feb 25 19:22:41 2018 +0000
+++ b/external/apache2/mDNSResponder/dist/Clients/dnssdutil.c   Sun Feb 25 19:25:33 2018 +0000
@@ -19,6 +19,7 @@
 #include <dns_sd_private.h>
 
 #if( TARGET_OS_DARWIN )
+       #include <dnsinfo.h>
        #include <libproc.h>
        #include <sys/proc_info.h>
 #endif
@@ -348,7 +349,7 @@
        ConnectionOptions(),
        BooleanOption( 'o', "oneshot",          &gQueryRecord_OneShot,                  "Finish after first set of results." ),
        IntegerOption( 'l', "timeLimit",        &gQueryRecord_TimeLimitSecs,    "seconds", "Maximum duration of the query record operation. Use '0' for no time limit.", false ),
-       BooleanOption( 'r', "raw",                      &gQueryRecord_RawRData,                 "Show record data as a hexdump." ),
+       BooleanOption(  0 , "raw",                      &gQueryRecord_RawRData,                 "Show record data as a hexdump." ),
        
        ConnectionSection(),
        CLI_OPTION_END()
@@ -502,18 +503,49 @@
 //     getaddrinfo-POSIX Command Options
 //===========================================================================================================================
 
-static const char *            gGAIPOSIX_Name          = NULL;
-static const char *            gGAIPOSIX_Family        = NULL;
+static const char *            gGAIPOSIX_HostName                      = NULL;
+static const char *            gGAIPOSIX_ServName                      = NULL;
+static const char *            gGAIPOSIX_Family                        = NULL;
+static int                             gGAIPOSIXFlag_AddrConfig        = false;
+static int                             gGAIPOSIXFlag_All                       = false;
+static int                             gGAIPOSIXFlag_CanonName         = false;
+static int                             gGAIPOSIXFlag_NumericHost       = false;
+static int                             gGAIPOSIXFlag_NumericServ       = false;
+static int                             gGAIPOSIXFlag_Passive           = false;
+static int                             gGAIPOSIXFlag_V4Mapped          = false;
+#if( defined( AI_V4MAPPED_CFG ) )
+static int                             gGAIPOSIXFlag_V4MappedCFG       = false;
+#endif
+#if( defined( AI_DEFAULT ) )
+static int                             gGAIPOSIXFlag_Default           = false;
+#endif
 
 static CLIOption               kGetAddrInfoPOSIXOpts[] =
 {
-       StringOption(   'n', "name",    &gGAIPOSIX_Name,        "domain name", "Domain name to resolve.", true ),
-       StringOptionEx( 'f', "family",  &gGAIPOSIX_Family,      "address family", "Address family to pass to getaddrinfo().", false,
-               "The address family value determines which value to use for the ai_family element of the hints struct addrinfo\n"
-               "argument used when calling getaddrinfo().\n"
+       StringOption(   'n', "hostname",                        &gGAIPOSIX_HostName,            "hostname", "Domain name to resolve or an IPv4 or IPv6 address.", true ),
+       StringOption(   's', "servname",                        &gGAIPOSIX_ServName,            "servname", "Port number in decimal or service name from services(5).", false ),
+       
+       CLI_OPTION_GROUP( "Hints " ),
+       StringOptionEx( 'f', "family",                          &gGAIPOSIX_Family,                      "address family", "Address family to use for hints ai_family field.", false,
                "\n"
                "Possible address family values are 'inet' for AF_INET, 'inet6' for AF_INET6, or 'unspec' for AF_UNSPEC. If no\n"
-               "address family is specified, then AF_UNSPEC is used.\n" ),
+               "address family is specified, then AF_UNSPEC is used.\n"
+               "\n" ),
+       BooleanOption(   0 , "flag-addrconfig",         &gGAIPOSIXFlag_AddrConfig,      "In hints ai_flags field, set AI_ADDRCONFIG." ),
+       BooleanOption(   0 , "flag-all",                        &gGAIPOSIXFlag_All,                     "In hints ai_flags field, set AI_ALL." ),
+       BooleanOption(   0 , "flag-canonname",          &gGAIPOSIXFlag_CanonName,       "In hints ai_flags field, set AI_CANONNAME." ),
+       BooleanOption(   0 , "flag-numerichost",        &gGAIPOSIXFlag_NumericHost,     "In hints ai_flags field, set AI_NUMERICHOST." ),
+       BooleanOption(   0 , "flag-numericserv",        &gGAIPOSIXFlag_NumericServ,     "In hints ai_flags field, set AI_NUMERICSERV." ),
+       BooleanOption(   0 , "flag-passive",            &gGAIPOSIXFlag_Passive,         "In hints ai_flags field, set AI_PASSIVE." ),
+       BooleanOption(   0 , "flag-v4mapped",           &gGAIPOSIXFlag_V4Mapped,        "In hints ai_flags field, set AI_V4MAPPED." ),
+#if( defined( AI_V4MAPPED_CFG ) )
+       BooleanOption(   0 , "flag-v4mappedcfg",        &gGAIPOSIXFlag_V4MappedCFG,     "In hints ai_flags field, set AI_V4MAPPED_CFG." ),
+#endif
+#if( defined( AI_DEFAULT ) )
+       BooleanOption(   0 , "flag-default",            &gGAIPOSIXFlag_Default,         "In hints ai_flags field, set AI_DEFAULT." ),
+#endif
+       
+       CLI_SECTION( "Notes", "See getaddrinfo(3) man page for more details.\n" ),
        CLI_OPTION_END()
 };
 
@@ -611,15 +643,21 @@
 static int                     gDNSQuery_RawRData              = false;
 static int                     gDNSQuery_Verbose               = false;
 
+#if( TARGET_OS_DARWIN )
+       #define kDNSQueryServerOptionIsRequired         false
+#else
+       #define kDNSQueryServerOptionIsRequired         true
+#endif
+
 static CLIOption               kDNSQueryOpts[] =
 {
        StringOption(  'n', "name",                     &gDNSQuery_Name,                        "name", "Question name (QNAME) to put in DNS query message.", true ),
        StringOption(  't', "type",                     &gDNSQuery_Type,                        "type", "Question type (QTYPE) to put in DNS query message. Default value is 'A'.", false ),
-       StringOption(  's', "server",           &gDNSQuery_Server,                      "IP address", "DNS server's IPv4 or IPv6 address.", true ),
+       StringOption(  's', "server",           &gDNSQuery_Server,                      "IP address", "DNS server's IPv4 or IPv6 address.", kDNSQueryServerOptionIsRequired ),
        IntegerOption( 'l', "timeLimit",        &gDNSQuery_TimeLimitSecs,       "seconds", "Specifies query time limit. Use '-1' for no limit and '0' to exit immediately after sending.", false ),
        BooleanOption(  0 , "tcp",                      &gDNSQuery_UseTCP,                      "Send the DNS query via TCP instead of UDP." ),
        IntegerOption( 'f', "flags",            &gDNSQuery_Flags,                       "flags", "16-bit value for DNS header flags/codes field. Default value is 0x0100 (Recursion Desired).", false ),
-       BooleanOption( 'r', "raw",                      &gDNSQuery_RawRData,            "Present record data as a hexdump." ),
+       BooleanOption(  0 , "raw",                      &gDNSQuery_RawRData,            "Present record data as a hexdump." ),
        BooleanOption( 'v', "verbose",          &gDNSQuery_Verbose,                     "Prints the DNS message to be sent to the server." ),
        CLI_OPTION_END()
 };
@@ -646,7 +684,7 @@
        StringOption(  't', "type",                     &gDNSCrypt_Type,                        "type", "Question type (QTYPE) to put in DNS query message.", true ),
        StringOption(  's', "server",           &gDNSCrypt_Server,                      "IP address", "DNS server's IPv4 or IPv6 address.", true ),
        IntegerOption( 'l', "timeLimit",        &gDNSCrypt_TimeLimitSecs,       "seconds", "Specifies query time limit. Use '-1' for no time limit and '0' to exit immediately after sending.", false ),
-       BooleanOption( 'r', "raw",                      &gDNSCrypt_RawRData,            "Present record data as a hexdump." ),
+       BooleanOption(  0 , "raw",                      &gDNSCrypt_RawRData,            "Present record data as a hexdump." ),
        BooleanOption( 'v', "verbose",          &gDNSCrypt_Verbose,                     "Prints the DNS message to be sent to the server." ),
        CLI_OPTION_END()
 };
@@ -664,6 +702,7 @@
 static int                     gMDNSQuery_UseIPv4              = false;
 static int                     gMDNSQuery_UseIPv6              = false;
 static int                     gMDNSQuery_AllResponses = false;
+static int                     gMDNSQuery_ReceiveSecs  = 1;
 
 static CLIOption               kMDNSQueryOpts[] =
 {
@@ -672,10 +711,11 @@
        StringOption(  't', "type",                     &gMDNSQuery_Type,                       "type", "Question type (QTYPE) to put in mDNS message.", true ),
        IntegerOption( 'p', "sourcePort",       &gMDNSQuery_SourcePort,         "port number", "UDP source port to use when sending mDNS messages. Default is 5353 for QM questions.", false ),
        BooleanOption( 'u', "QU",                       &gMDNSQuery_IsQU,                       "Set the unicast-response bit, i.e., send a QU question." ),
-       BooleanOption( 'r', "raw",                      &gMDNSQuery_RawRData,           "Present record data as a hexdump." ),
+       BooleanOption(  0 , "raw",                      &gMDNSQuery_RawRData,           "Present record data as a hexdump." ),
        BooleanOption(  0 , "ipv4",                     &gMDNSQuery_UseIPv4,            "Use IPv4." ),
        BooleanOption(  0 , "ipv6",                     &gMDNSQuery_UseIPv6,            "Use IPv6." ),
-       BooleanOption( 'a', "allResponses",     &gMDNSQuery_AllResponses,       "Print all responses." ),
+       BooleanOption( 'a', "allResponses",     &gMDNSQuery_AllResponses,       "Print all received mDNS messages, not just those containing answers." ),
+       IntegerOption( 'r', "receiveTime",      &gMDNSQuery_ReceiveSecs,        "seconds", "Amount of time to spend receiving messages after the query is sent. The default is one second. Use -1 for 
unlimited time.", false ),
        CLI_OPTION_END()
 };
 
@@ -931,6 +971,9 @@
 static void                    SocketContextCancelHandler( void *inContext );
 static OSStatus                StringToInt32( const char *inString, int32_t *outValue );
 static OSStatus                StringToUInt32( const char *inString, uint32_t *outValue );
+#if( TARGET_OS_DARWIN )
+static OSStatus                GetDefaultDNSServer( sockaddr_ip *outAddr );
+#endif
 
 #define AddRmvString( X )              ( ( (X) & kDNSServiceFlagsAdd ) ? "Add" : "Rmv" )
 #define Unused( X )                            (void)(X)
@@ -1686,7 +1729,7 @@
        Boolean                         printedHeader;  // True if the results header was printed.
        Boolean                         oneShotMode;    // True if command is done after the first set of results (one-shot mode).
        Boolean                         gotRecord;              // True if in one-shot mode and received at least one record of the desired type.
-       Boolean                         printRawRData;  // True if RDATA results are not to be formatted.
+       Boolean                         printRawRData;  // True if RDATA results are not to be formatted when printed.
        
 }      QueryRecordContext;
 
@@ -2753,15 +2796,17 @@
 
 static void    GetAddrInfoPOSIXCmd( void )
 {
-       OSStatus                                err;
-       struct addrinfo                 hints;
-       struct addrinfo *               addrInfo;
-       struct addrinfo *               addrInfoList = NULL;
-       int                                             addrCount;
-       char                                    time[ kTimestampBufLen ];
+       OSStatus                                        err;
+       struct addrinfo                         hints;
+       const struct addrinfo *         addrInfo;
+       struct addrinfo *                       addrInfoList = NULL;
+       char                                            time[ kTimestampBufLen ];
        
        memset( &hints, 0, sizeof( hints ) );
        hints.ai_socktype = SOCK_STREAM;
+       
+       // Set hints address family.
+       
        if( !gGAIPOSIX_Family )                                                                         hints.ai_family = AF_UNSPEC;
        else if( strcasecmp( gGAIPOSIX_Family, "inet" ) == 0 )          hints.ai_family = AF_INET;
        else if( strcasecmp( gGAIPOSIX_Family, "inet6" ) == 0 )         hints.ai_family = AF_INET6;
@@ -2773,32 +2818,66 @@
                goto exit;
        }
        
-       FPrintF( stdout, "Name:           %s\n", gGAIPOSIX_Name );
-       FPrintF( stdout, "Address family: %s\n", AddressFamilyStr( hints.ai_family ) );
+       // Set hints flags.
+       
+       if( gGAIPOSIXFlag_AddrConfig )  hints.ai_flags |= AI_ADDRCONFIG;
+       if( gGAIPOSIXFlag_All )                 hints.ai_flags |= AI_ALL;
+       if( gGAIPOSIXFlag_CanonName )   hints.ai_flags |= AI_CANONNAME;
+       if( gGAIPOSIXFlag_NumericHost ) hints.ai_flags |= AI_NUMERICHOST;
+       if( gGAIPOSIXFlag_NumericServ ) hints.ai_flags |= AI_NUMERICSERV;
+       if( gGAIPOSIXFlag_Passive )             hints.ai_flags |= AI_PASSIVE;
+       if( gGAIPOSIXFlag_V4Mapped )    hints.ai_flags |= AI_V4MAPPED;
+#if( defined( AI_V4MAPPED_CFG ) )
+       if( gGAIPOSIXFlag_V4MappedCFG ) hints.ai_flags |= AI_V4MAPPED_CFG;
+#endif
+#if( defined( AI_DEFAULT ) )
+       if( gGAIPOSIXFlag_Default )             hints.ai_flags |= AI_DEFAULT;
+#endif
+       
+       // Print prologue.
+       
+       FPrintF( stdout, "Hostname:       %s\n",        gGAIPOSIX_HostName );
+       FPrintF( stdout, "Servname:       %s\n",        gGAIPOSIX_ServName );
+       FPrintF( stdout, "Address family: %s\n",        AddressFamilyStr( hints.ai_family ) );
+       FPrintF( stdout, "Flags:          0x%X < ",     hints.ai_flags );
+       if( hints.ai_flags & AI_NUMERICSERV )   FPrintF( stdout, "AI_NUMERICSERV " );
+       if( hints.ai_flags & AI_V4MAPPED )              FPrintF( stdout, "AI_V4MAPPED " );
+       if( hints.ai_flags & AI_ADDRCONFIG )    FPrintF( stdout, "AI_ADDRCONFIG " );
+#if( defined( AI_V4MAPPED_CFG ) )
+       if( hints.ai_flags & AI_V4MAPPED_CFG )  FPrintF( stdout, "AI_V4MAPPED_CFG " );
+#endif
+       if( hints.ai_flags & AI_ALL )                   FPrintF( stdout, "AI_ALL " );
+       if( hints.ai_flags & AI_NUMERICHOST )   FPrintF( stdout, "AI_NUMERICHOST " );
+       if( hints.ai_flags & AI_CANONNAME )             FPrintF( stdout, "AI_CANONNAME " );
+       if( hints.ai_flags & AI_PASSIVE )               FPrintF( stdout, "AI_PASSIVE " );
+       FPrintF( stdout, ">\n" );
        FPrintF( stdout, "Start time:     %s\n", GetTimestampStr( time ) );
        FPrintF( stdout, "---\n" );
        
-       err = getaddrinfo( gGAIPOSIX_Name, NULL, &hints, &addrInfoList );
-       FPrintF( stdout, "%s:\n", GetTimestampStr( time ) );
+       // Call getaddrinfo().
+       
+       err = getaddrinfo( gGAIPOSIX_HostName, gGAIPOSIX_ServName, &hints, &addrInfoList );
+       GetTimestampStr( time );
        if( err )
        {
-               FPrintF( stderr, "getaddrinfo() error %#m: %s.\n", err, gai_strerror( err ) );
-               goto exit;
-       }
-       
-       addrCount = 0;
-       for( addrInfo = addrInfoList; addrInfo; addrInfo = addrInfo->ai_next ) { ++addrCount; }
-       
-       FPrintF( stdout, "Addresses (%d total):\n", addrCount );
-       for( addrInfo = addrInfoList; addrInfo; addrInfo = addrInfo->ai_next )
-       {
-               FPrintF( stdout, "%##a\n", addrInfo->ai_addr );
-       }
+               FPrintF( stderr, "Error %#m: %s.\n", err, gai_strerror( err ) );
+       }
+       else
+       {
+               int             addrCount = 0;
+               
+               for( addrInfo = addrInfoList; addrInfo; addrInfo = addrInfo->ai_next ) { ++addrCount; }
+               
+               FPrintF( stdout, "Addresses (%d total):\n", addrCount );
+               for( addrInfo = addrInfoList; addrInfo; addrInfo = addrInfo->ai_next )
+               {
+                       FPrintF( stdout, "%##a\n", addrInfo->ai_addr );
+               }
+       }
+       FPrintF( stdout, "---\n" );
+       FPrintF( stdout, "End time:       %s\n", time );
        
 exit:
-       FPrintF( stdout, "---\n" );
-       FPrintF( stdout, "End time:       %s\n", GetTimestampStr( time ) );
-       
        if( addrInfoList ) freeaddrinfo( addrInfoList );
        if( err ) exit( 1 );
 }
@@ -4570,7 +4649,7 @@
        
        if( gDNSQuery_TimeLimitSecs < -1 )
        {
-               FPrintF( stdout, "Invalid wait period: %d seconds.\n", gDNSQuery_TimeLimitSecs );
+               FPrintF( stdout, "Invalid time limit: %d seconds.\n", gDNSQuery_TimeLimitSecs );
                err = kParamErr;
                goto exit;
        }
@@ -4593,8 +4672,20 @@
        context->useTCP                 = gDNSQuery_UseTCP       ? true : false;
        context->printRawRData  = gDNSQuery_RawRData ? true : false;
        
-       err = StringToSockAddr( gDNSQuery_Server, &context->serverAddr, sizeof( context->serverAddr ), NULL );
-       require_noerr( err, exit );
+#if( TARGET_OS_DARWIN )
+       if( gDNSQuery_Server )
+#endif
+       {
+               err = StringToSockAddr( gDNSQuery_Server, &context->serverAddr, sizeof( context->serverAddr ), NULL );
+               require_noerr( err, exit );
+       }
+#if( TARGET_OS_DARWIN )
+       else
+       {
+               err = GetDefaultDNSServer( &context->serverAddr );
+               require_noerr( err, exit );
+       }



Home | Main Index | Thread Index | Old Index