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