1 /* -*- Mode: C; tab-width: 4 -*-
3 * Copyright (c) 2003-2004, Apple Computer, Inc. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
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.
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.
30 /*! @header DNS Service Discovery
32 * @discussion This section describes the functions, callbacks, and data structures
33 * that make up the DNS Service Discovery API.
35 * The DNS Service Discovery API is part of Bonjour, Apple's implementation
36 * of zero-configuration networking (ZEROCONF).
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.
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).
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.
58 /* _DNS_SD_H contains the mDNSResponder version number for this header file, formatted as follows:
59 * Major part of the build number * 10000 +
60 * minor part of the build number * 100
61 * For example, Mac OS X 10.4.9 has mDNSResponder-108.4, which would be represented as
62 * version 1080400. This allows C code to do simple greater-than and less-than comparisons:
63 * e.g. an application that requires the DNSServiceGetProperty() call (new in mDNSResponder-126) can check:
65 * #if _DNS_SD_H+0 >= 1260000
66 * ... some C code that calls DNSServiceGetProperty() ...
69 * The version defined in this header file symbol allows for compile-time
70 * checking, so that C code building with earlier versions of the header file
71 * can avoid compile errors trying to use functions that aren't even defined
72 * in those earlier versions. Similar checks may also be performed at run-time:
73 * => weak linking -- to avoid link failures if run with an earlier
74 * version of the library that's missing some desired symbol, or
75 * => DNSServiceGetProperty(DaemonVersion) -- to verify whether the running daemon
76 * ("system service" on Windows) meets some required minimum functionality level.
80 #define _DNS_SD_H 3793700
98 #ifndef NOT_HAVE_SA_LEN
99 #define NOT_HAVE_SA_LEN
101 #ifndef MDNS_DEBUGMSGS
102 #define MDNS_DEBUGMSGS 0
104 #ifndef WIN32_LEAN_AND_MEAN
105 #define WIN32_LEAN_AND_MEAN
107 #ifndef USE_TCP_LOOPBACK
108 #define USE_TCP_LOOPBACK
110 #ifndef _CRT_SECURE_NO_DEPRECATE
111 #define _CRT_SECURE_NO_DEPRECATE
113 #ifndef _CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES
114 #define _CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES 1
117 /* Set to 1 if libdispatch is supported
118 * Note: May also be set by project and/or Makefile
120 #ifndef _DNS_SD_LIBDISPATCH
121 #define _DNS_SD_LIBDISPATCH 0
122 #endif /* ndef _DNS_SD_LIBDISPATCH */
124 /* standard calling convention under Win32 is __stdcall */
125 /* Note: When compiling Intel EFI (Extensible Firmware Interface) under MS Visual Studio, the */
126 /* _WIN32 symbol is defined by the compiler even though it's NOT compiling code for Windows32 */
127 #if defined(_WIN32) && !defined(EFI32) && !defined(EFI64)
128 #define DNSSD_API __stdcall
133 /* stdint.h does not exist on FreeBSD 4.x; its types are defined in sys/types.h instead */
134 #if defined(__FreeBSD__) && (__FreeBSD__ < 5)
135 #include <sys/types.h>
137 /* Likewise, on Sun, standard integer types are in sys/types.h */
138 #elif defined(__sun__)
139 #include <sys/types.h>
141 /* EFI does not have stdint.h, or anything else equivalent */
142 #elif defined(EFI32) || defined(EFI64) || defined(EFIX64)
144 #if !defined(_STDINT_H_)
145 typedef UINT8
uint8_t;
147 typedef UINT16
uint16_t;
148 typedef INT16
int16_t;
149 typedef UINT32
uint32_t;
150 typedef INT32
int32_t;
152 /* Windows has its own differences */
153 #elif defined(_WIN32)
156 #ifndef _MSL_STDINT_H
157 typedef UINT8
uint8_t;
159 typedef UINT16
uint16_t;
160 typedef INT16
int16_t;
161 typedef UINT32
uint32_t;
162 typedef INT32
int32_t;
165 /* All other Posix platforms use stdint.h */
170 #if _DNS_SD_LIBDISPATCH
171 #include <dispatch/dispatch.h>
174 /* DNSServiceRef, DNSRecordRef
176 * Opaque internal data types.
177 * Note: client is responsible for serializing access to these structures if
178 * they are shared between concurrent threads.
181 typedef struct _DNSServiceRef_t
*DNSServiceRef
;
182 typedef struct _DNSRecordRef_t
*DNSRecordRef
;
186 /*! @enum General flags
187 * Most DNS-SD API functions and callbacks include a DNSServiceFlags parameter.
188 * As a general rule, any given bit in the 32-bit flags field has a specific fixed meaning,
189 * regardless of the function or callback being used. For any given function or callback,
190 * typically only a subset of the possible flags are meaningful, and all others should be zero.
191 * The discussion section for each API call describes which flags are valid for that call
192 * and callback. In some cases, for a particular call, it may be that no flags are currently
193 * defined, in which case the DNSServiceFlags parameter exists purely to allow future expansion.
194 * In all cases, developers should expect that in future releases, it is possible that new flag
195 * values will be defined, and write code with this in mind. For example, code that tests
196 * if (flags == kDNSServiceFlagsAdd) ...
197 * will fail if, in a future release, another bit in the 32-bit flags field is also set.
198 * The reliable way to test whether a particular bit is set is not with an equality test,
199 * but with a bitwise mask:
200 * if (flags & kDNSServiceFlagsAdd) ...
204 kDNSServiceFlagsMoreComing
= 0x1,
205 /* MoreComing indicates to a callback that at least one more result is
206 * queued and will be delivered following immediately after this one.
207 * When the MoreComing flag is set, applications should not immediately
208 * update their UI, because this can result in a great deal of ugly flickering
209 * on the screen, and can waste a great deal of CPU time repeatedly updating
210 * the screen with content that is then immediately erased, over and over.
211 * Applications should wait until MoreComing is not set, and then
212 * update their UI when no more changes are imminent.
213 * When MoreComing is not set, that doesn't mean there will be no more
214 * answers EVER, just that there are no more answers immediately
215 * available right now at this instant. If more answers become available
216 * in the future they will be delivered as usual.
219 kDNSServiceFlagsAdd
= 0x2,
220 kDNSServiceFlagsDefault
= 0x4,
221 /* Flags for domain enumeration and browse/query reply callbacks.
222 * "Default" applies only to enumeration and is only valid in
223 * conjunction with "Add". An enumeration callback with the "Add"
224 * flag NOT set indicates a "Remove", i.e. the domain is no longer
228 kDNSServiceFlagsNoAutoRename
= 0x8,
229 /* Flag for specifying renaming behavior on name conflict when registering
230 * non-shared records. By default, name conflicts are automatically handled
231 * by renaming the service. NoAutoRename overrides this behavior - with this
232 * flag set, name conflicts will result in a callback. The NoAutorename flag
233 * is only valid if a name is explicitly specified when registering a service
234 * (i.e. the default name is not used.)
237 kDNSServiceFlagsShared
= 0x10,
238 kDNSServiceFlagsUnique
= 0x20,
239 /* Flag for registering individual records on a connected
240 * DNSServiceRef. Shared indicates that there may be multiple records
241 * with this name on the network (e.g. PTR records). Unique indicates that the
242 * record's name is to be unique on the network (e.g. SRV records).
245 kDNSServiceFlagsBrowseDomains
= 0x40,
246 kDNSServiceFlagsRegistrationDomains
= 0x80,
247 /* Flags for specifying domain enumeration type in DNSServiceEnumerateDomains.
248 * BrowseDomains enumerates domains recommended for browsing, RegistrationDomains
249 * enumerates domains recommended for registration.
252 kDNSServiceFlagsLongLivedQuery
= 0x100,
253 /* Flag for creating a long-lived unicast query for the DNSServiceQueryRecord call. */
255 kDNSServiceFlagsAllowRemoteQuery
= 0x200,
256 /* Flag for creating a record for which we will answer remote queries
257 * (queries from hosts more than one hop away; hosts not directly connected to the local link).
260 kDNSServiceFlagsForceMulticast
= 0x400,
261 /* Flag for signifying that a query or registration should be performed exclusively via multicast
262 * DNS, even for a name in a domain (e.g. foo.apple.com.) that would normally imply unicast DNS.
265 kDNSServiceFlagsForce
= 0x800,
266 /* Flag for signifying a "stronger" variant of an operation.
267 * Currently defined only for DNSServiceReconfirmRecord(), where it forces a record to
268 * be removed from the cache immediately, instead of querying for a few seconds before
269 * concluding that the record is no longer valid and then removing it. This flag should
270 * be used with caution because if a service browsing PTR record is indeed still valid
271 * on the network, forcing its removal will result in a user-interface flap -- the
272 * discovered service instance will disappear, and then re-appear moments later.
275 kDNSServiceFlagsReturnIntermediates
= 0x1000,
276 /* Flag for returning intermediate results.
277 * For example, if a query results in an authoritative NXDomain (name does not exist)
278 * then that result is returned to the client. However the query is not implicitly
279 * cancelled -- it remains active and if the answer subsequently changes
280 * (e.g. because a VPN tunnel is subsequently established) then that positive
281 * result will still be returned to the client.
282 * Similarly, if a query results in a CNAME record, then in addition to following
283 * the CNAME referral, the intermediate CNAME result is also returned to the client.
284 * When this flag is not set, NXDomain errors are not returned, and CNAME records
285 * are followed silently without informing the client of the intermediate steps.
286 * (In earlier builds this flag was briefly calledkDNSServiceFlagsReturnCNAME)
289 kDNSServiceFlagsNonBrowsable
= 0x2000,
290 /* A service registered with the NonBrowsable flag set can be resolved using
291 * DNSServiceResolve(), but will not be discoverable using DNSServiceBrowse().
292 * This is for cases where the name is actually a GUID; it is found by other means;
293 * there is no end-user benefit to browsing to find a long list of opaque GUIDs.
294 * Using the NonBrowsable flag creates SRV+TXT without the cost of also advertising
295 * an associated PTR record.
298 kDNSServiceFlagsShareConnection
= 0x4000,
299 /* For efficiency, clients that perform many concurrent operations may want to use a
300 * single Unix Domain Socket connection with the background daemon, instead of having a
301 * separate connection for each independent operation. To use this mode, clients first
302 * call DNSServiceCreateConnection(&MainRef) to initialize the main DNSServiceRef.
303 * For each subsequent operation that is to share that same connection, the client copies
304 * the MainRef, and then passes the address of that copy, setting the ShareConnection flag
305 * to tell the library that this DNSServiceRef is not a typical uninitialized DNSServiceRef;
306 * it's a copy of an existing DNSServiceRef whose connection information should be reused.
310 * DNSServiceErrorType error;
311 * DNSServiceRef MainRef;
312 * error = DNSServiceCreateConnection(&MainRef);
314 * DNSServiceRef BrowseRef = MainRef; // Important: COPY the primary DNSServiceRef first...
315 * error = DNSServiceBrowse(&BrowseRef, kDNSServiceFlagsShareConnection, ...); // then use the copy
318 * DNSServiceRefDeallocate(BrowseRef); // Terminate the browse operation
319 * DNSServiceRefDeallocate(MainRef); // Terminate the shared connection
323 * 1. Collective kDNSServiceFlagsMoreComing flag
324 * When callbacks are invoked using a shared DNSServiceRef, the
325 * kDNSServiceFlagsMoreComing flag applies collectively to *all* active
326 * operations sharing the same parent DNSServiceRef. If the MoreComing flag is
327 * set it means that there are more results queued on this parent DNSServiceRef,
328 * but not necessarily more results for this particular callback function.
329 * The implication of this for client programmers is that when a callback
330 * is invoked with the MoreComing flag set, the code should update its
331 * internal data structures with the new result, and set a variable indicating
332 * that its UI needs to be updated. Then, later when a callback is eventually
333 * invoked with the MoreComing flag not set, the code should update *all*
334 * stale UI elements related to that shared parent DNSServiceRef that need
335 * updating, not just the UI elements related to the particular callback
336 * that happened to be the last one to be invoked.
338 * 2. Canceling operations and kDNSServiceFlagsMoreComing
339 * Whenever you cancel any operation for which you had deferred UI updates
340 * waiting because of a kDNSServiceFlagsMoreComing flag, you should perform
341 * those deferred UI updates. This is because, after cancelling the operation,
342 * you can no longer wait for a callback *without* MoreComing set, to tell
343 * you do perform your deferred UI updates (the operation has been canceled,
344 * so there will be no more callbacks). An implication of the collective
345 * kDNSServiceFlagsMoreComing flag for shared connections is that this
346 * guideline applies more broadly -- any time you cancel an operation on
347 * a shared connection, you should perform all deferred UI updates for all
348 * operations sharing that connection. This is because the MoreComing flag
349 * might have been referring to events coming for the operation you canceled,
350 * which will now not be coming because the operation has been canceled.
352 * 3. Only share DNSServiceRef's created with DNSServiceCreateConnection
353 * Calling DNSServiceCreateConnection(&ref) creates a special shareable DNSServiceRef.
354 * DNSServiceRef's created by other calls like DNSServiceBrowse() or DNSServiceResolve()
355 * cannot be shared by copying them and using kDNSServiceFlagsShareConnection.
357 * 4. Don't Double-Deallocate
358 * Calling DNSServiceRefDeallocate(ref) for a particular operation's DNSServiceRef terminates
359 * just that operation. Calling DNSServiceRefDeallocate(ref) for the main shared DNSServiceRef
360 * (the parent DNSServiceRef, originally created by DNSServiceCreateConnection(&ref))
361 * automatically terminates the shared connection and all operations that were still using it.
362 * After doing this, DO NOT then attempt to deallocate any remaining subordinate DNSServiceRef's.
363 * The memory used by those subordinate DNSServiceRef's has already been freed, so any attempt
364 * to do a DNSServiceRefDeallocate (or any other operation) on them will result in accesses
365 * to freed memory, leading to crashes or other equally undesirable results.
368 * The dns_sd.h API does not presuppose any particular threading model, and consequently
369 * does no locking of its own (which would require linking some specific threading library).
370 * If client code calls API routines on the same DNSServiceRef concurrently
371 * from multiple threads, it is the client's responsibility to use a mutext
372 * lock or take similar appropriate precautions to serialize those calls.
375 kDNSServiceFlagsSuppressUnusable
= 0x8000,
377 * This flag is meaningful only in DNSServiceQueryRecord which suppresses unusable queries on the
378 * wire. If "hostname" is a wide-area unicast DNS hostname (i.e. not a ".local." name)
379 * but this host has no routable IPv6 address, then the call will not try to look up IPv6 addresses
380 * for "hostname", since any addresses it found would be unlikely to be of any use anyway. Similarly,
381 * if this host has no routable IPv4 address, the call will not try to look up IPv4 addresses for
385 kDNSServiceFlagsTimeout
= 0x10000,
387 * When kDNServiceFlagsTimeout is passed to DNSServiceQueryRecord or DNSServiceGetAddrInfo, the query is
388 * stopped after a certain number of seconds have elapsed. The time at which the query will be stopped
389 * is determined by the system and cannot be configured by the user. The query will be stopped irrespective
390 * of whether a response was given earlier or not. When the query is stopped, the callback will be called
391 * with an error code of kDNSServiceErr_Timeout and a NULL sockaddr will be returned for DNSServiceGetAddrInfo
392 * and zero length rdata will be returned for DNSServiceQueryRecord.
395 kDNSServiceFlagsIncludeP2P
= 0x20000,
397 * Include P2P interfaces when kDNSServiceInterfaceIndexAny is specified.
398 * By default, specifying kDNSServiceInterfaceIndexAny does not include P2P interfaces.
401 kDNSServiceFlagsWakeOnResolve
= 0x40000,
403 * This flag is meaningful only in DNSServiceResolve. When set, it tries to send a magic packet
404 * to wake up the client.
407 kDNSServiceFlagsBackgroundTrafficClass
= 0x80000,
409 * This flag is meaningful in DNSServiceBrowse, DNSServiceGetAddrInfo, DNSServiceQueryRecord,
410 * and DNSServiceResolve. When set, it uses the background traffic
411 * class for packets that service the request.
414 kDNSServiceFlagsIncludeAWDL
= 0x100000
416 * Include AWDL interface when kDNSServiceInterfaceIndexAny is specified.
420 /* Possible protocols for DNSServiceNATPortMappingCreate(). */
423 kDNSServiceProtocol_IPv4
= 0x01,
424 kDNSServiceProtocol_IPv6
= 0x02,
425 /* 0x04 and 0x08 reserved for future internetwork protocols */
427 kDNSServiceProtocol_UDP
= 0x10,
428 kDNSServiceProtocol_TCP
= 0x20
429 /* 0x40 and 0x80 reserved for future transport protocols, e.g. SCTP [RFC 2960]
430 * or DCCP [RFC 4340]. If future NAT gateways are created that support port
431 * mappings for these protocols, new constants will be defined here.
436 * The values for DNS Classes and Types are listed in RFC 1035, and are available
437 * on every OS in its DNS header file. Unfortunately every OS does not have the
438 * same header file containing DNS Class and Type constants, and the names of
439 * the constants are not consistent. For example, BIND 8 uses "T_A",
440 * BIND 9 uses "ns_t_a", Windows uses "DNS_TYPE_A", etc.
441 * For this reason, these constants are also listed here, so that code using
442 * the DNS-SD programming APIs can use these constants, so that the same code
443 * can compile on all our supported platforms.
448 kDNSServiceClass_IN
= 1 /* Internet */
453 kDNSServiceType_A
= 1, /* Host address. */
454 kDNSServiceType_NS
= 2, /* Authoritative server. */
455 kDNSServiceType_MD
= 3, /* Mail destination. */
456 kDNSServiceType_MF
= 4, /* Mail forwarder. */
457 kDNSServiceType_CNAME
= 5, /* Canonical name. */
458 kDNSServiceType_SOA
= 6, /* Start of authority zone. */
459 kDNSServiceType_MB
= 7, /* Mailbox domain name. */
460 kDNSServiceType_MG
= 8, /* Mail group member. */
461 kDNSServiceType_MR
= 9, /* Mail rename name. */
462 kDNSServiceType_NULL
= 10, /* Null resource record. */
463 kDNSServiceType_WKS
= 11, /* Well known service. */
464 kDNSServiceType_PTR
= 12, /* Domain name pointer. */
465 kDNSServiceType_HINFO
= 13, /* Host information. */
466 kDNSServiceType_MINFO
= 14, /* Mailbox information. */
467 kDNSServiceType_MX
= 15, /* Mail routing information. */
468 kDNSServiceType_TXT
= 16, /* One or more text strings (NOT "zero or more..."). */
469 kDNSServiceType_RP
= 17, /* Responsible person. */
470 kDNSServiceType_AFSDB
= 18, /* AFS cell database. */
471 kDNSServiceType_X25
= 19, /* X_25 calling address. */
472 kDNSServiceType_ISDN
= 20, /* ISDN calling address. */
473 kDNSServiceType_RT
= 21, /* Router. */
474 kDNSServiceType_NSAP
= 22, /* NSAP address. */
475 kDNSServiceType_NSAP_PTR
= 23, /* Reverse NSAP lookup (deprecated). */
476 kDNSServiceType_SIG
= 24, /* Security signature. */
477 kDNSServiceType_KEY
= 25, /* Security key. */
478 kDNSServiceType_PX
= 26, /* X.400 mail mapping. */
479 kDNSServiceType_GPOS
= 27, /* Geographical position (withdrawn). */
480 kDNSServiceType_AAAA
= 28, /* IPv6 Address. */
481 kDNSServiceType_LOC
= 29, /* Location Information. */
482 kDNSServiceType_NXT
= 30, /* Next domain (security). */
483 kDNSServiceType_EID
= 31, /* Endpoint identifier. */
484 kDNSServiceType_NIMLOC
= 32, /* Nimrod Locator. */
485 kDNSServiceType_SRV
= 33, /* Server Selection. */
486 kDNSServiceType_ATMA
= 34, /* ATM Address */
487 kDNSServiceType_NAPTR
= 35, /* Naming Authority PoinTeR */
488 kDNSServiceType_KX
= 36, /* Key Exchange */
489 kDNSServiceType_CERT
= 37, /* Certification record */
490 kDNSServiceType_A6
= 38, /* IPv6 Address (deprecated) */
491 kDNSServiceType_DNAME
= 39, /* Non-terminal DNAME (for IPv6) */
492 kDNSServiceType_SINK
= 40, /* Kitchen sink (experimental) */
493 kDNSServiceType_OPT
= 41, /* EDNS0 option (meta-RR) */
494 kDNSServiceType_APL
= 42, /* Address Prefix List */
495 kDNSServiceType_DS
= 43, /* Delegation Signer */
496 kDNSServiceType_SSHFP
= 44, /* SSH Key Fingerprint */
497 kDNSServiceType_IPSECKEY
= 45, /* IPSECKEY */
498 kDNSServiceType_RRSIG
= 46, /* RRSIG */
499 kDNSServiceType_NSEC
= 47, /* Denial of Existence */
500 kDNSServiceType_DNSKEY
= 48, /* DNSKEY */
501 kDNSServiceType_DHCID
= 49, /* DHCP Client Identifier */
502 kDNSServiceType_NSEC3
= 50, /* Hashed Authenticated Denial of Existence */
503 kDNSServiceType_NSEC3PARAM
= 51, /* Hashed Authenticated Denial of Existence */
505 kDNSServiceType_HIP
= 55, /* Host Identity Protocol */
507 kDNSServiceType_SPF
= 99, /* Sender Policy Framework for E-Mail */
508 kDNSServiceType_UINFO
= 100, /* IANA-Reserved */
509 kDNSServiceType_UID
= 101, /* IANA-Reserved */
510 kDNSServiceType_GID
= 102, /* IANA-Reserved */
511 kDNSServiceType_UNSPEC
= 103, /* IANA-Reserved */
513 kDNSServiceType_TKEY
= 249, /* Transaction key */
514 kDNSServiceType_TSIG
= 250, /* Transaction signature. */
515 kDNSServiceType_IXFR
= 251, /* Incremental zone transfer. */
516 kDNSServiceType_AXFR
= 252, /* Transfer zone of authority. */
517 kDNSServiceType_MAILB
= 253, /* Transfer mailbox records. */
518 kDNSServiceType_MAILA
= 254, /* Transfer mail agent records. */
519 kDNSServiceType_ANY
= 255 /* Wildcard match. */
522 /* possible error code values */
525 kDNSServiceErr_NoError
= 0,
526 kDNSServiceErr_Unknown
= -65537, /* 0xFFFE FFFF */
527 kDNSServiceErr_NoSuchName
= -65538,
528 kDNSServiceErr_NoMemory
= -65539,
529 kDNSServiceErr_BadParam
= -65540,
530 kDNSServiceErr_BadReference
= -65541,
531 kDNSServiceErr_BadState
= -65542,
532 kDNSServiceErr_BadFlags
= -65543,
533 kDNSServiceErr_Unsupported
= -65544,
534 kDNSServiceErr_NotInitialized
= -65545,
535 kDNSServiceErr_AlreadyRegistered
= -65547,
536 kDNSServiceErr_NameConflict
= -65548,
537 kDNSServiceErr_Invalid
= -65549,
538 kDNSServiceErr_Firewall
= -65550,
539 kDNSServiceErr_Incompatible
= -65551, /* client library incompatible with daemon */
540 kDNSServiceErr_BadInterfaceIndex
= -65552,
541 kDNSServiceErr_Refused
= -65553,
542 kDNSServiceErr_NoSuchRecord
= -65554,
543 kDNSServiceErr_NoAuth
= -65555,
544 kDNSServiceErr_NoSuchKey
= -65556,
545 kDNSServiceErr_NATTraversal
= -65557,
546 kDNSServiceErr_DoubleNAT
= -65558,
547 kDNSServiceErr_BadTime
= -65559, /* Codes up to here existed in Tiger */
548 kDNSServiceErr_BadSig
= -65560,
549 kDNSServiceErr_BadKey
= -65561,
550 kDNSServiceErr_Transient
= -65562,
551 kDNSServiceErr_ServiceNotRunning
= -65563, /* Background daemon not running */
552 kDNSServiceErr_NATPortMappingUnsupported
= -65564, /* NAT doesn't support NAT-PMP or UPnP */
553 kDNSServiceErr_NATPortMappingDisabled
= -65565, /* NAT supports NAT-PMP or UPnP but it's disabled by the administrator */
554 kDNSServiceErr_NoRouter
= -65566, /* No router currently configured (probably no network connectivity) */
555 kDNSServiceErr_PollingMode
= -65567,
556 kDNSServiceErr_Timeout
= -65568
558 /* mDNS Error codes are in the range
559 * FFFE FF00 (-65792) to FFFE FFFF (-65537) */
562 /* Maximum length, in bytes, of a service name represented as a */
563 /* literal C-String, including the terminating NULL at the end. */
566 /* Maximum length, in bytes, of a domain name represented as an *escaped* C-String */
567 /* including the final trailing dot, and the C-String terminating NULL at the end. */
569 #define kDNSServiceMaxDomainName 1009
572 * Notes on DNS Name Escaping
574 * "Why is kDNSServiceMaxDomainName 1009, when the maximum legal domain name is 256 bytes?"
576 * All strings used in the DNS-SD APIs are UTF-8 strings. Apart from the exceptions noted below,
577 * the APIs expect the strings to be properly escaped, using the conventional DNS escaping rules:
579 * '\\' represents a single literal '\' in the name
580 * '\.' represents a single literal '.' in the name
581 * '\ddd', where ddd is a three-digit decimal value from 000 to 255,
582 * represents a single literal byte with that value.
583 * A bare unescaped '.' is a label separator, marking a boundary between domain and subdomain.
585 * The exceptions, that do not use escaping, are the routines where the full
586 * DNS name of a resource is broken, for convenience, into servicename/regtype/domain.
587 * In these routines, the "servicename" is NOT escaped. It does not need to be, since
588 * it is, by definition, just a single literal string. Any characters in that string
589 * represent exactly what they are. The "regtype" portion is, technically speaking,
590 * escaped, but since legal regtypes are only allowed to contain letters, digits,
591 * and hyphens, there is nothing to escape, so the issue is moot. The "domain"
592 * portion is also escaped, though most domains in use on the public Internet
593 * today, like regtypes, don't contain any characters that need to be escaped.
594 * As DNS-SD becomes more popular, rich-text domains for service discovery will
595 * become common, so software should be written to cope with domains with escaping.
597 * The servicename may be up to 63 bytes of UTF-8 text (not counting the C-String
598 * terminating NULL at the end). The regtype is of the form _service._tcp or
599 * _service._udp, where the "service" part is 1-15 characters, which may be
600 * letters, digits, or hyphens. The domain part of the three-part name may be
601 * any legal domain, providing that the resulting servicename+regtype+domain
602 * name does not exceed 256 bytes.
604 * For most software, these issues are transparent. When browsing, the discovered
605 * servicenames should simply be displayed as-is. When resolving, the discovered
606 * servicename/regtype/domain are simply passed unchanged to DNSServiceResolve().
607 * When a DNSServiceResolve() succeeds, the returned fullname is already in
608 * the correct format to pass to standard system DNS APIs such as res_query().
609 * For converting from servicename/regtype/domain to a single properly-escaped
610 * full DNS name, the helper function DNSServiceConstructFullName() is provided.
612 * The following (highly contrived) example illustrates the escaping process.
613 * Suppose you have an service called "Dr. Smith\Dr. Johnson", of type "_ftp._tcp"
614 * in subdomain "4th. Floor" of subdomain "Building 2" of domain "apple.com."
615 * The full (escaped) DNS name of this service's SRV record would be:
616 * Dr\.\032Smith\\Dr\.\032Johnson._ftp._tcp.4th\.\032Floor.Building\0322.apple.com.
621 * Constants for specifying an interface index
623 * Specific interface indexes are identified via a 32-bit unsigned integer returned
624 * by the if_nametoindex() family of calls.
626 * If the client passes 0 for interface index, that means "do the right thing",
627 * which (at present) means, "if the name is in an mDNS local multicast domain
628 * (e.g. 'local.', '254.169.in-addr.arpa.', '{8,9,A,B}.E.F.ip6.arpa.') then multicast
629 * on all applicable interfaces, otherwise send via unicast to the appropriate
630 * DNS server." Normally, most clients will use 0 for interface index to
631 * automatically get the default sensible behaviour.
633 * If the client passes a positive interface index, then for multicast names that
634 * indicates to do the operation only on that one interface. For unicast names the
635 * interface index is ignored unless kDNSServiceFlagsForceMulticast is also set.
637 * If the client passes kDNSServiceInterfaceIndexLocalOnly when registering
638 * a service, then that service will be found *only* by other local clients
639 * on the same machine that are browsing using kDNSServiceInterfaceIndexLocalOnly
640 * or kDNSServiceInterfaceIndexAny.
641 * If a client has a 'private' service, accessible only to other processes
642 * running on the same machine, this allows the client to advertise that service
643 * in a way such that it does not inadvertently appear in service lists on
644 * all the other machines on the network.
646 * If the client passes kDNSServiceInterfaceIndexLocalOnly when browsing
647 * then it will find *all* records registered on that same local machine.
648 * Clients explicitly wishing to discover *only* LocalOnly services can
649 * accomplish this by inspecting the interfaceIndex of each service reported
650 * to their DNSServiceBrowseReply() callback function, and discarding those
651 * where the interface index is not kDNSServiceInterfaceIndexLocalOnly.
653 * kDNSServiceInterfaceIndexP2P is meaningful only in Browse, QueryRecord,
654 * and Resolve operations. It should not be used in other DNSService APIs.
656 * - If kDNSServiceInterfaceIndexP2P is passed to DNSServiceBrowse or
657 * DNSServiceQueryRecord, it restricts the operation to P2P.
659 * - If kDNSServiceInterfaceIndexP2P is passed to DNSServiceResolve, it is
660 * mapped internally to kDNSServiceInterfaceIndexAny with the kDNSServiceFlagsIncludeP2P
661 * set, because resolving a P2P service may create and/or enable an interface whose
662 * index is not known a priori. The resolve callback will indicate the index of the
663 * interface via which the service can be accessed.
665 * If applications pass kDNSServiceInterfaceIndexAny to DNSServiceBrowse
666 * or DNSServiceQueryRecord, they must set the kDNSServiceFlagsIncludeP2P flag
667 * to include P2P. In this case, if a service instance or the record being queried
668 * is found over P2P, the resulting ADD event will indicate kDNSServiceInterfaceIndexP2P
669 * as the interface index.
672 #define kDNSServiceInterfaceIndexAny 0
673 #define kDNSServiceInterfaceIndexLocalOnly ((uint32_t)-1)
674 #define kDNSServiceInterfaceIndexUnicast ((uint32_t)-2)
675 #define kDNSServiceInterfaceIndexP2P ((uint32_t)-3)
677 typedef uint32_t DNSServiceFlags
;
678 typedef uint32_t DNSServiceProtocol
;
679 typedef int32_t DNSServiceErrorType
;
682 /*********************************************************************************************
686 *********************************************************************************************/
688 /* DNSServiceGetProperty() Parameters:
690 * property: The requested property.
691 * Currently the only property defined is kDNSServiceProperty_DaemonVersion.
693 * result: Place to store result.
694 * For retrieving DaemonVersion, this should be the address of a uint32_t.
696 * size: Pointer to uint32_t containing size of the result location.
697 * For retrieving DaemonVersion, this should be sizeof(uint32_t).
698 * On return the uint32_t is updated to the size of the data returned.
699 * For DaemonVersion, the returned size is always sizeof(uint32_t), but
700 * future properties could be defined which return variable-sized results.
702 * return value: Returns kDNSServiceErr_NoError on success, or kDNSServiceErr_ServiceNotRunning
703 * if the daemon (or "system service" on Windows) is not running.
706 DNSServiceErrorType DNSSD_API DNSServiceGetProperty
708 const char *property
, /* Requested property (i.e. kDNSServiceProperty_DaemonVersion) */
709 void *result
, /* Pointer to place to store result */
710 uint32_t *size
/* size of result location */
714 * When requesting kDNSServiceProperty_DaemonVersion, the result pointer must point
715 * to a 32-bit unsigned integer, and the size parameter must be set to sizeof(uint32_t).
717 * On return, the 32-bit unsigned integer contains the version number, formatted as follows:
718 * Major part of the build number * 10000 +
719 * minor part of the build number * 100
721 * For example, Mac OS X 10.4.9 has mDNSResponder-108.4, which would be represented as
722 * version 1080400. This allows applications to do simple greater-than and less-than comparisons:
723 * e.g. an application that requires at least mDNSResponder-108.4 can check:
725 * if (version >= 1080400) ...
730 * uint32_t size = sizeof(version);
731 * DNSServiceErrorType err = DNSServiceGetProperty(kDNSServiceProperty_DaemonVersion, &version, &size);
732 * if (!err) printf("Bonjour version is %d.%d\n", version / 10000, version / 100 % 100);
735 #define kDNSServiceProperty_DaemonVersion "DaemonVersion"
738 /*********************************************************************************************
740 * Unix Domain Socket access, DNSServiceRef deallocation, and data processing functions
742 *********************************************************************************************/
744 /* DNSServiceRefSockFD()
746 * Access underlying Unix domain socket for an initialized DNSServiceRef.
747 * The DNS Service Discovery implementation uses this socket to communicate between the client and
748 * the mDNSResponder daemon. The application MUST NOT directly read from or write to this socket.
749 * Access to the socket is provided so that it can be used as a kqueue event source, a CFRunLoop
750 * event source, in a select() loop, etc. When the underlying event management subsystem (kqueue/
751 * select/CFRunLoop etc.) indicates to the client that data is available for reading on the
752 * socket, the client should call DNSServiceProcessResult(), which will extract the daemon's
753 * reply from the socket, and pass it to the appropriate application callback. By using a run
754 * loop or select(), results from the daemon can be processed asynchronously. Alternatively,
755 * a client can choose to fork a thread and have it loop calling "DNSServiceProcessResult(ref);"
756 * If DNSServiceProcessResult() is called when no data is available for reading on the socket, it
757 * will block until data does become available, and then process the data and return to the caller.
758 * When data arrives on the socket, the client is responsible for calling DNSServiceProcessResult(ref)
759 * in a timely fashion -- if the client allows a large backlog of data to build up the daemon
760 * may terminate the connection.
762 * sdRef: A DNSServiceRef initialized by any of the DNSService calls.
764 * return value: The DNSServiceRef's underlying socket descriptor, or -1 on
768 int DNSSD_API
DNSServiceRefSockFD(DNSServiceRef sdRef
);
771 /* DNSServiceProcessResult()
773 * Read a reply from the daemon, calling the appropriate application callback. This call will
774 * block until the daemon's response is received. Use DNSServiceRefSockFD() in
775 * conjunction with a run loop or select() to determine the presence of a response from the
776 * server before calling this function to process the reply without blocking. Call this function
777 * at any point if it is acceptable to block until the daemon's response arrives. Note that the
778 * client is responsible for ensuring that DNSServiceProcessResult() is called whenever there is
779 * a reply from the daemon - the daemon may terminate its connection with a client that does not
780 * process the daemon's responses.
782 * sdRef: A DNSServiceRef initialized by any of the DNSService calls
783 * that take a callback parameter.
785 * return value: Returns kDNSServiceErr_NoError on success, otherwise returns
786 * an error code indicating the specific failure that occurred.
789 DNSServiceErrorType DNSSD_API
DNSServiceProcessResult(DNSServiceRef sdRef
);
792 /* DNSServiceRefDeallocate()
794 * Terminate a connection with the daemon and free memory associated with the DNSServiceRef.
795 * Any services or records registered with this DNSServiceRef will be deregistered. Any
796 * Browse, Resolve, or Query operations called with this reference will be terminated.
798 * Note: If the reference's underlying socket is used in a run loop or select() call, it should
799 * be removed BEFORE DNSServiceRefDeallocate() is called, as this function closes the reference's
802 * Note: If the reference was initialized with DNSServiceCreateConnection(), any DNSRecordRefs
803 * created via this reference will be invalidated by this call - the resource records are
804 * deregistered, and their DNSRecordRefs may not be used in subsequent functions. Similarly,
805 * if the reference was initialized with DNSServiceRegister, and an extra resource record was
806 * added to the service via DNSServiceAddRecord(), the DNSRecordRef created by the Add() call
807 * is invalidated when this function is called - the DNSRecordRef may not be used in subsequent
810 * Note: This call is to be used only with the DNSServiceRef defined by this API. It is
811 * not compatible with dns_service_discovery_ref objects defined in the legacy Mach-based
812 * DNSServiceDiscovery.h API.
814 * sdRef: A DNSServiceRef initialized by any of the DNSService calls.
818 void DNSSD_API
DNSServiceRefDeallocate(DNSServiceRef sdRef
);
821 /*********************************************************************************************
825 *********************************************************************************************/
827 /* DNSServiceEnumerateDomains()
829 * Asynchronously enumerate domains available for browsing and registration.
831 * The enumeration MUST be cancelled via DNSServiceRefDeallocate() when no more domains
834 * Note that the names returned are (like all of DNS-SD) UTF-8 strings,
835 * and are escaped using standard DNS escaping rules.
836 * (See "Notes on DNS Name Escaping" earlier in this file for more details.)
837 * A graphical browser displaying a hierarchical tree-structured view should cut
838 * the names at the bare dots to yield individual labels, then de-escape each
839 * label according to the escaping rules, and then display the resulting UTF-8 text.
841 * DNSServiceDomainEnumReply Callback Parameters:
843 * sdRef: The DNSServiceRef initialized by DNSServiceEnumerateDomains().
845 * flags: Possible values are:
846 * kDNSServiceFlagsMoreComing
847 * kDNSServiceFlagsAdd
848 * kDNSServiceFlagsDefault
850 * interfaceIndex: Specifies the interface on which the domain exists. (The index for a given
851 * interface is determined via the if_nametoindex() family of calls.)
853 * errorCode: Will be kDNSServiceErr_NoError (0) on success, otherwise indicates
854 * the failure that occurred (other parameters are undefined if errorCode is nonzero).
856 * replyDomain: The name of the domain.
858 * context: The context pointer passed to DNSServiceEnumerateDomains.
862 typedef void (DNSSD_API
*DNSServiceDomainEnumReply
)
865 DNSServiceFlags flags
,
866 uint32_t interfaceIndex
,
867 DNSServiceErrorType errorCode
,
868 const char *replyDomain
,
873 /* DNSServiceEnumerateDomains() Parameters:
875 * sdRef: A pointer to an uninitialized DNSServiceRef. If the call succeeds
876 * then it initializes the DNSServiceRef, returns kDNSServiceErr_NoError,
877 * and the enumeration operation will run indefinitely until the client
878 * terminates it by passing this DNSServiceRef to DNSServiceRefDeallocate().
880 * flags: Possible values are:
881 * kDNSServiceFlagsBrowseDomains to enumerate domains recommended for browsing.
882 * kDNSServiceFlagsRegistrationDomains to enumerate domains recommended
885 * interfaceIndex: If non-zero, specifies the interface on which to look for domains.
886 * (the index for a given interface is determined via the if_nametoindex()
887 * family of calls.) Most applications will pass 0 to enumerate domains on
888 * all interfaces. See "Constants for specifying an interface index" for more details.
890 * callBack: The function to be called when a domain is found or the call asynchronously
893 * context: An application context pointer which is passed to the callback function
896 * return value: Returns kDNSServiceErr_NoError on success (any subsequent, asynchronous
897 * errors are delivered to the callback), otherwise returns an error code indicating
898 * the error that occurred (the callback is not invoked and the DNSServiceRef
899 * is not initialized).
902 DNSServiceErrorType DNSSD_API DNSServiceEnumerateDomains
904 DNSServiceRef
*sdRef
,
905 DNSServiceFlags flags
,
906 uint32_t interfaceIndex
,
907 DNSServiceDomainEnumReply callBack
,
908 void *context
/* may be NULL */
912 /*********************************************************************************************
914 * Service Registration
916 *********************************************************************************************/
918 /* Register a service that is discovered via Browse() and Resolve() calls.
920 * DNSServiceRegisterReply() Callback Parameters:
922 * sdRef: The DNSServiceRef initialized by DNSServiceRegister().
924 * flags: When a name is successfully registered, the callback will be
925 * invoked with the kDNSServiceFlagsAdd flag set. When Wide-Area
926 * DNS-SD is in use, it is possible for a single service to get
927 * more than one success callback (e.g. one in the "local" multicast
928 * DNS domain, and another in a wide-area unicast DNS domain).
929 * If a successfully-registered name later suffers a name conflict
930 * or similar problem and has to be deregistered, the callback will
931 * be invoked with the kDNSServiceFlagsAdd flag not set. The callback
932 * is *not* invoked in the case where the caller explicitly terminates
933 * the service registration by calling DNSServiceRefDeallocate(ref);
935 * errorCode: Will be kDNSServiceErr_NoError on success, otherwise will
936 * indicate the failure that occurred (including name conflicts,
937 * if the kDNSServiceFlagsNoAutoRename flag was used when registering.)
938 * Other parameters are undefined if errorCode is nonzero.
940 * name: The service name registered (if the application did not specify a name in
941 * DNSServiceRegister(), this indicates what name was automatically chosen).
943 * regtype: The type of service registered, as it was passed to the callout.
945 * domain: The domain on which the service was registered (if the application did not
946 * specify a domain in DNSServiceRegister(), this indicates the default domain
947 * on which the service was registered).
949 * context: The context pointer that was passed to the callout.
953 typedef void (DNSSD_API
*DNSServiceRegisterReply
)
956 DNSServiceFlags flags
,
957 DNSServiceErrorType errorCode
,
965 /* DNSServiceRegister() Parameters:
967 * sdRef: A pointer to an uninitialized DNSServiceRef. If the call succeeds
968 * then it initializes the DNSServiceRef, returns kDNSServiceErr_NoError,
969 * and the registration will remain active indefinitely until the client
970 * terminates it by passing this DNSServiceRef to DNSServiceRefDeallocate().
972 * interfaceIndex: If non-zero, specifies the interface on which to register the service
973 * (the index for a given interface is determined via the if_nametoindex()
974 * family of calls.) Most applications will pass 0 to register on all
975 * available interfaces. See "Constants for specifying an interface index" for more details.
977 * flags: Indicates the renaming behavior on name conflict (most applications
978 * will pass 0). See flag definitions above for details.
980 * name: If non-NULL, specifies the service name to be registered.
981 * Most applications will not specify a name, in which case the computer
982 * name is used (this name is communicated to the client via the callback).
983 * If a name is specified, it must be 1-63 bytes of UTF-8 text.
984 * If the name is longer than 63 bytes it will be automatically truncated
985 * to a legal length, unless the NoAutoRename flag is set,
986 * in which case kDNSServiceErr_BadParam will be returned.
988 * regtype: The service type followed by the protocol, separated by a dot
989 * (e.g. "_ftp._tcp"). The service type must be an underscore, followed
990 * by 1-15 characters, which may be letters, digits, or hyphens.
991 * The transport protocol must be "_tcp" or "_udp". New service types
992 * should be registered at <http://www.dns-sd.org/ServiceTypes.html>.
994 * Additional subtypes of the primary service type (where a service
995 * type has defined subtypes) follow the primary service type in a
996 * comma-separated list, with no additional spaces, e.g.
997 * "_primarytype._tcp,_subtype1,_subtype2,_subtype3"
998 * Subtypes provide a mechanism for filtered browsing: A client browsing
999 * for "_primarytype._tcp" will discover all instances of this type;
1000 * a client browsing for "_primarytype._tcp,_subtype2" will discover only
1001 * those instances that were registered with "_subtype2" in their list of
1002 * registered subtypes.
1004 * The subtype mechanism can be illustrated with some examples using the
1005 * dns-sd command-line tool:
1007 * % dns-sd -R Simple _test._tcp "" 1001 &
1008 * % dns-sd -R Better _test._tcp,HasFeatureA "" 1002 &
1009 * % dns-sd -R Best _test._tcp,HasFeatureA,HasFeatureB "" 1003 &
1012 * % dns-sd -B _test._tcp # will find all three services
1013 * % dns-sd -B _test._tcp,HasFeatureA # finds "Better" and "Best"
1014 * % dns-sd -B _test._tcp,HasFeatureB # finds only "Best"
1016 * Subtype labels may be up to 63 bytes long, and may contain any eight-
1017 * bit byte values, including zero bytes. However, due to the nature of
1018 * using a C-string-based API, conventional DNS escaping must be used for
1019 * dots ('.'), commas (','), backslashes ('\') and zero bytes, as shown below:
1021 * % dns-sd -R Test '_test._tcp,s\.one,s\,two,s\\three,s\000four' local 123
1023 * domain: If non-NULL, specifies the domain on which to advertise the service.
1024 * Most applications will not specify a domain, instead automatically
1025 * registering in the default domain(s).
1027 * host: If non-NULL, specifies the SRV target host name. Most applications
1028 * will not specify a host, instead automatically using the machine's
1029 * default host name(s). Note that specifying a non-NULL host does NOT
1030 * create an address record for that host - the application is responsible
1031 * for ensuring that the appropriate address record exists, or creating it
1032 * via DNSServiceRegisterRecord().
1034 * port: The port, in network byte order, on which the service accepts connections.
1035 * Pass 0 for a "placeholder" service (i.e. a service that will not be discovered
1036 * by browsing, but will cause a name conflict if another client tries to
1037 * register that same name). Most clients will not use placeholder services.
1039 * txtLen: The length of the txtRecord, in bytes. Must be zero if the txtRecord is NULL.
1041 * txtRecord: The TXT record rdata. A non-NULL txtRecord MUST be a properly formatted DNS
1042 * TXT record, i.e. <length byte> <data> <length byte> <data> ...
1043 * Passing NULL for the txtRecord is allowed as a synonym for txtLen=1, txtRecord="",
1044 * i.e. it creates a TXT record of length one containing a single empty string.
1045 * RFC 1035 doesn't allow a TXT record to contain *zero* strings, so a single empty
1046 * string is the smallest legal DNS TXT record.
1047 * As with the other parameters, the DNSServiceRegister call copies the txtRecord
1048 * data; e.g. if you allocated the storage for the txtRecord parameter with malloc()
1049 * then you can safely free that memory right after the DNSServiceRegister call returns.
1051 * callBack: The function to be called when the registration completes or asynchronously
1052 * fails. The client MAY pass NULL for the callback - The client will NOT be notified
1053 * of the default values picked on its behalf, and the client will NOT be notified of any
1054 * asynchronous errors (e.g. out of memory errors, etc.) that may prevent the registration
1055 * of the service. The client may NOT pass the NoAutoRename flag if the callback is NULL.
1056 * The client may still deregister the service at any time via DNSServiceRefDeallocate().
1058 * context: An application context pointer which is passed to the callback function
1061 * return value: Returns kDNSServiceErr_NoError on success (any subsequent, asynchronous
1062 * errors are delivered to the callback), otherwise returns an error code indicating
1063 * the error that occurred (the callback is never invoked and the DNSServiceRef
1064 * is not initialized).
1067 DNSServiceErrorType DNSSD_API DNSServiceRegister
1069 DNSServiceRef
*sdRef
,
1070 DNSServiceFlags flags
,
1071 uint32_t interfaceIndex
,
1072 const char *name
, /* may be NULL */
1073 const char *regtype
,
1074 const char *domain
, /* may be NULL */
1075 const char *host
, /* may be NULL */
1076 uint16_t port
, /* In network byte order */
1078 const void *txtRecord
, /* may be NULL */
1079 DNSServiceRegisterReply callBack
, /* may be NULL */
1080 void *context
/* may be NULL */
1084 /* DNSServiceAddRecord()
1086 * Add a record to a registered service. The name of the record will be the same as the
1087 * registered service's name.
1088 * The record can later be updated or deregistered by passing the RecordRef initialized
1089 * by this function to DNSServiceUpdateRecord() or DNSServiceRemoveRecord().
1091 * Note that the DNSServiceAddRecord/UpdateRecord/RemoveRecord are *NOT* thread-safe
1092 * with respect to a single DNSServiceRef. If you plan to have multiple threads
1093 * in your program simultaneously add, update, or remove records from the same
1094 * DNSServiceRef, then it's the caller's responsibility to use a mutext lock
1095 * or take similar appropriate precautions to serialize those calls.
1099 * sdRef: A DNSServiceRef initialized by DNSServiceRegister().
1101 * RecordRef: A pointer to an uninitialized DNSRecordRef. Upon successful completion of this
1102 * call, this ref may be passed to DNSServiceUpdateRecord() or DNSServiceRemoveRecord().
1103 * If the above DNSServiceRef is passed to DNSServiceRefDeallocate(), RecordRef is also
1104 * invalidated and may not be used further.
1106 * flags: Currently ignored, reserved for future use.
1108 * rrtype: The type of the record (e.g. kDNSServiceType_TXT, kDNSServiceType_SRV, etc)
1110 * rdlen: The length, in bytes, of the rdata.
1112 * rdata: The raw rdata to be contained in the added resource record.
1114 * ttl: The time to live of the resource record, in seconds.
1115 * Most clients should pass 0 to indicate that the system should
1116 * select a sensible default value.
1118 * return value: Returns kDNSServiceErr_NoError on success, otherwise returns an
1119 * error code indicating the error that occurred (the RecordRef is not initialized).
1122 DNSServiceErrorType DNSSD_API DNSServiceAddRecord
1124 DNSServiceRef sdRef
,
1125 DNSRecordRef
*RecordRef
,
1126 DNSServiceFlags flags
,
1134 /* DNSServiceUpdateRecord
1136 * Update a registered resource record. The record must either be:
1137 * - The primary txt record of a service registered via DNSServiceRegister()
1138 * - A record added to a registered service via DNSServiceAddRecord()
1139 * - An individual record registered by DNSServiceRegisterRecord()
1143 * sdRef: A DNSServiceRef that was initialized by DNSServiceRegister()
1144 * or DNSServiceCreateConnection().
1146 * RecordRef: A DNSRecordRef initialized by DNSServiceAddRecord, or NULL to update the
1147 * service's primary txt record.
1149 * flags: Currently ignored, reserved for future use.
1151 * rdlen: The length, in bytes, of the new rdata.
1153 * rdata: The new rdata to be contained in the updated resource record.
1155 * ttl: The time to live of the updated resource record, in seconds.
1156 * Most clients should pass 0 to indicate that the system should
1157 * select a sensible default value.
1159 * return value: Returns kDNSServiceErr_NoError on success, otherwise returns an
1160 * error code indicating the error that occurred.
1163 DNSServiceErrorType DNSSD_API DNSServiceUpdateRecord
1165 DNSServiceRef sdRef
,
1166 DNSRecordRef RecordRef
, /* may be NULL */
1167 DNSServiceFlags flags
,
1174 /* DNSServiceRemoveRecord
1176 * Remove a record previously added to a service record set via DNSServiceAddRecord(), or deregister
1177 * an record registered individually via DNSServiceRegisterRecord().
1181 * sdRef: A DNSServiceRef initialized by DNSServiceRegister() (if the
1182 * record being removed was registered via DNSServiceAddRecord()) or by
1183 * DNSServiceCreateConnection() (if the record being removed was registered via
1184 * DNSServiceRegisterRecord()).
1186 * recordRef: A DNSRecordRef initialized by a successful call to DNSServiceAddRecord()
1187 * or DNSServiceRegisterRecord().
1189 * flags: Currently ignored, reserved for future use.
1191 * return value: Returns kDNSServiceErr_NoError on success, otherwise returns an
1192 * error code indicating the error that occurred.
1195 DNSServiceErrorType DNSSD_API DNSServiceRemoveRecord
1197 DNSServiceRef sdRef
,
1198 DNSRecordRef RecordRef
,
1199 DNSServiceFlags flags
1203 /*********************************************************************************************
1207 *********************************************************************************************/
1209 /* Browse for instances of a service.
1211 * DNSServiceBrowseReply() Parameters:
1213 * sdRef: The DNSServiceRef initialized by DNSServiceBrowse().
1215 * flags: Possible values are kDNSServiceFlagsMoreComing and kDNSServiceFlagsAdd.
1216 * See flag definitions for details.
1218 * interfaceIndex: The interface on which the service is advertised. This index should
1219 * be passed to DNSServiceResolve() when resolving the service.
1221 * errorCode: Will be kDNSServiceErr_NoError (0) on success, otherwise will
1222 * indicate the failure that occurred. Other parameters are undefined if
1223 * the errorCode is nonzero.
1225 * serviceName: The discovered service name. This name should be displayed to the user,
1226 * and stored for subsequent use in the DNSServiceResolve() call.
1228 * regtype: The service type, which is usually (but not always) the same as was passed
1229 * to DNSServiceBrowse(). One case where the discovered service type may
1230 * not be the same as the requested service type is when using subtypes:
1231 * The client may want to browse for only those ftp servers that allow
1232 * anonymous connections. The client will pass the string "_ftp._tcp,_anon"
1233 * to DNSServiceBrowse(), but the type of the service that's discovered
1234 * is simply "_ftp._tcp". The regtype for each discovered service instance
1235 * should be stored along with the name, so that it can be passed to
1236 * DNSServiceResolve() when the service is later resolved.
1238 * domain: The domain of the discovered service instance. This may or may not be the
1239 * same as the domain that was passed to DNSServiceBrowse(). The domain for each
1240 * discovered service instance should be stored along with the name, so that
1241 * it can be passed to DNSServiceResolve() when the service is later resolved.
1243 * context: The context pointer that was passed to the callout.
1247 typedef void (DNSSD_API
*DNSServiceBrowseReply
)
1249 DNSServiceRef sdRef
,
1250 DNSServiceFlags flags
,
1251 uint32_t interfaceIndex
,
1252 DNSServiceErrorType errorCode
,
1253 const char *serviceName
,
1254 const char *regtype
,
1255 const char *replyDomain
,
1260 /* DNSServiceBrowse() Parameters:
1262 * sdRef: A pointer to an uninitialized DNSServiceRef. If the call succeeds
1263 * then it initializes the DNSServiceRef, returns kDNSServiceErr_NoError,
1264 * and the browse operation will run indefinitely until the client
1265 * terminates it by passing this DNSServiceRef to DNSServiceRefDeallocate().
1267 * flags: Currently ignored, reserved for future use.
1269 * interfaceIndex: If non-zero, specifies the interface on which to browse for services
1270 * (the index for a given interface is determined via the if_nametoindex()
1271 * family of calls.) Most applications will pass 0 to browse on all available
1272 * interfaces. See "Constants for specifying an interface index" for more details.
1274 * regtype: The service type being browsed for followed by the protocol, separated by a
1275 * dot (e.g. "_ftp._tcp"). The transport protocol must be "_tcp" or "_udp".
1276 * A client may optionally specify a single subtype to perform filtered browsing:
1277 * e.g. browsing for "_primarytype._tcp,_subtype" will discover only those
1278 * instances of "_primarytype._tcp" that were registered specifying "_subtype"
1279 * in their list of registered subtypes.
1281 * domain: If non-NULL, specifies the domain on which to browse for services.
1282 * Most applications will not specify a domain, instead browsing on the
1283 * default domain(s).
1285 * callBack: The function to be called when an instance of the service being browsed for
1286 * is found, or if the call asynchronously fails.
1288 * context: An application context pointer which is passed to the callback function
1291 * return value: Returns kDNSServiceErr_NoError on success (any subsequent, asynchronous
1292 * errors are delivered to the callback), otherwise returns an error code indicating
1293 * the error that occurred (the callback is not invoked and the DNSServiceRef
1294 * is not initialized).
1297 DNSServiceErrorType DNSSD_API DNSServiceBrowse
1299 DNSServiceRef
*sdRef
,
1300 DNSServiceFlags flags
,
1301 uint32_t interfaceIndex
,
1302 const char *regtype
,
1303 const char *domain
, /* may be NULL */
1304 DNSServiceBrowseReply callBack
,
1305 void *context
/* may be NULL */
1309 /* DNSServiceResolve()
1311 * Resolve a service name discovered via DNSServiceBrowse() to a target host name, port number, and
1314 * Note: Applications should NOT use DNSServiceResolve() solely for txt record monitoring - use
1315 * DNSServiceQueryRecord() instead, as it is more efficient for this task.
1317 * Note: When the desired results have been returned, the client MUST terminate the resolve by calling
1318 * DNSServiceRefDeallocate().
1320 * Note: DNSServiceResolve() behaves correctly for typical services that have a single SRV record
1321 * and a single TXT record. To resolve non-standard services with multiple SRV or TXT records,
1322 * DNSServiceQueryRecord() should be used.
1324 * DNSServiceResolveReply Callback Parameters:
1326 * sdRef: The DNSServiceRef initialized by DNSServiceResolve().
1328 * flags: Possible values: kDNSServiceFlagsMoreComing
1330 * interfaceIndex: The interface on which the service was resolved.
1332 * errorCode: Will be kDNSServiceErr_NoError (0) on success, otherwise will
1333 * indicate the failure that occurred. Other parameters are undefined if
1334 * the errorCode is nonzero.
1336 * fullname: The full service domain name, in the form <servicename>.<protocol>.<domain>.
1337 * (This name is escaped following standard DNS rules, making it suitable for
1338 * passing to standard system DNS APIs such as res_query(), or to the
1339 * special-purpose functions included in this API that take fullname parameters.
1340 * See "Notes on DNS Name Escaping" earlier in this file for more details.)
1342 * hosttarget: The target hostname of the machine providing the service. This name can
1343 * be passed to functions like gethostbyname() to identify the host's IP address.
1345 * port: The port, in network byte order, on which connections are accepted for this service.
1347 * txtLen: The length of the txt record, in bytes.
1349 * txtRecord: The service's primary txt record, in standard txt record format.
1351 * context: The context pointer that was passed to the callout.
1353 * NOTE: In earlier versions of this header file, the txtRecord parameter was declared "const char *"
1354 * This is incorrect, since it contains length bytes which are values in the range 0 to 255, not -128 to +127.
1355 * Depending on your compiler settings, this change may cause signed/unsigned mismatch warnings.
1356 * These should be fixed by updating your own callback function definition to match the corrected
1357 * function signature using "const unsigned char *txtRecord". Making this change may also fix inadvertent
1358 * bugs in your callback function, where it could have incorrectly interpreted a length byte with value 250
1359 * as being -6 instead, with various bad consequences ranging from incorrect operation to software crashes.
1360 * If you need to maintain portable code that will compile cleanly with both the old and new versions of
1361 * this header file, you should update your callback function definition to use the correct unsigned value,
1362 * and then in the place where you pass your callback function to DNSServiceResolve(), use a cast to eliminate
1363 * the compiler warning, e.g.:
1364 * DNSServiceResolve(sd, flags, index, name, regtype, domain, (DNSServiceResolveReply)MyCallback, context);
1365 * This will ensure that your code compiles cleanly without warnings (and more importantly, works correctly)
1366 * with both the old header and with the new corrected version.
1370 typedef void (DNSSD_API
*DNSServiceResolveReply
)
1372 DNSServiceRef sdRef
,
1373 DNSServiceFlags flags
,
1374 uint32_t interfaceIndex
,
1375 DNSServiceErrorType errorCode
,
1376 const char *fullname
,
1377 const char *hosttarget
,
1378 uint16_t port
, /* In network byte order */
1380 const unsigned char *txtRecord
,
1385 /* DNSServiceResolve() Parameters
1387 * sdRef: A pointer to an uninitialized DNSServiceRef. If the call succeeds
1388 * then it initializes the DNSServiceRef, returns kDNSServiceErr_NoError,
1389 * and the resolve operation will run indefinitely until the client
1390 * terminates it by passing this DNSServiceRef to DNSServiceRefDeallocate().
1392 * flags: Specifying kDNSServiceFlagsForceMulticast will cause query to be
1393 * performed with a link-local mDNS query, even if the name is an
1394 * apparently non-local name (i.e. a name not ending in ".local.")
1396 * interfaceIndex: The interface on which to resolve the service. If this resolve call is
1397 * as a result of a currently active DNSServiceBrowse() operation, then the
1398 * interfaceIndex should be the index reported in the DNSServiceBrowseReply
1399 * callback. If this resolve call is using information previously saved
1400 * (e.g. in a preference file) for later use, then use interfaceIndex 0, because
1401 * the desired service may now be reachable via a different physical interface.
1402 * See "Constants for specifying an interface index" for more details.
1404 * name: The name of the service instance to be resolved, as reported to the
1405 * DNSServiceBrowseReply() callback.
1407 * regtype: The type of the service instance to be resolved, as reported to the
1408 * DNSServiceBrowseReply() callback.
1410 * domain: The domain of the service instance to be resolved, as reported to the
1411 * DNSServiceBrowseReply() callback.
1413 * callBack: The function to be called when a result is found, or if the call
1414 * asynchronously fails.
1416 * context: An application context pointer which is passed to the callback function
1419 * return value: Returns kDNSServiceErr_NoError on success (any subsequent, asynchronous
1420 * errors are delivered to the callback), otherwise returns an error code indicating
1421 * the error that occurred (the callback is never invoked and the DNSServiceRef
1422 * is not initialized).
1425 DNSServiceErrorType DNSSD_API DNSServiceResolve
1427 DNSServiceRef
*sdRef
,
1428 DNSServiceFlags flags
,
1429 uint32_t interfaceIndex
,
1431 const char *regtype
,
1433 DNSServiceResolveReply callBack
,
1434 void *context
/* may be NULL */
1438 /*********************************************************************************************
1440 * Querying Individual Specific Records
1442 *********************************************************************************************/
1444 /* DNSServiceQueryRecord
1446 * Query for an arbitrary DNS record.
1448 * DNSServiceQueryRecordReply() Callback Parameters:
1450 * sdRef: The DNSServiceRef initialized by DNSServiceQueryRecord().
1452 * flags: Possible values are kDNSServiceFlagsMoreComing and
1453 * kDNSServiceFlagsAdd. The Add flag is NOT set for PTR records
1454 * with a ttl of 0, i.e. "Remove" events.
1456 * interfaceIndex: The interface on which the query was resolved (the index for a given
1457 * interface is determined via the if_nametoindex() family of calls).
1458 * See "Constants for specifying an interface index" for more details.
1460 * errorCode: Will be kDNSServiceErr_NoError on success, otherwise will
1461 * indicate the failure that occurred. Other parameters are undefined if
1462 * errorCode is nonzero.
1464 * fullname: The resource record's full domain name.
1466 * rrtype: The resource record's type (e.g. kDNSServiceType_PTR, kDNSServiceType_SRV, etc)
1468 * rrclass: The class of the resource record (usually kDNSServiceClass_IN).
1470 * rdlen: The length, in bytes, of the resource record rdata.
1472 * rdata: The raw rdata of the resource record.
1474 * ttl: If the client wishes to cache the result for performance reasons,
1475 * the TTL indicates how long the client may legitimately hold onto
1476 * this result, in seconds. After the TTL expires, the client should
1477 * consider the result no longer valid, and if it requires this data
1478 * again, it should be re-fetched with a new query. Of course, this
1479 * only applies to clients that cancel the asynchronous operation when
1480 * they get a result. Clients that leave the asynchronous operation
1481 * running can safely assume that the data remains valid until they
1482 * get another callback telling them otherwise.
1484 * context: The context pointer that was passed to the callout.
1488 typedef void (DNSSD_API
*DNSServiceQueryRecordReply
)
1490 DNSServiceRef sdRef
,
1491 DNSServiceFlags flags
,
1492 uint32_t interfaceIndex
,
1493 DNSServiceErrorType errorCode
,
1494 const char *fullname
,
1504 /* DNSServiceQueryRecord() Parameters:
1506 * sdRef: A pointer to an uninitialized DNSServiceRef. If the call succeeds
1507 * then it initializes the DNSServiceRef, returns kDNSServiceErr_NoError,
1508 * and the query operation will run indefinitely until the client
1509 * terminates it by passing this DNSServiceRef to DNSServiceRefDeallocate().
1511 * flags: kDNSServiceFlagsForceMulticast or kDNSServiceFlagsLongLivedQuery.
1512 * Pass kDNSServiceFlagsLongLivedQuery to create a "long-lived" unicast
1513 * query to a unicast DNS server that implements the protocol. This flag
1514 * has no effect on link-local multicast queries.
1516 * interfaceIndex: If non-zero, specifies the interface on which to issue the query
1517 * (the index for a given interface is determined via the if_nametoindex()
1518 * family of calls.) Passing 0 causes the name to be queried for on all
1519 * interfaces. See "Constants for specifying an interface index" for more details.
1521 * fullname: The full domain name of the resource record to be queried for.
1523 * rrtype: The numerical type of the resource record to be queried for
1524 * (e.g. kDNSServiceType_PTR, kDNSServiceType_SRV, etc)
1526 * rrclass: The class of the resource record (usually kDNSServiceClass_IN).
1528 * callBack: The function to be called when a result is found, or if the call
1529 * asynchronously fails.
1531 * context: An application context pointer which is passed to the callback function
1534 * return value: Returns kDNSServiceErr_NoError on success (any subsequent, asynchronous
1535 * errors are delivered to the callback), otherwise returns an error code indicating
1536 * the error that occurred (the callback is never invoked and the DNSServiceRef
1537 * is not initialized).
1540 DNSServiceErrorType DNSSD_API DNSServiceQueryRecord
1542 DNSServiceRef
*sdRef
,
1543 DNSServiceFlags flags
,
1544 uint32_t interfaceIndex
,
1545 const char *fullname
,
1548 DNSServiceQueryRecordReply callBack
,
1549 void *context
/* may be NULL */
1553 /*********************************************************************************************
1555 * Unified lookup of both IPv4 and IPv6 addresses for a fully qualified hostname
1557 *********************************************************************************************/
1559 /* DNSServiceGetAddrInfo
1561 * Queries for the IP address of a hostname by using either Multicast or Unicast DNS.
1563 * DNSServiceGetAddrInfoReply() parameters:
1565 * sdRef: The DNSServiceRef initialized by DNSServiceGetAddrInfo().
1567 * flags: Possible values are kDNSServiceFlagsMoreComing and
1568 * kDNSServiceFlagsAdd.
1570 * interfaceIndex: The interface to which the answers pertain.
1572 * errorCode: Will be kDNSServiceErr_NoError on success, otherwise will
1573 * indicate the failure that occurred. Other parameters are
1574 * undefined if errorCode is nonzero.
1576 * hostname: The fully qualified domain name of the host to be queried for.
1578 * address: IPv4 or IPv6 address.
1580 * ttl: If the client wishes to cache the result for performance reasons,
1581 * the TTL indicates how long the client may legitimately hold onto
1582 * this result, in seconds. After the TTL expires, the client should
1583 * consider the result no longer valid, and if it requires this data
1584 * again, it should be re-fetched with a new query. Of course, this
1585 * only applies to clients that cancel the asynchronous operation when
1586 * they get a result. Clients that leave the asynchronous operation
1587 * running can safely assume that the data remains valid until they
1588 * get another callback telling them otherwise.
1590 * context: The context pointer that was passed to the callout.
1594 typedef void (DNSSD_API
*DNSServiceGetAddrInfoReply
)
1596 DNSServiceRef sdRef
,
1597 DNSServiceFlags flags
,
1598 uint32_t interfaceIndex
,
1599 DNSServiceErrorType errorCode
,
1600 const char *hostname
,
1601 const struct sockaddr
*address
,
1607 /* DNSServiceGetAddrInfo() Parameters:
1609 * sdRef: A pointer to an uninitialized DNSServiceRef. If the call succeeds then it
1610 * initializes the DNSServiceRef, returns kDNSServiceErr_NoError, and the query
1611 * begins and will last indefinitely until the client terminates the query
1612 * by passing this DNSServiceRef to DNSServiceRefDeallocate().
1614 * flags: kDNSServiceFlagsForceMulticast or kDNSServiceFlagsLongLivedQuery.
1615 * Pass kDNSServiceFlagsLongLivedQuery to create a "long-lived" unicast
1616 * query to a unicast DNS server that implements the protocol. This flag
1617 * has no effect on link-local multicast queries.
1619 * interfaceIndex: The interface on which to issue the query. Passing 0 causes the query to be
1620 * sent on all active interfaces via Multicast or the primary interface via Unicast.
1622 * protocol: Pass in kDNSServiceProtocol_IPv4 to look up IPv4 addresses, or kDNSServiceProtocol_IPv6
1623 * to look up IPv6 addresses, or both to look up both kinds. If neither flag is
1624 * set, the system will apply an intelligent heuristic, which is (currently)
1625 * that it will attempt to look up both, except:
1627 * * If "hostname" is a wide-area unicast DNS hostname (i.e. not a ".local." name)
1628 * but this host has no routable IPv6 address, then the call will not try to
1629 * look up IPv6 addresses for "hostname", since any addresses it found would be
1630 * unlikely to be of any use anyway. Similarly, if this host has no routable
1631 * IPv4 address, the call will not try to look up IPv4 addresses for "hostname".
1633 * hostname: The fully qualified domain name of the host to be queried for.
1635 * callBack: The function to be called when the query succeeds or fails asynchronously.
1637 * context: An application context pointer which is passed to the callback function
1640 * return value: Returns kDNSServiceErr_NoError on success (any subsequent, asynchronous
1641 * errors are delivered to the callback), otherwise returns an error code indicating
1642 * the error that occurred.
1645 DNSServiceErrorType DNSSD_API DNSServiceGetAddrInfo
1647 DNSServiceRef
*sdRef
,
1648 DNSServiceFlags flags
,
1649 uint32_t interfaceIndex
,
1650 DNSServiceProtocol protocol
,
1651 const char *hostname
,
1652 DNSServiceGetAddrInfoReply callBack
,
1653 void *context
/* may be NULL */
1657 /*********************************************************************************************
1659 * Special Purpose Calls:
1660 * DNSServiceCreateConnection(), DNSServiceRegisterRecord(), DNSServiceReconfirmRecord()
1661 * (most applications will not use these)
1663 *********************************************************************************************/
1665 /* DNSServiceCreateConnection()
1667 * Create a connection to the daemon allowing efficient registration of
1668 * multiple individual records.
1672 * sdRef: A pointer to an uninitialized DNSServiceRef. Deallocating
1673 * the reference (via DNSServiceRefDeallocate()) severs the
1674 * connection and deregisters all records registered on this connection.
1676 * return value: Returns kDNSServiceErr_NoError on success, otherwise returns
1677 * an error code indicating the specific failure that occurred (in which
1678 * case the DNSServiceRef is not initialized).
1681 DNSServiceErrorType DNSSD_API
DNSServiceCreateConnection(DNSServiceRef
*sdRef
);
1684 /* DNSServiceRegisterRecord
1686 * Register an individual resource record on a connected DNSServiceRef.
1688 * Note that name conflicts occurring for records registered via this call must be handled
1689 * by the client in the callback.
1691 * DNSServiceRegisterRecordReply() parameters:
1693 * sdRef: The connected DNSServiceRef initialized by
1694 * DNSServiceCreateConnection().
1696 * RecordRef: The DNSRecordRef initialized by DNSServiceRegisterRecord(). If the above
1697 * DNSServiceRef is passed to DNSServiceRefDeallocate(), this DNSRecordRef is
1698 * invalidated, and may not be used further.
1700 * flags: Currently unused, reserved for future use.
1702 * errorCode: Will be kDNSServiceErr_NoError on success, otherwise will
1703 * indicate the failure that occurred (including name conflicts.)
1704 * Other parameters are undefined if errorCode is nonzero.
1706 * context: The context pointer that was passed to the callout.
1710 typedef void (DNSSD_API
*DNSServiceRegisterRecordReply
)
1712 DNSServiceRef sdRef
,
1713 DNSRecordRef RecordRef
,
1714 DNSServiceFlags flags
,
1715 DNSServiceErrorType errorCode
,
1720 /* DNSServiceRegisterRecord() Parameters:
1722 * sdRef: A DNSServiceRef initialized by DNSServiceCreateConnection().
1724 * RecordRef: A pointer to an uninitialized DNSRecordRef. Upon successful completion of this
1725 * call, this ref may be passed to DNSServiceUpdateRecord() or DNSServiceRemoveRecord().
1726 * (To deregister ALL records registered on a single connected DNSServiceRef
1727 * and deallocate each of their corresponding DNSServiceRecordRefs, call
1728 * DNSServiceRefDeallocate()).
1730 * flags: Possible values are kDNSServiceFlagsShared or kDNSServiceFlagsUnique
1731 * (see flag type definitions for details).
1733 * interfaceIndex: If non-zero, specifies the interface on which to register the record
1734 * (the index for a given interface is determined via the if_nametoindex()
1735 * family of calls.) Passing 0 causes the record to be registered on all interfaces.
1736 * See "Constants for specifying an interface index" for more details.
1738 * fullname: The full domain name of the resource record.
1740 * rrtype: The numerical type of the resource record (e.g. kDNSServiceType_PTR, kDNSServiceType_SRV, etc)
1742 * rrclass: The class of the resource record (usually kDNSServiceClass_IN)
1744 * rdlen: Length, in bytes, of the rdata.
1746 * rdata: A pointer to the raw rdata, as it is to appear in the DNS record.
1748 * ttl: The time to live of the resource record, in seconds.
1749 * Most clients should pass 0 to indicate that the system should
1750 * select a sensible default value.
1752 * callBack: The function to be called when a result is found, or if the call
1753 * asynchronously fails (e.g. because of a name conflict.)
1755 * context: An application context pointer which is passed to the callback function
1758 * return value: Returns kDNSServiceErr_NoError on success (any subsequent, asynchronous
1759 * errors are delivered to the callback), otherwise returns an error code indicating
1760 * the error that occurred (the callback is never invoked and the DNSRecordRef is
1764 DNSServiceErrorType DNSSD_API DNSServiceRegisterRecord
1766 DNSServiceRef sdRef
,
1767 DNSRecordRef
*RecordRef
,
1768 DNSServiceFlags flags
,
1769 uint32_t interfaceIndex
,
1770 const char *fullname
,
1776 DNSServiceRegisterRecordReply callBack
,
1777 void *context
/* may be NULL */
1781 /* DNSServiceReconfirmRecord
1783 * Instruct the daemon to verify the validity of a resource record that appears
1784 * to be out of date (e.g. because TCP connection to a service's target failed.)
1785 * Causes the record to be flushed from the daemon's cache (as well as all other
1786 * daemons' caches on the network) if the record is determined to be invalid.
1787 * Use this routine conservatively. Reconfirming a record necessarily consumes
1788 * network bandwidth, so this should not be done indiscriminately.
1792 * flags: Pass kDNSServiceFlagsForce to force immediate deletion of record,
1793 * instead of after some number of reconfirmation queries have gone unanswered.
1795 * interfaceIndex: Specifies the interface of the record in question.
1796 * The caller must specify the interface.
1797 * This API (by design) causes increased network traffic, so it requires
1798 * the caller to be precise about which record should be reconfirmed.
1799 * It is not possible to pass zero for the interface index to perform
1800 * a "wildcard" reconfirmation, where *all* matching records are reconfirmed.
1802 * fullname: The resource record's full domain name.
1804 * rrtype: The resource record's type (e.g. kDNSServiceType_PTR, kDNSServiceType_SRV, etc)
1806 * rrclass: The class of the resource record (usually kDNSServiceClass_IN).
1808 * rdlen: The length, in bytes, of the resource record rdata.
1810 * rdata: The raw rdata of the resource record.
1814 DNSServiceErrorType DNSSD_API DNSServiceReconfirmRecord
1816 DNSServiceFlags flags
,
1817 uint32_t interfaceIndex
,
1818 const char *fullname
,
1825 /*********************************************************************************************
1829 *********************************************************************************************/
1831 /* DNSServiceNATPortMappingCreate
1833 * Request a port mapping in the NAT gateway, which maps a port on the local machine
1834 * to an external port on the NAT. The NAT should support either the NAT-PMP or the UPnP IGD
1835 * protocol for this API to create a successful mapping.
1837 * The port mapping will be renewed indefinitely until the client process exits, or
1838 * explicitly terminates the port mapping request by calling DNSServiceRefDeallocate().
1839 * The client callback will be invoked, informing the client of the NAT gateway's
1840 * external IP address and the external port that has been allocated for this client.
1841 * The client should then record this external IP address and port using whatever
1842 * directory service mechanism it is using to enable peers to connect to it.
1843 * (Clients advertising services using Wide-Area DNS-SD DO NOT need to use this API
1844 * -- when a client calls DNSServiceRegister() NAT mappings are automatically created
1845 * and the external IP address and port for the service are recorded in the global DNS.
1846 * Only clients using some directory mechanism other than Wide-Area DNS-SD need to use
1847 * this API to explicitly map their own ports.)
1849 * It's possible that the client callback could be called multiple times, for example
1850 * if the NAT gateway's IP address changes, or if a configuration change results in a
1851 * different external port being mapped for this client. Over the lifetime of any long-lived
1852 * port mapping, the client should be prepared to handle these notifications of changes
1853 * in the environment, and should update its recorded address and/or port as appropriate.
1855 * NOTE: There are two unusual aspects of how the DNSServiceNATPortMappingCreate API works,
1856 * which were intentionally designed to help simplify client code:
1858 * 1. It's not an error to request a NAT mapping when the machine is not behind a NAT gateway.
1859 * In other NAT mapping APIs, if you request a NAT mapping and the machine is not behind a NAT
1860 * gateway, then the API returns an error code -- it can't get you a NAT mapping if there's no
1861 * NAT gateway. The DNSServiceNATPortMappingCreate API takes a different view. Working out
1862 * whether or not you need a NAT mapping can be tricky and non-obvious, particularly on
1863 * a machine with multiple active network interfaces. Rather than make every client recreate
1864 * this logic for deciding whether a NAT mapping is required, the PortMapping API does that
1865 * work for you. If the client calls the PortMapping API when the machine already has a
1866 * routable public IP address, then instead of complaining about it and giving an error,
1867 * the PortMapping API just invokes your callback, giving the machine's public address
1868 * and your own port number. This means you don't need to write code to work out whether
1869 * your client needs to call the PortMapping API -- just call it anyway, and if it wasn't
1870 * necessary, no harm is done:
1872 * - If the machine already has a routable public IP address, then your callback
1873 * will just be invoked giving your own address and port.
1874 * - If a NAT mapping is required and obtained, then your callback will be invoked
1875 * giving you the external address and port.
1876 * - If a NAT mapping is required but not obtained from the local NAT gateway,
1877 * or the machine has no network connectivity, then your callback will be
1878 * invoked giving zero address and port.
1880 * 2. In other NAT mapping APIs, if a laptop computer is put to sleep and woken up on a new
1881 * network, it's the client's job to notice this, and work out whether a NAT mapping
1882 * is required on the new network, and make a new NAT mapping request if necessary.
1883 * The DNSServiceNATPortMappingCreate API does this for you, automatically.
1884 * The client just needs to make one call to the PortMapping API, and its callback will
1885 * be invoked any time the mapping state changes. This property complements point (1) above.
1886 * If the client didn't make a NAT mapping request just because it determined that one was
1887 * not required at that particular moment in time, the client would then have to monitor
1888 * for network state changes to determine if a NAT port mapping later became necessary.
1889 * By unconditionally making a NAT mapping request, even when a NAT mapping not to be
1890 * necessary, the PortMapping API will then begin monitoring network state changes on behalf of
1891 * the client, and if a NAT mapping later becomes necessary, it will automatically create a NAT
1892 * mapping and inform the client with a new callback giving the new address and port information.
1894 * DNSServiceNATPortMappingReply() parameters:
1896 * sdRef: The DNSServiceRef initialized by DNSServiceNATPortMappingCreate().
1898 * flags: Currently unused, reserved for future use.
1900 * interfaceIndex: The interface through which the NAT gateway is reached.
1902 * errorCode: Will be kDNSServiceErr_NoError on success.
1903 * Will be kDNSServiceErr_DoubleNAT when the NAT gateway is itself behind one or
1904 * more layers of NAT, in which case the other parameters have the defined values.
1905 * For other failures, will indicate the failure that occurred, and the other
1906 * parameters are undefined.
1908 * externalAddress: Four byte IPv4 address in network byte order.
1910 * protocol: Will be kDNSServiceProtocol_UDP or kDNSServiceProtocol_TCP or both.
1912 * internalPort: The port on the local machine that was mapped.
1914 * externalPort: The actual external port in the NAT gateway that was mapped.
1915 * This is likely to be different than the requested external port.
1917 * ttl: The lifetime of the NAT port mapping created on the gateway.
1918 * This controls how quickly stale mappings will be garbage-collected
1919 * if the client machine crashes, suffers a power failure, is disconnected
1920 * from the network, or suffers some other unfortunate demise which
1921 * causes it to vanish without explicitly removing its NAT port mapping.
1922 * It's possible that the ttl value will differ from the requested ttl value.
1924 * context: The context pointer that was passed to the callout.
1928 typedef void (DNSSD_API
*DNSServiceNATPortMappingReply
)
1930 DNSServiceRef sdRef
,
1931 DNSServiceFlags flags
,
1932 uint32_t interfaceIndex
,
1933 DNSServiceErrorType errorCode
,
1934 uint32_t externalAddress
, /* four byte IPv4 address in network byte order */
1935 DNSServiceProtocol protocol
,
1936 uint16_t internalPort
, /* In network byte order */
1937 uint16_t externalPort
, /* In network byte order and may be different than the requested port */
1938 uint32_t ttl
, /* may be different than the requested ttl */
1943 /* DNSServiceNATPortMappingCreate() Parameters:
1945 * sdRef: A pointer to an uninitialized DNSServiceRef. If the call succeeds then it
1946 * initializes the DNSServiceRef, returns kDNSServiceErr_NoError, and the nat
1947 * port mapping will last indefinitely until the client terminates the port
1948 * mapping request by passing this DNSServiceRef to DNSServiceRefDeallocate().
1950 * flags: Currently ignored, reserved for future use.
1952 * interfaceIndex: The interface on which to create port mappings in a NAT gateway. Passing 0 causes
1953 * the port mapping request to be sent on the primary interface.
1955 * protocol: To request a port mapping, pass in kDNSServiceProtocol_UDP, or kDNSServiceProtocol_TCP,
1956 * or (kDNSServiceProtocol_UDP | kDNSServiceProtocol_TCP) to map both.
1957 * The local listening port number must also be specified in the internalPort parameter.
1958 * To just discover the NAT gateway's external IP address, pass zero for protocol,
1959 * internalPort, externalPort and ttl.
1961 * internalPort: The port number in network byte order on the local machine which is listening for packets.
1963 * externalPort: The requested external port in network byte order in the NAT gateway that you would
1964 * like to map to the internal port. Pass 0 if you don't care which external port is chosen for you.
1966 * ttl: The requested renewal period of the NAT port mapping, in seconds.
1967 * If the client machine crashes, suffers a power failure, is disconnected from
1968 * the network, or suffers some other unfortunate demise which causes it to vanish
1969 * unexpectedly without explicitly removing its NAT port mappings, then the NAT gateway
1970 * will garbage-collect old stale NAT port mappings when their lifetime expires.
1971 * Requesting a short TTL causes such orphaned mappings to be garbage-collected
1972 * more promptly, but consumes system resources and network bandwidth with
1973 * frequent renewal packets to keep the mapping from expiring.
1974 * Requesting a long TTL is more efficient on the network, but in the event of the
1975 * client vanishing, stale NAT port mappings will not be garbage-collected as quickly.
1976 * Most clients should pass 0 to use a system-wide default value.
1978 * callBack: The function to be called when the port mapping request succeeds or fails asynchronously.
1980 * context: An application context pointer which is passed to the callback function
1983 * return value: Returns kDNSServiceErr_NoError on success (any subsequent, asynchronous
1984 * errors are delivered to the callback), otherwise returns an error code indicating
1985 * the error that occurred.
1987 * If you don't actually want a port mapped, and are just calling the API
1988 * because you want to find out the NAT's external IP address (e.g. for UI
1989 * display) then pass zero for protocol, internalPort, externalPort and ttl.
1992 DNSServiceErrorType DNSSD_API DNSServiceNATPortMappingCreate
1994 DNSServiceRef
*sdRef
,
1995 DNSServiceFlags flags
,
1996 uint32_t interfaceIndex
,
1997 DNSServiceProtocol protocol
, /* TCP and/or UDP */
1998 uint16_t internalPort
, /* network byte order */
1999 uint16_t externalPort
, /* network byte order */
2000 uint32_t ttl
, /* time to live in seconds */
2001 DNSServiceNATPortMappingReply callBack
,
2002 void *context
/* may be NULL */
2006 /*********************************************************************************************
2008 * General Utility Functions
2010 *********************************************************************************************/
2012 /* DNSServiceConstructFullName()
2014 * Concatenate a three-part domain name (as returned by the above callbacks) into a
2015 * properly-escaped full domain name. Note that callbacks in the above functions ALREADY ESCAPE
2016 * strings where necessary.
2020 * fullName: A pointer to a buffer that where the resulting full domain name is to be written.
2021 * The buffer must be kDNSServiceMaxDomainName (1009) bytes in length to
2022 * accommodate the longest legal domain name without buffer overrun.
2024 * service: The service name - any dots or backslashes must NOT be escaped.
2025 * May be NULL (to construct a PTR record name, e.g.
2026 * "_ftp._tcp.apple.com.").
2028 * regtype: The service type followed by the protocol, separated by a dot
2029 * (e.g. "_ftp._tcp").
2031 * domain: The domain name, e.g. "apple.com.". Literal dots or backslashes,
2032 * if any, must be escaped, e.g. "1st\. Floor.apple.com."
2034 * return value: Returns kDNSServiceErr_NoError (0) on success, kDNSServiceErr_BadParam on error.
2038 DNSServiceErrorType DNSSD_API DNSServiceConstructFullName
2040 char * const fullName
,
2041 const char * const service
, /* may be NULL */
2042 const char * const regtype
,
2043 const char * const domain
2047 /*********************************************************************************************
2049 * TXT Record Construction Functions
2051 *********************************************************************************************/
2054 * A typical calling sequence for TXT record construction is something like:
2056 * Client allocates storage for TXTRecord data (e.g. declare buffer on the stack)
2057 * TXTRecordCreate();
2058 * TXTRecordSetValue();
2059 * TXTRecordSetValue();
2060 * TXTRecordSetValue();
2062 * DNSServiceRegister( ... TXTRecordGetLength(), TXTRecordGetBytesPtr() ... );
2063 * TXTRecordDeallocate();
2064 * Explicitly deallocate storage for TXTRecord data (if not allocated on the stack)
2070 * Opaque internal data type.
2071 * Note: Represents a DNS-SD TXT record.
2074 typedef union _TXTRecordRef_t
{ char PrivateData
[16]; char *ForceNaturalAlignment
; } TXTRecordRef
;
2077 /* TXTRecordCreate()
2079 * Creates a new empty TXTRecordRef referencing the specified storage.
2081 * If the buffer parameter is NULL, or the specified storage size is not
2082 * large enough to hold a key subsequently added using TXTRecordSetValue(),
2083 * then additional memory will be added as needed using malloc().
2085 * On some platforms, when memory is low, malloc() may fail. In this
2086 * case, TXTRecordSetValue() will return kDNSServiceErr_NoMemory, and this
2087 * error condition will need to be handled as appropriate by the caller.
2089 * You can avoid the need to handle this error condition if you ensure
2090 * that the storage you initially provide is large enough to hold all
2091 * the key/value pairs that are to be added to the record.
2092 * The caller can precompute the exact length required for all of the
2093 * key/value pairs to be added, or simply provide a fixed-sized buffer
2094 * known in advance to be large enough.
2095 * A no-value (key-only) key requires (1 + key length) bytes.
2096 * A key with empty value requires (1 + key length + 1) bytes.
2097 * A key with non-empty value requires (1 + key length + 1 + value length).
2098 * For most applications, DNS-SD TXT records are generally
2099 * less than 100 bytes, so in most cases a simple fixed-sized
2100 * 256-byte buffer will be more than sufficient.
2101 * Recommended size limits for DNS-SD TXT Records are discussed in
2102 * <http://files.dns-sd.org/draft-cheshire-dnsext-dns-sd.txt>
2104 * Note: When passing parameters to and from these TXT record APIs,
2105 * the key name does not include the '=' character. The '=' character
2106 * is the separator between the key and value in the on-the-wire
2107 * packet format; it is not part of either the key or the value.
2109 * txtRecord: A pointer to an uninitialized TXTRecordRef.
2111 * bufferLen: The size of the storage provided in the "buffer" parameter.
2113 * buffer: Optional caller-supplied storage used to hold the TXTRecord data.
2114 * This storage must remain valid for as long as
2118 void DNSSD_API TXTRecordCreate
2120 TXTRecordRef
*txtRecord
,
2126 /* TXTRecordDeallocate()
2128 * Releases any resources allocated in the course of preparing a TXT Record
2129 * using TXTRecordCreate()/TXTRecordSetValue()/TXTRecordRemoveValue().
2130 * Ownership of the buffer provided in TXTRecordCreate() returns to the client.
2132 * txtRecord: A TXTRecordRef initialized by calling TXTRecordCreate().
2136 void DNSSD_API TXTRecordDeallocate
2138 TXTRecordRef
*txtRecord
2142 /* TXTRecordSetValue()
2144 * Adds a key (optionally with value) to a TXTRecordRef. If the "key" already
2145 * exists in the TXTRecordRef, then the current value will be replaced with
2147 * Keys may exist in four states with respect to a given TXT record:
2148 * - Absent (key does not appear at all)
2149 * - Present with no value ("key" appears alone)
2150 * - Present with empty value ("key=" appears in TXT record)
2151 * - Present with non-empty value ("key=value" appears in TXT record)
2152 * For more details refer to "Data Syntax for DNS-SD TXT Records" in
2153 * <http://files.dns-sd.org/draft-cheshire-dnsext-dns-sd.txt>
2155 * txtRecord: A TXTRecordRef initialized by calling TXTRecordCreate().
2157 * key: A null-terminated string which only contains printable ASCII
2158 * values (0x20-0x7E), excluding '=' (0x3D). Keys should be
2159 * 9 characters or fewer (not counting the terminating null).
2161 * valueSize: The size of the value.
2163 * value: Any binary value. For values that represent
2164 * textual data, UTF-8 is STRONGLY recommended.
2165 * For values that represent textual data, valueSize
2166 * should NOT include the terminating null (if any)
2167 * at the end of the string.
2168 * If NULL, then "key" will be added with no value.
2169 * If non-NULL but valueSize is zero, then "key=" will be
2170 * added with empty value.
2172 * return value: Returns kDNSServiceErr_NoError on success.
2173 * Returns kDNSServiceErr_Invalid if the "key" string contains
2174 * illegal characters.
2175 * Returns kDNSServiceErr_NoMemory if adding this key would
2176 * exceed the available storage.
2179 DNSServiceErrorType DNSSD_API TXTRecordSetValue
2181 TXTRecordRef
*txtRecord
,
2183 uint8_t valueSize
, /* may be zero */
2184 const void *value
/* may be NULL */
2188 /* TXTRecordRemoveValue()
2190 * Removes a key from a TXTRecordRef. The "key" must be an
2191 * ASCII string which exists in the TXTRecordRef.
2193 * txtRecord: A TXTRecordRef initialized by calling TXTRecordCreate().
2195 * key: A key name which exists in the TXTRecordRef.
2197 * return value: Returns kDNSServiceErr_NoError on success.
2198 * Returns kDNSServiceErr_NoSuchKey if the "key" does not
2199 * exist in the TXTRecordRef.
2202 DNSServiceErrorType DNSSD_API TXTRecordRemoveValue
2204 TXTRecordRef
*txtRecord
,
2209 /* TXTRecordGetLength()
2211 * Allows you to determine the length of the raw bytes within a TXTRecordRef.
2213 * txtRecord: A TXTRecordRef initialized by calling TXTRecordCreate().
2215 * return value: Returns the size of the raw bytes inside a TXTRecordRef
2216 * which you can pass directly to DNSServiceRegister() or
2217 * to DNSServiceUpdateRecord().
2218 * Returns 0 if the TXTRecordRef is empty.
2221 uint16_t DNSSD_API TXTRecordGetLength
2223 const TXTRecordRef
*txtRecord
2227 /* TXTRecordGetBytesPtr()
2229 * Allows you to retrieve a pointer to the raw bytes within a TXTRecordRef.
2231 * txtRecord: A TXTRecordRef initialized by calling TXTRecordCreate().
2233 * return value: Returns a pointer to the raw bytes inside the TXTRecordRef
2234 * which you can pass directly to DNSServiceRegister() or
2235 * to DNSServiceUpdateRecord().
2238 const void * DNSSD_API TXTRecordGetBytesPtr
2240 const TXTRecordRef
*txtRecord
2244 /*********************************************************************************************
2246 * TXT Record Parsing Functions
2248 *********************************************************************************************/
2251 * A typical calling sequence for TXT record parsing is something like:
2253 * Receive TXT record data in DNSServiceResolve() callback
2254 * if (TXTRecordContainsKey(txtLen, txtRecord, "key")) then do something
2255 * val1ptr = TXTRecordGetValuePtr(txtLen, txtRecord, "key1", &len1);
2256 * val2ptr = TXTRecordGetValuePtr(txtLen, txtRecord, "key2", &len2);
2258 * memcpy(myval1, val1ptr, len1);
2259 * memcpy(myval2, val2ptr, len2);
2263 * If you wish to retain the values after return from the DNSServiceResolve()
2264 * callback, then you need to copy the data to your own storage using memcpy()
2265 * or similar, as shown in the example above.
2267 * If for some reason you need to parse a TXT record you built yourself
2268 * using the TXT record construction functions above, then you can do
2269 * that using TXTRecordGetLength and TXTRecordGetBytesPtr calls:
2270 * TXTRecordGetValue(TXTRecordGetLength(x), TXTRecordGetBytesPtr(x), key, &len);
2272 * Most applications only fetch keys they know about from a TXT record and
2274 * However, some debugging tools wish to fetch and display all keys.
2275 * To do that, use the TXTRecordGetCount() and TXTRecordGetItemAtIndex() calls.
2278 /* TXTRecordContainsKey()
2280 * Allows you to determine if a given TXT Record contains a specified key.
2282 * txtLen: The size of the received TXT Record.
2284 * txtRecord: Pointer to the received TXT Record bytes.
2286 * key: A null-terminated ASCII string containing the key name.
2288 * return value: Returns 1 if the TXT Record contains the specified key.
2289 * Otherwise, it returns 0.
2292 int DNSSD_API TXTRecordContainsKey
2295 const void *txtRecord
,
2300 /* TXTRecordGetValuePtr()
2302 * Allows you to retrieve the value for a given key from a TXT Record.
2304 * txtLen: The size of the received TXT Record
2306 * txtRecord: Pointer to the received TXT Record bytes.
2308 * key: A null-terminated ASCII string containing the key name.
2310 * valueLen: On output, will be set to the size of the "value" data.
2312 * return value: Returns NULL if the key does not exist in this TXT record,
2313 * or exists with no value (to differentiate between
2314 * these two cases use TXTRecordContainsKey()).
2315 * Returns pointer to location within TXT Record bytes
2316 * if the key exists with empty or non-empty value.
2317 * For empty value, valueLen will be zero.
2318 * For non-empty value, valueLen will be length of value data.
2321 const void * DNSSD_API TXTRecordGetValuePtr
2324 const void *txtRecord
,
2330 /* TXTRecordGetCount()
2332 * Returns the number of keys stored in the TXT Record. The count
2333 * can be used with TXTRecordGetItemAtIndex() to iterate through the keys.
2335 * txtLen: The size of the received TXT Record.
2337 * txtRecord: Pointer to the received TXT Record bytes.
2339 * return value: Returns the total number of keys in the TXT Record.
2343 uint16_t DNSSD_API TXTRecordGetCount
2346 const void *txtRecord
2350 /* TXTRecordGetItemAtIndex()
2352 * Allows you to retrieve a key name and value pointer, given an index into
2353 * a TXT Record. Legal index values range from zero to TXTRecordGetCount()-1.
2354 * It's also possible to iterate through keys in a TXT record by simply
2355 * calling TXTRecordGetItemAtIndex() repeatedly, beginning with index zero
2356 * and increasing until TXTRecordGetItemAtIndex() returns kDNSServiceErr_Invalid.
2359 * For keys with no value, *value is set to NULL and *valueLen is zero.
2360 * For keys with empty value, *value is non-NULL and *valueLen is zero.
2361 * For keys with non-empty value, *value is non-NULL and *valueLen is non-zero.
2363 * txtLen: The size of the received TXT Record.
2365 * txtRecord: Pointer to the received TXT Record bytes.
2367 * itemIndex: An index into the TXT Record.
2369 * keyBufLen: The size of the string buffer being supplied.
2371 * key: A string buffer used to store the key name.
2372 * On return, the buffer contains a null-terminated C string
2373 * giving the key name. DNS-SD TXT keys are usually
2374 * 9 characters or fewer. To hold the maximum possible
2375 * key name, the buffer should be 256 bytes long.
2377 * valueLen: On output, will be set to the size of the "value" data.
2379 * value: On output, *value is set to point to location within TXT
2380 * Record bytes that holds the value data.
2382 * return value: Returns kDNSServiceErr_NoError on success.
2383 * Returns kDNSServiceErr_NoMemory if keyBufLen is too short.
2384 * Returns kDNSServiceErr_Invalid if index is greater than
2385 * TXTRecordGetCount()-1.
2388 DNSServiceErrorType DNSSD_API TXTRecordGetItemAtIndex
2391 const void *txtRecord
,
2399 #if _DNS_SD_LIBDISPATCH
2401 * DNSServiceSetDispatchQueue
2403 * Allows you to schedule a DNSServiceRef on a serial dispatch queue for receiving asynchronous
2404 * callbacks. It's the clients responsibility to ensure that the provided dispatch queue is running.
2406 * A typical application that uses CFRunLoopRun or dispatch_main on its main thread will
2407 * usually schedule DNSServiceRefs on its main queue (which is always a serial queue)
2408 * using "DNSServiceSetDispatchQueue(sdref, dispatch_get_main_queue());"
2410 * If there is any error during the processing of events, the application callback will
2411 * be called with an error code. For shared connections, each subordinate DNSServiceRef
2412 * will get its own error callback. Currently these error callbacks only happen
2413 * if the mDNSResponder daemon is manually terminated or crashes, and the error
2414 * code in this case is kDNSServiceErr_ServiceNotRunning. The application must call
2415 * DNSServiceRefDeallocate to free the DNSServiceRef when it gets such an error code.
2416 * These error callbacks are rare and should not normally happen on customer machines,
2417 * but application code should be written defensively to handle such error callbacks
2418 * gracefully if they occur.
2420 * After using DNSServiceSetDispatchQueue on a DNSServiceRef, calling DNSServiceProcessResult
2421 * on the same DNSServiceRef will result in undefined behavior and should be avoided.
2423 * Once the application successfully schedules a DNSServiceRef on a serial dispatch queue using
2424 * DNSServiceSetDispatchQueue, it cannot remove the DNSServiceRef from the dispatch queue, or use
2425 * DNSServiceSetDispatchQueue a second time to schedule the DNSServiceRef onto a different serial dispatch
2426 * queue. Once scheduled onto a dispatch queue a DNSServiceRef will deliver events to that queue until
2427 * the application no longer requires that operation and terminates it using DNSServiceRefDeallocate.
2429 * service: DNSServiceRef that was allocated and returned to the application, when the
2430 * application calls one of the DNSService API.
2432 * queue: dispatch queue where the application callback will be scheduled
2434 * return value: Returns kDNSServiceErr_NoError on success.
2435 * Returns kDNSServiceErr_NoMemory if it cannot create a dispatch source
2436 * Returns kDNSServiceErr_BadParam if the service param is invalid or the
2437 * queue param is invalid
2440 DNSServiceErrorType DNSSD_API DNSServiceSetDispatchQueue
2442 DNSServiceRef service
,
2443 dispatch_queue_t queue
2445 #endif //_DNS_SD_LIBDISPATCH
2447 #if !defined(_WIN32)
2448 typedef void (DNSSD_API
*DNSServiceSleepKeepaliveReply
)
2450 DNSServiceRef sdRef
,
2451 DNSServiceErrorType errorCode
,
2454 DNSServiceErrorType DNSSD_API DNSServiceSleepKeepalive
2456 DNSServiceRef
*sdRef
,
2457 DNSServiceFlags flags
,
2459 unsigned int timeout
,
2460 DNSServiceSleepKeepaliveReply callBack
,
2465 #ifdef __APPLE_API_PRIVATE
2468 #endif //__APPLE_API_PRIVATE
2470 /* Some C compiler cleverness. We can make the compiler check certain things for us,
2471 * and report errors at compile-time if anything is wrong. The usual way to do this would
2472 * be to use a run-time "if" statement or the conventional run-time "assert" mechanism, but
2473 * then you don't find out what's wrong until you run the software. This way, if the assertion
2474 * condition is false, the array size is negative, and the compiler complains immediately.
2477 struct CompileTimeAssertionChecks_DNS_SD
2479 char assert0
[(sizeof(union _TXTRecordRef_t
) == 16) ? 1 : -1];
2486 #endif /* _DNS_SD_H */