summaryrefslogtreecommitdiffstats
path: root/mDNSResponder/Clients
diff options
context:
space:
mode:
authorSebastian Huber <sebastian.huber@embedded-brains.de>2018-09-19 08:52:21 +0200
committerSebastian Huber <sebastian.huber@embedded-brains.de>2018-09-20 11:23:32 +0200
commitf761b290f135957f47e1c9af71b4a81c76c32b48 (patch)
tree2b7d273db4ff2388867efec5ad432fa49cd4047e /mDNSResponder/Clients
parentmDNSResponder: Update to v576.30.4 (diff)
downloadrtems-libbsd-f761b290f135957f47e1c9af71b4a81c76c32b48.tar.bz2
mDNSResponder: Update to v625.41.2
The sources can be obtained via: https://opensource.apple.com/tarballs/mDNSResponder/mDNSResponder-625.41.2.tar.gz Update #3522.
Diffstat (limited to 'mDNSResponder/Clients')
-rw-r--r--mDNSResponder/Clients/ClientCommon.c6
-rw-r--r--mDNSResponder/Clients/dns-sd.c52
-rw-r--r--mDNSResponder/Clients/dnsctl.c86
3 files changed, 57 insertions, 87 deletions
diff --git a/mDNSResponder/Clients/ClientCommon.c b/mDNSResponder/Clients/ClientCommon.c
index 68f354cc..cb59e7b9 100644
--- a/mDNSResponder/Clients/ClientCommon.c
+++ b/mDNSResponder/Clients/ClientCommon.c
@@ -1,8 +1,8 @@
/* -*- Mode: C; tab-width: 4 -*-
*
- * Copyright (c) 2008 Apple Inc. All rights reserved.
+ * Copyright (c) 2008-2011 Apple Inc. All rights reserved.
*
- * Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple Computer, Inc.
+ * Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple Inc.
* ("Apple") in consideration of your agreement to the following terms, and your
* use, installation, modification or redistribution of this Apple software
* constitutes acceptance of these terms. If you do not agree with these terms,
@@ -16,7 +16,7 @@
* the Apple Software in its entirety and without modifications, you must retain
* this notice and the following text and disclaimers in all such redistributions of
* the Apple Software. Neither the name, trademarks, service marks or logos of
- * Apple Computer, Inc. may be used to endorse or promote products derived from the
+ * Apple Inc. may be used to endorse or promote products derived from the
* Apple Software without specific prior written permission from Apple. Except as
* expressly stated in this notice, no other rights or licenses, express or implied,
* are granted by Apple herein, including but not limited to any patent rights that
diff --git a/mDNSResponder/Clients/dns-sd.c b/mDNSResponder/Clients/dns-sd.c
index 9acf41e5..9469d24d 100644
--- a/mDNSResponder/Clients/dns-sd.c
+++ b/mDNSResponder/Clients/dns-sd.c
@@ -1,8 +1,8 @@
/* -*- Mode: C; tab-width: 4 -*-
*
- * Copyright (c) 2002-2013 Apple Inc. All rights reserved.
+ * Copyright (c) 2002-2015 Apple Inc. All rights reserved.
*
- * Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple Computer, Inc.
+ * Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple Inc.
* ("Apple") in consideration of your agreement to the following terms, and your
* use, installation, modification or redistribution of this Apple software
* constitutes acceptance of these terms. If you do not agree with these terms,
@@ -16,7 +16,7 @@
* the Apple Software in its entirety and without modifications, you must retain
* this notice and the following text and disclaimers in all such redistributions of
* the Apple Software. Neither the name, trademarks, service marks or logos of
- * Apple Computer, Inc. may be used to endorse or promote products derived from the
+ * Apple Inc. may be used to endorse or promote products derived from the
* Apple Software without specific prior written permission from Apple. Except as
* expressly stated in this notice, no other rights or licenses, express or implied,
* are granted by Apple herein, including but not limited to any patent rights that
@@ -57,14 +57,6 @@
// 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()
@@ -185,14 +177,6 @@ static const char kFilePathSep = '/';
#include <dispatch/private.h>
#endif
-// The "+0" is to cope with the case where _DNS_SD_H is defined but empty (e.g. on Mac OS X 10.4 and earlier)
-#if _DNS_SD_H+0 >= 116
-#define HAS_NAT_PMP_API 1
-#define HAS_ADDRINFO_API 1
-#else
-#define kDNSServiceFlagsReturnIntermediates 0
-#endif
-
//*************************************************************************************************************
// Globals
@@ -421,7 +405,6 @@ done:
#endif //_DNS_SD_LIBDISPATCH
}
-#if HAS_NAT_PMP_API | HAS_ADDRINFO_API
static DNSServiceProtocol GetProtocol(const char *s)
{
if (!strcasecmp(s, "v4" )) return(kDNSServiceProtocol_IPv4);
@@ -434,7 +417,6 @@ static DNSServiceProtocol GetProtocol(const char *s)
else if (!strcasecmp(s, "tcpudp" )) return(kDNSServiceProtocol_UDP | kDNSServiceProtocol_TCP);
else return(atoi(s));
}
-#endif
//*************************************************************************************************************
@@ -494,18 +476,14 @@ static void print_usage(const char *arg0, int print_all)
fprintf(stderr, "%s -q <name> <rrtype> <rrclass> (Generic query for any record type)\n", arg0);
fprintf(stderr, "%s -D <name> <rrtype> <rrclass>(Validate query for any record type with DNSSEC)\n", arg0);
fprintf(stderr, "%s -Z <Type> <Domain> (Output results in Zone File format)\n", arg0);
-#if HAS_ADDRINFO_API
fprintf(stderr, "%s -G v4/v6/v4v6 <name> (Get address information for hostname)\n", arg0);
fprintf(stderr, "%s -g v4/v6/v4v6 <name> (Validate address info for hostname with DNSSEC)\n", arg0);
-#endif
fprintf(stderr, "%s -V (Get version of currently running daemon / system service)\n", arg0);
if (print_all) //Print all available options for dns-sd tool
{
fprintf(stderr, "%s -C <FQDN> <rrtype> <rrclass> (Query; reconfirming each result)\n", arg0);
-#if HAS_NAT_PMP_API
fprintf(stderr, "%s -X udp/tcp/udptcp <IntPort> <ExtPort> <TTL> (NAT Port Mapping)\n", arg0);
-#endif
fprintf(stderr, "%s -A (Test Adding/Updating/Deleting a record)\n", arg0);
fprintf(stderr, "%s -U (Test updating a TXT record)\n", arg0);
fprintf(stderr, "%s -N (Test adding a large NULL record)\n", arg0);
@@ -1041,15 +1019,15 @@ static void DNSSD_API qr_reply(DNSServiceRef sdref, const DNSServiceFlags flags,
case kDNSServiceType_CNAME:
case kDNSServiceType_PTR:
case kDNSServiceType_DNAME:
- p += snprintd(p, sizeof(rdb), &rd);
+ snprintd(p, sizeof(rdb), &rd);
break;
case kDNSServiceType_SOA:
p += snprintd(p, rdb + sizeof(rdb) - p, &rd); // mname
p += snprintf(p, rdb + sizeof(rdb) - p, " ");
p += snprintd(p, rdb + sizeof(rdb) - p, &rd); // rname
- p += snprintf(p, rdb + sizeof(rdb) - p, " Ser %d Ref %d Ret %d Exp %d Min %d",
- ntohl(((uint32_t*)rd)[0]), ntohl(((uint32_t*)rd)[1]), ntohl(((uint32_t*)rd)[2]), ntohl(((uint32_t*)rd)[3]), ntohl(((uint32_t*)rd)[4]));
+ snprintf(p, rdb + sizeof(rdb) - p, " Ser %d Ref %d Ret %d Exp %d Min %d",
+ ntohl(((uint32_t*)rd)[0]), ntohl(((uint32_t*)rd)[1]), ntohl(((uint32_t*)rd)[2]), ntohl(((uint32_t*)rd)[3]), ntohl(((uint32_t*)rd)[4]));
break;
case kDNSServiceType_AAAA:
@@ -1060,9 +1038,9 @@ static void DNSSD_API qr_reply(DNSServiceRef sdref, const DNSServiceFlags flags,
case kDNSServiceType_SRV:
p += snprintf(p, rdb + sizeof(rdb) - p, "%d %d %d ", // priority, weight, port
- ntohs(*(unsigned short*)rd), ntohs(*(unsigned short*)(rd+2)), ntohs(*(unsigned short*)(rd+4)));
+ ntohs(*(unsigned short*)rd), ntohs(*(unsigned short*)(rd+2)), ntohs(*(unsigned short*)(rd+4)));
rd += 6;
- p += snprintd(p, rdb + sizeof(rdb) - p, &rd); // target host
+ snprintd(p, rdb + sizeof(rdb) - p, &rd); // target host
break;
case kDNSServiceType_DS:
@@ -1124,7 +1102,6 @@ static void DNSSD_API qr_reply(DNSServiceRef sdref, const DNSServiceFlags flags,
fflush(stdout);
}
-#if HAS_NAT_PMP_API
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
@@ -1146,9 +1123,7 @@ static void DNSSD_API port_mapping_create_reply(DNSServiceRef sdref, DNSServiceF
if (!(flags & kDNSServiceFlagsMoreComing)) fflush(stdout);
}
-#endif
-#if HAS_ADDRINFO_API
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)
{
char *op = (flags & kDNSServiceFlagsAdd) ? "Add" : "Rmv";
@@ -1218,7 +1193,6 @@ static void DNSSD_API addrinfo_reply(DNSServiceRef sdref, const DNSServiceFlags
if (!(flags & kDNSServiceFlagsMoreComing))
fflush(stdout);
}
-#endif
//*************************************************************************************************************
// The main test function
@@ -1362,6 +1336,7 @@ static DNSServiceErrorType RegisterProxyAddressRecord(DNSServiceRef sdref, const
// Any DNSService* call will initialize WinSock for us, so we make sure
// DNSServiceCreateConnection() is called before getip() is.
struct sockaddr_storage hostaddr;
+ memset(&hostaddr, 0, sizeof(hostaddr));
getip(ip, &hostaddr);
flags |= kDNSServiceFlagsUnique;
if (hostaddr.ss_family == AF_INET)
@@ -1553,12 +1528,8 @@ int main(int argc, char **argv)
if (argc < 2) goto Fail; // Minimum command line is the command name and one argument
operation = getfirstoption(argc, argv, "EFBZLlRPQqCAUNTMISVHhD"
- #if HAS_NAT_PMP_API
"X"
- #endif
- #if HAS_ADDRINFO_API
"Gg"
- #endif
, &opi);
if (operation == -1) goto Fail;
@@ -1592,6 +1563,7 @@ int main(int argc, char **argv)
if (dom[0] == '.' && dom[1] == 0) dom[0] = 0; // We allow '.' on the command line as a synonym for empty string
printf("Browsing for %s%s%s\n", typ, dom[0] ? "." : "", dom);
err = DNSServiceCreateConnection(&client);
+ if (err) { fprintf(stderr, "DNSServiceCreateConnection returned %d\n", err); return(err); }
sc1 = client;
err = DNSServiceBrowse(&sc1, kDNSServiceFlagsShareConnection, opinterface, typ, dom, zonedata_browse, NULL);
break;
@@ -1694,7 +1666,6 @@ int main(int argc, char **argv)
break;
}
-#if HAS_NAT_PMP_API
case 'X': {
if (argc == opi) // If no arguments, just fetch IP address
err = DNSServiceNATPortMappingCreate(&client, 0, 0, 0, 0, 0, 0, port_mapping_create_reply, NULL);
@@ -1711,9 +1682,7 @@ int main(int argc, char **argv)
else goto Fail;
break;
}
-#endif
-#if HAS_ADDRINFO_API
case 'g':
case 'G': {
flags |= kDNSServiceFlagsReturnIntermediates;
@@ -1731,7 +1700,6 @@ int main(int argc, char **argv)
err = DNSServiceGetAddrInfo(&client, flags, opinterface, GetProtocol(argv[opi+0]), argv[opi+1], addrinfo_reply, NULL);
break;
}
-#endif
case 'S': {
Opaque16 registerPort = { { 0x23, 0x45 } }; // 9029 decimal
diff --git a/mDNSResponder/Clients/dnsctl.c b/mDNSResponder/Clients/dnsctl.c
index bb2a0716..f10f2259 100644
--- a/mDNSResponder/Clients/dnsctl.c
+++ b/mDNSResponder/Clients/dnsctl.c
@@ -1,6 +1,6 @@
/* -*- Mode: C; tab-width: 4 -*-
*
- * Copyright (c) 2012 Apple Inc. All rights reserved.
+ * Copyright (c) 2012-2015 Apple Inc. All rights reserved.
*
* dnsctl.c
* Command-line tool using libdns_services.dylib
@@ -31,24 +31,24 @@ static DNSXConnRef ClientRef = NULL;
// Utility Funcs:
//*************************************************************************************************************
-static void printtimestamp(void)
+static void printtimestamp(void)
{
- struct tm tm;
- int ms;
+ struct tm tm;
+ int ms;
static char date[16];
static char new_date[16];
- struct timeval tv;
+ struct timeval tv;
gettimeofday(&tv, NULL);
localtime_r((time_t*)&tv.tv_sec, &tm);
ms = tv.tv_usec/1000;
strftime(new_date, sizeof(new_date), "%a %d %b %Y", &tm);
//display date only if it has changed
if (strncmp(date, new_date, sizeof(new_date)))
- {
+ {
printf("DATE: ---%s---\n", new_date);
- strncpy(date, new_date, sizeof(date));
- }
- printf("%2d:%02d:%02d.%03d ", tm.tm_hour, tm.tm_min, tm.tm_sec, ms);
+ strlcpy(date, new_date, sizeof(date));
+ }
+ printf("%2d:%02d:%02d.%03d ", tm.tm_hour, tm.tm_min, tm.tm_sec, ms);
}
static void print_usage(const char *arg0)
@@ -69,18 +69,18 @@ static void dnsproxy_reply(DNSXConnRef connRef, DNSXErrorType errCode)
printtimestamp();
switch (errCode)
{
- case kDNSX_NoError : printf(" SUCCESS \n"); break;
- case kDNSX_DictError : printf(" DICT ERROR \n"); break;
+ case kDNSX_NoError : printf(" SUCCESS \n");
+ break;
case kDNSX_DaemonNotRunning : printf(" NO DAEMON \n");
- DNSXRefDeAlloc(ClientRef); break;
- case kDNSX_Engaged : printf(" ENGAGED \n");
- DNSXRefDeAlloc(ClientRef); break;
+ DNSXRefDeAlloc(ClientRef); break;
+ case kDNSX_BadParam : printf(" BAD PARAMETER \n");
+ DNSXRefDeAlloc(ClientRef); break;
case kDNSX_UnknownErr :
- default : printf("UNKNOWN ERR \n");
- DNSXRefDeAlloc(ClientRef); break;
+ default : printf(" UNKNOWN ERR \n");
+ DNSXRefDeAlloc(ClientRef); break;
}
fflush(NULL);
-
+
}
//*************************************************************************************************************
@@ -88,40 +88,41 @@ static void dnsproxy_reply(DNSXConnRef connRef, DNSXErrorType errCode)
int main(int argc, char **argv)
{
DNSXErrorType err;
-
+
// Default i/p intf is lo0 and o/p intf is primary interface
IfIndex Ipintfs[MaxInputIf] = {1, 0, 0, 0, 0};
IfIndex Opintf = kDNSIfindexAny;
-
+
// Extract program name from argv[0], which by convention contains the path to this executable
- const char *a0 = strrchr(argv[0], kFilePathSep) + 1;
+ const char *a0 = strrchr(argv[0], kFilePathSep) + 1;
if (a0 == (const char *)1)
a0 = argv[0];
-
+
// Must run as root
- if (0 != geteuid())
- {
- fprintf(stderr, "%s MUST run as root!!\n", a0);
- exit(-1);
+ if (0 != geteuid())
+ {
+ fprintf(stderr, "%s MUST run as root!!\n", a0);
+ exit(-1);
}
if ((sizeof(argv) == 8))
printf("dnsctl running in 64-bit mode\n");
else if ((sizeof(argv) == 4))
printf("dnsctl running in 32-bit mode\n");
-
+
// expects atleast one argument
if (argc < 2)
goto Usage;
-
+
if ( !strcmp(argv[1], "-DP") || !strcmp(argv[1], "-dp") )
{
if (argc == 2)
{
printtimestamp();
- printf("Proceeding to Enable DNSProxy on mDNSResponder with Default Parameters\n");
+ printf("Enabling DNSProxy on mDNSResponder with Default Parameters\n");
dispatch_queue_t my_Q = dispatch_queue_create("com.apple.dnsctl.callback_queue", NULL);
err = DNSXEnableProxy(&ClientRef, kDNSProxyEnable, Ipintfs, Opintf, my_Q, dnsproxy_reply);
- }
+ if (err) fprintf(stderr, "DNSXEnableProxy returned %d\n", err);
+ }
else if (argc > 2)
{
argc--;
@@ -129,17 +130,17 @@ int main(int argc, char **argv)
if (!strcmp(argv[1], "-o"))
{
Opintf = if_nametoindex(argv[2]);
- if (!Opintf)
+ if (!Opintf)
Opintf = atoi(argv[2]);
- if (!Opintf)
- {
- fprintf(stderr, "Could not parse o/p interface [%s]: Passing default primary \n", argv[2]);
+ if (!Opintf)
+ {
+ fprintf(stderr, "Could not parse o/p interface [%s]: Passing default primary \n", argv[2]);
Opintf = kDNSIfindexAny;
}
argc -= 2;
argv += 2;
}
- if (argc > 2 && !strcmp(argv[1], "-i"))
+ if (argc > 2 && !strcmp(argv[1], "-i"))
{
int i;
argc--;
@@ -148,29 +149,30 @@ int main(int argc, char **argv)
{
Ipintfs[i] = if_nametoindex(argv[1]);
if (!Ipintfs[i])
- Ipintfs[i] = atoi(argv[1]);
+ Ipintfs[i] = atoi(argv[1]);
if (!Ipintfs[i])
{
- fprintf(stderr, "Could not parse i/p interface [%s]: Passing default lo0 \n", argv[2]);
+ fprintf(stderr, "Could not parse i/p interface [%s]: Passing default lo0 \n", argv[2]);
Ipintfs[i] = 1;
}
argc--;
argv++;
}
- }
+ }
printtimestamp();
- printf("Proceeding to Enable DNSProxy on mDNSResponder \n");
+ printf("Enabling DNSProxy on mDNSResponder \n");
dispatch_queue_t my_Q = dispatch_queue_create("com.apple.dnsctl.callback_queue", NULL);
- err = DNSXEnableProxy(&ClientRef, kDNSProxyEnable, Ipintfs, Opintf, my_Q, dnsproxy_reply);
+ err = DNSXEnableProxy(&ClientRef, kDNSProxyEnable, Ipintfs, Opintf, my_Q, dnsproxy_reply);
+ if (err) fprintf(stderr, "DNSXEnableProxy returned %d\n", err);
}
}
else
{
goto Usage;
}
-
- dispatch_main();
-
+
+ dispatch_main();
+
Usage:
print_usage(a0);
return 0;