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