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