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