xref: /titanic_52/usr/src/lib/libdns_sd/common/dns_sd.h (revision 5ffb0c9b03b5149ff4f5821a62be4a52408ada2a)
14b22b933Srs200217 /* -*- Mode: C; tab-width: 4 -*-
24b22b933Srs200217  *
3*5ffb0c9bSToomas Soome  * Copyright (c) 2003-2013 Apple Computer, Inc. All rights reserved.
44b22b933Srs200217  *
54b22b933Srs200217  * Redistribution and use in source and binary forms, with or without
64b22b933Srs200217  * modification, are permitted provided that the following conditions are met:
74b22b933Srs200217  *
84b22b933Srs200217  * 1.  Redistributions of source code must retain the above copyright notice,
94b22b933Srs200217  *     this list of conditions and the following disclaimer.
104b22b933Srs200217  * 2.  Redistributions in binary form must reproduce the above copyright notice,
114b22b933Srs200217  *     this list of conditions and the following disclaimer in the documentation
124b22b933Srs200217  *     and/or other materials provided with the distribution.
134b22b933Srs200217  * 3.  Neither the name of Apple Computer, Inc. ("Apple") nor the names of its
144b22b933Srs200217  *     contributors may be used to endorse or promote products derived from this
154b22b933Srs200217  *     software without specific prior written permission.
164b22b933Srs200217  *
174b22b933Srs200217  * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
184b22b933Srs200217  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
194b22b933Srs200217  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
204b22b933Srs200217  * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
214b22b933Srs200217  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
224b22b933Srs200217  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
234b22b933Srs200217  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
244b22b933Srs200217  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
254b22b933Srs200217  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
264b22b933Srs200217  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
274b22b933Srs200217  */
284b22b933Srs200217 
29*5ffb0c9bSToomas Soome 
30*5ffb0c9bSToomas Soome /*! @header     DNS Service Discovery
31*5ffb0c9bSToomas Soome  *
32*5ffb0c9bSToomas Soome  * @discussion  This section describes the functions, callbacks, and data structures
33*5ffb0c9bSToomas Soome  *              that make up the DNS Service Discovery API.
34*5ffb0c9bSToomas Soome  *
35*5ffb0c9bSToomas Soome  *              The DNS Service Discovery API is part of Bonjour, Apple's implementation
36*5ffb0c9bSToomas Soome  *              of zero-configuration networking (ZEROCONF).
37*5ffb0c9bSToomas Soome  *
38*5ffb0c9bSToomas Soome  *              Bonjour allows you to register a network service, such as a
39*5ffb0c9bSToomas Soome  *              printer or file server, so that it can be found by name or browsed
40*5ffb0c9bSToomas Soome  *              for by service type and domain. Using Bonjour, applications can
41*5ffb0c9bSToomas Soome  *              discover what services are available on the network, along with
42*5ffb0c9bSToomas Soome  *              all the information -- such as name, IP address, and port --
43*5ffb0c9bSToomas Soome  *              necessary to access a particular service.
44*5ffb0c9bSToomas Soome  *
45*5ffb0c9bSToomas Soome  *              In effect, Bonjour combines the functions of a local DNS server and
46*5ffb0c9bSToomas Soome  *              AppleTalk. Bonjour allows applications to provide user-friendly printer
47*5ffb0c9bSToomas Soome  *              and server browsing, among other things, over standard IP networks.
48*5ffb0c9bSToomas Soome  *              This behavior is a result of combining protocols such as multicast and
49*5ffb0c9bSToomas Soome  *              DNS to add new functionality to the network (such as multicast DNS).
50*5ffb0c9bSToomas Soome  *
51*5ffb0c9bSToomas Soome  *              Bonjour gives applications easy access to services over local IP
52*5ffb0c9bSToomas Soome  *              networks without requiring the service or the application to support
53*5ffb0c9bSToomas Soome  *              an AppleTalk or a Netbeui stack, and without requiring a DNS server
54*5ffb0c9bSToomas Soome  *              for the local network.
55*5ffb0c9bSToomas Soome  */
56*5ffb0c9bSToomas Soome 
57*5ffb0c9bSToomas Soome /* _DNS_SD_H contains the API version number for this header file
58*5ffb0c9bSToomas Soome  * The API version defined in this header file symbol allows for compile-time
59*5ffb0c9bSToomas Soome  * checking, so that C code building with earlier versions of the header file
60*5ffb0c9bSToomas Soome  * can avoid compile errors trying to use functions that aren't even defined
61*5ffb0c9bSToomas Soome  * in those earlier versions. Similar checks may also be performed at run-time:
62*5ffb0c9bSToomas Soome  *  => weak linking -- to avoid link failures if run with an earlier
63*5ffb0c9bSToomas Soome  *     version of the library that's missing some desired symbol, or
64*5ffb0c9bSToomas Soome  *  => DNSServiceGetProperty(DaemonVersion) -- to verify whether the running daemon
65*5ffb0c9bSToomas Soome  *     ("system service" on Windows) meets some required minimum functionality level.
66*5ffb0c9bSToomas Soome  */
674b22b933Srs200217 
684b22b933Srs200217 #ifndef _DNS_SD_H
69*5ffb0c9bSToomas Soome #define _DNS_SD_H 5763004
704b22b933Srs200217 
714b22b933Srs200217 #ifdef  __cplusplus
724b22b933Srs200217 extern "C" {
734b22b933Srs200217 #endif
744b22b933Srs200217 
75*5ffb0c9bSToomas Soome /* Set to 1 if libdispatch is supported
76*5ffb0c9bSToomas Soome  * Note: May also be set by project and/or Makefile
77*5ffb0c9bSToomas Soome  */
78*5ffb0c9bSToomas Soome #ifndef _DNS_SD_LIBDISPATCH
79*5ffb0c9bSToomas Soome #define _DNS_SD_LIBDISPATCH 0
80*5ffb0c9bSToomas Soome #endif /* ndef _DNS_SD_LIBDISPATCH */
81*5ffb0c9bSToomas Soome 
824b22b933Srs200217 /* standard calling convention under Win32 is __stdcall */
834b22b933Srs200217 /* Note: When compiling Intel EFI (Extensible Firmware Interface) under MS Visual Studio, the */
844b22b933Srs200217 /* _WIN32 symbol is defined by the compiler even though it's NOT compiling code for Windows32 */
854b22b933Srs200217 #if defined(_WIN32) && !defined(EFI32) && !defined(EFI64)
864b22b933Srs200217 #define DNSSD_API __stdcall
874b22b933Srs200217 #else
884b22b933Srs200217 #define DNSSD_API
894b22b933Srs200217 #endif
904b22b933Srs200217 
914b22b933Srs200217 /* stdint.h does not exist on FreeBSD 4.x; its types are defined in sys/types.h instead */
924b22b933Srs200217 #if defined(__FreeBSD__) && (__FreeBSD__ < 5)
934b22b933Srs200217 #include <sys/types.h>
944b22b933Srs200217 
954b22b933Srs200217 /* Likewise, on Sun, standard integer types are in sys/types.h */
964b22b933Srs200217 #elif defined(__sun__)
974b22b933Srs200217 #include <sys/types.h>
984b22b933Srs200217 
994b22b933Srs200217 /* EFI does not have stdint.h, or anything else equivalent */
100*5ffb0c9bSToomas Soome #elif defined(EFI32) || defined(EFI64) || defined(EFIX64)
101*5ffb0c9bSToomas Soome #include "Tiano.h"
102*5ffb0c9bSToomas Soome #if !defined(_STDINT_H_)
1034b22b933Srs200217 typedef UINT8 uint8_t;
1044b22b933Srs200217 typedef INT8 int8_t;
1054b22b933Srs200217 typedef UINT16 uint16_t;
1064b22b933Srs200217 typedef INT16 int16_t;
1074b22b933Srs200217 typedef UINT32 uint32_t;
1084b22b933Srs200217 typedef INT32 int32_t;
109*5ffb0c9bSToomas Soome #endif
1104b22b933Srs200217 /* Windows has its own differences */
1114b22b933Srs200217 #elif defined(_WIN32)
1124b22b933Srs200217 #include <windows.h>
1134b22b933Srs200217 #define _UNUSED
1144b22b933Srs200217 #ifndef _MSL_STDINT_H
1154b22b933Srs200217 typedef UINT8 uint8_t;
1164b22b933Srs200217 typedef INT8 int8_t;
1174b22b933Srs200217 typedef UINT16 uint16_t;
1184b22b933Srs200217 typedef INT16 int16_t;
1194b22b933Srs200217 typedef UINT32 uint32_t;
1204b22b933Srs200217 typedef INT32 int32_t;
1214b22b933Srs200217 #endif
1224b22b933Srs200217 
1234b22b933Srs200217 /* All other Posix platforms use stdint.h */
1244b22b933Srs200217 #else
1254b22b933Srs200217 #include <stdint.h>
126*5ffb0c9bSToomas Soome #endif
127*5ffb0c9bSToomas Soome 
128*5ffb0c9bSToomas Soome #if _DNS_SD_LIBDISPATCH
129*5ffb0c9bSToomas Soome #include <dispatch/dispatch.h>
1304b22b933Srs200217 #endif
1314b22b933Srs200217 
1324b22b933Srs200217 /* DNSServiceRef, DNSRecordRef
1334b22b933Srs200217  *
1344b22b933Srs200217  * Opaque internal data types.
1354b22b933Srs200217  * Note: client is responsible for serializing access to these structures if
1364b22b933Srs200217  * they are shared between concurrent threads.
1374b22b933Srs200217  */
1384b22b933Srs200217 
1394b22b933Srs200217 typedef struct _DNSServiceRef_t *DNSServiceRef;
1404b22b933Srs200217 typedef struct _DNSRecordRef_t *DNSRecordRef;
1414b22b933Srs200217 
142*5ffb0c9bSToomas Soome struct sockaddr;
143*5ffb0c9bSToomas Soome 
144*5ffb0c9bSToomas Soome /*! @enum General flags
145*5ffb0c9bSToomas Soome  * Most DNS-SD API functions and callbacks include a DNSServiceFlags parameter.
146*5ffb0c9bSToomas Soome  * As a general rule, any given bit in the 32-bit flags field has a specific fixed meaning,
147*5ffb0c9bSToomas Soome  * regardless of the function or callback being used. For any given function or callback,
148*5ffb0c9bSToomas Soome  * typically only a subset of the possible flags are meaningful, and all others should be zero.
149*5ffb0c9bSToomas Soome  * The discussion section for each API call describes which flags are valid for that call
150*5ffb0c9bSToomas Soome  * and callback. In some cases, for a particular call, it may be that no flags are currently
151*5ffb0c9bSToomas Soome  * defined, in which case the DNSServiceFlags parameter exists purely to allow future expansion.
152*5ffb0c9bSToomas Soome  * In all cases, developers should expect that in future releases, it is possible that new flag
153*5ffb0c9bSToomas Soome  * values will be defined, and write code with this in mind. For example, code that tests
154*5ffb0c9bSToomas Soome  *     if (flags == kDNSServiceFlagsAdd) ...
155*5ffb0c9bSToomas Soome  * will fail if, in a future release, another bit in the 32-bit flags field is also set.
156*5ffb0c9bSToomas Soome  * The reliable way to test whether a particular bit is set is not with an equality test,
157*5ffb0c9bSToomas Soome  * but with a bitwise mask:
158*5ffb0c9bSToomas Soome  *     if (flags & kDNSServiceFlagsAdd) ...
159*5ffb0c9bSToomas Soome  * With the exception of kDNSServiceFlagsValidate, each flag can be valid(be set)
160*5ffb0c9bSToomas Soome  * EITHER only as an input to one of the DNSService*() APIs OR only as an output
161*5ffb0c9bSToomas Soome  * (provide status) through any of the callbacks used. For example, kDNSServiceFlagsAdd
162*5ffb0c9bSToomas Soome  * can be set only as an output in the callback, whereas the kDNSServiceFlagsIncludeP2P
163*5ffb0c9bSToomas Soome  * can be set only as an input to the DNSService*() APIs. See comments on kDNSServiceFlagsValidate
164*5ffb0c9bSToomas Soome  * defined in enum below.
165*5ffb0c9bSToomas Soome  */
1664b22b933Srs200217 enum
1674b22b933Srs200217 {
1684b22b933Srs200217     kDNSServiceFlagsMoreComing          = 0x1,
1694b22b933Srs200217     /* MoreComing indicates to a callback that at least one more result is
1704b22b933Srs200217      * queued and will be delivered following immediately after this one.
171*5ffb0c9bSToomas Soome      * When the MoreComing flag is set, applications should not immediately
172*5ffb0c9bSToomas Soome      * update their UI, because this can result in a great deal of ugly flickering
173*5ffb0c9bSToomas Soome      * on the screen, and can waste a great deal of CPU time repeatedly updating
174*5ffb0c9bSToomas Soome      * the screen with content that is then immediately erased, over and over.
175*5ffb0c9bSToomas Soome      * Applications should wait until MoreComing is not set, and then
176*5ffb0c9bSToomas Soome      * update their UI when no more changes are imminent.
1774b22b933Srs200217      * When MoreComing is not set, that doesn't mean there will be no more
1784b22b933Srs200217      * answers EVER, just that there are no more answers immediately
1794b22b933Srs200217      * available right now at this instant. If more answers become available
1804b22b933Srs200217      * in the future they will be delivered as usual.
1814b22b933Srs200217      */
1824b22b933Srs200217 
1834b22b933Srs200217     kDNSServiceFlagsAdd                 = 0x2,
1844b22b933Srs200217     kDNSServiceFlagsDefault             = 0x4,
1854b22b933Srs200217     /* Flags for domain enumeration and browse/query reply callbacks.
1864b22b933Srs200217      * "Default" applies only to enumeration and is only valid in
187*5ffb0c9bSToomas Soome      * conjunction with "Add". An enumeration callback with the "Add"
1884b22b933Srs200217      * flag NOT set indicates a "Remove", i.e. the domain is no longer
1894b22b933Srs200217      * valid.
1904b22b933Srs200217      */
1914b22b933Srs200217 
1924b22b933Srs200217     kDNSServiceFlagsNoAutoRename        = 0x8,
1934b22b933Srs200217     /* Flag for specifying renaming behavior on name conflict when registering
1944b22b933Srs200217      * non-shared records. By default, name conflicts are automatically handled
1954b22b933Srs200217      * by renaming the service. NoAutoRename overrides this behavior - with this
1964b22b933Srs200217      * flag set, name conflicts will result in a callback. The NoAutorename flag
1974b22b933Srs200217      * is only valid if a name is explicitly specified when registering a service
1984b22b933Srs200217      * (i.e. the default name is not used.)
1994b22b933Srs200217      */
2004b22b933Srs200217 
2014b22b933Srs200217     kDNSServiceFlagsShared              = 0x10,
2024b22b933Srs200217     kDNSServiceFlagsUnique              = 0x20,
2034b22b933Srs200217     /* Flag for registering individual records on a connected
2044b22b933Srs200217      * DNSServiceRef. Shared indicates that there may be multiple records
2054b22b933Srs200217      * with this name on the network (e.g. PTR records). Unique indicates that the
2064b22b933Srs200217      * record's name is to be unique on the network (e.g. SRV records).
2074b22b933Srs200217      */
2084b22b933Srs200217 
2094b22b933Srs200217     kDNSServiceFlagsBrowseDomains       = 0x40,
2104b22b933Srs200217     kDNSServiceFlagsRegistrationDomains = 0x80,
2114b22b933Srs200217     /* Flags for specifying domain enumeration type in DNSServiceEnumerateDomains.
2124b22b933Srs200217      * BrowseDomains enumerates domains recommended for browsing, RegistrationDomains
2134b22b933Srs200217      * enumerates domains recommended for registration.
2144b22b933Srs200217      */
2154b22b933Srs200217 
2164b22b933Srs200217     kDNSServiceFlagsLongLivedQuery      = 0x100,
2174b22b933Srs200217     /* Flag for creating a long-lived unicast query for the DNSServiceQueryRecord call. */
2184b22b933Srs200217 
2194b22b933Srs200217     kDNSServiceFlagsAllowRemoteQuery    = 0x200,
2204b22b933Srs200217     /* Flag for creating a record for which we will answer remote queries
2214b22b933Srs200217      * (queries from hosts more than one hop away; hosts not directly connected to the local link).
2224b22b933Srs200217      */
2234b22b933Srs200217 
2244b22b933Srs200217     kDNSServiceFlagsForceMulticast      = 0x400,
225*5ffb0c9bSToomas Soome     /* Flag for signifying that a query or registration should be performed exclusively via multicast
226*5ffb0c9bSToomas Soome      * DNS, even for a name in a domain (e.g. foo.apple.com.) that would normally imply unicast DNS.
2274b22b933Srs200217      */
2284b22b933Srs200217 
229*5ffb0c9bSToomas Soome     kDNSServiceFlagsForce               = 0x800,    // This flag is deprecated.
230*5ffb0c9bSToomas Soome 
231*5ffb0c9bSToomas Soome     kDNSServiceFlagsKnownUnique         = 0x800,
232*5ffb0c9bSToomas Soome     /*
233*5ffb0c9bSToomas Soome      * Client guarantees that record names are unique, so we can skip sending out initial
234*5ffb0c9bSToomas Soome      * probe messages.  Standard name conflict resolution is still done if a conflict is discovered.
235*5ffb0c9bSToomas Soome      * Currently only valid for a DNSServiceRegister call.
236*5ffb0c9bSToomas Soome      */
237*5ffb0c9bSToomas Soome 
238*5ffb0c9bSToomas Soome     kDNSServiceFlagsReturnIntermediates = 0x1000,
239*5ffb0c9bSToomas Soome     /* Flag for returning intermediate results.
240*5ffb0c9bSToomas Soome      * For example, if a query results in an authoritative NXDomain (name does not exist)
241*5ffb0c9bSToomas Soome      * then that result is returned to the client. However the query is not implicitly
242*5ffb0c9bSToomas Soome      * cancelled -- it remains active and if the answer subsequently changes
243*5ffb0c9bSToomas Soome      * (e.g. because a VPN tunnel is subsequently established) then that positive
244*5ffb0c9bSToomas Soome      * result will still be returned to the client.
245*5ffb0c9bSToomas Soome      * Similarly, if a query results in a CNAME record, then in addition to following
246*5ffb0c9bSToomas Soome      * the CNAME referral, the intermediate CNAME result is also returned to the client.
247*5ffb0c9bSToomas Soome      * When this flag is not set, NXDomain errors are not returned, and CNAME records
248*5ffb0c9bSToomas Soome      * are followed silently without informing the client of the intermediate steps.
249*5ffb0c9bSToomas Soome      * (In earlier builds this flag was briefly calledkDNSServiceFlagsReturnCNAME)
250*5ffb0c9bSToomas Soome      */
251*5ffb0c9bSToomas Soome 
252*5ffb0c9bSToomas Soome     kDNSServiceFlagsNonBrowsable        = 0x2000,
253*5ffb0c9bSToomas Soome     /* A service registered with the NonBrowsable flag set can be resolved using
254*5ffb0c9bSToomas Soome      * DNSServiceResolve(), but will not be discoverable using DNSServiceBrowse().
255*5ffb0c9bSToomas Soome      * This is for cases where the name is actually a GUID; it is found by other means;
256*5ffb0c9bSToomas Soome      * there is no end-user benefit to browsing to find a long list of opaque GUIDs.
257*5ffb0c9bSToomas Soome      * Using the NonBrowsable flag creates SRV+TXT without the cost of also advertising
258*5ffb0c9bSToomas Soome      * an associated PTR record.
259*5ffb0c9bSToomas Soome      */
260*5ffb0c9bSToomas Soome 
261*5ffb0c9bSToomas Soome     kDNSServiceFlagsShareConnection     = 0x4000,
262*5ffb0c9bSToomas Soome     /* For efficiency, clients that perform many concurrent operations may want to use a
263*5ffb0c9bSToomas Soome      * single Unix Domain Socket connection with the background daemon, instead of having a
264*5ffb0c9bSToomas Soome      * separate connection for each independent operation. To use this mode, clients first
265*5ffb0c9bSToomas Soome      * call DNSServiceCreateConnection(&MainRef) to initialize the main DNSServiceRef.
266*5ffb0c9bSToomas Soome      * For each subsequent operation that is to share that same connection, the client copies
267*5ffb0c9bSToomas Soome      * the MainRef, and then passes the address of that copy, setting the ShareConnection flag
268*5ffb0c9bSToomas Soome      * to tell the library that this DNSServiceRef is not a typical uninitialized DNSServiceRef;
269*5ffb0c9bSToomas Soome      * it's a copy of an existing DNSServiceRef whose connection information should be reused.
270*5ffb0c9bSToomas Soome      *
271*5ffb0c9bSToomas Soome      * For example:
272*5ffb0c9bSToomas Soome      *
273*5ffb0c9bSToomas Soome      * DNSServiceErrorType error;
274*5ffb0c9bSToomas Soome      * DNSServiceRef MainRef;
275*5ffb0c9bSToomas Soome      * error = DNSServiceCreateConnection(&MainRef);
276*5ffb0c9bSToomas Soome      * if (error) ...
277*5ffb0c9bSToomas Soome      * DNSServiceRef BrowseRef = MainRef;  // Important: COPY the primary DNSServiceRef first...
278*5ffb0c9bSToomas Soome      * error = DNSServiceBrowse(&BrowseRef, kDNSServiceFlagsShareConnection, ...); // then use the copy
279*5ffb0c9bSToomas Soome      * if (error) ...
280*5ffb0c9bSToomas Soome      * ...
281*5ffb0c9bSToomas Soome      * DNSServiceRefDeallocate(BrowseRef); // Terminate the browse operation
282*5ffb0c9bSToomas Soome      * DNSServiceRefDeallocate(MainRef);   // Terminate the shared connection
283*5ffb0c9bSToomas Soome      * Also see Point 4.(Don't Double-Deallocate if the MainRef has been Deallocated) in Notes below:
284*5ffb0c9bSToomas Soome      *
285*5ffb0c9bSToomas Soome      * Notes:
286*5ffb0c9bSToomas Soome      *
287*5ffb0c9bSToomas Soome      * 1. Collective kDNSServiceFlagsMoreComing flag
288*5ffb0c9bSToomas Soome      * When callbacks are invoked using a shared DNSServiceRef, the
289*5ffb0c9bSToomas Soome      * kDNSServiceFlagsMoreComing flag applies collectively to *all* active
290*5ffb0c9bSToomas Soome      * operations sharing the same parent DNSServiceRef. If the MoreComing flag is
291*5ffb0c9bSToomas Soome      * set it means that there are more results queued on this parent DNSServiceRef,
292*5ffb0c9bSToomas Soome      * but not necessarily more results for this particular callback function.
293*5ffb0c9bSToomas Soome      * The implication of this for client programmers is that when a callback
294*5ffb0c9bSToomas Soome      * is invoked with the MoreComing flag set, the code should update its
295*5ffb0c9bSToomas Soome      * internal data structures with the new result, and set a variable indicating
296*5ffb0c9bSToomas Soome      * that its UI needs to be updated. Then, later when a callback is eventually
297*5ffb0c9bSToomas Soome      * invoked with the MoreComing flag not set, the code should update *all*
298*5ffb0c9bSToomas Soome      * stale UI elements related to that shared parent DNSServiceRef that need
299*5ffb0c9bSToomas Soome      * updating, not just the UI elements related to the particular callback
300*5ffb0c9bSToomas Soome      * that happened to be the last one to be invoked.
301*5ffb0c9bSToomas Soome      *
302*5ffb0c9bSToomas Soome      * 2. Canceling operations and kDNSServiceFlagsMoreComing
303*5ffb0c9bSToomas Soome      * Whenever you cancel any operation for which you had deferred UI updates
304*5ffb0c9bSToomas Soome      * waiting because of a kDNSServiceFlagsMoreComing flag, you should perform
305*5ffb0c9bSToomas Soome      * those deferred UI updates. This is because, after cancelling the operation,
306*5ffb0c9bSToomas Soome      * you can no longer wait for a callback *without* MoreComing set, to tell
307*5ffb0c9bSToomas Soome      * you do perform your deferred UI updates (the operation has been canceled,
308*5ffb0c9bSToomas Soome      * so there will be no more callbacks). An implication of the collective
309*5ffb0c9bSToomas Soome      * kDNSServiceFlagsMoreComing flag for shared connections is that this
310*5ffb0c9bSToomas Soome      * guideline applies more broadly -- any time you cancel an operation on
311*5ffb0c9bSToomas Soome      * a shared connection, you should perform all deferred UI updates for all
312*5ffb0c9bSToomas Soome      * operations sharing that connection. This is because the MoreComing flag
313*5ffb0c9bSToomas Soome      * might have been referring to events coming for the operation you canceled,
314*5ffb0c9bSToomas Soome      * which will now not be coming because the operation has been canceled.
315*5ffb0c9bSToomas Soome      *
316*5ffb0c9bSToomas Soome      * 3. Only share DNSServiceRef's created with DNSServiceCreateConnection
317*5ffb0c9bSToomas Soome      * Calling DNSServiceCreateConnection(&ref) creates a special shareable DNSServiceRef.
318*5ffb0c9bSToomas Soome      * DNSServiceRef's created by other calls like DNSServiceBrowse() or DNSServiceResolve()
319*5ffb0c9bSToomas Soome      * cannot be shared by copying them and using kDNSServiceFlagsShareConnection.
320*5ffb0c9bSToomas Soome      *
321*5ffb0c9bSToomas Soome      * 4. Don't Double-Deallocate if the MainRef has been Deallocated
322*5ffb0c9bSToomas Soome      * Calling DNSServiceRefDeallocate(ref) for a particular operation's DNSServiceRef terminates
323*5ffb0c9bSToomas Soome      * just that operation. Calling DNSServiceRefDeallocate(ref) for the main shared DNSServiceRef
324*5ffb0c9bSToomas Soome      * (the parent DNSServiceRef, originally created by DNSServiceCreateConnection(&ref))
325*5ffb0c9bSToomas Soome      * automatically terminates the shared connection and all operations that were still using it.
326*5ffb0c9bSToomas Soome      * After doing this, DO NOT then attempt to deallocate any remaining subordinate DNSServiceRef's.
327*5ffb0c9bSToomas Soome      * The memory used by those subordinate DNSServiceRef's has already been freed, so any attempt
328*5ffb0c9bSToomas Soome      * to do a DNSServiceRefDeallocate (or any other operation) on them will result in accesses
329*5ffb0c9bSToomas Soome      * to freed memory, leading to crashes or other equally undesirable results.
330*5ffb0c9bSToomas Soome      *
331*5ffb0c9bSToomas Soome      * 5. Thread Safety
332*5ffb0c9bSToomas Soome      * The dns_sd.h API does not presuppose any particular threading model, and consequently
333*5ffb0c9bSToomas Soome      * does no locking of its own (which would require linking some specific threading library).
334*5ffb0c9bSToomas Soome      * If client code calls API routines on the same DNSServiceRef concurrently
335*5ffb0c9bSToomas Soome      * from multiple threads, it is the client's responsibility to use a mutext
336*5ffb0c9bSToomas Soome      * lock or take similar appropriate precautions to serialize those calls.
337*5ffb0c9bSToomas Soome      */
338*5ffb0c9bSToomas Soome 
339*5ffb0c9bSToomas Soome     kDNSServiceFlagsSuppressUnusable    = 0x8000,
340*5ffb0c9bSToomas Soome     /*
341*5ffb0c9bSToomas Soome      * This flag is meaningful only in DNSServiceQueryRecord which suppresses unusable queries on the
342*5ffb0c9bSToomas Soome      * wire. If "hostname" is a wide-area unicast DNS hostname (i.e. not a ".local." name)
343*5ffb0c9bSToomas Soome      * but this host has no routable IPv6 address, then the call will not try to look up IPv6 addresses
344*5ffb0c9bSToomas Soome      * for "hostname", since any addresses it found would be unlikely to be of any use anyway. Similarly,
345*5ffb0c9bSToomas Soome      * if this host has no routable IPv4 address, the call will not try to look up IPv4 addresses for
346*5ffb0c9bSToomas Soome      * "hostname".
347*5ffb0c9bSToomas Soome      */
348*5ffb0c9bSToomas Soome 
349*5ffb0c9bSToomas Soome     kDNSServiceFlagsTimeout            = 0x10000,
350*5ffb0c9bSToomas Soome     /*
351*5ffb0c9bSToomas Soome      * When kDNServiceFlagsTimeout is passed to DNSServiceQueryRecord or DNSServiceGetAddrInfo, the query is
352*5ffb0c9bSToomas Soome      * stopped after a certain number of seconds have elapsed. The time at which the query will be stopped
353*5ffb0c9bSToomas Soome      * is determined by the system and cannot be configured by the user. The query will be stopped irrespective
354*5ffb0c9bSToomas Soome      * of whether a response was given earlier or not. When the query is stopped, the callback will be called
355*5ffb0c9bSToomas Soome      * with an error code of kDNSServiceErr_Timeout and a NULL sockaddr will be returned for DNSServiceGetAddrInfo
356*5ffb0c9bSToomas Soome      * and zero length rdata will be returned for DNSServiceQueryRecord.
357*5ffb0c9bSToomas Soome      */
358*5ffb0c9bSToomas Soome 
359*5ffb0c9bSToomas Soome     kDNSServiceFlagsIncludeP2P          = 0x20000,
360*5ffb0c9bSToomas Soome     /*
361*5ffb0c9bSToomas Soome      * Include P2P interfaces when kDNSServiceInterfaceIndexAny is specified.
362*5ffb0c9bSToomas Soome      * By default, specifying kDNSServiceInterfaceIndexAny does not include P2P interfaces.
363*5ffb0c9bSToomas Soome      */
364*5ffb0c9bSToomas Soome 
365*5ffb0c9bSToomas Soome     kDNSServiceFlagsWakeOnResolve      = 0x40000,
366*5ffb0c9bSToomas Soome     /*
367*5ffb0c9bSToomas Soome     * This flag is meaningful only in DNSServiceResolve. When set, it tries to send a magic packet
368*5ffb0c9bSToomas Soome     * to wake up the client.
369*5ffb0c9bSToomas Soome     */
370*5ffb0c9bSToomas Soome 
371*5ffb0c9bSToomas Soome     kDNSServiceFlagsBackgroundTrafficClass  = 0x80000,
372*5ffb0c9bSToomas Soome     /*
373*5ffb0c9bSToomas Soome     * This flag is meaningful for Unicast DNS queries. When set, it uses the background traffic
374*5ffb0c9bSToomas Soome     * class for packets that service the request.
375*5ffb0c9bSToomas Soome     */
376*5ffb0c9bSToomas Soome 
377*5ffb0c9bSToomas Soome     kDNSServiceFlagsIncludeAWDL      = 0x100000,
378*5ffb0c9bSToomas Soome    /*
379*5ffb0c9bSToomas Soome     * Include AWDL interface when kDNSServiceInterfaceIndexAny is specified.
380*5ffb0c9bSToomas Soome     */
381*5ffb0c9bSToomas Soome 
382*5ffb0c9bSToomas Soome     kDNSServiceFlagsValidate               = 0x200000,
383*5ffb0c9bSToomas Soome    /*
384*5ffb0c9bSToomas Soome     * This flag is meaningful in DNSServiceGetAddrInfo and DNSServiceQueryRecord. This is the ONLY flag to be valid
385*5ffb0c9bSToomas Soome     * as an input to the APIs and also an output through the callbacks in the APIs.
386*5ffb0c9bSToomas Soome     *
387*5ffb0c9bSToomas Soome     * When this flag is passed to DNSServiceQueryRecord and DNSServiceGetAddrInfo to resolve unicast names,
388*5ffb0c9bSToomas Soome     * the response  will be validated using DNSSEC. The validation results are delivered using the flags field in
389*5ffb0c9bSToomas Soome     * the callback and kDNSServiceFlagsValidate is marked in the flags to indicate that DNSSEC status is also available.
390*5ffb0c9bSToomas Soome     * When the callback is called to deliver the query results, the validation results may or may not be available.
391*5ffb0c9bSToomas Soome     * If it is not delivered along with the results, the validation status is delivered when the validation completes.
392*5ffb0c9bSToomas Soome     *
393*5ffb0c9bSToomas Soome     * When the validation results are delivered in the callback, it is indicated by marking the flags with
394*5ffb0c9bSToomas Soome     * kDNSServiceFlagsValidate and kDNSServiceFlagsAdd along with the DNSSEC status flags (described below) and a NULL
395*5ffb0c9bSToomas Soome     * sockaddr will be returned for DNSServiceGetAddrInfo and zero length rdata will be returned for DNSServiceQueryRecord.
396*5ffb0c9bSToomas Soome     * DNSSEC validation results are for the whole RRSet and not just individual records delivered in the callback. When
397*5ffb0c9bSToomas Soome     * kDNSServiceFlagsAdd is not set in the flags, applications should implicitly assume that the DNSSEC status of the
398*5ffb0c9bSToomas Soome     * RRSet that has been delivered up until that point is not valid anymore, till another callback is called with
399*5ffb0c9bSToomas Soome     * kDNSServiceFlagsAdd and kDNSServiceFlagsValidate.
400*5ffb0c9bSToomas Soome     *
401*5ffb0c9bSToomas Soome     * The following four flags indicate the status of the DNSSEC validation and marked in the flags field of the callback.
402*5ffb0c9bSToomas Soome     * When any of the four flags is set, kDNSServiceFlagsValidate will also be set. To check the validation status, the
403*5ffb0c9bSToomas Soome     * other applicable output flags should be masked. See kDNSServiceOutputFlags below.
404*5ffb0c9bSToomas Soome     */
405*5ffb0c9bSToomas Soome 
406*5ffb0c9bSToomas Soome     kDNSServiceFlagsSecure                 = 0x200010,
407*5ffb0c9bSToomas Soome    /*
408*5ffb0c9bSToomas Soome     * The response has been validated by verifying all the signaures in the response and was able to
409*5ffb0c9bSToomas Soome     * build a successful authentication chain starting from a known trust anchor.
410*5ffb0c9bSToomas Soome     */
411*5ffb0c9bSToomas Soome 
412*5ffb0c9bSToomas Soome     kDNSServiceFlagsInsecure               = 0x200020,
413*5ffb0c9bSToomas Soome    /*
414*5ffb0c9bSToomas Soome     * A chain of trust cannot be built starting from a known trust anchor to the response.
415*5ffb0c9bSToomas Soome     */
416*5ffb0c9bSToomas Soome 
417*5ffb0c9bSToomas Soome     kDNSServiceFlagsBogus                  = 0x200040,
418*5ffb0c9bSToomas Soome    /*
419*5ffb0c9bSToomas Soome     * If the response cannot be verified to be secure due to expired signatures, missing signatures etc.,
420*5ffb0c9bSToomas Soome     * then the results are considered to be bogus.
421*5ffb0c9bSToomas Soome     */
422*5ffb0c9bSToomas Soome 
423*5ffb0c9bSToomas Soome     kDNSServiceFlagsIndeterminate          = 0x200080,
424*5ffb0c9bSToomas Soome    /*
425*5ffb0c9bSToomas Soome     * There is no valid trust anchor that can be used to determine whether a response is secure or not.
426*5ffb0c9bSToomas Soome     */
427*5ffb0c9bSToomas Soome 
428*5ffb0c9bSToomas Soome     kDNSServiceFlagsUnicastResponse        = 0x400000,
429*5ffb0c9bSToomas Soome    /*
430*5ffb0c9bSToomas Soome     * Request unicast response to query.
431*5ffb0c9bSToomas Soome     */
432*5ffb0c9bSToomas Soome     kDNSServiceFlagsValidateOptional       = 0x800000,
433*5ffb0c9bSToomas Soome 
434*5ffb0c9bSToomas Soome     /*
435*5ffb0c9bSToomas Soome      * This flag is identical to kDNSServiceFlagsValidate except for the case where the response
436*5ffb0c9bSToomas Soome      * cannot be validated. If this flag is set in DNSServiceQueryRecord or DNSServiceGetAddrInfo,
437*5ffb0c9bSToomas Soome      * the DNSSEC records will be requested for validation. If they cannot be received for some reason
438*5ffb0c9bSToomas Soome      * during the validation (e.g., zone is not signed, zone is signed but cannot be traced back to
439*5ffb0c9bSToomas Soome      * root, recursive server does not understand DNSSEC etc.), then this will fallback to the default
440*5ffb0c9bSToomas Soome      * behavior where the validation will not be performed and no DNSSEC results will be provided.
441*5ffb0c9bSToomas Soome      *
442*5ffb0c9bSToomas Soome      * If the zone is signed and there is a valid path to a known trust anchor configured in the system
443*5ffb0c9bSToomas Soome      * and the application requires DNSSEC validation irrespective of the DNSSEC awareness in the current
444*5ffb0c9bSToomas Soome      * network, then this option MUST not be used. This is only intended to be used during the transition
445*5ffb0c9bSToomas Soome      * period where the different nodes participating in the DNS resolution may not understand DNSSEC or
446*5ffb0c9bSToomas Soome      * managed properly (e.g. missing DS record) but still want to be able to resolve DNS successfully.
447*5ffb0c9bSToomas Soome      */
448*5ffb0c9bSToomas Soome 
449*5ffb0c9bSToomas Soome     kDNSServiceFlagsWakeOnlyService        = 0x1000000,
450*5ffb0c9bSToomas Soome     /*
451*5ffb0c9bSToomas Soome      * This flag is meaningful only in DNSServiceRegister. When set, the service will not be registered
452*5ffb0c9bSToomas Soome      * with sleep proxy server during sleep.
453*5ffb0c9bSToomas Soome      */
454*5ffb0c9bSToomas Soome 
455*5ffb0c9bSToomas Soome     kDNSServiceFlagsThresholdOne           = 0x2000000,
456*5ffb0c9bSToomas Soome     kDNSServiceFlagsThresholdFinder        = 0x4000000,
457*5ffb0c9bSToomas Soome     kDNSServiceFlagsThresholdReached       = kDNSServiceFlagsThresholdOne,
458*5ffb0c9bSToomas Soome     /*
459*5ffb0c9bSToomas Soome      * kDNSServiceFlagsThresholdOne is meaningful only in DNSServiceBrowse. When set,
460*5ffb0c9bSToomas Soome      * the system will stop issuing browse queries on the network once the number
461*5ffb0c9bSToomas Soome      * of answers returned is one or more.  It will issue queries on the network
462*5ffb0c9bSToomas Soome      * again if the number of answers drops to zero.
463*5ffb0c9bSToomas Soome      * This flag is for Apple internal use only. Third party developers
464*5ffb0c9bSToomas Soome      * should not rely on this behavior being supported in any given software release.
465*5ffb0c9bSToomas Soome      *
466*5ffb0c9bSToomas Soome      * kDNSServiceFlagsThresholdFinder is meaningful only in DNSServiceBrowse. When set,
467*5ffb0c9bSToomas Soome      * the system will stop issuing browse queries on the network once the number
468*5ffb0c9bSToomas Soome      * of answers has reached the threshold set for Finder.
469*5ffb0c9bSToomas Soome      * It will issue queries on the network again if the number of answers drops below
470*5ffb0c9bSToomas Soome      * this threshold.
471*5ffb0c9bSToomas Soome      * This flag is for Apple internal use only. Third party developers
472*5ffb0c9bSToomas Soome      * should not rely on this behavior being supported in any given software release.
473*5ffb0c9bSToomas Soome      *
474*5ffb0c9bSToomas Soome      * When kDNSServiceFlagsThresholdReached is set in the client callback add or remove event,
475*5ffb0c9bSToomas Soome      * it indicates that the browse answer threshold has been reached and no
476*5ffb0c9bSToomas Soome      * browse requests will be generated on the network until the number of answers falls
477*5ffb0c9bSToomas Soome      * below the threshold value.  Add and remove events can still occur based
478*5ffb0c9bSToomas Soome      * on incoming Bonjour traffic observed by the system.
479*5ffb0c9bSToomas Soome      * The set of services return to the client is not guaranteed to represent the
480*5ffb0c9bSToomas Soome      * entire set of services present on the network once the threshold has been reached.
481*5ffb0c9bSToomas Soome      *
482*5ffb0c9bSToomas Soome      * Note, while kDNSServiceFlagsThresholdReached and kDNSServiceFlagsThresholdOne
483*5ffb0c9bSToomas Soome      * have the same value, there  isn't a conflict because kDNSServiceFlagsThresholdReached
484*5ffb0c9bSToomas Soome      * is only set in the callbacks and kDNSServiceFlagsThresholdOne is only set on
485*5ffb0c9bSToomas Soome      * input to a DNSServiceBrowse call.
486*5ffb0c9bSToomas Soome      */
487*5ffb0c9bSToomas Soome      kDNSServiceFlagsDenyCellular           = 0x8000000,
488*5ffb0c9bSToomas Soome     /*
489*5ffb0c9bSToomas Soome      * This flag is meaningful only for Unicast DNS queries. When set, the kernel will restrict
490*5ffb0c9bSToomas Soome      * DNS resolutions on the cellular interface for that request.
491*5ffb0c9bSToomas Soome      */
492*5ffb0c9bSToomas Soome 
493*5ffb0c9bSToomas Soome      kDNSServiceFlagsServiceIndex           = 0x10000000,
494*5ffb0c9bSToomas Soome     /*
495*5ffb0c9bSToomas Soome      * This flag is meaningful only for DNSServiceGetAddrInfo() for Unicast DNS queries.
496*5ffb0c9bSToomas Soome      * When set, DNSServiceGetAddrInfo() will interpret the "interfaceIndex" argument of the call
497*5ffb0c9bSToomas Soome      * as the "serviceIndex".
498*5ffb0c9bSToomas Soome      */
499*5ffb0c9bSToomas Soome 
500*5ffb0c9bSToomas Soome      kDNSServiceFlagsDenyExpensive          = 0x20000000
501*5ffb0c9bSToomas Soome     /*
502*5ffb0c9bSToomas Soome      * This flag is meaningful only for Unicast DNS queries. When set, the kernel will restrict
503*5ffb0c9bSToomas Soome      * DNS resolutions on interfaces defined as expensive for that request.
504*5ffb0c9bSToomas Soome      */
505*5ffb0c9bSToomas Soome 
506*5ffb0c9bSToomas Soome };
507*5ffb0c9bSToomas Soome 
508*5ffb0c9bSToomas Soome #define kDNSServiceOutputFlags (kDNSServiceFlagsValidate | kDNSServiceFlagsValidateOptional | kDNSServiceFlagsMoreComing | kDNSServiceFlagsAdd | kDNSServiceFlagsDefault)
509*5ffb0c9bSToomas Soome    /* All the output flags excluding the DNSSEC Status flags. Typically used to check DNSSEC Status */
510*5ffb0c9bSToomas Soome 
511*5ffb0c9bSToomas Soome /* Possible protocol values */
512*5ffb0c9bSToomas Soome enum
513*5ffb0c9bSToomas Soome {
514*5ffb0c9bSToomas Soome     /* for DNSServiceGetAddrInfo() */
515*5ffb0c9bSToomas Soome     kDNSServiceProtocol_IPv4 = 0x01,
516*5ffb0c9bSToomas Soome     kDNSServiceProtocol_IPv6 = 0x02,
517*5ffb0c9bSToomas Soome     /* 0x04 and 0x08 reserved for future internetwork protocols */
518*5ffb0c9bSToomas Soome 
519*5ffb0c9bSToomas Soome     /* for DNSServiceNATPortMappingCreate() */
520*5ffb0c9bSToomas Soome     kDNSServiceProtocol_UDP  = 0x10,
521*5ffb0c9bSToomas Soome     kDNSServiceProtocol_TCP  = 0x20
522*5ffb0c9bSToomas Soome                                /* 0x40 and 0x80 reserved for future transport protocols, e.g. SCTP [RFC 2960]
523*5ffb0c9bSToomas Soome                                 * or DCCP [RFC 4340]. If future NAT gateways are created that support port
524*5ffb0c9bSToomas Soome                                 * mappings for these protocols, new constants will be defined here.
5254b22b933Srs200217                                 */
5264b22b933Srs200217 };
5274b22b933Srs200217 
5284b22b933Srs200217 /*
5294b22b933Srs200217  * The values for DNS Classes and Types are listed in RFC 1035, and are available
5304b22b933Srs200217  * on every OS in its DNS header file. Unfortunately every OS does not have the
5314b22b933Srs200217  * same header file containing DNS Class and Type constants, and the names of
5324b22b933Srs200217  * the constants are not consistent. For example, BIND 8 uses "T_A",
5334b22b933Srs200217  * BIND 9 uses "ns_t_a", Windows uses "DNS_TYPE_A", etc.
5344b22b933Srs200217  * For this reason, these constants are also listed here, so that code using
5354b22b933Srs200217  * the DNS-SD programming APIs can use these constants, so that the same code
5364b22b933Srs200217  * can compile on all our supported platforms.
5374b22b933Srs200217  */
5384b22b933Srs200217 
5394b22b933Srs200217 enum
5404b22b933Srs200217 {
5414b22b933Srs200217     kDNSServiceClass_IN       = 1       /* Internet */
5424b22b933Srs200217 };
5434b22b933Srs200217 
5444b22b933Srs200217 enum
5454b22b933Srs200217 {
5464b22b933Srs200217     kDNSServiceType_A          = 1,      /* Host address. */
5474b22b933Srs200217     kDNSServiceType_NS         = 2,      /* Authoritative server. */
5484b22b933Srs200217     kDNSServiceType_MD         = 3,      /* Mail destination. */
5494b22b933Srs200217     kDNSServiceType_MF         = 4,      /* Mail forwarder. */
5504b22b933Srs200217     kDNSServiceType_CNAME      = 5,      /* Canonical name. */
5514b22b933Srs200217     kDNSServiceType_SOA        = 6,      /* Start of authority zone. */
5524b22b933Srs200217     kDNSServiceType_MB         = 7,      /* Mailbox domain name. */
5534b22b933Srs200217     kDNSServiceType_MG         = 8,      /* Mail group member. */
5544b22b933Srs200217     kDNSServiceType_MR         = 9,      /* Mail rename name. */
5554b22b933Srs200217     kDNSServiceType_NULL       = 10,     /* Null resource record. */
5564b22b933Srs200217     kDNSServiceType_WKS        = 11,     /* Well known service. */
5574b22b933Srs200217     kDNSServiceType_PTR        = 12,     /* Domain name pointer. */
5584b22b933Srs200217     kDNSServiceType_HINFO      = 13,     /* Host information. */
5594b22b933Srs200217     kDNSServiceType_MINFO      = 14,     /* Mailbox information. */
5604b22b933Srs200217     kDNSServiceType_MX         = 15,     /* Mail routing information. */
561*5ffb0c9bSToomas Soome     kDNSServiceType_TXT        = 16,     /* One or more text strings (NOT "zero or more..."). */
5624b22b933Srs200217     kDNSServiceType_RP         = 17,     /* Responsible person. */
5634b22b933Srs200217     kDNSServiceType_AFSDB      = 18,     /* AFS cell database. */
5644b22b933Srs200217     kDNSServiceType_X25        = 19,     /* X_25 calling address. */
5654b22b933Srs200217     kDNSServiceType_ISDN       = 20,     /* ISDN calling address. */
5664b22b933Srs200217     kDNSServiceType_RT         = 21,     /* Router. */
5674b22b933Srs200217     kDNSServiceType_NSAP       = 22,     /* NSAP address. */
5684b22b933Srs200217     kDNSServiceType_NSAP_PTR   = 23,     /* Reverse NSAP lookup (deprecated). */
5694b22b933Srs200217     kDNSServiceType_SIG        = 24,     /* Security signature. */
5704b22b933Srs200217     kDNSServiceType_KEY        = 25,     /* Security key. */
5714b22b933Srs200217     kDNSServiceType_PX         = 26,     /* X.400 mail mapping. */
5724b22b933Srs200217     kDNSServiceType_GPOS       = 27,     /* Geographical position (withdrawn). */
5734b22b933Srs200217     kDNSServiceType_AAAA       = 28,     /* IPv6 Address. */
5744b22b933Srs200217     kDNSServiceType_LOC        = 29,     /* Location Information. */
5754b22b933Srs200217     kDNSServiceType_NXT        = 30,     /* Next domain (security). */
5764b22b933Srs200217     kDNSServiceType_EID        = 31,     /* Endpoint identifier. */
5774b22b933Srs200217     kDNSServiceType_NIMLOC     = 32,     /* Nimrod Locator. */
5784b22b933Srs200217     kDNSServiceType_SRV        = 33,     /* Server Selection. */
5794b22b933Srs200217     kDNSServiceType_ATMA       = 34,     /* ATM Address */
5804b22b933Srs200217     kDNSServiceType_NAPTR      = 35,     /* Naming Authority PoinTeR */
5814b22b933Srs200217     kDNSServiceType_KX         = 36,     /* Key Exchange */
5824b22b933Srs200217     kDNSServiceType_CERT       = 37,     /* Certification record */
5834b22b933Srs200217     kDNSServiceType_A6         = 38,     /* IPv6 Address (deprecated) */
5844b22b933Srs200217     kDNSServiceType_DNAME      = 39,     /* Non-terminal DNAME (for IPv6) */
585*5ffb0c9bSToomas Soome     kDNSServiceType_SINK       = 40,     /* Kitchen sink (experimental) */
5864b22b933Srs200217     kDNSServiceType_OPT        = 41,     /* EDNS0 option (meta-RR) */
587*5ffb0c9bSToomas Soome     kDNSServiceType_APL        = 42,     /* Address Prefix List */
588*5ffb0c9bSToomas Soome     kDNSServiceType_DS         = 43,     /* Delegation Signer */
589*5ffb0c9bSToomas Soome     kDNSServiceType_SSHFP      = 44,     /* SSH Key Fingerprint */
590*5ffb0c9bSToomas Soome     kDNSServiceType_IPSECKEY   = 45,     /* IPSECKEY */
591*5ffb0c9bSToomas Soome     kDNSServiceType_RRSIG      = 46,     /* RRSIG */
592*5ffb0c9bSToomas Soome     kDNSServiceType_NSEC       = 47,     /* Denial of Existence */
593*5ffb0c9bSToomas Soome     kDNSServiceType_DNSKEY     = 48,     /* DNSKEY */
594*5ffb0c9bSToomas Soome     kDNSServiceType_DHCID      = 49,     /* DHCP Client Identifier */
595*5ffb0c9bSToomas Soome     kDNSServiceType_NSEC3      = 50,     /* Hashed Authenticated Denial of Existence */
596*5ffb0c9bSToomas Soome     kDNSServiceType_NSEC3PARAM = 51,     /* Hashed Authenticated Denial of Existence */
597*5ffb0c9bSToomas Soome 
598*5ffb0c9bSToomas Soome     kDNSServiceType_HIP        = 55,     /* Host Identity Protocol */
599*5ffb0c9bSToomas Soome 
600*5ffb0c9bSToomas Soome     kDNSServiceType_SPF        = 99,     /* Sender Policy Framework for E-Mail */
601*5ffb0c9bSToomas Soome     kDNSServiceType_UINFO      = 100,    /* IANA-Reserved */
602*5ffb0c9bSToomas Soome     kDNSServiceType_UID        = 101,    /* IANA-Reserved */
603*5ffb0c9bSToomas Soome     kDNSServiceType_GID        = 102,    /* IANA-Reserved */
604*5ffb0c9bSToomas Soome     kDNSServiceType_UNSPEC     = 103,    /* IANA-Reserved */
605*5ffb0c9bSToomas Soome 
6064b22b933Srs200217     kDNSServiceType_TKEY       = 249,    /* Transaction key */
6074b22b933Srs200217     kDNSServiceType_TSIG       = 250,    /* Transaction signature. */
6084b22b933Srs200217     kDNSServiceType_IXFR       = 251,    /* Incremental zone transfer. */
6094b22b933Srs200217     kDNSServiceType_AXFR       = 252,    /* Transfer zone of authority. */
6104b22b933Srs200217     kDNSServiceType_MAILB      = 253,    /* Transfer mailbox records. */
6114b22b933Srs200217     kDNSServiceType_MAILA      = 254,    /* Transfer mail agent records. */
6124b22b933Srs200217     kDNSServiceType_ANY        = 255     /* Wildcard match. */
6134b22b933Srs200217 };
6144b22b933Srs200217 
6154b22b933Srs200217 /* possible error code values */
6164b22b933Srs200217 enum
6174b22b933Srs200217 {
6184b22b933Srs200217     kDNSServiceErr_NoError                   = 0,
6194b22b933Srs200217     kDNSServiceErr_Unknown                   = -65537,  /* 0xFFFE FFFF */
6204b22b933Srs200217     kDNSServiceErr_NoSuchName                = -65538,
6214b22b933Srs200217     kDNSServiceErr_NoMemory                  = -65539,
6224b22b933Srs200217     kDNSServiceErr_BadParam                  = -65540,
6234b22b933Srs200217     kDNSServiceErr_BadReference              = -65541,
6244b22b933Srs200217     kDNSServiceErr_BadState                  = -65542,
6254b22b933Srs200217     kDNSServiceErr_BadFlags                  = -65543,
6264b22b933Srs200217     kDNSServiceErr_Unsupported               = -65544,
6274b22b933Srs200217     kDNSServiceErr_NotInitialized            = -65545,
6284b22b933Srs200217     kDNSServiceErr_AlreadyRegistered         = -65547,
6294b22b933Srs200217     kDNSServiceErr_NameConflict              = -65548,
6304b22b933Srs200217     kDNSServiceErr_Invalid                   = -65549,
6314b22b933Srs200217     kDNSServiceErr_Firewall                  = -65550,
6324b22b933Srs200217     kDNSServiceErr_Incompatible              = -65551,  /* client library incompatible with daemon */
6334b22b933Srs200217     kDNSServiceErr_BadInterfaceIndex         = -65552,
6344b22b933Srs200217     kDNSServiceErr_Refused                   = -65553,
6354b22b933Srs200217     kDNSServiceErr_NoSuchRecord              = -65554,
6364b22b933Srs200217     kDNSServiceErr_NoAuth                    = -65555,
6374b22b933Srs200217     kDNSServiceErr_NoSuchKey                 = -65556,
6384b22b933Srs200217     kDNSServiceErr_NATTraversal              = -65557,
6394b22b933Srs200217     kDNSServiceErr_DoubleNAT                 = -65558,
640*5ffb0c9bSToomas Soome     kDNSServiceErr_BadTime                   = -65559,  /* Codes up to here existed in Tiger */
641*5ffb0c9bSToomas Soome     kDNSServiceErr_BadSig                    = -65560,
642*5ffb0c9bSToomas Soome     kDNSServiceErr_BadKey                    = -65561,
643*5ffb0c9bSToomas Soome     kDNSServiceErr_Transient                 = -65562,
644*5ffb0c9bSToomas Soome     kDNSServiceErr_ServiceNotRunning         = -65563,  /* Background daemon not running */
645*5ffb0c9bSToomas Soome     kDNSServiceErr_NATPortMappingUnsupported = -65564,  /* NAT doesn't support PCP, NAT-PMP or UPnP */
646*5ffb0c9bSToomas Soome     kDNSServiceErr_NATPortMappingDisabled    = -65565,  /* NAT supports PCP, NAT-PMP or UPnP, but it's disabled by the administrator */
647*5ffb0c9bSToomas Soome     kDNSServiceErr_NoRouter                  = -65566,  /* No router currently configured (probably no network connectivity) */
648*5ffb0c9bSToomas Soome     kDNSServiceErr_PollingMode               = -65567,
649*5ffb0c9bSToomas Soome     kDNSServiceErr_Timeout                   = -65568
650*5ffb0c9bSToomas Soome 
6514b22b933Srs200217                                                /* mDNS Error codes are in the range
6524b22b933Srs200217                                                 * FFFE FF00 (-65792) to FFFE FFFF (-65537) */
6534b22b933Srs200217 };
6544b22b933Srs200217 
6554b22b933Srs200217 /* Maximum length, in bytes, of a service name represented as a */
6564b22b933Srs200217 /* literal C-String, including the terminating NULL at the end. */
6574b22b933Srs200217 
6584b22b933Srs200217 #define kDNSServiceMaxServiceName 64
6594b22b933Srs200217 
6604b22b933Srs200217 /* Maximum length, in bytes, of a domain name represented as an *escaped* C-String */
6614b22b933Srs200217 /* including the final trailing dot, and the C-String terminating NULL at the end. */
6624b22b933Srs200217 
663*5ffb0c9bSToomas Soome #define kDNSServiceMaxDomainName 1009
6644b22b933Srs200217 
6654b22b933Srs200217 /*
6664b22b933Srs200217  * Notes on DNS Name Escaping
6674b22b933Srs200217  *   -- or --
668*5ffb0c9bSToomas Soome  * "Why is kDNSServiceMaxDomainName 1009, when the maximum legal domain name is 256 bytes?"
6694b22b933Srs200217  *
670*5ffb0c9bSToomas Soome  * All strings used in the DNS-SD APIs are UTF-8 strings. Apart from the exceptions noted below,
671*5ffb0c9bSToomas Soome  * the APIs expect the strings to be properly escaped, using the conventional DNS escaping rules:
6724b22b933Srs200217  *
6734b22b933Srs200217  *   '\\' represents a single literal '\' in the name
6744b22b933Srs200217  *   '\.' represents a single literal '.' in the name
6754b22b933Srs200217  *   '\ddd', where ddd is a three-digit decimal value from 000 to 255,
6764b22b933Srs200217  *        represents a single literal byte with that value.
6774b22b933Srs200217  *   A bare unescaped '.' is a label separator, marking a boundary between domain and subdomain.
6784b22b933Srs200217  *
6794b22b933Srs200217  * The exceptions, that do not use escaping, are the routines where the full
6804b22b933Srs200217  * DNS name of a resource is broken, for convenience, into servicename/regtype/domain.
6814b22b933Srs200217  * In these routines, the "servicename" is NOT escaped. It does not need to be, since
6824b22b933Srs200217  * it is, by definition, just a single literal string. Any characters in that string
6834b22b933Srs200217  * represent exactly what they are. The "regtype" portion is, technically speaking,
6844b22b933Srs200217  * escaped, but since legal regtypes are only allowed to contain letters, digits,
6854b22b933Srs200217  * and hyphens, there is nothing to escape, so the issue is moot. The "domain"
6864b22b933Srs200217  * portion is also escaped, though most domains in use on the public Internet
6874b22b933Srs200217  * today, like regtypes, don't contain any characters that need to be escaped.
6884b22b933Srs200217  * As DNS-SD becomes more popular, rich-text domains for service discovery will
6894b22b933Srs200217  * become common, so software should be written to cope with domains with escaping.
6904b22b933Srs200217  *
6914b22b933Srs200217  * The servicename may be up to 63 bytes of UTF-8 text (not counting the C-String
6924b22b933Srs200217  * terminating NULL at the end). The regtype is of the form _service._tcp or
693*5ffb0c9bSToomas Soome  * _service._udp, where the "service" part is 1-15 characters, which may be
6944b22b933Srs200217  * letters, digits, or hyphens. The domain part of the three-part name may be
6954b22b933Srs200217  * any legal domain, providing that the resulting servicename+regtype+domain
696*5ffb0c9bSToomas Soome  * name does not exceed 256 bytes.
6974b22b933Srs200217  *
6984b22b933Srs200217  * For most software, these issues are transparent. When browsing, the discovered
6994b22b933Srs200217  * servicenames should simply be displayed as-is. When resolving, the discovered
7004b22b933Srs200217  * servicename/regtype/domain are simply passed unchanged to DNSServiceResolve().
7014b22b933Srs200217  * When a DNSServiceResolve() succeeds, the returned fullname is already in
7024b22b933Srs200217  * the correct format to pass to standard system DNS APIs such as res_query().
7034b22b933Srs200217  * For converting from servicename/regtype/domain to a single properly-escaped
7044b22b933Srs200217  * full DNS name, the helper function DNSServiceConstructFullName() is provided.
7054b22b933Srs200217  *
7064b22b933Srs200217  * The following (highly contrived) example illustrates the escaping process.
7074b22b933Srs200217  * Suppose you have an service called "Dr. Smith\Dr. Johnson", of type "_ftp._tcp"
7084b22b933Srs200217  * in subdomain "4th. Floor" of subdomain "Building 2" of domain "apple.com."
7094b22b933Srs200217  * The full (escaped) DNS name of this service's SRV record would be:
7104b22b933Srs200217  * Dr\.\032Smith\\Dr\.\032Johnson._ftp._tcp.4th\.\032Floor.Building\0322.apple.com.
7114b22b933Srs200217  */
7124b22b933Srs200217 
7134b22b933Srs200217 
7144b22b933Srs200217 /*
7154b22b933Srs200217  * Constants for specifying an interface index
7164b22b933Srs200217  *
7174b22b933Srs200217  * Specific interface indexes are identified via a 32-bit unsigned integer returned
7184b22b933Srs200217  * by the if_nametoindex() family of calls.
7194b22b933Srs200217  *
7204b22b933Srs200217  * If the client passes 0 for interface index, that means "do the right thing",
7214b22b933Srs200217  * which (at present) means, "if the name is in an mDNS local multicast domain
7224b22b933Srs200217  * (e.g. 'local.', '254.169.in-addr.arpa.', '{8,9,A,B}.E.F.ip6.arpa.') then multicast
7234b22b933Srs200217  * on all applicable interfaces, otherwise send via unicast to the appropriate
7244b22b933Srs200217  * DNS server." Normally, most clients will use 0 for interface index to
7254b22b933Srs200217  * automatically get the default sensible behaviour.
7264b22b933Srs200217  *
7274b22b933Srs200217  * If the client passes a positive interface index, then for multicast names that
7284b22b933Srs200217  * indicates to do the operation only on that one interface. For unicast names the
7294b22b933Srs200217  * interface index is ignored unless kDNSServiceFlagsForceMulticast is also set.
7304b22b933Srs200217  *
7314b22b933Srs200217  * If the client passes kDNSServiceInterfaceIndexLocalOnly when registering
7324b22b933Srs200217  * a service, then that service will be found *only* by other local clients
7334b22b933Srs200217  * on the same machine that are browsing using kDNSServiceInterfaceIndexLocalOnly
7344b22b933Srs200217  * or kDNSServiceInterfaceIndexAny.
7354b22b933Srs200217  * If a client has a 'private' service, accessible only to other processes
7364b22b933Srs200217  * running on the same machine, this allows the client to advertise that service
7374b22b933Srs200217  * in a way such that it does not inadvertently appear in service lists on
7384b22b933Srs200217  * all the other machines on the network.
7394b22b933Srs200217  *
7404b22b933Srs200217  * If the client passes kDNSServiceInterfaceIndexLocalOnly when browsing
7414b22b933Srs200217  * then it will find *all* records registered on that same local machine.
7424b22b933Srs200217  * Clients explicitly wishing to discover *only* LocalOnly services can
7434b22b933Srs200217  * accomplish this by inspecting the interfaceIndex of each service reported
7444b22b933Srs200217  * to their DNSServiceBrowseReply() callback function, and discarding those
7454b22b933Srs200217  * where the interface index is not kDNSServiceInterfaceIndexLocalOnly.
746*5ffb0c9bSToomas Soome  *
747*5ffb0c9bSToomas Soome  * kDNSServiceInterfaceIndexP2P is meaningful only in Browse, QueryRecord, Register,
748*5ffb0c9bSToomas Soome  * and Resolve operations. It should not be used in other DNSService APIs.
749*5ffb0c9bSToomas Soome  *
750*5ffb0c9bSToomas Soome  * - If kDNSServiceInterfaceIndexP2P is passed to DNSServiceBrowse or
751*5ffb0c9bSToomas Soome  *   DNSServiceQueryRecord, it restricts the operation to P2P.
752*5ffb0c9bSToomas Soome  *
753*5ffb0c9bSToomas Soome  * - If kDNSServiceInterfaceIndexP2P is passed to DNSServiceRegister, it is
754*5ffb0c9bSToomas Soome  *   mapped internally to kDNSServiceInterfaceIndexAny with the kDNSServiceFlagsIncludeP2P
755*5ffb0c9bSToomas Soome  *   set.
756*5ffb0c9bSToomas Soome  *
757*5ffb0c9bSToomas Soome  * - If kDNSServiceInterfaceIndexP2P is passed to DNSServiceResolve, it is
758*5ffb0c9bSToomas Soome  *   mapped internally to kDNSServiceInterfaceIndexAny with the kDNSServiceFlagsIncludeP2P
759*5ffb0c9bSToomas Soome  *   set, because resolving a P2P service may create and/or enable an interface whose
760*5ffb0c9bSToomas Soome  *   index is not known a priori. The resolve callback will indicate the index of the
761*5ffb0c9bSToomas Soome  *   interface via which the service can be accessed.
762*5ffb0c9bSToomas Soome  *
763*5ffb0c9bSToomas Soome  * If applications pass kDNSServiceInterfaceIndexAny to DNSServiceBrowse
764*5ffb0c9bSToomas Soome  * or DNSServiceQueryRecord, they must set the kDNSServiceFlagsIncludeP2P flag
765*5ffb0c9bSToomas Soome  * to include P2P. In this case, if a service instance or the record being queried
766*5ffb0c9bSToomas Soome  * is found over P2P, the resulting ADD event will indicate kDNSServiceInterfaceIndexP2P
767*5ffb0c9bSToomas Soome  * as the interface index.
7684b22b933Srs200217  */
7694b22b933Srs200217 
7704b22b933Srs200217 #define kDNSServiceInterfaceIndexAny 0
7714b22b933Srs200217 #define kDNSServiceInterfaceIndexLocalOnly ((uint32_t)-1)
772*5ffb0c9bSToomas Soome #define kDNSServiceInterfaceIndexUnicast   ((uint32_t)-2)
773*5ffb0c9bSToomas Soome #define kDNSServiceInterfaceIndexP2P       ((uint32_t)-3)
7744b22b933Srs200217 
7754b22b933Srs200217 typedef uint32_t DNSServiceFlags;
776*5ffb0c9bSToomas Soome typedef uint32_t DNSServiceProtocol;
7774b22b933Srs200217 typedef int32_t DNSServiceErrorType;
7784b22b933Srs200217 
7794b22b933Srs200217 
7804b22b933Srs200217 /*********************************************************************************************
7814b22b933Srs200217 *
782*5ffb0c9bSToomas Soome * Version checking
783*5ffb0c9bSToomas Soome *
784*5ffb0c9bSToomas Soome *********************************************************************************************/
785*5ffb0c9bSToomas Soome 
786*5ffb0c9bSToomas Soome /* DNSServiceGetProperty() Parameters:
787*5ffb0c9bSToomas Soome  *
788*5ffb0c9bSToomas Soome  * property:        The requested property.
789*5ffb0c9bSToomas Soome  *                  Currently the only property defined is kDNSServiceProperty_DaemonVersion.
790*5ffb0c9bSToomas Soome  *
791*5ffb0c9bSToomas Soome  * result:          Place to store result.
792*5ffb0c9bSToomas Soome  *                  For retrieving DaemonVersion, this should be the address of a uint32_t.
793*5ffb0c9bSToomas Soome  *
794*5ffb0c9bSToomas Soome  * size:            Pointer to uint32_t containing size of the result location.
795*5ffb0c9bSToomas Soome  *                  For retrieving DaemonVersion, this should be sizeof(uint32_t).
796*5ffb0c9bSToomas Soome  *                  On return the uint32_t is updated to the size of the data returned.
797*5ffb0c9bSToomas Soome  *                  For DaemonVersion, the returned size is always sizeof(uint32_t), but
798*5ffb0c9bSToomas Soome  *                  future properties could be defined which return variable-sized results.
799*5ffb0c9bSToomas Soome  *
800*5ffb0c9bSToomas Soome  * return value:    Returns kDNSServiceErr_NoError on success, or kDNSServiceErr_ServiceNotRunning
801*5ffb0c9bSToomas Soome  *                  if the daemon (or "system service" on Windows) is not running.
802*5ffb0c9bSToomas Soome  */
803*5ffb0c9bSToomas Soome 
804*5ffb0c9bSToomas Soome DNSServiceErrorType DNSSD_API DNSServiceGetProperty
805*5ffb0c9bSToomas Soome (
806*5ffb0c9bSToomas Soome     const char *property,  /* Requested property (i.e. kDNSServiceProperty_DaemonVersion) */
807*5ffb0c9bSToomas Soome     void       *result,    /* Pointer to place to store result */
808*5ffb0c9bSToomas Soome     uint32_t   *size       /* size of result location */
809*5ffb0c9bSToomas Soome );
810*5ffb0c9bSToomas Soome 
811*5ffb0c9bSToomas Soome /*
812*5ffb0c9bSToomas Soome  * When requesting kDNSServiceProperty_DaemonVersion, the result pointer must point
813*5ffb0c9bSToomas Soome  * to a 32-bit unsigned integer, and the size parameter must be set to sizeof(uint32_t).
814*5ffb0c9bSToomas Soome  *
815*5ffb0c9bSToomas Soome  * On return, the 32-bit unsigned integer contains the API version number
816*5ffb0c9bSToomas Soome  *
817*5ffb0c9bSToomas Soome  * For example, Mac OS X 10.4.9 has API version 1080400.
818*5ffb0c9bSToomas Soome  * This allows applications to do simple greater-than and less-than comparisons:
819*5ffb0c9bSToomas Soome  * e.g. an application that requires at least API version 1080400 can check:
820*5ffb0c9bSToomas Soome  *   if (version >= 1080400) ...
821*5ffb0c9bSToomas Soome  *
822*5ffb0c9bSToomas Soome  * Example usage:
823*5ffb0c9bSToomas Soome  * uint32_t version;
824*5ffb0c9bSToomas Soome  * uint32_t size = sizeof(version);
825*5ffb0c9bSToomas Soome  * DNSServiceErrorType err = DNSServiceGetProperty(kDNSServiceProperty_DaemonVersion, &version, &size);
826*5ffb0c9bSToomas Soome  * if (!err) printf("DNS_SD API version is %d.%d\n", version / 10000, version / 100 % 100);
827*5ffb0c9bSToomas Soome  */
828*5ffb0c9bSToomas Soome 
829*5ffb0c9bSToomas Soome #define kDNSServiceProperty_DaemonVersion "DaemonVersion"
830*5ffb0c9bSToomas Soome 
831*5ffb0c9bSToomas Soome 
832*5ffb0c9bSToomas Soome // Map the source port of the local UDP socket that was opened for sending the DNS query
833*5ffb0c9bSToomas Soome // to the process ID of the application that triggered the DNS resolution.
834*5ffb0c9bSToomas Soome //
835*5ffb0c9bSToomas Soome /* DNSServiceGetPID() Parameters:
836*5ffb0c9bSToomas Soome  *
837*5ffb0c9bSToomas Soome  * srcport:         Source port (in network byte order) of the UDP socket that was created by
838*5ffb0c9bSToomas Soome  *                  the daemon to send the DNS query on the wire.
839*5ffb0c9bSToomas Soome  *
840*5ffb0c9bSToomas Soome  * pid:             Process ID of the application that started the name resolution which triggered
841*5ffb0c9bSToomas Soome  *                  the daemon to send the query on the wire. The value can be -1 if the srcport
842*5ffb0c9bSToomas Soome  *                  cannot be mapped.
843*5ffb0c9bSToomas Soome  *
844*5ffb0c9bSToomas Soome  * return value:    Returns kDNSServiceErr_NoError on success, or kDNSServiceErr_ServiceNotRunning
845*5ffb0c9bSToomas Soome  *                  if the daemon is not running. The value of the pid is undefined if the return
846*5ffb0c9bSToomas Soome  *                  value has error.
847*5ffb0c9bSToomas Soome  */
848*5ffb0c9bSToomas Soome DNSServiceErrorType DNSSD_API DNSServiceGetPID
849*5ffb0c9bSToomas Soome (
850*5ffb0c9bSToomas Soome     uint16_t srcport,
851*5ffb0c9bSToomas Soome     int32_t *pid
852*5ffb0c9bSToomas Soome );
853*5ffb0c9bSToomas Soome 
854*5ffb0c9bSToomas Soome /*********************************************************************************************
855*5ffb0c9bSToomas Soome *
8564b22b933Srs200217 * Unix Domain Socket access, DNSServiceRef deallocation, and data processing functions
8574b22b933Srs200217 *
8584b22b933Srs200217 *********************************************************************************************/
8594b22b933Srs200217 
8604b22b933Srs200217 /* DNSServiceRefSockFD()
8614b22b933Srs200217  *
8624b22b933Srs200217  * Access underlying Unix domain socket for an initialized DNSServiceRef.
863*5ffb0c9bSToomas Soome  * The DNS Service Discovery implementation uses this socket to communicate between the client and
864*5ffb0c9bSToomas Soome  * the daemon. The application MUST NOT directly read from or write to this socket.
865*5ffb0c9bSToomas Soome  * Access to the socket is provided so that it can be used as a kqueue event source, a CFRunLoop
866*5ffb0c9bSToomas Soome  * event source, in a select() loop, etc. When the underlying event management subsystem (kqueue/
867*5ffb0c9bSToomas Soome  * select/CFRunLoop etc.) indicates to the client that data is available for reading on the
868*5ffb0c9bSToomas Soome  * socket, the client should call DNSServiceProcessResult(), which will extract the daemon's
869*5ffb0c9bSToomas Soome  * reply from the socket, and pass it to the appropriate application callback. By using a run
870*5ffb0c9bSToomas Soome  * loop or select(), results from the daemon can be processed asynchronously. Alternatively,
871*5ffb0c9bSToomas Soome  * a client can choose to fork a thread and have it loop calling "DNSServiceProcessResult(ref);"
872*5ffb0c9bSToomas Soome  * If DNSServiceProcessResult() is called when no data is available for reading on the socket, it
873*5ffb0c9bSToomas Soome  * will block until data does become available, and then process the data and return to the caller.
874*5ffb0c9bSToomas Soome  * The application is reponsible for checking the return value of DNSServiceProcessResult() to determine
875*5ffb0c9bSToomas Soome  * if the socket is valid and if it should continue to process data on the socket.
876*5ffb0c9bSToomas Soome  * When data arrives on the socket, the client is responsible for calling DNSServiceProcessResult(ref)
877*5ffb0c9bSToomas Soome  * in a timely fashion -- if the client allows a large backlog of data to build up the daemon
878*5ffb0c9bSToomas Soome  * may terminate the connection.
8794b22b933Srs200217  *
8804b22b933Srs200217  * sdRef:           A DNSServiceRef initialized by any of the DNSService calls.
8814b22b933Srs200217  *
8824b22b933Srs200217  * return value:    The DNSServiceRef's underlying socket descriptor, or -1 on
8834b22b933Srs200217  *                  error.
8844b22b933Srs200217  */
8854b22b933Srs200217 
8864b22b933Srs200217 int DNSSD_API DNSServiceRefSockFD(DNSServiceRef sdRef);
8874b22b933Srs200217 
8884b22b933Srs200217 
8894b22b933Srs200217 /* DNSServiceProcessResult()
8904b22b933Srs200217  *
8914b22b933Srs200217  * Read a reply from the daemon, calling the appropriate application callback. This call will
8924b22b933Srs200217  * block until the daemon's response is received. Use DNSServiceRefSockFD() in
8934b22b933Srs200217  * conjunction with a run loop or select() to determine the presence of a response from the
8944b22b933Srs200217  * server before calling this function to process the reply without blocking. Call this function
8954b22b933Srs200217  * at any point if it is acceptable to block until the daemon's response arrives. Note that the
8964b22b933Srs200217  * client is responsible for ensuring that DNSServiceProcessResult() is called whenever there is
8974b22b933Srs200217  * a reply from the daemon - the daemon may terminate its connection with a client that does not
8984b22b933Srs200217  * process the daemon's responses.
8994b22b933Srs200217  *
9004b22b933Srs200217  * sdRef:           A DNSServiceRef initialized by any of the DNSService calls
9014b22b933Srs200217  *                  that take a callback parameter.
9024b22b933Srs200217  *
9034b22b933Srs200217  * return value:    Returns kDNSServiceErr_NoError on success, otherwise returns
9044b22b933Srs200217  *                  an error code indicating the specific failure that occurred.
9054b22b933Srs200217  */
9064b22b933Srs200217 
9074b22b933Srs200217 DNSServiceErrorType DNSSD_API DNSServiceProcessResult(DNSServiceRef sdRef);
9084b22b933Srs200217 
9094b22b933Srs200217 
9104b22b933Srs200217 /* DNSServiceRefDeallocate()
9114b22b933Srs200217  *
9124b22b933Srs200217  * Terminate a connection with the daemon and free memory associated with the DNSServiceRef.
9134b22b933Srs200217  * Any services or records registered with this DNSServiceRef will be deregistered. Any
9144b22b933Srs200217  * Browse, Resolve, or Query operations called with this reference will be terminated.
9154b22b933Srs200217  *
9164b22b933Srs200217  * Note: If the reference's underlying socket is used in a run loop or select() call, it should
9174b22b933Srs200217  * be removed BEFORE DNSServiceRefDeallocate() is called, as this function closes the reference's
9184b22b933Srs200217  * socket.
9194b22b933Srs200217  *
9204b22b933Srs200217  * Note: If the reference was initialized with DNSServiceCreateConnection(), any DNSRecordRefs
9214b22b933Srs200217  * created via this reference will be invalidated by this call - the resource records are
9224b22b933Srs200217  * deregistered, and their DNSRecordRefs may not be used in subsequent functions. Similarly,
9234b22b933Srs200217  * if the reference was initialized with DNSServiceRegister, and an extra resource record was
9244b22b933Srs200217  * added to the service via DNSServiceAddRecord(), the DNSRecordRef created by the Add() call
9254b22b933Srs200217  * is invalidated when this function is called - the DNSRecordRef may not be used in subsequent
9264b22b933Srs200217  * functions.
9274b22b933Srs200217  *
928*5ffb0c9bSToomas Soome  * Note: This call is to be used only with the DNSServiceRef defined by this API.
9294b22b933Srs200217  *
9304b22b933Srs200217  * sdRef:           A DNSServiceRef initialized by any of the DNSService calls.
9314b22b933Srs200217  *
9324b22b933Srs200217  */
9334b22b933Srs200217 
9344b22b933Srs200217 void DNSSD_API DNSServiceRefDeallocate(DNSServiceRef sdRef);
9354b22b933Srs200217 
9364b22b933Srs200217 
9374b22b933Srs200217 /*********************************************************************************************
9384b22b933Srs200217 *
9394b22b933Srs200217 * Domain Enumeration
9404b22b933Srs200217 *
9414b22b933Srs200217 *********************************************************************************************/
9424b22b933Srs200217 
9434b22b933Srs200217 /* DNSServiceEnumerateDomains()
9444b22b933Srs200217  *
9454b22b933Srs200217  * Asynchronously enumerate domains available for browsing and registration.
9464b22b933Srs200217  *
9474b22b933Srs200217  * The enumeration MUST be cancelled via DNSServiceRefDeallocate() when no more domains
9484b22b933Srs200217  * are to be found.
9494b22b933Srs200217  *
9504b22b933Srs200217  * Note that the names returned are (like all of DNS-SD) UTF-8 strings,
9514b22b933Srs200217  * and are escaped using standard DNS escaping rules.
9524b22b933Srs200217  * (See "Notes on DNS Name Escaping" earlier in this file for more details.)
9534b22b933Srs200217  * A graphical browser displaying a hierarchical tree-structured view should cut
9544b22b933Srs200217  * the names at the bare dots to yield individual labels, then de-escape each
9554b22b933Srs200217  * label according to the escaping rules, and then display the resulting UTF-8 text.
9564b22b933Srs200217  *
9574b22b933Srs200217  * DNSServiceDomainEnumReply Callback Parameters:
9584b22b933Srs200217  *
9594b22b933Srs200217  * sdRef:           The DNSServiceRef initialized by DNSServiceEnumerateDomains().
9604b22b933Srs200217  *
9614b22b933Srs200217  * flags:           Possible values are:
9624b22b933Srs200217  *                  kDNSServiceFlagsMoreComing
9634b22b933Srs200217  *                  kDNSServiceFlagsAdd
9644b22b933Srs200217  *                  kDNSServiceFlagsDefault
9654b22b933Srs200217  *
9664b22b933Srs200217  * interfaceIndex:  Specifies the interface on which the domain exists. (The index for a given
9674b22b933Srs200217  *                  interface is determined via the if_nametoindex() family of calls.)
9684b22b933Srs200217  *
9694b22b933Srs200217  * errorCode:       Will be kDNSServiceErr_NoError (0) on success, otherwise indicates
9704b22b933Srs200217  *                  the failure that occurred (other parameters are undefined if errorCode is nonzero).
9714b22b933Srs200217  *
9724b22b933Srs200217  * replyDomain:     The name of the domain.
9734b22b933Srs200217  *
9744b22b933Srs200217  * context:         The context pointer passed to DNSServiceEnumerateDomains.
9754b22b933Srs200217  *
9764b22b933Srs200217  */
9774b22b933Srs200217 
9784b22b933Srs200217 typedef void (DNSSD_API *DNSServiceDomainEnumReply)
9794b22b933Srs200217 (
9804b22b933Srs200217     DNSServiceRef sdRef,
9814b22b933Srs200217     DNSServiceFlags flags,
9824b22b933Srs200217     uint32_t interfaceIndex,
9834b22b933Srs200217     DNSServiceErrorType errorCode,
9844b22b933Srs200217     const char                          *replyDomain,
9854b22b933Srs200217     void                                *context
9864b22b933Srs200217 );
9874b22b933Srs200217 
9884b22b933Srs200217 
9894b22b933Srs200217 /* DNSServiceEnumerateDomains() Parameters:
9904b22b933Srs200217  *
9914b22b933Srs200217  * sdRef:           A pointer to an uninitialized DNSServiceRef. If the call succeeds
9924b22b933Srs200217  *                  then it initializes the DNSServiceRef, returns kDNSServiceErr_NoError,
9934b22b933Srs200217  *                  and the enumeration operation will run indefinitely until the client
9944b22b933Srs200217  *                  terminates it by passing this DNSServiceRef to DNSServiceRefDeallocate().
9954b22b933Srs200217  *
9964b22b933Srs200217  * flags:           Possible values are:
9974b22b933Srs200217  *                  kDNSServiceFlagsBrowseDomains to enumerate domains recommended for browsing.
9984b22b933Srs200217  *                  kDNSServiceFlagsRegistrationDomains to enumerate domains recommended
9994b22b933Srs200217  *                  for registration.
10004b22b933Srs200217  *
10014b22b933Srs200217  * interfaceIndex:  If non-zero, specifies the interface on which to look for domains.
10024b22b933Srs200217  *                  (the index for a given interface is determined via the if_nametoindex()
10034b22b933Srs200217  *                  family of calls.) Most applications will pass 0 to enumerate domains on
10044b22b933Srs200217  *                  all interfaces. See "Constants for specifying an interface index" for more details.
10054b22b933Srs200217  *
10064b22b933Srs200217  * callBack:        The function to be called when a domain is found or the call asynchronously
10074b22b933Srs200217  *                  fails.
10084b22b933Srs200217  *
10094b22b933Srs200217  * context:         An application context pointer which is passed to the callback function
10104b22b933Srs200217  *                  (may be NULL).
10114b22b933Srs200217  *
1012*5ffb0c9bSToomas Soome  * return value:    Returns kDNSServiceErr_NoError on success (any subsequent, asynchronous
10134b22b933Srs200217  *                  errors are delivered to the callback), otherwise returns an error code indicating
10144b22b933Srs200217  *                  the error that occurred (the callback is not invoked and the DNSServiceRef
1015*5ffb0c9bSToomas Soome  *                  is not initialized).
10164b22b933Srs200217  */
10174b22b933Srs200217 
10184b22b933Srs200217 DNSServiceErrorType DNSSD_API DNSServiceEnumerateDomains
10194b22b933Srs200217 (
10204b22b933Srs200217     DNSServiceRef                       *sdRef,
10214b22b933Srs200217     DNSServiceFlags flags,
10224b22b933Srs200217     uint32_t interfaceIndex,
10234b22b933Srs200217     DNSServiceDomainEnumReply callBack,
10244b22b933Srs200217     void                                *context  /* may be NULL */
10254b22b933Srs200217 );
10264b22b933Srs200217 
10274b22b933Srs200217 
10284b22b933Srs200217 /*********************************************************************************************
10294b22b933Srs200217 *
10304b22b933Srs200217 *  Service Registration
10314b22b933Srs200217 *
10324b22b933Srs200217 *********************************************************************************************/
10334b22b933Srs200217 
10344b22b933Srs200217 /* Register a service that is discovered via Browse() and Resolve() calls.
10354b22b933Srs200217  *
10364b22b933Srs200217  * DNSServiceRegisterReply() Callback Parameters:
10374b22b933Srs200217  *
10384b22b933Srs200217  * sdRef:           The DNSServiceRef initialized by DNSServiceRegister().
10394b22b933Srs200217  *
1040*5ffb0c9bSToomas Soome  * flags:           When a name is successfully registered, the callback will be
1041*5ffb0c9bSToomas Soome  *                  invoked with the kDNSServiceFlagsAdd flag set. When Wide-Area
1042*5ffb0c9bSToomas Soome  *                  DNS-SD is in use, it is possible for a single service to get
1043*5ffb0c9bSToomas Soome  *                  more than one success callback (e.g. one in the "local" multicast
1044*5ffb0c9bSToomas Soome  *                  DNS domain, and another in a wide-area unicast DNS domain).
1045*5ffb0c9bSToomas Soome  *                  If a successfully-registered name later suffers a name conflict
1046*5ffb0c9bSToomas Soome  *                  or similar problem and has to be deregistered, the callback will
1047*5ffb0c9bSToomas Soome  *                  be invoked with the kDNSServiceFlagsAdd flag not set. The callback
1048*5ffb0c9bSToomas Soome  *                  is *not* invoked in the case where the caller explicitly terminates
1049*5ffb0c9bSToomas Soome  *                  the service registration by calling DNSServiceRefDeallocate(ref);
10504b22b933Srs200217  *
10514b22b933Srs200217  * errorCode:       Will be kDNSServiceErr_NoError on success, otherwise will
10524b22b933Srs200217  *                  indicate the failure that occurred (including name conflicts,
10534b22b933Srs200217  *                  if the kDNSServiceFlagsNoAutoRename flag was used when registering.)
10544b22b933Srs200217  *                  Other parameters are undefined if errorCode is nonzero.
10554b22b933Srs200217  *
10564b22b933Srs200217  * name:            The service name registered (if the application did not specify a name in
10574b22b933Srs200217  *                  DNSServiceRegister(), this indicates what name was automatically chosen).
10584b22b933Srs200217  *
10594b22b933Srs200217  * regtype:         The type of service registered, as it was passed to the callout.
10604b22b933Srs200217  *
10614b22b933Srs200217  * domain:          The domain on which the service was registered (if the application did not
10624b22b933Srs200217  *                  specify a domain in DNSServiceRegister(), this indicates the default domain
10634b22b933Srs200217  *                  on which the service was registered).
10644b22b933Srs200217  *
10654b22b933Srs200217  * context:         The context pointer that was passed to the callout.
10664b22b933Srs200217  *
10674b22b933Srs200217  */
10684b22b933Srs200217 
10694b22b933Srs200217 typedef void (DNSSD_API *DNSServiceRegisterReply)
10704b22b933Srs200217 (
10714b22b933Srs200217     DNSServiceRef sdRef,
10724b22b933Srs200217     DNSServiceFlags flags,
10734b22b933Srs200217     DNSServiceErrorType errorCode,
10744b22b933Srs200217     const char                          *name,
10754b22b933Srs200217     const char                          *regtype,
10764b22b933Srs200217     const char                          *domain,
10774b22b933Srs200217     void                                *context
10784b22b933Srs200217 );
10794b22b933Srs200217 
10804b22b933Srs200217 
10814b22b933Srs200217 /* DNSServiceRegister() Parameters:
10824b22b933Srs200217  *
10834b22b933Srs200217  * sdRef:           A pointer to an uninitialized DNSServiceRef. If the call succeeds
10844b22b933Srs200217  *                  then it initializes the DNSServiceRef, returns kDNSServiceErr_NoError,
10854b22b933Srs200217  *                  and the registration will remain active indefinitely until the client
10864b22b933Srs200217  *                  terminates it by passing this DNSServiceRef to DNSServiceRefDeallocate().
10874b22b933Srs200217  *
10884b22b933Srs200217  * interfaceIndex:  If non-zero, specifies the interface on which to register the service
10894b22b933Srs200217  *                  (the index for a given interface is determined via the if_nametoindex()
10904b22b933Srs200217  *                  family of calls.) Most applications will pass 0 to register on all
10914b22b933Srs200217  *                  available interfaces. See "Constants for specifying an interface index" for more details.
10924b22b933Srs200217  *
10934b22b933Srs200217  * flags:           Indicates the renaming behavior on name conflict (most applications
10944b22b933Srs200217  *                  will pass 0). See flag definitions above for details.
10954b22b933Srs200217  *
10964b22b933Srs200217  * name:            If non-NULL, specifies the service name to be registered.
10974b22b933Srs200217  *                  Most applications will not specify a name, in which case the computer
10984b22b933Srs200217  *                  name is used (this name is communicated to the client via the callback).
10994b22b933Srs200217  *                  If a name is specified, it must be 1-63 bytes of UTF-8 text.
11004b22b933Srs200217  *                  If the name is longer than 63 bytes it will be automatically truncated
11014b22b933Srs200217  *                  to a legal length, unless the NoAutoRename flag is set,
11024b22b933Srs200217  *                  in which case kDNSServiceErr_BadParam will be returned.
11034b22b933Srs200217  *
11044b22b933Srs200217  * regtype:         The service type followed by the protocol, separated by a dot
11054b22b933Srs200217  *                  (e.g. "_ftp._tcp"). The service type must be an underscore, followed
1106*5ffb0c9bSToomas Soome  *                  by 1-15 characters, which may be letters, digits, or hyphens.
11074b22b933Srs200217  *                  The transport protocol must be "_tcp" or "_udp". New service types
11084b22b933Srs200217  *                  should be registered at <http://www.dns-sd.org/ServiceTypes.html>.
11094b22b933Srs200217  *
1110*5ffb0c9bSToomas Soome  *                  Additional subtypes of the primary service type (where a service
1111*5ffb0c9bSToomas Soome  *                  type has defined subtypes) follow the primary service type in a
1112*5ffb0c9bSToomas Soome  *                  comma-separated list, with no additional spaces, e.g.
1113*5ffb0c9bSToomas Soome  *                      "_primarytype._tcp,_subtype1,_subtype2,_subtype3"
1114*5ffb0c9bSToomas Soome  *                  Subtypes provide a mechanism for filtered browsing: A client browsing
1115*5ffb0c9bSToomas Soome  *                  for "_primarytype._tcp" will discover all instances of this type;
1116*5ffb0c9bSToomas Soome  *                  a client browsing for "_primarytype._tcp,_subtype2" will discover only
1117*5ffb0c9bSToomas Soome  *                  those instances that were registered with "_subtype2" in their list of
1118*5ffb0c9bSToomas Soome  *                  registered subtypes.
1119*5ffb0c9bSToomas Soome  *
1120*5ffb0c9bSToomas Soome  *                  The subtype mechanism can be illustrated with some examples using the
1121*5ffb0c9bSToomas Soome  *                  dns-sd command-line tool:
1122*5ffb0c9bSToomas Soome  *
1123*5ffb0c9bSToomas Soome  *                  % dns-sd -R Simple _test._tcp "" 1001 &
1124*5ffb0c9bSToomas Soome  *                  % dns-sd -R Better _test._tcp,HasFeatureA "" 1002 &
1125*5ffb0c9bSToomas Soome  *                  % dns-sd -R Best   _test._tcp,HasFeatureA,HasFeatureB "" 1003 &
1126*5ffb0c9bSToomas Soome  *
1127*5ffb0c9bSToomas Soome  *                  Now:
1128*5ffb0c9bSToomas Soome  *                  % dns-sd -B _test._tcp             # will find all three services
1129*5ffb0c9bSToomas Soome  *                  % dns-sd -B _test._tcp,HasFeatureA # finds "Better" and "Best"
1130*5ffb0c9bSToomas Soome  *                  % dns-sd -B _test._tcp,HasFeatureB # finds only "Best"
1131*5ffb0c9bSToomas Soome  *
1132*5ffb0c9bSToomas Soome  *                  Subtype labels may be up to 63 bytes long, and may contain any eight-
1133*5ffb0c9bSToomas Soome  *                  bit byte values, including zero bytes. However, due to the nature of
1134*5ffb0c9bSToomas Soome  *                  using a C-string-based API, conventional DNS escaping must be used for
1135*5ffb0c9bSToomas Soome  *                  dots ('.'), commas (','), backslashes ('\') and zero bytes, as shown below:
1136*5ffb0c9bSToomas Soome  *
1137*5ffb0c9bSToomas Soome  *                  % dns-sd -R Test '_test._tcp,s\.one,s\,two,s\\three,s\000four' local 123
1138*5ffb0c9bSToomas Soome  *
1139*5ffb0c9bSToomas Soome  *                  When a service is registered, all the clients browsing for the registered
1140*5ffb0c9bSToomas Soome  *                  type ("regtype") will discover it. If the discovery should be
1141*5ffb0c9bSToomas Soome  *                  restricted to a smaller set of well known peers, the service can be
1142*5ffb0c9bSToomas Soome  *                  registered with additional data (group identifier) that is known
1143*5ffb0c9bSToomas Soome  *                  only to a smaller set of peers. The group identifier should follow primary
1144*5ffb0c9bSToomas Soome  *                  service type using a colon (":") as a delimeter. If subtypes are also present,
1145*5ffb0c9bSToomas Soome  *                  it should be given before the subtype as shown below.
1146*5ffb0c9bSToomas Soome  *
1147*5ffb0c9bSToomas Soome  *                  % dns-sd -R _test1 _http._tcp:mygroup1 local 1001
1148*5ffb0c9bSToomas Soome  *                  % dns-sd -R _test2 _http._tcp:mygroup2 local 1001
1149*5ffb0c9bSToomas Soome  *                  % dns-sd -R _test3 _http._tcp:mygroup3,HasFeatureA local 1001
1150*5ffb0c9bSToomas Soome  *
1151*5ffb0c9bSToomas Soome  *                  Now:
1152*5ffb0c9bSToomas Soome  *                  % dns-sd -B _http._tcp:"mygroup1"                # will discover only test1
1153*5ffb0c9bSToomas Soome  *                  % dns-sd -B _http._tcp:"mygroup2"                # will discover only test2
1154*5ffb0c9bSToomas Soome  *                  % dns-sd -B _http._tcp:"mygroup3",HasFeatureA    # will discover only test3
1155*5ffb0c9bSToomas Soome  *
1156*5ffb0c9bSToomas Soome  *                  By specifying the group information, only the members of that group are
1157*5ffb0c9bSToomas Soome  *                  discovered.
1158*5ffb0c9bSToomas Soome  *
1159*5ffb0c9bSToomas Soome  *                  The group identifier itself is not sent in clear. Only a hash of the group
1160*5ffb0c9bSToomas Soome  *                  identifier is sent and the clients discover them anonymously. The group identifier
1161*5ffb0c9bSToomas Soome  *                  may be up to 256 bytes long and may contain any eight bit values except comma which
1162*5ffb0c9bSToomas Soome  *                  should be escaped.
1163*5ffb0c9bSToomas Soome  *
11644b22b933Srs200217  * domain:          If non-NULL, specifies the domain on which to advertise the service.
11654b22b933Srs200217  *                  Most applications will not specify a domain, instead automatically
11664b22b933Srs200217  *                  registering in the default domain(s).
11674b22b933Srs200217  *
11684b22b933Srs200217  * host:            If non-NULL, specifies the SRV target host name. Most applications
11694b22b933Srs200217  *                  will not specify a host, instead automatically using the machine's
11704b22b933Srs200217  *                  default host name(s). Note that specifying a non-NULL host does NOT
11714b22b933Srs200217  *                  create an address record for that host - the application is responsible
11724b22b933Srs200217  *                  for ensuring that the appropriate address record exists, or creating it
11734b22b933Srs200217  *                  via DNSServiceRegisterRecord().
11744b22b933Srs200217  *
11754b22b933Srs200217  * port:            The port, in network byte order, on which the service accepts connections.
11764b22b933Srs200217  *                  Pass 0 for a "placeholder" service (i.e. a service that will not be discovered
11774b22b933Srs200217  *                  by browsing, but will cause a name conflict if another client tries to
11784b22b933Srs200217  *                  register that same name). Most clients will not use placeholder services.
11794b22b933Srs200217  *
11804b22b933Srs200217  * txtLen:          The length of the txtRecord, in bytes. Must be zero if the txtRecord is NULL.
11814b22b933Srs200217  *
11824b22b933Srs200217  * txtRecord:       The TXT record rdata. A non-NULL txtRecord MUST be a properly formatted DNS
11834b22b933Srs200217  *                  TXT record, i.e. <length byte> <data> <length byte> <data> ...
11844b22b933Srs200217  *                  Passing NULL for the txtRecord is allowed as a synonym for txtLen=1, txtRecord="",
11854b22b933Srs200217  *                  i.e. it creates a TXT record of length one containing a single empty string.
11864b22b933Srs200217  *                  RFC 1035 doesn't allow a TXT record to contain *zero* strings, so a single empty
11874b22b933Srs200217  *                  string is the smallest legal DNS TXT record.
11884b22b933Srs200217  *                  As with the other parameters, the DNSServiceRegister call copies the txtRecord
11894b22b933Srs200217  *                  data; e.g. if you allocated the storage for the txtRecord parameter with malloc()
11904b22b933Srs200217  *                  then you can safely free that memory right after the DNSServiceRegister call returns.
11914b22b933Srs200217  *
11924b22b933Srs200217  * callBack:        The function to be called when the registration completes or asynchronously
11934b22b933Srs200217  *                  fails. The client MAY pass NULL for the callback -  The client will NOT be notified
11944b22b933Srs200217  *                  of the default values picked on its behalf, and the client will NOT be notified of any
11954b22b933Srs200217  *                  asynchronous errors (e.g. out of memory errors, etc.) that may prevent the registration
11964b22b933Srs200217  *                  of the service. The client may NOT pass the NoAutoRename flag if the callback is NULL.
11974b22b933Srs200217  *                  The client may still deregister the service at any time via DNSServiceRefDeallocate().
11984b22b933Srs200217  *
11994b22b933Srs200217  * context:         An application context pointer which is passed to the callback function
12004b22b933Srs200217  *                  (may be NULL).
12014b22b933Srs200217  *
1202*5ffb0c9bSToomas Soome  * return value:    Returns kDNSServiceErr_NoError on success (any subsequent, asynchronous
12034b22b933Srs200217  *                  errors are delivered to the callback), otherwise returns an error code indicating
12044b22b933Srs200217  *                  the error that occurred (the callback is never invoked and the DNSServiceRef
1205*5ffb0c9bSToomas Soome  *                  is not initialized).
12064b22b933Srs200217  */
12074b22b933Srs200217 
12084b22b933Srs200217 DNSServiceErrorType DNSSD_API DNSServiceRegister
12094b22b933Srs200217 (
12104b22b933Srs200217     DNSServiceRef                       *sdRef,
12114b22b933Srs200217     DNSServiceFlags flags,
12124b22b933Srs200217     uint32_t interfaceIndex,
12134b22b933Srs200217     const char                          *name,         /* may be NULL */
12144b22b933Srs200217     const char                          *regtype,
12154b22b933Srs200217     const char                          *domain,       /* may be NULL */
12164b22b933Srs200217     const char                          *host,         /* may be NULL */
1217*5ffb0c9bSToomas Soome     uint16_t port,                                     /* In network byte order */
12184b22b933Srs200217     uint16_t txtLen,
12194b22b933Srs200217     const void                          *txtRecord,    /* may be NULL */
12204b22b933Srs200217     DNSServiceRegisterReply callBack,                  /* may be NULL */
12214b22b933Srs200217     void                                *context       /* may be NULL */
12224b22b933Srs200217 );
12234b22b933Srs200217 
12244b22b933Srs200217 
12254b22b933Srs200217 /* DNSServiceAddRecord()
12264b22b933Srs200217  *
12274b22b933Srs200217  * Add a record to a registered service. The name of the record will be the same as the
12284b22b933Srs200217  * registered service's name.
12294b22b933Srs200217  * The record can later be updated or deregistered by passing the RecordRef initialized
12304b22b933Srs200217  * by this function to DNSServiceUpdateRecord() or DNSServiceRemoveRecord().
12314b22b933Srs200217  *
12324b22b933Srs200217  * Note that the DNSServiceAddRecord/UpdateRecord/RemoveRecord are *NOT* thread-safe
12334b22b933Srs200217  * with respect to a single DNSServiceRef. If you plan to have multiple threads
12344b22b933Srs200217  * in your program simultaneously add, update, or remove records from the same
12354b22b933Srs200217  * DNSServiceRef, then it's the caller's responsibility to use a mutext lock
12364b22b933Srs200217  * or take similar appropriate precautions to serialize those calls.
12374b22b933Srs200217  *
12384b22b933Srs200217  * Parameters;
12394b22b933Srs200217  *
12404b22b933Srs200217  * sdRef:           A DNSServiceRef initialized by DNSServiceRegister().
12414b22b933Srs200217  *
12424b22b933Srs200217  * RecordRef:       A pointer to an uninitialized DNSRecordRef. Upon succesfull completion of this
12434b22b933Srs200217  *                  call, this ref may be passed to DNSServiceUpdateRecord() or DNSServiceRemoveRecord().
12444b22b933Srs200217  *                  If the above DNSServiceRef is passed to DNSServiceRefDeallocate(), RecordRef is also
12454b22b933Srs200217  *                  invalidated and may not be used further.
12464b22b933Srs200217  *
12474b22b933Srs200217  * flags:           Currently ignored, reserved for future use.
12484b22b933Srs200217  *
12494b22b933Srs200217  * rrtype:          The type of the record (e.g. kDNSServiceType_TXT, kDNSServiceType_SRV, etc)
12504b22b933Srs200217  *
12514b22b933Srs200217  * rdlen:           The length, in bytes, of the rdata.
12524b22b933Srs200217  *
12534b22b933Srs200217  * rdata:           The raw rdata to be contained in the added resource record.
12544b22b933Srs200217  *
1255*5ffb0c9bSToomas Soome  * ttl:             The time to live of the resource record, in seconds.
1256*5ffb0c9bSToomas Soome  *                  Most clients should pass 0 to indicate that the system should
1257*5ffb0c9bSToomas Soome  *                  select a sensible default value.
12584b22b933Srs200217  *
12594b22b933Srs200217  * return value:    Returns kDNSServiceErr_NoError on success, otherwise returns an
12604b22b933Srs200217  *                  error code indicating the error that occurred (the RecordRef is not initialized).
12614b22b933Srs200217  */
12624b22b933Srs200217 
12634b22b933Srs200217 DNSServiceErrorType DNSSD_API DNSServiceAddRecord
12644b22b933Srs200217 (
12654b22b933Srs200217     DNSServiceRef sdRef,
12664b22b933Srs200217     DNSRecordRef                        *RecordRef,
12674b22b933Srs200217     DNSServiceFlags flags,
12684b22b933Srs200217     uint16_t rrtype,
12694b22b933Srs200217     uint16_t rdlen,
12704b22b933Srs200217     const void                          *rdata,
12714b22b933Srs200217     uint32_t ttl
12724b22b933Srs200217 );
12734b22b933Srs200217 
12744b22b933Srs200217 
12754b22b933Srs200217 /* DNSServiceUpdateRecord
12764b22b933Srs200217  *
12774b22b933Srs200217  * Update a registered resource record. The record must either be:
12784b22b933Srs200217  *   - The primary txt record of a service registered via DNSServiceRegister()
12794b22b933Srs200217  *   - A record added to a registered service via DNSServiceAddRecord()
12804b22b933Srs200217  *   - An individual record registered by DNSServiceRegisterRecord()
12814b22b933Srs200217  *
12824b22b933Srs200217  * Parameters:
12834b22b933Srs200217  *
12844b22b933Srs200217  * sdRef:           A DNSServiceRef that was initialized by DNSServiceRegister()
12854b22b933Srs200217  *                  or DNSServiceCreateConnection().
12864b22b933Srs200217  *
12874b22b933Srs200217  * RecordRef:       A DNSRecordRef initialized by DNSServiceAddRecord, or NULL to update the
12884b22b933Srs200217  *                  service's primary txt record.
12894b22b933Srs200217  *
12904b22b933Srs200217  * flags:           Currently ignored, reserved for future use.
12914b22b933Srs200217  *
12924b22b933Srs200217  * rdlen:           The length, in bytes, of the new rdata.
12934b22b933Srs200217  *
12944b22b933Srs200217  * rdata:           The new rdata to be contained in the updated resource record.
12954b22b933Srs200217  *
12964b22b933Srs200217  * ttl:             The time to live of the updated resource record, in seconds.
1297*5ffb0c9bSToomas Soome  *                  Most clients should pass 0 to indicate that the system should
1298*5ffb0c9bSToomas Soome  *                  select a sensible default value.
12994b22b933Srs200217  *
13004b22b933Srs200217  * return value:    Returns kDNSServiceErr_NoError on success, otherwise returns an
13014b22b933Srs200217  *                  error code indicating the error that occurred.
13024b22b933Srs200217  */
13034b22b933Srs200217 
13044b22b933Srs200217 DNSServiceErrorType DNSSD_API DNSServiceUpdateRecord
13054b22b933Srs200217 (
13064b22b933Srs200217     DNSServiceRef sdRef,
13074b22b933Srs200217     DNSRecordRef RecordRef,                            /* may be NULL */
13084b22b933Srs200217     DNSServiceFlags flags,
13094b22b933Srs200217     uint16_t rdlen,
13104b22b933Srs200217     const void                          *rdata,
13114b22b933Srs200217     uint32_t ttl
13124b22b933Srs200217 );
13134b22b933Srs200217 
13144b22b933Srs200217 
13154b22b933Srs200217 /* DNSServiceRemoveRecord
13164b22b933Srs200217  *
13174b22b933Srs200217  * Remove a record previously added to a service record set via DNSServiceAddRecord(), or deregister
13184b22b933Srs200217  * an record registered individually via DNSServiceRegisterRecord().
13194b22b933Srs200217  *
13204b22b933Srs200217  * Parameters:
13214b22b933Srs200217  *
13224b22b933Srs200217  * sdRef:           A DNSServiceRef initialized by DNSServiceRegister() (if the
13234b22b933Srs200217  *                  record being removed was registered via DNSServiceAddRecord()) or by
13244b22b933Srs200217  *                  DNSServiceCreateConnection() (if the record being removed was registered via
13254b22b933Srs200217  *                  DNSServiceRegisterRecord()).
13264b22b933Srs200217  *
13274b22b933Srs200217  * recordRef:       A DNSRecordRef initialized by a successful call to DNSServiceAddRecord()
13284b22b933Srs200217  *                  or DNSServiceRegisterRecord().
13294b22b933Srs200217  *
13304b22b933Srs200217  * flags:           Currently ignored, reserved for future use.
13314b22b933Srs200217  *
13324b22b933Srs200217  * return value:    Returns kDNSServiceErr_NoError on success, otherwise returns an
13334b22b933Srs200217  *                  error code indicating the error that occurred.
13344b22b933Srs200217  */
13354b22b933Srs200217 
13364b22b933Srs200217 DNSServiceErrorType DNSSD_API DNSServiceRemoveRecord
13374b22b933Srs200217 (
13384b22b933Srs200217     DNSServiceRef sdRef,
13394b22b933Srs200217     DNSRecordRef RecordRef,
13404b22b933Srs200217     DNSServiceFlags flags
13414b22b933Srs200217 );
13424b22b933Srs200217 
13434b22b933Srs200217 
13444b22b933Srs200217 /*********************************************************************************************
13454b22b933Srs200217 *
13464b22b933Srs200217 *  Service Discovery
13474b22b933Srs200217 *
13484b22b933Srs200217 *********************************************************************************************/
13494b22b933Srs200217 
13504b22b933Srs200217 /* Browse for instances of a service.
13514b22b933Srs200217  *
13524b22b933Srs200217  * DNSServiceBrowseReply() Parameters:
13534b22b933Srs200217  *
13544b22b933Srs200217  * sdRef:           The DNSServiceRef initialized by DNSServiceBrowse().
13554b22b933Srs200217  *
13564b22b933Srs200217  * flags:           Possible values are kDNSServiceFlagsMoreComing and kDNSServiceFlagsAdd.
13574b22b933Srs200217  *                  See flag definitions for details.
13584b22b933Srs200217  *
13594b22b933Srs200217  * interfaceIndex:  The interface on which the service is advertised. This index should
13604b22b933Srs200217  *                  be passed to DNSServiceResolve() when resolving the service.
13614b22b933Srs200217  *
13624b22b933Srs200217  * errorCode:       Will be kDNSServiceErr_NoError (0) on success, otherwise will
13634b22b933Srs200217  *                  indicate the failure that occurred. Other parameters are undefined if
13644b22b933Srs200217  *                  the errorCode is nonzero.
13654b22b933Srs200217  *
13664b22b933Srs200217  * serviceName:     The discovered service name. This name should be displayed to the user,
13674b22b933Srs200217  *                  and stored for subsequent use in the DNSServiceResolve() call.
13684b22b933Srs200217  *
13694b22b933Srs200217  * regtype:         The service type, which is usually (but not always) the same as was passed
13704b22b933Srs200217  *                  to DNSServiceBrowse(). One case where the discovered service type may
13714b22b933Srs200217  *                  not be the same as the requested service type is when using subtypes:
13724b22b933Srs200217  *                  The client may want to browse for only those ftp servers that allow
13734b22b933Srs200217  *                  anonymous connections. The client will pass the string "_ftp._tcp,_anon"
13744b22b933Srs200217  *                  to DNSServiceBrowse(), but the type of the service that's discovered
13754b22b933Srs200217  *                  is simply "_ftp._tcp". The regtype for each discovered service instance
13764b22b933Srs200217  *                  should be stored along with the name, so that it can be passed to
13774b22b933Srs200217  *                  DNSServiceResolve() when the service is later resolved.
13784b22b933Srs200217  *
13794b22b933Srs200217  * domain:          The domain of the discovered service instance. This may or may not be the
13804b22b933Srs200217  *                  same as the domain that was passed to DNSServiceBrowse(). The domain for each
13814b22b933Srs200217  *                  discovered service instance should be stored along with the name, so that
13824b22b933Srs200217  *                  it can be passed to DNSServiceResolve() when the service is later resolved.
13834b22b933Srs200217  *
13844b22b933Srs200217  * context:         The context pointer that was passed to the callout.
13854b22b933Srs200217  *
13864b22b933Srs200217  */
13874b22b933Srs200217 
13884b22b933Srs200217 typedef void (DNSSD_API *DNSServiceBrowseReply)
13894b22b933Srs200217 (
13904b22b933Srs200217     DNSServiceRef sdRef,
13914b22b933Srs200217     DNSServiceFlags flags,
13924b22b933Srs200217     uint32_t interfaceIndex,
13934b22b933Srs200217     DNSServiceErrorType errorCode,
13944b22b933Srs200217     const char                          *serviceName,
13954b22b933Srs200217     const char                          *regtype,
13964b22b933Srs200217     const char                          *replyDomain,
13974b22b933Srs200217     void                                *context
13984b22b933Srs200217 );
13994b22b933Srs200217 
14004b22b933Srs200217 
14014b22b933Srs200217 /* DNSServiceBrowse() Parameters:
14024b22b933Srs200217  *
14034b22b933Srs200217  * sdRef:           A pointer to an uninitialized DNSServiceRef. If the call succeeds
14044b22b933Srs200217  *                  then it initializes the DNSServiceRef, returns kDNSServiceErr_NoError,
14054b22b933Srs200217  *                  and the browse operation will run indefinitely until the client
14064b22b933Srs200217  *                  terminates it by passing this DNSServiceRef to DNSServiceRefDeallocate().
14074b22b933Srs200217  *
14084b22b933Srs200217  * flags:           Currently ignored, reserved for future use.
14094b22b933Srs200217  *
14104b22b933Srs200217  * interfaceIndex:  If non-zero, specifies the interface on which to browse for services
14114b22b933Srs200217  *                  (the index for a given interface is determined via the if_nametoindex()
14124b22b933Srs200217  *                  family of calls.) Most applications will pass 0 to browse on all available
14134b22b933Srs200217  *                  interfaces. See "Constants for specifying an interface index" for more details.
14144b22b933Srs200217  *
14154b22b933Srs200217  * regtype:         The service type being browsed for followed by the protocol, separated by a
14164b22b933Srs200217  *                  dot (e.g. "_ftp._tcp"). The transport protocol must be "_tcp" or "_udp".
1417*5ffb0c9bSToomas Soome  *                  A client may optionally specify a single subtype to perform filtered browsing:
1418*5ffb0c9bSToomas Soome  *                  e.g. browsing for "_primarytype._tcp,_subtype" will discover only those
1419*5ffb0c9bSToomas Soome  *                  instances of "_primarytype._tcp" that were registered specifying "_subtype"
1420*5ffb0c9bSToomas Soome  *                  in their list of registered subtypes. Additionally, a group identifier may
1421*5ffb0c9bSToomas Soome  *                  also be specified before the subtype e.g., _primarytype._tcp:GroupID, which
1422*5ffb0c9bSToomas Soome  *                  will discover only the members that register the service with GroupID. See
1423*5ffb0c9bSToomas Soome  *                  DNSServiceRegister for more details.
14244b22b933Srs200217  *
14254b22b933Srs200217  * domain:          If non-NULL, specifies the domain on which to browse for services.
14264b22b933Srs200217  *                  Most applications will not specify a domain, instead browsing on the
14274b22b933Srs200217  *                  default domain(s).
14284b22b933Srs200217  *
14294b22b933Srs200217  * callBack:        The function to be called when an instance of the service being browsed for
14304b22b933Srs200217  *                  is found, or if the call asynchronously fails.
14314b22b933Srs200217  *
14324b22b933Srs200217  * context:         An application context pointer which is passed to the callback function
14334b22b933Srs200217  *                  (may be NULL).
14344b22b933Srs200217  *
1435*5ffb0c9bSToomas Soome  * return value:    Returns kDNSServiceErr_NoError on success (any subsequent, asynchronous
14364b22b933Srs200217  *                  errors are delivered to the callback), otherwise returns an error code indicating
14374b22b933Srs200217  *                  the error that occurred (the callback is not invoked and the DNSServiceRef
1438*5ffb0c9bSToomas Soome  *                  is not initialized).
14394b22b933Srs200217  */
14404b22b933Srs200217 
14414b22b933Srs200217 DNSServiceErrorType DNSSD_API DNSServiceBrowse
14424b22b933Srs200217 (
14434b22b933Srs200217     DNSServiceRef                       *sdRef,
14444b22b933Srs200217     DNSServiceFlags flags,
14454b22b933Srs200217     uint32_t interfaceIndex,
14464b22b933Srs200217     const char                          *regtype,
14474b22b933Srs200217     const char                          *domain,    /* may be NULL */
14484b22b933Srs200217     DNSServiceBrowseReply callBack,
14494b22b933Srs200217     void                                *context    /* may be NULL */
14504b22b933Srs200217 );
14514b22b933Srs200217 
14524b22b933Srs200217 
14534b22b933Srs200217 /* DNSServiceResolve()
14544b22b933Srs200217  *
14554b22b933Srs200217  * Resolve a service name discovered via DNSServiceBrowse() to a target host name, port number, and
14564b22b933Srs200217  * txt record.
14574b22b933Srs200217  *
14584b22b933Srs200217  * Note: Applications should NOT use DNSServiceResolve() solely for txt record monitoring - use
14594b22b933Srs200217  * DNSServiceQueryRecord() instead, as it is more efficient for this task.
14604b22b933Srs200217  *
14614b22b933Srs200217  * Note: When the desired results have been returned, the client MUST terminate the resolve by calling
14624b22b933Srs200217  * DNSServiceRefDeallocate().
14634b22b933Srs200217  *
14644b22b933Srs200217  * Note: DNSServiceResolve() behaves correctly for typical services that have a single SRV record
14654b22b933Srs200217  * and a single TXT record. To resolve non-standard services with multiple SRV or TXT records,
14664b22b933Srs200217  * DNSServiceQueryRecord() should be used.
14674b22b933Srs200217  *
14684b22b933Srs200217  * DNSServiceResolveReply Callback Parameters:
14694b22b933Srs200217  *
14704b22b933Srs200217  * sdRef:           The DNSServiceRef initialized by DNSServiceResolve().
14714b22b933Srs200217  *
1472*5ffb0c9bSToomas Soome  * flags:           Possible values: kDNSServiceFlagsMoreComing
14734b22b933Srs200217  *
14744b22b933Srs200217  * interfaceIndex:  The interface on which the service was resolved.
14754b22b933Srs200217  *
14764b22b933Srs200217  * errorCode:       Will be kDNSServiceErr_NoError (0) on success, otherwise will
14774b22b933Srs200217  *                  indicate the failure that occurred. Other parameters are undefined if
14784b22b933Srs200217  *                  the errorCode is nonzero.
14794b22b933Srs200217  *
14804b22b933Srs200217  * fullname:        The full service domain name, in the form <servicename>.<protocol>.<domain>.
14814b22b933Srs200217  *                  (This name is escaped following standard DNS rules, making it suitable for
14824b22b933Srs200217  *                  passing to standard system DNS APIs such as res_query(), or to the
14834b22b933Srs200217  *                  special-purpose functions included in this API that take fullname parameters.
14844b22b933Srs200217  *                  See "Notes on DNS Name Escaping" earlier in this file for more details.)
14854b22b933Srs200217  *
14864b22b933Srs200217  * hosttarget:      The target hostname of the machine providing the service. This name can
14874b22b933Srs200217  *                  be passed to functions like gethostbyname() to identify the host's IP address.
14884b22b933Srs200217  *
14894b22b933Srs200217  * port:            The port, in network byte order, on which connections are accepted for this service.
14904b22b933Srs200217  *
14914b22b933Srs200217  * txtLen:          The length of the txt record, in bytes.
14924b22b933Srs200217  *
14934b22b933Srs200217  * txtRecord:       The service's primary txt record, in standard txt record format.
14944b22b933Srs200217  *
14954b22b933Srs200217  * context:         The context pointer that was passed to the callout.
14964b22b933Srs200217  *
14974b22b933Srs200217  * NOTE: In earlier versions of this header file, the txtRecord parameter was declared "const char *"
14984b22b933Srs200217  * This is incorrect, since it contains length bytes which are values in the range 0 to 255, not -128 to +127.
14994b22b933Srs200217  * Depending on your compiler settings, this change may cause signed/unsigned mismatch warnings.
15004b22b933Srs200217  * These should be fixed by updating your own callback function definition to match the corrected
15014b22b933Srs200217  * function signature using "const unsigned char *txtRecord". Making this change may also fix inadvertent
15024b22b933Srs200217  * bugs in your callback function, where it could have incorrectly interpreted a length byte with value 250
15034b22b933Srs200217  * as being -6 instead, with various bad consequences ranging from incorrect operation to software crashes.
15044b22b933Srs200217  * If you need to maintain portable code that will compile cleanly with both the old and new versions of
15054b22b933Srs200217  * this header file, you should update your callback function definition to use the correct unsigned value,
15064b22b933Srs200217  * and then in the place where you pass your callback function to DNSServiceResolve(), use a cast to eliminate
15074b22b933Srs200217  * the compiler warning, e.g.:
15084b22b933Srs200217  *   DNSServiceResolve(sd, flags, index, name, regtype, domain, (DNSServiceResolveReply)MyCallback, context);
15094b22b933Srs200217  * This will ensure that your code compiles cleanly without warnings (and more importantly, works correctly)
15104b22b933Srs200217  * with both the old header and with the new corrected version.
15114b22b933Srs200217  *
15124b22b933Srs200217  */
15134b22b933Srs200217 
15144b22b933Srs200217 typedef void (DNSSD_API *DNSServiceResolveReply)
15154b22b933Srs200217 (
15164b22b933Srs200217     DNSServiceRef sdRef,
15174b22b933Srs200217     DNSServiceFlags flags,
15184b22b933Srs200217     uint32_t interfaceIndex,
15194b22b933Srs200217     DNSServiceErrorType errorCode,
15204b22b933Srs200217     const char                          *fullname,
15214b22b933Srs200217     const char                          *hosttarget,
1522*5ffb0c9bSToomas Soome     uint16_t port,                                   /* In network byte order */
15234b22b933Srs200217     uint16_t txtLen,
15244b22b933Srs200217     const unsigned char                 *txtRecord,
15254b22b933Srs200217     void                                *context
15264b22b933Srs200217 );
15274b22b933Srs200217 
15284b22b933Srs200217 
15294b22b933Srs200217 /* DNSServiceResolve() Parameters
15304b22b933Srs200217  *
15314b22b933Srs200217  * sdRef:           A pointer to an uninitialized DNSServiceRef. If the call succeeds
15324b22b933Srs200217  *                  then it initializes the DNSServiceRef, returns kDNSServiceErr_NoError,
15334b22b933Srs200217  *                  and the resolve operation will run indefinitely until the client
15344b22b933Srs200217  *                  terminates it by passing this DNSServiceRef to DNSServiceRefDeallocate().
15354b22b933Srs200217  *
1536*5ffb0c9bSToomas Soome  * flags:           Specifying kDNSServiceFlagsForceMulticast will cause query to be
1537*5ffb0c9bSToomas Soome  *                  performed with a link-local mDNS query, even if the name is an
1538*5ffb0c9bSToomas Soome  *                  apparently non-local name (i.e. a name not ending in ".local.")
15394b22b933Srs200217  *
15404b22b933Srs200217  * interfaceIndex:  The interface on which to resolve the service. If this resolve call is
15414b22b933Srs200217  *                  as a result of a currently active DNSServiceBrowse() operation, then the
15424b22b933Srs200217  *                  interfaceIndex should be the index reported in the DNSServiceBrowseReply
15434b22b933Srs200217  *                  callback. If this resolve call is using information previously saved
15444b22b933Srs200217  *                  (e.g. in a preference file) for later use, then use interfaceIndex 0, because
15454b22b933Srs200217  *                  the desired service may now be reachable via a different physical interface.
15464b22b933Srs200217  *                  See "Constants for specifying an interface index" for more details.
15474b22b933Srs200217  *
15484b22b933Srs200217  * name:            The name of the service instance to be resolved, as reported to the
15494b22b933Srs200217  *                  DNSServiceBrowseReply() callback.
15504b22b933Srs200217  *
15514b22b933Srs200217  * regtype:         The type of the service instance to be resolved, as reported to the
15524b22b933Srs200217  *                  DNSServiceBrowseReply() callback.
15534b22b933Srs200217  *
15544b22b933Srs200217  * domain:          The domain of the service instance to be resolved, as reported to the
15554b22b933Srs200217  *                  DNSServiceBrowseReply() callback.
15564b22b933Srs200217  *
15574b22b933Srs200217  * callBack:        The function to be called when a result is found, or if the call
15584b22b933Srs200217  *                  asynchronously fails.
15594b22b933Srs200217  *
15604b22b933Srs200217  * context:         An application context pointer which is passed to the callback function
15614b22b933Srs200217  *                  (may be NULL).
15624b22b933Srs200217  *
1563*5ffb0c9bSToomas Soome  * return value:    Returns kDNSServiceErr_NoError on success (any subsequent, asynchronous
15644b22b933Srs200217  *                  errors are delivered to the callback), otherwise returns an error code indicating
15654b22b933Srs200217  *                  the error that occurred (the callback is never invoked and the DNSServiceRef
1566*5ffb0c9bSToomas Soome  *                  is not initialized).
15674b22b933Srs200217  */
15684b22b933Srs200217 
15694b22b933Srs200217 DNSServiceErrorType DNSSD_API DNSServiceResolve
15704b22b933Srs200217 (
15714b22b933Srs200217     DNSServiceRef                       *sdRef,
15724b22b933Srs200217     DNSServiceFlags flags,
15734b22b933Srs200217     uint32_t interfaceIndex,
15744b22b933Srs200217     const char                          *name,
15754b22b933Srs200217     const char                          *regtype,
15764b22b933Srs200217     const char                          *domain,
15774b22b933Srs200217     DNSServiceResolveReply callBack,
15784b22b933Srs200217     void                                *context  /* may be NULL */
15794b22b933Srs200217 );
15804b22b933Srs200217 
15814b22b933Srs200217 
15824b22b933Srs200217 /*********************************************************************************************
15834b22b933Srs200217 *
1584*5ffb0c9bSToomas Soome *  Querying Individual Specific Records
1585*5ffb0c9bSToomas Soome *
1586*5ffb0c9bSToomas Soome *********************************************************************************************/
1587*5ffb0c9bSToomas Soome 
1588*5ffb0c9bSToomas Soome /* DNSServiceQueryRecord
1589*5ffb0c9bSToomas Soome  *
1590*5ffb0c9bSToomas Soome  * Query for an arbitrary DNS record.
1591*5ffb0c9bSToomas Soome  *
1592*5ffb0c9bSToomas Soome  * DNSServiceQueryRecordReply() Callback Parameters:
1593*5ffb0c9bSToomas Soome  *
1594*5ffb0c9bSToomas Soome  * sdRef:           The DNSServiceRef initialized by DNSServiceQueryRecord().
1595*5ffb0c9bSToomas Soome  *
1596*5ffb0c9bSToomas Soome  * flags:           Possible values are kDNSServiceFlagsMoreComing and
1597*5ffb0c9bSToomas Soome  *                  kDNSServiceFlagsAdd. The Add flag is NOT set for PTR records
1598*5ffb0c9bSToomas Soome  *                  with a ttl of 0, i.e. "Remove" events.
1599*5ffb0c9bSToomas Soome  *
1600*5ffb0c9bSToomas Soome  * interfaceIndex:  The interface on which the query was resolved (the index for a given
1601*5ffb0c9bSToomas Soome  *                  interface is determined via the if_nametoindex() family of calls).
1602*5ffb0c9bSToomas Soome  *                  See "Constants for specifying an interface index" for more details.
1603*5ffb0c9bSToomas Soome  *
1604*5ffb0c9bSToomas Soome  * errorCode:       Will be kDNSServiceErr_NoError on success, otherwise will
1605*5ffb0c9bSToomas Soome  *                  indicate the failure that occurred. Other parameters are undefined if
1606*5ffb0c9bSToomas Soome  *                  errorCode is nonzero.
1607*5ffb0c9bSToomas Soome  *
1608*5ffb0c9bSToomas Soome  * fullname:        The resource record's full domain name.
1609*5ffb0c9bSToomas Soome  *
1610*5ffb0c9bSToomas Soome  * rrtype:          The resource record's type (e.g. kDNSServiceType_PTR, kDNSServiceType_SRV, etc)
1611*5ffb0c9bSToomas Soome  *
1612*5ffb0c9bSToomas Soome  * rrclass:         The class of the resource record (usually kDNSServiceClass_IN).
1613*5ffb0c9bSToomas Soome  *
1614*5ffb0c9bSToomas Soome  * rdlen:           The length, in bytes, of the resource record rdata.
1615*5ffb0c9bSToomas Soome  *
1616*5ffb0c9bSToomas Soome  * rdata:           The raw rdata of the resource record.
1617*5ffb0c9bSToomas Soome  *
1618*5ffb0c9bSToomas Soome  * ttl:             If the client wishes to cache the result for performance reasons,
1619*5ffb0c9bSToomas Soome  *                  the TTL indicates how long the client may legitimately hold onto
1620*5ffb0c9bSToomas Soome  *                  this result, in seconds. After the TTL expires, the client should
1621*5ffb0c9bSToomas Soome  *                  consider the result no longer valid, and if it requires this data
1622*5ffb0c9bSToomas Soome  *                  again, it should be re-fetched with a new query. Of course, this
1623*5ffb0c9bSToomas Soome  *                  only applies to clients that cancel the asynchronous operation when
1624*5ffb0c9bSToomas Soome  *                  they get a result. Clients that leave the asynchronous operation
1625*5ffb0c9bSToomas Soome  *                  running can safely assume that the data remains valid until they
1626*5ffb0c9bSToomas Soome  *                  get another callback telling them otherwise.
1627*5ffb0c9bSToomas Soome  *
1628*5ffb0c9bSToomas Soome  * context:         The context pointer that was passed to the callout.
1629*5ffb0c9bSToomas Soome  *
1630*5ffb0c9bSToomas Soome  */
1631*5ffb0c9bSToomas Soome 
1632*5ffb0c9bSToomas Soome typedef void (DNSSD_API *DNSServiceQueryRecordReply)
1633*5ffb0c9bSToomas Soome (
1634*5ffb0c9bSToomas Soome     DNSServiceRef sdRef,
1635*5ffb0c9bSToomas Soome     DNSServiceFlags flags,
1636*5ffb0c9bSToomas Soome     uint32_t interfaceIndex,
1637*5ffb0c9bSToomas Soome     DNSServiceErrorType errorCode,
1638*5ffb0c9bSToomas Soome     const char                          *fullname,
1639*5ffb0c9bSToomas Soome     uint16_t rrtype,
1640*5ffb0c9bSToomas Soome     uint16_t rrclass,
1641*5ffb0c9bSToomas Soome     uint16_t rdlen,
1642*5ffb0c9bSToomas Soome     const void                          *rdata,
1643*5ffb0c9bSToomas Soome     uint32_t ttl,
1644*5ffb0c9bSToomas Soome     void                                *context
1645*5ffb0c9bSToomas Soome );
1646*5ffb0c9bSToomas Soome 
1647*5ffb0c9bSToomas Soome 
1648*5ffb0c9bSToomas Soome /* DNSServiceQueryRecord() Parameters:
1649*5ffb0c9bSToomas Soome  *
1650*5ffb0c9bSToomas Soome  * sdRef:           A pointer to an uninitialized DNSServiceRef. If the call succeeds
1651*5ffb0c9bSToomas Soome  *                  then it initializes the DNSServiceRef, returns kDNSServiceErr_NoError,
1652*5ffb0c9bSToomas Soome  *                  and the query operation will run indefinitely until the client
1653*5ffb0c9bSToomas Soome  *                  terminates it by passing this DNSServiceRef to DNSServiceRefDeallocate().
1654*5ffb0c9bSToomas Soome  *
1655*5ffb0c9bSToomas Soome  * flags:           kDNSServiceFlagsForceMulticast or kDNSServiceFlagsLongLivedQuery.
1656*5ffb0c9bSToomas Soome  *                  Pass kDNSServiceFlagsLongLivedQuery to create a "long-lived" unicast
1657*5ffb0c9bSToomas Soome  *                  query to a unicast DNS server that implements the protocol. This flag
1658*5ffb0c9bSToomas Soome  *                  has no effect on link-local multicast queries.
1659*5ffb0c9bSToomas Soome  *
1660*5ffb0c9bSToomas Soome  * interfaceIndex:  If non-zero, specifies the interface on which to issue the query
1661*5ffb0c9bSToomas Soome  *                  (the index for a given interface is determined via the if_nametoindex()
1662*5ffb0c9bSToomas Soome  *                  family of calls.) Passing 0 causes the name to be queried for on all
1663*5ffb0c9bSToomas Soome  *                  interfaces. See "Constants for specifying an interface index" for more details.
1664*5ffb0c9bSToomas Soome  *
1665*5ffb0c9bSToomas Soome  * fullname:        The full domain name of the resource record to be queried for.
1666*5ffb0c9bSToomas Soome  *
1667*5ffb0c9bSToomas Soome  * rrtype:          The numerical type of the resource record to be queried for
1668*5ffb0c9bSToomas Soome  *                  (e.g. kDNSServiceType_PTR, kDNSServiceType_SRV, etc)
1669*5ffb0c9bSToomas Soome  *
1670*5ffb0c9bSToomas Soome  * rrclass:         The class of the resource record (usually kDNSServiceClass_IN).
1671*5ffb0c9bSToomas Soome  *
1672*5ffb0c9bSToomas Soome  * callBack:        The function to be called when a result is found, or if the call
1673*5ffb0c9bSToomas Soome  *                  asynchronously fails.
1674*5ffb0c9bSToomas Soome  *
1675*5ffb0c9bSToomas Soome  * context:         An application context pointer which is passed to the callback function
1676*5ffb0c9bSToomas Soome  *                  (may be NULL).
1677*5ffb0c9bSToomas Soome  *
1678*5ffb0c9bSToomas Soome  * return value:    Returns kDNSServiceErr_NoError on success (any subsequent, asynchronous
1679*5ffb0c9bSToomas Soome  *                  errors are delivered to the callback), otherwise returns an error code indicating
1680*5ffb0c9bSToomas Soome  *                  the error that occurred (the callback is never invoked and the DNSServiceRef
1681*5ffb0c9bSToomas Soome  *                  is not initialized).
1682*5ffb0c9bSToomas Soome  */
1683*5ffb0c9bSToomas Soome 
1684*5ffb0c9bSToomas Soome DNSServiceErrorType DNSSD_API DNSServiceQueryRecord
1685*5ffb0c9bSToomas Soome (
1686*5ffb0c9bSToomas Soome     DNSServiceRef                       *sdRef,
1687*5ffb0c9bSToomas Soome     DNSServiceFlags flags,
1688*5ffb0c9bSToomas Soome     uint32_t interfaceIndex,
1689*5ffb0c9bSToomas Soome     const char                          *fullname,
1690*5ffb0c9bSToomas Soome     uint16_t rrtype,
1691*5ffb0c9bSToomas Soome     uint16_t rrclass,
1692*5ffb0c9bSToomas Soome     DNSServiceQueryRecordReply callBack,
1693*5ffb0c9bSToomas Soome     void                                *context  /* may be NULL */
1694*5ffb0c9bSToomas Soome );
1695*5ffb0c9bSToomas Soome 
1696*5ffb0c9bSToomas Soome 
1697*5ffb0c9bSToomas Soome /*********************************************************************************************
1698*5ffb0c9bSToomas Soome *
1699*5ffb0c9bSToomas Soome *  Unified lookup of both IPv4 and IPv6 addresses for a fully qualified hostname
1700*5ffb0c9bSToomas Soome *
1701*5ffb0c9bSToomas Soome *********************************************************************************************/
1702*5ffb0c9bSToomas Soome 
1703*5ffb0c9bSToomas Soome /* DNSServiceGetAddrInfo
1704*5ffb0c9bSToomas Soome  *
1705*5ffb0c9bSToomas Soome  * Queries for the IP address of a hostname by using either Multicast or Unicast DNS.
1706*5ffb0c9bSToomas Soome  *
1707*5ffb0c9bSToomas Soome  * DNSServiceGetAddrInfoReply() parameters:
1708*5ffb0c9bSToomas Soome  *
1709*5ffb0c9bSToomas Soome  * sdRef:           The DNSServiceRef initialized by DNSServiceGetAddrInfo().
1710*5ffb0c9bSToomas Soome  *
1711*5ffb0c9bSToomas Soome  * flags:           Possible values are kDNSServiceFlagsMoreComing and
1712*5ffb0c9bSToomas Soome  *                  kDNSServiceFlagsAdd.
1713*5ffb0c9bSToomas Soome  *
1714*5ffb0c9bSToomas Soome  * interfaceIndex:  The interface to which the answers pertain.
1715*5ffb0c9bSToomas Soome  *
1716*5ffb0c9bSToomas Soome  * errorCode:       Will be kDNSServiceErr_NoError on success, otherwise will
1717*5ffb0c9bSToomas Soome  *                  indicate the failure that occurred.  Other parameters are
1718*5ffb0c9bSToomas Soome  *                  undefined if errorCode is nonzero.
1719*5ffb0c9bSToomas Soome  *
1720*5ffb0c9bSToomas Soome  * hostname:        The fully qualified domain name of the host to be queried for.
1721*5ffb0c9bSToomas Soome  *
1722*5ffb0c9bSToomas Soome  * address:         IPv4 or IPv6 address.
1723*5ffb0c9bSToomas Soome  *
1724*5ffb0c9bSToomas Soome  * ttl:             If the client wishes to cache the result for performance reasons,
1725*5ffb0c9bSToomas Soome  *                  the TTL indicates how long the client may legitimately hold onto
1726*5ffb0c9bSToomas Soome  *                  this result, in seconds. After the TTL expires, the client should
1727*5ffb0c9bSToomas Soome  *                  consider the result no longer valid, and if it requires this data
1728*5ffb0c9bSToomas Soome  *                  again, it should be re-fetched with a new query. Of course, this
1729*5ffb0c9bSToomas Soome  *                  only applies to clients that cancel the asynchronous operation when
1730*5ffb0c9bSToomas Soome  *                  they get a result. Clients that leave the asynchronous operation
1731*5ffb0c9bSToomas Soome  *                  running can safely assume that the data remains valid until they
1732*5ffb0c9bSToomas Soome  *                  get another callback telling them otherwise.
1733*5ffb0c9bSToomas Soome  *
1734*5ffb0c9bSToomas Soome  * context:         The context pointer that was passed to the callout.
1735*5ffb0c9bSToomas Soome  *
1736*5ffb0c9bSToomas Soome  */
1737*5ffb0c9bSToomas Soome 
1738*5ffb0c9bSToomas Soome typedef void (DNSSD_API *DNSServiceGetAddrInfoReply)
1739*5ffb0c9bSToomas Soome (
1740*5ffb0c9bSToomas Soome     DNSServiceRef sdRef,
1741*5ffb0c9bSToomas Soome     DNSServiceFlags flags,
1742*5ffb0c9bSToomas Soome     uint32_t interfaceIndex,
1743*5ffb0c9bSToomas Soome     DNSServiceErrorType errorCode,
1744*5ffb0c9bSToomas Soome     const char                       *hostname,
1745*5ffb0c9bSToomas Soome     const struct sockaddr            *address,
1746*5ffb0c9bSToomas Soome     uint32_t ttl,
1747*5ffb0c9bSToomas Soome     void                             *context
1748*5ffb0c9bSToomas Soome );
1749*5ffb0c9bSToomas Soome 
1750*5ffb0c9bSToomas Soome 
1751*5ffb0c9bSToomas Soome /* DNSServiceGetAddrInfo() Parameters:
1752*5ffb0c9bSToomas Soome  *
1753*5ffb0c9bSToomas Soome  * sdRef:           A pointer to an uninitialized DNSServiceRef. If the call succeeds then it
1754*5ffb0c9bSToomas Soome  *                  initializes the DNSServiceRef, returns kDNSServiceErr_NoError, and the query
1755*5ffb0c9bSToomas Soome  *                  begins and will last indefinitely until the client terminates the query
1756*5ffb0c9bSToomas Soome  *                  by passing this DNSServiceRef to DNSServiceRefDeallocate().
1757*5ffb0c9bSToomas Soome  *
1758*5ffb0c9bSToomas Soome  * flags:           kDNSServiceFlagsForceMulticast
1759*5ffb0c9bSToomas Soome  *
1760*5ffb0c9bSToomas Soome  * interfaceIndex:  The interface on which to issue the query.  Passing 0 causes the query to be
1761*5ffb0c9bSToomas Soome  *                  sent on all active interfaces via Multicast or the primary interface via Unicast.
1762*5ffb0c9bSToomas Soome  *
1763*5ffb0c9bSToomas Soome  * protocol:        Pass in kDNSServiceProtocol_IPv4 to look up IPv4 addresses, or kDNSServiceProtocol_IPv6
1764*5ffb0c9bSToomas Soome  *                  to look up IPv6 addresses, or both to look up both kinds. If neither flag is
1765*5ffb0c9bSToomas Soome  *                  set, the system will apply an intelligent heuristic, which is (currently)
1766*5ffb0c9bSToomas Soome  *                  that it will attempt to look up both, except:
1767*5ffb0c9bSToomas Soome  *
1768*5ffb0c9bSToomas Soome  *                   * If "hostname" is a wide-area unicast DNS hostname (i.e. not a ".local." name)
1769*5ffb0c9bSToomas Soome  *                     but this host has no routable IPv6 address, then the call will not try to
1770*5ffb0c9bSToomas Soome  *                     look up IPv6 addresses for "hostname", since any addresses it found would be
1771*5ffb0c9bSToomas Soome  *                     unlikely to be of any use anyway. Similarly, if this host has no routable
1772*5ffb0c9bSToomas Soome  *                     IPv4 address, the call will not try to look up IPv4 addresses for "hostname".
1773*5ffb0c9bSToomas Soome  *
1774*5ffb0c9bSToomas Soome  * hostname:        The fully qualified domain name of the host to be queried for.
1775*5ffb0c9bSToomas Soome  *
1776*5ffb0c9bSToomas Soome  * callBack:        The function to be called when the query succeeds or fails asynchronously.
1777*5ffb0c9bSToomas Soome  *
1778*5ffb0c9bSToomas Soome  * context:         An application context pointer which is passed to the callback function
1779*5ffb0c9bSToomas Soome  *                  (may be NULL).
1780*5ffb0c9bSToomas Soome  *
1781*5ffb0c9bSToomas Soome  * return value:    Returns kDNSServiceErr_NoError on success (any subsequent, asynchronous
1782*5ffb0c9bSToomas Soome  *                  errors are delivered to the callback), otherwise returns an error code indicating
1783*5ffb0c9bSToomas Soome  *                  the error that occurred.
1784*5ffb0c9bSToomas Soome  */
1785*5ffb0c9bSToomas Soome 
1786*5ffb0c9bSToomas Soome DNSServiceErrorType DNSSD_API DNSServiceGetAddrInfo
1787*5ffb0c9bSToomas Soome (
1788*5ffb0c9bSToomas Soome     DNSServiceRef                    *sdRef,
1789*5ffb0c9bSToomas Soome     DNSServiceFlags flags,
1790*5ffb0c9bSToomas Soome     uint32_t interfaceIndex,
1791*5ffb0c9bSToomas Soome     DNSServiceProtocol protocol,
1792*5ffb0c9bSToomas Soome     const char                       *hostname,
1793*5ffb0c9bSToomas Soome     DNSServiceGetAddrInfoReply callBack,
1794*5ffb0c9bSToomas Soome     void                             *context          /* may be NULL */
1795*5ffb0c9bSToomas Soome );
1796*5ffb0c9bSToomas Soome 
1797*5ffb0c9bSToomas Soome 
1798*5ffb0c9bSToomas Soome /*********************************************************************************************
1799*5ffb0c9bSToomas Soome *
1800*5ffb0c9bSToomas Soome *  Special Purpose Calls:
1801*5ffb0c9bSToomas Soome *  DNSServiceCreateConnection(), DNSServiceRegisterRecord(), DNSServiceReconfirmRecord()
1802*5ffb0c9bSToomas Soome *  (most applications will not use these)
18034b22b933Srs200217 *
18044b22b933Srs200217 *********************************************************************************************/
18054b22b933Srs200217 
18064b22b933Srs200217 /* DNSServiceCreateConnection()
18074b22b933Srs200217  *
18084b22b933Srs200217  * Create a connection to the daemon allowing efficient registration of
18094b22b933Srs200217  * multiple individual records.
18104b22b933Srs200217  *
18114b22b933Srs200217  * Parameters:
18124b22b933Srs200217  *
18134b22b933Srs200217  * sdRef:           A pointer to an uninitialized DNSServiceRef. Deallocating
18144b22b933Srs200217  *                  the reference (via DNSServiceRefDeallocate()) severs the
18154b22b933Srs200217  *                  connection and deregisters all records registered on this connection.
18164b22b933Srs200217  *
18174b22b933Srs200217  * return value:    Returns kDNSServiceErr_NoError on success, otherwise returns
18184b22b933Srs200217  *                  an error code indicating the specific failure that occurred (in which
18194b22b933Srs200217  *                  case the DNSServiceRef is not initialized).
18204b22b933Srs200217  */
18214b22b933Srs200217 
18224b22b933Srs200217 DNSServiceErrorType DNSSD_API DNSServiceCreateConnection(DNSServiceRef *sdRef);
18234b22b933Srs200217 
18244b22b933Srs200217 /* DNSServiceRegisterRecord
18254b22b933Srs200217  *
18264b22b933Srs200217  * Register an individual resource record on a connected DNSServiceRef.
18274b22b933Srs200217  *
18284b22b933Srs200217  * Note that name conflicts occurring for records registered via this call must be handled
18294b22b933Srs200217  * by the client in the callback.
18304b22b933Srs200217  *
18314b22b933Srs200217  * DNSServiceRegisterRecordReply() parameters:
18324b22b933Srs200217  *
18334b22b933Srs200217  * sdRef:           The connected DNSServiceRef initialized by
18344b22b933Srs200217  *                  DNSServiceCreateConnection().
18354b22b933Srs200217  *
18364b22b933Srs200217  * RecordRef:       The DNSRecordRef initialized by DNSServiceRegisterRecord(). If the above
18374b22b933Srs200217  *                  DNSServiceRef is passed to DNSServiceRefDeallocate(), this DNSRecordRef is
18384b22b933Srs200217  *                  invalidated, and may not be used further.
18394b22b933Srs200217  *
18404b22b933Srs200217  * flags:           Currently unused, reserved for future use.
18414b22b933Srs200217  *
18424b22b933Srs200217  * errorCode:       Will be kDNSServiceErr_NoError on success, otherwise will
18434b22b933Srs200217  *                  indicate the failure that occurred (including name conflicts.)
18444b22b933Srs200217  *                  Other parameters are undefined if errorCode is nonzero.
18454b22b933Srs200217  *
18464b22b933Srs200217  * context:         The context pointer that was passed to the callout.
18474b22b933Srs200217  *
18484b22b933Srs200217  */
18494b22b933Srs200217 
18504b22b933Srs200217 typedef void (DNSSD_API *DNSServiceRegisterRecordReply)
18514b22b933Srs200217 (
18524b22b933Srs200217     DNSServiceRef sdRef,
18534b22b933Srs200217     DNSRecordRef RecordRef,
18544b22b933Srs200217     DNSServiceFlags flags,
18554b22b933Srs200217     DNSServiceErrorType errorCode,
18564b22b933Srs200217     void                                *context
18574b22b933Srs200217 );
18584b22b933Srs200217 
18594b22b933Srs200217 
18604b22b933Srs200217 /* DNSServiceRegisterRecord() Parameters:
18614b22b933Srs200217  *
18624b22b933Srs200217  * sdRef:           A DNSServiceRef initialized by DNSServiceCreateConnection().
18634b22b933Srs200217  *
18644b22b933Srs200217  * RecordRef:       A pointer to an uninitialized DNSRecordRef. Upon succesfull completion of this
18654b22b933Srs200217  *                  call, this ref may be passed to DNSServiceUpdateRecord() or DNSServiceRemoveRecord().
18664b22b933Srs200217  *                  (To deregister ALL records registered on a single connected DNSServiceRef
18674b22b933Srs200217  *                  and deallocate each of their corresponding DNSServiceRecordRefs, call
1868*5ffb0c9bSToomas Soome  *                  DNSServiceRefDeallocate()).
18694b22b933Srs200217  *
18704b22b933Srs200217  * flags:           Possible values are kDNSServiceFlagsShared or kDNSServiceFlagsUnique
18714b22b933Srs200217  *                  (see flag type definitions for details).
18724b22b933Srs200217  *
18734b22b933Srs200217  * interfaceIndex:  If non-zero, specifies the interface on which to register the record
18744b22b933Srs200217  *                  (the index for a given interface is determined via the if_nametoindex()
18754b22b933Srs200217  *                  family of calls.) Passing 0 causes the record to be registered on all interfaces.
18764b22b933Srs200217  *                  See "Constants for specifying an interface index" for more details.
18774b22b933Srs200217  *
18784b22b933Srs200217  * fullname:        The full domain name of the resource record.
18794b22b933Srs200217  *
18804b22b933Srs200217  * rrtype:          The numerical type of the resource record (e.g. kDNSServiceType_PTR, kDNSServiceType_SRV, etc)
18814b22b933Srs200217  *
18824b22b933Srs200217  * rrclass:         The class of the resource record (usually kDNSServiceClass_IN)
18834b22b933Srs200217  *
18844b22b933Srs200217  * rdlen:           Length, in bytes, of the rdata.
18854b22b933Srs200217  *
18864b22b933Srs200217  * rdata:           A pointer to the raw rdata, as it is to appear in the DNS record.
18874b22b933Srs200217  *
1888*5ffb0c9bSToomas Soome  * ttl:             The time to live of the resource record, in seconds.
1889*5ffb0c9bSToomas Soome  *                  Most clients should pass 0 to indicate that the system should
1890*5ffb0c9bSToomas Soome  *                  select a sensible default value.
18914b22b933Srs200217  *
18924b22b933Srs200217  * callBack:        The function to be called when a result is found, or if the call
18934b22b933Srs200217  *                  asynchronously fails (e.g. because of a name conflict.)
18944b22b933Srs200217  *
18954b22b933Srs200217  * context:         An application context pointer which is passed to the callback function
18964b22b933Srs200217  *                  (may be NULL).
18974b22b933Srs200217  *
1898*5ffb0c9bSToomas Soome  * return value:    Returns kDNSServiceErr_NoError on success (any subsequent, asynchronous
18994b22b933Srs200217  *                  errors are delivered to the callback), otherwise returns an error code indicating
19004b22b933Srs200217  *                  the error that occurred (the callback is never invoked and the DNSRecordRef is
1901*5ffb0c9bSToomas Soome  *                  not initialized).
19024b22b933Srs200217  */
19034b22b933Srs200217 
19044b22b933Srs200217 DNSServiceErrorType DNSSD_API DNSServiceRegisterRecord
19054b22b933Srs200217 (
19064b22b933Srs200217     DNSServiceRef sdRef,
19074b22b933Srs200217     DNSRecordRef                        *RecordRef,
19084b22b933Srs200217     DNSServiceFlags flags,
19094b22b933Srs200217     uint32_t interfaceIndex,
19104b22b933Srs200217     const char                          *fullname,
19114b22b933Srs200217     uint16_t rrtype,
19124b22b933Srs200217     uint16_t rrclass,
19134b22b933Srs200217     uint16_t rdlen,
19144b22b933Srs200217     const void                          *rdata,
19154b22b933Srs200217     uint32_t ttl,
19164b22b933Srs200217     DNSServiceRegisterRecordReply callBack,
19174b22b933Srs200217     void                                *context    /* may be NULL */
19184b22b933Srs200217 );
19194b22b933Srs200217 
19204b22b933Srs200217 
19214b22b933Srs200217 /* DNSServiceReconfirmRecord
19224b22b933Srs200217  *
1923*5ffb0c9bSToomas Soome  * Instruct the daemon to verify the validity of a resource record that appears
1924*5ffb0c9bSToomas Soome  * to be out of date (e.g. because TCP connection to a service's target failed.)
19254b22b933Srs200217  * Causes the record to be flushed from the daemon's cache (as well as all other
19264b22b933Srs200217  * daemons' caches on the network) if the record is determined to be invalid.
1927*5ffb0c9bSToomas Soome  * Use this routine conservatively. Reconfirming a record necessarily consumes
1928*5ffb0c9bSToomas Soome  * network bandwidth, so this should not be done indiscriminately.
19294b22b933Srs200217  *
19304b22b933Srs200217  * Parameters:
19314b22b933Srs200217  *
1932*5ffb0c9bSToomas Soome  * flags:           Not currently used.
19334b22b933Srs200217  *
1934*5ffb0c9bSToomas Soome  * interfaceIndex:  Specifies the interface of the record in question.
1935*5ffb0c9bSToomas Soome  *                  The caller must specify the interface.
1936*5ffb0c9bSToomas Soome  *                  This API (by design) causes increased network traffic, so it requires
1937*5ffb0c9bSToomas Soome  *                  the caller to be precise about which record should be reconfirmed.
1938*5ffb0c9bSToomas Soome  *                  It is not possible to pass zero for the interface index to perform
1939*5ffb0c9bSToomas Soome  *                  a "wildcard" reconfirmation, where *all* matching records are reconfirmed.
19404b22b933Srs200217  *
19414b22b933Srs200217  * fullname:        The resource record's full domain name.
19424b22b933Srs200217  *
19434b22b933Srs200217  * rrtype:          The resource record's type (e.g. kDNSServiceType_PTR, kDNSServiceType_SRV, etc)
19444b22b933Srs200217  *
19454b22b933Srs200217  * rrclass:         The class of the resource record (usually kDNSServiceClass_IN).
19464b22b933Srs200217  *
19474b22b933Srs200217  * rdlen:           The length, in bytes, of the resource record rdata.
19484b22b933Srs200217  *
19494b22b933Srs200217  * rdata:           The raw rdata of the resource record.
19504b22b933Srs200217  *
19514b22b933Srs200217  */
19524b22b933Srs200217 
19534b22b933Srs200217 DNSServiceErrorType DNSSD_API DNSServiceReconfirmRecord
19544b22b933Srs200217 (
19554b22b933Srs200217     DNSServiceFlags flags,
19564b22b933Srs200217     uint32_t interfaceIndex,
19574b22b933Srs200217     const char                         *fullname,
19584b22b933Srs200217     uint16_t rrtype,
19594b22b933Srs200217     uint16_t rrclass,
19604b22b933Srs200217     uint16_t rdlen,
19614b22b933Srs200217     const void                         *rdata
19624b22b933Srs200217 );
19634b22b933Srs200217 
19644b22b933Srs200217 
19654b22b933Srs200217 /*********************************************************************************************
19664b22b933Srs200217 *
1967*5ffb0c9bSToomas Soome *  NAT Port Mapping
1968*5ffb0c9bSToomas Soome *
1969*5ffb0c9bSToomas Soome *********************************************************************************************/
1970*5ffb0c9bSToomas Soome 
1971*5ffb0c9bSToomas Soome /* DNSServiceNATPortMappingCreate
1972*5ffb0c9bSToomas Soome  *
1973*5ffb0c9bSToomas Soome  * Request a port mapping in the NAT gateway, which maps a port on the local machine
1974*5ffb0c9bSToomas Soome  * to an external port on the NAT. The NAT should support either PCP, NAT-PMP or the
1975*5ffb0c9bSToomas Soome  * UPnP/IGD protocol for this API to create a successful mapping. Note that this API
1976*5ffb0c9bSToomas Soome  * currently supports IPv4 addresses/mappings only. If the NAT gateway supports PCP and
1977*5ffb0c9bSToomas Soome  * returns an IPv6 address (incorrectly, since this API specifically requests IPv4
1978*5ffb0c9bSToomas Soome  * addresses), the DNSServiceNATPortMappingReply callback will be invoked with errorCode
1979*5ffb0c9bSToomas Soome  * kDNSServiceErr_NATPortMappingUnsupported.
1980*5ffb0c9bSToomas Soome  *
1981*5ffb0c9bSToomas Soome  * The port mapping will be renewed indefinitely until the client process exits, or
1982*5ffb0c9bSToomas Soome  * explicitly terminates the port mapping request by calling DNSServiceRefDeallocate().
1983*5ffb0c9bSToomas Soome  * The client callback will be invoked, informing the client of the NAT gateway's
1984*5ffb0c9bSToomas Soome  * external IP address and the external port that has been allocated for this client.
1985*5ffb0c9bSToomas Soome  * The client should then record this external IP address and port using whatever
1986*5ffb0c9bSToomas Soome  * directory service mechanism it is using to enable peers to connect to it.
1987*5ffb0c9bSToomas Soome  * (Clients advertising services using Wide-Area DNS-SD DO NOT need to use this API
1988*5ffb0c9bSToomas Soome  * -- when a client calls DNSServiceRegister() NAT mappings are automatically created
1989*5ffb0c9bSToomas Soome  * and the external IP address and port for the service are recorded in the global DNS.
1990*5ffb0c9bSToomas Soome  * Only clients using some directory mechanism other than Wide-Area DNS-SD need to use
1991*5ffb0c9bSToomas Soome  * this API to explicitly map their own ports.)
1992*5ffb0c9bSToomas Soome  *
1993*5ffb0c9bSToomas Soome  * It's possible that the client callback could be called multiple times, for example
1994*5ffb0c9bSToomas Soome  * if the NAT gateway's IP address changes, or if a configuration change results in a
1995*5ffb0c9bSToomas Soome  * different external port being mapped for this client. Over the lifetime of any long-lived
1996*5ffb0c9bSToomas Soome  * port mapping, the client should be prepared to handle these notifications of changes
1997*5ffb0c9bSToomas Soome  * in the environment, and should update its recorded address and/or port as appropriate.
1998*5ffb0c9bSToomas Soome  *
1999*5ffb0c9bSToomas Soome  * NOTE: There are two unusual aspects of how the DNSServiceNATPortMappingCreate API works,
2000*5ffb0c9bSToomas Soome  * which were intentionally designed to help simplify client code:
2001*5ffb0c9bSToomas Soome  *
2002*5ffb0c9bSToomas Soome  *  1. It's not an error to request a NAT mapping when the machine is not behind a NAT gateway.
2003*5ffb0c9bSToomas Soome  *     In other NAT mapping APIs, if you request a NAT mapping and the machine is not behind a NAT
2004*5ffb0c9bSToomas Soome  *     gateway, then the API returns an error code -- it can't get you a NAT mapping if there's no
2005*5ffb0c9bSToomas Soome  *     NAT gateway. The DNSServiceNATPortMappingCreate API takes a different view. Working out
2006*5ffb0c9bSToomas Soome  *     whether or not you need a NAT mapping can be tricky and non-obvious, particularly on
2007*5ffb0c9bSToomas Soome  *     a machine with multiple active network interfaces. Rather than make every client recreate
2008*5ffb0c9bSToomas Soome  *     this logic for deciding whether a NAT mapping is required, the PortMapping API does that
2009*5ffb0c9bSToomas Soome  *     work for you. If the client calls the PortMapping API when the machine already has a
2010*5ffb0c9bSToomas Soome  *     routable public IP address, then instead of complaining about it and giving an error,
2011*5ffb0c9bSToomas Soome  *     the PortMapping API just invokes your callback, giving the machine's public address
2012*5ffb0c9bSToomas Soome  *     and your own port number. This means you don't need to write code to work out whether
2013*5ffb0c9bSToomas Soome  *     your client needs to call the PortMapping API -- just call it anyway, and if it wasn't
2014*5ffb0c9bSToomas Soome  *     necessary, no harm is done:
2015*5ffb0c9bSToomas Soome  *
2016*5ffb0c9bSToomas Soome  *     - If the machine already has a routable public IP address, then your callback
2017*5ffb0c9bSToomas Soome  *       will just be invoked giving your own address and port.
2018*5ffb0c9bSToomas Soome  *     - If a NAT mapping is required and obtained, then your callback will be invoked
2019*5ffb0c9bSToomas Soome  *       giving you the external address and port.
2020*5ffb0c9bSToomas Soome  *     - If a NAT mapping is required but not obtained from the local NAT gateway,
2021*5ffb0c9bSToomas Soome  *       or the machine has no network connectivity, then your callback will be
2022*5ffb0c9bSToomas Soome  *       invoked giving zero address and port.
2023*5ffb0c9bSToomas Soome  *
2024*5ffb0c9bSToomas Soome  *  2. In other NAT mapping APIs, if a laptop computer is put to sleep and woken up on a new
2025*5ffb0c9bSToomas Soome  *     network, it's the client's job to notice this, and work out whether a NAT mapping
2026*5ffb0c9bSToomas Soome  *     is required on the new network, and make a new NAT mapping request if necessary.
2027*5ffb0c9bSToomas Soome  *     The DNSServiceNATPortMappingCreate API does this for you, automatically.
2028*5ffb0c9bSToomas Soome  *     The client just needs to make one call to the PortMapping API, and its callback will
2029*5ffb0c9bSToomas Soome  *     be invoked any time the mapping state changes. This property complements point (1) above.
2030*5ffb0c9bSToomas Soome  *     If the client didn't make a NAT mapping request just because it determined that one was
2031*5ffb0c9bSToomas Soome  *     not required at that particular moment in time, the client would then have to monitor
2032*5ffb0c9bSToomas Soome  *     for network state changes to determine if a NAT port mapping later became necessary.
2033*5ffb0c9bSToomas Soome  *     By unconditionally making a NAT mapping request, even when a NAT mapping not to be
2034*5ffb0c9bSToomas Soome  *     necessary, the PortMapping API will then begin monitoring network state changes on behalf of
2035*5ffb0c9bSToomas Soome  *     the client, and if a NAT mapping later becomes necessary, it will automatically create a NAT
2036*5ffb0c9bSToomas Soome  *     mapping and inform the client with a new callback giving the new address and port information.
2037*5ffb0c9bSToomas Soome  *
2038*5ffb0c9bSToomas Soome  * DNSServiceNATPortMappingReply() parameters:
2039*5ffb0c9bSToomas Soome  *
2040*5ffb0c9bSToomas Soome  * sdRef:           The DNSServiceRef initialized by DNSServiceNATPortMappingCreate().
2041*5ffb0c9bSToomas Soome  *
2042*5ffb0c9bSToomas Soome  * flags:           Currently unused, reserved for future use.
2043*5ffb0c9bSToomas Soome  *
2044*5ffb0c9bSToomas Soome  * interfaceIndex:  The interface through which the NAT gateway is reached.
2045*5ffb0c9bSToomas Soome  *
2046*5ffb0c9bSToomas Soome  * errorCode:       Will be kDNSServiceErr_NoError on success.
2047*5ffb0c9bSToomas Soome  *                  Will be kDNSServiceErr_DoubleNAT when the NAT gateway is itself behind one or
2048*5ffb0c9bSToomas Soome  *                  more layers of NAT, in which case the other parameters have the defined values.
2049*5ffb0c9bSToomas Soome  *                  For other failures, will indicate the failure that occurred, and the other
2050*5ffb0c9bSToomas Soome  *                  parameters are undefined.
2051*5ffb0c9bSToomas Soome  *
2052*5ffb0c9bSToomas Soome  * externalAddress: Four byte IPv4 address in network byte order.
2053*5ffb0c9bSToomas Soome  *
2054*5ffb0c9bSToomas Soome  * protocol:        Will be kDNSServiceProtocol_UDP or kDNSServiceProtocol_TCP or both.
2055*5ffb0c9bSToomas Soome  *
2056*5ffb0c9bSToomas Soome  * internalPort:    The port on the local machine that was mapped.
2057*5ffb0c9bSToomas Soome  *
2058*5ffb0c9bSToomas Soome  * externalPort:    The actual external port in the NAT gateway that was mapped.
2059*5ffb0c9bSToomas Soome  *                  This is likely to be different than the requested external port.
2060*5ffb0c9bSToomas Soome  *
2061*5ffb0c9bSToomas Soome  * ttl:             The lifetime of the NAT port mapping created on the gateway.
2062*5ffb0c9bSToomas Soome  *                  This controls how quickly stale mappings will be garbage-collected
2063*5ffb0c9bSToomas Soome  *                  if the client machine crashes, suffers a power failure, is disconnected
2064*5ffb0c9bSToomas Soome  *                  from the network, or suffers some other unfortunate demise which
2065*5ffb0c9bSToomas Soome  *                  causes it to vanish without explicitly removing its NAT port mapping.
2066*5ffb0c9bSToomas Soome  *                  It's possible that the ttl value will differ from the requested ttl value.
2067*5ffb0c9bSToomas Soome  *
2068*5ffb0c9bSToomas Soome  * context:         The context pointer that was passed to the callout.
2069*5ffb0c9bSToomas Soome  *
2070*5ffb0c9bSToomas Soome  */
2071*5ffb0c9bSToomas Soome 
2072*5ffb0c9bSToomas Soome typedef void (DNSSD_API *DNSServiceNATPortMappingReply)
2073*5ffb0c9bSToomas Soome (
2074*5ffb0c9bSToomas Soome     DNSServiceRef sdRef,
2075*5ffb0c9bSToomas Soome     DNSServiceFlags flags,
2076*5ffb0c9bSToomas Soome     uint32_t interfaceIndex,
2077*5ffb0c9bSToomas Soome     DNSServiceErrorType errorCode,
2078*5ffb0c9bSToomas Soome     uint32_t externalAddress,                           /* four byte IPv4 address in network byte order */
2079*5ffb0c9bSToomas Soome     DNSServiceProtocol protocol,
2080*5ffb0c9bSToomas Soome     uint16_t internalPort,                              /* In network byte order */
2081*5ffb0c9bSToomas Soome     uint16_t externalPort,                              /* In network byte order and may be different than the requested port */
2082*5ffb0c9bSToomas Soome     uint32_t ttl,                                       /* may be different than the requested ttl */
2083*5ffb0c9bSToomas Soome     void                             *context
2084*5ffb0c9bSToomas Soome );
2085*5ffb0c9bSToomas Soome 
2086*5ffb0c9bSToomas Soome 
2087*5ffb0c9bSToomas Soome /* DNSServiceNATPortMappingCreate() Parameters:
2088*5ffb0c9bSToomas Soome  *
2089*5ffb0c9bSToomas Soome  * sdRef:           A pointer to an uninitialized DNSServiceRef. If the call succeeds then it
2090*5ffb0c9bSToomas Soome  *                  initializes the DNSServiceRef, returns kDNSServiceErr_NoError, and the nat
2091*5ffb0c9bSToomas Soome  *                  port mapping will last indefinitely until the client terminates the port
2092*5ffb0c9bSToomas Soome  *                  mapping request by passing this DNSServiceRef to DNSServiceRefDeallocate().
2093*5ffb0c9bSToomas Soome  *
2094*5ffb0c9bSToomas Soome  * flags:           Currently ignored, reserved for future use.
2095*5ffb0c9bSToomas Soome  *
2096*5ffb0c9bSToomas Soome  * interfaceIndex:  The interface on which to create port mappings in a NAT gateway. Passing 0 causes
2097*5ffb0c9bSToomas Soome  *                  the port mapping request to be sent on the primary interface.
2098*5ffb0c9bSToomas Soome  *
2099*5ffb0c9bSToomas Soome  * protocol:        To request a port mapping, pass in kDNSServiceProtocol_UDP, or kDNSServiceProtocol_TCP,
2100*5ffb0c9bSToomas Soome  *                  or (kDNSServiceProtocol_UDP | kDNSServiceProtocol_TCP) to map both.
2101*5ffb0c9bSToomas Soome  *                  The local listening port number must also be specified in the internalPort parameter.
2102*5ffb0c9bSToomas Soome  *                  To just discover the NAT gateway's external IP address, pass zero for protocol,
2103*5ffb0c9bSToomas Soome  *                  internalPort, externalPort and ttl.
2104*5ffb0c9bSToomas Soome  *
2105*5ffb0c9bSToomas Soome  * internalPort:    The port number in network byte order on the local machine which is listening for packets.
2106*5ffb0c9bSToomas Soome  *
2107*5ffb0c9bSToomas Soome  * externalPort:    The requested external port in network byte order in the NAT gateway that you would
2108*5ffb0c9bSToomas Soome  *                  like to map to the internal port. Pass 0 if you don't care which external port is chosen for you.
2109*5ffb0c9bSToomas Soome  *
2110*5ffb0c9bSToomas Soome  * ttl:             The requested renewal period of the NAT port mapping, in seconds.
2111*5ffb0c9bSToomas Soome  *                  If the client machine crashes, suffers a power failure, is disconnected from
2112*5ffb0c9bSToomas Soome  *                  the network, or suffers some other unfortunate demise which causes it to vanish
2113*5ffb0c9bSToomas Soome  *                  unexpectedly without explicitly removing its NAT port mappings, then the NAT gateway
2114*5ffb0c9bSToomas Soome  *                  will garbage-collect old stale NAT port mappings when their lifetime expires.
2115*5ffb0c9bSToomas Soome  *                  Requesting a short TTL causes such orphaned mappings to be garbage-collected
2116*5ffb0c9bSToomas Soome  *                  more promptly, but consumes system resources and network bandwidth with
2117*5ffb0c9bSToomas Soome  *                  frequent renewal packets to keep the mapping from expiring.
2118*5ffb0c9bSToomas Soome  *                  Requesting a long TTL is more efficient on the network, but in the event of the
2119*5ffb0c9bSToomas Soome  *                  client vanishing, stale NAT port mappings will not be garbage-collected as quickly.
2120*5ffb0c9bSToomas Soome  *                  Most clients should pass 0 to use a system-wide default value.
2121*5ffb0c9bSToomas Soome  *
2122*5ffb0c9bSToomas Soome  * callBack:        The function to be called when the port mapping request succeeds or fails asynchronously.
2123*5ffb0c9bSToomas Soome  *
2124*5ffb0c9bSToomas Soome  * context:         An application context pointer which is passed to the callback function
2125*5ffb0c9bSToomas Soome  *                  (may be NULL).
2126*5ffb0c9bSToomas Soome  *
2127*5ffb0c9bSToomas Soome  * return value:    Returns kDNSServiceErr_NoError on success (any subsequent, asynchronous
2128*5ffb0c9bSToomas Soome  *                  errors are delivered to the callback), otherwise returns an error code indicating
2129*5ffb0c9bSToomas Soome  *                  the error that occurred.
2130*5ffb0c9bSToomas Soome  *
2131*5ffb0c9bSToomas Soome  *                  If you don't actually want a port mapped, and are just calling the API
2132*5ffb0c9bSToomas Soome  *                  because you want to find out the NAT's external IP address (e.g. for UI
2133*5ffb0c9bSToomas Soome  *                  display) then pass zero for protocol, internalPort, externalPort and ttl.
2134*5ffb0c9bSToomas Soome  */
2135*5ffb0c9bSToomas Soome 
2136*5ffb0c9bSToomas Soome DNSServiceErrorType DNSSD_API DNSServiceNATPortMappingCreate
2137*5ffb0c9bSToomas Soome (
2138*5ffb0c9bSToomas Soome     DNSServiceRef                    *sdRef,
2139*5ffb0c9bSToomas Soome     DNSServiceFlags flags,
2140*5ffb0c9bSToomas Soome     uint32_t interfaceIndex,
2141*5ffb0c9bSToomas Soome     DNSServiceProtocol protocol,                        /* TCP and/or UDP          */
2142*5ffb0c9bSToomas Soome     uint16_t internalPort,                              /* network byte order      */
2143*5ffb0c9bSToomas Soome     uint16_t externalPort,                              /* network byte order      */
2144*5ffb0c9bSToomas Soome     uint32_t ttl,                                       /* time to live in seconds */
2145*5ffb0c9bSToomas Soome     DNSServiceNATPortMappingReply callBack,
2146*5ffb0c9bSToomas Soome     void                             *context           /* may be NULL             */
2147*5ffb0c9bSToomas Soome );
2148*5ffb0c9bSToomas Soome 
2149*5ffb0c9bSToomas Soome 
2150*5ffb0c9bSToomas Soome /*********************************************************************************************
2151*5ffb0c9bSToomas Soome *
21524b22b933Srs200217 *  General Utility Functions
21534b22b933Srs200217 *
21544b22b933Srs200217 *********************************************************************************************/
21554b22b933Srs200217 
21564b22b933Srs200217 /* DNSServiceConstructFullName()
21574b22b933Srs200217  *
21584b22b933Srs200217  * Concatenate a three-part domain name (as returned by the above callbacks) into a
21594b22b933Srs200217  * properly-escaped full domain name. Note that callbacks in the above functions ALREADY ESCAPE
21604b22b933Srs200217  * strings where necessary.
21614b22b933Srs200217  *
21624b22b933Srs200217  * Parameters:
21634b22b933Srs200217  *
21644b22b933Srs200217  * fullName:        A pointer to a buffer that where the resulting full domain name is to be written.
2165*5ffb0c9bSToomas Soome  *                  The buffer must be kDNSServiceMaxDomainName (1009) bytes in length to
21664b22b933Srs200217  *                  accommodate the longest legal domain name without buffer overrun.
21674b22b933Srs200217  *
21684b22b933Srs200217  * service:         The service name - any dots or backslashes must NOT be escaped.
21694b22b933Srs200217  *                  May be NULL (to construct a PTR record name, e.g.
21704b22b933Srs200217  *                  "_ftp._tcp.apple.com.").
21714b22b933Srs200217  *
21724b22b933Srs200217  * regtype:         The service type followed by the protocol, separated by a dot
21734b22b933Srs200217  *                  (e.g. "_ftp._tcp").
21744b22b933Srs200217  *
21754b22b933Srs200217  * domain:          The domain name, e.g. "apple.com.". Literal dots or backslashes,
21764b22b933Srs200217  *                  if any, must be escaped, e.g. "1st\. Floor.apple.com."
21774b22b933Srs200217  *
2178*5ffb0c9bSToomas Soome  * return value:    Returns kDNSServiceErr_NoError (0) on success, kDNSServiceErr_BadParam on error.
21794b22b933Srs200217  *
21804b22b933Srs200217  */
21814b22b933Srs200217 
2182*5ffb0c9bSToomas Soome DNSServiceErrorType DNSSD_API DNSServiceConstructFullName
21834b22b933Srs200217 (
2184*5ffb0c9bSToomas Soome     char                            * const fullName,
2185*5ffb0c9bSToomas Soome     const char                      * const service,      /* may be NULL */
2186*5ffb0c9bSToomas Soome     const char                      * const regtype,
2187*5ffb0c9bSToomas Soome     const char                      * const domain
21884b22b933Srs200217 );
21894b22b933Srs200217 
21904b22b933Srs200217 
21914b22b933Srs200217 /*********************************************************************************************
21924b22b933Srs200217 *
21934b22b933Srs200217 *   TXT Record Construction Functions
21944b22b933Srs200217 *
21954b22b933Srs200217 *********************************************************************************************/
21964b22b933Srs200217 
21974b22b933Srs200217 /*
21984b22b933Srs200217  * A typical calling sequence for TXT record construction is something like:
21994b22b933Srs200217  *
22004b22b933Srs200217  * Client allocates storage for TXTRecord data (e.g. declare buffer on the stack)
22014b22b933Srs200217  * TXTRecordCreate();
22024b22b933Srs200217  * TXTRecordSetValue();
22034b22b933Srs200217  * TXTRecordSetValue();
22044b22b933Srs200217  * TXTRecordSetValue();
22054b22b933Srs200217  * ...
22064b22b933Srs200217  * DNSServiceRegister( ... TXTRecordGetLength(), TXTRecordGetBytesPtr() ... );
22074b22b933Srs200217  * TXTRecordDeallocate();
22084b22b933Srs200217  * Explicitly deallocate storage for TXTRecord data (if not allocated on the stack)
22094b22b933Srs200217  */
22104b22b933Srs200217 
22114b22b933Srs200217 
22124b22b933Srs200217 /* TXTRecordRef
22134b22b933Srs200217  *
22144b22b933Srs200217  * Opaque internal data type.
22154b22b933Srs200217  * Note: Represents a DNS-SD TXT record.
22164b22b933Srs200217  */
22174b22b933Srs200217 
22184b22b933Srs200217 typedef union _TXTRecordRef_t { char PrivateData[16]; char *ForceNaturalAlignment; } TXTRecordRef;
22194b22b933Srs200217 
22204b22b933Srs200217 
22214b22b933Srs200217 /* TXTRecordCreate()
22224b22b933Srs200217  *
22234b22b933Srs200217  * Creates a new empty TXTRecordRef referencing the specified storage.
22244b22b933Srs200217  *
22254b22b933Srs200217  * If the buffer parameter is NULL, or the specified storage size is not
22264b22b933Srs200217  * large enough to hold a key subsequently added using TXTRecordSetValue(),
22274b22b933Srs200217  * then additional memory will be added as needed using malloc().
22284b22b933Srs200217  *
22294b22b933Srs200217  * On some platforms, when memory is low, malloc() may fail. In this
22304b22b933Srs200217  * case, TXTRecordSetValue() will return kDNSServiceErr_NoMemory, and this
22314b22b933Srs200217  * error condition will need to be handled as appropriate by the caller.
22324b22b933Srs200217  *
22334b22b933Srs200217  * You can avoid the need to handle this error condition if you ensure
22344b22b933Srs200217  * that the storage you initially provide is large enough to hold all
22354b22b933Srs200217  * the key/value pairs that are to be added to the record.
22364b22b933Srs200217  * The caller can precompute the exact length required for all of the
22374b22b933Srs200217  * key/value pairs to be added, or simply provide a fixed-sized buffer
22384b22b933Srs200217  * known in advance to be large enough.
22394b22b933Srs200217  * A no-value (key-only) key requires  (1 + key length) bytes.
22404b22b933Srs200217  * A key with empty value requires     (1 + key length + 1) bytes.
22414b22b933Srs200217  * A key with non-empty value requires (1 + key length + 1 + value length).
22424b22b933Srs200217  * For most applications, DNS-SD TXT records are generally
22434b22b933Srs200217  * less than 100 bytes, so in most cases a simple fixed-sized
22444b22b933Srs200217  * 256-byte buffer will be more than sufficient.
22454b22b933Srs200217  * Recommended size limits for DNS-SD TXT Records are discussed in
22464b22b933Srs200217  * <http://files.dns-sd.org/draft-cheshire-dnsext-dns-sd.txt>
22474b22b933Srs200217  *
22484b22b933Srs200217  * Note: When passing parameters to and from these TXT record APIs,
22494b22b933Srs200217  * the key name does not include the '=' character. The '=' character
22504b22b933Srs200217  * is the separator between the key and value in the on-the-wire
22514b22b933Srs200217  * packet format; it is not part of either the key or the value.
22524b22b933Srs200217  *
22534b22b933Srs200217  * txtRecord:       A pointer to an uninitialized TXTRecordRef.
22544b22b933Srs200217  *
22554b22b933Srs200217  * bufferLen:       The size of the storage provided in the "buffer" parameter.
22564b22b933Srs200217  *
22574b22b933Srs200217  * buffer:          Optional caller-supplied storage used to hold the TXTRecord data.
22584b22b933Srs200217  *                  This storage must remain valid for as long as
22594b22b933Srs200217  *                  the TXTRecordRef.
22604b22b933Srs200217  */
22614b22b933Srs200217 
22624b22b933Srs200217 void DNSSD_API TXTRecordCreate
22634b22b933Srs200217 (
22644b22b933Srs200217     TXTRecordRef     *txtRecord,
22654b22b933Srs200217     uint16_t bufferLen,
22664b22b933Srs200217     void             *buffer
22674b22b933Srs200217 );
22684b22b933Srs200217 
22694b22b933Srs200217 
22704b22b933Srs200217 /* TXTRecordDeallocate()
22714b22b933Srs200217  *
22724b22b933Srs200217  * Releases any resources allocated in the course of preparing a TXT Record
22734b22b933Srs200217  * using TXTRecordCreate()/TXTRecordSetValue()/TXTRecordRemoveValue().
22744b22b933Srs200217  * Ownership of the buffer provided in TXTRecordCreate() returns to the client.
22754b22b933Srs200217  *
22764b22b933Srs200217  * txtRecord:           A TXTRecordRef initialized by calling TXTRecordCreate().
22774b22b933Srs200217  *
22784b22b933Srs200217  */
22794b22b933Srs200217 
22804b22b933Srs200217 void DNSSD_API TXTRecordDeallocate
22814b22b933Srs200217 (
22824b22b933Srs200217     TXTRecordRef     *txtRecord
22834b22b933Srs200217 );
22844b22b933Srs200217 
22854b22b933Srs200217 
22864b22b933Srs200217 /* TXTRecordSetValue()
22874b22b933Srs200217  *
22884b22b933Srs200217  * Adds a key (optionally with value) to a TXTRecordRef. If the "key" already
22894b22b933Srs200217  * exists in the TXTRecordRef, then the current value will be replaced with
22904b22b933Srs200217  * the new value.
22914b22b933Srs200217  * Keys may exist in four states with respect to a given TXT record:
22924b22b933Srs200217  *  - Absent (key does not appear at all)
22934b22b933Srs200217  *  - Present with no value ("key" appears alone)
22944b22b933Srs200217  *  - Present with empty value ("key=" appears in TXT record)
22954b22b933Srs200217  *  - Present with non-empty value ("key=value" appears in TXT record)
22964b22b933Srs200217  * For more details refer to "Data Syntax for DNS-SD TXT Records" in
22974b22b933Srs200217  * <http://files.dns-sd.org/draft-cheshire-dnsext-dns-sd.txt>
22984b22b933Srs200217  *
22994b22b933Srs200217  * txtRecord:       A TXTRecordRef initialized by calling TXTRecordCreate().
23004b22b933Srs200217  *
23014b22b933Srs200217  * key:             A null-terminated string which only contains printable ASCII
23024b22b933Srs200217  *                  values (0x20-0x7E), excluding '=' (0x3D). Keys should be
2303*5ffb0c9bSToomas Soome  *                  9 characters or fewer (not counting the terminating null).
23044b22b933Srs200217  *
23054b22b933Srs200217  * valueSize:       The size of the value.
23064b22b933Srs200217  *
23074b22b933Srs200217  * value:           Any binary value. For values that represent
23084b22b933Srs200217  *                  textual data, UTF-8 is STRONGLY recommended.
23094b22b933Srs200217  *                  For values that represent textual data, valueSize
23104b22b933Srs200217  *                  should NOT include the terminating null (if any)
23114b22b933Srs200217  *                  at the end of the string.
23124b22b933Srs200217  *                  If NULL, then "key" will be added with no value.
23134b22b933Srs200217  *                  If non-NULL but valueSize is zero, then "key=" will be
23144b22b933Srs200217  *                  added with empty value.
23154b22b933Srs200217  *
23164b22b933Srs200217  * return value:    Returns kDNSServiceErr_NoError on success.
23174b22b933Srs200217  *                  Returns kDNSServiceErr_Invalid if the "key" string contains
23184b22b933Srs200217  *                  illegal characters.
23194b22b933Srs200217  *                  Returns kDNSServiceErr_NoMemory if adding this key would
23204b22b933Srs200217  *                  exceed the available storage.
23214b22b933Srs200217  */
23224b22b933Srs200217 
23234b22b933Srs200217 DNSServiceErrorType DNSSD_API TXTRecordSetValue
23244b22b933Srs200217 (
23254b22b933Srs200217     TXTRecordRef     *txtRecord,
23264b22b933Srs200217     const char       *key,
23274b22b933Srs200217     uint8_t valueSize,                 /* may be zero */
23284b22b933Srs200217     const void       *value            /* may be NULL */
23294b22b933Srs200217 );
23304b22b933Srs200217 
23314b22b933Srs200217 
23324b22b933Srs200217 /* TXTRecordRemoveValue()
23334b22b933Srs200217  *
23344b22b933Srs200217  * Removes a key from a TXTRecordRef. The "key" must be an
23354b22b933Srs200217  * ASCII string which exists in the TXTRecordRef.
23364b22b933Srs200217  *
23374b22b933Srs200217  * txtRecord:       A TXTRecordRef initialized by calling TXTRecordCreate().
23384b22b933Srs200217  *
23394b22b933Srs200217  * key:             A key name which exists in the TXTRecordRef.
23404b22b933Srs200217  *
23414b22b933Srs200217  * return value:    Returns kDNSServiceErr_NoError on success.
23424b22b933Srs200217  *                  Returns kDNSServiceErr_NoSuchKey if the "key" does not
23434b22b933Srs200217  *                  exist in the TXTRecordRef.
23444b22b933Srs200217  */
23454b22b933Srs200217 
23464b22b933Srs200217 DNSServiceErrorType DNSSD_API TXTRecordRemoveValue
23474b22b933Srs200217 (
23484b22b933Srs200217     TXTRecordRef     *txtRecord,
23494b22b933Srs200217     const char       *key
23504b22b933Srs200217 );
23514b22b933Srs200217 
23524b22b933Srs200217 
23534b22b933Srs200217 /* TXTRecordGetLength()
23544b22b933Srs200217  *
23554b22b933Srs200217  * Allows you to determine the length of the raw bytes within a TXTRecordRef.
23564b22b933Srs200217  *
23574b22b933Srs200217  * txtRecord:       A TXTRecordRef initialized by calling TXTRecordCreate().
23584b22b933Srs200217  *
23594b22b933Srs200217  * return value:    Returns the size of the raw bytes inside a TXTRecordRef
23604b22b933Srs200217  *                  which you can pass directly to DNSServiceRegister() or
23614b22b933Srs200217  *                  to DNSServiceUpdateRecord().
23624b22b933Srs200217  *                  Returns 0 if the TXTRecordRef is empty.
23634b22b933Srs200217  */
23644b22b933Srs200217 
23654b22b933Srs200217 uint16_t DNSSD_API TXTRecordGetLength
23664b22b933Srs200217 (
23674b22b933Srs200217     const TXTRecordRef *txtRecord
23684b22b933Srs200217 );
23694b22b933Srs200217 
23704b22b933Srs200217 
23714b22b933Srs200217 /* TXTRecordGetBytesPtr()
23724b22b933Srs200217  *
23734b22b933Srs200217  * Allows you to retrieve a pointer to the raw bytes within a TXTRecordRef.
23744b22b933Srs200217  *
23754b22b933Srs200217  * txtRecord:       A TXTRecordRef initialized by calling TXTRecordCreate().
23764b22b933Srs200217  *
23774b22b933Srs200217  * return value:    Returns a pointer to the raw bytes inside the TXTRecordRef
23784b22b933Srs200217  *                  which you can pass directly to DNSServiceRegister() or
23794b22b933Srs200217  *                  to DNSServiceUpdateRecord().
23804b22b933Srs200217  */
23814b22b933Srs200217 
23824b22b933Srs200217 const void * DNSSD_API TXTRecordGetBytesPtr
23834b22b933Srs200217 (
23844b22b933Srs200217     const TXTRecordRef *txtRecord
23854b22b933Srs200217 );
23864b22b933Srs200217 
23874b22b933Srs200217 
23884b22b933Srs200217 /*********************************************************************************************
23894b22b933Srs200217 *
23904b22b933Srs200217 *   TXT Record Parsing Functions
23914b22b933Srs200217 *
23924b22b933Srs200217 *********************************************************************************************/
23934b22b933Srs200217 
23944b22b933Srs200217 /*
23954b22b933Srs200217  * A typical calling sequence for TXT record parsing is something like:
23964b22b933Srs200217  *
23974b22b933Srs200217  * Receive TXT record data in DNSServiceResolve() callback
23984b22b933Srs200217  * if (TXTRecordContainsKey(txtLen, txtRecord, "key")) then do something
23994b22b933Srs200217  * val1ptr = TXTRecordGetValuePtr(txtLen, txtRecord, "key1", &len1);
24004b22b933Srs200217  * val2ptr = TXTRecordGetValuePtr(txtLen, txtRecord, "key2", &len2);
24014b22b933Srs200217  * ...
2402*5ffb0c9bSToomas Soome  * memcpy(myval1, val1ptr, len1);
2403*5ffb0c9bSToomas Soome  * memcpy(myval2, val2ptr, len2);
24044b22b933Srs200217  * ...
24054b22b933Srs200217  * return;
24064b22b933Srs200217  *
24074b22b933Srs200217  * If you wish to retain the values after return from the DNSServiceResolve()
2408*5ffb0c9bSToomas Soome  * callback, then you need to copy the data to your own storage using memcpy()
24094b22b933Srs200217  * or similar, as shown in the example above.
24104b22b933Srs200217  *
24114b22b933Srs200217  * If for some reason you need to parse a TXT record you built yourself
24124b22b933Srs200217  * using the TXT record construction functions above, then you can do
24134b22b933Srs200217  * that using TXTRecordGetLength and TXTRecordGetBytesPtr calls:
24144b22b933Srs200217  * TXTRecordGetValue(TXTRecordGetLength(x), TXTRecordGetBytesPtr(x), key, &len);
24154b22b933Srs200217  *
24164b22b933Srs200217  * Most applications only fetch keys they know about from a TXT record and
24174b22b933Srs200217  * ignore the rest.
24184b22b933Srs200217  * However, some debugging tools wish to fetch and display all keys.
24194b22b933Srs200217  * To do that, use the TXTRecordGetCount() and TXTRecordGetItemAtIndex() calls.
24204b22b933Srs200217  */
24214b22b933Srs200217 
24224b22b933Srs200217 /* TXTRecordContainsKey()
24234b22b933Srs200217  *
24244b22b933Srs200217  * Allows you to determine if a given TXT Record contains a specified key.
24254b22b933Srs200217  *
24264b22b933Srs200217  * txtLen:          The size of the received TXT Record.
24274b22b933Srs200217  *
24284b22b933Srs200217  * txtRecord:       Pointer to the received TXT Record bytes.
24294b22b933Srs200217  *
24304b22b933Srs200217  * key:             A null-terminated ASCII string containing the key name.
24314b22b933Srs200217  *
24324b22b933Srs200217  * return value:    Returns 1 if the TXT Record contains the specified key.
24334b22b933Srs200217  *                  Otherwise, it returns 0.
24344b22b933Srs200217  */
24354b22b933Srs200217 
24364b22b933Srs200217 int DNSSD_API TXTRecordContainsKey
24374b22b933Srs200217 (
24384b22b933Srs200217     uint16_t txtLen,
24394b22b933Srs200217     const void       *txtRecord,
24404b22b933Srs200217     const char       *key
24414b22b933Srs200217 );
24424b22b933Srs200217 
24434b22b933Srs200217 
24444b22b933Srs200217 /* TXTRecordGetValuePtr()
24454b22b933Srs200217  *
24464b22b933Srs200217  * Allows you to retrieve the value for a given key from a TXT Record.
24474b22b933Srs200217  *
24484b22b933Srs200217  * txtLen:          The size of the received TXT Record
24494b22b933Srs200217  *
24504b22b933Srs200217  * txtRecord:       Pointer to the received TXT Record bytes.
24514b22b933Srs200217  *
24524b22b933Srs200217  * key:             A null-terminated ASCII string containing the key name.
24534b22b933Srs200217  *
24544b22b933Srs200217  * valueLen:        On output, will be set to the size of the "value" data.
24554b22b933Srs200217  *
24564b22b933Srs200217  * return value:    Returns NULL if the key does not exist in this TXT record,
24574b22b933Srs200217  *                  or exists with no value (to differentiate between
24584b22b933Srs200217  *                  these two cases use TXTRecordContainsKey()).
24594b22b933Srs200217  *                  Returns pointer to location within TXT Record bytes
24604b22b933Srs200217  *                  if the key exists with empty or non-empty value.
24614b22b933Srs200217  *                  For empty value, valueLen will be zero.
24624b22b933Srs200217  *                  For non-empty value, valueLen will be length of value data.
24634b22b933Srs200217  */
24644b22b933Srs200217 
24654b22b933Srs200217 const void * DNSSD_API TXTRecordGetValuePtr
24664b22b933Srs200217 (
24674b22b933Srs200217     uint16_t txtLen,
24684b22b933Srs200217     const void       *txtRecord,
24694b22b933Srs200217     const char       *key,
24704b22b933Srs200217     uint8_t          *valueLen
24714b22b933Srs200217 );
24724b22b933Srs200217 
24734b22b933Srs200217 
24744b22b933Srs200217 /* TXTRecordGetCount()
24754b22b933Srs200217  *
24764b22b933Srs200217  * Returns the number of keys stored in the TXT Record. The count
24774b22b933Srs200217  * can be used with TXTRecordGetItemAtIndex() to iterate through the keys.
24784b22b933Srs200217  *
24794b22b933Srs200217  * txtLen:          The size of the received TXT Record.
24804b22b933Srs200217  *
24814b22b933Srs200217  * txtRecord:       Pointer to the received TXT Record bytes.
24824b22b933Srs200217  *
24834b22b933Srs200217  * return value:    Returns the total number of keys in the TXT Record.
24844b22b933Srs200217  *
24854b22b933Srs200217  */
24864b22b933Srs200217 
24874b22b933Srs200217 uint16_t DNSSD_API TXTRecordGetCount
24884b22b933Srs200217 (
24894b22b933Srs200217     uint16_t txtLen,
24904b22b933Srs200217     const void       *txtRecord
24914b22b933Srs200217 );
24924b22b933Srs200217 
24934b22b933Srs200217 
24944b22b933Srs200217 /* TXTRecordGetItemAtIndex()
24954b22b933Srs200217  *
24964b22b933Srs200217  * Allows you to retrieve a key name and value pointer, given an index into
24974b22b933Srs200217  * a TXT Record. Legal index values range from zero to TXTRecordGetCount()-1.
24984b22b933Srs200217  * It's also possible to iterate through keys in a TXT record by simply
24994b22b933Srs200217  * calling TXTRecordGetItemAtIndex() repeatedly, beginning with index zero
25004b22b933Srs200217  * and increasing until TXTRecordGetItemAtIndex() returns kDNSServiceErr_Invalid.
25014b22b933Srs200217  *
25024b22b933Srs200217  * On return:
25034b22b933Srs200217  * For keys with no value, *value is set to NULL and *valueLen is zero.
25044b22b933Srs200217  * For keys with empty value, *value is non-NULL and *valueLen is zero.
25054b22b933Srs200217  * For keys with non-empty value, *value is non-NULL and *valueLen is non-zero.
25064b22b933Srs200217  *
25074b22b933Srs200217  * txtLen:          The size of the received TXT Record.
25084b22b933Srs200217  *
25094b22b933Srs200217  * txtRecord:       Pointer to the received TXT Record bytes.
25104b22b933Srs200217  *
2511*5ffb0c9bSToomas Soome  * itemIndex:       An index into the TXT Record.
25124b22b933Srs200217  *
25134b22b933Srs200217  * keyBufLen:       The size of the string buffer being supplied.
25144b22b933Srs200217  *
25154b22b933Srs200217  * key:             A string buffer used to store the key name.
25164b22b933Srs200217  *                  On return, the buffer contains a null-terminated C string
25174b22b933Srs200217  *                  giving the key name. DNS-SD TXT keys are usually
2518*5ffb0c9bSToomas Soome  *                  9 characters or fewer. To hold the maximum possible
25194b22b933Srs200217  *                  key name, the buffer should be 256 bytes long.
25204b22b933Srs200217  *
25214b22b933Srs200217  * valueLen:        On output, will be set to the size of the "value" data.
25224b22b933Srs200217  *
25234b22b933Srs200217  * value:           On output, *value is set to point to location within TXT
25244b22b933Srs200217  *                  Record bytes that holds the value data.
25254b22b933Srs200217  *
25264b22b933Srs200217  * return value:    Returns kDNSServiceErr_NoError on success.
25274b22b933Srs200217  *                  Returns kDNSServiceErr_NoMemory if keyBufLen is too short.
25284b22b933Srs200217  *                  Returns kDNSServiceErr_Invalid if index is greater than
25294b22b933Srs200217  *                  TXTRecordGetCount()-1.
25304b22b933Srs200217  */
25314b22b933Srs200217 
25324b22b933Srs200217 DNSServiceErrorType DNSSD_API TXTRecordGetItemAtIndex
25334b22b933Srs200217 (
25344b22b933Srs200217     uint16_t txtLen,
25354b22b933Srs200217     const void       *txtRecord,
2536*5ffb0c9bSToomas Soome     uint16_t itemIndex,
25374b22b933Srs200217     uint16_t keyBufLen,
25384b22b933Srs200217     char             *key,
25394b22b933Srs200217     uint8_t          *valueLen,
25404b22b933Srs200217     const void       **value
25414b22b933Srs200217 );
25424b22b933Srs200217 
2543*5ffb0c9bSToomas Soome #if _DNS_SD_LIBDISPATCH
25444b22b933Srs200217 /*
2545*5ffb0c9bSToomas Soome  * DNSServiceSetDispatchQueue
2546*5ffb0c9bSToomas Soome  *
2547*5ffb0c9bSToomas Soome  * Allows you to schedule a DNSServiceRef on a serial dispatch queue for receiving asynchronous
2548*5ffb0c9bSToomas Soome  * callbacks.  It's the clients responsibility to ensure that the provided dispatch queue is running.
2549*5ffb0c9bSToomas Soome  *
2550*5ffb0c9bSToomas Soome  * A typical application that uses CFRunLoopRun or dispatch_main on its main thread will
2551*5ffb0c9bSToomas Soome  * usually schedule DNSServiceRefs on its main queue (which is always a serial queue)
2552*5ffb0c9bSToomas Soome  * using "DNSServiceSetDispatchQueue(sdref, dispatch_get_main_queue());"
2553*5ffb0c9bSToomas Soome  *
2554*5ffb0c9bSToomas Soome  * If there is any error during the processing of events, the application callback will
2555*5ffb0c9bSToomas Soome  * be called with an error code. For shared connections, each subordinate DNSServiceRef
2556*5ffb0c9bSToomas Soome  * will get its own error callback. Currently these error callbacks only happen
2557*5ffb0c9bSToomas Soome  * if the daemon is manually terminated or crashes, and the error
2558*5ffb0c9bSToomas Soome  * code in this case is kDNSServiceErr_ServiceNotRunning. The application must call
2559*5ffb0c9bSToomas Soome  * DNSServiceRefDeallocate to free the DNSServiceRef when it gets such an error code.
2560*5ffb0c9bSToomas Soome  * These error callbacks are rare and should not normally happen on customer machines,
2561*5ffb0c9bSToomas Soome  * but application code should be written defensively to handle such error callbacks
2562*5ffb0c9bSToomas Soome  * gracefully if they occur.
2563*5ffb0c9bSToomas Soome  *
2564*5ffb0c9bSToomas Soome  * After using DNSServiceSetDispatchQueue on a DNSServiceRef, calling DNSServiceProcessResult
2565*5ffb0c9bSToomas Soome  * on the same DNSServiceRef will result in undefined behavior and should be avoided.
2566*5ffb0c9bSToomas Soome  *
2567*5ffb0c9bSToomas Soome  * Once the application successfully schedules a DNSServiceRef on a serial dispatch queue using
2568*5ffb0c9bSToomas Soome  * DNSServiceSetDispatchQueue, it cannot remove the DNSServiceRef from the dispatch queue, or use
2569*5ffb0c9bSToomas Soome  * DNSServiceSetDispatchQueue a second time to schedule the DNSServiceRef onto a different serial dispatch
2570*5ffb0c9bSToomas Soome  * queue. Once scheduled onto a dispatch queue a DNSServiceRef will deliver events to that queue until
2571*5ffb0c9bSToomas Soome  * the application no longer requires that operation and terminates it using DNSServiceRefDeallocate.
2572*5ffb0c9bSToomas Soome  *
2573*5ffb0c9bSToomas Soome  * service:         DNSServiceRef that was allocated and returned to the application, when the
2574*5ffb0c9bSToomas Soome  *                  application calls one of the DNSService API.
2575*5ffb0c9bSToomas Soome  *
2576*5ffb0c9bSToomas Soome  * queue:           dispatch queue where the application callback will be scheduled
2577*5ffb0c9bSToomas Soome  *
2578*5ffb0c9bSToomas Soome  * return value:    Returns kDNSServiceErr_NoError on success.
2579*5ffb0c9bSToomas Soome  *                  Returns kDNSServiceErr_NoMemory if it cannot create a dispatch source
2580*5ffb0c9bSToomas Soome  *                  Returns kDNSServiceErr_BadParam if the service param is invalid or the
2581*5ffb0c9bSToomas Soome  *                  queue param is invalid
25824b22b933Srs200217  */
25834b22b933Srs200217 
2584*5ffb0c9bSToomas Soome DNSServiceErrorType DNSSD_API DNSServiceSetDispatchQueue
2585*5ffb0c9bSToomas Soome (
2586*5ffb0c9bSToomas Soome     DNSServiceRef service,
2587*5ffb0c9bSToomas Soome     dispatch_queue_t queue
2588*5ffb0c9bSToomas Soome );
2589*5ffb0c9bSToomas Soome #endif //_DNS_SD_LIBDISPATCH
2590*5ffb0c9bSToomas Soome 
2591*5ffb0c9bSToomas Soome #if !defined(_WIN32)
2592*5ffb0c9bSToomas Soome typedef void (DNSSD_API *DNSServiceSleepKeepaliveReply)
2593*5ffb0c9bSToomas Soome (
2594*5ffb0c9bSToomas Soome     DNSServiceRef sdRef,
2595*5ffb0c9bSToomas Soome     DNSServiceErrorType errorCode,
2596*5ffb0c9bSToomas Soome     void                                *context
2597*5ffb0c9bSToomas Soome );
2598*5ffb0c9bSToomas Soome DNSServiceErrorType DNSSD_API DNSServiceSleepKeepalive
2599*5ffb0c9bSToomas Soome (
2600*5ffb0c9bSToomas Soome     DNSServiceRef                       *sdRef,
2601*5ffb0c9bSToomas Soome     DNSServiceFlags flags,
2602*5ffb0c9bSToomas Soome     int fd,
2603*5ffb0c9bSToomas Soome     unsigned int timeout,
2604*5ffb0c9bSToomas Soome     DNSServiceSleepKeepaliveReply callBack,
2605*5ffb0c9bSToomas Soome     void                                *context
2606*5ffb0c9bSToomas Soome );
2607*5ffb0c9bSToomas Soome #endif
2608*5ffb0c9bSToomas Soome 
2609*5ffb0c9bSToomas Soome #ifdef APPLE_OSX_mDNSResponder
2610*5ffb0c9bSToomas Soome /* DNSServiceCreateDelegateConnection()
26114b22b933Srs200217  *
2612*5ffb0c9bSToomas Soome  * Create a delegate connection to the daemon allowing efficient registration of
2613*5ffb0c9bSToomas Soome  * multiple individual records.
26144b22b933Srs200217  *
26154b22b933Srs200217  * Parameters:
26164b22b933Srs200217  *
2617*5ffb0c9bSToomas Soome  * sdRef:           A pointer to an uninitialized DNSServiceRef. Deallocating
2618*5ffb0c9bSToomas Soome  *                  the reference (via DNSServiceRefDeallocate()) severs the
2619*5ffb0c9bSToomas Soome  *                  connection and deregisters all records registered on this connection.
26204b22b933Srs200217  *
2621*5ffb0c9bSToomas Soome  * pid :            Process ID of the delegate
26224b22b933Srs200217  *
2623*5ffb0c9bSToomas Soome  * uuid:            UUID of the delegate
2624*5ffb0c9bSToomas Soome  *
2625*5ffb0c9bSToomas Soome  *                  Note that only one of the two arguments (pid or uuid) can be specified. If pid
2626*5ffb0c9bSToomas Soome  *                  is zero, uuid will be assumed to be a valid value; otherwise pid will be used.
2627*5ffb0c9bSToomas Soome  *
2628*5ffb0c9bSToomas Soome  * return value:    Returns kDNSServiceErr_NoError on success, otherwise returns
2629*5ffb0c9bSToomas Soome  *                  an error code indicating the specific failure that occurred (in which
2630*5ffb0c9bSToomas Soome  *                  case the DNSServiceRef is not initialized). kDNSServiceErr_NotAuth is
2631*5ffb0c9bSToomas Soome  *                  returned to indicate that the calling process does not have entitlements
2632*5ffb0c9bSToomas Soome  *                  to use this API.
26334b22b933Srs200217  */
2634*5ffb0c9bSToomas Soome DNSServiceErrorType DNSSD_API DNSServiceCreateDelegateConnection(DNSServiceRef *sdRef, int32_t pid, uuid_t uuid);
2635*5ffb0c9bSToomas Soome #endif
26364b22b933Srs200217 
2637*5ffb0c9bSToomas Soome #ifdef __APPLE_API_PRIVATE
2638*5ffb0c9bSToomas Soome 
2639*5ffb0c9bSToomas Soome #define kDNSServiceCompPrivateDNS   "PrivateDNS"
2640*5ffb0c9bSToomas Soome #define kDNSServiceCompMulticastDNS "MulticastDNS"
26414b22b933Srs200217 
26424b22b933Srs200217 #endif //__APPLE_API_PRIVATE
26434b22b933Srs200217 
2644*5ffb0c9bSToomas Soome /* Some C compiler cleverness. We can make the compiler check certain things for us,
2645*5ffb0c9bSToomas Soome  * and report errors at compile-time if anything is wrong. The usual way to do this would
2646*5ffb0c9bSToomas Soome  * be to use a run-time "if" statement or the conventional run-time "assert" mechanism, but
2647*5ffb0c9bSToomas Soome  * then you don't find out what's wrong until you run the software. This way, if the assertion
2648*5ffb0c9bSToomas Soome  * condition is false, the array size is negative, and the complier complains immediately.
2649*5ffb0c9bSToomas Soome  */
26504b22b933Srs200217 
2651*5ffb0c9bSToomas Soome struct CompileTimeAssertionChecks_DNS_SD
26524b22b933Srs200217 {
26534b22b933Srs200217     char assert0[(sizeof(union _TXTRecordRef_t) == 16) ? 1 : -1];
26544b22b933Srs200217 };
26554b22b933Srs200217 
26564b22b933Srs200217 #ifdef  __cplusplus
26574b22b933Srs200217 }
26584b22b933Srs200217 #endif
26594b22b933Srs200217 
26604b22b933Srs200217 #endif  /* _DNS_SD_H */
2661