]> git.saurik.com Git - apple/mdnsresponder.git/blob - mDNSShared/dns_sd.h
mDNSResponder-176.2.tar.gz
[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 1760200
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, /* 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 kDNSServiceErr_NoRouter = -65566, /* No router currently configured (probably no network connectivity) */
449 kDNSServiceErr_PollingMode = -65567
450
451 /* mDNS Error codes are in the range
452 * FFFE FF00 (-65792) to FFFE FFFF (-65537) */
453 };
454
455 /* Maximum length, in bytes, of a service name represented as a */
456 /* literal C-String, including the terminating NULL at the end. */
457
458 #define kDNSServiceMaxServiceName 64
459
460 /* Maximum length, in bytes, of a domain name represented as an *escaped* C-String */
461 /* including the final trailing dot, and the C-String terminating NULL at the end. */
462
463 #define kDNSServiceMaxDomainName 1005
464
465 /*
466 * Notes on DNS Name Escaping
467 * -- or --
468 * "Why is kDNSServiceMaxDomainName 1005, when the maximum legal domain name is 255 bytes?"
469 *
470 * All strings used in DNS-SD are UTF-8 strings.
471 * With few exceptions, most are also escaped using standard DNS escaping rules:
472 *
473 * '\\' represents a single literal '\' in the name
474 * '\.' represents a single literal '.' in the name
475 * '\ddd', where ddd is a three-digit decimal value from 000 to 255,
476 * represents a single literal byte with that value.
477 * A bare unescaped '.' is a label separator, marking a boundary between domain and subdomain.
478 *
479 * The exceptions, that do not use escaping, are the routines where the full
480 * DNS name of a resource is broken, for convenience, into servicename/regtype/domain.
481 * In these routines, the "servicename" is NOT escaped. It does not need to be, since
482 * it is, by definition, just a single literal string. Any characters in that string
483 * represent exactly what they are. The "regtype" portion is, technically speaking,
484 * escaped, but since legal regtypes are only allowed to contain letters, digits,
485 * and hyphens, there is nothing to escape, so the issue is moot. The "domain"
486 * portion is also escaped, though most domains in use on the public Internet
487 * today, like regtypes, don't contain any characters that need to be escaped.
488 * As DNS-SD becomes more popular, rich-text domains for service discovery will
489 * become common, so software should be written to cope with domains with escaping.
490 *
491 * The servicename may be up to 63 bytes of UTF-8 text (not counting the C-String
492 * terminating NULL at the end). The regtype is of the form _service._tcp or
493 * _service._udp, where the "service" part is 1-14 characters, which may be
494 * letters, digits, or hyphens. The domain part of the three-part name may be
495 * any legal domain, providing that the resulting servicename+regtype+domain
496 * name does not exceed 255 bytes.
497 *
498 * For most software, these issues are transparent. When browsing, the discovered
499 * servicenames should simply be displayed as-is. When resolving, the discovered
500 * servicename/regtype/domain are simply passed unchanged to DNSServiceResolve().
501 * When a DNSServiceResolve() succeeds, the returned fullname is already in
502 * the correct format to pass to standard system DNS APIs such as res_query().
503 * For converting from servicename/regtype/domain to a single properly-escaped
504 * full DNS name, the helper function DNSServiceConstructFullName() is provided.
505 *
506 * The following (highly contrived) example illustrates the escaping process.
507 * Suppose you have an service called "Dr. Smith\Dr. Johnson", of type "_ftp._tcp"
508 * in subdomain "4th. Floor" of subdomain "Building 2" of domain "apple.com."
509 * The full (escaped) DNS name of this service's SRV record would be:
510 * Dr\.\032Smith\\Dr\.\032Johnson._ftp._tcp.4th\.\032Floor.Building\0322.apple.com.
511 */
512
513
514 /*
515 * Constants for specifying an interface index
516 *
517 * Specific interface indexes are identified via a 32-bit unsigned integer returned
518 * by the if_nametoindex() family of calls.
519 *
520 * If the client passes 0 for interface index, that means "do the right thing",
521 * which (at present) means, "if the name is in an mDNS local multicast domain
522 * (e.g. 'local.', '254.169.in-addr.arpa.', '{8,9,A,B}.E.F.ip6.arpa.') then multicast
523 * on all applicable interfaces, otherwise send via unicast to the appropriate
524 * DNS server." Normally, most clients will use 0 for interface index to
525 * automatically get the default sensible behaviour.
526 *
527 * If the client passes a positive interface index, then for multicast names that
528 * indicates to do the operation only on that one interface. For unicast names the
529 * interface index is ignored unless kDNSServiceFlagsForceMulticast is also set.
530 *
531 * If the client passes kDNSServiceInterfaceIndexLocalOnly when registering
532 * a service, then that service will be found *only* by other local clients
533 * on the same machine that are browsing using kDNSServiceInterfaceIndexLocalOnly
534 * or kDNSServiceInterfaceIndexAny.
535 * If a client has a 'private' service, accessible only to other processes
536 * running on the same machine, this allows the client to advertise that service
537 * in a way such that it does not inadvertently appear in service lists on
538 * all the other machines on the network.
539 *
540 * If the client passes kDNSServiceInterfaceIndexLocalOnly when browsing
541 * then it will find *all* records registered on that same local machine.
542 * Clients explicitly wishing to discover *only* LocalOnly services can
543 * accomplish this by inspecting the interfaceIndex of each service reported
544 * to their DNSServiceBrowseReply() callback function, and discarding those
545 * where the interface index is not kDNSServiceInterfaceIndexLocalOnly.
546 */
547
548 #define kDNSServiceInterfaceIndexAny 0
549 #define kDNSServiceInterfaceIndexLocalOnly ((uint32_t)-1)
550 #define kDNSServiceInterfaceIndexUnicast ((uint32_t)-2)
551
552 typedef uint32_t DNSServiceFlags;
553 typedef uint32_t DNSServiceProtocol;
554 typedef int32_t DNSServiceErrorType;
555
556
557 /*********************************************************************************************
558 *
559 * Version checking
560 *
561 *********************************************************************************************/
562
563 /* DNSServiceGetProperty() Parameters:
564 *
565 * property: The requested property.
566 * Currently the only property defined is kDNSServiceProperty_DaemonVersion.
567 *
568 * result: Place to store result.
569 * For retrieving DaemonVersion, this should be the address of a uint32_t.
570 *
571 * size: Pointer to uint32_t containing size of the result location.
572 * For retrieving DaemonVersion, this should be sizeof(uint32_t).
573 * On return the uint32_t is updated to the size of the data returned.
574 * For DaemonVersion, the returned size is always sizeof(uint32_t), but
575 * future properties could be defined which return variable-sized results.
576 *
577 * return value: Returns kDNSServiceErr_NoError on success, or kDNSServiceErr_ServiceNotRunning
578 * if the daemon (or "system service" on Windows) is not running.
579 */
580
581 DNSServiceErrorType DNSSD_API DNSServiceGetProperty
582 (
583 const char *property, /* Requested property (i.e. kDNSServiceProperty_DaemonVersion) */
584 void *result, /* Pointer to place to store result */
585 uint32_t *size /* size of result location */
586 );
587
588 /*
589 * When requesting kDNSServiceProperty_DaemonVersion, the result pointer must point
590 * to a 32-bit unsigned integer, and the size parameter must be set to sizeof(uint32_t).
591 *
592 * On return, the 32-bit unsigned integer contains the version number, formatted as follows:
593 * Major part of the build number * 10000 +
594 * minor part of the build number * 100
595 *
596 * For example, Mac OS X 10.4.9 has mDNSResponder-108.4, which would be represented as
597 * version 1080400. This allows applications to do simple greater-than and less-than comparisons:
598 * e.g. an application that requires at least mDNSResponder-108.4 can check:
599 *
600 * if (version >= 1080400) ...
601 *
602 * Example usage:
603 *
604 * uint32_t version;
605 * uint32_t size = sizeof(version);
606 * DNSServiceErrorType err = DNSServiceGetProperty(kDNSServiceProperty_DaemonVersion, &version, &size);
607 * if (!err) printf("Bonjour version is %d.%d\n", version / 10000, version / 100 % 100);
608 */
609
610 #define kDNSServiceProperty_DaemonVersion "DaemonVersion"
611
612
613 /*********************************************************************************************
614 *
615 * Unix Domain Socket access, DNSServiceRef deallocation, and data processing functions
616 *
617 *********************************************************************************************/
618
619 /* DNSServiceRefSockFD()
620 *
621 * Access underlying Unix domain socket for an initialized DNSServiceRef.
622 * The DNS Service Discovery implementation uses this socket to communicate between the client and
623 * the mDNSResponder daemon. The application MUST NOT directly read from or write to this socket.
624 * Access to the socket is provided so that it can be used as a kqueue event source, a CFRunLoop
625 * event source, in a select() loop, etc. When the underlying event management subsystem (kqueue/
626 * select/CFRunLoop etc.) indicates to the client that data is available for reading on the
627 * socket, the client should call DNSServiceProcessResult(), which will extract the daemon's
628 * reply from the socket, and pass it to the appropriate application callback. By using a run
629 * loop or select(), results from the daemon can be processed asynchronously. Alternatively,
630 * a client can choose to fork a thread and have it loop calling "DNSServiceProcessResult(ref);"
631 * If DNSServiceProcessResult() is called when no data is available for reading on the socket, it
632 * will block until data does become available, and then process the data and return to the caller.
633 * When data arrives on the socket, the client is responsible for calling DNSServiceProcessResult(ref)
634 * in a timely fashion -- if the client allows a large backlog of data to build up the daemon
635 * may terminate the connection.
636 *
637 * sdRef: A DNSServiceRef initialized by any of the DNSService calls.
638 *
639 * return value: The DNSServiceRef's underlying socket descriptor, or -1 on
640 * error.
641 */
642
643 int DNSSD_API DNSServiceRefSockFD(DNSServiceRef sdRef);
644
645
646 /* DNSServiceProcessResult()
647 *
648 * Read a reply from the daemon, calling the appropriate application callback. This call will
649 * block until the daemon's response is received. Use DNSServiceRefSockFD() in
650 * conjunction with a run loop or select() to determine the presence of a response from the
651 * server before calling this function to process the reply without blocking. Call this function
652 * at any point if it is acceptable to block until the daemon's response arrives. Note that the
653 * client is responsible for ensuring that DNSServiceProcessResult() is called whenever there is
654 * a reply from the daemon - the daemon may terminate its connection with a client that does not
655 * process the daemon's responses.
656 *
657 * sdRef: A DNSServiceRef initialized by any of the DNSService calls
658 * that take a callback parameter.
659 *
660 * return value: Returns kDNSServiceErr_NoError on success, otherwise returns
661 * an error code indicating the specific failure that occurred.
662 */
663
664 DNSServiceErrorType DNSSD_API DNSServiceProcessResult(DNSServiceRef sdRef);
665
666
667 /* DNSServiceRefDeallocate()
668 *
669 * Terminate a connection with the daemon and free memory associated with the DNSServiceRef.
670 * Any services or records registered with this DNSServiceRef will be deregistered. Any
671 * Browse, Resolve, or Query operations called with this reference will be terminated.
672 *
673 * Note: If the reference's underlying socket is used in a run loop or select() call, it should
674 * be removed BEFORE DNSServiceRefDeallocate() is called, as this function closes the reference's
675 * socket.
676 *
677 * Note: If the reference was initialized with DNSServiceCreateConnection(), any DNSRecordRefs
678 * created via this reference will be invalidated by this call - the resource records are
679 * deregistered, and their DNSRecordRefs may not be used in subsequent functions. Similarly,
680 * if the reference was initialized with DNSServiceRegister, and an extra resource record was
681 * added to the service via DNSServiceAddRecord(), the DNSRecordRef created by the Add() call
682 * is invalidated when this function is called - the DNSRecordRef may not be used in subsequent
683 * functions.
684 *
685 * Note: This call is to be used only with the DNSServiceRef defined by this API. It is
686 * not compatible with dns_service_discovery_ref objects defined in the legacy Mach-based
687 * DNSServiceDiscovery.h API.
688 *
689 * sdRef: A DNSServiceRef initialized by any of the DNSService calls.
690 *
691 */
692
693 void DNSSD_API DNSServiceRefDeallocate(DNSServiceRef sdRef);
694
695
696 /*********************************************************************************************
697 *
698 * Domain Enumeration
699 *
700 *********************************************************************************************/
701
702 /* DNSServiceEnumerateDomains()
703 *
704 * Asynchronously enumerate domains available for browsing and registration.
705 *
706 * The enumeration MUST be cancelled via DNSServiceRefDeallocate() when no more domains
707 * are to be found.
708 *
709 * Note that the names returned are (like all of DNS-SD) UTF-8 strings,
710 * and are escaped using standard DNS escaping rules.
711 * (See "Notes on DNS Name Escaping" earlier in this file for more details.)
712 * A graphical browser displaying a hierarchical tree-structured view should cut
713 * the names at the bare dots to yield individual labels, then de-escape each
714 * label according to the escaping rules, and then display the resulting UTF-8 text.
715 *
716 * DNSServiceDomainEnumReply Callback Parameters:
717 *
718 * sdRef: The DNSServiceRef initialized by DNSServiceEnumerateDomains().
719 *
720 * flags: Possible values are:
721 * kDNSServiceFlagsMoreComing
722 * kDNSServiceFlagsAdd
723 * kDNSServiceFlagsDefault
724 *
725 * interfaceIndex: Specifies the interface on which the domain exists. (The index for a given
726 * interface is determined via the if_nametoindex() family of calls.)
727 *
728 * errorCode: Will be kDNSServiceErr_NoError (0) on success, otherwise indicates
729 * the failure that occurred (other parameters are undefined if errorCode is nonzero).
730 *
731 * replyDomain: The name of the domain.
732 *
733 * context: The context pointer passed to DNSServiceEnumerateDomains.
734 *
735 */
736
737 typedef void (DNSSD_API *DNSServiceDomainEnumReply)
738 (
739 DNSServiceRef sdRef,
740 DNSServiceFlags flags,
741 uint32_t interfaceIndex,
742 DNSServiceErrorType errorCode,
743 const char *replyDomain,
744 void *context
745 );
746
747
748 /* DNSServiceEnumerateDomains() Parameters:
749 *
750 * sdRef: A pointer to an uninitialized DNSServiceRef. If the call succeeds
751 * then it initializes the DNSServiceRef, returns kDNSServiceErr_NoError,
752 * and the enumeration operation will run indefinitely until the client
753 * terminates it by passing this DNSServiceRef to DNSServiceRefDeallocate().
754 *
755 * flags: Possible values are:
756 * kDNSServiceFlagsBrowseDomains to enumerate domains recommended for browsing.
757 * kDNSServiceFlagsRegistrationDomains to enumerate domains recommended
758 * for registration.
759 *
760 * interfaceIndex: If non-zero, specifies the interface on which to look for domains.
761 * (the index for a given interface is determined via the if_nametoindex()
762 * family of calls.) Most applications will pass 0 to enumerate domains on
763 * all interfaces. See "Constants for specifying an interface index" for more details.
764 *
765 * callBack: The function to be called when a domain is found or the call asynchronously
766 * fails.
767 *
768 * context: An application context pointer which is passed to the callback function
769 * (may be NULL).
770 *
771 * return value: Returns kDNSServiceErr_NoError on success (any subsequent, asynchronous
772 * errors are delivered to the callback), otherwise returns an error code indicating
773 * the error that occurred (the callback is not invoked and the DNSServiceRef
774 * is not initialized).
775 */
776
777 DNSServiceErrorType DNSSD_API DNSServiceEnumerateDomains
778 (
779 DNSServiceRef *sdRef,
780 DNSServiceFlags flags,
781 uint32_t interfaceIndex,
782 DNSServiceDomainEnumReply callBack,
783 void *context /* may be NULL */
784 );
785
786
787 /*********************************************************************************************
788 *
789 * Service Registration
790 *
791 *********************************************************************************************/
792
793 /* Register a service that is discovered via Browse() and Resolve() calls.
794 *
795 * DNSServiceRegisterReply() Callback Parameters:
796 *
797 * sdRef: The DNSServiceRef initialized by DNSServiceRegister().
798 *
799 * flags: When a name is successfully registered, the callback will be
800 * invoked with the kDNSServiceFlagsAdd flag set. When Wide-Area
801 * DNS-SD is in use, it is possible for a single service to get
802 * more than one success callback (e.g. one in the "local" multicast
803 * DNS domain, and another in a wide-area unicast DNS domain).
804 * If a successfully-registered name later suffers a name conflict
805 * or similar problem and has to be deregistered, the callback will
806 * be invoked with the kDNSServiceFlagsAdd flag not set. The callback
807 * is *not* invoked in the case where the caller explicitly terminates
808 * the service registration by calling DNSServiceRefDeallocate(ref);
809 *
810 * errorCode: Will be kDNSServiceErr_NoError on success, otherwise will
811 * indicate the failure that occurred (including name conflicts,
812 * if the kDNSServiceFlagsNoAutoRename flag was used when registering.)
813 * Other parameters are undefined if errorCode is nonzero.
814 *
815 * name: The service name registered (if the application did not specify a name in
816 * DNSServiceRegister(), this indicates what name was automatically chosen).
817 *
818 * regtype: The type of service registered, as it was passed to the callout.
819 *
820 * domain: The domain on which the service was registered (if the application did not
821 * specify a domain in DNSServiceRegister(), this indicates the default domain
822 * on which the service was registered).
823 *
824 * context: The context pointer that was passed to the callout.
825 *
826 */
827
828 typedef void (DNSSD_API *DNSServiceRegisterReply)
829 (
830 DNSServiceRef sdRef,
831 DNSServiceFlags flags,
832 DNSServiceErrorType errorCode,
833 const char *name,
834 const char *regtype,
835 const char *domain,
836 void *context
837 );
838
839
840 /* DNSServiceRegister() Parameters:
841 *
842 * sdRef: A pointer to an uninitialized DNSServiceRef. If the call succeeds
843 * then it initializes the DNSServiceRef, returns kDNSServiceErr_NoError,
844 * and the registration will remain active indefinitely until the client
845 * terminates it by passing this DNSServiceRef to DNSServiceRefDeallocate().
846 *
847 * interfaceIndex: If non-zero, specifies the interface on which to register the service
848 * (the index for a given interface is determined via the if_nametoindex()
849 * family of calls.) Most applications will pass 0 to register on all
850 * available interfaces. See "Constants for specifying an interface index" for more details.
851 *
852 * flags: Indicates the renaming behavior on name conflict (most applications
853 * will pass 0). See flag definitions above for details.
854 *
855 * name: If non-NULL, specifies the service name to be registered.
856 * Most applications will not specify a name, in which case the computer
857 * name is used (this name is communicated to the client via the callback).
858 * If a name is specified, it must be 1-63 bytes of UTF-8 text.
859 * If the name is longer than 63 bytes it will be automatically truncated
860 * to a legal length, unless the NoAutoRename flag is set,
861 * in which case kDNSServiceErr_BadParam will be returned.
862 *
863 * regtype: The service type followed by the protocol, separated by a dot
864 * (e.g. "_ftp._tcp"). The service type must be an underscore, followed
865 * by 1-14 characters, which may be letters, digits, or hyphens.
866 * The transport protocol must be "_tcp" or "_udp". New service types
867 * should be registered at <http://www.dns-sd.org/ServiceTypes.html>.
868 *
869 * Additional subtypes of the primary service type (where a service
870 * type has defined subtypes) follow the primary service type in a
871 * comma-separated list, with no additional spaces, e.g.
872 * "_primarytype._tcp,_subtype1,_subtype2,_subtype3"
873 * Subtypes provide a mechanism for filtered browsing: A client browsing
874 * for "_primarytype._tcp" will discover all instances of this type;
875 * a client browsing for "_primarytype._tcp,_subtype2" will discover only
876 * those instances that were registered with "_subtype2" in their list of
877 * registered subtypes.
878 *
879 * The subtype mechanism can be illustrated with some examples using the
880 * dns-sd command-line tool:
881 *
882 * % dns-sd -R Simple _test._tcp "" 1001 &
883 * % dns-sd -R Better _test._tcp,HasFeatureA "" 1002 &
884 * % dns-sd -R Best _test._tcp,HasFeatureA,HasFeatureB "" 1003 &
885 *
886 * Now:
887 * % dns-sd -B _test._tcp # will find all three services
888 * % dns-sd -B _test._tcp,HasFeatureA # finds "Better" and "Best"
889 * % dns-sd -B _test._tcp,HasFeatureB # finds only "Best"
890 *
891 * domain: If non-NULL, specifies the domain on which to advertise the service.
892 * Most applications will not specify a domain, instead automatically
893 * registering in the default domain(s).
894 *
895 * host: If non-NULL, specifies the SRV target host name. Most applications
896 * will not specify a host, instead automatically using the machine's
897 * default host name(s). Note that specifying a non-NULL host does NOT
898 * create an address record for that host - the application is responsible
899 * for ensuring that the appropriate address record exists, or creating it
900 * via DNSServiceRegisterRecord().
901 *
902 * port: The port, in network byte order, on which the service accepts connections.
903 * Pass 0 for a "placeholder" service (i.e. a service that will not be discovered
904 * by browsing, but will cause a name conflict if another client tries to
905 * register that same name). Most clients will not use placeholder services.
906 *
907 * txtLen: The length of the txtRecord, in bytes. Must be zero if the txtRecord is NULL.
908 *
909 * txtRecord: The TXT record rdata. A non-NULL txtRecord MUST be a properly formatted DNS
910 * TXT record, i.e. <length byte> <data> <length byte> <data> ...
911 * Passing NULL for the txtRecord is allowed as a synonym for txtLen=1, txtRecord="",
912 * i.e. it creates a TXT record of length one containing a single empty string.
913 * RFC 1035 doesn't allow a TXT record to contain *zero* strings, so a single empty
914 * string is the smallest legal DNS TXT record.
915 * As with the other parameters, the DNSServiceRegister call copies the txtRecord
916 * data; e.g. if you allocated the storage for the txtRecord parameter with malloc()
917 * then you can safely free that memory right after the DNSServiceRegister call returns.
918 *
919 * callBack: The function to be called when the registration completes or asynchronously
920 * fails. The client MAY pass NULL for the callback - The client will NOT be notified
921 * of the default values picked on its behalf, and the client will NOT be notified of any
922 * asynchronous errors (e.g. out of memory errors, etc.) that may prevent the registration
923 * of the service. The client may NOT pass the NoAutoRename flag if the callback is NULL.
924 * The client may still deregister the service at any time via DNSServiceRefDeallocate().
925 *
926 * context: An application context pointer which is passed to the callback function
927 * (may be NULL).
928 *
929 * return value: Returns kDNSServiceErr_NoError on success (any subsequent, asynchronous
930 * errors are delivered to the callback), otherwise returns an error code indicating
931 * the error that occurred (the callback is never invoked and the DNSServiceRef
932 * is not initialized).
933 */
934
935 DNSServiceErrorType DNSSD_API DNSServiceRegister
936 (
937 DNSServiceRef *sdRef,
938 DNSServiceFlags flags,
939 uint32_t interfaceIndex,
940 const char *name, /* may be NULL */
941 const char *regtype,
942 const char *domain, /* may be NULL */
943 const char *host, /* may be NULL */
944 uint16_t port,
945 uint16_t txtLen,
946 const void *txtRecord, /* may be NULL */
947 DNSServiceRegisterReply callBack, /* may be NULL */
948 void *context /* may be NULL */
949 );
950
951
952 /* DNSServiceAddRecord()
953 *
954 * Add a record to a registered service. The name of the record will be the same as the
955 * registered service's name.
956 * The record can later be updated or deregistered by passing the RecordRef initialized
957 * by this function to DNSServiceUpdateRecord() or DNSServiceRemoveRecord().
958 *
959 * Note that the DNSServiceAddRecord/UpdateRecord/RemoveRecord are *NOT* thread-safe
960 * with respect to a single DNSServiceRef. If you plan to have multiple threads
961 * in your program simultaneously add, update, or remove records from the same
962 * DNSServiceRef, then it's the caller's responsibility to use a mutext lock
963 * or take similar appropriate precautions to serialize those calls.
964 *
965 * Parameters;
966 *
967 * sdRef: A DNSServiceRef initialized by DNSServiceRegister().
968 *
969 * RecordRef: A pointer to an uninitialized DNSRecordRef. Upon succesfull completion of this
970 * call, this ref may be passed to DNSServiceUpdateRecord() or DNSServiceRemoveRecord().
971 * If the above DNSServiceRef is passed to DNSServiceRefDeallocate(), RecordRef is also
972 * invalidated and may not be used further.
973 *
974 * flags: Currently ignored, reserved for future use.
975 *
976 * rrtype: The type of the record (e.g. kDNSServiceType_TXT, kDNSServiceType_SRV, etc)
977 *
978 * rdlen: The length, in bytes, of the rdata.
979 *
980 * rdata: The raw rdata to be contained in the added resource record.
981 *
982 * ttl: The time to live of the resource record, in seconds. Pass 0 to use a default value.
983 *
984 * return value: Returns kDNSServiceErr_NoError on success, otherwise returns an
985 * error code indicating the error that occurred (the RecordRef is not initialized).
986 */
987
988 DNSServiceErrorType DNSSD_API DNSServiceAddRecord
989 (
990 DNSServiceRef sdRef,
991 DNSRecordRef *RecordRef,
992 DNSServiceFlags flags,
993 uint16_t rrtype,
994 uint16_t rdlen,
995 const void *rdata,
996 uint32_t ttl
997 );
998
999
1000 /* DNSServiceUpdateRecord
1001 *
1002 * Update a registered resource record. The record must either be:
1003 * - The primary txt record of a service registered via DNSServiceRegister()
1004 * - A record added to a registered service via DNSServiceAddRecord()
1005 * - An individual record registered by DNSServiceRegisterRecord()
1006 *
1007 * Parameters:
1008 *
1009 * sdRef: A DNSServiceRef that was initialized by DNSServiceRegister()
1010 * or DNSServiceCreateConnection().
1011 *
1012 * RecordRef: A DNSRecordRef initialized by DNSServiceAddRecord, or NULL to update the
1013 * service's primary txt record.
1014 *
1015 * flags: Currently ignored, reserved for future use.
1016 *
1017 * rdlen: The length, in bytes, of the new rdata.
1018 *
1019 * rdata: The new rdata to be contained in the updated resource record.
1020 *
1021 * ttl: The time to live of the updated resource record, in seconds.
1022 *
1023 * return value: Returns kDNSServiceErr_NoError on success, otherwise returns an
1024 * error code indicating the error that occurred.
1025 */
1026
1027 DNSServiceErrorType DNSSD_API DNSServiceUpdateRecord
1028 (
1029 DNSServiceRef sdRef,
1030 DNSRecordRef RecordRef, /* may be NULL */
1031 DNSServiceFlags flags,
1032 uint16_t rdlen,
1033 const void *rdata,
1034 uint32_t ttl
1035 );
1036
1037
1038 /* DNSServiceRemoveRecord
1039 *
1040 * Remove a record previously added to a service record set via DNSServiceAddRecord(), or deregister
1041 * an record registered individually via DNSServiceRegisterRecord().
1042 *
1043 * Parameters:
1044 *
1045 * sdRef: A DNSServiceRef initialized by DNSServiceRegister() (if the
1046 * record being removed was registered via DNSServiceAddRecord()) or by
1047 * DNSServiceCreateConnection() (if the record being removed was registered via
1048 * DNSServiceRegisterRecord()).
1049 *
1050 * recordRef: A DNSRecordRef initialized by a successful call to DNSServiceAddRecord()
1051 * or DNSServiceRegisterRecord().
1052 *
1053 * flags: Currently ignored, reserved for future use.
1054 *
1055 * return value: Returns kDNSServiceErr_NoError on success, otherwise returns an
1056 * error code indicating the error that occurred.
1057 */
1058
1059 DNSServiceErrorType DNSSD_API DNSServiceRemoveRecord
1060 (
1061 DNSServiceRef sdRef,
1062 DNSRecordRef RecordRef,
1063 DNSServiceFlags flags
1064 );
1065
1066
1067 /*********************************************************************************************
1068 *
1069 * Service Discovery
1070 *
1071 *********************************************************************************************/
1072
1073 /* Browse for instances of a service.
1074 *
1075 * DNSServiceBrowseReply() Parameters:
1076 *
1077 * sdRef: The DNSServiceRef initialized by DNSServiceBrowse().
1078 *
1079 * flags: Possible values are kDNSServiceFlagsMoreComing and kDNSServiceFlagsAdd.
1080 * See flag definitions for details.
1081 *
1082 * interfaceIndex: The interface on which the service is advertised. This index should
1083 * be passed to DNSServiceResolve() when resolving the service.
1084 *
1085 * errorCode: Will be kDNSServiceErr_NoError (0) on success, otherwise will
1086 * indicate the failure that occurred. Other parameters are undefined if
1087 * the errorCode is nonzero.
1088 *
1089 * serviceName: The discovered service name. This name should be displayed to the user,
1090 * and stored for subsequent use in the DNSServiceResolve() call.
1091 *
1092 * regtype: The service type, which is usually (but not always) the same as was passed
1093 * to DNSServiceBrowse(). One case where the discovered service type may
1094 * not be the same as the requested service type is when using subtypes:
1095 * The client may want to browse for only those ftp servers that allow
1096 * anonymous connections. The client will pass the string "_ftp._tcp,_anon"
1097 * to DNSServiceBrowse(), but the type of the service that's discovered
1098 * is simply "_ftp._tcp". The regtype for each discovered service instance
1099 * should be stored along with the name, so that it can be passed to
1100 * DNSServiceResolve() when the service is later resolved.
1101 *
1102 * domain: The domain of the discovered service instance. This may or may not be the
1103 * same as the domain that was passed to DNSServiceBrowse(). The domain for each
1104 * discovered service instance should be stored along with the name, so that
1105 * it can be passed to DNSServiceResolve() when the service is later resolved.
1106 *
1107 * context: The context pointer that was passed to the callout.
1108 *
1109 */
1110
1111 typedef void (DNSSD_API *DNSServiceBrowseReply)
1112 (
1113 DNSServiceRef sdRef,
1114 DNSServiceFlags flags,
1115 uint32_t interfaceIndex,
1116 DNSServiceErrorType errorCode,
1117 const char *serviceName,
1118 const char *regtype,
1119 const char *replyDomain,
1120 void *context
1121 );
1122
1123
1124 /* DNSServiceBrowse() Parameters:
1125 *
1126 * sdRef: A pointer to an uninitialized DNSServiceRef. If the call succeeds
1127 * then it initializes the DNSServiceRef, returns kDNSServiceErr_NoError,
1128 * and the browse operation will run indefinitely until the client
1129 * terminates it by passing this DNSServiceRef to DNSServiceRefDeallocate().
1130 *
1131 * flags: Currently ignored, reserved for future use.
1132 *
1133 * interfaceIndex: If non-zero, specifies the interface on which to browse for services
1134 * (the index for a given interface is determined via the if_nametoindex()
1135 * family of calls.) Most applications will pass 0 to browse on all available
1136 * interfaces. See "Constants for specifying an interface index" for more details.
1137 *
1138 * regtype: The service type being browsed for followed by the protocol, separated by a
1139 * dot (e.g. "_ftp._tcp"). The transport protocol must be "_tcp" or "_udp".
1140 * A client may optionally specify a single subtype to perform filtered browsing:
1141 * e.g. browsing for "_primarytype._tcp,_subtype" will discover only those
1142 * instances of "_primarytype._tcp" that were registered specifying "_subtype"
1143 * in their list of registered subtypes.
1144 *
1145 * domain: If non-NULL, specifies the domain on which to browse for services.
1146 * Most applications will not specify a domain, instead browsing on the
1147 * default domain(s).
1148 *
1149 * callBack: The function to be called when an instance of the service being browsed for
1150 * is found, or if the call asynchronously fails.
1151 *
1152 * context: An application context pointer which is passed to the callback function
1153 * (may be NULL).
1154 *
1155 * return value: Returns kDNSServiceErr_NoError on success (any subsequent, asynchronous
1156 * errors are delivered to the callback), otherwise returns an error code indicating
1157 * the error that occurred (the callback is not invoked and the DNSServiceRef
1158 * is not initialized).
1159 */
1160
1161 DNSServiceErrorType DNSSD_API DNSServiceBrowse
1162 (
1163 DNSServiceRef *sdRef,
1164 DNSServiceFlags flags,
1165 uint32_t interfaceIndex,
1166 const char *regtype,
1167 const char *domain, /* may be NULL */
1168 DNSServiceBrowseReply callBack,
1169 void *context /* may be NULL */
1170 );
1171
1172
1173 /* DNSServiceResolve()
1174 *
1175 * Resolve a service name discovered via DNSServiceBrowse() to a target host name, port number, and
1176 * txt record.
1177 *
1178 * Note: Applications should NOT use DNSServiceResolve() solely for txt record monitoring - use
1179 * DNSServiceQueryRecord() instead, as it is more efficient for this task.
1180 *
1181 * Note: When the desired results have been returned, the client MUST terminate the resolve by calling
1182 * DNSServiceRefDeallocate().
1183 *
1184 * Note: DNSServiceResolve() behaves correctly for typical services that have a single SRV record
1185 * and a single TXT record. To resolve non-standard services with multiple SRV or TXT records,
1186 * DNSServiceQueryRecord() should be used.
1187 *
1188 * DNSServiceResolveReply Callback Parameters:
1189 *
1190 * sdRef: The DNSServiceRef initialized by DNSServiceResolve().
1191 *
1192 * flags: Possible values: kDNSServiceFlagsMoreComing
1193 *
1194 * interfaceIndex: The interface on which the service was resolved.
1195 *
1196 * errorCode: Will be kDNSServiceErr_NoError (0) on success, otherwise will
1197 * indicate the failure that occurred. Other parameters are undefined if
1198 * the errorCode is nonzero.
1199 *
1200 * fullname: The full service domain name, in the form <servicename>.<protocol>.<domain>.
1201 * (This name is escaped following standard DNS rules, making it suitable for
1202 * passing to standard system DNS APIs such as res_query(), or to the
1203 * special-purpose functions included in this API that take fullname parameters.
1204 * See "Notes on DNS Name Escaping" earlier in this file for more details.)
1205 *
1206 * hosttarget: The target hostname of the machine providing the service. This name can
1207 * be passed to functions like gethostbyname() to identify the host's IP address.
1208 *
1209 * port: The port, in network byte order, on which connections are accepted for this service.
1210 *
1211 * txtLen: The length of the txt record, in bytes.
1212 *
1213 * txtRecord: The service's primary txt record, in standard txt record format.
1214 *
1215 * context: The context pointer that was passed to the callout.
1216 *
1217 * NOTE: In earlier versions of this header file, the txtRecord parameter was declared "const char *"
1218 * This is incorrect, since it contains length bytes which are values in the range 0 to 255, not -128 to +127.
1219 * Depending on your compiler settings, this change may cause signed/unsigned mismatch warnings.
1220 * These should be fixed by updating your own callback function definition to match the corrected
1221 * function signature using "const unsigned char *txtRecord". Making this change may also fix inadvertent
1222 * bugs in your callback function, where it could have incorrectly interpreted a length byte with value 250
1223 * as being -6 instead, with various bad consequences ranging from incorrect operation to software crashes.
1224 * If you need to maintain portable code that will compile cleanly with both the old and new versions of
1225 * this header file, you should update your callback function definition to use the correct unsigned value,
1226 * and then in the place where you pass your callback function to DNSServiceResolve(), use a cast to eliminate
1227 * the compiler warning, e.g.:
1228 * DNSServiceResolve(sd, flags, index, name, regtype, domain, (DNSServiceResolveReply)MyCallback, context);
1229 * This will ensure that your code compiles cleanly without warnings (and more importantly, works correctly)
1230 * with both the old header and with the new corrected version.
1231 *
1232 */
1233
1234 typedef void (DNSSD_API *DNSServiceResolveReply)
1235 (
1236 DNSServiceRef sdRef,
1237 DNSServiceFlags flags,
1238 uint32_t interfaceIndex,
1239 DNSServiceErrorType errorCode,
1240 const char *fullname,
1241 const char *hosttarget,
1242 uint16_t port,
1243 uint16_t txtLen,
1244 const unsigned char *txtRecord,
1245 void *context
1246 );
1247
1248
1249 /* DNSServiceResolve() Parameters
1250 *
1251 * sdRef: A pointer to an uninitialized DNSServiceRef. If the call succeeds
1252 * then it initializes the DNSServiceRef, returns kDNSServiceErr_NoError,
1253 * and the resolve operation will run indefinitely until the client
1254 * terminates it by passing this DNSServiceRef to DNSServiceRefDeallocate().
1255 *
1256 * flags: Specifying kDNSServiceFlagsForceMulticast will cause query to be
1257 * performed with a link-local mDNS query, even if the name is an
1258 * apparently non-local name (i.e. a name not ending in ".local.")
1259 *
1260 * interfaceIndex: The interface on which to resolve the service. If this resolve call is
1261 * as a result of a currently active DNSServiceBrowse() operation, then the
1262 * interfaceIndex should be the index reported in the DNSServiceBrowseReply
1263 * callback. If this resolve call is using information previously saved
1264 * (e.g. in a preference file) for later use, then use interfaceIndex 0, because
1265 * the desired service may now be reachable via a different physical interface.
1266 * See "Constants for specifying an interface index" for more details.
1267 *
1268 * name: The name of the service instance to be resolved, as reported to the
1269 * DNSServiceBrowseReply() callback.
1270 *
1271 * regtype: The type of the service instance to be resolved, as reported to the
1272 * DNSServiceBrowseReply() callback.
1273 *
1274 * domain: The domain of the service instance to be resolved, as reported to the
1275 * DNSServiceBrowseReply() callback.
1276 *
1277 * callBack: The function to be called when a result is found, or if the call
1278 * asynchronously fails.
1279 *
1280 * context: An application context pointer which is passed to the callback function
1281 * (may be NULL).
1282 *
1283 * return value: Returns kDNSServiceErr_NoError on success (any subsequent, asynchronous
1284 * errors are delivered to the callback), otherwise returns an error code indicating
1285 * the error that occurred (the callback is never invoked and the DNSServiceRef
1286 * is not initialized).
1287 */
1288
1289 DNSServiceErrorType DNSSD_API DNSServiceResolve
1290 (
1291 DNSServiceRef *sdRef,
1292 DNSServiceFlags flags,
1293 uint32_t interfaceIndex,
1294 const char *name,
1295 const char *regtype,
1296 const char *domain,
1297 DNSServiceResolveReply callBack,
1298 void *context /* may be NULL */
1299 );
1300
1301
1302 /*********************************************************************************************
1303 *
1304 * Querying Individual Specific Records
1305 *
1306 *********************************************************************************************/
1307
1308 /* DNSServiceQueryRecord
1309 *
1310 * Query for an arbitrary DNS record.
1311 *
1312 * DNSServiceQueryRecordReply() Callback Parameters:
1313 *
1314 * sdRef: The DNSServiceRef initialized by DNSServiceQueryRecord().
1315 *
1316 * flags: Possible values are kDNSServiceFlagsMoreComing and
1317 * kDNSServiceFlagsAdd. The Add flag is NOT set for PTR records
1318 * with a ttl of 0, i.e. "Remove" events.
1319 *
1320 * interfaceIndex: The interface on which the query was resolved (the index for a given
1321 * interface is determined via the if_nametoindex() family of calls).
1322 * See "Constants for specifying an interface index" for more details.
1323 *
1324 * errorCode: Will be kDNSServiceErr_NoError on success, otherwise will
1325 * indicate the failure that occurred. Other parameters are undefined if
1326 * errorCode is nonzero.
1327 *
1328 * fullname: The resource record's full domain name.
1329 *
1330 * rrtype: The resource record's type (e.g. kDNSServiceType_PTR, kDNSServiceType_SRV, etc)
1331 *
1332 * rrclass: The class of the resource record (usually kDNSServiceClass_IN).
1333 *
1334 * rdlen: The length, in bytes, of the resource record rdata.
1335 *
1336 * rdata: The raw rdata of the resource record.
1337 *
1338 * ttl: If the client wishes to cache the result for performance reasons,
1339 * the TTL indicates how long the client may legitimately hold onto
1340 * this result, in seconds. After the TTL expires, the client should
1341 * consider the result no longer valid, and if it requires this data
1342 * again, it should be re-fetched with a new query. Of course, this
1343 * only applies to clients that cancel the asynchronous operation when
1344 * they get a result. Clients that leave the asynchronous operation
1345 * running can safely assume that the data remains valid until they
1346 * get another callback telling them otherwise.
1347 *
1348 * context: The context pointer that was passed to the callout.
1349 *
1350 */
1351
1352 typedef void (DNSSD_API *DNSServiceQueryRecordReply)
1353 (
1354 DNSServiceRef sdRef,
1355 DNSServiceFlags flags,
1356 uint32_t interfaceIndex,
1357 DNSServiceErrorType errorCode,
1358 const char *fullname,
1359 uint16_t rrtype,
1360 uint16_t rrclass,
1361 uint16_t rdlen,
1362 const void *rdata,
1363 uint32_t ttl,
1364 void *context
1365 );
1366
1367
1368 /* DNSServiceQueryRecord() Parameters:
1369 *
1370 * sdRef: A pointer to an uninitialized DNSServiceRef. If the call succeeds
1371 * then it initializes the DNSServiceRef, returns kDNSServiceErr_NoError,
1372 * and the query operation will run indefinitely until the client
1373 * terminates it by passing this DNSServiceRef to DNSServiceRefDeallocate().
1374 *
1375 * flags: kDNSServiceFlagsForceMulticast or kDNSServiceFlagsLongLivedQuery.
1376 * Pass kDNSServiceFlagsLongLivedQuery to create a "long-lived" unicast
1377 * query in a non-local domain. Without setting this flag, unicast queries
1378 * will be one-shot - that is, only answers available at the time of the call
1379 * will be returned. By setting this flag, answers (including Add and Remove
1380 * events) that become available after the initial call is made will generate
1381 * callbacks. This flag has no effect on link-local multicast queries.
1382 *
1383 * interfaceIndex: If non-zero, specifies the interface on which to issue the query
1384 * (the index for a given interface is determined via the if_nametoindex()
1385 * family of calls.) Passing 0 causes the name to be queried for on all
1386 * interfaces. See "Constants for specifying an interface index" for more details.
1387 *
1388 * fullname: The full domain name of the resource record to be queried for.
1389 *
1390 * rrtype: The numerical type of the resource record to be queried for
1391 * (e.g. kDNSServiceType_PTR, kDNSServiceType_SRV, etc)
1392 *
1393 * rrclass: The class of the resource record (usually kDNSServiceClass_IN).
1394 *
1395 * callBack: The function to be called when a result is found, or if the call
1396 * asynchronously fails.
1397 *
1398 * context: An application context pointer which is passed to the callback function
1399 * (may be NULL).
1400 *
1401 * return value: Returns kDNSServiceErr_NoError on success (any subsequent, asynchronous
1402 * errors are delivered to the callback), otherwise returns an error code indicating
1403 * the error that occurred (the callback is never invoked and the DNSServiceRef
1404 * is not initialized).
1405 */
1406
1407 DNSServiceErrorType DNSSD_API DNSServiceQueryRecord
1408 (
1409 DNSServiceRef *sdRef,
1410 DNSServiceFlags flags,
1411 uint32_t interfaceIndex,
1412 const char *fullname,
1413 uint16_t rrtype,
1414 uint16_t rrclass,
1415 DNSServiceQueryRecordReply callBack,
1416 void *context /* may be NULL */
1417 );
1418
1419
1420 /*********************************************************************************************
1421 *
1422 * Unified lookup of both IPv4 and IPv6 addresses for a fully qualified hostname
1423 *
1424 *********************************************************************************************/
1425
1426 /* DNSServiceGetAddrInfo
1427 *
1428 * Queries for the IP address of a hostname by using either Multicast or Unicast DNS.
1429 *
1430 * DNSServiceGetAddrInfoReply() parameters:
1431 *
1432 * sdRef: The DNSServiceRef initialized by DNSServiceGetAddrInfo().
1433 *
1434 * flags: Possible values are kDNSServiceFlagsMoreComing and
1435 * kDNSServiceFlagsAdd.
1436 *
1437 * interfaceIndex: The interface to which the answers pertain.
1438 *
1439 * errorCode: Will be kDNSServiceErr_NoError on success, otherwise will
1440 * indicate the failure that occurred. Other parameters are
1441 * undefined if errorCode is nonzero.
1442 *
1443 * hostname: The fully qualified domain name of the host to be queried for.
1444 *
1445 * address: IPv4 or IPv6 address.
1446 *
1447 * ttl: If the client wishes to cache the result for performance reasons,
1448 * the TTL indicates how long the client may legitimately hold onto
1449 * this result, in seconds. After the TTL expires, the client should
1450 * consider the result no longer valid, and if it requires this data
1451 * again, it should be re-fetched with a new query. Of course, this
1452 * only applies to clients that cancel the asynchronous operation when
1453 * they get a result. Clients that leave the asynchronous operation
1454 * running can safely assume that the data remains valid until they
1455 * get another callback telling them otherwise.
1456 *
1457 * context: The context pointer that was passed to the callout.
1458 *
1459 */
1460
1461 typedef void (DNSSD_API *DNSServiceGetAddrInfoReply)
1462 (
1463 DNSServiceRef sdRef,
1464 DNSServiceFlags flags,
1465 uint32_t interfaceIndex,
1466 DNSServiceErrorType errorCode,
1467 const char *hostname,
1468 const struct sockaddr *address,
1469 uint32_t ttl,
1470 void *context
1471 );
1472
1473
1474 /* DNSServiceGetAddrInfo() Parameters:
1475 *
1476 * sdRef: A pointer to an uninitialized DNSServiceRef. If the call succeeds then it
1477 * initializes the DNSServiceRef, returns kDNSServiceErr_NoError, and the query
1478 * begins and will last indefinitely until the client terminates the query
1479 * by passing this DNSServiceRef to DNSServiceRefDeallocate().
1480 *
1481 * flags: kDNSServiceFlagsForceMulticast or kDNSServiceFlagsLongLivedQuery.
1482 * Pass kDNSServiceFlagsLongLivedQuery to create a "long-lived" unicast
1483 * query in a non-local domain. Without setting this flag, unicast queries
1484 * will be one-shot - that is, only answers available at the time of the call
1485 * will be returned. By setting this flag, answers (including Add and Remove
1486 * events) that become available after the initial call is made will generate
1487 * callbacks. This flag has no effect on link-local multicast queries.
1488 *
1489 * interfaceIndex: The interface on which to issue the query. Passing 0 causes the query to be
1490 * sent on all active interfaces via Multicast or the primary interface via Unicast.
1491 *
1492 * protocol: Pass in kDNSServiceProtocol_IPv4 to look up IPv4 addresses, or kDNSServiceProtocol_IPv6
1493 * to look up IPv6 addresses, or both to look up both kinds. If neither flag is
1494 * set, the system will apply an intelligent heuristic, which is (currently)
1495 * that it will attempt to look up both, except:
1496 *
1497 * * If "hostname" is a wide-area unicast DNS hostname (i.e. not a ".local." name)
1498 * but this host has no routable IPv6 address, then the call will not try to
1499 * look up IPv6 addresses for "hostname", since any addresses it found would be
1500 * unlikely to be of any use anyway. Similarly, if this host has no routable
1501 * IPv4 address, the call will not try to look up IPv4 addresses for "hostname".
1502 *
1503 * * If "hostname" is a link-local multicast DNS hostname (i.e. a ".local." name)
1504 * but this host has no IPv6 address of any kind, then it will not try to look
1505 * up IPv6 addresses for "hostname". Similarly, if this host has no IPv4 address
1506 * of any kind, the call will not try to look up IPv4 addresses for "hostname".
1507 *
1508 * hostname: The fully qualified domain name of the host to be queried for.
1509 *
1510 * callBack: The function to be called when the query succeeds or fails asynchronously.
1511 *
1512 * context: An application context pointer which is passed to the callback function
1513 * (may be NULL).
1514 *
1515 * return value: Returns kDNSServiceErr_NoError on success (any subsequent, asynchronous
1516 * errors are delivered to the callback), otherwise returns an error code indicating
1517 * the error that occurred.
1518 */
1519
1520 DNSServiceErrorType DNSSD_API DNSServiceGetAddrInfo
1521 (
1522 DNSServiceRef *sdRef,
1523 DNSServiceFlags flags,
1524 uint32_t interfaceIndex,
1525 DNSServiceProtocol protocol,
1526 const char *hostname,
1527 DNSServiceGetAddrInfoReply callBack,
1528 void *context /* may be NULL */
1529 );
1530
1531
1532 /*********************************************************************************************
1533 *
1534 * Special Purpose Calls:
1535 * DNSServiceCreateConnection(), DNSServiceRegisterRecord(), DNSServiceReconfirmRecord()
1536 * (most applications will not use these)
1537 *
1538 *********************************************************************************************/
1539
1540 /* DNSServiceCreateConnection()
1541 *
1542 * Create a connection to the daemon allowing efficient registration of
1543 * multiple individual records.
1544 *
1545 * Parameters:
1546 *
1547 * sdRef: A pointer to an uninitialized DNSServiceRef. Deallocating
1548 * the reference (via DNSServiceRefDeallocate()) severs the
1549 * connection and deregisters all records registered on this connection.
1550 *
1551 * return value: Returns kDNSServiceErr_NoError on success, otherwise returns
1552 * an error code indicating the specific failure that occurred (in which
1553 * case the DNSServiceRef is not initialized).
1554 */
1555
1556 DNSServiceErrorType DNSSD_API DNSServiceCreateConnection(DNSServiceRef *sdRef);
1557
1558
1559 /* DNSServiceRegisterRecord
1560 *
1561 * Register an individual resource record on a connected DNSServiceRef.
1562 *
1563 * Note that name conflicts occurring for records registered via this call must be handled
1564 * by the client in the callback.
1565 *
1566 * DNSServiceRegisterRecordReply() parameters:
1567 *
1568 * sdRef: The connected DNSServiceRef initialized by
1569 * DNSServiceCreateConnection().
1570 *
1571 * RecordRef: The DNSRecordRef initialized by DNSServiceRegisterRecord(). If the above
1572 * DNSServiceRef is passed to DNSServiceRefDeallocate(), this DNSRecordRef is
1573 * invalidated, and may not be used further.
1574 *
1575 * flags: Currently unused, reserved for future use.
1576 *
1577 * errorCode: Will be kDNSServiceErr_NoError on success, otherwise will
1578 * indicate the failure that occurred (including name conflicts.)
1579 * Other parameters are undefined if errorCode is nonzero.
1580 *
1581 * context: The context pointer that was passed to the callout.
1582 *
1583 */
1584
1585 typedef void (DNSSD_API *DNSServiceRegisterRecordReply)
1586 (
1587 DNSServiceRef sdRef,
1588 DNSRecordRef RecordRef,
1589 DNSServiceFlags flags,
1590 DNSServiceErrorType errorCode,
1591 void *context
1592 );
1593
1594
1595 /* DNSServiceRegisterRecord() Parameters:
1596 *
1597 * sdRef: A DNSServiceRef initialized by DNSServiceCreateConnection().
1598 *
1599 * RecordRef: A pointer to an uninitialized DNSRecordRef. Upon succesfull completion of this
1600 * call, this ref may be passed to DNSServiceUpdateRecord() or DNSServiceRemoveRecord().
1601 * (To deregister ALL records registered on a single connected DNSServiceRef
1602 * and deallocate each of their corresponding DNSServiceRecordRefs, call
1603 * DNSServiceRefDealloocate()).
1604 *
1605 * flags: Possible values are kDNSServiceFlagsShared or kDNSServiceFlagsUnique
1606 * (see flag type definitions for details).
1607 *
1608 * interfaceIndex: If non-zero, specifies the interface on which to register the record
1609 * (the index for a given interface is determined via the if_nametoindex()
1610 * family of calls.) Passing 0 causes the record to be registered on all interfaces.
1611 * See "Constants for specifying an interface index" for more details.
1612 *
1613 * fullname: The full domain name of the resource record.
1614 *
1615 * rrtype: The numerical type of the resource record (e.g. kDNSServiceType_PTR, kDNSServiceType_SRV, etc)
1616 *
1617 * rrclass: The class of the resource record (usually kDNSServiceClass_IN)
1618 *
1619 * rdlen: Length, in bytes, of the rdata.
1620 *
1621 * rdata: A pointer to the raw rdata, as it is to appear in the DNS record.
1622 *
1623 * ttl: The time to live of the resource record, in seconds. Pass 0 to use a default value.
1624 *
1625 * callBack: The function to be called when a result is found, or if the call
1626 * asynchronously fails (e.g. because of a name conflict.)
1627 *
1628 * context: An application context pointer which is passed to the callback function
1629 * (may be NULL).
1630 *
1631 * return value: Returns kDNSServiceErr_NoError on success (any subsequent, asynchronous
1632 * errors are delivered to the callback), otherwise returns an error code indicating
1633 * the error that occurred (the callback is never invoked and the DNSRecordRef is
1634 * not initialized).
1635 */
1636
1637 DNSServiceErrorType DNSSD_API DNSServiceRegisterRecord
1638 (
1639 DNSServiceRef sdRef,
1640 DNSRecordRef *RecordRef,
1641 DNSServiceFlags flags,
1642 uint32_t interfaceIndex,
1643 const char *fullname,
1644 uint16_t rrtype,
1645 uint16_t rrclass,
1646 uint16_t rdlen,
1647 const void *rdata,
1648 uint32_t ttl,
1649 DNSServiceRegisterRecordReply callBack,
1650 void *context /* may be NULL */
1651 );
1652
1653
1654 /* DNSServiceReconfirmRecord
1655 *
1656 * Instruct the daemon to verify the validity of a resource record that appears
1657 * to be out of date (e.g. because TCP connection to a service's target failed.)
1658 * Causes the record to be flushed from the daemon's cache (as well as all other
1659 * daemons' caches on the network) if the record is determined to be invalid.
1660 * Use this routine conservatively. Reconfirming a record necessarily consumes
1661 * network bandwidth, so this should not be done indiscriminately.
1662 *
1663 * Parameters:
1664 *
1665 * flags: Pass kDNSServiceFlagsForce to force immediate deletion of record,
1666 * instead of after some number of reconfirmation queries have gone unanswered.
1667 *
1668 * interfaceIndex: Specifies the interface of the record in question.
1669 * The caller must specify the interface.
1670 * This API (by design) causes increased network traffic, so it requires
1671 * the caller to be precise about which record should be reconfirmed.
1672 * It is not possible to pass zero for the interface index to perform
1673 * a "wildcard" reconfirmation, where *all* matching records are reconfirmed.
1674 *
1675 * fullname: The resource record's full domain name.
1676 *
1677 * rrtype: The resource record's type (e.g. kDNSServiceType_PTR, kDNSServiceType_SRV, etc)
1678 *
1679 * rrclass: The class of the resource record (usually kDNSServiceClass_IN).
1680 *
1681 * rdlen: The length, in bytes, of the resource record rdata.
1682 *
1683 * rdata: The raw rdata of the resource record.
1684 *
1685 */
1686
1687 DNSServiceErrorType DNSSD_API DNSServiceReconfirmRecord
1688 (
1689 DNSServiceFlags flags,
1690 uint32_t interfaceIndex,
1691 const char *fullname,
1692 uint16_t rrtype,
1693 uint16_t rrclass,
1694 uint16_t rdlen,
1695 const void *rdata
1696 );
1697
1698
1699 /*********************************************************************************************
1700 *
1701 * NAT Port Mapping
1702 *
1703 *********************************************************************************************/
1704
1705 /* DNSServiceNATPortMappingCreate
1706 *
1707 * Request a port mapping in the NAT gateway which maps a port on the local machine
1708 * to a public port on the NAT.
1709 * The port mapping will be renewed indefinitely until the client process exits, or
1710 * explicitly terminates the port mapping request by calling DNSServiceRefDeallocate().
1711 * The client callback will be invoked, informing the client of the NAT gateway's
1712 * public IP address and the public port that has been allocated for this client.
1713 * The client should then record this public IP address and port using whatever
1714 * directory service mechanism it is using to enable peers to connect to it.
1715 * (Clients advertising services using Wide-Area DNS-SD DO NOT need to use this API
1716 * -- when a client calls DNSServiceRegister() NAT mappings are automatically created
1717 * and the public IP address and port for the service are recorded in the global DNS.
1718 * Only clients using some directory mechanism other than Wide-Area DNS-SD need to use
1719 * this API to explicitly map their own ports.)
1720 * It's possible that the client callback could be called multiple times, for example
1721 * if the NAT gateway's IP address changes, or if a configuration change results in a
1722 * different public port being mapped for this client. Over the lifetime of any long-lived
1723 * port mapping, the client should be prepared to handle these notifications of changes
1724 * in the environment, and should update its recorded address and/or port as appropriate.
1725 *
1726 * DNSServiceNATPortMappingReply() parameters:
1727 *
1728 * sdRef: The DNSServiceRef initialized by DNSServiceNATPortMappingCreate().
1729 *
1730 * flags: Currently unused, reserved for future use.
1731 *
1732 * interfaceIndex: The interface through which the NAT gateway is reached.
1733 *
1734 * errorCode: Will be kDNSServiceErr_NoError on success.
1735 * Will be kDNSServiceErr_DoubleNAT when the NAT gateway is itself behind one or
1736 * more layers of NAT, in which case the other parameters have the defined values.
1737 * For other failures, will indicate the failure that occurred, and the other
1738 * parameters are undefined.
1739 *
1740 * publicAddress: Four byte IPv4 address in network byte order.
1741 *
1742 * protocol: Will be kDNSServiceProtocol_UDP or kDNSServiceProtocol_TCP or both.
1743 *
1744 * privatePort: The port on the local machine that was mapped.
1745 *
1746 * publicPort: The actual public port in the NAT gateway that was mapped.
1747 * This is very likely to be different than the requested public port.
1748 *
1749 * ttl: The lifetime of the NAT port mapping created on the gateway.
1750 * This controls how quickly stale mappings will be garbage-collected
1751 * if the client machine crashes, suffers a power failure, is disconnected
1752 * from the network, or suffers some other unfortunate demise which
1753 * causes it to vanish without explicitly removing its NAT port mapping.
1754 * It's possible that the ttl value will differ from the requested ttl value.
1755 *
1756 * context: The context pointer that was passed to the callout.
1757 *
1758 */
1759
1760 typedef void (DNSSD_API *DNSServiceNATPortMappingReply)
1761 (
1762 DNSServiceRef sdRef,
1763 DNSServiceFlags flags,
1764 uint32_t interfaceIndex,
1765 DNSServiceErrorType errorCode,
1766 uint32_t publicAddress, /* four byte IPv4 address in network byte order */
1767 DNSServiceProtocol protocol,
1768 uint16_t privatePort,
1769 uint16_t publicPort, /* may be different than the requested port */
1770 uint32_t ttl, /* may be different than the requested ttl */
1771 void *context
1772 );
1773
1774
1775 /* DNSServiceNATPortMappingCreate() Parameters:
1776 *
1777 * sdRef: A pointer to an uninitialized DNSServiceRef. If the call succeeds then it
1778 * initializes the DNSServiceRef, returns kDNSServiceErr_NoError, and the nat
1779 * port mapping will last indefinitely until the client terminates the port
1780 * mapping request by passing this DNSServiceRef to DNSServiceRefDeallocate().
1781 *
1782 * flags: Currently ignored, reserved for future use.
1783 *
1784 * interfaceIndex: The interface on which to create port mappings in a NAT gateway. Passing 0 causes
1785 * the port mapping request to be sent on the primary interface.
1786 *
1787 * protocol: To request a port mapping, pass in kDNSServiceProtocol_UDP, or kDNSServiceProtocol_TCP,
1788 * or (kDNSServiceProtocol_UDP | kDNSServiceProtocol_TCP) to map both.
1789 * The local listening port number must also be specified in the privatePort parameter.
1790 * To just discover the NAT gateway's public IP address, pass zero for protocol,
1791 * privatePort, publicPort and ttl.
1792 *
1793 * privatePort: The port number in network byte order on the local machine which is listening for packets.
1794 *
1795 * publicPort: The requested public port in network byte order in the NAT gateway that you would
1796 * like to map to the private port. Pass 0 if you don't care which public port is chosen for you.
1797 *
1798 * ttl: The requested renewal period of the NAT port mapping, in seconds.
1799 * If the client machine crashes, suffers a power failure, is disconnected from
1800 * the network, or suffers some other unfortunate demise which causes it to vanish
1801 * unexpectedly without explicitly removing its NAT port mappings, then the NAT gateway
1802 * will garbage-collect old stale NAT port mappings when their lifetime expires.
1803 * Requesting a short TTL causes such orphaned mappings to be garbage-collected
1804 * more promptly, but consumes system resources and network bandwidth with
1805 * frequent renewal packets to keep the mapping from expiring.
1806 * Requesting a long TTL is more efficient on the network, but in the event of the
1807 * client vanishing, stale NAT port mappings will not be garbage-collected as quickly.
1808 * Most clients should pass 0 to use a system-wide default value.
1809 *
1810 * callBack: The function to be called when the port mapping request succeeds or fails asynchronously.
1811 *
1812 * context: An application context pointer which is passed to the callback function
1813 * (may be NULL).
1814 *
1815 * return value: Returns kDNSServiceErr_NoError on success (any subsequent, asynchronous
1816 * errors are delivered to the callback), otherwise returns an error code indicating
1817 * the error that occurred.
1818 *
1819 * If you don't actually want a port mapped, and are just calling the API
1820 * because you want to find out the NAT's public IP address (e.g. for UI
1821 * display) then pass zero for protocol, privatePort, publicPort and ttl.
1822 */
1823
1824 DNSServiceErrorType DNSSD_API DNSServiceNATPortMappingCreate
1825 (
1826 DNSServiceRef *sdRef,
1827 DNSServiceFlags flags,
1828 uint32_t interfaceIndex,
1829 DNSServiceProtocol protocol, /* TCP and/or UDP */
1830 uint16_t privatePort, /* network byte order */
1831 uint16_t publicPort, /* network byte order */
1832 uint32_t ttl, /* time to live in seconds */
1833 DNSServiceNATPortMappingReply callBack,
1834 void *context /* may be NULL */
1835 );
1836
1837
1838 /*********************************************************************************************
1839 *
1840 * General Utility Functions
1841 *
1842 *********************************************************************************************/
1843
1844 /* DNSServiceConstructFullName()
1845 *
1846 * Concatenate a three-part domain name (as returned by the above callbacks) into a
1847 * properly-escaped full domain name. Note that callbacks in the above functions ALREADY ESCAPE
1848 * strings where necessary.
1849 *
1850 * Parameters:
1851 *
1852 * fullName: A pointer to a buffer that where the resulting full domain name is to be written.
1853 * The buffer must be kDNSServiceMaxDomainName (1005) bytes in length to
1854 * accommodate the longest legal domain name without buffer overrun.
1855 *
1856 * service: The service name - any dots or backslashes must NOT be escaped.
1857 * May be NULL (to construct a PTR record name, e.g.
1858 * "_ftp._tcp.apple.com.").
1859 *
1860 * regtype: The service type followed by the protocol, separated by a dot
1861 * (e.g. "_ftp._tcp").
1862 *
1863 * domain: The domain name, e.g. "apple.com.". Literal dots or backslashes,
1864 * if any, must be escaped, e.g. "1st\. Floor.apple.com."
1865 *
1866 * return value: Returns 0 on success, -1 on error.
1867 *
1868 */
1869
1870 int DNSSD_API DNSServiceConstructFullName
1871 (
1872 char *fullName,
1873 const char *service, /* may be NULL */
1874 const char *regtype,
1875 const char *domain
1876 );
1877
1878
1879 /*********************************************************************************************
1880 *
1881 * TXT Record Construction Functions
1882 *
1883 *********************************************************************************************/
1884
1885 /*
1886 * A typical calling sequence for TXT record construction is something like:
1887 *
1888 * Client allocates storage for TXTRecord data (e.g. declare buffer on the stack)
1889 * TXTRecordCreate();
1890 * TXTRecordSetValue();
1891 * TXTRecordSetValue();
1892 * TXTRecordSetValue();
1893 * ...
1894 * DNSServiceRegister( ... TXTRecordGetLength(), TXTRecordGetBytesPtr() ... );
1895 * TXTRecordDeallocate();
1896 * Explicitly deallocate storage for TXTRecord data (if not allocated on the stack)
1897 */
1898
1899
1900 /* TXTRecordRef
1901 *
1902 * Opaque internal data type.
1903 * Note: Represents a DNS-SD TXT record.
1904 */
1905
1906 typedef union _TXTRecordRef_t { char PrivateData[16]; char *ForceNaturalAlignment; } TXTRecordRef;
1907
1908
1909 /* TXTRecordCreate()
1910 *
1911 * Creates a new empty TXTRecordRef referencing the specified storage.
1912 *
1913 * If the buffer parameter is NULL, or the specified storage size is not
1914 * large enough to hold a key subsequently added using TXTRecordSetValue(),
1915 * then additional memory will be added as needed using malloc().
1916 *
1917 * On some platforms, when memory is low, malloc() may fail. In this
1918 * case, TXTRecordSetValue() will return kDNSServiceErr_NoMemory, and this
1919 * error condition will need to be handled as appropriate by the caller.
1920 *
1921 * You can avoid the need to handle this error condition if you ensure
1922 * that the storage you initially provide is large enough to hold all
1923 * the key/value pairs that are to be added to the record.
1924 * The caller can precompute the exact length required for all of the
1925 * key/value pairs to be added, or simply provide a fixed-sized buffer
1926 * known in advance to be large enough.
1927 * A no-value (key-only) key requires (1 + key length) bytes.
1928 * A key with empty value requires (1 + key length + 1) bytes.
1929 * A key with non-empty value requires (1 + key length + 1 + value length).
1930 * For most applications, DNS-SD TXT records are generally
1931 * less than 100 bytes, so in most cases a simple fixed-sized
1932 * 256-byte buffer will be more than sufficient.
1933 * Recommended size limits for DNS-SD TXT Records are discussed in
1934 * <http://files.dns-sd.org/draft-cheshire-dnsext-dns-sd.txt>
1935 *
1936 * Note: When passing parameters to and from these TXT record APIs,
1937 * the key name does not include the '=' character. The '=' character
1938 * is the separator between the key and value in the on-the-wire
1939 * packet format; it is not part of either the key or the value.
1940 *
1941 * txtRecord: A pointer to an uninitialized TXTRecordRef.
1942 *
1943 * bufferLen: The size of the storage provided in the "buffer" parameter.
1944 *
1945 * buffer: Optional caller-supplied storage used to hold the TXTRecord data.
1946 * This storage must remain valid for as long as
1947 * the TXTRecordRef.
1948 */
1949
1950 void DNSSD_API TXTRecordCreate
1951 (
1952 TXTRecordRef *txtRecord,
1953 uint16_t bufferLen,
1954 void *buffer
1955 );
1956
1957
1958 /* TXTRecordDeallocate()
1959 *
1960 * Releases any resources allocated in the course of preparing a TXT Record
1961 * using TXTRecordCreate()/TXTRecordSetValue()/TXTRecordRemoveValue().
1962 * Ownership of the buffer provided in TXTRecordCreate() returns to the client.
1963 *
1964 * txtRecord: A TXTRecordRef initialized by calling TXTRecordCreate().
1965 *
1966 */
1967
1968 void DNSSD_API TXTRecordDeallocate
1969 (
1970 TXTRecordRef *txtRecord
1971 );
1972
1973
1974 /* TXTRecordSetValue()
1975 *
1976 * Adds a key (optionally with value) to a TXTRecordRef. If the "key" already
1977 * exists in the TXTRecordRef, then the current value will be replaced with
1978 * the new value.
1979 * Keys may exist in four states with respect to a given TXT record:
1980 * - Absent (key does not appear at all)
1981 * - Present with no value ("key" appears alone)
1982 * - Present with empty value ("key=" appears in TXT record)
1983 * - Present with non-empty value ("key=value" appears in TXT record)
1984 * For more details refer to "Data Syntax for DNS-SD TXT Records" in
1985 * <http://files.dns-sd.org/draft-cheshire-dnsext-dns-sd.txt>
1986 *
1987 * txtRecord: A TXTRecordRef initialized by calling TXTRecordCreate().
1988 *
1989 * key: A null-terminated string which only contains printable ASCII
1990 * values (0x20-0x7E), excluding '=' (0x3D). Keys should be
1991 * 8 characters or less (not counting the terminating null).
1992 *
1993 * valueSize: The size of the value.
1994 *
1995 * value: Any binary value. For values that represent
1996 * textual data, UTF-8 is STRONGLY recommended.
1997 * For values that represent textual data, valueSize
1998 * should NOT include the terminating null (if any)
1999 * at the end of the string.
2000 * If NULL, then "key" will be added with no value.
2001 * If non-NULL but valueSize is zero, then "key=" will be
2002 * added with empty value.
2003 *
2004 * return value: Returns kDNSServiceErr_NoError on success.
2005 * Returns kDNSServiceErr_Invalid if the "key" string contains
2006 * illegal characters.
2007 * Returns kDNSServiceErr_NoMemory if adding this key would
2008 * exceed the available storage.
2009 */
2010
2011 DNSServiceErrorType DNSSD_API TXTRecordSetValue
2012 (
2013 TXTRecordRef *txtRecord,
2014 const char *key,
2015 uint8_t valueSize, /* may be zero */
2016 const void *value /* may be NULL */
2017 );
2018
2019
2020 /* TXTRecordRemoveValue()
2021 *
2022 * Removes a key from a TXTRecordRef. The "key" must be an
2023 * ASCII string which exists in the TXTRecordRef.
2024 *
2025 * txtRecord: A TXTRecordRef initialized by calling TXTRecordCreate().
2026 *
2027 * key: A key name which exists in the TXTRecordRef.
2028 *
2029 * return value: Returns kDNSServiceErr_NoError on success.
2030 * Returns kDNSServiceErr_NoSuchKey if the "key" does not
2031 * exist in the TXTRecordRef.
2032 */
2033
2034 DNSServiceErrorType DNSSD_API TXTRecordRemoveValue
2035 (
2036 TXTRecordRef *txtRecord,
2037 const char *key
2038 );
2039
2040
2041 /* TXTRecordGetLength()
2042 *
2043 * Allows you to determine the length of the raw bytes within a TXTRecordRef.
2044 *
2045 * txtRecord: A TXTRecordRef initialized by calling TXTRecordCreate().
2046 *
2047 * return value: Returns the size of the raw bytes inside a TXTRecordRef
2048 * which you can pass directly to DNSServiceRegister() or
2049 * to DNSServiceUpdateRecord().
2050 * Returns 0 if the TXTRecordRef is empty.
2051 */
2052
2053 uint16_t DNSSD_API TXTRecordGetLength
2054 (
2055 const TXTRecordRef *txtRecord
2056 );
2057
2058
2059 /* TXTRecordGetBytesPtr()
2060 *
2061 * Allows you to retrieve a pointer to the raw bytes within a TXTRecordRef.
2062 *
2063 * txtRecord: A TXTRecordRef initialized by calling TXTRecordCreate().
2064 *
2065 * return value: Returns a pointer to the raw bytes inside the TXTRecordRef
2066 * which you can pass directly to DNSServiceRegister() or
2067 * to DNSServiceUpdateRecord().
2068 */
2069
2070 const void * DNSSD_API TXTRecordGetBytesPtr
2071 (
2072 const TXTRecordRef *txtRecord
2073 );
2074
2075
2076 /*********************************************************************************************
2077 *
2078 * TXT Record Parsing Functions
2079 *
2080 *********************************************************************************************/
2081
2082 /*
2083 * A typical calling sequence for TXT record parsing is something like:
2084 *
2085 * Receive TXT record data in DNSServiceResolve() callback
2086 * if (TXTRecordContainsKey(txtLen, txtRecord, "key")) then do something
2087 * val1ptr = TXTRecordGetValuePtr(txtLen, txtRecord, "key1", &len1);
2088 * val2ptr = TXTRecordGetValuePtr(txtLen, txtRecord, "key2", &len2);
2089 * ...
2090 * bcopy(val1ptr, myval1, len1);
2091 * bcopy(val2ptr, myval2, len2);
2092 * ...
2093 * return;
2094 *
2095 * If you wish to retain the values after return from the DNSServiceResolve()
2096 * callback, then you need to copy the data to your own storage using bcopy()
2097 * or similar, as shown in the example above.
2098 *
2099 * If for some reason you need to parse a TXT record you built yourself
2100 * using the TXT record construction functions above, then you can do
2101 * that using TXTRecordGetLength and TXTRecordGetBytesPtr calls:
2102 * TXTRecordGetValue(TXTRecordGetLength(x), TXTRecordGetBytesPtr(x), key, &len);
2103 *
2104 * Most applications only fetch keys they know about from a TXT record and
2105 * ignore the rest.
2106 * However, some debugging tools wish to fetch and display all keys.
2107 * To do that, use the TXTRecordGetCount() and TXTRecordGetItemAtIndex() calls.
2108 */
2109
2110 /* TXTRecordContainsKey()
2111 *
2112 * Allows you to determine if a given TXT Record contains a specified key.
2113 *
2114 * txtLen: The size of the received TXT Record.
2115 *
2116 * txtRecord: Pointer to the received TXT Record bytes.
2117 *
2118 * key: A null-terminated ASCII string containing the key name.
2119 *
2120 * return value: Returns 1 if the TXT Record contains the specified key.
2121 * Otherwise, it returns 0.
2122 */
2123
2124 int DNSSD_API TXTRecordContainsKey
2125 (
2126 uint16_t txtLen,
2127 const void *txtRecord,
2128 const char *key
2129 );
2130
2131
2132 /* TXTRecordGetValuePtr()
2133 *
2134 * Allows you to retrieve the value for a given key from a TXT Record.
2135 *
2136 * txtLen: The size of the received TXT Record
2137 *
2138 * txtRecord: Pointer to the received TXT Record bytes.
2139 *
2140 * key: A null-terminated ASCII string containing the key name.
2141 *
2142 * valueLen: On output, will be set to the size of the "value" data.
2143 *
2144 * return value: Returns NULL if the key does not exist in this TXT record,
2145 * or exists with no value (to differentiate between
2146 * these two cases use TXTRecordContainsKey()).
2147 * Returns pointer to location within TXT Record bytes
2148 * if the key exists with empty or non-empty value.
2149 * For empty value, valueLen will be zero.
2150 * For non-empty value, valueLen will be length of value data.
2151 */
2152
2153 const void * DNSSD_API TXTRecordGetValuePtr
2154 (
2155 uint16_t txtLen,
2156 const void *txtRecord,
2157 const char *key,
2158 uint8_t *valueLen
2159 );
2160
2161
2162 /* TXTRecordGetCount()
2163 *
2164 * Returns the number of keys stored in the TXT Record. The count
2165 * can be used with TXTRecordGetItemAtIndex() to iterate through the keys.
2166 *
2167 * txtLen: The size of the received TXT Record.
2168 *
2169 * txtRecord: Pointer to the received TXT Record bytes.
2170 *
2171 * return value: Returns the total number of keys in the TXT Record.
2172 *
2173 */
2174
2175 uint16_t DNSSD_API TXTRecordGetCount
2176 (
2177 uint16_t txtLen,
2178 const void *txtRecord
2179 );
2180
2181
2182 /* TXTRecordGetItemAtIndex()
2183 *
2184 * Allows you to retrieve a key name and value pointer, given an index into
2185 * a TXT Record. Legal index values range from zero to TXTRecordGetCount()-1.
2186 * It's also possible to iterate through keys in a TXT record by simply
2187 * calling TXTRecordGetItemAtIndex() repeatedly, beginning with index zero
2188 * and increasing until TXTRecordGetItemAtIndex() returns kDNSServiceErr_Invalid.
2189 *
2190 * On return:
2191 * For keys with no value, *value is set to NULL and *valueLen is zero.
2192 * For keys with empty value, *value is non-NULL and *valueLen is zero.
2193 * For keys with non-empty value, *value is non-NULL and *valueLen is non-zero.
2194 *
2195 * txtLen: The size of the received TXT Record.
2196 *
2197 * txtRecord: Pointer to the received TXT Record bytes.
2198 *
2199 * itemIndex: An index into the TXT Record.
2200 *
2201 * keyBufLen: The size of the string buffer being supplied.
2202 *
2203 * key: A string buffer used to store the key name.
2204 * On return, the buffer contains a null-terminated C string
2205 * giving the key name. DNS-SD TXT keys are usually
2206 * 8 characters or less. To hold the maximum possible
2207 * key name, the buffer should be 256 bytes long.
2208 *
2209 * valueLen: On output, will be set to the size of the "value" data.
2210 *
2211 * value: On output, *value is set to point to location within TXT
2212 * Record bytes that holds the value data.
2213 *
2214 * return value: Returns kDNSServiceErr_NoError on success.
2215 * Returns kDNSServiceErr_NoMemory if keyBufLen is too short.
2216 * Returns kDNSServiceErr_Invalid if index is greater than
2217 * TXTRecordGetCount()-1.
2218 */
2219
2220 DNSServiceErrorType DNSSD_API TXTRecordGetItemAtIndex
2221 (
2222 uint16_t txtLen,
2223 const void *txtRecord,
2224 uint16_t itemIndex,
2225 uint16_t keyBufLen,
2226 char *key,
2227 uint8_t *valueLen,
2228 const void **value
2229 );
2230
2231 #ifdef __APPLE_API_PRIVATE
2232
2233 /*
2234 * Mac OS X specific functionality
2235 * 3rd party clients of this API should not depend on future support or availability of this routine
2236 */
2237
2238 /* DNSServiceSetDefaultDomainForUser()
2239 *
2240 * Set the default domain for the caller's UID. Future browse and registration
2241 * calls by this user that do not specify an explicit domain will browse and
2242 * register in this wide-area domain in addition to .local. In addition, this
2243 * domain will be returned as a Browse domain via domain enumeration calls.
2244 *
2245 * Parameters:
2246 *
2247 * flags: Pass kDNSServiceFlagsAdd to add a domain for a user. Call without
2248 * this flag set to clear a previously added domain.
2249 *
2250 * domain: The domain to be used for the caller's UID.
2251 *
2252 * return value: Returns kDNSServiceErr_NoError on success, otherwise returns
2253 * an error code indicating the error that occurred.
2254 */
2255
2256 DNSServiceErrorType DNSSD_API DNSServiceSetDefaultDomainForUser
2257 (
2258 DNSServiceFlags flags,
2259 const char *domain
2260 );
2261
2262 /* Symbol defined to tell System Configuration Framework where to look in the Dynamic Store
2263 * for the list of PrivateDNS domains that need to be handed off to mDNSResponder
2264 * (the complete key is "State:/Network/PrivateDNS")
2265 */
2266 #define kDNSServiceCompPrivateDNS "PrivateDNS"
2267 #define kDNSServiceCompMulticastDNS "MulticastDNS"
2268
2269 #endif //__APPLE_API_PRIVATE
2270
2271 /* Some C compiler cleverness. We can make the compiler check certain things for us,
2272 * and report errors at compile-time if anything is wrong. The usual way to do this would
2273 * be to use a run-time "if" statement or the conventional run-time "assert" mechanism, but
2274 * then you don't find out what's wrong until you run the software. This way, if the assertion
2275 * condition is false, the array size is negative, and the complier complains immediately.
2276 */
2277
2278 struct CompileTimeAssertionChecks_DNS_SD
2279 {
2280 char assert0[(sizeof(union _TXTRecordRef_t) == 16) ? 1 : -1];
2281 };
2282
2283 #ifdef __cplusplus
2284 }
2285 #endif
2286
2287 #endif /* _DNS_SD_H */