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

55-freebsd-126-freebsd-12
Last change on this file since f01edf1 was f01edf1, checked in by Sebastian Huber <sebastian.huber@…>, on 09/19/18 at 06:53:26

mDNSResponder: Update to v765.1.2

The sources can be obtained via:

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

Move mDNS_StartResolveService() and mDNS_StopResolveService() to an
RTEMS-specific file (rtemsbsd/mdns/mDNSResolveService.c) using the
v576.30.4 implementation. Apple removed these functions without
explanation.

Update #3522.

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