xref: /titanic_44/usr/src/lib/libdns_sd/common/dns_sd.h (revision 4557a2a1868181b517f5dfe61ba6eeba58edf4c0)
1 /* -*- Mode: C; tab-width: 4 -*-
2  *
3  * Copyright (c) 2003-2004, Apple Computer, Inc. All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * 1.  Redistributions of source code must retain the above copyright notice,
9  *     this list of conditions and the following disclaimer.
10  * 2.  Redistributions in binary form must reproduce the above copyright notice,
11  *     this list of conditions and the following disclaimer in the documentation
12  *     and/or other materials provided with the distribution.
13  * 3.  Neither the name of Apple Computer, Inc. ("Apple") nor the names of its
14  *     contributors may be used to endorse or promote products derived from this
15  *     software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
18  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20  * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
21  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  */
28 
29 #pragma ident	"%Z%%M%	%I%	%E% SMI"
30 
31 #ifndef _DNS_SD_H
32 #define _DNS_SD_H
33 
34 #ifdef  __cplusplus
35     extern "C" {
36 #endif
37 
38 /* standard calling convention under Win32 is __stdcall */
39 /* Note: When compiling Intel EFI (Extensible Firmware Interface) under MS Visual Studio, the */
40 /* _WIN32 symbol is defined by the compiler even though it's NOT compiling code for Windows32 */
41 #if defined(_WIN32) && !defined(EFI32) && !defined(EFI64)
42 #define DNSSD_API __stdcall
43 #else
44 #define DNSSD_API
45 #endif
46 
47 /* stdint.h does not exist on FreeBSD 4.x; its types are defined in sys/types.h instead */
48 #if defined(__FreeBSD__) && (__FreeBSD__ < 5)
49 #include <sys/types.h>
50 
51 /* Likewise, on Sun, standard integer types are in sys/types.h */
52 #elif defined(__sun__)
53 #include <sys/types.h>
54 
55 /* EFI does not have stdint.h, or anything else equivalent */
56 #elif defined(EFI32) || defined(EFI64)
57 typedef UINT8       uint8_t;
58 typedef INT8        int8_t;
59 typedef UINT16      uint16_t;
60 typedef INT16       int16_t;
61 typedef UINT32      uint32_t;
62 typedef INT32       int32_t;
63 
64 /* Windows has its own differences */
65 #elif defined(_WIN32)
66 #include <windows.h>
67 #define _UNUSED
68 #define bzero(a, b) memset(a, 0, b)
69 #ifndef _MSL_STDINT_H
70 typedef UINT8       uint8_t;
71 typedef INT8        int8_t;
72 typedef UINT16      uint16_t;
73 typedef INT16       int16_t;
74 typedef UINT32      uint32_t;
75 typedef INT32       int32_t;
76 #endif
77 
78 /* All other Posix platforms use stdint.h */
79 #else
80 #include <stdint.h>
81 #include <strings.h>
82 #endif
83 
84 /* DNSServiceRef, DNSRecordRef
85  *
86  * Opaque internal data types.
87  * Note: client is responsible for serializing access to these structures if
88  * they are shared between concurrent threads.
89  */
90 
91 typedef struct _DNSServiceRef_t *DNSServiceRef;
92 typedef struct _DNSRecordRef_t *DNSRecordRef;
93 
94 /* General flags used in functions defined below */
95 enum
96     {
97     kDNSServiceFlagsMoreComing          = 0x1,
98     /* MoreComing indicates to a callback that at least one more result is
99      * queued and will be delivered following immediately after this one.
100      * Applications should not update their UI to display browse
101      * results when the MoreComing flag is set, because this would
102      * result in a great deal of ugly flickering on the screen.
103      * Applications should instead wait until until MoreComing is not set,
104      * and then update their UI.
105      * When MoreComing is not set, that doesn't mean there will be no more
106      * answers EVER, just that there are no more answers immediately
107      * available right now at this instant. If more answers become available
108      * in the future they will be delivered as usual.
109      */
110 
111     kDNSServiceFlagsAdd                 = 0x2,
112     kDNSServiceFlagsDefault             = 0x4,
113     /* Flags for domain enumeration and browse/query reply callbacks.
114      * "Default" applies only to enumeration and is only valid in
115      * conjuction with "Add".  An enumeration callback with the "Add"
116      * flag NOT set indicates a "Remove", i.e. the domain is no longer
117      * valid.
118      */
119 
120     kDNSServiceFlagsNoAutoRename        = 0x8,
121     /* Flag for specifying renaming behavior on name conflict when registering
122      * non-shared records. By default, name conflicts are automatically handled
123      * by renaming the service.  NoAutoRename overrides this behavior - with this
124      * flag set, name conflicts will result in a callback.  The NoAutorename flag
125      * is only valid if a name is explicitly specified when registering a service
126      * (i.e. the default name is not used.)
127      */
128 
129     kDNSServiceFlagsShared              = 0x10,
130     kDNSServiceFlagsUnique              = 0x20,
131     /* Flag for registering individual records on a connected
132      * DNSServiceRef.  Shared indicates that there may be multiple records
133      * with this name on the network (e.g. PTR records).  Unique indicates that the
134      * record's name is to be unique on the network (e.g. SRV records).
135      */
136 
137     kDNSServiceFlagsBrowseDomains       = 0x40,
138     kDNSServiceFlagsRegistrationDomains = 0x80,
139     /* Flags for specifying domain enumeration type in DNSServiceEnumerateDomains.
140      * BrowseDomains enumerates domains recommended for browsing, RegistrationDomains
141      * enumerates domains recommended for registration.
142      */
143 
144     kDNSServiceFlagsLongLivedQuery      = 0x100,
145     /* Flag for creating a long-lived unicast query for the DNSServiceQueryRecord call. */
146 
147     kDNSServiceFlagsAllowRemoteQuery    = 0x200,
148     /* Flag for creating a record for which we will answer remote queries
149      * (queries from hosts more than one hop away; hosts not directly connected to the local link).
150      */
151 
152     kDNSServiceFlagsForceMulticast      = 0x400,
153     /* Flag for signifying that a query or registration should be performed exclusively via multicast DNS,
154      * even for a name in a domain (e.g. foo.apple.com.) that would normally imply unicast DNS.
155      */
156 
157     kDNSServiceFlagsReturnCNAME         = 0x800
158     /* Flag for returning CNAME records in the DNSServiceQueryRecord call. CNAME records are
159      * normally followed without indicating to the client that there was a CNAME record.
160      */
161     };
162 
163 /*
164  * The values for DNS Classes and Types are listed in RFC 1035, and are available
165  * on every OS in its DNS header file. Unfortunately every OS does not have the
166  * same header file containing DNS Class and Type constants, and the names of
167  * the constants are not consistent. For example, BIND 8 uses "T_A",
168  * BIND 9 uses "ns_t_a", Windows uses "DNS_TYPE_A", etc.
169  * For this reason, these constants are also listed here, so that code using
170  * the DNS-SD programming APIs can use these constants, so that the same code
171  * can compile on all our supported platforms.
172  */
173 
174 enum
175     {
176     kDNSServiceClass_IN       = 1       /* Internet */
177     };
178 
179 enum
180     {
181     kDNSServiceType_A         = 1,      /* Host address. */
182     kDNSServiceType_NS        = 2,      /* Authoritative server. */
183     kDNSServiceType_MD        = 3,      /* Mail destination. */
184     kDNSServiceType_MF        = 4,      /* Mail forwarder. */
185     kDNSServiceType_CNAME     = 5,      /* Canonical name. */
186     kDNSServiceType_SOA       = 6,      /* Start of authority zone. */
187     kDNSServiceType_MB        = 7,      /* Mailbox domain name. */
188     kDNSServiceType_MG        = 8,      /* Mail group member. */
189     kDNSServiceType_MR        = 9,      /* Mail rename name. */
190     kDNSServiceType_NULL      = 10,     /* Null resource record. */
191     kDNSServiceType_WKS       = 11,     /* Well known service. */
192     kDNSServiceType_PTR       = 12,     /* Domain name pointer. */
193     kDNSServiceType_HINFO     = 13,     /* Host information. */
194     kDNSServiceType_MINFO     = 14,     /* Mailbox information. */
195     kDNSServiceType_MX        = 15,     /* Mail routing information. */
196     kDNSServiceType_TXT       = 16,     /* One or more text strings. */
197     kDNSServiceType_RP        = 17,     /* Responsible person. */
198     kDNSServiceType_AFSDB     = 18,     /* AFS cell database. */
199     kDNSServiceType_X25       = 19,     /* X_25 calling address. */
200     kDNSServiceType_ISDN      = 20,     /* ISDN calling address. */
201     kDNSServiceType_RT        = 21,     /* Router. */
202     kDNSServiceType_NSAP      = 22,     /* NSAP address. */
203     kDNSServiceType_NSAP_PTR  = 23,     /* Reverse NSAP lookup (deprecated). */
204     kDNSServiceType_SIG       = 24,     /* Security signature. */
205     kDNSServiceType_KEY       = 25,     /* Security key. */
206     kDNSServiceType_PX        = 26,     /* X.400 mail mapping. */
207     kDNSServiceType_GPOS      = 27,     /* Geographical position (withdrawn). */
208     kDNSServiceType_AAAA      = 28,     /* IPv6 Address. */
209     kDNSServiceType_LOC       = 29,     /* Location Information. */
210     kDNSServiceType_NXT       = 30,     /* Next domain (security). */
211     kDNSServiceType_EID       = 31,     /* Endpoint identifier. */
212     kDNSServiceType_NIMLOC    = 32,     /* Nimrod Locator. */
213     kDNSServiceType_SRV       = 33,     /* Server Selection. */
214     kDNSServiceType_ATMA      = 34,     /* ATM Address */
215     kDNSServiceType_NAPTR     = 35,     /* Naming Authority PoinTeR */
216     kDNSServiceType_KX        = 36,     /* Key Exchange */
217     kDNSServiceType_CERT      = 37,     /* Certification record */
218     kDNSServiceType_A6        = 38,     /* IPv6 Address (deprecated) */
219     kDNSServiceType_DNAME     = 39,     /* Non-terminal DNAME (for IPv6) */
220     kDNSServiceType_SINK      = 40,     /* Kitchen sink (experimentatl) */
221     kDNSServiceType_OPT       = 41,     /* EDNS0 option (meta-RR) */
222     kDNSServiceType_TKEY      = 249,    /* Transaction key */
223     kDNSServiceType_TSIG      = 250,    /* Transaction signature. */
224     kDNSServiceType_IXFR      = 251,    /* Incremental zone transfer. */
225     kDNSServiceType_AXFR      = 252,    /* Transfer zone of authority. */
226     kDNSServiceType_MAILB     = 253,    /* Transfer mailbox records. */
227     kDNSServiceType_MAILA     = 254,    /* Transfer mail agent records. */
228     kDNSServiceType_ANY       = 255     /* Wildcard match. */
229     };
230 
231 
232 /* possible error code values */
233 enum
234     {
235     kDNSServiceErr_NoError             = 0,
236     kDNSServiceErr_Unknown             = -65537,       /* 0xFFFE FFFF */
237     kDNSServiceErr_NoSuchName          = -65538,
238     kDNSServiceErr_NoMemory            = -65539,
239     kDNSServiceErr_BadParam            = -65540,
240     kDNSServiceErr_BadReference        = -65541,
241     kDNSServiceErr_BadState            = -65542,
242     kDNSServiceErr_BadFlags            = -65543,
243     kDNSServiceErr_Unsupported         = -65544,
244     kDNSServiceErr_NotInitialized      = -65545,
245     kDNSServiceErr_AlreadyRegistered   = -65547,
246     kDNSServiceErr_NameConflict        = -65548,
247     kDNSServiceErr_Invalid             = -65549,
248     kDNSServiceErr_Firewall            = -65550,
249     kDNSServiceErr_Incompatible        = -65551,        /* client library incompatible with daemon */
250     kDNSServiceErr_BadInterfaceIndex   = -65552,
251     kDNSServiceErr_Refused             = -65553,
252     kDNSServiceErr_NoSuchRecord        = -65554,
253     kDNSServiceErr_NoAuth              = -65555,
254     kDNSServiceErr_NoSuchKey           = -65556,
255     kDNSServiceErr_NATTraversal        = -65557,
256     kDNSServiceErr_DoubleNAT           = -65558,
257     kDNSServiceErr_BadTime             = -65559
258     /* mDNS Error codes are in the range
259      * FFFE FF00 (-65792) to FFFE FFFF (-65537) */
260     };
261 
262 
263 /* Maximum length, in bytes, of a service name represented as a */
264 /* literal C-String, including the terminating NULL at the end. */
265 
266 #define kDNSServiceMaxServiceName 64
267 
268 /* Maximum length, in bytes, of a domain name represented as an *escaped* C-String */
269 /* including the final trailing dot, and the C-String terminating NULL at the end. */
270 
271 #define kDNSServiceMaxDomainName 1005
272 
273 /*
274  * Notes on DNS Name Escaping
275  *   -- or --
276  * "Why is kDNSServiceMaxDomainName 1005, when the maximum legal domain name is 255 bytes?"
277  *
278  * All strings used in DNS-SD are UTF-8 strings.
279  * With few exceptions, most are also escaped using standard DNS escaping rules:
280  *
281  *   '\\' represents a single literal '\' in the name
282  *   '\.' represents a single literal '.' in the name
283  *   '\ddd', where ddd is a three-digit decimal value from 000 to 255,
284  *        represents a single literal byte with that value.
285  *   A bare unescaped '.' is a label separator, marking a boundary between domain and subdomain.
286  *
287  * The exceptions, that do not use escaping, are the routines where the full
288  * DNS name of a resource is broken, for convenience, into servicename/regtype/domain.
289  * In these routines, the "servicename" is NOT escaped. It does not need to be, since
290  * it is, by definition, just a single literal string. Any characters in that string
291  * represent exactly what they are. The "regtype" portion is, technically speaking,
292  * escaped, but since legal regtypes are only allowed to contain letters, digits,
293  * and hyphens, there is nothing to escape, so the issue is moot. The "domain"
294  * portion is also escaped, though most domains in use on the public Internet
295  * today, like regtypes, don't contain any characters that need to be escaped.
296  * As DNS-SD becomes more popular, rich-text domains for service discovery will
297  * become common, so software should be written to cope with domains with escaping.
298  *
299  * The servicename may be up to 63 bytes of UTF-8 text (not counting the C-String
300  * terminating NULL at the end). The regtype is of the form _service._tcp or
301  * _service._udp, where the "service" part is 1-14 characters, which may be
302  * letters, digits, or hyphens. The domain part of the three-part name may be
303  * any legal domain, providing that the resulting servicename+regtype+domain
304  * name does not exceed 255 bytes.
305  *
306  * For most software, these issues are transparent. When browsing, the discovered
307  * servicenames should simply be displayed as-is. When resolving, the discovered
308  * servicename/regtype/domain are simply passed unchanged to DNSServiceResolve().
309  * When a DNSServiceResolve() succeeds, the returned fullname is already in
310  * the correct format to pass to standard system DNS APIs such as res_query().
311  * For converting from servicename/regtype/domain to a single properly-escaped
312  * full DNS name, the helper function DNSServiceConstructFullName() is provided.
313  *
314  * The following (highly contrived) example illustrates the escaping process.
315  * Suppose you have an service called "Dr. Smith\Dr. Johnson", of type "_ftp._tcp"
316  * in subdomain "4th. Floor" of subdomain "Building 2" of domain "apple.com."
317  * The full (escaped) DNS name of this service's SRV record would be:
318  * Dr\.\032Smith\\Dr\.\032Johnson._ftp._tcp.4th\.\032Floor.Building\0322.apple.com.
319  */
320 
321 
322 /*
323  * Constants for specifying an interface index
324  *
325  * Specific interface indexes are identified via a 32-bit unsigned integer returned
326  * by the if_nametoindex() family of calls.
327  *
328  * If the client passes 0 for interface index, that means "do the right thing",
329  * which (at present) means, "if the name is in an mDNS local multicast domain
330  * (e.g. 'local.', '254.169.in-addr.arpa.', '{8,9,A,B}.E.F.ip6.arpa.') then multicast
331  * on all applicable interfaces, otherwise send via unicast to the appropriate
332  * DNS server." Normally, most clients will use 0 for interface index to
333  * automatically get the default sensible behaviour.
334  *
335  * If the client passes a positive interface index, then for multicast names that
336  * indicates to do the operation only on that one interface. For unicast names the
337  * interface index is ignored unless kDNSServiceFlagsForceMulticast is also set.
338  *
339  * If the client passes kDNSServiceInterfaceIndexLocalOnly when registering
340  * a service, then that service will be found *only* by other local clients
341  * on the same machine that are browsing using kDNSServiceInterfaceIndexLocalOnly
342  * or kDNSServiceInterfaceIndexAny.
343  * If a client has a 'private' service, accessible only to other processes
344  * running on the same machine, this allows the client to advertise that service
345  * in a way such that it does not inadvertently appear in service lists on
346  * all the other machines on the network.
347  *
348  * If the client passes kDNSServiceInterfaceIndexLocalOnly when browsing
349  * then it will find *all* records registered on that same local machine.
350  * Clients explicitly wishing to discover *only* LocalOnly services can
351  * accomplish this by inspecting the interfaceIndex of each service reported
352  * to their DNSServiceBrowseReply() callback function, and discarding those
353  * where the interface index is not kDNSServiceInterfaceIndexLocalOnly.
354  */
355 
356 #define kDNSServiceInterfaceIndexAny 0
357 #define kDNSServiceInterfaceIndexLocalOnly ( (uint32_t) -1 )
358 
359 
360 typedef uint32_t DNSServiceFlags;
361 typedef int32_t DNSServiceErrorType;
362 
363 
364 /*********************************************************************************************
365  *
366  * Unix Domain Socket access, DNSServiceRef deallocation, and data processing functions
367  *
368  *********************************************************************************************/
369 
370 
371 /* DNSServiceRefSockFD()
372  *
373  * Access underlying Unix domain socket for an initialized DNSServiceRef.
374  * The DNS Service Discovery implmementation uses this socket to communicate between
375  * the client and the mDNSResponder daemon.  The application MUST NOT directly read from
376  * or write to this socket.  Access to the socket is provided so that it can be used as a
377  * run loop source, or in a select() loop: when data is available for reading on the socket,
378  * DNSServiceProcessResult() should be called, which will extract the daemon's reply from
379  * the socket, and pass it to the appropriate application callback.  By using a run loop or
380  * select(), results from the daemon can be processed asynchronously.  Without using these
381  * constructs, DNSServiceProcessResult() will block until the response from the daemon arrives.
382  * The client is responsible for ensuring that the data on the socket is processed in a timely
383  * fashion - the daemon may terminate its connection with a client that does not clear its
384  * socket buffer.
385  *
386  * sdRef:            A DNSServiceRef initialized by any of the DNSService calls.
387  *
388  * return value:    The DNSServiceRef's underlying socket descriptor, or -1 on
389  *                  error.
390  */
391 
392 int DNSSD_API DNSServiceRefSockFD(DNSServiceRef sdRef);
393 
394 
395 /* DNSServiceProcessResult()
396  *
397  * Read a reply from the daemon, calling the appropriate application callback.  This call will
398  * block until the daemon's response is received.  Use DNSServiceRefSockFD() in
399  * conjunction with a run loop or select() to determine the presence of a response from the
400  * server before calling this function to process the reply without blocking.  Call this function
401  * at any point if it is acceptable to block until the daemon's response arrives.  Note that the
402  * client is responsible for ensuring that DNSServiceProcessResult() is called whenever there is
403  * a reply from the daemon - the daemon may terminate its connection with a client that does not
404  * process the daemon's responses.
405  *
406  * sdRef:           A DNSServiceRef initialized by any of the DNSService calls
407  *                  that take a callback parameter.
408  *
409  * return value:    Returns kDNSServiceErr_NoError on success, otherwise returns
410  *                  an error code indicating the specific failure that occurred.
411  */
412 
413 DNSServiceErrorType DNSSD_API DNSServiceProcessResult(DNSServiceRef sdRef);
414 
415 
416 /* DNSServiceRefDeallocate()
417  *
418  * Terminate a connection with the daemon and free memory associated with the DNSServiceRef.
419  * Any services or records registered with this DNSServiceRef will be deregistered. Any
420  * Browse, Resolve, or Query operations called with this reference will be terminated.
421  *
422  * Note: If the reference's underlying socket is used in a run loop or select() call, it should
423  * be removed BEFORE DNSServiceRefDeallocate() is called, as this function closes the reference's
424  * socket.
425  *
426  * Note: If the reference was initialized with DNSServiceCreateConnection(), any DNSRecordRefs
427  * created via this reference will be invalidated by this call - the resource records are
428  * deregistered, and their DNSRecordRefs may not be used in subsequent functions.  Similarly,
429  * if the reference was initialized with DNSServiceRegister, and an extra resource record was
430  * added to the service via DNSServiceAddRecord(), the DNSRecordRef created by the Add() call
431  * is invalidated when this function is called - the DNSRecordRef may not be used in subsequent
432  * functions.
433  *
434  * Note: This call is to be used only with the DNSServiceRef defined by this API.  It is
435  * not compatible with dns_service_discovery_ref objects defined in the legacy Mach-based
436  * DNSServiceDiscovery.h API.
437  *
438  * sdRef:           A DNSServiceRef initialized by any of the DNSService calls.
439  *
440  */
441 
442 void DNSSD_API DNSServiceRefDeallocate(DNSServiceRef sdRef);
443 
444 
445 /*********************************************************************************************
446  *
447  * Domain Enumeration
448  *
449  *********************************************************************************************/
450 
451 /* DNSServiceEnumerateDomains()
452  *
453  * Asynchronously enumerate domains available for browsing and registration.
454  *
455  * The enumeration MUST be cancelled via DNSServiceRefDeallocate() when no more domains
456  * are to be found.
457  *
458  * Note that the names returned are (like all of DNS-SD) UTF-8 strings,
459  * and are escaped using standard DNS escaping rules.
460  * (See "Notes on DNS Name Escaping" earlier in this file for more details.)
461  * A graphical browser displaying a hierarchical tree-structured view should cut
462  * the names at the bare dots to yield individual labels, then de-escape each
463  * label according to the escaping rules, and then display the resulting UTF-8 text.
464  *
465  * DNSServiceDomainEnumReply Callback Parameters:
466  *
467  * sdRef:           The DNSServiceRef initialized by DNSServiceEnumerateDomains().
468  *
469  * flags:           Possible values are:
470  *                  kDNSServiceFlagsMoreComing
471  *                  kDNSServiceFlagsAdd
472  *                  kDNSServiceFlagsDefault
473  *
474  * interfaceIndex:  Specifies the interface on which the domain exists.  (The index for a given
475  *                  interface is determined via the if_nametoindex() family of calls.)
476  *
477  * errorCode:       Will be kDNSServiceErr_NoError (0) on success, otherwise indicates
478  *                  the failure that occurred (other parameters are undefined if errorCode is nonzero).
479  *
480  * replyDomain:     The name of the domain.
481  *
482  * context:         The context pointer passed to DNSServiceEnumerateDomains.
483  *
484  */
485 
486 typedef void (DNSSD_API *DNSServiceDomainEnumReply)
487     (
488     DNSServiceRef                       sdRef,
489     DNSServiceFlags                     flags,
490     uint32_t                            interfaceIndex,
491     DNSServiceErrorType                 errorCode,
492     const char                          *replyDomain,
493     void                                *context
494     );
495 
496 
497 /* DNSServiceEnumerateDomains() Parameters:
498  *
499  *
500  * sdRef:           A pointer to an uninitialized DNSServiceRef. If the call succeeds
501  *                  then it initializes the DNSServiceRef, returns kDNSServiceErr_NoError,
502  *                  and the enumeration operation will run indefinitely until the client
503  *                  terminates it by passing this DNSServiceRef to DNSServiceRefDeallocate().
504  *
505  * flags:           Possible values are:
506  *                  kDNSServiceFlagsBrowseDomains to enumerate domains recommended for browsing.
507  *                  kDNSServiceFlagsRegistrationDomains to enumerate domains recommended
508  *                  for registration.
509  *
510  * interfaceIndex:  If non-zero, specifies the interface on which to look for domains.
511  *                  (the index for a given interface is determined via the if_nametoindex()
512  *                  family of calls.)  Most applications will pass 0 to enumerate domains on
513  *                  all interfaces. See "Constants for specifying an interface index" for more details.
514  *
515  * callBack:        The function to be called when a domain is found or the call asynchronously
516  *                  fails.
517  *
518  * context:         An application context pointer which is passed to the callback function
519  *                  (may be NULL).
520  *
521  * return value:    Returns kDNSServiceErr_NoError on succeses (any subsequent, asynchronous
522  *                  errors are delivered to the callback), otherwise returns an error code indicating
523  *                  the error that occurred (the callback is not invoked and the DNSServiceRef
524  *                  is not initialized.)
525  */
526 
527 DNSServiceErrorType DNSSD_API DNSServiceEnumerateDomains
528     (
529     DNSServiceRef                       *sdRef,
530     DNSServiceFlags                     flags,
531     uint32_t                            interfaceIndex,
532     DNSServiceDomainEnumReply           callBack,
533     void                                *context  /* may be NULL */
534     );
535 
536 
537 /*********************************************************************************************
538  *
539  *  Service Registration
540  *
541  *********************************************************************************************/
542 
543 /* Register a service that is discovered via Browse() and Resolve() calls.
544  *
545  *
546  * DNSServiceRegisterReply() Callback Parameters:
547  *
548  * sdRef:           The DNSServiceRef initialized by DNSServiceRegister().
549  *
550  * flags:           Currently unused, reserved for future use.
551  *
552  * errorCode:       Will be kDNSServiceErr_NoError on success, otherwise will
553  *                  indicate the failure that occurred (including name conflicts,
554  *                  if the kDNSServiceFlagsNoAutoRename flag was used when registering.)
555  *                  Other parameters are undefined if errorCode is nonzero.
556  *
557  * name:            The service name registered (if the application did not specify a name in
558  *                  DNSServiceRegister(), this indicates what name was automatically chosen).
559  *
560  * regtype:         The type of service registered, as it was passed to the callout.
561  *
562  * domain:          The domain on which the service was registered (if the application did not
563  *                  specify a domain in DNSServiceRegister(), this indicates the default domain
564  *                  on which the service was registered).
565  *
566  * context:         The context pointer that was passed to the callout.
567  *
568  */
569 
570 typedef void (DNSSD_API *DNSServiceRegisterReply)
571     (
572     DNSServiceRef                       sdRef,
573     DNSServiceFlags                     flags,
574     DNSServiceErrorType                 errorCode,
575     const char                          *name,
576     const char                          *regtype,
577     const char                          *domain,
578     void                                *context
579     );
580 
581 
582 /* DNSServiceRegister()  Parameters:
583  *
584  * sdRef:           A pointer to an uninitialized DNSServiceRef. If the call succeeds
585  *                  then it initializes the DNSServiceRef, returns kDNSServiceErr_NoError,
586  *                  and the registration will remain active indefinitely until the client
587  *                  terminates it by passing this DNSServiceRef to DNSServiceRefDeallocate().
588  *
589  * interfaceIndex:  If non-zero, specifies the interface on which to register the service
590  *                  (the index for a given interface is determined via the if_nametoindex()
591  *                  family of calls.)  Most applications will pass 0 to register on all
592  *                  available interfaces. See "Constants for specifying an interface index" for more details.
593  *
594  * flags:           Indicates the renaming behavior on name conflict (most applications
595  *                  will pass 0).  See flag definitions above for details.
596  *
597  * name:            If non-NULL, specifies the service name to be registered.
598  *                  Most applications will not specify a name, in which case the computer
599  *                  name is used (this name is communicated to the client via the callback).
600  *                  If a name is specified, it must be 1-63 bytes of UTF-8 text.
601  *                  If the name is longer than 63 bytes it will be automatically truncated
602  *                  to a legal length, unless the NoAutoRename flag is set,
603  *                  in which case kDNSServiceErr_BadParam will be returned.
604  *
605  * regtype:         The service type followed by the protocol, separated by a dot
606  *                  (e.g. "_ftp._tcp"). The service type must be an underscore, followed
607  *                  by 1-14 characters, which may be letters, digits, or hyphens.
608  *                  The transport protocol must be "_tcp" or "_udp". New service types
609  *                  should be registered at <http://www.dns-sd.org/ServiceTypes.html>.
610  *
611  * domain:          If non-NULL, specifies the domain on which to advertise the service.
612  *                  Most applications will not specify a domain, instead automatically
613  *                  registering in the default domain(s).
614  *
615  * host:            If non-NULL, specifies the SRV target host name.  Most applications
616  *                  will not specify a host, instead automatically using the machine's
617  *                  default host name(s).  Note that specifying a non-NULL host does NOT
618  *                  create an address record for that host - the application is responsible
619  *                  for ensuring that the appropriate address record exists, or creating it
620  *                  via DNSServiceRegisterRecord().
621  *
622  * port:            The port, in network byte order, on which the service accepts connections.
623  *                  Pass 0 for a "placeholder" service (i.e. a service that will not be discovered
624  *                  by browsing, but will cause a name conflict if another client tries to
625  *                  register that same name).  Most clients will not use placeholder services.
626  *
627  * txtLen:          The length of the txtRecord, in bytes.  Must be zero if the txtRecord is NULL.
628  *
629  * txtRecord:       The TXT record rdata. A non-NULL txtRecord MUST be a properly formatted DNS
630  *                  TXT record, i.e. <length byte> <data> <length byte> <data> ...
631  *                  Passing NULL for the txtRecord is allowed as a synonym for txtLen=1, txtRecord="",
632  *                  i.e. it creates a TXT record of length one containing a single empty string.
633  *                  RFC 1035 doesn't allow a TXT record to contain *zero* strings, so a single empty
634  *                  string is the smallest legal DNS TXT record.
635  *                  As with the other parameters, the DNSServiceRegister call copies the txtRecord
636  *                  data; e.g. if you allocated the storage for the txtRecord parameter with malloc()
637  *                  then you can safely free that memory right after the DNSServiceRegister call returns.
638  *
639  * callBack:        The function to be called when the registration completes or asynchronously
640  *                  fails.  The client MAY pass NULL for the callback -  The client will NOT be notified
641  *                  of the default values picked on its behalf, and the client will NOT be notified of any
642  *                  asynchronous errors (e.g. out of memory errors, etc.) that may prevent the registration
643  *                  of the service.  The client may NOT pass the NoAutoRename flag if the callback is NULL.
644  *                  The client may still deregister the service at any time via DNSServiceRefDeallocate().
645  *
646  * context:         An application context pointer which is passed to the callback function
647  *                  (may be NULL).
648  *
649  * return value:    Returns kDNSServiceErr_NoError on succeses (any subsequent, asynchronous
650  *                  errors are delivered to the callback), otherwise returns an error code indicating
651  *                  the error that occurred (the callback is never invoked and the DNSServiceRef
652  *                  is not initialized.)
653  */
654 
655 DNSServiceErrorType DNSSD_API DNSServiceRegister
656     (
657     DNSServiceRef                       *sdRef,
658     DNSServiceFlags                     flags,
659     uint32_t                            interfaceIndex,
660     const char                          *name,         /* may be NULL */
661     const char                          *regtype,
662     const char                          *domain,       /* may be NULL */
663     const char                          *host,         /* may be NULL */
664     uint16_t                            port,
665     uint16_t                            txtLen,
666     const void                          *txtRecord,    /* may be NULL */
667     DNSServiceRegisterReply             callBack,      /* may be NULL */
668     void                                *context       /* may be NULL */
669     );
670 
671 
672 /* DNSServiceAddRecord()
673  *
674  * Add a record to a registered service.  The name of the record will be the same as the
675  * registered service's name.
676  * The record can later be updated or deregistered by passing the RecordRef initialized
677  * by this function to DNSServiceUpdateRecord() or DNSServiceRemoveRecord().
678  *
679  * Note that the DNSServiceAddRecord/UpdateRecord/RemoveRecord are *NOT* thread-safe
680  * with respect to a single DNSServiceRef. If you plan to have multiple threads
681  * in your program simultaneously add, update, or remove records from the same
682  * DNSServiceRef, then it's the caller's responsibility to use a mutext lock
683  * or take similar appropriate precautions to serialize those calls.
684  *
685  *
686  * Parameters;
687  *
688  * sdRef:           A DNSServiceRef initialized by DNSServiceRegister().
689  *
690  * RecordRef:       A pointer to an uninitialized DNSRecordRef.  Upon succesfull completion of this
691  *                  call, this ref may be passed to DNSServiceUpdateRecord() or DNSServiceRemoveRecord().
692  *                  If the above DNSServiceRef is passed to DNSServiceRefDeallocate(), RecordRef is also
693  *                  invalidated and may not be used further.
694  *
695  * flags:           Currently ignored, reserved for future use.
696  *
697  * rrtype:          The type of the record (e.g. kDNSServiceType_TXT, kDNSServiceType_SRV, etc)
698  *
699  * rdlen:           The length, in bytes, of the rdata.
700  *
701  * rdata:           The raw rdata to be contained in the added resource record.
702  *
703  * ttl:             The time to live of the resource record, in seconds.  Pass 0 to use a default value.
704  *
705  * return value:    Returns kDNSServiceErr_NoError on success, otherwise returns an
706  *                  error code indicating the error that occurred (the RecordRef is not initialized).
707  */
708 
709 DNSServiceErrorType DNSSD_API DNSServiceAddRecord
710     (
711     DNSServiceRef                       sdRef,
712     DNSRecordRef                        *RecordRef,
713     DNSServiceFlags                     flags,
714     uint16_t                            rrtype,
715     uint16_t                            rdlen,
716     const void                          *rdata,
717     uint32_t                            ttl
718     );
719 
720 
721 /* DNSServiceUpdateRecord
722  *
723  * Update a registered resource record.  The record must either be:
724  *   - The primary txt record of a service registered via DNSServiceRegister()
725  *   - A record added to a registered service via DNSServiceAddRecord()
726  *   - An individual record registered by DNSServiceRegisterRecord()
727  *
728  *
729  * Parameters:
730  *
731  * sdRef:           A DNSServiceRef that was initialized by DNSServiceRegister()
732  *                  or DNSServiceCreateConnection().
733  *
734  * RecordRef:       A DNSRecordRef initialized by DNSServiceAddRecord, or NULL to update the
735  *                  service's primary txt record.
736  *
737  * flags:           Currently ignored, reserved for future use.
738  *
739  * rdlen:           The length, in bytes, of the new rdata.
740  *
741  * rdata:           The new rdata to be contained in the updated resource record.
742  *
743  * ttl:             The time to live of the updated resource record, in seconds.
744  *
745  * return value:    Returns kDNSServiceErr_NoError on success, otherwise returns an
746  *                  error code indicating the error that occurred.
747  */
748 
749 DNSServiceErrorType DNSSD_API DNSServiceUpdateRecord
750     (
751     DNSServiceRef                       sdRef,
752     DNSRecordRef                        RecordRef,     /* may be NULL */
753     DNSServiceFlags                     flags,
754     uint16_t                            rdlen,
755     const void                          *rdata,
756     uint32_t                            ttl
757     );
758 
759 
760 /* DNSServiceRemoveRecord
761  *
762  * Remove a record previously added to a service record set via DNSServiceAddRecord(), or deregister
763  * an record registered individually via DNSServiceRegisterRecord().
764  *
765  * Parameters:
766  *
767  * sdRef:           A DNSServiceRef initialized by DNSServiceRegister() (if the
768  *                  record being removed was registered via DNSServiceAddRecord()) or by
769  *                  DNSServiceCreateConnection() (if the record being removed was registered via
770  *                  DNSServiceRegisterRecord()).
771  *
772  * recordRef:       A DNSRecordRef initialized by a successful call to DNSServiceAddRecord()
773  *                  or DNSServiceRegisterRecord().
774  *
775  * flags:           Currently ignored, reserved for future use.
776  *
777  * return value:    Returns kDNSServiceErr_NoError on success, otherwise returns an
778  *                  error code indicating the error that occurred.
779  */
780 
781 DNSServiceErrorType DNSSD_API DNSServiceRemoveRecord
782     (
783     DNSServiceRef                 sdRef,
784     DNSRecordRef                  RecordRef,
785     DNSServiceFlags               flags
786     );
787 
788 
789 /*********************************************************************************************
790  *
791  *  Service Discovery
792  *
793  *********************************************************************************************/
794 
795 /* Browse for instances of a service.
796  *
797  *
798  * DNSServiceBrowseReply() Parameters:
799  *
800  * sdRef:           The DNSServiceRef initialized by DNSServiceBrowse().
801  *
802  * flags:           Possible values are kDNSServiceFlagsMoreComing and kDNSServiceFlagsAdd.
803  *                  See flag definitions for details.
804  *
805  * interfaceIndex:  The interface on which the service is advertised.  This index should
806  *                  be passed to DNSServiceResolve() when resolving the service.
807  *
808  * errorCode:       Will be kDNSServiceErr_NoError (0) on success, otherwise will
809  *                  indicate the failure that occurred.  Other parameters are undefined if
810  *                  the errorCode is nonzero.
811  *
812  * serviceName:     The discovered service name. This name should be displayed to the user,
813  *                  and stored for subsequent use in the DNSServiceResolve() call.
814  *
815  * regtype:         The service type, which is usually (but not always) the same as was passed
816  *                  to DNSServiceBrowse(). One case where the discovered service type may
817  *                  not be the same as the requested service type is when using subtypes:
818  *                  The client may want to browse for only those ftp servers that allow
819  *                  anonymous connections. The client will pass the string "_ftp._tcp,_anon"
820  *                  to DNSServiceBrowse(), but the type of the service that's discovered
821  *                  is simply "_ftp._tcp". The regtype for each discovered service instance
822  *                  should be stored along with the name, so that it can be passed to
823  *                  DNSServiceResolve() when the service is later resolved.
824  *
825  * domain:          The domain of the discovered service instance. This may or may not be the
826  *                  same as the domain that was passed to DNSServiceBrowse(). The domain for each
827  *                  discovered service instance should be stored along with the name, so that
828  *                  it can be passed to DNSServiceResolve() when the service is later resolved.
829  *
830  * context:         The context pointer that was passed to the callout.
831  *
832  */
833 
834 typedef void (DNSSD_API *DNSServiceBrowseReply)
835     (
836     DNSServiceRef                       sdRef,
837     DNSServiceFlags                     flags,
838     uint32_t                            interfaceIndex,
839     DNSServiceErrorType                 errorCode,
840     const char                          *serviceName,
841     const char                          *regtype,
842     const char                          *replyDomain,
843     void                                *context
844     );
845 
846 
847 /* DNSServiceBrowse() Parameters:
848  *
849  * sdRef:           A pointer to an uninitialized DNSServiceRef. If the call succeeds
850  *                  then it initializes the DNSServiceRef, returns kDNSServiceErr_NoError,
851  *                  and the browse operation will run indefinitely until the client
852  *                  terminates it by passing this DNSServiceRef to DNSServiceRefDeallocate().
853  *
854  * flags:           Currently ignored, reserved for future use.
855  *
856  * interfaceIndex:  If non-zero, specifies the interface on which to browse for services
857  *                  (the index for a given interface is determined via the if_nametoindex()
858  *                  family of calls.)  Most applications will pass 0 to browse on all available
859  *                  interfaces. See "Constants for specifying an interface index" for more details.
860  *
861  * regtype:         The service type being browsed for followed by the protocol, separated by a
862  *                  dot (e.g. "_ftp._tcp").  The transport protocol must be "_tcp" or "_udp".
863  *
864  * domain:          If non-NULL, specifies the domain on which to browse for services.
865  *                  Most applications will not specify a domain, instead browsing on the
866  *                  default domain(s).
867  *
868  * callBack:        The function to be called when an instance of the service being browsed for
869  *                  is found, or if the call asynchronously fails.
870  *
871  * context:         An application context pointer which is passed to the callback function
872  *                  (may be NULL).
873  *
874  * return value:    Returns kDNSServiceErr_NoError on succeses (any subsequent, asynchronous
875  *                  errors are delivered to the callback), otherwise returns an error code indicating
876  *                  the error that occurred (the callback is not invoked and the DNSServiceRef
877  *                  is not initialized.)
878  */
879 
880 DNSServiceErrorType DNSSD_API DNSServiceBrowse
881     (
882     DNSServiceRef                       *sdRef,
883     DNSServiceFlags                     flags,
884     uint32_t                            interfaceIndex,
885     const char                          *regtype,
886     const char                          *domain,    /* may be NULL */
887     DNSServiceBrowseReply               callBack,
888     void                                *context    /* may be NULL */
889     );
890 
891 
892 /* DNSServiceResolve()
893  *
894  * Resolve a service name discovered via DNSServiceBrowse() to a target host name, port number, and
895  * txt record.
896  *
897  * Note: Applications should NOT use DNSServiceResolve() solely for txt record monitoring - use
898  * DNSServiceQueryRecord() instead, as it is more efficient for this task.
899  *
900  * Note: When the desired results have been returned, the client MUST terminate the resolve by calling
901  * DNSServiceRefDeallocate().
902  *
903  * Note: DNSServiceResolve() behaves correctly for typical services that have a single SRV record
904  * and a single TXT record. To resolve non-standard services with multiple SRV or TXT records,
905  * DNSServiceQueryRecord() should be used.
906  *
907  * DNSServiceResolveReply Callback Parameters:
908  *
909  * sdRef:           The DNSServiceRef initialized by DNSServiceResolve().
910  *
911  * flags:           Currently unused, reserved for future use.
912  *
913  * interfaceIndex:  The interface on which the service was resolved.
914  *
915  * errorCode:       Will be kDNSServiceErr_NoError (0) on success, otherwise will
916  *                  indicate the failure that occurred.  Other parameters are undefined if
917  *                  the errorCode is nonzero.
918  *
919  * fullname:        The full service domain name, in the form <servicename>.<protocol>.<domain>.
920  *                  (This name is escaped following standard DNS rules, making it suitable for
921  *                  passing to standard system DNS APIs such as res_query(), or to the
922  *                  special-purpose functions included in this API that take fullname parameters.
923  *                  See "Notes on DNS Name Escaping" earlier in this file for more details.)
924  *
925  * hosttarget:      The target hostname of the machine providing the service.  This name can
926  *                  be passed to functions like gethostbyname() to identify the host's IP address.
927  *
928  * port:            The port, in network byte order, on which connections are accepted for this service.
929  *
930  * txtLen:          The length of the txt record, in bytes.
931  *
932  * txtRecord:       The service's primary txt record, in standard txt record format.
933  *
934  * context:         The context pointer that was passed to the callout.
935  *
936  * NOTE: In earlier versions of this header file, the txtRecord parameter was declared "const char *"
937  * This is incorrect, since it contains length bytes which are values in the range 0 to 255, not -128 to +127.
938  * Depending on your compiler settings, this change may cause signed/unsigned mismatch warnings.
939  * These should be fixed by updating your own callback function definition to match the corrected
940  * function signature using "const unsigned char *txtRecord". Making this change may also fix inadvertent
941  * bugs in your callback function, where it could have incorrectly interpreted a length byte with value 250
942  * as being -6 instead, with various bad consequences ranging from incorrect operation to software crashes.
943  * If you need to maintain portable code that will compile cleanly with both the old and new versions of
944  * this header file, you should update your callback function definition to use the correct unsigned value,
945  * and then in the place where you pass your callback function to DNSServiceResolve(), use a cast to eliminate
946  * the compiler warning, e.g.:
947  *   DNSServiceResolve(sd, flags, index, name, regtype, domain, (DNSServiceResolveReply)MyCallback, context);
948  * This will ensure that your code compiles cleanly without warnings (and more importantly, works correctly)
949  * with both the old header and with the new corrected version.
950  *
951  */
952 
953 typedef void (DNSSD_API *DNSServiceResolveReply)
954     (
955     DNSServiceRef                       sdRef,
956     DNSServiceFlags                     flags,
957     uint32_t                            interfaceIndex,
958     DNSServiceErrorType                 errorCode,
959     const char                          *fullname,
960     const char                          *hosttarget,
961     uint16_t                            port,
962     uint16_t                            txtLen,
963     const unsigned char                 *txtRecord,
964     void                                *context
965     );
966 
967 
968 /* DNSServiceResolve() Parameters
969  *
970  * sdRef:           A pointer to an uninitialized DNSServiceRef. If the call succeeds
971  *                  then it initializes the DNSServiceRef, returns kDNSServiceErr_NoError,
972  *                  and the resolve operation will run indefinitely until the client
973  *                  terminates it by passing this DNSServiceRef to DNSServiceRefDeallocate().
974  *
975  * flags:           Currently ignored, reserved for future use.
976  *
977  * interfaceIndex:  The interface on which to resolve the service. If this resolve call is
978  *                  as a result of a currently active DNSServiceBrowse() operation, then the
979  *                  interfaceIndex should be the index reported in the DNSServiceBrowseReply
980  *                  callback. If this resolve call is using information previously saved
981  *                  (e.g. in a preference file) for later use, then use interfaceIndex 0, because
982  *                  the desired service may now be reachable via a different physical interface.
983  *                  See "Constants for specifying an interface index" for more details.
984  *
985  * name:            The name of the service instance to be resolved, as reported to the
986  *                  DNSServiceBrowseReply() callback.
987  *
988  * regtype:         The type of the service instance to be resolved, as reported to the
989  *                  DNSServiceBrowseReply() callback.
990  *
991  * domain:          The domain of the service instance to be resolved, as reported to the
992  *                  DNSServiceBrowseReply() callback.
993  *
994  * callBack:        The function to be called when a result is found, or if the call
995  *                  asynchronously fails.
996  *
997  * context:         An application context pointer which is passed to the callback function
998  *                  (may be NULL).
999  *
1000  * return value:    Returns kDNSServiceErr_NoError on succeses (any subsequent, asynchronous
1001  *                  errors are delivered to the callback), otherwise returns an error code indicating
1002  *                  the error that occurred (the callback is never invoked and the DNSServiceRef
1003  *                  is not initialized.)
1004  */
1005 
1006 DNSServiceErrorType DNSSD_API DNSServiceResolve
1007     (
1008     DNSServiceRef                       *sdRef,
1009     DNSServiceFlags                     flags,
1010     uint32_t                            interfaceIndex,
1011     const char                          *name,
1012     const char                          *regtype,
1013     const char                          *domain,
1014     DNSServiceResolveReply              callBack,
1015     void                                *context  /* may be NULL */
1016     );
1017 
1018 
1019 /*********************************************************************************************
1020  *
1021  *  Special Purpose Calls (most applications will not use these)
1022  *
1023  *********************************************************************************************/
1024 
1025 /* DNSServiceCreateConnection()
1026  *
1027  * Create a connection to the daemon allowing efficient registration of
1028  * multiple individual records.
1029  *
1030  *
1031  * Parameters:
1032  *
1033  * sdRef:           A pointer to an uninitialized DNSServiceRef.  Deallocating
1034  *                  the reference (via DNSServiceRefDeallocate()) severs the
1035  *                  connection and deregisters all records registered on this connection.
1036  *
1037  * return value:    Returns kDNSServiceErr_NoError on success, otherwise returns
1038  *                  an error code indicating the specific failure that occurred (in which
1039  *                  case the DNSServiceRef is not initialized).
1040  */
1041 
1042 DNSServiceErrorType DNSSD_API DNSServiceCreateConnection(DNSServiceRef *sdRef);
1043 
1044 
1045 /* DNSServiceRegisterRecord
1046  *
1047  * Register an individual resource record on a connected DNSServiceRef.
1048  *
1049  * Note that name conflicts occurring for records registered via this call must be handled
1050  * by the client in the callback.
1051  *
1052  *
1053  * DNSServiceRegisterRecordReply() parameters:
1054  *
1055  * sdRef:           The connected DNSServiceRef initialized by
1056  *                  DNSServiceCreateConnection().
1057  *
1058  * RecordRef:       The DNSRecordRef initialized by DNSServiceRegisterRecord().  If the above
1059  *                  DNSServiceRef is passed to DNSServiceRefDeallocate(), this DNSRecordRef is
1060  *                  invalidated, and may not be used further.
1061  *
1062  * flags:           Currently unused, reserved for future use.
1063  *
1064  * errorCode:       Will be kDNSServiceErr_NoError on success, otherwise will
1065  *                  indicate the failure that occurred (including name conflicts.)
1066  *                  Other parameters are undefined if errorCode is nonzero.
1067  *
1068  * context:         The context pointer that was passed to the callout.
1069  *
1070  */
1071 
1072  typedef void (DNSSD_API *DNSServiceRegisterRecordReply)
1073     (
1074     DNSServiceRef                       sdRef,
1075     DNSRecordRef                        RecordRef,
1076     DNSServiceFlags                     flags,
1077     DNSServiceErrorType                 errorCode,
1078     void                                *context
1079     );
1080 
1081 
1082 /* DNSServiceRegisterRecord() Parameters:
1083  *
1084  * sdRef:           A DNSServiceRef initialized by DNSServiceCreateConnection().
1085  *
1086  * RecordRef:       A pointer to an uninitialized DNSRecordRef.  Upon succesfull completion of this
1087  *                  call, this ref may be passed to DNSServiceUpdateRecord() or DNSServiceRemoveRecord().
1088  *                  (To deregister ALL records registered on a single connected DNSServiceRef
1089  *                  and deallocate each of their corresponding DNSServiceRecordRefs, call
1090  *                  DNSServiceRefDealloocate()).
1091  *
1092  * flags:           Possible values are kDNSServiceFlagsShared or kDNSServiceFlagsUnique
1093  *                  (see flag type definitions for details).
1094  *
1095  * interfaceIndex:  If non-zero, specifies the interface on which to register the record
1096  *                  (the index for a given interface is determined via the if_nametoindex()
1097  *                  family of calls.)  Passing 0 causes the record to be registered on all interfaces.
1098  *                  See "Constants for specifying an interface index" for more details.
1099  *
1100  * fullname:        The full domain name of the resource record.
1101  *
1102  * rrtype:          The numerical type of the resource record (e.g. kDNSServiceType_PTR, kDNSServiceType_SRV, etc)
1103  *
1104  * rrclass:         The class of the resource record (usually kDNSServiceClass_IN)
1105  *
1106  * rdlen:           Length, in bytes, of the rdata.
1107  *
1108  * rdata:           A pointer to the raw rdata, as it is to appear in the DNS record.
1109  *
1110  * ttl:             The time to live of the resource record, in seconds.  Pass 0 to use a default value.
1111  *
1112  * callBack:        The function to be called when a result is found, or if the call
1113  *                  asynchronously fails (e.g. because of a name conflict.)
1114  *
1115  * context:         An application context pointer which is passed to the callback function
1116  *                  (may be NULL).
1117  *
1118  * return value:    Returns kDNSServiceErr_NoError on succeses (any subsequent, asynchronous
1119  *                  errors are delivered to the callback), otherwise returns an error code indicating
1120  *                  the error that occurred (the callback is never invoked and the DNSRecordRef is
1121  *                  not initialized.)
1122  */
1123 
1124 DNSServiceErrorType DNSSD_API DNSServiceRegisterRecord
1125     (
1126     DNSServiceRef                       sdRef,
1127     DNSRecordRef                        *RecordRef,
1128     DNSServiceFlags                     flags,
1129     uint32_t                            interfaceIndex,
1130     const char                          *fullname,
1131     uint16_t                            rrtype,
1132     uint16_t                            rrclass,
1133     uint16_t                            rdlen,
1134     const void                          *rdata,
1135     uint32_t                            ttl,
1136     DNSServiceRegisterRecordReply       callBack,
1137     void                                *context    /* may be NULL */
1138     );
1139 
1140 
1141 /* DNSServiceQueryRecord
1142  *
1143  * Query for an arbitrary DNS record.
1144  *
1145  *
1146  * DNSServiceQueryRecordReply() Callback Parameters:
1147  *
1148  * sdRef:           The DNSServiceRef initialized by DNSServiceQueryRecord().
1149  *
1150  * flags:           Possible values are kDNSServiceFlagsMoreComing and
1151  *                  kDNSServiceFlagsAdd.  The Add flag is NOT set for PTR records
1152  *                  with a ttl of 0, i.e. "Remove" events.
1153  *
1154  * interfaceIndex:  The interface on which the query was resolved (the index for a given
1155  *                  interface is determined via the if_nametoindex() family of calls).
1156  *                  See "Constants for specifying an interface index" for more details.
1157  *
1158  * errorCode:       Will be kDNSServiceErr_NoError on success, otherwise will
1159  *                  indicate the failure that occurred.  Other parameters are undefined if
1160  *                  errorCode is nonzero.
1161  *
1162  * fullname:        The resource record's full domain name.
1163  *
1164  * rrtype:          The resource record's type (e.g. kDNSServiceType_PTR, kDNSServiceType_SRV, etc)
1165  *
1166  * rrclass:         The class of the resource record (usually kDNSServiceClass_IN).
1167  *
1168  * rdlen:           The length, in bytes, of the resource record rdata.
1169  *
1170  * rdata:           The raw rdata of the resource record.
1171  *
1172  * ttl:             The resource record's time to live, in seconds.
1173  *
1174  * context:         The context pointer that was passed to the callout.
1175  *
1176  */
1177 
1178 typedef void (DNSSD_API *DNSServiceQueryRecordReply)
1179     (
1180     DNSServiceRef                       DNSServiceRef,
1181     DNSServiceFlags                     flags,
1182     uint32_t                            interfaceIndex,
1183     DNSServiceErrorType                 errorCode,
1184     const char                          *fullname,
1185     uint16_t                            rrtype,
1186     uint16_t                            rrclass,
1187     uint16_t                            rdlen,
1188     const void                          *rdata,
1189     uint32_t                            ttl,
1190     void                                *context
1191     );
1192 
1193 
1194 /* DNSServiceQueryRecord() Parameters:
1195  *
1196  * sdRef:           A pointer to an uninitialized DNSServiceRef. If the call succeeds
1197  *                  then it initializes the DNSServiceRef, returns kDNSServiceErr_NoError,
1198  *                  and the query operation will run indefinitely until the client
1199  *                  terminates it by passing this DNSServiceRef to DNSServiceRefDeallocate().
1200  *
1201  * flags:           Pass kDNSServiceFlagsLongLivedQuery to create a "long-lived" unicast
1202  *                  query in a non-local domain.  Without setting this flag, unicast queries
1203  *                  will be one-shot - that is, only answers available at the time of the call
1204  *                  will be returned.  By setting this flag, answers (including Add and Remove
1205  *                  events) that become available after the initial call is made will generate
1206  *                  callbacks.  This flag has no effect on link-local multicast queries.
1207  *
1208  * interfaceIndex:  If non-zero, specifies the interface on which to issue the query
1209  *                  (the index for a given interface is determined via the if_nametoindex()
1210  *                  family of calls.)  Passing 0 causes the name to be queried for on all
1211  *                  interfaces. See "Constants for specifying an interface index" for more details.
1212  *
1213  * fullname:        The full domain name of the resource record to be queried for.
1214  *
1215  * rrtype:          The numerical type of the resource record to be queried for
1216  *                  (e.g. kDNSServiceType_PTR, kDNSServiceType_SRV, etc)
1217  *
1218  * rrclass:         The class of the resource record (usually kDNSServiceClass_IN).
1219  *
1220  * callBack:        The function to be called when a result is found, or if the call
1221  *                  asynchronously fails.
1222  *
1223  * context:         An application context pointer which is passed to the callback function
1224  *                  (may be NULL).
1225  *
1226  * return value:    Returns kDNSServiceErr_NoError on succeses (any subsequent, asynchronous
1227  *                  errors are delivered to the callback), otherwise returns an error code indicating
1228  *                  the error that occurred (the callback is never invoked and the DNSServiceRef
1229  *                  is not initialized.)
1230  */
1231 
1232 DNSServiceErrorType DNSSD_API DNSServiceQueryRecord
1233     (
1234     DNSServiceRef                       *sdRef,
1235     DNSServiceFlags                     flags,
1236     uint32_t                            interfaceIndex,
1237     const char                          *fullname,
1238     uint16_t                            rrtype,
1239     uint16_t                            rrclass,
1240     DNSServiceQueryRecordReply          callBack,
1241     void                                *context  /* may be NULL */
1242     );
1243 
1244 
1245 /* DNSServiceReconfirmRecord
1246  *
1247  * Instruct the daemon to verify the validity of a resource record that appears to
1248  * be out of date (e.g. because tcp connection to a service's target failed.)
1249  * Causes the record to be flushed from the daemon's cache (as well as all other
1250  * daemons' caches on the network) if the record is determined to be invalid.
1251  *
1252  * Parameters:
1253  *
1254  * flags:           Currently unused, reserved for future use.
1255  *
1256  * interfaceIndex:  If non-zero, specifies the interface of the record in question.
1257  *                  Passing 0 causes all instances of this record to be reconfirmed.
1258  *
1259  * fullname:        The resource record's full domain name.
1260  *
1261  * rrtype:          The resource record's type (e.g. kDNSServiceType_PTR, kDNSServiceType_SRV, etc)
1262  *
1263  * rrclass:         The class of the resource record (usually kDNSServiceClass_IN).
1264  *
1265  * rdlen:           The length, in bytes, of the resource record rdata.
1266  *
1267  * rdata:           The raw rdata of the resource record.
1268  *
1269  */
1270 
1271 DNSServiceErrorType DNSSD_API DNSServiceReconfirmRecord
1272     (
1273     DNSServiceFlags                    flags,
1274     uint32_t                           interfaceIndex,
1275     const char                         *fullname,
1276     uint16_t                           rrtype,
1277     uint16_t                           rrclass,
1278     uint16_t                           rdlen,
1279     const void                         *rdata
1280     );
1281 
1282 
1283 /*********************************************************************************************
1284  *
1285  *  General Utility Functions
1286  *
1287  *********************************************************************************************/
1288 
1289 /* DNSServiceConstructFullName()
1290  *
1291  * Concatenate a three-part domain name (as returned by the above callbacks) into a
1292  * properly-escaped full domain name. Note that callbacks in the above functions ALREADY ESCAPE
1293  * strings where necessary.
1294  *
1295  * Parameters:
1296  *
1297  * fullName:        A pointer to a buffer that where the resulting full domain name is to be written.
1298  *                  The buffer must be kDNSServiceMaxDomainName (1005) bytes in length to
1299  *                  accommodate the longest legal domain name without buffer overrun.
1300  *
1301  * service:         The service name - any dots or backslashes must NOT be escaped.
1302  *                  May be NULL (to construct a PTR record name, e.g.
1303  *                  "_ftp._tcp.apple.com.").
1304  *
1305  * regtype:         The service type followed by the protocol, separated by a dot
1306  *                  (e.g. "_ftp._tcp").
1307  *
1308  * domain:          The domain name, e.g. "apple.com.".  Literal dots or backslashes,
1309  *                  if any, must be escaped, e.g. "1st\. Floor.apple.com."
1310  *
1311  * return value:    Returns 0 on success, -1 on error.
1312  *
1313  */
1314 
1315 int DNSSD_API DNSServiceConstructFullName
1316     (
1317     char                            *fullName,
1318     const char                      *service,      /* may be NULL */
1319     const char                      *regtype,
1320     const char                      *domain
1321     );
1322 
1323 
1324 /*********************************************************************************************
1325  *
1326  *   TXT Record Construction Functions
1327  *
1328  *********************************************************************************************/
1329 
1330 /*
1331  * A typical calling sequence for TXT record construction is something like:
1332  *
1333  * Client allocates storage for TXTRecord data (e.g. declare buffer on the stack)
1334  * TXTRecordCreate();
1335  * TXTRecordSetValue();
1336  * TXTRecordSetValue();
1337  * TXTRecordSetValue();
1338  * ...
1339  * DNSServiceRegister( ... TXTRecordGetLength(), TXTRecordGetBytesPtr() ... );
1340  * TXTRecordDeallocate();
1341  * Explicitly deallocate storage for TXTRecord data (if not allocated on the stack)
1342  */
1343 
1344 
1345 /* TXTRecordRef
1346  *
1347  * Opaque internal data type.
1348  * Note: Represents a DNS-SD TXT record.
1349  */
1350 
1351 typedef union _TXTRecordRef_t { char PrivateData[16]; char *ForceNaturalAlignment; } TXTRecordRef;
1352 
1353 
1354 /* TXTRecordCreate()
1355  *
1356  * Creates a new empty TXTRecordRef referencing the specified storage.
1357  *
1358  * If the buffer parameter is NULL, or the specified storage size is not
1359  * large enough to hold a key subsequently added using TXTRecordSetValue(),
1360  * then additional memory will be added as needed using malloc().
1361  *
1362  * On some platforms, when memory is low, malloc() may fail. In this
1363  * case, TXTRecordSetValue() will return kDNSServiceErr_NoMemory, and this
1364  * error condition will need to be handled as appropriate by the caller.
1365  *
1366  * You can avoid the need to handle this error condition if you ensure
1367  * that the storage you initially provide is large enough to hold all
1368  * the key/value pairs that are to be added to the record.
1369  * The caller can precompute the exact length required for all of the
1370  * key/value pairs to be added, or simply provide a fixed-sized buffer
1371  * known in advance to be large enough.
1372  * A no-value (key-only) key requires  (1 + key length) bytes.
1373  * A key with empty value requires     (1 + key length + 1) bytes.
1374  * A key with non-empty value requires (1 + key length + 1 + value length).
1375  * For most applications, DNS-SD TXT records are generally
1376  * less than 100 bytes, so in most cases a simple fixed-sized
1377  * 256-byte buffer will be more than sufficient.
1378  * Recommended size limits for DNS-SD TXT Records are discussed in
1379  * <http://files.dns-sd.org/draft-cheshire-dnsext-dns-sd.txt>
1380  *
1381  * Note: When passing parameters to and from these TXT record APIs,
1382  * the key name does not include the '=' character. The '=' character
1383  * is the separator between the key and value in the on-the-wire
1384  * packet format; it is not part of either the key or the value.
1385  *
1386  * txtRecord:       A pointer to an uninitialized TXTRecordRef.
1387  *
1388  * bufferLen:       The size of the storage provided in the "buffer" parameter.
1389  *
1390  * buffer:          Optional caller-supplied storage used to hold the TXTRecord data.
1391  *                  This storage must remain valid for as long as
1392  *                  the TXTRecordRef.
1393  */
1394 
1395 void DNSSD_API TXTRecordCreate
1396     (
1397     TXTRecordRef     *txtRecord,
1398     uint16_t         bufferLen,
1399     void             *buffer
1400     );
1401 
1402 
1403 /* TXTRecordDeallocate()
1404  *
1405  * Releases any resources allocated in the course of preparing a TXT Record
1406  * using TXTRecordCreate()/TXTRecordSetValue()/TXTRecordRemoveValue().
1407  * Ownership of the buffer provided in TXTRecordCreate() returns to the client.
1408  *
1409  * txtRecord:           A TXTRecordRef initialized by calling TXTRecordCreate().
1410  *
1411  */
1412 
1413 void DNSSD_API TXTRecordDeallocate
1414     (
1415     TXTRecordRef     *txtRecord
1416     );
1417 
1418 
1419 /* TXTRecordSetValue()
1420  *
1421  * Adds a key (optionally with value) to a TXTRecordRef. If the "key" already
1422  * exists in the TXTRecordRef, then the current value will be replaced with
1423  * the new value.
1424  * Keys may exist in four states with respect to a given TXT record:
1425  *  - Absent (key does not appear at all)
1426  *  - Present with no value ("key" appears alone)
1427  *  - Present with empty value ("key=" appears in TXT record)
1428  *  - Present with non-empty value ("key=value" appears in TXT record)
1429  * For more details refer to "Data Syntax for DNS-SD TXT Records" in
1430  * <http://files.dns-sd.org/draft-cheshire-dnsext-dns-sd.txt>
1431  *
1432  * txtRecord:       A TXTRecordRef initialized by calling TXTRecordCreate().
1433  *
1434  * key:             A null-terminated string which only contains printable ASCII
1435  *                  values (0x20-0x7E), excluding '=' (0x3D). Keys should be
1436  *                  8 characters or less (not counting the terminating null).
1437  *
1438  * valueSize:       The size of the value.
1439  *
1440  * value:           Any binary value. For values that represent
1441  *                  textual data, UTF-8 is STRONGLY recommended.
1442  *                  For values that represent textual data, valueSize
1443  *                  should NOT include the terminating null (if any)
1444  *                  at the end of the string.
1445  *                  If NULL, then "key" will be added with no value.
1446  *                  If non-NULL but valueSize is zero, then "key=" will be
1447  *                  added with empty value.
1448  *
1449  * return value:    Returns kDNSServiceErr_NoError on success.
1450  *                  Returns kDNSServiceErr_Invalid if the "key" string contains
1451  *                  illegal characters.
1452  *                  Returns kDNSServiceErr_NoMemory if adding this key would
1453  *                  exceed the available storage.
1454  */
1455 
1456 DNSServiceErrorType DNSSD_API TXTRecordSetValue
1457     (
1458     TXTRecordRef     *txtRecord,
1459     const char       *key,
1460     uint8_t          valueSize,        /* may be zero */
1461     const void       *value            /* may be NULL */
1462     );
1463 
1464 
1465 /* TXTRecordRemoveValue()
1466  *
1467  * Removes a key from a TXTRecordRef.  The "key" must be an
1468  * ASCII string which exists in the TXTRecordRef.
1469  *
1470  * txtRecord:       A TXTRecordRef initialized by calling TXTRecordCreate().
1471  *
1472  * key:             A key name which exists in the TXTRecordRef.
1473  *
1474  * return value:    Returns kDNSServiceErr_NoError on success.
1475  *                  Returns kDNSServiceErr_NoSuchKey if the "key" does not
1476  *                  exist in the TXTRecordRef.
1477  */
1478 
1479 DNSServiceErrorType DNSSD_API TXTRecordRemoveValue
1480     (
1481     TXTRecordRef     *txtRecord,
1482     const char       *key
1483     );
1484 
1485 
1486 /* TXTRecordGetLength()
1487  *
1488  * Allows you to determine the length of the raw bytes within a TXTRecordRef.
1489  *
1490  * txtRecord:       A TXTRecordRef initialized by calling TXTRecordCreate().
1491  *
1492  * return value:    Returns the size of the raw bytes inside a TXTRecordRef
1493  *                  which you can pass directly to DNSServiceRegister() or
1494  *                  to DNSServiceUpdateRecord().
1495  *                  Returns 0 if the TXTRecordRef is empty.
1496  */
1497 
1498 uint16_t DNSSD_API TXTRecordGetLength
1499     (
1500     const TXTRecordRef *txtRecord
1501     );
1502 
1503 
1504 /* TXTRecordGetBytesPtr()
1505  *
1506  * Allows you to retrieve a pointer to the raw bytes within a TXTRecordRef.
1507  *
1508  * txtRecord:       A TXTRecordRef initialized by calling TXTRecordCreate().
1509  *
1510  * return value:    Returns a pointer to the raw bytes inside the TXTRecordRef
1511  *                  which you can pass directly to DNSServiceRegister() or
1512  *                  to DNSServiceUpdateRecord().
1513  */
1514 
1515 const void * DNSSD_API TXTRecordGetBytesPtr
1516     (
1517     const TXTRecordRef *txtRecord
1518     );
1519 
1520 
1521 /*********************************************************************************************
1522  *
1523  *   TXT Record Parsing Functions
1524  *
1525  *********************************************************************************************/
1526 
1527 /*
1528  * A typical calling sequence for TXT record parsing is something like:
1529  *
1530  * Receive TXT record data in DNSServiceResolve() callback
1531  * if (TXTRecordContainsKey(txtLen, txtRecord, "key")) then do something
1532  * val1ptr = TXTRecordGetValuePtr(txtLen, txtRecord, "key1", &len1);
1533  * val2ptr = TXTRecordGetValuePtr(txtLen, txtRecord, "key2", &len2);
1534  * ...
1535  * bcopy(val1ptr, myval1, len1);
1536  * bcopy(val2ptr, myval2, len2);
1537  * ...
1538  * return;
1539  *
1540  * If you wish to retain the values after return from the DNSServiceResolve()
1541  * callback, then you need to copy the data to your own storage using bcopy()
1542  * or similar, as shown in the example above.
1543  *
1544  * If for some reason you need to parse a TXT record you built yourself
1545  * using the TXT record construction functions above, then you can do
1546  * that using TXTRecordGetLength and TXTRecordGetBytesPtr calls:
1547  * TXTRecordGetValue(TXTRecordGetLength(x), TXTRecordGetBytesPtr(x), key, &len);
1548  *
1549  * Most applications only fetch keys they know about from a TXT record and
1550  * ignore the rest.
1551  * However, some debugging tools wish to fetch and display all keys.
1552  * To do that, use the TXTRecordGetCount() and TXTRecordGetItemAtIndex() calls.
1553  */
1554 
1555 /* TXTRecordContainsKey()
1556  *
1557  * Allows you to determine if a given TXT Record contains a specified key.
1558  *
1559  * txtLen:          The size of the received TXT Record.
1560  *
1561  * txtRecord:       Pointer to the received TXT Record bytes.
1562  *
1563  * key:             A null-terminated ASCII string containing the key name.
1564  *
1565  * return value:    Returns 1 if the TXT Record contains the specified key.
1566  *                  Otherwise, it returns 0.
1567  */
1568 
1569 int DNSSD_API TXTRecordContainsKey
1570     (
1571     uint16_t         txtLen,
1572     const void       *txtRecord,
1573     const char       *key
1574     );
1575 
1576 
1577 /* TXTRecordGetValuePtr()
1578  *
1579  * Allows you to retrieve the value for a given key from a TXT Record.
1580  *
1581  * txtLen:          The size of the received TXT Record
1582  *
1583  * txtRecord:       Pointer to the received TXT Record bytes.
1584  *
1585  * key:             A null-terminated ASCII string containing the key name.
1586  *
1587  * valueLen:        On output, will be set to the size of the "value" data.
1588  *
1589  * return value:    Returns NULL if the key does not exist in this TXT record,
1590  *                  or exists with no value (to differentiate between
1591  *                  these two cases use TXTRecordContainsKey()).
1592  *                  Returns pointer to location within TXT Record bytes
1593  *                  if the key exists with empty or non-empty value.
1594  *                  For empty value, valueLen will be zero.
1595  *                  For non-empty value, valueLen will be length of value data.
1596  */
1597 
1598 const void * DNSSD_API TXTRecordGetValuePtr
1599     (
1600     uint16_t         txtLen,
1601     const void       *txtRecord,
1602     const char       *key,
1603     uint8_t          *valueLen
1604     );
1605 
1606 
1607 /* TXTRecordGetCount()
1608  *
1609  * Returns the number of keys stored in the TXT Record.  The count
1610  * can be used with TXTRecordGetItemAtIndex() to iterate through the keys.
1611  *
1612  * txtLen:          The size of the received TXT Record.
1613  *
1614  * txtRecord:       Pointer to the received TXT Record bytes.
1615  *
1616  * return value:    Returns the total number of keys in the TXT Record.
1617  *
1618  */
1619 
1620 uint16_t DNSSD_API TXTRecordGetCount
1621     (
1622     uint16_t         txtLen,
1623     const void       *txtRecord
1624     );
1625 
1626 
1627 /* TXTRecordGetItemAtIndex()
1628  *
1629  * Allows you to retrieve a key name and value pointer, given an index into
1630  * a TXT Record.  Legal index values range from zero to TXTRecordGetCount()-1.
1631  * It's also possible to iterate through keys in a TXT record by simply
1632  * calling TXTRecordGetItemAtIndex() repeatedly, beginning with index zero
1633  * and increasing until TXTRecordGetItemAtIndex() returns kDNSServiceErr_Invalid.
1634  *
1635  * On return:
1636  * For keys with no value, *value is set to NULL and *valueLen is zero.
1637  * For keys with empty value, *value is non-NULL and *valueLen is zero.
1638  * For keys with non-empty value, *value is non-NULL and *valueLen is non-zero.
1639  *
1640  * txtLen:          The size of the received TXT Record.
1641  *
1642  * txtRecord:       Pointer to the received TXT Record bytes.
1643  *
1644  * index:           An index into the TXT Record.
1645  *
1646  * keyBufLen:       The size of the string buffer being supplied.
1647  *
1648  * key:             A string buffer used to store the key name.
1649  *                  On return, the buffer contains a null-terminated C string
1650  *                  giving the key name. DNS-SD TXT keys are usually
1651  *                  8 characters or less. To hold the maximum possible
1652  *                  key name, the buffer should be 256 bytes long.
1653  *
1654  * valueLen:        On output, will be set to the size of the "value" data.
1655  *
1656  * value:           On output, *value is set to point to location within TXT
1657  *                  Record bytes that holds the value data.
1658  *
1659  * return value:    Returns kDNSServiceErr_NoError on success.
1660  *                  Returns kDNSServiceErr_NoMemory if keyBufLen is too short.
1661  *                  Returns kDNSServiceErr_Invalid if index is greater than
1662  *                  TXTRecordGetCount()-1.
1663  */
1664 
1665 DNSServiceErrorType DNSSD_API TXTRecordGetItemAtIndex
1666     (
1667     uint16_t         txtLen,
1668     const void       *txtRecord,
1669     uint16_t         index,
1670     uint16_t         keyBufLen,
1671     char             *key,
1672     uint8_t          *valueLen,
1673     const void       **value
1674     );
1675 
1676 #ifdef __APPLE_API_PRIVATE
1677 
1678 /*
1679  * Mac OS X specific functionality
1680  * 3rd party clients of this API should not depend on future support or availability of this routine
1681  */
1682 
1683 /* DNSServiceSetDefaultDomainForUser()
1684  *
1685  * Set the default domain for the caller's UID.  Future browse and registration
1686  * calls by this user that do not specify an explicit domain will browse and
1687  * register in this wide-area domain in addition to .local.  In addition, this
1688  * domain will be returned as a Browse domain via domain enumeration calls.
1689  *
1690  *
1691  * Parameters:
1692  *
1693  * flags:           Pass kDNSServiceFlagsAdd to add a domain for a user.  Call without
1694  *                  this flag set to clear a previously added domain.
1695  *
1696  * domain:          The domain to be used for the caller's UID.
1697  *
1698  * return value:    Returns kDNSServiceErr_NoError on succeses, otherwise returns
1699  *                  an error code indicating the error that occurred
1700  */
1701 
1702 DNSServiceErrorType DNSSD_API DNSServiceSetDefaultDomainForUser
1703     (
1704     DNSServiceFlags                    flags,
1705     const char                         *domain
1706     );
1707 
1708 #endif //__APPLE_API_PRIVATE
1709 
1710 // Some C compiler cleverness. We can make the compiler check certain things for us,
1711 // and report errors at compile-time if anything is wrong. The usual way to do this would
1712 // be to use a run-time "if" statement or the conventional run-time "assert" mechanism, but
1713 // then you don't find out what's wrong until you run the software. This way, if the assertion
1714 // condition is false, the array size is negative, and the complier complains immediately.
1715 
1716 struct DNS_SD_CompileTimeAssertionChecks
1717 	{
1718 	char assert0[(sizeof(union _TXTRecordRef_t) == 16) ? 1 : -1];
1719 	};
1720 
1721 #ifdef  __cplusplus
1722     }
1723 #endif
1724 
1725 #endif  /* _DNS_SD_H */
1726