source: rtems-libbsd/mDNSResponder/mDNSShared/dns_sd.h @ 49ebc73

55-freebsd-126-freebsd-12
Last change on this file since 49ebc73 was 49ebc73, checked in by Sebastian Huber <sebastian.huber@…>, on 09/20/18 at 09:12:30

mDNSResponder: Update to v576.30.4

The sources can be obtained via:

https://opensource.apple.com/tarballs/mDNSResponder/mDNSResponder-576.30.4.tar.gz

Update #3522.

  • Property mode set to 100644
File size: 127.2 KB
Line 
1/* -*- Mode: C; tab-width: 4 -*-
2 *
3 * Copyright (c) 2003-2013 Apple Computer, Inc. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 *
8 * 1.  Redistributions of source code must retain the above copyright notice,
9 *     this list of conditions and the following disclaimer.
10 * 2.  Redistributions in binary form must reproduce the above copyright notice,
11 *     this list of conditions and the following disclaimer in the documentation
12 *     and/or other materials provided with the distribution.
13 * 3.  Neither the name of Apple Computer, Inc. ("Apple") nor the names of its
14 *     contributors may be used to endorse or promote products derived from this
15 *     software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
18 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
21 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29
30/*! @header     DNS Service Discovery
31 *
32 * @discussion  This section describes the functions, callbacks, and data structures
33 *              that make up the DNS Service Discovery API.
34 *
35 *              The DNS Service Discovery API is part of Bonjour, Apple's implementation
36 *              of zero-configuration networking (ZEROCONF).
37 *
38 *              Bonjour allows you to register a network service, such as a
39 *              printer or file server, so that it can be found by name or browsed
40 *              for by service type and domain. Using Bonjour, applications can
41 *              discover what services are available on the network, along with
42 *              all the information -- such as name, IP address, and port --
43 *              necessary to access a particular service.
44 *
45 *              In effect, Bonjour combines the functions of a local DNS server and
46 *              AppleTalk. Bonjour allows applications to provide user-friendly printer
47 *              and server browsing, among other things, over standard IP networks.
48 *              This behavior is a result of combining protocols such as multicast and
49 *              DNS to add new functionality to the network (such as multicast DNS).
50 *
51 *              Bonjour gives applications easy access to services over local IP
52 *              networks without requiring the service or the application to support
53 *              an AppleTalk or a Netbeui stack, and without requiring a DNS server
54 *              for the local network.
55 */
56
57/* _DNS_SD_H contains the API version number for this header file
58 * The API version defined in this header file symbol allows for compile-time
59 * checking, so that C code building with earlier versions of the header file
60 * can avoid compile errors trying to use functions that aren't even defined
61 * in those earlier versions. Similar checks may also be performed at run-time:
62 *  => weak linking -- to avoid link failures if run with an earlier
63 *     version of the library that's missing some desired symbol, or
64 *  => DNSServiceGetProperty(DaemonVersion) -- to verify whether the running daemon
65 *     ("system service" on Windows) meets some required minimum functionality level.
66 */
67
68#ifndef _DNS_SD_H
69#define _DNS_SD_H 5763004
70
71#ifdef  __cplusplus
72extern "C" {
73#endif
74
75/* Set to 1 if libdispatch is supported
76 * Note: May also be set by project and/or Makefile
77 */
78#ifndef _DNS_SD_LIBDISPATCH
79#define _DNS_SD_LIBDISPATCH 0
80#endif /* ndef _DNS_SD_LIBDISPATCH */
81
82/* standard calling convention under Win32 is __stdcall */
83/* Note: When compiling Intel EFI (Extensible Firmware Interface) under MS Visual Studio, the */
84/* _WIN32 symbol is defined by the compiler even though it's NOT compiling code for Windows32 */
85#if defined(_WIN32) && !defined(EFI32) && !defined(EFI64)
86#define DNSSD_API __stdcall
87#else
88#define DNSSD_API
89#endif
90
91/* stdint.h does not exist on FreeBSD 4.x; its types are defined in sys/types.h instead */
92#if defined(__FreeBSD__) && (__FreeBSD__ < 5)
93#include <sys/types.h>
94
95/* Likewise, on Sun, standard integer types are in sys/types.h */
96#elif defined(__sun__)
97#include <sys/types.h>
98
99/* EFI does not have stdint.h, or anything else equivalent */
100#elif defined(EFI32) || defined(EFI64) || defined(EFIX64)
101#include "Tiano.h"
102#if !defined(_STDINT_H_)
103typedef UINT8 uint8_t;
104typedef INT8 int8_t;
105typedef UINT16 uint16_t;
106typedef INT16 int16_t;
107typedef UINT32 uint32_t;
108typedef INT32 int32_t;
109#endif
110/* Windows has its own differences */
111#elif defined(_WIN32)
112#include <windows.h>
113#define _UNUSED
114#ifndef _MSL_STDINT_H
115typedef UINT8 uint8_t;
116typedef INT8 int8_t;
117typedef UINT16 uint16_t;
118typedef INT16 int16_t;
119typedef UINT32 uint32_t;
120typedef INT32 int32_t;
121#endif
122
123/* All other Posix platforms use stdint.h */
124#else
125#include <stdint.h>
126#endif
127
128#if _DNS_SD_LIBDISPATCH
129#include <dispatch/dispatch.h>
130#endif
131
132/* DNSServiceRef, DNSRecordRef
133 *
134 * Opaque internal data types.
135 * Note: client is responsible for serializing access to these structures if
136 * they are shared between concurrent threads.
137 */
138
139typedef struct _DNSServiceRef_t *DNSServiceRef;
140typedef struct _DNSRecordRef_t *DNSRecordRef;
141
142struct sockaddr;
143
144/*! @enum General flags
145 * Most DNS-SD API functions and callbacks include a DNSServiceFlags parameter.
146 * As a general rule, any given bit in the 32-bit flags field has a specific fixed meaning,
147 * regardless of the function or callback being used. For any given function or callback,
148 * typically only a subset of the possible flags are meaningful, and all others should be zero.
149 * The discussion section for each API call describes which flags are valid for that call
150 * and callback. In some cases, for a particular call, it may be that no flags are currently
151 * defined, in which case the DNSServiceFlags parameter exists purely to allow future expansion.
152 * In all cases, developers should expect that in future releases, it is possible that new flag
153 * values will be defined, and write code with this in mind. For example, code that tests
154 *     if (flags == kDNSServiceFlagsAdd) ...
155 * will fail if, in a future release, another bit in the 32-bit flags field is also set.
156 * The reliable way to test whether a particular bit is set is not with an equality test,
157 * but with a bitwise mask:
158 *     if (flags & kDNSServiceFlagsAdd) ...
159 * With the exception of kDNSServiceFlagsValidate, each flag can be valid(be set)
160 * EITHER only as an input to one of the DNSService*() APIs OR only as an output
161 * (provide status) through any of the callbacks used. For example, kDNSServiceFlagsAdd
162 * can be set only as an output in the callback, whereas the kDNSServiceFlagsIncludeP2P
163 * can be set only as an input to the DNSService*() APIs. See comments on kDNSServiceFlagsValidate 
164 * defined in enum below.
165 */
166enum
167{
168    kDNSServiceFlagsMoreComing          = 0x1,
169    /* MoreComing indicates to a callback that at least one more result is
170     * queued and will be delivered following immediately after this one.
171     * When the MoreComing flag is set, applications should not immediately
172     * update their UI, because this can result in a great deal of ugly flickering
173     * on the screen, and can waste a great deal of CPU time repeatedly updating
174     * the screen with content that is then immediately erased, over and over.
175     * Applications should wait until MoreComing is not set, and then
176     * update their UI when no more changes are imminent.
177     * When MoreComing is not set, that doesn't mean there will be no more
178     * answers EVER, just that there are no more answers immediately
179     * available right now at this instant. If more answers become available
180     * in the future they will be delivered as usual.
181     */
182
183    kDNSServiceFlagsAdd                 = 0x2,
184    kDNSServiceFlagsDefault             = 0x4,
185    /* Flags for domain enumeration and browse/query reply callbacks.
186     * "Default" applies only to enumeration and is only valid in
187     * conjunction with "Add". An enumeration callback with the "Add"
188     * flag NOT set indicates a "Remove", i.e. the domain is no longer
189     * valid.
190     */
191
192    kDNSServiceFlagsNoAutoRename        = 0x8,
193    /* Flag for specifying renaming behavior on name conflict when registering
194     * non-shared records. By default, name conflicts are automatically handled
195     * by renaming the service. NoAutoRename overrides this behavior - with this
196     * flag set, name conflicts will result in a callback. The NoAutorename flag
197     * is only valid if a name is explicitly specified when registering a service
198     * (i.e. the default name is not used.)
199     */
200
201    kDNSServiceFlagsShared              = 0x10,
202    kDNSServiceFlagsUnique              = 0x20,
203    /* Flag for registering individual records on a connected
204     * DNSServiceRef. Shared indicates that there may be multiple records
205     * with this name on the network (e.g. PTR records). Unique indicates that the
206     * record's name is to be unique on the network (e.g. SRV records).
207     */
208
209    kDNSServiceFlagsBrowseDomains       = 0x40,
210    kDNSServiceFlagsRegistrationDomains = 0x80,
211    /* Flags for specifying domain enumeration type in DNSServiceEnumerateDomains.
212     * BrowseDomains enumerates domains recommended for browsing, RegistrationDomains
213     * enumerates domains recommended for registration.
214     */
215
216    kDNSServiceFlagsLongLivedQuery      = 0x100,
217    /* Flag for creating a long-lived unicast query for the DNSServiceQueryRecord call. */
218
219    kDNSServiceFlagsAllowRemoteQuery    = 0x200,
220    /* Flag for creating a record for which we will answer remote queries
221     * (queries from hosts more than one hop away; hosts not directly connected to the local link).
222     */
223
224    kDNSServiceFlagsForceMulticast      = 0x400,
225    /* Flag for signifying that a query or registration should be performed exclusively via multicast
226     * DNS, even for a name in a domain (e.g. foo.apple.com.) that would normally imply unicast DNS.
227     */
228
229    kDNSServiceFlagsForce               = 0x800,    // This flag is deprecated.
230
231    kDNSServiceFlagsKnownUnique         = 0x800,
232    /*
233     * Client guarantees that record names are unique, so we can skip sending out initial
234     * probe messages.  Standard name conflict resolution is still done if a conflict is discovered.
235     * Currently only valid for a DNSServiceRegister call.
236     */
237
238    kDNSServiceFlagsReturnIntermediates = 0x1000,
239    /* Flag for returning intermediate results.
240     * For example, if a query results in an authoritative NXDomain (name does not exist)
241     * then that result is returned to the client. However the query is not implicitly
242     * cancelled -- it remains active and if the answer subsequently changes
243     * (e.g. because a VPN tunnel is subsequently established) then that positive
244     * result will still be returned to the client.
245     * Similarly, if a query results in a CNAME record, then in addition to following
246     * the CNAME referral, the intermediate CNAME result is also returned to the client.
247     * When this flag is not set, NXDomain errors are not returned, and CNAME records
248     * are followed silently without informing the client of the intermediate steps.
249     * (In earlier builds this flag was briefly calledkDNSServiceFlagsReturnCNAME)
250     */
251
252    kDNSServiceFlagsNonBrowsable        = 0x2000,
253    /* A service registered with the NonBrowsable flag set can be resolved using
254     * DNSServiceResolve(), but will not be discoverable using DNSServiceBrowse().
255     * This is for cases where the name is actually a GUID; it is found by other means;
256     * there is no end-user benefit to browsing to find a long list of opaque GUIDs.
257     * Using the NonBrowsable flag creates SRV+TXT without the cost of also advertising
258     * an associated PTR record.
259     */
260
261    kDNSServiceFlagsShareConnection     = 0x4000,
262    /* For efficiency, clients that perform many concurrent operations may want to use a
263     * single Unix Domain Socket connection with the background daemon, instead of having a
264     * separate connection for each independent operation. To use this mode, clients first
265     * call DNSServiceCreateConnection(&MainRef) to initialize the main DNSServiceRef.
266     * For each subsequent operation that is to share that same connection, the client copies
267     * the MainRef, and then passes the address of that copy, setting the ShareConnection flag
268     * to tell the library that this DNSServiceRef is not a typical uninitialized DNSServiceRef;
269     * it's a copy of an existing DNSServiceRef whose connection information should be reused.
270     *
271     * For example:
272     *
273     * DNSServiceErrorType error;
274     * DNSServiceRef MainRef;
275     * error = DNSServiceCreateConnection(&MainRef);
276     * if (error) ...
277     * DNSServiceRef BrowseRef = MainRef;  // Important: COPY the primary DNSServiceRef first...
278     * error = DNSServiceBrowse(&BrowseRef, kDNSServiceFlagsShareConnection, ...); // then use the copy
279     * if (error) ...
280     * ...
281     * DNSServiceRefDeallocate(BrowseRef); // Terminate the browse operation
282     * DNSServiceRefDeallocate(MainRef);   // Terminate the shared connection
283     * Also see Point 4.(Don't Double-Deallocate if the MainRef has been Deallocated) in Notes below:
284     *
285     * Notes:
286     *
287     * 1. Collective kDNSServiceFlagsMoreComing flag
288     * When callbacks are invoked using a shared DNSServiceRef, the
289     * kDNSServiceFlagsMoreComing flag applies collectively to *all* active
290     * operations sharing the same parent DNSServiceRef. If the MoreComing flag is
291     * set it means that there are more results queued on this parent DNSServiceRef,
292     * but not necessarily more results for this particular callback function.
293     * The implication of this for client programmers is that when a callback
294     * is invoked with the MoreComing flag set, the code should update its
295     * internal data structures with the new result, and set a variable indicating
296     * that its UI needs to be updated. Then, later when a callback is eventually
297     * invoked with the MoreComing flag not set, the code should update *all*
298     * stale UI elements related to that shared parent DNSServiceRef that need
299     * updating, not just the UI elements related to the particular callback
300     * that happened to be the last one to be invoked.
301     *
302     * 2. Canceling operations and kDNSServiceFlagsMoreComing
303     * Whenever you cancel any operation for which you had deferred UI updates
304     * waiting because of a kDNSServiceFlagsMoreComing flag, you should perform
305     * those deferred UI updates. This is because, after cancelling the operation,
306     * you can no longer wait for a callback *without* MoreComing set, to tell
307     * you do perform your deferred UI updates (the operation has been canceled,
308     * so there will be no more callbacks). An implication of the collective
309     * kDNSServiceFlagsMoreComing flag for shared connections is that this
310     * guideline applies more broadly -- any time you cancel an operation on
311     * a shared connection, you should perform all deferred UI updates for all
312     * operations sharing that connection. This is because the MoreComing flag
313     * might have been referring to events coming for the operation you canceled,
314     * which will now not be coming because the operation has been canceled.
315     *
316     * 3. Only share DNSServiceRef's created with DNSServiceCreateConnection
317     * Calling DNSServiceCreateConnection(&ref) creates a special shareable DNSServiceRef.
318     * DNSServiceRef's created by other calls like DNSServiceBrowse() or DNSServiceResolve()
319     * cannot be shared by copying them and using kDNSServiceFlagsShareConnection.
320     *
321     * 4. Don't Double-Deallocate if the MainRef has been Deallocated
322     * Calling DNSServiceRefDeallocate(ref) for a particular operation's DNSServiceRef terminates
323     * just that operation. Calling DNSServiceRefDeallocate(ref) for the main shared DNSServiceRef
324     * (the parent DNSServiceRef, originally created by DNSServiceCreateConnection(&ref))
325     * automatically terminates the shared connection and all operations that were still using it.
326     * After doing this, DO NOT then attempt to deallocate any remaining subordinate DNSServiceRef's.
327     * The memory used by those subordinate DNSServiceRef's has already been freed, so any attempt
328     * to do a DNSServiceRefDeallocate (or any other operation) on them will result in accesses
329     * to freed memory, leading to crashes or other equally undesirable results.
330     *
331     * 5. Thread Safety
332     * The dns_sd.h API does not presuppose any particular threading model, and consequently
333     * does no locking of its own (which would require linking some specific threading library).
334     * If client code calls API routines on the same DNSServiceRef concurrently
335     * from multiple threads, it is the client's responsibility to use a mutext
336     * lock or take similar appropriate precautions to serialize those calls.
337     */
338
339    kDNSServiceFlagsSuppressUnusable    = 0x8000,
340    /*
341     * This flag is meaningful only in DNSServiceQueryRecord which suppresses unusable queries on the
342     * wire. If "hostname" is a wide-area unicast DNS hostname (i.e. not a ".local." name)
343     * but this host has no routable IPv6 address, then the call will not try to look up IPv6 addresses
344     * for "hostname", since any addresses it found would be unlikely to be of any use anyway. Similarly,
345     * if this host has no routable IPv4 address, the call will not try to look up IPv4 addresses for
346     * "hostname".
347     */
348
349    kDNSServiceFlagsTimeout            = 0x10000,
350    /*
351     * When kDNServiceFlagsTimeout is passed to DNSServiceQueryRecord or DNSServiceGetAddrInfo, the query is
352     * stopped after a certain number of seconds have elapsed. The time at which the query will be stopped
353     * is determined by the system and cannot be configured by the user. The query will be stopped irrespective
354     * of whether a response was given earlier or not. When the query is stopped, the callback will be called
355     * with an error code of kDNSServiceErr_Timeout and a NULL sockaddr will be returned for DNSServiceGetAddrInfo
356     * and zero length rdata will be returned for DNSServiceQueryRecord.
357     */
358
359    kDNSServiceFlagsIncludeP2P          = 0x20000,
360    /*
361     * Include P2P interfaces when kDNSServiceInterfaceIndexAny is specified.
362     * By default, specifying kDNSServiceInterfaceIndexAny does not include P2P interfaces.
363     */
364
365    kDNSServiceFlagsWakeOnResolve      = 0x40000,
366    /*
367    * This flag is meaningful only in DNSServiceResolve. When set, it tries to send a magic packet
368    * to wake up the client.
369    */
370
371    kDNSServiceFlagsBackgroundTrafficClass  = 0x80000,
372    /*
373    * This flag is meaningful for Unicast DNS queries. When set, it uses the background traffic
374    * class for packets that service the request.
375    */
376
377    kDNSServiceFlagsIncludeAWDL      = 0x100000,
378   /*
379    * Include AWDL interface when kDNSServiceInterfaceIndexAny is specified.
380    */
381
382    kDNSServiceFlagsValidate               = 0x200000,
383   /*
384    * This flag is meaningful in DNSServiceGetAddrInfo and DNSServiceQueryRecord. This is the ONLY flag to be valid
385    * as an input to the APIs and also an output through the callbacks in the APIs.
386    *
387    * When this flag is passed to DNSServiceQueryRecord and DNSServiceGetAddrInfo to resolve unicast names,
388    * the response  will be validated using DNSSEC. The validation results are delivered using the flags field in
389    * the callback and kDNSServiceFlagsValidate is marked in the flags to indicate that DNSSEC status is also available.
390    * When the callback is called to deliver the query results, the validation results may or may not be available.
391    * If it is not delivered along with the results, the validation status is delivered when the validation completes.
392    *
393    * When the validation results are delivered in the callback, it is indicated by marking the flags with
394    * kDNSServiceFlagsValidate and kDNSServiceFlagsAdd along with the DNSSEC status flags (described below) and a NULL
395    * sockaddr will be returned for DNSServiceGetAddrInfo and zero length rdata will be returned for DNSServiceQueryRecord.
396    * DNSSEC validation results are for the whole RRSet and not just individual records delivered in the callback. When
397    * kDNSServiceFlagsAdd is not set in the flags, applications should implicitly assume that the DNSSEC status of the
398    * RRSet that has been delivered up until that point is not valid anymore, till another callback is called with
399    * kDNSServiceFlagsAdd and kDNSServiceFlagsValidate.
400    *
401    * The following four flags indicate the status of the DNSSEC validation and marked in the flags field of the callback.
402    * When any of the four flags is set, kDNSServiceFlagsValidate will also be set. To check the validation status, the
403    * other applicable output flags should be masked. See kDNSServiceOutputFlags below.
404    */
405
406    kDNSServiceFlagsSecure                 = 0x200010,
407   /*
408    * The response has been validated by verifying all the signaures in the response and was able to
409    * build a successful authentication chain starting from a known trust anchor.   
410    */
411
412    kDNSServiceFlagsInsecure               = 0x200020,
413   /*
414    * A chain of trust cannot be built starting from a known trust anchor to the response.
415    */
416
417    kDNSServiceFlagsBogus                  = 0x200040,
418   /*
419    * If the response cannot be verified to be secure due to expired signatures, missing signatures etc.,
420    * then the results are considered to be bogus.
421    */
422
423    kDNSServiceFlagsIndeterminate          = 0x200080,
424   /*
425    * There is no valid trust anchor that can be used to determine whether a response is secure or not.
426    */
427
428    kDNSServiceFlagsUnicastResponse        = 0x400000,
429   /*
430    * Request unicast response to query.
431    */
432    kDNSServiceFlagsValidateOptional       = 0x800000,
433
434    /*
435     * This flag is identical to kDNSServiceFlagsValidate except for the case where the response
436     * cannot be validated. If this flag is set in DNSServiceQueryRecord or DNSServiceGetAddrInfo,
437     * the DNSSEC records will be requested for validation. If they cannot be received for some reason
438     * during the validation (e.g., zone is not signed, zone is signed but cannot be traced back to
439     * root, recursive server does not understand DNSSEC etc.), then this will fallback to the default
440     * behavior where the validation will not be performed and no DNSSEC results will be provided.
441     *
442     * If the zone is signed and there is a valid path to a known trust anchor configured in the system
443     * and the application requires DNSSEC validation irrespective of the DNSSEC awareness in the current
444     * network, then this option MUST not be used. This is only intended to be used during the transition
445     * period where the different nodes participating in the DNS resolution may not understand DNSSEC or
446     * managed properly (e.g. missing DS record) but still want to be able to resolve DNS successfully.
447     */
448
449    kDNSServiceFlagsWakeOnlyService        = 0x1000000,
450    /*
451     * This flag is meaningful only in DNSServiceRegister. When set, the service will not be registered
452     * with sleep proxy server during sleep.
453     */
454
455    kDNSServiceFlagsThresholdOne           = 0x2000000,
456    kDNSServiceFlagsThresholdFinder        = 0x4000000,
457    kDNSServiceFlagsThresholdReached       = kDNSServiceFlagsThresholdOne,
458    /*
459     * kDNSServiceFlagsThresholdOne is meaningful only in DNSServiceBrowse. When set,
460     * the system will stop issuing browse queries on the network once the number
461     * of answers returned is one or more.  It will issue queries on the network
462     * again if the number of answers drops to zero.
463     * This flag is for Apple internal use only. Third party developers
464     * should not rely on this behavior being supported in any given software release.
465     *
466     * kDNSServiceFlagsThresholdFinder is meaningful only in DNSServiceBrowse. When set,
467     * the system will stop issuing browse queries on the network once the number
468     * of answers has reached the threshold set for Finder.
469     * It will issue queries on the network again if the number of answers drops below
470     * this threshold.
471     * This flag is for Apple internal use only. Third party developers
472     * should not rely on this behavior being supported in any given software release.
473     *
474     * When kDNSServiceFlagsThresholdReached is set in the client callback add or remove event,
475     * it indicates that the browse answer threshold has been reached and no
476     * browse requests will be generated on the network until the number of answers falls
477     * below the threshold value.  Add and remove events can still occur based
478     * on incoming Bonjour traffic observed by the system.
479     * The set of services return to the client is not guaranteed to represent the
480     * entire set of services present on the network once the threshold has been reached.
481     *
482     * Note, while kDNSServiceFlagsThresholdReached and kDNSServiceFlagsThresholdOne
483     * have the same value, there  isn't a conflict because kDNSServiceFlagsThresholdReached
484     * is only set in the callbacks and kDNSServiceFlagsThresholdOne is only set on
485     * input to a DNSServiceBrowse call.
486     */
487     kDNSServiceFlagsDenyCellular           = 0x8000000,
488    /*
489     * This flag is meaningful only for Unicast DNS queries. When set, the kernel will restrict
490     * DNS resolutions on the cellular interface for that request.
491     */
492
493     kDNSServiceFlagsServiceIndex           = 0x10000000,
494    /*
495     * This flag is meaningful only for DNSServiceGetAddrInfo() for Unicast DNS queries.
496     * When set, DNSServiceGetAddrInfo() will interpret the "interfaceIndex" argument of the call
497     * as the "serviceIndex".
498     */
499
500     kDNSServiceFlagsDenyExpensive          = 0x20000000
501    /*
502     * This flag is meaningful only for Unicast DNS queries. When set, the kernel will restrict
503     * DNS resolutions on interfaces defined as expensive for that request.
504     */
505
506};
507
508#define kDNSServiceOutputFlags (kDNSServiceFlagsValidate | kDNSServiceFlagsValidateOptional | kDNSServiceFlagsMoreComing | kDNSServiceFlagsAdd | kDNSServiceFlagsDefault)
509   /* All the output flags excluding the DNSSEC Status flags. Typically used to check DNSSEC Status */
510
511/* Possible protocol values */
512enum
513{
514    /* for DNSServiceGetAddrInfo() */
515    kDNSServiceProtocol_IPv4 = 0x01,
516    kDNSServiceProtocol_IPv6 = 0x02,
517    /* 0x04 and 0x08 reserved for future internetwork protocols */
518
519    /* for DNSServiceNATPortMappingCreate() */
520    kDNSServiceProtocol_UDP  = 0x10,
521    kDNSServiceProtocol_TCP  = 0x20
522                               /* 0x40 and 0x80 reserved for future transport protocols, e.g. SCTP [RFC 2960]
523                                * or DCCP [RFC 4340]. If future NAT gateways are created that support port
524                                * mappings for these protocols, new constants will be defined here.
525                                */
526};
527
528/*
529 * The values for DNS Classes and Types are listed in RFC 1035, and are available
530 * on every OS in its DNS header file. Unfortunately every OS does not have the
531 * same header file containing DNS Class and Type constants, and the names of
532 * the constants are not consistent. For example, BIND 8 uses "T_A",
533 * BIND 9 uses "ns_t_a", Windows uses "DNS_TYPE_A", etc.
534 * For this reason, these constants are also listed here, so that code using
535 * the DNS-SD programming APIs can use these constants, so that the same code
536 * can compile on all our supported platforms.
537 */
538
539enum
540{
541    kDNSServiceClass_IN       = 1       /* Internet */
542};
543
544enum
545{
546    kDNSServiceType_A          = 1,      /* Host address. */
547    kDNSServiceType_NS         = 2,      /* Authoritative server. */
548    kDNSServiceType_MD         = 3,      /* Mail destination. */
549    kDNSServiceType_MF         = 4,      /* Mail forwarder. */
550    kDNSServiceType_CNAME      = 5,      /* Canonical name. */
551    kDNSServiceType_SOA        = 6,      /* Start of authority zone. */
552    kDNSServiceType_MB         = 7,      /* Mailbox domain name. */
553    kDNSServiceType_MG         = 8,      /* Mail group member. */
554    kDNSServiceType_MR         = 9,      /* Mail rename name. */
555    kDNSServiceType_NULL       = 10,     /* Null resource record. */
556    kDNSServiceType_WKS        = 11,     /* Well known service. */
557    kDNSServiceType_PTR        = 12,     /* Domain name pointer. */
558    kDNSServiceType_HINFO      = 13,     /* Host information. */
559    kDNSServiceType_MINFO      = 14,     /* Mailbox information. */
560    kDNSServiceType_MX         = 15,     /* Mail routing information. */
561    kDNSServiceType_TXT        = 16,     /* One or more text strings (NOT "zero or more..."). */
562    kDNSServiceType_RP         = 17,     /* Responsible person. */
563    kDNSServiceType_AFSDB      = 18,     /* AFS cell database. */
564    kDNSServiceType_X25        = 19,     /* X_25 calling address. */
565    kDNSServiceType_ISDN       = 20,     /* ISDN calling address. */
566    kDNSServiceType_RT         = 21,     /* Router. */
567    kDNSServiceType_NSAP       = 22,     /* NSAP address. */
568    kDNSServiceType_NSAP_PTR   = 23,     /* Reverse NSAP lookup (deprecated). */
569    kDNSServiceType_SIG        = 24,     /* Security signature. */
570    kDNSServiceType_KEY        = 25,     /* Security key. */
571    kDNSServiceType_PX         = 26,     /* X.400 mail mapping. */
572    kDNSServiceType_GPOS       = 27,     /* Geographical position (withdrawn). */
573    kDNSServiceType_AAAA       = 28,     /* IPv6 Address. */
574    kDNSServiceType_LOC        = 29,     /* Location Information. */
575    kDNSServiceType_NXT        = 30,     /* Next domain (security). */
576    kDNSServiceType_EID        = 31,     /* Endpoint identifier. */
577    kDNSServiceType_NIMLOC     = 32,     /* Nimrod Locator. */
578    kDNSServiceType_SRV        = 33,     /* Server Selection. */
579    kDNSServiceType_ATMA       = 34,     /* ATM Address */
580    kDNSServiceType_NAPTR      = 35,     /* Naming Authority PoinTeR */
581    kDNSServiceType_KX         = 36,     /* Key Exchange */
582    kDNSServiceType_CERT       = 37,     /* Certification record */
583    kDNSServiceType_A6         = 38,     /* IPv6 Address (deprecated) */
584    kDNSServiceType_DNAME      = 39,     /* Non-terminal DNAME (for IPv6) */
585    kDNSServiceType_SINK       = 40,     /* Kitchen sink (experimental) */
586    kDNSServiceType_OPT        = 41,     /* EDNS0 option (meta-RR) */
587    kDNSServiceType_APL        = 42,     /* Address Prefix List */
588    kDNSServiceType_DS         = 43,     /* Delegation Signer */
589    kDNSServiceType_SSHFP      = 44,     /* SSH Key Fingerprint */
590    kDNSServiceType_IPSECKEY   = 45,     /* IPSECKEY */
591    kDNSServiceType_RRSIG      = 46,     /* RRSIG */
592    kDNSServiceType_NSEC       = 47,     /* Denial of Existence */
593    kDNSServiceType_DNSKEY     = 48,     /* DNSKEY */
594    kDNSServiceType_DHCID      = 49,     /* DHCP Client Identifier */
595    kDNSServiceType_NSEC3      = 50,     /* Hashed Authenticated Denial of Existence */
596    kDNSServiceType_NSEC3PARAM = 51,     /* Hashed Authenticated Denial of Existence */
597
598    kDNSServiceType_HIP        = 55,     /* Host Identity Protocol */
599
600    kDNSServiceType_SPF        = 99,     /* Sender Policy Framework for E-Mail */
601    kDNSServiceType_UINFO      = 100,    /* IANA-Reserved */
602    kDNSServiceType_UID        = 101,    /* IANA-Reserved */
603    kDNSServiceType_GID        = 102,    /* IANA-Reserved */
604    kDNSServiceType_UNSPEC     = 103,    /* IANA-Reserved */
605
606    kDNSServiceType_TKEY       = 249,    /* Transaction key */
607    kDNSServiceType_TSIG       = 250,    /* Transaction signature. */
608    kDNSServiceType_IXFR       = 251,    /* Incremental zone transfer. */
609    kDNSServiceType_AXFR       = 252,    /* Transfer zone of authority. */
610    kDNSServiceType_MAILB      = 253,    /* Transfer mailbox records. */
611    kDNSServiceType_MAILA      = 254,    /* Transfer mail agent records. */
612    kDNSServiceType_ANY        = 255     /* Wildcard match. */
613};
614
615/* possible error code values */
616enum
617{
618    kDNSServiceErr_NoError                   = 0,
619    kDNSServiceErr_Unknown                   = -65537,  /* 0xFFFE FFFF */
620    kDNSServiceErr_NoSuchName                = -65538,
621    kDNSServiceErr_NoMemory                  = -65539,
622    kDNSServiceErr_BadParam                  = -65540,
623    kDNSServiceErr_BadReference              = -65541,
624    kDNSServiceErr_BadState                  = -65542,
625    kDNSServiceErr_BadFlags                  = -65543,
626    kDNSServiceErr_Unsupported               = -65544,
627    kDNSServiceErr_NotInitialized            = -65545,
628    kDNSServiceErr_AlreadyRegistered         = -65547,
629    kDNSServiceErr_NameConflict              = -65548,
630    kDNSServiceErr_Invalid                   = -65549,
631    kDNSServiceErr_Firewall                  = -65550,
632    kDNSServiceErr_Incompatible              = -65551,  /* client library incompatible with daemon */
633    kDNSServiceErr_BadInterfaceIndex         = -65552,
634    kDNSServiceErr_Refused                   = -65553,
635    kDNSServiceErr_NoSuchRecord              = -65554,
636    kDNSServiceErr_NoAuth                    = -65555,
637    kDNSServiceErr_NoSuchKey                 = -65556,
638    kDNSServiceErr_NATTraversal              = -65557,
639    kDNSServiceErr_DoubleNAT                 = -65558,
640    kDNSServiceErr_BadTime                   = -65559,  /* Codes up to here existed in Tiger */
641    kDNSServiceErr_BadSig                    = -65560,
642    kDNSServiceErr_BadKey                    = -65561,
643    kDNSServiceErr_Transient                 = -65562,
644    kDNSServiceErr_ServiceNotRunning         = -65563,  /* Background daemon not running */
645    kDNSServiceErr_NATPortMappingUnsupported = -65564,  /* NAT doesn't support PCP, NAT-PMP or UPnP */
646    kDNSServiceErr_NATPortMappingDisabled    = -65565,  /* NAT supports PCP, NAT-PMP or UPnP, but it's disabled by the administrator */
647    kDNSServiceErr_NoRouter                  = -65566,  /* No router currently configured (probably no network connectivity) */
648    kDNSServiceErr_PollingMode               = -65567,
649    kDNSServiceErr_Timeout                   = -65568
650
651                                               /* mDNS Error codes are in the range
652                                                * FFFE FF00 (-65792) to FFFE FFFF (-65537) */
653};
654
655/* Maximum length, in bytes, of a service name represented as a */
656/* literal C-String, including the terminating NULL at the end. */
657
658#define kDNSServiceMaxServiceName 64
659
660/* Maximum length, in bytes, of a domain name represented as an *escaped* C-String */
661/* including the final trailing dot, and the C-String terminating NULL at the end. */
662
663#define kDNSServiceMaxDomainName 1009
664
665/*
666 * Notes on DNS Name Escaping
667 *   -- or --
668 * "Why is kDNSServiceMaxDomainName 1009, when the maximum legal domain name is 256 bytes?"
669 *
670 * All strings used in the DNS-SD APIs are UTF-8 strings. Apart from the exceptions noted below,
671 * the APIs expect the strings to be properly escaped, using the conventional DNS escaping rules:
672 *
673 *   '\\' represents a single literal '\' in the name
674 *   '\.' represents a single literal '.' in the name
675 *   '\ddd', where ddd is a three-digit decimal value from 000 to 255,
676 *        represents a single literal byte with that value.
677 *   A bare unescaped '.' is a label separator, marking a boundary between domain and subdomain.
678 *
679 * The exceptions, that do not use escaping, are the routines where the full
680 * DNS name of a resource is broken, for convenience, into servicename/regtype/domain.
681 * In these routines, the "servicename" is NOT escaped. It does not need to be, since
682 * it is, by definition, just a single literal string. Any characters in that string
683 * represent exactly what they are. The "regtype" portion is, technically speaking,
684 * escaped, but since legal regtypes are only allowed to contain letters, digits,
685 * and hyphens, there is nothing to escape, so the issue is moot. The "domain"
686 * portion is also escaped, though most domains in use on the public Internet
687 * today, like regtypes, don't contain any characters that need to be escaped.
688 * As DNS-SD becomes more popular, rich-text domains for service discovery will
689 * become common, so software should be written to cope with domains with escaping.
690 *
691 * The servicename may be up to 63 bytes of UTF-8 text (not counting the C-String
692 * terminating NULL at the end). The regtype is of the form _service._tcp or
693 * _service._udp, where the "service" part is 1-15 characters, which may be
694 * letters, digits, or hyphens. The domain part of the three-part name may be
695 * any legal domain, providing that the resulting servicename+regtype+domain
696 * name does not exceed 256 bytes.
697 *
698 * For most software, these issues are transparent. When browsing, the discovered
699 * servicenames should simply be displayed as-is. When resolving, the discovered
700 * servicename/regtype/domain are simply passed unchanged to DNSServiceResolve().
701 * When a DNSServiceResolve() succeeds, the returned fullname is already in
702 * the correct format to pass to standard system DNS APIs such as res_query().
703 * For converting from servicename/regtype/domain to a single properly-escaped
704 * full DNS name, the helper function DNSServiceConstructFullName() is provided.
705 *
706 * The following (highly contrived) example illustrates the escaping process.
707 * Suppose you have an service called "Dr. Smith\Dr. Johnson", of type "_ftp._tcp"
708 * in subdomain "4th. Floor" of subdomain "Building 2" of domain "apple.com."
709 * The full (escaped) DNS name of this service's SRV record would be:
710 * Dr\.\032Smith\\Dr\.\032Johnson._ftp._tcp.4th\.\032Floor.Building\0322.apple.com.
711 */
712
713
714/*
715 * Constants for specifying an interface index
716 *
717 * Specific interface indexes are identified via a 32-bit unsigned integer returned
718 * by the if_nametoindex() family of calls.
719 *
720 * If the client passes 0 for interface index, that means "do the right thing",
721 * which (at present) means, "if the name is in an mDNS local multicast domain
722 * (e.g. 'local.', '254.169.in-addr.arpa.', '{8,9,A,B}.E.F.ip6.arpa.') then multicast
723 * on all applicable interfaces, otherwise send via unicast to the appropriate
724 * DNS server." Normally, most clients will use 0 for interface index to
725 * automatically get the default sensible behaviour.
726 *
727 * If the client passes a positive interface index, then for multicast names that
728 * indicates to do the operation only on that one interface. For unicast names the
729 * interface index is ignored unless kDNSServiceFlagsForceMulticast is also set.
730 *
731 * If the client passes kDNSServiceInterfaceIndexLocalOnly when registering
732 * a service, then that service will be found *only* by other local clients
733 * on the same machine that are browsing using kDNSServiceInterfaceIndexLocalOnly
734 * or kDNSServiceInterfaceIndexAny.
735 * If a client has a 'private' service, accessible only to other processes
736 * running on the same machine, this allows the client to advertise that service
737 * in a way such that it does not inadvertently appear in service lists on
738 * all the other machines on the network.
739 *
740 * If the client passes kDNSServiceInterfaceIndexLocalOnly when browsing
741 * then it will find *all* records registered on that same local machine.
742 * Clients explicitly wishing to discover *only* LocalOnly services can
743 * accomplish this by inspecting the interfaceIndex of each service reported
744 * to their DNSServiceBrowseReply() callback function, and discarding those
745 * where the interface index is not kDNSServiceInterfaceIndexLocalOnly.
746 *
747 * kDNSServiceInterfaceIndexP2P is meaningful only in Browse, QueryRecord, Register,
748 * and Resolve operations. It should not be used in other DNSService APIs.
749 *
750 * - If kDNSServiceInterfaceIndexP2P is passed to DNSServiceBrowse or
751 *   DNSServiceQueryRecord, it restricts the operation to P2P.
752 *
753 * - If kDNSServiceInterfaceIndexP2P is passed to DNSServiceRegister, it is
754 *   mapped internally to kDNSServiceInterfaceIndexAny with the kDNSServiceFlagsIncludeP2P
755 *   set.
756 *
757 * - If kDNSServiceInterfaceIndexP2P is passed to DNSServiceResolve, it is
758 *   mapped internally to kDNSServiceInterfaceIndexAny with the kDNSServiceFlagsIncludeP2P
759 *   set, because resolving a P2P service may create and/or enable an interface whose
760 *   index is not known a priori. The resolve callback will indicate the index of the
761 *   interface via which the service can be accessed.
762 *
763 * If applications pass kDNSServiceInterfaceIndexAny to DNSServiceBrowse
764 * or DNSServiceQueryRecord, they must set the kDNSServiceFlagsIncludeP2P flag
765 * to include P2P. In this case, if a service instance or the record being queried
766 * is found over P2P, the resulting ADD event will indicate kDNSServiceInterfaceIndexP2P
767 * as the interface index.
768 */
769
770#define kDNSServiceInterfaceIndexAny 0
771#define kDNSServiceInterfaceIndexLocalOnly ((uint32_t)-1)
772#define kDNSServiceInterfaceIndexUnicast   ((uint32_t)-2)
773#define kDNSServiceInterfaceIndexP2P       ((uint32_t)-3)
774
775typedef uint32_t DNSServiceFlags;
776typedef uint32_t DNSServiceProtocol;
777typedef int32_t DNSServiceErrorType;
778
779
780/*********************************************************************************************
781*
782* Version checking
783*
784*********************************************************************************************/
785
786/* DNSServiceGetProperty() Parameters:
787 *
788 * property:        The requested property.
789 *                  Currently the only property defined is kDNSServiceProperty_DaemonVersion.
790 *
791 * result:          Place to store result.
792 *                  For retrieving DaemonVersion, this should be the address of a uint32_t.
793 *
794 * size:            Pointer to uint32_t containing size of the result location.
795 *                  For retrieving DaemonVersion, this should be sizeof(uint32_t).
796 *                  On return the uint32_t is updated to the size of the data returned.
797 *                  For DaemonVersion, the returned size is always sizeof(uint32_t), but
798 *                  future properties could be defined which return variable-sized results.
799 *
800 * return value:    Returns kDNSServiceErr_NoError on success, or kDNSServiceErr_ServiceNotRunning
801 *                  if the daemon (or "system service" on Windows) is not running.
802 */
803
804DNSServiceErrorType DNSSD_API DNSServiceGetProperty
805(
806    const char *property,  /* Requested property (i.e. kDNSServiceProperty_DaemonVersion) */
807    void       *result,    /* Pointer to place to store result */
808    uint32_t   *size       /* size of result location */
809);
810
811/*
812 * When requesting kDNSServiceProperty_DaemonVersion, the result pointer must point
813 * to a 32-bit unsigned integer, and the size parameter must be set to sizeof(uint32_t).
814 *
815 * On return, the 32-bit unsigned integer contains the API version number
816 *
817 * For example, Mac OS X 10.4.9 has API version 1080400.
818 * This allows applications to do simple greater-than and less-than comparisons:
819 * e.g. an application that requires at least API version 1080400 can check:
820 *   if (version >= 1080400) ...
821 *
822 * Example usage:
823 * uint32_t version;
824 * uint32_t size = sizeof(version);
825 * DNSServiceErrorType err = DNSServiceGetProperty(kDNSServiceProperty_DaemonVersion, &version, &size);
826 * if (!err) printf("DNS_SD API version is %d.%d\n", version / 10000, version / 100 % 100);
827 */
828
829#define kDNSServiceProperty_DaemonVersion "DaemonVersion"
830
831
832// Map the source port of the local UDP socket that was opened for sending the DNS query
833// to the process ID of the application that triggered the DNS resolution.
834//
835/* DNSServiceGetPID() Parameters:
836 *
837 * srcport:         Source port (in network byte order) of the UDP socket that was created by
838 *                  the daemon to send the DNS query on the wire.
839 *
840 * pid:             Process ID of the application that started the name resolution which triggered
841 *                  the daemon to send the query on the wire. The value can be -1 if the srcport
842 *                  cannot be mapped.
843 *
844 * return value:    Returns kDNSServiceErr_NoError on success, or kDNSServiceErr_ServiceNotRunning
845 *                  if the daemon is not running. The value of the pid is undefined if the return
846 *                  value has error.
847 */
848DNSServiceErrorType DNSSD_API DNSServiceGetPID
849(
850    uint16_t srcport,
851    int32_t *pid
852);
853
854/*********************************************************************************************
855*
856* Unix Domain Socket access, DNSServiceRef deallocation, and data processing functions
857*
858*********************************************************************************************/
859
860/* DNSServiceRefSockFD()
861 *
862 * Access underlying Unix domain socket for an initialized DNSServiceRef.
863 * The DNS Service Discovery implementation uses this socket to communicate between the client and
864 * the daemon. The application MUST NOT directly read from or write to this socket.
865 * Access to the socket is provided so that it can be used as a kqueue event source, a CFRunLoop
866 * event source, in a select() loop, etc. When the underlying event management subsystem (kqueue/
867 * select/CFRunLoop etc.) indicates to the client that data is available for reading on the
868 * socket, the client should call DNSServiceProcessResult(), which will extract the daemon's
869 * reply from the socket, and pass it to the appropriate application callback. By using a run
870 * loop or select(), results from the daemon can be processed asynchronously. Alternatively,
871 * a client can choose to fork a thread and have it loop calling "DNSServiceProcessResult(ref);"
872 * If DNSServiceProcessResult() is called when no data is available for reading on the socket, it
873 * will block until data does become available, and then process the data and return to the caller.
874 * The application is reponsible for checking the return value of DNSServiceProcessResult() to determine
875 * if the socket is valid and if it should continue to process data on the socket.
876 * When data arrives on the socket, the client is responsible for calling DNSServiceProcessResult(ref)
877 * in a timely fashion -- if the client allows a large backlog of data to build up the daemon
878 * may terminate the connection.
879 *
880 * sdRef:           A DNSServiceRef initialized by any of the DNSService calls.
881 *
882 * return value:    The DNSServiceRef's underlying socket descriptor, or -1 on
883 *                  error.
884 */
885
886int DNSSD_API DNSServiceRefSockFD(DNSServiceRef sdRef);
887
888
889/* DNSServiceProcessResult()
890 *
891 * Read a reply from the daemon, calling the appropriate application callback. This call will
892 * block until the daemon's response is received. Use DNSServiceRefSockFD() in
893 * conjunction with a run loop or select() to determine the presence of a response from the
894 * server before calling this function to process the reply without blocking. Call this function
895 * at any point if it is acceptable to block until the daemon's response arrives. Note that the
896 * client is responsible for ensuring that DNSServiceProcessResult() is called whenever there is
897 * a reply from the daemon - the daemon may terminate its connection with a client that does not
898 * process the daemon's responses.
899 *
900 * sdRef:           A DNSServiceRef initialized by any of the DNSService calls
901 *                  that take a callback parameter.
902 *
903 * return value:    Returns kDNSServiceErr_NoError on success, otherwise returns
904 *                  an error code indicating the specific failure that occurred.
905 */
906
907DNSServiceErrorType DNSSD_API DNSServiceProcessResult(DNSServiceRef sdRef);
908
909
910/* DNSServiceRefDeallocate()
911 *
912 * Terminate a connection with the daemon and free memory associated with the DNSServiceRef.
913 * Any services or records registered with this DNSServiceRef will be deregistered. Any
914 * Browse, Resolve, or Query operations called with this reference will be terminated.
915 *
916 * Note: If the reference's underlying socket is used in a run loop or select() call, it should
917 * be removed BEFORE DNSServiceRefDeallocate() is called, as this function closes the reference's
918 * socket.
919 *
920 * Note: If the reference was initialized with DNSServiceCreateConnection(), any DNSRecordRefs
921 * created via this reference will be invalidated by this call - the resource records are
922 * deregistered, and their DNSRecordRefs may not be used in subsequent functions. Similarly,
923 * if the reference was initialized with DNSServiceRegister, and an extra resource record was
924 * added to the service via DNSServiceAddRecord(), the DNSRecordRef created by the Add() call
925 * is invalidated when this function is called - the DNSRecordRef may not be used in subsequent
926 * functions.
927 *
928 * Note: This call is to be used only with the DNSServiceRef defined by this API.
929 *
930 * sdRef:           A DNSServiceRef initialized by any of the DNSService calls.
931 *
932 */
933
934void DNSSD_API DNSServiceRefDeallocate(DNSServiceRef sdRef);
935
936
937/*********************************************************************************************
938*
939* Domain Enumeration
940*
941*********************************************************************************************/
942
943/* DNSServiceEnumerateDomains()
944 *
945 * Asynchronously enumerate domains available for browsing and registration.
946 *
947 * The enumeration MUST be cancelled via DNSServiceRefDeallocate() when no more domains
948 * are to be found.
949 *
950 * Note that the names returned are (like all of DNS-SD) UTF-8 strings,
951 * and are escaped using standard DNS escaping rules.
952 * (See "Notes on DNS Name Escaping" earlier in this file for more details.)
953 * A graphical browser displaying a hierarchical tree-structured view should cut
954 * the names at the bare dots to yield individual labels, then de-escape each
955 * label according to the escaping rules, and then display the resulting UTF-8 text.
956 *
957 * DNSServiceDomainEnumReply Callback Parameters:
958 *
959 * sdRef:           The DNSServiceRef initialized by DNSServiceEnumerateDomains().
960 *
961 * flags:           Possible values are:
962 *                  kDNSServiceFlagsMoreComing
963 *                  kDNSServiceFlagsAdd
964 *                  kDNSServiceFlagsDefault
965 *
966 * interfaceIndex:  Specifies the interface on which the domain exists. (The index for a given
967 *                  interface is determined via the if_nametoindex() family of calls.)
968 *
969 * errorCode:       Will be kDNSServiceErr_NoError (0) on success, otherwise indicates
970 *                  the failure that occurred (other parameters are undefined if errorCode is nonzero).
971 *
972 * replyDomain:     The name of the domain.
973 *
974 * context:         The context pointer passed to DNSServiceEnumerateDomains.
975 *
976 */
977
978typedef void (DNSSD_API *DNSServiceDomainEnumReply)
979(
980    DNSServiceRef sdRef,
981    DNSServiceFlags flags,
982    uint32_t interfaceIndex,
983    DNSServiceErrorType errorCode,
984    const char                          *replyDomain,
985    void                                *context
986);
987
988
989/* DNSServiceEnumerateDomains() Parameters:
990 *
991 * sdRef:           A pointer to an uninitialized DNSServiceRef. If the call succeeds
992 *                  then it initializes the DNSServiceRef, returns kDNSServiceErr_NoError,
993 *                  and the enumeration operation will run indefinitely until the client
994 *                  terminates it by passing this DNSServiceRef to DNSServiceRefDeallocate().
995 *
996 * flags:           Possible values are:
997 *                  kDNSServiceFlagsBrowseDomains to enumerate domains recommended for browsing.
998 *                  kDNSServiceFlagsRegistrationDomains to enumerate domains recommended
999 *                  for registration.
1000 *
1001 * interfaceIndex:  If non-zero, specifies the interface on which to look for domains.
1002 *                  (the index for a given interface is determined via the if_nametoindex()
1003 *                  family of calls.) Most applications will pass 0 to enumerate domains on
1004 *                  all interfaces. See "Constants for specifying an interface index" for more details.
1005 *
1006 * callBack:        The function to be called when a domain is found or the call asynchronously
1007 *                  fails.
1008 *
1009 * context:         An application context pointer which is passed to the callback function
1010 *                  (may be NULL).
1011 *
1012 * return value:    Returns kDNSServiceErr_NoError on success (any subsequent, asynchronous
1013 *                  errors are delivered to the callback), otherwise returns an error code indicating
1014 *                  the error that occurred (the callback is not invoked and the DNSServiceRef
1015 *                  is not initialized).
1016 */
1017
1018DNSServiceErrorType DNSSD_API DNSServiceEnumerateDomains
1019(
1020    DNSServiceRef                       *sdRef,
1021    DNSServiceFlags flags,
1022    uint32_t interfaceIndex,
1023    DNSServiceDomainEnumReply callBack,
1024    void                                *context  /* may be NULL */
1025);
1026
1027
1028/*********************************************************************************************
1029*
1030*  Service Registration
1031*
1032*********************************************************************************************/
1033
1034/* Register a service that is discovered via Browse() and Resolve() calls.
1035 *
1036 * DNSServiceRegisterReply() Callback Parameters:
1037 *
1038 * sdRef:           The DNSServiceRef initialized by DNSServiceRegister().
1039 *
1040 * flags:           When a name is successfully registered, the callback will be
1041 *                  invoked with the kDNSServiceFlagsAdd flag set. When Wide-Area
1042 *                  DNS-SD is in use, it is possible for a single service to get
1043 *                  more than one success callback (e.g. one in the "local" multicast
1044 *                  DNS domain, and another in a wide-area unicast DNS domain).
1045 *                  If a successfully-registered name later suffers a name conflict
1046 *                  or similar problem and has to be deregistered, the callback will
1047 *                  be invoked with the kDNSServiceFlagsAdd flag not set. The callback
1048 *                  is *not* invoked in the case where the caller explicitly terminates
1049 *                  the service registration by calling DNSServiceRefDeallocate(ref);
1050 *
1051 * errorCode:       Will be kDNSServiceErr_NoError on success, otherwise will
1052 *                  indicate the failure that occurred (including name conflicts,
1053 *                  if the kDNSServiceFlagsNoAutoRename flag was used when registering.)
1054 *                  Other parameters are undefined if errorCode is nonzero.
1055 *
1056 * name:            The service name registered (if the application did not specify a name in
1057 *                  DNSServiceRegister(), this indicates what name was automatically chosen).
1058 *
1059 * regtype:         The type of service registered, as it was passed to the callout.
1060 *
1061 * domain:          The domain on which the service was registered (if the application did not
1062 *                  specify a domain in DNSServiceRegister(), this indicates the default domain
1063 *                  on which the service was registered).
1064 *
1065 * context:         The context pointer that was passed to the callout.
1066 *
1067 */
1068
1069typedef void (DNSSD_API *DNSServiceRegisterReply)
1070(
1071    DNSServiceRef sdRef,
1072    DNSServiceFlags flags,
1073    DNSServiceErrorType errorCode,
1074    const char                          *name,
1075    const char                          *regtype,
1076    const char                          *domain,
1077    void                                *context
1078);
1079
1080
1081/* DNSServiceRegister() Parameters:
1082 *
1083 * sdRef:           A pointer to an uninitialized DNSServiceRef. If the call succeeds
1084 *                  then it initializes the DNSServiceRef, returns kDNSServiceErr_NoError,
1085 *                  and the registration will remain active indefinitely until the client
1086 *                  terminates it by passing this DNSServiceRef to DNSServiceRefDeallocate().
1087 *
1088 * interfaceIndex:  If non-zero, specifies the interface on which to register the service
1089 *                  (the index for a given interface is determined via the if_nametoindex()
1090 *                  family of calls.) Most applications will pass 0 to register on all
1091 *                  available interfaces. See "Constants for specifying an interface index" for more details.
1092 *
1093 * flags:           Indicates the renaming behavior on name conflict (most applications
1094 *                  will pass 0). See flag definitions above for details.
1095 *
1096 * name:            If non-NULL, specifies the service name to be registered.
1097 *                  Most applications will not specify a name, in which case the computer
1098 *                  name is used (this name is communicated to the client via the callback).
1099 *                  If a name is specified, it must be 1-63 bytes of UTF-8 text.
1100 *                  If the name is longer than 63 bytes it will be automatically truncated
1101 *                  to a legal length, unless the NoAutoRename flag is set,
1102 *                  in which case kDNSServiceErr_BadParam will be returned.
1103 *
1104 * regtype:         The service type followed by the protocol, separated by a dot
1105 *                  (e.g. "_ftp._tcp"). The service type must be an underscore, followed
1106 *                  by 1-15 characters, which may be letters, digits, or hyphens.
1107 *                  The transport protocol must be "_tcp" or "_udp". New service types
1108 *                  should be registered at <http://www.dns-sd.org/ServiceTypes.html>.
1109 *
1110 *                  Additional subtypes of the primary service type (where a service
1111 *                  type has defined subtypes) follow the primary service type in a
1112 *                  comma-separated list, with no additional spaces, e.g.
1113 *                      "_primarytype._tcp,_subtype1,_subtype2,_subtype3"
1114 *                  Subtypes provide a mechanism for filtered browsing: A client browsing
1115 *                  for "_primarytype._tcp" will discover all instances of this type;
1116 *                  a client browsing for "_primarytype._tcp,_subtype2" will discover only
1117 *                  those instances that were registered with "_subtype2" in their list of
1118 *                  registered subtypes.
1119 *
1120 *                  The subtype mechanism can be illustrated with some examples using the
1121 *                  dns-sd command-line tool:
1122 *
1123 *                  % dns-sd -R Simple _test._tcp "" 1001 &
1124 *                  % dns-sd -R Better _test._tcp,HasFeatureA "" 1002 &
1125 *                  % dns-sd -R Best   _test._tcp,HasFeatureA,HasFeatureB "" 1003 &
1126 *
1127 *                  Now:
1128 *                  % dns-sd -B _test._tcp             # will find all three services
1129 *                  % dns-sd -B _test._tcp,HasFeatureA # finds "Better" and "Best"
1130 *                  % dns-sd -B _test._tcp,HasFeatureB # finds only "Best"
1131 *
1132 *                  Subtype labels may be up to 63 bytes long, and may contain any eight-
1133 *                  bit byte values, including zero bytes. However, due to the nature of
1134 *                  using a C-string-based API, conventional DNS escaping must be used for
1135 *                  dots ('.'), commas (','), backslashes ('\') and zero bytes, as shown below:
1136 *
1137 *                  % dns-sd -R Test '_test._tcp,s\.one,s\,two,s\\three,s\000four' local 123
1138 *
1139 *                  When a service is registered, all the clients browsing for the registered
1140 *                  type ("regtype") will discover it. If the discovery should be
1141 *                  restricted to a smaller set of well known peers, the service can be
1142 *                  registered with additional data (group identifier) that is known
1143 *                  only to a smaller set of peers. The group identifier should follow primary
1144 *                  service type using a colon (":") as a delimeter. If subtypes are also present,
1145 *                  it should be given before the subtype as shown below.
1146 *
1147 *                  % dns-sd -R _test1 _http._tcp:mygroup1 local 1001
1148 *                  % dns-sd -R _test2 _http._tcp:mygroup2 local 1001
1149 *                  % dns-sd -R _test3 _http._tcp:mygroup3,HasFeatureA local 1001
1150 *
1151 *                  Now:
1152 *                  % dns-sd -B _http._tcp:"mygroup1"                # will discover only test1
1153 *                  % dns-sd -B _http._tcp:"mygroup2"                # will discover only test2
1154 *                  % dns-sd -B _http._tcp:"mygroup3",HasFeatureA    # will discover only test3
1155 *                 
1156 *                  By specifying the group information, only the members of that group are
1157 *                  discovered.
1158 *
1159 *                  The group identifier itself is not sent in clear. Only a hash of the group
1160 *                  identifier is sent and the clients discover them anonymously. The group identifier
1161 *                  may be up to 256 bytes long and may contain any eight bit values except comma which
1162 *                  should be escaped.
1163 *
1164 * domain:          If non-NULL, specifies the domain on which to advertise the service.
1165 *                  Most applications will not specify a domain, instead automatically
1166 *                  registering in the default domain(s).
1167 *
1168 * host:            If non-NULL, specifies the SRV target host name. Most applications
1169 *                  will not specify a host, instead automatically using the machine's
1170 *                  default host name(s). Note that specifying a non-NULL host does NOT
1171 *                  create an address record for that host - the application is responsible
1172 *                  for ensuring that the appropriate address record exists, or creating it
1173 *                  via DNSServiceRegisterRecord().
1174 *
1175 * port:            The port, in network byte order, on which the service accepts connections.
1176 *                  Pass 0 for a "placeholder" service (i.e. a service that will not be discovered
1177 *                  by browsing, but will cause a name conflict if another client tries to
1178 *                  register that same name). Most clients will not use placeholder services.
1179 *
1180 * txtLen:          The length of the txtRecord, in bytes. Must be zero if the txtRecord is NULL.
1181 *
1182 * txtRecord:       The TXT record rdata. A non-NULL txtRecord MUST be a properly formatted DNS
1183 *                  TXT record, i.e. <length byte> <data> <length byte> <data> ...
1184 *                  Passing NULL for the txtRecord is allowed as a synonym for txtLen=1, txtRecord="",
1185 *                  i.e. it creates a TXT record of length one containing a single empty string.
1186 *                  RFC 1035 doesn't allow a TXT record to contain *zero* strings, so a single empty
1187 *                  string is the smallest legal DNS TXT record.
1188 *                  As with the other parameters, the DNSServiceRegister call copies the txtRecord
1189 *                  data; e.g. if you allocated the storage for the txtRecord parameter with malloc()
1190 *                  then you can safely free that memory right after the DNSServiceRegister call returns.
1191 *
1192 * callBack:        The function to be called when the registration completes or asynchronously
1193 *                  fails. The client MAY pass NULL for the callback -  The client will NOT be notified
1194 *                  of the default values picked on its behalf, and the client will NOT be notified of any
1195 *                  asynchronous errors (e.g. out of memory errors, etc.) that may prevent the registration
1196 *                  of the service. The client may NOT pass the NoAutoRename flag if the callback is NULL.
1197 *                  The client may still deregister the service at any time via DNSServiceRefDeallocate().
1198 *
1199 * context:         An application context pointer which is passed to the callback function
1200 *                  (may be NULL).
1201 *
1202 * return value:    Returns kDNSServiceErr_NoError on success (any subsequent, asynchronous
1203 *                  errors are delivered to the callback), otherwise returns an error code indicating
1204 *                  the error that occurred (the callback is never invoked and the DNSServiceRef
1205 *                  is not initialized).
1206 */
1207
1208DNSServiceErrorType DNSSD_API DNSServiceRegister
1209(
1210    DNSServiceRef                       *sdRef,
1211    DNSServiceFlags flags,
1212    uint32_t interfaceIndex,
1213    const char                          *name,         /* may be NULL */
1214    const char                          *regtype,
1215    const char                          *domain,       /* may be NULL */
1216    const char                          *host,         /* may be NULL */
1217    uint16_t port,                                     /* In network byte order */
1218    uint16_t txtLen,
1219    const void                          *txtRecord,    /* may be NULL */
1220    DNSServiceRegisterReply callBack,                  /* may be NULL */
1221    void                                *context       /* may be NULL */
1222);
1223
1224
1225/* DNSServiceAddRecord()
1226 *
1227 * Add a record to a registered service. The name of the record will be the same as the
1228 * registered service's name.
1229 * The record can later be updated or deregistered by passing the RecordRef initialized
1230 * by this function to DNSServiceUpdateRecord() or DNSServiceRemoveRecord().
1231 *
1232 * Note that the DNSServiceAddRecord/UpdateRecord/RemoveRecord are *NOT* thread-safe
1233 * with respect to a single DNSServiceRef. If you plan to have multiple threads
1234 * in your program simultaneously add, update, or remove records from the same
1235 * DNSServiceRef, then it's the caller's responsibility to use a mutext lock
1236 * or take similar appropriate precautions to serialize those calls.
1237 *
1238 * Parameters;
1239 *
1240 * sdRef:           A DNSServiceRef initialized by DNSServiceRegister().
1241 *
1242 * RecordRef:       A pointer to an uninitialized DNSRecordRef. Upon succesfull completion of this
1243 *                  call, this ref may be passed to DNSServiceUpdateRecord() or DNSServiceRemoveRecord().
1244 *                  If the above DNSServiceRef is passed to DNSServiceRefDeallocate(), RecordRef is also
1245 *                  invalidated and may not be used further.
1246 *
1247 * flags:           Currently ignored, reserved for future use.
1248 *
1249 * rrtype:          The type of the record (e.g. kDNSServiceType_TXT, kDNSServiceType_SRV, etc)
1250 *
1251 * rdlen:           The length, in bytes, of the rdata.
1252 *
1253 * rdata:           The raw rdata to be contained in the added resource record.
1254 *
1255 * ttl:             The time to live of the resource record, in seconds.
1256 *                  Most clients should pass 0 to indicate that the system should
1257 *                  select a sensible default value.
1258 *
1259 * return value:    Returns kDNSServiceErr_NoError on success, otherwise returns an
1260 *                  error code indicating the error that occurred (the RecordRef is not initialized).
1261 */
1262
1263DNSServiceErrorType DNSSD_API DNSServiceAddRecord
1264(
1265    DNSServiceRef sdRef,
1266    DNSRecordRef                        *RecordRef,
1267    DNSServiceFlags flags,
1268    uint16_t rrtype,
1269    uint16_t rdlen,
1270    const void                          *rdata,
1271    uint32_t ttl
1272);
1273
1274
1275/* DNSServiceUpdateRecord
1276 *
1277 * Update a registered resource record. The record must either be:
1278 *   - The primary txt record of a service registered via DNSServiceRegister()
1279 *   - A record added to a registered service via DNSServiceAddRecord()
1280 *   - An individual record registered by DNSServiceRegisterRecord()
1281 *
1282 * Parameters:
1283 *
1284 * sdRef:           A DNSServiceRef that was initialized by DNSServiceRegister()
1285 *                  or DNSServiceCreateConnection().
1286 *
1287 * RecordRef:       A DNSRecordRef initialized by DNSServiceAddRecord, or NULL to update the
1288 *                  service's primary txt record.
1289 *
1290 * flags:           Currently ignored, reserved for future use.
1291 *
1292 * rdlen:           The length, in bytes, of the new rdata.
1293 *
1294 * rdata:           The new rdata to be contained in the updated resource record.
1295 *
1296 * ttl:             The time to live of the updated resource record, in seconds.
1297 *                  Most clients should pass 0 to indicate that the system should
1298 *                  select a sensible default value.
1299 *
1300 * return value:    Returns kDNSServiceErr_NoError on success, otherwise returns an
1301 *                  error code indicating the error that occurred.
1302 */
1303
1304DNSServiceErrorType DNSSD_API DNSServiceUpdateRecord
1305(
1306    DNSServiceRef sdRef,
1307    DNSRecordRef RecordRef,                            /* may be NULL */
1308    DNSServiceFlags flags,
1309    uint16_t rdlen,
1310    const void                          *rdata,
1311    uint32_t ttl
1312);
1313
1314
1315/* DNSServiceRemoveRecord
1316 *
1317 * Remove a record previously added to a service record set via DNSServiceAddRecord(), or deregister
1318 * an record registered individually via DNSServiceRegisterRecord().
1319 *
1320 * Parameters:
1321 *
1322 * sdRef:           A DNSServiceRef initialized by DNSServiceRegister() (if the
1323 *                  record being removed was registered via DNSServiceAddRecord()) or by
1324 *                  DNSServiceCreateConnection() (if the record being removed was registered via
1325 *                  DNSServiceRegisterRecord()).
1326 *
1327 * recordRef:       A DNSRecordRef initialized by a successful call to DNSServiceAddRecord()
1328 *                  or DNSServiceRegisterRecord().
1329 *
1330 * flags:           Currently ignored, reserved for future use.
1331 *
1332 * return value:    Returns kDNSServiceErr_NoError on success, otherwise returns an
1333 *                  error code indicating the error that occurred.
1334 */
1335
1336DNSServiceErrorType DNSSD_API DNSServiceRemoveRecord
1337(
1338    DNSServiceRef sdRef,
1339    DNSRecordRef RecordRef,
1340    DNSServiceFlags flags
1341);
1342
1343
1344/*********************************************************************************************
1345*
1346*  Service Discovery
1347*
1348*********************************************************************************************/
1349
1350/* Browse for instances of a service.
1351 *
1352 * DNSServiceBrowseReply() Parameters:
1353 *
1354 * sdRef:           The DNSServiceRef initialized by DNSServiceBrowse().
1355 *
1356 * flags:           Possible values are kDNSServiceFlagsMoreComing and kDNSServiceFlagsAdd.
1357 *                  See flag definitions for details.
1358 *
1359 * interfaceIndex:  The interface on which the service is advertised. This index should
1360 *                  be passed to DNSServiceResolve() when resolving the service.
1361 *
1362 * errorCode:       Will be kDNSServiceErr_NoError (0) on success, otherwise will
1363 *                  indicate the failure that occurred. Other parameters are undefined if
1364 *                  the errorCode is nonzero.
1365 *
1366 * serviceName:     The discovered service name. This name should be displayed to the user,
1367 *                  and stored for subsequent use in the DNSServiceResolve() call.
1368 *
1369 * regtype:         The service type, which is usually (but not always) the same as was passed
1370 *                  to DNSServiceBrowse(). One case where the discovered service type may
1371 *                  not be the same as the requested service type is when using subtypes:
1372 *                  The client may want to browse for only those ftp servers that allow
1373 *                  anonymous connections. The client will pass the string "_ftp._tcp,_anon"
1374 *                  to DNSServiceBrowse(), but the type of the service that's discovered
1375 *                  is simply "_ftp._tcp". The regtype for each discovered service instance
1376 *                  should be stored along with the name, so that it can be passed to
1377 *                  DNSServiceResolve() when the service is later resolved.
1378 *
1379 * domain:          The domain of the discovered service instance. This may or may not be the
1380 *                  same as the domain that was passed to DNSServiceBrowse(). The domain for each
1381 *                  discovered service instance should be stored along with the name, so that
1382 *                  it can be passed to DNSServiceResolve() when the service is later resolved.
1383 *
1384 * context:         The context pointer that was passed to the callout.
1385 *
1386 */
1387
1388typedef void (DNSSD_API *DNSServiceBrowseReply)
1389(
1390    DNSServiceRef sdRef,
1391    DNSServiceFlags flags,
1392    uint32_t interfaceIndex,
1393    DNSServiceErrorType errorCode,
1394    const char                          *serviceName,
1395    const char                          *regtype,
1396    const char                          *replyDomain,
1397    void                                *context
1398);
1399
1400
1401/* DNSServiceBrowse() Parameters:
1402 *
1403 * sdRef:           A pointer to an uninitialized DNSServiceRef. If the call succeeds
1404 *                  then it initializes the DNSServiceRef, returns kDNSServiceErr_NoError,
1405 *                  and the browse operation will run indefinitely until the client
1406 *                  terminates it by passing this DNSServiceRef to DNSServiceRefDeallocate().
1407 *
1408 * flags:           Currently ignored, reserved for future use.
1409 *
1410 * interfaceIndex:  If non-zero, specifies the interface on which to browse for services
1411 *                  (the index for a given interface is determined via the if_nametoindex()
1412 *                  family of calls.) Most applications will pass 0 to browse on all available
1413 *                  interfaces. See "Constants for specifying an interface index" for more details.
1414 *
1415 * regtype:         The service type being browsed for followed by the protocol, separated by a
1416 *                  dot (e.g. "_ftp._tcp"). The transport protocol must be "_tcp" or "_udp".
1417 *                  A client may optionally specify a single subtype to perform filtered browsing:
1418 *                  e.g. browsing for "_primarytype._tcp,_subtype" will discover only those
1419 *                  instances of "_primarytype._tcp" that were registered specifying "_subtype"
1420 *                  in their list of registered subtypes. Additionally, a group identifier may
1421 *                  also be specified before the subtype e.g., _primarytype._tcp:GroupID, which
1422 *                  will discover only the members that register the service with GroupID. See
1423 *                  DNSServiceRegister for more details.
1424 *
1425 * domain:          If non-NULL, specifies the domain on which to browse for services.
1426 *                  Most applications will not specify a domain, instead browsing on the
1427 *                  default domain(s).
1428 *
1429 * callBack:        The function to be called when an instance of the service being browsed for
1430 *                  is found, or if the call asynchronously fails.
1431 *
1432 * context:         An application context pointer which is passed to the callback function
1433 *                  (may be NULL).
1434 *
1435 * return value:    Returns kDNSServiceErr_NoError on success (any subsequent, asynchronous
1436 *                  errors are delivered to the callback), otherwise returns an error code indicating
1437 *                  the error that occurred (the callback is not invoked and the DNSServiceRef
1438 *                  is not initialized).
1439 */
1440
1441DNSServiceErrorType DNSSD_API DNSServiceBrowse
1442(
1443    DNSServiceRef                       *sdRef,
1444    DNSServiceFlags flags,
1445    uint32_t interfaceIndex,
1446    const char                          *regtype,
1447    const char                          *domain,    /* may be NULL */
1448    DNSServiceBrowseReply callBack,
1449    void                                *context    /* may be NULL */
1450);
1451
1452
1453/* DNSServiceResolve()
1454 *
1455 * Resolve a service name discovered via DNSServiceBrowse() to a target host name, port number, and
1456 * txt record.
1457 *
1458 * Note: Applications should NOT use DNSServiceResolve() solely for txt record monitoring - use
1459 * DNSServiceQueryRecord() instead, as it is more efficient for this task.
1460 *
1461 * Note: When the desired results have been returned, the client MUST terminate the resolve by calling
1462 * DNSServiceRefDeallocate().
1463 *
1464 * Note: DNSServiceResolve() behaves correctly for typical services that have a single SRV record
1465 * and a single TXT record. To resolve non-standard services with multiple SRV or TXT records,
1466 * DNSServiceQueryRecord() should be used.
1467 *
1468 * DNSServiceResolveReply Callback Parameters:
1469 *
1470 * sdRef:           The DNSServiceRef initialized by DNSServiceResolve().
1471 *
1472 * flags:           Possible values: kDNSServiceFlagsMoreComing
1473 *
1474 * interfaceIndex:  The interface on which the service was resolved.
1475 *
1476 * errorCode:       Will be kDNSServiceErr_NoError (0) on success, otherwise will
1477 *                  indicate the failure that occurred. Other parameters are undefined if
1478 *                  the errorCode is nonzero.
1479 *
1480 * fullname:        The full service domain name, in the form <servicename>.<protocol>.<domain>.
1481 *                  (This name is escaped following standard DNS rules, making it suitable for
1482 *                  passing to standard system DNS APIs such as res_query(), or to the
1483 *                  special-purpose functions included in this API that take fullname parameters.
1484 *                  See "Notes on DNS Name Escaping" earlier in this file for more details.)
1485 *
1486 * hosttarget:      The target hostname of the machine providing the service. This name can
1487 *                  be passed to functions like gethostbyname() to identify the host's IP address.
1488 *
1489 * port:            The port, in network byte order, on which connections are accepted for this service.
1490 *
1491 * txtLen:          The length of the txt record, in bytes.
1492 *
1493 * txtRecord:       The service's primary txt record, in standard txt record format.
1494 *
1495 * context:         The context pointer that was passed to the callout.
1496 *
1497 * NOTE: In earlier versions of this header file, the txtRecord parameter was declared "const char *"
1498 * This is incorrect, since it contains length bytes which are values in the range 0 to 255, not -128 to +127.
1499 * Depending on your compiler settings, this change may cause signed/unsigned mismatch warnings.
1500 * These should be fixed by updating your own callback function definition to match the corrected
1501 * function signature using "const unsigned char *txtRecord". Making this change may also fix inadvertent
1502 * bugs in your callback function, where it could have incorrectly interpreted a length byte with value 250
1503 * as being -6 instead, with various bad consequences ranging from incorrect operation to software crashes.
1504 * If you need to maintain portable code that will compile cleanly with both the old and new versions of
1505 * this header file, you should update your callback function definition to use the correct unsigned value,
1506 * and then in the place where you pass your callback function to DNSServiceResolve(), use a cast to eliminate
1507 * the compiler warning, e.g.:
1508 *   DNSServiceResolve(sd, flags, index, name, regtype, domain, (DNSServiceResolveReply)MyCallback, context);
1509 * This will ensure that your code compiles cleanly without warnings (and more importantly, works correctly)
1510 * with both the old header and with the new corrected version.
1511 *
1512 */
1513
1514typedef void (DNSSD_API *DNSServiceResolveReply)
1515(
1516    DNSServiceRef sdRef,
1517    DNSServiceFlags flags,
1518    uint32_t interfaceIndex,
1519    DNSServiceErrorType errorCode,
1520    const char                          *fullname,
1521    const char                          *hosttarget,
1522    uint16_t port,                                   /* In network byte order */
1523    uint16_t txtLen,
1524    const unsigned char                 *txtRecord,
1525    void                                *context
1526);
1527
1528
1529/* DNSServiceResolve() Parameters
1530 *
1531 * sdRef:           A pointer to an uninitialized DNSServiceRef. If the call succeeds
1532 *                  then it initializes the DNSServiceRef, returns kDNSServiceErr_NoError,
1533 *                  and the resolve operation will run indefinitely until the client
1534 *                  terminates it by passing this DNSServiceRef to DNSServiceRefDeallocate().
1535 *
1536 * flags:           Specifying kDNSServiceFlagsForceMulticast will cause query to be
1537 *                  performed with a link-local mDNS query, even if the name is an
1538 *                  apparently non-local name (i.e. a name not ending in ".local.")
1539 *
1540 * interfaceIndex:  The interface on which to resolve the service. If this resolve call is
1541 *                  as a result of a currently active DNSServiceBrowse() operation, then the
1542 *                  interfaceIndex should be the index reported in the DNSServiceBrowseReply
1543 *                  callback. If this resolve call is using information previously saved
1544 *                  (e.g. in a preference file) for later use, then use interfaceIndex 0, because
1545 *                  the desired service may now be reachable via a different physical interface.
1546 *                  See "Constants for specifying an interface index" for more details.
1547 *
1548 * name:            The name of the service instance to be resolved, as reported to the
1549 *                  DNSServiceBrowseReply() callback.
1550 *
1551 * regtype:         The type of the service instance to be resolved, as reported to the
1552 *                  DNSServiceBrowseReply() callback.
1553 *
1554 * domain:          The domain of the service instance to be resolved, as reported to the
1555 *                  DNSServiceBrowseReply() callback.
1556 *
1557 * callBack:        The function to be called when a result is found, or if the call
1558 *                  asynchronously fails.
1559 *
1560 * context:         An application context pointer which is passed to the callback function
1561 *                  (may be NULL).
1562 *
1563 * return value:    Returns kDNSServiceErr_NoError on success (any subsequent, asynchronous
1564 *                  errors are delivered to the callback), otherwise returns an error code indicating
1565 *                  the error that occurred (the callback is never invoked and the DNSServiceRef
1566 *                  is not initialized).
1567 */
1568
1569DNSServiceErrorType DNSSD_API DNSServiceResolve
1570(
1571    DNSServiceRef                       *sdRef,
1572    DNSServiceFlags flags,
1573    uint32_t interfaceIndex,
1574    const char                          *name,
1575    const char                          *regtype,
1576    const char                          *domain,
1577    DNSServiceResolveReply callBack,
1578    void                                *context  /* may be NULL */
1579);
1580
1581
1582/*********************************************************************************************
1583*
1584*  Querying Individual Specific Records
1585*
1586*********************************************************************************************/
1587
1588/* DNSServiceQueryRecord
1589 *
1590 * Query for an arbitrary DNS record.
1591 *
1592 * DNSServiceQueryRecordReply() Callback Parameters:
1593 *
1594 * sdRef:           The DNSServiceRef initialized by DNSServiceQueryRecord().
1595 *
1596 * flags:           Possible values are kDNSServiceFlagsMoreComing and
1597 *                  kDNSServiceFlagsAdd. The Add flag is NOT set for PTR records
1598 *                  with a ttl of 0, i.e. "Remove" events.
1599 *
1600 * interfaceIndex:  The interface on which the query was resolved (the index for a given
1601 *                  interface is determined via the if_nametoindex() family of calls).
1602 *                  See "Constants for specifying an interface index" for more details.
1603 *
1604 * errorCode:       Will be kDNSServiceErr_NoError on success, otherwise will
1605 *                  indicate the failure that occurred. Other parameters are undefined if
1606 *                  errorCode is nonzero.
1607 *
1608 * fullname:        The resource record's full domain name.
1609 *
1610 * rrtype:          The resource record's type (e.g. kDNSServiceType_PTR, kDNSServiceType_SRV, etc)
1611 *
1612 * rrclass:         The class of the resource record (usually kDNSServiceClass_IN).
1613 *
1614 * rdlen:           The length, in bytes, of the resource record rdata.
1615 *
1616 * rdata:           The raw rdata of the resource record.
1617 *
1618 * ttl:             If the client wishes to cache the result for performance reasons,
1619 *                  the TTL indicates how long the client may legitimately hold onto
1620 *                  this result, in seconds. After the TTL expires, the client should
1621 *                  consider the result no longer valid, and if it requires this data
1622 *                  again, it should be re-fetched with a new query. Of course, this
1623 *                  only applies to clients that cancel the asynchronous operation when
1624 *                  they get a result. Clients that leave the asynchronous operation
1625 *                  running can safely assume that the data remains valid until they
1626 *                  get another callback telling them otherwise.
1627 *
1628 * context:         The context pointer that was passed to the callout.
1629 *
1630 */
1631
1632typedef void (DNSSD_API *DNSServiceQueryRecordReply)
1633(
1634    DNSServiceRef sdRef,
1635    DNSServiceFlags flags,
1636    uint32_t interfaceIndex,
1637    DNSServiceErrorType errorCode,
1638    const char                          *fullname,
1639    uint16_t rrtype,
1640    uint16_t rrclass,
1641    uint16_t rdlen,
1642    const void                          *rdata,
1643    uint32_t ttl,
1644    void                                *context
1645);
1646
1647
1648/* DNSServiceQueryRecord() Parameters:
1649 *
1650 * sdRef:           A pointer to an uninitialized DNSServiceRef. If the call succeeds
1651 *                  then it initializes the DNSServiceRef, returns kDNSServiceErr_NoError,
1652 *                  and the query operation will run indefinitely until the client
1653 *                  terminates it by passing this DNSServiceRef to DNSServiceRefDeallocate().
1654 *
1655 * flags:           kDNSServiceFlagsForceMulticast or kDNSServiceFlagsLongLivedQuery.
1656 *                  Pass kDNSServiceFlagsLongLivedQuery to create a "long-lived" unicast
1657 *                  query to a unicast DNS server that implements the protocol. This flag
1658 *                  has no effect on link-local multicast queries.
1659 *
1660 * interfaceIndex:  If non-zero, specifies the interface on which to issue the query
1661 *                  (the index for a given interface is determined via the if_nametoindex()
1662 *                  family of calls.) Passing 0 causes the name to be queried for on all
1663 *                  interfaces. See "Constants for specifying an interface index" for more details.
1664 *
1665 * fullname:        The full domain name of the resource record to be queried for.
1666 *
1667 * rrtype:          The numerical type of the resource record to be queried for
1668 *                  (e.g. kDNSServiceType_PTR, kDNSServiceType_SRV, etc)
1669 *
1670 * rrclass:         The class of the resource record (usually kDNSServiceClass_IN).
1671 *
1672 * callBack:        The function to be called when a result is found, or if the call
1673 *                  asynchronously fails.
1674 *
1675 * context:         An application context pointer which is passed to the callback function
1676 *                  (may be NULL).
1677 *
1678 * return value:    Returns kDNSServiceErr_NoError on success (any subsequent, asynchronous
1679 *                  errors are delivered to the callback), otherwise returns an error code indicating
1680 *                  the error that occurred (the callback is never invoked and the DNSServiceRef
1681 *                  is not initialized).
1682 */
1683
1684DNSServiceErrorType DNSSD_API DNSServiceQueryRecord
1685(
1686    DNSServiceRef                       *sdRef,
1687    DNSServiceFlags flags,
1688    uint32_t interfaceIndex,
1689    const char                          *fullname,
1690    uint16_t rrtype,
1691    uint16_t rrclass,
1692    DNSServiceQueryRecordReply callBack,
1693    void                                *context  /* may be NULL */
1694);
1695
1696
1697/*********************************************************************************************
1698*
1699*  Unified lookup of both IPv4 and IPv6 addresses for a fully qualified hostname
1700*
1701*********************************************************************************************/
1702
1703/* DNSServiceGetAddrInfo
1704 *
1705 * Queries for the IP address of a hostname by using either Multicast or Unicast DNS.
1706 *
1707 * DNSServiceGetAddrInfoReply() parameters:
1708 *
1709 * sdRef:           The DNSServiceRef initialized by DNSServiceGetAddrInfo().
1710 *
1711 * flags:           Possible values are kDNSServiceFlagsMoreComing and
1712 *                  kDNSServiceFlagsAdd.
1713 *
1714 * interfaceIndex:  The interface to which the answers pertain.
1715 *
1716 * errorCode:       Will be kDNSServiceErr_NoError on success, otherwise will
1717 *                  indicate the failure that occurred.  Other parameters are
1718 *                  undefined if errorCode is nonzero.
1719 *
1720 * hostname:        The fully qualified domain name of the host to be queried for.
1721 *
1722 * address:         IPv4 or IPv6 address.
1723 *
1724 * ttl:             If the client wishes to cache the result for performance reasons,
1725 *                  the TTL indicates how long the client may legitimately hold onto
1726 *                  this result, in seconds. After the TTL expires, the client should
1727 *                  consider the result no longer valid, and if it requires this data
1728 *                  again, it should be re-fetched with a new query. Of course, this
1729 *                  only applies to clients that cancel the asynchronous operation when
1730 *                  they get a result. Clients that leave the asynchronous operation
1731 *                  running can safely assume that the data remains valid until they
1732 *                  get another callback telling them otherwise.
1733 *
1734 * context:         The context pointer that was passed to the callout.
1735 *
1736 */
1737
1738typedef void (DNSSD_API *DNSServiceGetAddrInfoReply)
1739(
1740    DNSServiceRef sdRef,
1741    DNSServiceFlags flags,
1742    uint32_t interfaceIndex,
1743    DNSServiceErrorType errorCode,
1744    const char                       *hostname,
1745    const struct sockaddr            *address,
1746    uint32_t ttl,
1747    void                             *context
1748);
1749
1750
1751/* DNSServiceGetAddrInfo() Parameters:
1752 *
1753 * sdRef:           A pointer to an uninitialized DNSServiceRef. If the call succeeds then it
1754 *                  initializes the DNSServiceRef, returns kDNSServiceErr_NoError, and the query
1755 *                  begins and will last indefinitely until the client terminates the query
1756 *                  by passing this DNSServiceRef to DNSServiceRefDeallocate().
1757 *
1758 * flags:           kDNSServiceFlagsForceMulticast
1759 *
1760 * interfaceIndex:  The interface on which to issue the query.  Passing 0 causes the query to be
1761 *                  sent on all active interfaces via Multicast or the primary interface via Unicast.
1762 *
1763 * protocol:        Pass in kDNSServiceProtocol_IPv4 to look up IPv4 addresses, or kDNSServiceProtocol_IPv6
1764 *                  to look up IPv6 addresses, or both to look up both kinds. If neither flag is
1765 *                  set, the system will apply an intelligent heuristic, which is (currently)
1766 *                  that it will attempt to look up both, except:
1767 *
1768 *                   * If "hostname" is a wide-area unicast DNS hostname (i.e. not a ".local." name)
1769 *                     but this host has no routable IPv6 address, then the call will not try to
1770 *                     look up IPv6 addresses for "hostname", since any addresses it found would be
1771 *                     unlikely to be of any use anyway. Similarly, if this host has no routable
1772 *                     IPv4 address, the call will not try to look up IPv4 addresses for "hostname".
1773 *
1774 * hostname:        The fully qualified domain name of the host to be queried for.
1775 *
1776 * callBack:        The function to be called when the query succeeds or fails asynchronously.
1777 *
1778 * context:         An application context pointer which is passed to the callback function
1779 *                  (may be NULL).
1780 *
1781 * return value:    Returns kDNSServiceErr_NoError on success (any subsequent, asynchronous
1782 *                  errors are delivered to the callback), otherwise returns an error code indicating
1783 *                  the error that occurred.
1784 */
1785
1786DNSServiceErrorType DNSSD_API DNSServiceGetAddrInfo
1787(
1788    DNSServiceRef                    *sdRef,
1789    DNSServiceFlags flags,
1790    uint32_t interfaceIndex,
1791    DNSServiceProtocol protocol,
1792    const char                       *hostname,
1793    DNSServiceGetAddrInfoReply callBack,
1794    void                             *context          /* may be NULL */
1795);
1796
1797
1798/*********************************************************************************************
1799*
1800*  Special Purpose Calls:
1801*  DNSServiceCreateConnection(), DNSServiceRegisterRecord(), DNSServiceReconfirmRecord()
1802*  (most applications will not use these)
1803*
1804*********************************************************************************************/
1805
1806/* DNSServiceCreateConnection()
1807 *
1808 * Create a connection to the daemon allowing efficient registration of
1809 * multiple individual records.
1810 *
1811 * Parameters:
1812 *
1813 * sdRef:           A pointer to an uninitialized DNSServiceRef. Deallocating
1814 *                  the reference (via DNSServiceRefDeallocate()) severs the
1815 *                  connection and deregisters all records registered on this connection.
1816 *
1817 * return value:    Returns kDNSServiceErr_NoError on success, otherwise returns
1818 *                  an error code indicating the specific failure that occurred (in which
1819 *                  case the DNSServiceRef is not initialized).
1820 */
1821
1822DNSServiceErrorType DNSSD_API DNSServiceCreateConnection(DNSServiceRef *sdRef);
1823
1824/* DNSServiceRegisterRecord
1825 *
1826 * Register an individual resource record on a connected DNSServiceRef.
1827 *
1828 * Note that name conflicts occurring for records registered via this call must be handled
1829 * by the client in the callback.
1830 *
1831 * DNSServiceRegisterRecordReply() parameters:
1832 *
1833 * sdRef:           The connected DNSServiceRef initialized by
1834 *                  DNSServiceCreateConnection().
1835 *
1836 * RecordRef:       The DNSRecordRef initialized by DNSServiceRegisterRecord(). If the above
1837 *                  DNSServiceRef is passed to DNSServiceRefDeallocate(), this DNSRecordRef is
1838 *                  invalidated, and may not be used further.
1839 *
1840 * flags:           Currently unused, reserved for future use.
1841 *
1842 * errorCode:       Will be kDNSServiceErr_NoError on success, otherwise will
1843 *                  indicate the failure that occurred (including name conflicts.)
1844 *                  Other parameters are undefined if errorCode is nonzero.
1845 *
1846 * context:         The context pointer that was passed to the callout.
1847 *
1848 */
1849
1850typedef void (DNSSD_API *DNSServiceRegisterRecordReply)
1851(
1852    DNSServiceRef sdRef,
1853    DNSRecordRef RecordRef,
1854    DNSServiceFlags flags,
1855    DNSServiceErrorType errorCode,
1856    void                                *context
1857);
1858
1859
1860/* DNSServiceRegisterRecord() Parameters:
1861 *
1862 * sdRef:           A DNSServiceRef initialized by DNSServiceCreateConnection().
1863 *
1864 * RecordRef:       A pointer to an uninitialized DNSRecordRef. Upon succesfull completion of this
1865 *                  call, this ref may be passed to DNSServiceUpdateRecord() or DNSServiceRemoveRecord().
1866 *                  (To deregister ALL records registered on a single connected DNSServiceRef
1867 *                  and deallocate each of their corresponding DNSServiceRecordRefs, call
1868 *                  DNSServiceRefDeallocate()).
1869 *
1870 * flags:           Possible values are kDNSServiceFlagsShared or kDNSServiceFlagsUnique
1871 *                  (see flag type definitions for details).
1872 *
1873 * interfaceIndex:  If non-zero, specifies the interface on which to register the record
1874 *                  (the index for a given interface is determined via the if_nametoindex()
1875 *                  family of calls.) Passing 0 causes the record to be registered on all interfaces.
1876 *                  See "Constants for specifying an interface index" for more details.
1877 *
1878 * fullname:        The full domain name of the resource record.
1879 *
1880 * rrtype:          The numerical type of the resource record (e.g. kDNSServiceType_PTR, kDNSServiceType_SRV, etc)
1881 *
1882 * rrclass:         The class of the resource record (usually kDNSServiceClass_IN)
1883 *
1884 * rdlen:           Length, in bytes, of the rdata.
1885 *
1886 * rdata:           A pointer to the raw rdata, as it is to appear in the DNS record.
1887 *
1888 * ttl:             The time to live of the resource record, in seconds.
1889 *                  Most clients should pass 0 to indicate that the system should
1890 *                  select a sensible default value.
1891 *
1892 * callBack:        The function to be called when a result is found, or if the call
1893 *                  asynchronously fails (e.g. because of a name conflict.)
1894 *
1895 * context:         An application context pointer which is passed to the callback function
1896 *                  (may be NULL).
1897 *
1898 * return value:    Returns kDNSServiceErr_NoError on success (any subsequent, asynchronous
1899 *                  errors are delivered to the callback), otherwise returns an error code indicating
1900 *                  the error that occurred (the callback is never invoked and the DNSRecordRef is
1901 *                  not initialized).
1902 */
1903
1904DNSServiceErrorType DNSSD_API DNSServiceRegisterRecord
1905(
1906    DNSServiceRef sdRef,
1907    DNSRecordRef                        *RecordRef,
1908    DNSServiceFlags flags,
1909    uint32_t interfaceIndex,
1910    const char                          *fullname,
1911    uint16_t rrtype,
1912    uint16_t rrclass,
1913    uint16_t rdlen,
1914    const void                          *rdata,
1915    uint32_t ttl,
1916    DNSServiceRegisterRecordReply callBack,
1917    void                                *context    /* may be NULL */
1918);
1919
1920
1921/* DNSServiceReconfirmRecord
1922 *
1923 * Instruct the daemon to verify the validity of a resource record that appears
1924 * to be out of date (e.g. because TCP connection to a service's target failed.)
1925 * Causes the record to be flushed from the daemon's cache (as well as all other
1926 * daemons' caches on the network) if the record is determined to be invalid.
1927 * Use this routine conservatively. Reconfirming a record necessarily consumes
1928 * network bandwidth, so this should not be done indiscriminately.
1929 *
1930 * Parameters:
1931 *
1932 * flags:           Not currently used.
1933 *
1934 * interfaceIndex:  Specifies the interface of the record in question.
1935 *                  The caller must specify the interface.
1936 *                  This API (by design) causes increased network traffic, so it requires
1937 *                  the caller to be precise about which record should be reconfirmed.
1938 *                  It is not possible to pass zero for the interface index to perform
1939 *                  a "wildcard" reconfirmation, where *all* matching records are reconfirmed.
1940 *
1941 * fullname:        The resource record's full domain name.
1942 *
1943 * rrtype:          The resource record's type (e.g. kDNSServiceType_PTR, kDNSServiceType_SRV, etc)
1944 *
1945 * rrclass:         The class of the resource record (usually kDNSServiceClass_IN).
1946 *
1947 * rdlen:           The length, in bytes, of the resource record rdata.
1948 *
1949 * rdata:           The raw rdata of the resource record.
1950 *
1951 */
1952
1953DNSServiceErrorType DNSSD_API DNSServiceReconfirmRecord
1954(
1955    DNSServiceFlags flags,
1956    uint32_t interfaceIndex,
1957    const char                         *fullname,
1958    uint16_t rrtype,
1959    uint16_t rrclass,
1960    uint16_t rdlen,
1961    const void                         *rdata
1962);
1963
1964
1965/*********************************************************************************************
1966*
1967*  NAT Port Mapping
1968*
1969*********************************************************************************************/
1970
1971/* DNSServiceNATPortMappingCreate
1972 *
1973 * Request a port mapping in the NAT gateway, which maps a port on the local machine
1974 * to an external port on the NAT. The NAT should support either PCP, NAT-PMP or the
1975 * UPnP/IGD protocol for this API to create a successful mapping. Note that this API
1976 * currently supports IPv4 addresses/mappings only. If the NAT gateway supports PCP and
1977 * returns an IPv6 address (incorrectly, since this API specifically requests IPv4
1978 * addresses), the DNSServiceNATPortMappingReply callback will be invoked with errorCode
1979 * kDNSServiceErr_NATPortMappingUnsupported.
1980 *
1981 * The port mapping will be renewed indefinitely until the client process exits, or
1982 * explicitly terminates the port mapping request by calling DNSServiceRefDeallocate().
1983 * The client callback will be invoked, informing the client of the NAT gateway's
1984 * external IP address and the external port that has been allocated for this client.
1985 * The client should then record this external IP address and port using whatever
1986 * directory service mechanism it is using to enable peers to connect to it.
1987 * (Clients advertising services using Wide-Area DNS-SD DO NOT need to use this API
1988 * -- when a client calls DNSServiceRegister() NAT mappings are automatically created
1989 * and the external IP address and port for the service are recorded in the global DNS.
1990 * Only clients using some directory mechanism other than Wide-Area DNS-SD need to use
1991 * this API to explicitly map their own ports.)
1992 *
1993 * It's possible that the client callback could be called multiple times, for example
1994 * if the NAT gateway's IP address changes, or if a configuration change results in a
1995 * different external port being mapped for this client. Over the lifetime of any long-lived
1996 * port mapping, the client should be prepared to handle these notifications of changes
1997 * in the environment, and should update its recorded address and/or port as appropriate.
1998 *
1999 * NOTE: There are two unusual aspects of how the DNSServiceNATPortMappingCreate API works,
2000 * which were intentionally designed to help simplify client code:
2001 *
2002 *  1. It's not an error to request a NAT mapping when the machine is not behind a NAT gateway.
2003 *     In other NAT mapping APIs, if you request a NAT mapping and the machine is not behind a NAT
2004 *     gateway, then the API returns an error code -- it can't get you a NAT mapping if there's no
2005 *     NAT gateway. The DNSServiceNATPortMappingCreate API takes a different view. Working out
2006 *     whether or not you need a NAT mapping can be tricky and non-obvious, particularly on
2007 *     a machine with multiple active network interfaces. Rather than make every client recreate
2008 *     this logic for deciding whether a NAT mapping is required, the PortMapping API does that
2009 *     work for you. If the client calls the PortMapping API when the machine already has a
2010 *     routable public IP address, then instead of complaining about it and giving an error,
2011 *     the PortMapping API just invokes your callback, giving the machine's public address
2012 *     and your own port number. This means you don't need to write code to work out whether
2013 *     your client needs to call the PortMapping API -- just call it anyway, and if it wasn't
2014 *     necessary, no harm is done:
2015 *
2016 *     - If the machine already has a routable public IP address, then your callback
2017 *       will just be invoked giving your own address and port.
2018 *     - If a NAT mapping is required and obtained, then your callback will be invoked
2019 *       giving you the external address and port.
2020 *     - If a NAT mapping is required but not obtained from the local NAT gateway,
2021 *       or the machine has no network connectivity, then your callback will be
2022 *       invoked giving zero address and port.
2023 *
2024 *  2. In other NAT mapping APIs, if a laptop computer is put to sleep and woken up on a new
2025 *     network, it's the client's job to notice this, and work out whether a NAT mapping
2026 *     is required on the new network, and make a new NAT mapping request if necessary.
2027 *     The DNSServiceNATPortMappingCreate API does this for you, automatically.
2028 *     The client just needs to make one call to the PortMapping API, and its callback will
2029 *     be invoked any time the mapping state changes. This property complements point (1) above.
2030 *     If the client didn't make a NAT mapping request just because it determined that one was
2031 *     not required at that particular moment in time, the client would then have to monitor
2032 *     for network state changes to determine if a NAT port mapping later became necessary.
2033 *     By unconditionally making a NAT mapping request, even when a NAT mapping not to be
2034 *     necessary, the PortMapping API will then begin monitoring network state changes on behalf of
2035 *     the client, and if a NAT mapping later becomes necessary, it will automatically create a NAT
2036 *     mapping and inform the client with a new callback giving the new address and port information.
2037 *
2038 * DNSServiceNATPortMappingReply() parameters:
2039 *
2040 * sdRef:           The DNSServiceRef initialized by DNSServiceNATPortMappingCreate().
2041 *
2042 * flags:           Currently unused, reserved for future use.
2043 *
2044 * interfaceIndex:  The interface through which the NAT gateway is reached.
2045 *
2046 * errorCode:       Will be kDNSServiceErr_NoError on success.
2047 *                  Will be kDNSServiceErr_DoubleNAT when the NAT gateway is itself behind one or
2048 *                  more layers of NAT, in which case the other parameters have the defined values.
2049 *                  For other failures, will indicate the failure that occurred, and the other
2050 *                  parameters are undefined.
2051 *
2052 * externalAddress: Four byte IPv4 address in network byte order.
2053 *
2054 * protocol:        Will be kDNSServiceProtocol_UDP or kDNSServiceProtocol_TCP or both.
2055 *
2056 * internalPort:    The port on the local machine that was mapped.
2057 *
2058 * externalPort:    The actual external port in the NAT gateway that was mapped.
2059 *                  This is likely to be different than the requested external port.
2060 *
2061 * ttl:             The lifetime of the NAT port mapping created on the gateway.
2062 *                  This controls how quickly stale mappings will be garbage-collected
2063 *                  if the client machine crashes, suffers a power failure, is disconnected
2064 *                  from the network, or suffers some other unfortunate demise which
2065 *                  causes it to vanish without explicitly removing its NAT port mapping.
2066 *                  It's possible that the ttl value will differ from the requested ttl value.
2067 *
2068 * context:         The context pointer that was passed to the callout.
2069 *
2070 */
2071
2072typedef void (DNSSD_API *DNSServiceNATPortMappingReply)
2073(
2074    DNSServiceRef sdRef,
2075    DNSServiceFlags flags,
2076    uint32_t interfaceIndex,
2077    DNSServiceErrorType errorCode,
2078    uint32_t externalAddress,                           /* four byte IPv4 address in network byte order */
2079    DNSServiceProtocol protocol,
2080    uint16_t internalPort,                              /* In network byte order */
2081    uint16_t externalPort,                              /* In network byte order and may be different than the requested port */
2082    uint32_t ttl,                                       /* may be different than the requested ttl */
2083    void                             *context
2084);
2085
2086
2087/* DNSServiceNATPortMappingCreate() Parameters:
2088 *
2089 * sdRef:           A pointer to an uninitialized DNSServiceRef. If the call succeeds then it
2090 *                  initializes the DNSServiceRef, returns kDNSServiceErr_NoError, and the nat
2091 *                  port mapping will last indefinitely until the client terminates the port
2092 *                  mapping request by passing this DNSServiceRef to DNSServiceRefDeallocate().
2093 *
2094 * flags:           Currently ignored, reserved for future use.
2095 *
2096 * interfaceIndex:  The interface on which to create port mappings in a NAT gateway. Passing 0 causes
2097 *                  the port mapping request to be sent on the primary interface.
2098 *
2099 * protocol:        To request a port mapping, pass in kDNSServiceProtocol_UDP, or kDNSServiceProtocol_TCP,
2100 *                  or (kDNSServiceProtocol_UDP | kDNSServiceProtocol_TCP) to map both.
2101 *                  The local listening port number must also be specified in the internalPort parameter.
2102 *                  To just discover the NAT gateway's external IP address, pass zero for protocol,
2103 *                  internalPort, externalPort and ttl.
2104 *
2105 * internalPort:    The port number in network byte order on the local machine which is listening for packets.
2106 *
2107 * externalPort:    The requested external port in network byte order in the NAT gateway that you would
2108 *                  like to map to the internal port. Pass 0 if you don't care which external port is chosen for you.
2109 *
2110 * ttl:             The requested renewal period of the NAT port mapping, in seconds.
2111 *                  If the client machine crashes, suffers a power failure, is disconnected from
2112 *                  the network, or suffers some other unfortunate demise which causes it to vanish
2113 *                  unexpectedly without explicitly removing its NAT port mappings, then the NAT gateway
2114 *                  will garbage-collect old stale NAT port mappings when their lifetime expires.
2115 *                  Requesting a short TTL causes such orphaned mappings to be garbage-collected
2116 *                  more promptly, but consumes system resources and network bandwidth with
2117 *                  frequent renewal packets to keep the mapping from expiring.
2118 *                  Requesting a long TTL is more efficient on the network, but in the event of the
2119 *                  client vanishing, stale NAT port mappings will not be garbage-collected as quickly.
2120 *                  Most clients should pass 0 to use a system-wide default value.
2121 *
2122 * callBack:        The function to be called when the port mapping request succeeds or fails asynchronously.
2123 *
2124 * context:         An application context pointer which is passed to the callback function
2125 *                  (may be NULL).
2126 *
2127 * return value:    Returns kDNSServiceErr_NoError on success (any subsequent, asynchronous
2128 *                  errors are delivered to the callback), otherwise returns an error code indicating
2129 *                  the error that occurred.
2130 *
2131 *                  If you don't actually want a port mapped, and are just calling the API
2132 *                  because you want to find out the NAT's external IP address (e.g. for UI
2133 *                  display) then pass zero for protocol, internalPort, externalPort and ttl.
2134 */
2135
2136DNSServiceErrorType DNSSD_API DNSServiceNATPortMappingCreate
2137(
2138    DNSServiceRef                    *sdRef,
2139    DNSServiceFlags flags,
2140    uint32_t interfaceIndex,
2141    DNSServiceProtocol protocol,                        /* TCP and/or UDP          */
2142    uint16_t internalPort,                              /* network byte order      */
2143    uint16_t externalPort,                              /* network byte order      */
2144    uint32_t ttl,                                       /* time to live in seconds */
2145    DNSServiceNATPortMappingReply callBack,
2146    void                             *context           /* may be NULL             */
2147);
2148
2149
2150/*********************************************************************************************
2151*
2152*  General Utility Functions
2153*
2154*********************************************************************************************/
2155
2156/* DNSServiceConstructFullName()
2157 *
2158 * Concatenate a three-part domain name (as returned by the above callbacks) into a
2159 * properly-escaped full domain name. Note that callbacks in the above functions ALREADY ESCAPE
2160 * strings where necessary.
2161 *
2162 * Parameters:
2163 *
2164 * fullName:        A pointer to a buffer that where the resulting full domain name is to be written.
2165 *                  The buffer must be kDNSServiceMaxDomainName (1009) bytes in length to
2166 *                  accommodate the longest legal domain name without buffer overrun.
2167 *
2168 * service:         The service name - any dots or backslashes must NOT be escaped.
2169 *                  May be NULL (to construct a PTR record name, e.g.
2170 *                  "_ftp._tcp.apple.com.").
2171 *
2172 * regtype:         The service type followed by the protocol, separated by a dot
2173 *                  (e.g. "_ftp._tcp").
2174 *
2175 * domain:          The domain name, e.g. "apple.com.". Literal dots or backslashes,
2176 *                  if any, must be escaped, e.g. "1st\. Floor.apple.com."
2177 *
2178 * return value:    Returns kDNSServiceErr_NoError (0) on success, kDNSServiceErr_BadParam on error.
2179 *
2180 */
2181
2182DNSServiceErrorType DNSSD_API DNSServiceConstructFullName
2183(
2184    char                            * const fullName,
2185    const char                      * const service,      /* may be NULL */
2186    const char                      * const regtype,
2187    const char                      * const domain
2188);
2189
2190
2191/*********************************************************************************************
2192*
2193*   TXT Record Construction Functions
2194*
2195*********************************************************************************************/
2196
2197/*
2198 * A typical calling sequence for TXT record construction is something like:
2199 *
2200 * Client allocates storage for TXTRecord data (e.g. declare buffer on the stack)
2201 * TXTRecordCreate();
2202 * TXTRecordSetValue();
2203 * TXTRecordSetValue();
2204 * TXTRecordSetValue();
2205 * ...
2206 * DNSServiceRegister( ... TXTRecordGetLength(), TXTRecordGetBytesPtr() ... );
2207 * TXTRecordDeallocate();
2208 * Explicitly deallocate storage for TXTRecord data (if not allocated on the stack)
2209 */
2210
2211
2212/* TXTRecordRef
2213 *
2214 * Opaque internal data type.
2215 * Note: Represents a DNS-SD TXT record.
2216 */
2217
2218typedef union _TXTRecordRef_t { char PrivateData[16]; char *ForceNaturalAlignment; } TXTRecordRef;
2219
2220
2221/* TXTRecordCreate()
2222 *
2223 * Creates a new empty TXTRecordRef referencing the specified storage.
2224 *
2225 * If the buffer parameter is NULL, or the specified storage size is not
2226 * large enough to hold a key subsequently added using TXTRecordSetValue(),
2227 * then additional memory will be added as needed using malloc().
2228 *
2229 * On some platforms, when memory is low, malloc() may fail. In this
2230 * case, TXTRecordSetValue() will return kDNSServiceErr_NoMemory, and this
2231 * error condition will need to be handled as appropriate by the caller.
2232 *
2233 * You can avoid the need to handle this error condition if you ensure
2234 * that the storage you initially provide is large enough to hold all
2235 * the key/value pairs that are to be added to the record.
2236 * The caller can precompute the exact length required for all of the
2237 * key/value pairs to be added, or simply provide a fixed-sized buffer
2238 * known in advance to be large enough.
2239 * A no-value (key-only) key requires  (1 + key length) bytes.
2240 * A key with empty value requires     (1 + key length + 1) bytes.
2241 * A key with non-empty value requires (1 + key length + 1 + value length).
2242 * For most applications, DNS-SD TXT records are generally
2243 * less than 100 bytes, so in most cases a simple fixed-sized
2244 * 256-byte buffer will be more than sufficient.
2245 * Recommended size limits for DNS-SD TXT Records are discussed in
2246 * <http://files.dns-sd.org/draft-cheshire-dnsext-dns-sd.txt>
2247 *
2248 * Note: When passing parameters to and from these TXT record APIs,
2249 * the key name does not include the '=' character. The '=' character
2250 * is the separator between the key and value in the on-the-wire
2251 * packet format; it is not part of either the key or the value.
2252 *
2253 * txtRecord:       A pointer to an uninitialized TXTRecordRef.
2254 *
2255 * bufferLen:       The size of the storage provided in the "buffer" parameter.
2256 *
2257 * buffer:          Optional caller-supplied storage used to hold the TXTRecord data.
2258 *                  This storage must remain valid for as long as
2259 *                  the TXTRecordRef.
2260 */
2261
2262void DNSSD_API TXTRecordCreate
2263(
2264    TXTRecordRef     *txtRecord,
2265    uint16_t bufferLen,
2266    void             *buffer
2267);
2268
2269
2270/* TXTRecordDeallocate()
2271 *
2272 * Releases any resources allocated in the course of preparing a TXT Record
2273 * using TXTRecordCreate()/TXTRecordSetValue()/TXTRecordRemoveValue().
2274 * Ownership of the buffer provided in TXTRecordCreate() returns to the client.
2275 *
2276 * txtRecord:           A TXTRecordRef initialized by calling TXTRecordCreate().
2277 *
2278 */
2279
2280void DNSSD_API TXTRecordDeallocate
2281(
2282    TXTRecordRef     *txtRecord
2283);
2284
2285
2286/* TXTRecordSetValue()
2287 *
2288 * Adds a key (optionally with value) to a TXTRecordRef. If the "key" already
2289 * exists in the TXTRecordRef, then the current value will be replaced with
2290 * the new value.
2291 * Keys may exist in four states with respect to a given TXT record:
2292 *  - Absent (key does not appear at all)
2293 *  - Present with no value ("key" appears alone)
2294 *  - Present with empty value ("key=" appears in TXT record)
2295 *  - Present with non-empty value ("key=value" appears in TXT record)
2296 * For more details refer to "Data Syntax for DNS-SD TXT Records" in
2297 * <http://files.dns-sd.org/draft-cheshire-dnsext-dns-sd.txt>
2298 *
2299 * txtRecord:       A TXTRecordRef initialized by calling TXTRecordCreate().
2300 *
2301 * key:             A null-terminated string which only contains printable ASCII
2302 *                  values (0x20-0x7E), excluding '=' (0x3D). Keys should be
2303 *                  9 characters or fewer (not counting the terminating null).
2304 *
2305 * valueSize:       The size of the value.
2306 *
2307 * value:           Any binary value. For values that represent
2308 *                  textual data, UTF-8 is STRONGLY recommended.
2309 *                  For values that represent textual data, valueSize
2310 *                  should NOT include the terminating null (if any)
2311 *                  at the end of the string.
2312 *                  If NULL, then "key" will be added with no value.
2313 *                  If non-NULL but valueSize is zero, then "key=" will be
2314 *                  added with empty value.
2315 *
2316 * return value:    Returns kDNSServiceErr_NoError on success.
2317 *                  Returns kDNSServiceErr_Invalid if the "key" string contains
2318 *                  illegal characters.
2319 *                  Returns kDNSServiceErr_NoMemory if adding this key would
2320 *                  exceed the available storage.
2321 */
2322
2323DNSServiceErrorType DNSSD_API TXTRecordSetValue
2324(
2325    TXTRecordRef     *txtRecord,
2326    const char       *key,
2327    uint8_t valueSize,                 /* may be zero */
2328    const void       *value            /* may be NULL */
2329);
2330
2331
2332/* TXTRecordRemoveValue()
2333 *
2334 * Removes a key from a TXTRecordRef. The "key" must be an
2335 * ASCII string which exists in the TXTRecordRef.
2336 *
2337 * txtRecord:       A TXTRecordRef initialized by calling TXTRecordCreate().
2338 *
2339 * key:             A key name which exists in the TXTRecordRef.
2340 *
2341 * return value:    Returns kDNSServiceErr_NoError on success.
2342 *                  Returns kDNSServiceErr_NoSuchKey if the "key" does not
2343 *                  exist in the TXTRecordRef.
2344 */
2345
2346DNSServiceErrorType DNSSD_API TXTRecordRemoveValue
2347(
2348    TXTRecordRef     *txtRecord,
2349    const char       *key
2350);
2351
2352
2353/* TXTRecordGetLength()
2354 *
2355 * Allows you to determine the length of the raw bytes within a TXTRecordRef.
2356 *
2357 * txtRecord:       A TXTRecordRef initialized by calling TXTRecordCreate().
2358 *
2359 * return value:    Returns the size of the raw bytes inside a TXTRecordRef
2360 *                  which you can pass directly to DNSServiceRegister() or
2361 *                  to DNSServiceUpdateRecord().
2362 *                  Returns 0 if the TXTRecordRef is empty.
2363 */
2364
2365uint16_t DNSSD_API TXTRecordGetLength
2366(
2367    const TXTRecordRef *txtRecord
2368);
2369
2370
2371/* TXTRecordGetBytesPtr()
2372 *
2373 * Allows you to retrieve a pointer to the raw bytes within a TXTRecordRef.
2374 *
2375 * txtRecord:       A TXTRecordRef initialized by calling TXTRecordCreate().
2376 *
2377 * return value:    Returns a pointer to the raw bytes inside the TXTRecordRef
2378 *                  which you can pass directly to DNSServiceRegister() or
2379 *                  to DNSServiceUpdateRecord().
2380 */
2381
2382const void * DNSSD_API TXTRecordGetBytesPtr
2383(
2384    const TXTRecordRef *txtRecord
2385);
2386
2387
2388/*********************************************************************************************
2389*
2390*   TXT Record Parsing Functions
2391*
2392*********************************************************************************************/
2393
2394/*
2395 * A typical calling sequence for TXT record parsing is something like:
2396 *
2397 * Receive TXT record data in DNSServiceResolve() callback
2398 * if (TXTRecordContainsKey(txtLen, txtRecord, "key")) then do something
2399 * val1ptr = TXTRecordGetValuePtr(txtLen, txtRecord, "key1", &len1);
2400 * val2ptr = TXTRecordGetValuePtr(txtLen, txtRecord, "key2", &len2);
2401 * ...
2402 * memcpy(myval1, val1ptr, len1);
2403 * memcpy(myval2, val2ptr, len2);
2404 * ...
2405 * return;
2406 *
2407 * If you wish to retain the values after return from the DNSServiceResolve()
2408 * callback, then you need to copy the data to your own storage using memcpy()
2409 * or similar, as shown in the example above.
2410 *
2411 * If for some reason you need to parse a TXT record you built yourself
2412 * using the TXT record construction functions above, then you can do
2413 * that using TXTRecordGetLength and TXTRecordGetBytesPtr calls:
2414 * TXTRecordGetValue(TXTRecordGetLength(x), TXTRecordGetBytesPtr(x), key, &len);
2415 *
2416 * Most applications only fetch keys they know about from a TXT record and
2417 * ignore the rest.
2418 * However, some debugging tools wish to fetch and display all keys.
2419 * To do that, use the TXTRecordGetCount() and TXTRecordGetItemAtIndex() calls.
2420 */
2421
2422/* TXTRecordContainsKey()
2423 *
2424 * Allows you to determine if a given TXT Record contains a specified key.
2425 *
2426 * txtLen:          The size of the received TXT Record.
2427 *
2428 * txtRecord:       Pointer to the received TXT Record bytes.
2429 *
2430 * key:             A null-terminated ASCII string containing the key name.
2431 *
2432 * return value:    Returns 1 if the TXT Record contains the specified key.
2433 *                  Otherwise, it returns 0.
2434 */
2435
2436int DNSSD_API TXTRecordContainsKey
2437(
2438    uint16_t txtLen,
2439    const void       *txtRecord,
2440    const char       *key
2441);
2442
2443
2444/* TXTRecordGetValuePtr()
2445 *
2446 * Allows you to retrieve the value for a given key from a TXT Record.
2447 *
2448 * txtLen:          The size of the received TXT Record
2449 *
2450 * txtRecord:       Pointer to the received TXT Record bytes.
2451 *
2452 * key:             A null-terminated ASCII string containing the key name.
2453 *
2454 * valueLen:        On output, will be set to the size of the "value" data.
2455 *
2456 * return value:    Returns NULL if the key does not exist in this TXT record,
2457 *                  or exists with no value (to differentiate between
2458 *                  these two cases use TXTRecordContainsKey()).
2459 *                  Returns pointer to location within TXT Record bytes
2460 *                  if the key exists with empty or non-empty value.
2461 *                  For empty value, valueLen will be zero.
2462 *                  For non-empty value, valueLen will be length of value data.
2463 */
2464
2465const void * DNSSD_API TXTRecordGetValuePtr
2466(
2467    uint16_t txtLen,
2468    const void       *txtRecord,
2469    const char       *key,
2470    uint8_t          *valueLen
2471);
2472
2473
2474/* TXTRecordGetCount()
2475 *
2476 * Returns the number of keys stored in the TXT Record. The count
2477 * can be used with TXTRecordGetItemAtIndex() to iterate through the keys.
2478 *
2479 * txtLen:          The size of the received TXT Record.
2480 *
2481 * txtRecord:       Pointer to the received TXT Record bytes.
2482 *
2483 * return value:    Returns the total number of keys in the TXT Record.
2484 *
2485 */
2486
2487uint16_t DNSSD_API TXTRecordGetCount
2488(
2489    uint16_t txtLen,
2490    const void       *txtRecord
2491);
2492
2493
2494/* TXTRecordGetItemAtIndex()
2495 *
2496 * Allows you to retrieve a key name and value pointer, given an index into
2497 * a TXT Record. Legal index values range from zero to TXTRecordGetCount()-1.
2498 * It's also possible to iterate through keys in a TXT record by simply
2499 * calling TXTRecordGetItemAtIndex() repeatedly, beginning with index zero
2500 * and increasing until TXTRecordGetItemAtIndex() returns kDNSServiceErr_Invalid.
2501 *
2502 * On return:
2503 * For keys with no value, *value is set to NULL and *valueLen is zero.
2504 * For keys with empty value, *value is non-NULL and *valueLen is zero.
2505 * For keys with non-empty value, *value is non-NULL and *valueLen is non-zero.
2506 *
2507 * txtLen:          The size of the received TXT Record.
2508 *
2509 * txtRecord:       Pointer to the received TXT Record bytes.
2510 *
2511 * itemIndex:       An index into the TXT Record.
2512 *
2513 * keyBufLen:       The size of the string buffer being supplied.
2514 *
2515 * key:             A string buffer used to store the key name.
2516 *                  On return, the buffer contains a null-terminated C string
2517 *                  giving the key name. DNS-SD TXT keys are usually
2518 *                  9 characters or fewer. To hold the maximum possible
2519 *                  key name, the buffer should be 256 bytes long.
2520 *
2521 * valueLen:        On output, will be set to the size of the "value" data.
2522 *
2523 * value:           On output, *value is set to point to location within TXT
2524 *                  Record bytes that holds the value data.
2525 *
2526 * return value:    Returns kDNSServiceErr_NoError on success.
2527 *                  Returns kDNSServiceErr_NoMemory if keyBufLen is too short.
2528 *                  Returns kDNSServiceErr_Invalid if index is greater than
2529 *                  TXTRecordGetCount()-1.
2530 */
2531
2532DNSServiceErrorType DNSSD_API TXTRecordGetItemAtIndex
2533(
2534    uint16_t txtLen,
2535    const void       *txtRecord,
2536    uint16_t itemIndex,
2537    uint16_t keyBufLen,
2538    char             *key,
2539    uint8_t          *valueLen,
2540    const void       **value
2541);
2542
2543#if _DNS_SD_LIBDISPATCH
2544/*
2545 * DNSServiceSetDispatchQueue
2546 *
2547 * Allows you to schedule a DNSServiceRef on a serial dispatch queue for receiving asynchronous
2548 * callbacks.  It's the clients responsibility to ensure that the provided dispatch queue is running.
2549 *
2550 * A typical application that uses CFRunLoopRun or dispatch_main on its main thread will
2551 * usually schedule DNSServiceRefs on its main queue (which is always a serial queue)
2552 * using "DNSServiceSetDispatchQueue(sdref, dispatch_get_main_queue());"
2553 *
2554 * If there is any error during the processing of events, the application callback will
2555 * be called with an error code. For shared connections, each subordinate DNSServiceRef
2556 * will get its own error callback. Currently these error callbacks only happen
2557 * if the daemon is manually terminated or crashes, and the error
2558 * code in this case is kDNSServiceErr_ServiceNotRunning. The application must call
2559 * DNSServiceRefDeallocate to free the DNSServiceRef when it gets such an error code.
2560 * These error callbacks are rare and should not normally happen on customer machines,
2561 * but application code should be written defensively to handle such error callbacks
2562 * gracefully if they occur.
2563 *
2564 * After using DNSServiceSetDispatchQueue on a DNSServiceRef, calling DNSServiceProcessResult
2565 * on the same DNSServiceRef will result in undefined behavior and should be avoided.
2566 *
2567 * Once the application successfully schedules a DNSServiceRef on a serial dispatch queue using
2568 * DNSServiceSetDispatchQueue, it cannot remove the DNSServiceRef from the dispatch queue, or use
2569 * DNSServiceSetDispatchQueue a second time to schedule the DNSServiceRef onto a different serial dispatch
2570 * queue. Once scheduled onto a dispatch queue a DNSServiceRef will deliver events to that queue until
2571 * the application no longer requires that operation and terminates it using DNSServiceRefDeallocate.
2572 *
2573 * service:         DNSServiceRef that was allocated and returned to the application, when the
2574 *                  application calls one of the DNSService API.
2575 *
2576 * queue:           dispatch queue where the application callback will be scheduled
2577 *
2578 * return value:    Returns kDNSServiceErr_NoError on success.
2579 *                  Returns kDNSServiceErr_NoMemory if it cannot create a dispatch source
2580 *                  Returns kDNSServiceErr_BadParam if the service param is invalid or the
2581 *                  queue param is invalid
2582 */
2583
2584DNSServiceErrorType DNSSD_API DNSServiceSetDispatchQueue
2585(
2586    DNSServiceRef service,
2587    dispatch_queue_t queue
2588);
2589#endif //_DNS_SD_LIBDISPATCH
2590
2591#if !defined(_WIN32)
2592typedef void (DNSSD_API *DNSServiceSleepKeepaliveReply)
2593(
2594    DNSServiceRef sdRef,
2595    DNSServiceErrorType errorCode,
2596    void                                *context
2597);
2598DNSServiceErrorType DNSSD_API DNSServiceSleepKeepalive
2599(
2600    DNSServiceRef                       *sdRef,
2601    DNSServiceFlags flags,
2602    int fd,
2603    unsigned int timeout,
2604    DNSServiceSleepKeepaliveReply callBack,
2605    void                                *context
2606);
2607#endif
2608
2609#ifdef APPLE_OSX_mDNSResponder
2610/* DNSServiceCreateDelegateConnection()
2611 *
2612 * Create a delegate connection to the daemon allowing efficient registration of
2613 * multiple individual records.
2614 *
2615 * Parameters:
2616 *
2617 * sdRef:           A pointer to an uninitialized DNSServiceRef. Deallocating
2618 *                  the reference (via DNSServiceRefDeallocate()) severs the
2619 *                  connection and deregisters all records registered on this connection.
2620 *
2621 * pid :            Process ID of the delegate
2622 *
2623 * uuid:            UUID of the delegate
2624 *
2625 *                  Note that only one of the two arguments (pid or uuid) can be specified. If pid
2626 *                  is zero, uuid will be assumed to be a valid value; otherwise pid will be used.
2627 *
2628 * return value:    Returns kDNSServiceErr_NoError on success, otherwise returns
2629 *                  an error code indicating the specific failure that occurred (in which
2630 *                  case the DNSServiceRef is not initialized). kDNSServiceErr_NotAuth is
2631 *                  returned to indicate that the calling process does not have entitlements
2632 *                  to use this API.
2633 */
2634DNSServiceErrorType DNSSD_API DNSServiceCreateDelegateConnection(DNSServiceRef *sdRef, int32_t pid, uuid_t uuid);
2635#endif
2636
2637#ifdef __APPLE_API_PRIVATE
2638
2639#define kDNSServiceCompPrivateDNS   "PrivateDNS"
2640#define kDNSServiceCompMulticastDNS "MulticastDNS"
2641
2642#endif //__APPLE_API_PRIVATE
2643
2644/* Some C compiler cleverness. We can make the compiler check certain things for us,
2645 * and report errors at compile-time if anything is wrong. The usual way to do this would
2646 * be to use a run-time "if" statement or the conventional run-time "assert" mechanism, but
2647 * then you don't find out what's wrong until you run the software. This way, if the assertion
2648 * condition is false, the array size is negative, and the complier complains immediately.
2649 */
2650
2651struct CompileTimeAssertionChecks_DNS_SD
2652{
2653    char assert0[(sizeof(union _TXTRecordRef_t) == 16) ? 1 : -1];
2654};
2655
2656#ifdef  __cplusplus
2657}
2658#endif
2659
2660#endif  /* _DNS_SD_H */
Note: See TracBrowser for help on using the repository browser.