]> git.saurik.com Git - apple/mdnsresponder.git/blob - mDNSShared/dns_sd.h
mDNSResponder-58.8.1.tar.gz
[apple/mdnsresponder.git] / mDNSShared / dns_sd.h
1 /*
2 * Copyright (c) 2003-2004, Apple Computer, Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are met:
6 *
7 * 1. Redistributions of source code must retain the above copyright notice,
8 * this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright notice,
10 * this list of conditions and the following disclaimer in the documentation
11 * and/or other materials provided with the distribution.
12 * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of its
13 * contributors may be used to endorse or promote products derived from this
14 * software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28 #ifndef _DNS_SD_H
29 #define _DNS_SD_H
30
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
34
35 /* standard calling convention under Win32 is __stdcall */
36 #if defined(_WIN32)
37 #define DNSSD_API __stdcall
38 #else
39 #define DNSSD_API
40 #endif
41
42 #if defined(__FreeBSD_version) && (__FreeBSD_version < 500000)
43 /* stdint.h does not exist on FreeBSD 4.x; its types are defined in sys/types.h instead */
44 #include <sys/types.h>
45 #elif defined(__sun__)
46 #include <sys/types.h>
47 #elif defined(_WIN32)
48 #include <windows.h>
49 #define _UNUSED
50 #define bzero(a, b) memset(a, 0, b)
51 typedef UINT8 uint8_t;
52 typedef INT8 int8_t;
53 typedef UINT16 uint16_t;
54 typedef INT16 int16_t;
55 typedef UINT32 uint32_t;
56 typedef INT32 int32_t;
57 #else
58 #include <stdint.h>
59 #endif
60
61 /* DNSServiceRef, DNSRecordRef
62 *
63 * Opaque internal data types.
64 * Note: client is responsible for serializing access to these structures if
65 * they are shared between concurrent threads.
66 */
67
68 typedef struct _DNSServiceRef_t *DNSServiceRef;
69 typedef struct _DNSRecordRef_t *DNSRecordRef;
70
71 /* General flags used in functions defined below */
72 enum
73 {
74 kDNSServiceFlagsMoreComing = 0x1,
75 /* MoreComing indicates to a callback that at least one more result is
76 * queued and will be delivered following immediately after this one.
77 * Applications should not update their UI to display browse
78 * results when the MoreComing flag is set, because this would
79 * result in a great deal of ugly flickering on the screen.
80 * Applications should instead wait until until MoreComing is not set,
81 * and then update their UI.
82 * When MoreComing is not set, that doesn't mean there will be no more
83 * answers EVER, just that there are no more answers immediately
84 * available right now at this instant. If more answers become available
85 * in the future they will be delivered as usual.
86 */
87
88 kDNSServiceFlagsAdd = 0x2,
89 kDNSServiceFlagsDefault = 0x4,
90 /* Flags for domain enumeration and browse/query reply callbacks.
91 * "Default" applies only to enumeration and is only valid in
92 * conjuction with "Add". An enumeration callback with the "Add"
93 * flag NOT set indicates a "Remove", i.e. the domain is no longer
94 * valid.
95 */
96
97 kDNSServiceFlagsNoAutoRename = 0x8,
98 /* Flag for specifying renaming behavior on name conflict when registering
99 * non-shared records. By default, name conflicts are automatically handled
100 * by renaming the service. NoAutoRename overrides this behavior - with this
101 * flag set, name conflicts will result in a callback. The NoAutorename flag
102 * is only valid if a name is explicitly specified when registering a service
103 * (i.e. the default name is not used.)
104 */
105
106 kDNSServiceFlagsShared = 0x10,
107 kDNSServiceFlagsUnique = 0x20,
108 /* Flag for registering individual records on a connected
109 * DNSServiceRef. Shared indicates that there may be multiple records
110 * with this name on the network (e.g. PTR records). Unique indicates that the
111 * record's name is to be unique on the network (e.g. SRV records).
112 */
113
114 kDNSServiceFlagsBrowseDomains = 0x40,
115 kDNSServiceFlagsRegistrationDomains = 0x80,
116 /* Flags for specifying domain enumeration type in DNSServiceEnumerateDomains.
117 * BrowseDomains enumerates domains recommended for browsing, RegistrationDomains
118 * enumerates domains recommended for registration.
119 */
120
121 kDNSServiceFlagsLongLivedQuery = 0x100,
122 /* Flag for creating a long-lived unicast query for the DNSServiceQueryRecord call. */
123
124 kDNSServiceFlagsAllowRemoteQuery = 0x200,
125 /* Flag for creating a record for which we will answer remote queries
126 * (queries from hosts more than one hop away; hosts not directly connected to the local link).
127 */
128
129 kDNSServiceFlagsForceMulticast = 0x400
130 /* Flag for signifying that a query or registration should be performed exclusively via multicast DNS,
131 * even for a name in a domain (e.g. foo.apple.com.) that would normally imply unicast DNS.
132 */
133 };
134
135 /*
136 * The values for DNS Classes and Types are listed in RFC 1035, and are available
137 * on every OS in its DNS header file. Unfortunately every OS does not have the
138 * same header file containing DNS Class and Type constants, and the names of
139 * the constants are not consistent. For example, BIND 8 uses "T_A",
140 * BIND 9 uses "ns_t_a", Windows uses "DNS_TYPE_A", etc.
141 * For this reason, these constants are also listed here, so that code using
142 * the DNS-SD programming APIs can use these constants, so that the same code
143 * can compile on all our supported platforms.
144 */
145
146 enum
147 {
148 kDNSServiceClass_IN = 1 /* Internet */
149 };
150
151 enum
152 {
153 kDNSServiceType_A = 1, /* Host address. */
154 kDNSServiceType_NS = 2, /* Authoritative server. */
155 kDNSServiceType_MD = 3, /* Mail destination. */
156 kDNSServiceType_MF = 4, /* Mail forwarder. */
157 kDNSServiceType_CNAME = 5, /* Canonical name. */
158 kDNSServiceType_SOA = 6, /* Start of authority zone. */
159 kDNSServiceType_MB = 7, /* Mailbox domain name. */
160 kDNSServiceType_MG = 8, /* Mail group member. */
161 kDNSServiceType_MR = 9, /* Mail rename name. */
162 kDNSServiceType_NULL = 10, /* Null resource record. */
163 kDNSServiceType_WKS = 11, /* Well known service. */
164 kDNSServiceType_PTR = 12, /* Domain name pointer. */
165 kDNSServiceType_HINFO = 13, /* Host information. */
166 kDNSServiceType_MINFO = 14, /* Mailbox information. */
167 kDNSServiceType_MX = 15, /* Mail routing information. */
168 kDNSServiceType_TXT = 16, /* Text strings. */
169 kDNSServiceType_RP = 17, /* Responsible person. */
170 kDNSServiceType_AFSDB = 18, /* AFS cell database. */
171 kDNSServiceType_X25 = 19, /* X_25 calling address. */
172 kDNSServiceType_ISDN = 20, /* ISDN calling address. */
173 kDNSServiceType_RT = 21, /* Router. */
174 kDNSServiceType_NSAP = 22, /* NSAP address. */
175 kDNSServiceType_NSAP_PTR = 23, /* Reverse NSAP lookup (deprecated). */
176 kDNSServiceType_SIG = 24, /* Security signature. */
177 kDNSServiceType_KEY = 25, /* Security key. */
178 kDNSServiceType_PX = 26, /* X.400 mail mapping. */
179 kDNSServiceType_GPOS = 27, /* Geographical position (withdrawn). */
180 kDNSServiceType_AAAA = 28, /* Ip6 Address. */
181 kDNSServiceType_LOC = 29, /* Location Information. */
182 kDNSServiceType_NXT = 30, /* Next domain (security). */
183 kDNSServiceType_EID = 31, /* Endpoint identifier. */
184 kDNSServiceType_NIMLOC = 32, /* Nimrod Locator. */
185 kDNSServiceType_SRV = 33, /* Server Selection. */
186 kDNSServiceType_ATMA = 34, /* ATM Address */
187 kDNSServiceType_NAPTR = 35, /* Naming Authority PoinTeR */
188 kDNSServiceType_KX = 36, /* Key Exchange */
189 kDNSServiceType_CERT = 37, /* Certification record */
190 kDNSServiceType_A6 = 38, /* IPv6 address (deprecates AAAA) */
191 kDNSServiceType_DNAME = 39, /* Non-terminal DNAME (for IPv6) */
192 kDNSServiceType_SINK = 40, /* Kitchen sink (experimentatl) */
193 kDNSServiceType_OPT = 41, /* EDNS0 option (meta-RR) */
194 kDNSServiceType_TKEY = 249, /* Transaction key */
195 kDNSServiceType_TSIG = 250, /* Transaction signature. */
196 kDNSServiceType_IXFR = 251, /* Incremental zone transfer. */
197 kDNSServiceType_AXFR = 252, /* Transfer zone of authority. */
198 kDNSServiceType_MAILB = 253, /* Transfer mailbox records. */
199 kDNSServiceType_MAILA = 254, /* Transfer mail agent records. */
200 kDNSServiceType_ANY = 255 /* Wildcard match. */
201 };
202
203
204 /* possible error code values */
205 enum
206 {
207 kDNSServiceErr_NoError = 0,
208 kDNSServiceErr_Unknown = -65537, /* 0xFFFE FFFF */
209 kDNSServiceErr_NoSuchName = -65538,
210 kDNSServiceErr_NoMemory = -65539,
211 kDNSServiceErr_BadParam = -65540,
212 kDNSServiceErr_BadReference = -65541,
213 kDNSServiceErr_BadState = -65542,
214 kDNSServiceErr_BadFlags = -65543,
215 kDNSServiceErr_Unsupported = -65544,
216 kDNSServiceErr_NotInitialized = -65545,
217 kDNSServiceErr_AlreadyRegistered = -65547,
218 kDNSServiceErr_NameConflict = -65548,
219 kDNSServiceErr_Invalid = -65549,
220 kDNSServiceErr_Firewall = -65550,
221 kDNSServiceErr_Incompatible = -65551, /* client library incompatible with daemon */
222 kDNSServiceErr_BadInterfaceIndex = -65552,
223 kDNSServiceErr_Refused = -65553,
224 kDNSServiceErr_NoSuchRecord = -65554,
225 kDNSServiceErr_NoAuth = -65555,
226 kDNSServiceErr_NoSuchKey = -65556,
227 kDNSServiceErr_NATTraversal = -65557,
228 kDNSServiceErr_DoubleNAT = -65558,
229 kDNSServiceErr_BadTime = -65559
230 /* mDNS Error codes are in the range
231 * FFFE FF00 (-65792) to FFFE FFFF (-65537) */
232 };
233
234
235 /* Maximum length, in bytes, of a domain name represented as an escaped C-String */
236 /* including the final trailing dot, and the C-String terminating NULL at the end */
237
238 #define kDNSServiceMaxDomainName 1005
239
240 /*
241 * Notes on DNS Name Escaping
242 * -- or --
243 * "Why is kDNSServiceMaxDomainName 1005, when the maximum legal domain name is 255 bytes?"
244 *
245 * All strings used in DNS-SD are UTF-8 strings.
246 * With few exceptions, most are also escaped using standard DNS escaping rules:
247 *
248 * '\\' represents a single literal '\' in the name
249 * '\.' represents a single literal '.' in the name
250 * '\ddd', where ddd is a three-digit decimal value from 000 to 255,
251 * represents a single literal byte with that value.
252 * A bare unescaped '.' is a label separator, marking a boundary between domain and subdomain.
253 *
254 * The exceptions, that do not use escaping, are the routines where the full
255 * DNS name of a resource is broken, for convenience, into servicename/regtype/domain.
256 * In these routines, the "servicename" is NOT escaped. It does not need to be, since
257 * it is, by definition, just a single literal string. Any characters in that string
258 * represent exactly what they are. The "regtype" portion is, technically speaking,
259 * escaped, but since legal regtypes are only allowed to contain letters, digits,
260 * and hyphens, the issue is moot. The "domain" portion is also escaped, though
261 * most domains in use on the public Internet today, like regtypes, don't contain
262 * any characters that need to be escaped. As DNS-SD becomes more popular, rich-text
263 * domains for service discovery will become common, so software should be written
264 * to cope with domains with escaping.
265 *
266 * For most software, these issues are transparent. When browsing, the discovered
267 * servicenames should simply be displayed as-is. When resolving, the discovered
268 * servicename/regtype/domain are simply passed unchanged to DNSServiceResolve().
269 * When a DNSServiceResolve() succeeds, the returned fullname is already in
270 * the correct format to pass to standard system DNS APIs such as res_query().
271 * For converting from servicename/regtype/domain to a single properly-escaped
272 * full DNS name, the helper function DNSServiceConstructFullName() is provided.
273 *
274 * The following (highly contrived) example illustrates the escaping process.
275 * Suppose you have an service called "Dr. Smith\Dr. Johnson", of type "_ftp._tcp"
276 * in subdomain "4th. Floor" of subdomain "Building 2" of domain "apple.com."
277 * The full (escaped) DNS name of this service's SRV record would be:
278 * Dr\.\032Smith\\Dr\.\032Johnson._ftp._tcp.4th\.\032Floor.Building\0322.apple.com.
279 */
280
281
282 /*
283 * Constants for specifying an interface index
284 *
285 * Specific interface indexes are identified via a 32-bit unsigned integer returned
286 * by the if_nametoindex() family of calls.
287 *
288 * If the client passes 0 for interface index, that means "do the right thing",
289 * which (at present) means, "if the name is in an mDNS local multicast domain
290 * (e.g. 'local.', '254.169.in-addr.arpa.', '0.8.E.F.ip6.arpa.') then multicast
291 * on all applicable interfaces, otherwise send via unicast to the appropriate
292 * DNS server." Normally, most clients will use 0 for interface index to
293 * automatically get the default sensible behaviour.
294 *
295 * If the client passes a positive interface index, then for multicast names that
296 * indicates to do the operation only on that one interface. For unicast names the
297 * interface index is ignored unless kDNSServiceFlagsForceMulticast is also set.
298 *
299 * If the client passes kDNSServiceInterfaceIndexLocalOnly when registering
300 * a service, then that service will be found *only* by other local clients
301 * on the same machine that are browsing using kDNSServiceInterfaceIndexLocalOnly
302 * or kDNSServiceInterfaceIndexAny.
303 * If a client has a 'private' service, accessible only to other processes
304 * running on the same machine, this allows the client to advertise that service
305 * in a way such that it does not inadvertently appear in service lists on
306 * all the other machines on the network.
307 *
308 * If the client passes kDNSServiceInterfaceIndexLocalOnly when browsing
309 * then it will find *all* records registered on that same local machine.
310 * Clients explicitly wishing to discover *only* LocalOnly services can
311 * accomplish this by inspecting the interfaceIndex of each service reported
312 * to their DNSServiceBrowseReply() callback function, and discarding those
313 * where the interface index is not kDNSServiceInterfaceIndexLocalOnly.
314 */
315
316 #define kDNSServiceInterfaceIndexAny 0
317 #define kDNSServiceInterfaceIndexLocalOnly ( (uint32_t) -1 )
318
319
320 typedef uint32_t DNSServiceFlags;
321 typedef int32_t DNSServiceErrorType;
322
323
324 /*********************************************************************************************
325 *
326 * Unix Domain Socket access, DNSServiceRef deallocation, and data processing functions
327 *
328 *********************************************************************************************/
329
330
331 /* DNSServiceRefSockFD()
332 *
333 * Access underlying Unix domain socket for an initialized DNSServiceRef.
334 * The DNS Service Discovery implmementation uses this socket to communicate between
335 * the client and the mDNSResponder daemon. The application MUST NOT directly read from
336 * or write to this socket. Access to the socket is provided so that it can be used as a
337 * run loop source, or in a select() loop: when data is available for reading on the socket,
338 * DNSServiceProcessResult() should be called, which will extract the daemon's reply from
339 * the socket, and pass it to the appropriate application callback. By using a run loop or
340 * select(), results from the daemon can be processed asynchronously. Without using these
341 * constructs, DNSServiceProcessResult() will block until the response from the daemon arrives.
342 * The client is responsible for ensuring that the data on the socket is processed in a timely
343 * fashion - the daemon may terminate its connection with a client that does not clear its
344 * socket buffer.
345 *
346 * sdRef: A DNSServiceRef initialized by any of the DNSService calls.
347 *
348 * return value: The DNSServiceRef's underlying socket descriptor, or -1 on
349 * error.
350 */
351
352 int DNSSD_API DNSServiceRefSockFD(DNSServiceRef sdRef);
353
354
355 /* DNSServiceProcessResult()
356 *
357 * Read a reply from the daemon, calling the appropriate application callback. This call will
358 * block until the daemon's response is received. Use DNSServiceRefSockFD() in
359 * conjunction with a run loop or select() to determine the presence of a response from the
360 * server before calling this function to process the reply without blocking. Call this function
361 * at any point if it is acceptable to block until the daemon's response arrives. Note that the
362 * client is responsible for ensuring that DNSServiceProcessResult() is called whenever there is
363 * a reply from the daemon - the daemon may terminate its connection with a client that does not
364 * process the daemon's responses.
365 *
366 * sdRef: A DNSServiceRef initialized by any of the DNSService calls
367 * that take a callback parameter.
368 *
369 * return value: Returns kDNSServiceErr_NoError on success, otherwise returns
370 * an error code indicating the specific failure that occurred.
371 */
372
373 DNSServiceErrorType DNSSD_API DNSServiceProcessResult(DNSServiceRef sdRef);
374
375
376 /* DNSServiceRefDeallocate()
377 *
378 * Terminate a connection with the daemon and free memory associated with the DNSServiceRef.
379 * Any services or records registered with this DNSServiceRef will be deregistered. Any
380 * Browse, Resolve, or Query operations called with this reference will be terminated.
381 *
382 * Note: If the reference's underlying socket is used in a run loop or select() call, it should
383 * be removed BEFORE DNSServiceRefDeallocate() is called, as this function closes the reference's
384 * socket.
385 *
386 * Note: If the reference was initialized with DNSServiceCreateConnection(), any DNSRecordRefs
387 * created via this reference will be invalidated by this call - the resource records are
388 * deregistered, and their DNSRecordRefs may not be used in subsequent functions. Similarly,
389 * if the reference was initialized with DNSServiceRegister, and an extra resource record was
390 * added to the service via DNSServiceAddRecord(), the DNSRecordRef created by the Add() call
391 * is invalidated when this function is called - the DNSRecordRef may not be used in subsequent
392 * functions.
393 *
394 * Note: This call is to be used only with the DNSServiceRef defined by this API. It is
395 * not compatible with dns_service_discovery_ref objects defined in the legacy Mach-based
396 * DNSServiceDiscovery.h API.
397 *
398 * sdRef: A DNSServiceRef initialized by any of the DNSService calls.
399 *
400 */
401
402 void DNSSD_API DNSServiceRefDeallocate(DNSServiceRef sdRef);
403
404
405 /*********************************************************************************************
406 *
407 * Domain Enumeration
408 *
409 *********************************************************************************************/
410
411 /* DNSServiceEnumerateDomains()
412 *
413 * Asynchronously enumerate domains available for browsing and registration.
414 *
415 * The enumeration MUST be cancelled via DNSServiceRefDeallocate() when no more domains
416 * are to be found.
417 *
418 * Note that the names returned are (like all of DNS-SD) UTF-8 strings,
419 * and are escaped using standard DNS escaping rules.
420 * (See "Notes on DNS Name Escaping" earlier in this file for more details.)
421 * A graphical browser displaying a hierarchical tree-structured view should cut
422 * the names at the bare dots to yield individual labels, then de-escape each
423 * label according to the escaping rules, and then display the resulting UTF-8 text.
424 *
425 * DNSServiceDomainEnumReply Callback Parameters:
426 *
427 * sdRef: The DNSServiceRef initialized by DNSServiceEnumerateDomains().
428 *
429 * flags: Possible values are:
430 * kDNSServiceFlagsMoreComing
431 * kDNSServiceFlagsAdd
432 * kDNSServiceFlagsDefault
433 *
434 * interfaceIndex: Specifies the interface on which the domain exists. (The index for a given
435 * interface is determined via the if_nametoindex() family of calls.)
436 *
437 * errorCode: Will be kDNSServiceErr_NoError (0) on success, otherwise indicates
438 * the failure that occurred (other parameters are undefined if errorCode is nonzero).
439 *
440 * replyDomain: The name of the domain.
441 *
442 * context: The context pointer passed to DNSServiceEnumerateDomains.
443 *
444 */
445
446 typedef void (DNSSD_API *DNSServiceDomainEnumReply)
447 (
448 DNSServiceRef sdRef,
449 DNSServiceFlags flags,
450 uint32_t interfaceIndex,
451 DNSServiceErrorType errorCode,
452 const char *replyDomain,
453 void *context
454 );
455
456
457 /* DNSServiceEnumerateDomains() Parameters:
458 *
459 *
460 * sdRef: A pointer to an uninitialized DNSServiceRef. If the call succeeds
461 * then it initializes the DNSServiceRef, returns kDNSServiceErr_NoError,
462 * and the enumeration operation will run indefinitely until the client
463 * terminates it by passing this DNSServiceRef to DNSServiceRefDeallocate().
464 *
465 * flags: Possible values are:
466 * kDNSServiceFlagsBrowseDomains to enumerate domains recommended for browsing.
467 * kDNSServiceFlagsRegistrationDomains to enumerate domains recommended
468 * for registration.
469 *
470 * interfaceIndex: If non-zero, specifies the interface on which to look for domains.
471 * (the index for a given interface is determined via the if_nametoindex()
472 * family of calls.) Most applications will pass 0 to enumerate domains on
473 * all interfaces. See "Constants for specifying an interface index" for more details.
474 *
475 * callBack: The function to be called when a domain is found or the call asynchronously
476 * fails.
477 *
478 * context: An application context pointer which is passed to the callback function
479 * (may be NULL).
480 *
481 * return value: Returns kDNSServiceErr_NoError on succeses (any subsequent, asynchronous
482 * errors are delivered to the callback), otherwise returns an error code indicating
483 * the error that occurred (the callback is not invoked and the DNSServiceRef
484 * is not initialized.)
485 */
486
487 DNSServiceErrorType DNSSD_API DNSServiceEnumerateDomains
488 (
489 DNSServiceRef *sdRef,
490 DNSServiceFlags flags,
491 uint32_t interfaceIndex,
492 DNSServiceDomainEnumReply callBack,
493 void *context /* may be NULL */
494 );
495
496
497 /*********************************************************************************************
498 *
499 * Service Registration
500 *
501 *********************************************************************************************/
502
503 /* Register a service that is discovered via Browse() and Resolve() calls.
504 *
505 *
506 * DNSServiceRegisterReply() Callback Parameters:
507 *
508 * sdRef: The DNSServiceRef initialized by DNSServiceRegister().
509 *
510 * flags: Currently unused, reserved for future use.
511 *
512 * errorCode: Will be kDNSServiceErr_NoError on success, otherwise will
513 * indicate the failure that occurred (including name conflicts, if the
514 * kDNSServiceFlagsNoAutoRename flag was passed to the
515 * callout.) Other parameters are undefined if errorCode is nonzero.
516 *
517 * name: The service name registered (if the application did not specify a name in
518 * DNSServiceRegister(), this indicates what name was automatically chosen).
519 *
520 * regtype: The type of service registered, as it was passed to the callout.
521 *
522 * domain: The domain on which the service was registered (if the application did not
523 * specify a domain in DNSServiceRegister(), this indicates the default domain
524 * on which the service was registered).
525 *
526 * context: The context pointer that was passed to the callout.
527 *
528 */
529
530 typedef void (DNSSD_API *DNSServiceRegisterReply)
531 (
532 DNSServiceRef sdRef,
533 DNSServiceFlags flags,
534 DNSServiceErrorType errorCode,
535 const char *name,
536 const char *regtype,
537 const char *domain,
538 void *context
539 );
540
541
542 /* DNSServiceRegister() Parameters:
543 *
544 * sdRef: A pointer to an uninitialized DNSServiceRef. If the call succeeds
545 * then it initializes the DNSServiceRef, returns kDNSServiceErr_NoError,
546 * and the registration will remain active indefinitely until the client
547 * terminates it by passing this DNSServiceRef to DNSServiceRefDeallocate().
548 *
549 * interfaceIndex: If non-zero, specifies the interface on which to register the service
550 * (the index for a given interface is determined via the if_nametoindex()
551 * family of calls.) Most applications will pass 0 to register on all
552 * available interfaces. See "Constants for specifying an interface index" for more details.
553 *
554 * flags: Indicates the renaming behavior on name conflict (most applications
555 * will pass 0). See flag definitions above for details.
556 *
557 * name: If non-NULL, specifies the service name to be registered.
558 * Most applications will not specify a name, in which case the
559 * computer name is used (this name is communicated to the client via
560 * the callback).
561 *
562 * regtype: The service type followed by the protocol, separated by a dot
563 * (e.g. "_ftp._tcp"). The transport protocol must be "_tcp" or "_udp".
564 * New service types should be registered at htp://www.dns-sd.org/ServiceTypes.html.
565 *
566 * domain: If non-NULL, specifies the domain on which to advertise the service.
567 * Most applications will not specify a domain, instead automatically
568 * registering in the default domain(s).
569 *
570 * host: If non-NULL, specifies the SRV target host name. Most applications
571 * will not specify a host, instead automatically using the machine's
572 * default host name(s). Note that specifying a non-NULL host does NOT
573 * create an address record for that host - the application is responsible
574 * for ensuring that the appropriate address record exists, or creating it
575 * via DNSServiceRegisterRecord().
576 *
577 * port: The port, in network byte order, on which the service accepts connections.
578 * Pass 0 for a "placeholder" service (i.e. a service that will not be discovered
579 * by browsing, but will cause a name conflict if another client tries to
580 * register that same name). Most clients will not use placeholder services.
581 *
582 * txtLen: The length of the txtRecord, in bytes. Must be zero if the txtRecord is NULL.
583 *
584 * txtRecord: The txt record rdata. May be NULL. Note that a non-NULL txtRecord
585 * MUST be a properly formatted DNS TXT record, i.e. <length byte> <data>
586 * <length byte> <data> ...
587 *
588 * callBack: The function to be called when the registration completes or asynchronously
589 * fails. The client MAY pass NULL for the callback - The client will NOT be notified
590 * of the default values picked on its behalf, and the client will NOT be notified of any
591 * asynchronous errors (e.g. out of memory errors, etc.) that may prevent the registration
592 * of the service. The client may NOT pass the NoAutoRename flag if the callback is NULL.
593 * The client may still deregister the service at any time via DNSServiceRefDeallocate().
594 *
595 * context: An application context pointer which is passed to the callback function
596 * (may be NULL).
597 *
598 * return value: Returns kDNSServiceErr_NoError on succeses (any subsequent, asynchronous
599 * errors are delivered to the callback), otherwise returns an error code indicating
600 * the error that occurred (the callback is never invoked and the DNSServiceRef
601 * is not initialized.)
602 *
603 */
604
605 DNSServiceErrorType DNSSD_API DNSServiceRegister
606 (
607 DNSServiceRef *sdRef,
608 DNSServiceFlags flags,
609 uint32_t interfaceIndex,
610 const char *name, /* may be NULL */
611 const char *regtype,
612 const char *domain, /* may be NULL */
613 const char *host, /* may be NULL */
614 uint16_t port,
615 uint16_t txtLen,
616 const void *txtRecord, /* may be NULL */
617 DNSServiceRegisterReply callBack, /* may be NULL */
618 void *context /* may be NULL */
619 );
620
621
622 /* DNSServiceAddRecord()
623 *
624 * Add a record to a registered service. The name of the record will be the same as the
625 * registered service's name.
626 * The record can later be updated or deregistered by passing the RecordRef initialized
627 * by this function to DNSServiceUpdateRecord() or DNSServiceRemoveRecord().
628 *
629 *
630 * Parameters;
631 *
632 * sdRef: A DNSServiceRef initialized by DNSServiceRegister().
633 *
634 * RecordRef: A pointer to an uninitialized DNSRecordRef. Upon succesfull completion of this
635 * call, this ref may be passed to DNSServiceUpdateRecord() or DNSServiceRemoveRecord().
636 * If the above DNSServiceRef is passed to DNSServiceRefDeallocate(), RecordRef is also
637 * invalidated and may not be used further.
638 *
639 * flags: Currently ignored, reserved for future use.
640 *
641 * rrtype: The type of the record (e.g. kDNSServiceType_TXT, kDNSServiceType_SRV, etc)
642 *
643 * rdlen: The length, in bytes, of the rdata.
644 *
645 * rdata: The raw rdata to be contained in the added resource record.
646 *
647 * ttl: The time to live of the resource record, in seconds. Pass 0 to use a default value.
648 *
649 * return value: Returns kDNSServiceErr_NoError on success, otherwise returns an
650 * error code indicating the error that occurred (the RecordRef is not initialized).
651 */
652
653 DNSServiceErrorType DNSSD_API DNSServiceAddRecord
654 (
655 DNSServiceRef sdRef,
656 DNSRecordRef *RecordRef,
657 DNSServiceFlags flags,
658 uint16_t rrtype,
659 uint16_t rdlen,
660 const void *rdata,
661 uint32_t ttl
662 );
663
664
665 /* DNSServiceUpdateRecord
666 *
667 * Update a registered resource record. The record must either be:
668 * - The primary txt record of a service registered via DNSServiceRegister()
669 * - A record added to a registered service via DNSServiceAddRecord()
670 * - An individual record registered by DNSServiceRegisterRecord()
671 *
672 *
673 * Parameters:
674 *
675 * sdRef: A DNSServiceRef that was initialized by DNSServiceRegister()
676 * or DNSServiceCreateConnection().
677 *
678 * RecordRef: A DNSRecordRef initialized by DNSServiceAddRecord, or NULL to update the
679 * service's primary txt record.
680 *
681 * flags: Currently ignored, reserved for future use.
682 *
683 * rdlen: The length, in bytes, of the new rdata.
684 *
685 * rdata: The new rdata to be contained in the updated resource record.
686 *
687 * ttl: The time to live of the updated resource record, in seconds.
688 *
689 * return value: Returns kDNSServiceErr_NoError on success, otherwise returns an
690 * error code indicating the error that occurred.
691 */
692
693 DNSServiceErrorType DNSSD_API DNSServiceUpdateRecord
694 (
695 DNSServiceRef sdRef,
696 DNSRecordRef RecordRef, /* may be NULL */
697 DNSServiceFlags flags,
698 uint16_t rdlen,
699 const void *rdata,
700 uint32_t ttl
701 );
702
703
704 /* DNSServiceRemoveRecord
705 *
706 * Remove a record previously added to a service record set via DNSServiceAddRecord(), or deregister
707 * an record registered individually via DNSServiceRegisterRecord().
708 *
709 * Parameters:
710 *
711 * sdRef: A DNSServiceRef initialized by DNSServiceRegister() (if the
712 * record being removed was registered via DNSServiceAddRecord()) or by
713 * DNSServiceCreateConnection() (if the record being removed was registered via
714 * DNSServiceRegisterRecord()).
715 *
716 * recordRef: A DNSRecordRef initialized by a successful call to DNSServiceAddRecord()
717 * or DNSServiceRegisterRecord().
718 *
719 * flags: Currently ignored, reserved for future use.
720 *
721 * return value: Returns kDNSServiceErr_NoError on success, otherwise returns an
722 * error code indicating the error that occurred.
723 */
724
725 DNSServiceErrorType DNSSD_API DNSServiceRemoveRecord
726 (
727 DNSServiceRef sdRef,
728 DNSRecordRef RecordRef,
729 DNSServiceFlags flags
730 );
731
732
733 /*********************************************************************************************
734 *
735 * Service Discovery
736 *
737 *********************************************************************************************/
738
739 /* Browse for instances of a service.
740 *
741 *
742 * DNSServiceBrowseReply() Parameters:
743 *
744 * sdRef: The DNSServiceRef initialized by DNSServiceBrowse().
745 *
746 * flags: Possible values are kDNSServiceFlagsMoreComing and kDNSServiceFlagsAdd.
747 * See flag definitions for details.
748 *
749 * interfaceIndex: The interface on which the service is advertised. This index should
750 * be passed to DNSServiceResolve() when resolving the service.
751 *
752 * errorCode: Will be kDNSServiceErr_NoError (0) on success, otherwise will
753 * indicate the failure that occurred. Other parameters are undefined if
754 * the errorCode is nonzero.
755 *
756 * serviceName: The discovered service name. This name should be displayed to the user,
757 * and stored for subsequent use in the DNSServiceResolve() call.
758 *
759 * regtype: The service type, which is usually (but not always) the same as was passed
760 * to DNSServiceBrowse(). One case where the discovered service type may
761 * not be the same as the requested service type is when using subtypes:
762 * The client may want to browse for only those ftp servers that allow
763 * anonymous connections. The client will pass the string "_ftp._tcp,_anon"
764 * to DNSServiceBrowse(), but the type of the service that's discovered
765 * is simply "_ftp._tcp". The regtype for each discovered service instance
766 * should be stored along with the name, so that it can be passed to
767 * DNSServiceResolve() when the service is later resolved.
768 *
769 * domain: The domain of the discovered service instance. This may or may not be the
770 * same as the domain that was passed to DNSServiceBrowse(). The domain for each
771 * discovered service instance should be stored along with the name, so that
772 * it can be passed to DNSServiceResolve() when the service is later resolved.
773 *
774 * context: The context pointer that was passed to the callout.
775 *
776 */
777
778 typedef void (DNSSD_API *DNSServiceBrowseReply)
779 (
780 DNSServiceRef sdRef,
781 DNSServiceFlags flags,
782 uint32_t interfaceIndex,
783 DNSServiceErrorType errorCode,
784 const char *serviceName,
785 const char *regtype,
786 const char *replyDomain,
787 void *context
788 );
789
790
791 /* DNSServiceBrowse() Parameters:
792 *
793 * sdRef: A pointer to an uninitialized DNSServiceRef. If the call succeeds
794 * then it initializes the DNSServiceRef, returns kDNSServiceErr_NoError,
795 * and the browse operation will run indefinitely until the client
796 * terminates it by passing this DNSServiceRef to DNSServiceRefDeallocate().
797 *
798 * flags: Currently ignored, reserved for future use.
799 *
800 * interfaceIndex: If non-zero, specifies the interface on which to browse for services
801 * (the index for a given interface is determined via the if_nametoindex()
802 * family of calls.) Most applications will pass 0 to browse on all available
803 * interfaces. See "Constants for specifying an interface index" for more details.
804 *
805 * regtype: The service type being browsed for followed by the protocol, separated by a
806 * dot (e.g. "_ftp._tcp"). The transport protocol must be "_tcp" or "_udp".
807 *
808 * domain: If non-NULL, specifies the domain on which to browse for services.
809 * Most applications will not specify a domain, instead browsing on the
810 * default domain(s).
811 *
812 * callBack: The function to be called when an instance of the service being browsed for
813 * is found, or if the call asynchronously fails.
814 *
815 * context: An application context pointer which is passed to the callback function
816 * (may be NULL).
817 *
818 * return value: Returns kDNSServiceErr_NoError on succeses (any subsequent, asynchronous
819 * errors are delivered to the callback), otherwise returns an error code indicating
820 * the error that occurred (the callback is not invoked and the DNSServiceRef
821 * is not initialized.)
822 */
823
824 DNSServiceErrorType DNSSD_API DNSServiceBrowse
825 (
826 DNSServiceRef *sdRef,
827 DNSServiceFlags flags,
828 uint32_t interfaceIndex,
829 const char *regtype,
830 const char *domain, /* may be NULL */
831 DNSServiceBrowseReply callBack,
832 void *context /* may be NULL */
833 );
834
835
836 /* DNSServiceResolve()
837 *
838 * Resolve a service name discovered via DNSServiceBrowse() to a target host name, port number, and
839 * txt record.
840 *
841 * Note: Applications should NOT use DNSServiceResolve() solely for txt record monitoring - use
842 * DNSServiceQueryRecord() instead, as it is more efficient for this task.
843 *
844 * Note: When the desired results have been returned, the client MUST terminate the resolve by calling
845 * DNSServiceRefDeallocate().
846 *
847 * Note: DNSServiceResolve() behaves correctly for typical services that have a single SRV record and
848 * a single TXT record (the TXT record may be empty.) To resolve non-standard services with multiple
849 * SRV or TXT records, DNSServiceQueryRecord() should be used.
850 *
851 * DNSServiceResolveReply Callback Parameters:
852 *
853 * sdRef: The DNSServiceRef initialized by DNSServiceResolve().
854 *
855 * flags: Currently unused, reserved for future use.
856 *
857 * interfaceIndex: The interface on which the service was resolved.
858 *
859 * errorCode: Will be kDNSServiceErr_NoError (0) on success, otherwise will
860 * indicate the failure that occurred. Other parameters are undefined if
861 * the errorCode is nonzero.
862 *
863 * fullname: The full service domain name, in the form <servicename>.<protocol>.<domain>.
864 * (This name is escaped following standard DNS rules, making it suitable for
865 * passing to standard system DNS APIs such as res_query(), or to the
866 * special-purpose functions included in this API that take fullname parameters.
867 * See "Notes on DNS Name Escaping" earlier in this file for more details.)
868 *
869 * hosttarget: The target hostname of the machine providing the service. This name can
870 * be passed to functions like gethostbyname() to identify the host's IP address.
871 *
872 * port: The port, in network byte order, on which connections are accepted for this service.
873 *
874 * txtLen: The length of the txt record, in bytes.
875 *
876 * txtRecord: The service's primary txt record, in standard txt record format.
877 *
878
879 * context: The context pointer that was passed to the callout.
880 *
881 */
882
883 typedef void (DNSSD_API *DNSServiceResolveReply)
884 (
885 DNSServiceRef sdRef,
886 DNSServiceFlags flags,
887 uint32_t interfaceIndex,
888 DNSServiceErrorType errorCode,
889 const char *fullname,
890 const char *hosttarget,
891 uint16_t port,
892 uint16_t txtLen,
893 const char *txtRecord,
894 void *context
895 );
896
897
898 /* DNSServiceResolve() Parameters
899 *
900 * sdRef: A pointer to an uninitialized DNSServiceRef. If the call succeeds
901 * then it initializes the DNSServiceRef, returns kDNSServiceErr_NoError,
902 * and the resolve operation will run indefinitely until the client
903 * terminates it by passing this DNSServiceRef to DNSServiceRefDeallocate().
904 *
905 * flags: Currently ignored, reserved for future use.
906 *
907 * interfaceIndex: The interface on which to resolve the service. If this resolve call is
908 * as a result of a currently active DNSServiceBrowse() operation, then the
909 * interfaceIndex should be the index reported in the DNSServiceBrowseReply
910 * callback. If this resolve call is using information previously saved
911 * (e.g. in a preference file) for later use, then use interfaceIndex 0, because
912 * the desired service may now be reachable via a different physical interface.
913 * See "Constants for specifying an interface index" for more details.
914 *
915 * name: The name of the service instance to be resolved, as reported to the
916 * DNSServiceBrowseReply() callback.
917 *
918 * regtype: The type of the service instance to be resolved, as reported to the
919 * DNSServiceBrowseReply() callback.
920 *
921 * domain: The domain of the service instance to be resolved, as reported to the
922 * DNSServiceBrowseReply() callback.
923 *
924 * callBack: The function to be called when a result is found, or if the call
925 * asynchronously fails.
926 *
927 * context: An application context pointer which is passed to the callback function
928 * (may be NULL).
929 *
930 * return value: Returns kDNSServiceErr_NoError on succeses (any subsequent, asynchronous
931 * errors are delivered to the callback), otherwise returns an error code indicating
932 * the error that occurred (the callback is never invoked and the DNSServiceRef
933 * is not initialized.)
934 */
935
936 DNSServiceErrorType DNSSD_API DNSServiceResolve
937 (
938 DNSServiceRef *sdRef,
939 DNSServiceFlags flags,
940 uint32_t interfaceIndex,
941 const char *name,
942 const char *regtype,
943 const char *domain,
944 DNSServiceResolveReply callBack,
945 void *context /* may be NULL */
946 );
947
948
949 /*********************************************************************************************
950 *
951 * Special Purpose Calls (most applications will not use these)
952 *
953 *********************************************************************************************/
954
955 /* DNSServiceCreateConnection()
956 *
957 * Create a connection to the daemon allowing efficient registration of
958 * multiple individual records.
959 *
960 *
961 * Parameters:
962 *
963 * sdRef: A pointer to an uninitialized DNSServiceRef. Deallocating
964 * the reference (via DNSServiceRefDeallocate()) severs the
965 * connection and deregisters all records registered on this connection.
966 *
967 * return value: Returns kDNSServiceErr_NoError on success, otherwise returns
968 * an error code indicating the specific failure that occurred (in which
969 * case the DNSServiceRef is not initialized).
970 */
971
972 DNSServiceErrorType DNSSD_API DNSServiceCreateConnection(DNSServiceRef *sdRef);
973
974
975 /* DNSServiceRegisterRecord
976 *
977 * Register an individual resource record on a connected DNSServiceRef.
978 *
979 * Note that name conflicts occurring for records registered via this call must be handled
980 * by the client in the callback.
981 *
982 *
983 * DNSServiceRegisterRecordReply() parameters:
984 *
985 * sdRef: The connected DNSServiceRef initialized by
986 * DNSServiceDiscoveryConnect().
987 *
988 * RecordRef: The DNSRecordRef initialized by DNSServiceRegisterRecord(). If the above
989 * DNSServiceRef is passed to DNSServiceRefDeallocate(), this DNSRecordRef is
990 * invalidated, and may not be used further.
991 *
992 * flags: Currently unused, reserved for future use.
993 *
994 * errorCode: Will be kDNSServiceErr_NoError on success, otherwise will
995 * indicate the failure that occurred (including name conflicts.)
996 * Other parameters are undefined if errorCode is nonzero.
997 *
998 * context: The context pointer that was passed to the callout.
999 *
1000 */
1001
1002 typedef void (DNSSD_API *DNSServiceRegisterRecordReply)
1003 (
1004 DNSServiceRef sdRef,
1005 DNSRecordRef RecordRef,
1006 DNSServiceFlags flags,
1007 DNSServiceErrorType errorCode,
1008 void *context
1009 );
1010
1011
1012 /* DNSServiceRegisterRecord() Parameters:
1013 *
1014 * sdRef: A DNSServiceRef initialized by DNSServiceCreateConnection().
1015 *
1016 * RecordRef: A pointer to an uninitialized DNSRecordRef. Upon succesfull completion of this
1017 * call, this ref may be passed to DNSServiceUpdateRecord() or DNSServiceRemoveRecord().
1018 * (To deregister ALL records registered on a single connected DNSServiceRef
1019 * and deallocate each of their corresponding DNSServiceRecordRefs, call
1020 * DNSServiceRefDealloocate()).
1021 *
1022 * flags: Possible values are kDNSServiceFlagsShared or kDNSServiceFlagsUnique
1023 * (see flag type definitions for details).
1024 *
1025 * interfaceIndex: If non-zero, specifies the interface on which to register the record
1026 * (the index for a given interface is determined via the if_nametoindex()
1027 * family of calls.) Passing 0 causes the record to be registered on all interfaces.
1028 * See "Constants for specifying an interface index" for more details.
1029 *
1030 * fullname: The full domain name of the resource record.
1031 *
1032 * rrtype: The numerical type of the resource record (e.g. kDNSServiceType_PTR, kDNSServiceType_SRV, etc)
1033 *
1034 * rrclass: The class of the resource record (usually kDNSServiceClass_IN)
1035 *
1036 * rdlen: Length, in bytes, of the rdata.
1037 *
1038 * rdata: A pointer to the raw rdata, as it is to appear in the DNS record.
1039 *
1040 * ttl: The time to live of the resource record, in seconds. Pass 0 to use a default value.
1041 *
1042 * callBack: The function to be called when a result is found, or if the call
1043 * asynchronously fails (e.g. because of a name conflict.)
1044 *
1045 * context: An application context pointer which is passed to the callback function
1046 * (may be NULL).
1047 *
1048 * return value: Returns kDNSServiceErr_NoError on succeses (any subsequent, asynchronous
1049 * errors are delivered to the callback), otherwise returns an error code indicating
1050 * the error that occurred (the callback is never invoked and the DNSRecordRef is
1051 * not initialized.)
1052 */
1053
1054 DNSServiceErrorType DNSSD_API DNSServiceRegisterRecord
1055 (
1056 DNSServiceRef sdRef,
1057 DNSRecordRef *RecordRef,
1058 DNSServiceFlags flags,
1059 uint32_t interfaceIndex,
1060 const char *fullname,
1061 uint16_t rrtype,
1062 uint16_t rrclass,
1063 uint16_t rdlen,
1064 const void *rdata,
1065 uint32_t ttl,
1066 DNSServiceRegisterRecordReply callBack,
1067 void *context /* may be NULL */
1068 );
1069
1070
1071 /* DNSServiceQueryRecord
1072 *
1073 * Query for an arbitrary DNS record.
1074 *
1075 *
1076 * DNSServiceQueryRecordReply() Callback Parameters:
1077 *
1078 * sdRef: The DNSServiceRef initialized by DNSServiceQueryRecord().
1079 *
1080 * flags: Possible values are kDNSServiceFlagsMoreComing and
1081 * kDNSServiceFlagsAdd. The Add flag is NOT set for PTR records
1082 * with a ttl of 0, i.e. "Remove" events.
1083 *
1084 * interfaceIndex: The interface on which the query was resolved (the index for a given
1085 * interface is determined via the if_nametoindex() family of calls).
1086 * See "Constants for specifying an interface index" for more details.
1087 *
1088 * errorCode: Will be kDNSServiceErr_NoError on success, otherwise will
1089 * indicate the failure that occurred. Other parameters are undefined if
1090 * errorCode is nonzero.
1091 *
1092 * fullname: The resource record's full domain name.
1093 *
1094 * rrtype: The resource record's type (e.g. kDNSServiceType_PTR, kDNSServiceType_SRV, etc)
1095 *
1096 * rrclass: The class of the resource record (usually kDNSServiceClass_IN).
1097 *
1098 * rdlen: The length, in bytes, of the resource record rdata.
1099 *
1100 * rdata: The raw rdata of the resource record.
1101 *
1102 * ttl: The resource record's time to live, in seconds.
1103 *
1104 * context: The context pointer that was passed to the callout.
1105 *
1106 */
1107
1108 typedef void (DNSSD_API *DNSServiceQueryRecordReply)
1109 (
1110 DNSServiceRef DNSServiceRef,
1111 DNSServiceFlags flags,
1112 uint32_t interfaceIndex,
1113 DNSServiceErrorType errorCode,
1114 const char *fullname,
1115 uint16_t rrtype,
1116 uint16_t rrclass,
1117 uint16_t rdlen,
1118 const void *rdata,
1119 uint32_t ttl,
1120 void *context
1121 );
1122
1123
1124 /* DNSServiceQueryRecord() Parameters:
1125 *
1126 * sdRef: A pointer to an uninitialized DNSServiceRef. If the call succeeds
1127 * then it initializes the DNSServiceRef, returns kDNSServiceErr_NoError,
1128 * and the query operation will run indefinitely until the client
1129 * terminates it by passing this DNSServiceRef to DNSServiceRefDeallocate().
1130 *
1131 * flags: Pass kDNSServiceFlagsLongLivedQuery to create a "long-lived" unicast
1132 * query in a non-local domain. Without setting this flag, unicast queries
1133 * will be one-shot - that is, only answers available at the time of the call
1134 * will be returned. By setting this flag, answers (including Add and Remove
1135 * events) that become available after the initial call is made will generate
1136 * callbacks. This flag has no effect on link-local multicast queries.
1137 *
1138 * interfaceIndex: If non-zero, specifies the interface on which to issue the query
1139 * (the index for a given interface is determined via the if_nametoindex()
1140 * family of calls.) Passing 0 causes the name to be queried for on all
1141 * interfaces. See "Constants for specifying an interface index" for more details.
1142 *
1143 * fullname: The full domain name of the resource record to be queried for.
1144 *
1145 * rrtype: The numerical type of the resource record to be queried for
1146 * (e.g. kDNSServiceType_PTR, kDNSServiceType_SRV, etc)
1147 *
1148 * rrclass: The class of the resource record (usually kDNSServiceClass_IN).
1149 *
1150 * callBack: The function to be called when a result is found, or if the call
1151 * asynchronously fails.
1152 *
1153 * context: An application context pointer which is passed to the callback function
1154 * (may be NULL).
1155 *
1156 * return value: Returns kDNSServiceErr_NoError on succeses (any subsequent, asynchronous
1157 * errors are delivered to the callback), otherwise returns an error code indicating
1158 * the error that occurred (the callback is never invoked and the DNSServiceRef
1159 * is not initialized.)
1160 */
1161
1162 DNSServiceErrorType DNSSD_API DNSServiceQueryRecord
1163 (
1164 DNSServiceRef *sdRef,
1165 DNSServiceFlags flags,
1166 uint32_t interfaceIndex,
1167 const char *fullname,
1168 uint16_t rrtype,
1169 uint16_t rrclass,
1170 DNSServiceQueryRecordReply callBack,
1171 void *context /* may be NULL */
1172 );
1173
1174
1175 /* DNSServiceReconfirmRecord
1176 *
1177 * Instruct the daemon to verify the validity of a resource record that appears to
1178 * be out of date (e.g. because tcp connection to a service's target failed.)
1179 * Causes the record to be flushed from the daemon's cache (as well as all other
1180 * daemons' caches on the network) if the record is determined to be invalid.
1181 *
1182 * Parameters:
1183 *
1184 * flags: Currently unused, reserved for future use.
1185 *
1186 * interfaceIndex: If non-zero, specifies the interface of the record in question.
1187 * Passing 0 causes all instances of this record to be reconfirmed.
1188 *
1189 * fullname: The resource record's full domain name.
1190 *
1191 * rrtype: The resource record's type (e.g. kDNSServiceType_PTR, kDNSServiceType_SRV, etc)
1192 *
1193 * rrclass: The class of the resource record (usually kDNSServiceClass_IN).
1194 *
1195 * rdlen: The length, in bytes, of the resource record rdata.
1196 *
1197 * rdata: The raw rdata of the resource record.
1198 *
1199 */
1200
1201 void DNSSD_API DNSServiceReconfirmRecord
1202 (
1203 DNSServiceFlags flags,
1204 uint32_t interfaceIndex,
1205 const char *fullname,
1206 uint16_t rrtype,
1207 uint16_t rrclass,
1208 uint16_t rdlen,
1209 const void *rdata
1210 );
1211
1212
1213 /*********************************************************************************************
1214 *
1215 * General Utility Functions
1216 *
1217 *********************************************************************************************/
1218
1219 /* DNSServiceConstructFullName()
1220 *
1221 * Concatenate a three-part domain name (as returned by the above callbacks) into a
1222 * properly-escaped full domain name. Note that callbacks in the above functions ALREADY ESCAPE
1223 * strings where necessary.
1224 *
1225 * Parameters:
1226 *
1227 * fullName: A pointer to a buffer that where the resulting full domain name is to be written.
1228 * The buffer must be kDNSServiceMaxDomainName (1005) bytes in length to
1229 * accommodate the longest legal domain name without buffer overrun.
1230 *
1231 * service: The service name - any dots or backslashes must NOT be escaped.
1232 * May be NULL (to construct a PTR record name, e.g.
1233 * "_ftp._tcp.apple.com.").
1234 *
1235 * regtype: The service type followed by the protocol, separated by a dot
1236 * (e.g. "_ftp._tcp").
1237 *
1238 * domain: The domain name, e.g. "apple.com.". Literal dots or backslashes,
1239 * if any, must be escaped, e.g. "1st\. Floor.apple.com."
1240 *
1241 * return value: Returns 0 on success, -1 on error.
1242 *
1243 */
1244
1245 int DNSSD_API DNSServiceConstructFullName
1246 (
1247 char *fullName,
1248 const char *service, /* may be NULL */
1249 const char *regtype,
1250 const char *domain
1251 );
1252
1253
1254 /*********************************************************************************************
1255 *
1256 * TXT Record Construction Functions
1257 *
1258 *********************************************************************************************/
1259
1260 /*
1261 * A typical calling sequence for TXT record construction is something like:
1262 *
1263 * Client allocates storage for TXTRecord data (e.g. declare buffer on the stack)
1264 * TXTRecordCreate();
1265 * TXTRecordSetValue();
1266 * TXTRecordSetValue();
1267 * TXTRecordSetValue();
1268 * ...
1269 * DNSServiceRegister( ... TXTRecordGetLength(), TXTRecordGetBytesPtr() ... );
1270 * TXTRecordDeallocate();
1271 * Explicitly deallocate storage for TXTRecord data (if not allocated on the stack)
1272 */
1273
1274
1275 /* TXTRecordRef
1276 *
1277 * Opaque internal data type.
1278 * Note: Represents a DNS-SD TXT record.
1279 */
1280
1281 typedef struct _TXTRecordRef_t { char privatedata[16]; } TXTRecordRef;
1282
1283
1284 /* TXTRecordCreate()
1285 *
1286 * Creates a new empty TXTRecordRef referencing the specified storage.
1287 *
1288 * If the buffer parameter is NULL, or the specified storage size is not
1289 * large enough to hold a key subsequently added using TXTRecordSetValue(),
1290 * then additional memory will be added as needed using malloc().
1291 *
1292 * On some platforms, when memory is low, malloc() may fail. In this
1293 * case, TXTRecordSetValue() will return kDNSServiceErr_NoMemory, and this
1294 * error condition will need to be handled as appropriate by the caller.
1295 *
1296 * You can avoid the need to handle this error condition if you ensure
1297 * that the storage you initially provide is large enough to hold all
1298 * the key/value pairs that are to be added to the record.
1299 * The caller can precompute the exact length required for all of the
1300 * key/value pairs to be added, or simply provide a fixed-sized buffer
1301 * known in advance to be large enough.
1302 * A no-value (key-only) key requires (1 + key length) bytes.
1303 * A key with empty value requires (1 + key length + 1) bytes.
1304 * A key with non-empty value requires (1 + key length + 1 + value length).
1305 * For most applications, DNS-SD TXT records are generally
1306 * less than 100 bytes, so in most cases a simple fixed-sized
1307 * 256-byte buffer will be more than sufficient.
1308 * Recommended size limits for DNS-SD TXT Records are discussed in
1309 * <http://files.dns-sd.org/draft-cheshire-dnsext-dns-sd.txt>
1310 *
1311 * Note: When passing parameters to and from these TXT record APIs,
1312 * the key name does not include the '=' character. The '=' character
1313 * is the separator between the key and value in the on-the-wire
1314 * packet format; it is not part of either the key or the value.
1315 *
1316 * txtRecord: A pointer to an uninitialized TXTRecordRef.
1317 *
1318 * bufferLen: The size of the storage provided in the "buffer" parameter.
1319 *
1320 * buffer: The storage used to hold the TXTRecord data.
1321 * This storage must remain valid for as long as
1322 * the TXTRecordRef.
1323 */
1324
1325 void DNSSD_API TXTRecordCreate
1326 (
1327 TXTRecordRef *txtRecord,
1328 uint16_t bufferLen,
1329 void *buffer
1330 );
1331
1332
1333 /* TXTRecordDeallocate()
1334 *
1335 * Releases any resources allocated in the course of preparing a TXT Record
1336 * using TXTRecordCreate()/TXTRecordSetValue()/TXTRecordRemoveValue().
1337 * Ownership of the buffer provided in TXTRecordCreate() returns to the client.
1338 *
1339 * txtRecord: A TXTRecordRef initialized by calling TXTRecordCreate().
1340 *
1341 */
1342
1343 void DNSSD_API TXTRecordDeallocate
1344 (
1345 TXTRecordRef *txtRecord
1346 );
1347
1348
1349 /* TXTRecordSetValue()
1350 *
1351 * Adds a key (optionally with value) to a TXTRecordRef. If the "key" already
1352 * exists in the TXTRecordRef, then the current value will be replaced with
1353 * the new value.
1354 * Keys may exist in four states with respect to a given TXT record:
1355 * - Absent (key does not appear at all)
1356 * - Present with no value ("key" appears alone)
1357 * - Present with empty value ("key=" appears in TXT record)
1358 * - Present with non-empty value ("key=value" appears in TXT record)
1359 * For more details refer to "Data Syntax for DNS-SD TXT Records" in
1360 * <http://files.dns-sd.org/draft-cheshire-dnsext-dns-sd.txt>
1361 *
1362 * txtRecord: A TXTRecordRef initialized by calling TXTRecordCreate().
1363 *
1364 * key: A null-terminated string which only contains printable ASCII
1365 * values (0x20-0x7E), excluding '=' (0x3D). Keys should be
1366 * 8 characters or less (not counting the terminating null).
1367 *
1368 * valueSize: The size of the value.
1369 *
1370 * value: Any binary value. For values that represent
1371 * textual data, UTF-8 is STRONGLY recommended.
1372 * For values that represent textual data, valueSize
1373 * should NOT include the terminating null (if any)
1374 * at the end of the string.
1375 * If NULL, then "key" will be added with no value.
1376 * If non-NULL but valueSize is zero, then "key=" will be
1377 * added with empty value.
1378 *
1379 * return value: Returns kDNSServiceErr_NoError on success.
1380 * Returns kDNSServiceErr_Invalid if the "key" string contains
1381 * illegal characters.
1382 * Returns kDNSServiceErr_NoMemory if adding this key would
1383 * exceed the available storage.
1384 */
1385
1386 DNSServiceErrorType DNSSD_API TXTRecordSetValue
1387 (
1388 TXTRecordRef *txtRecord,
1389 const char *key,
1390 uint8_t valueSize, /* may be zero */
1391 const void *value /* may be NULL */
1392 );
1393
1394
1395 /* TXTRecordRemoveValue()
1396 *
1397 * Removes a key from a TXTRecordRef. The "key" must be an
1398 * ASCII string which exists in the TXTRecordRef.
1399 *
1400 * txtRecord: A TXTRecordRef initialized by calling TXTRecordCreate().
1401 *
1402 * key: A key name which exists in the TXTRecordRef.
1403 *
1404 * return value: Returns kDNSServiceErr_NoError on success.
1405 * Returns kDNSServiceErr_NoSuchKey if the "key" does not
1406 * exist in the TXTRecordRef.
1407 *
1408 */
1409
1410 DNSServiceErrorType DNSSD_API TXTRecordRemoveValue
1411 (
1412 TXTRecordRef *txtRecord,
1413 const char *key
1414 );
1415
1416
1417 /* TXTRecordGetLength()
1418 *
1419 * Allows you to determine the length of the raw bytes within a TXTRecordRef.
1420 *
1421 * txtRecord: A TXTRecordRef initialized by calling TXTRecordCreate().
1422 *
1423 * return value: Returns the size of the raw bytes inside a TXTRecordRef
1424 * which you can pass directly to DNSServiceRegister() or
1425 * to DNSServiceUpdateRecord().
1426 * Returns 0 if the TXTRecordRef is empty.
1427 *
1428 */
1429
1430 uint16_t DNSSD_API TXTRecordGetLength
1431 (
1432 const TXTRecordRef *txtRecord
1433 );
1434
1435
1436 /* TXTRecordGetBytesPtr()
1437 *
1438 * Allows you to retrieve a pointer to the raw bytes within a TXTRecordRef.
1439 *
1440 * txtRecord: A TXTRecordRef initialized by calling TXTRecordCreate().
1441 *
1442 * return value: Returns a pointer to the raw bytes inside the TXTRecordRef
1443 * which you can pass directly to DNSServiceRegister() or
1444 * to DNSServiceUpdateRecord().
1445 *
1446 */
1447
1448 const void * DNSSD_API TXTRecordGetBytesPtr
1449 (
1450 const TXTRecordRef *txtRecord
1451 );
1452
1453
1454 /*********************************************************************************************
1455 *
1456 * TXT Record Parsing Functions
1457 *
1458 *********************************************************************************************/
1459
1460 /*
1461 * A typical calling sequence for TXT record parsing is something like:
1462 *
1463 * Receive TXT record data in DNSServiceResolve() callback
1464 * if (TXTRecordContainsKey(txtLen, txtRecord, "key")) then do something
1465 * val1ptr = TXTRecordGetValuePtr(txtLen, txtRecord, "key1", &len1);
1466 * val2ptr = TXTRecordGetValuePtr(txtLen, txtRecord, "key2", &len2);
1467 * ...
1468 * bcopy(val1ptr, myval1, len1);
1469 * bcopy(val2ptr, myval2, len2);
1470 * ...
1471 * return;
1472 *
1473 * If you wish to retain the values after return from the DNSServiceResolve()
1474 * callback, then you need to copy the data to your own storage using bcopy()
1475 * or similar, as shown in the example above.
1476 *
1477 * If for some reason you need to parse a TXT record you built yourself
1478 * using the TXT record construction functions above, then you can do
1479 * that using TXTRecordGetLength and TXTRecordGetBytesPtr calls:
1480 * TXTRecordGetValue(TXTRecordGetLength(x), TXTRecordGetBytesPtr(x), key, &len);
1481 *
1482 * Most applications only fetch keys they know about from a TXT record and
1483 * ignore the rest.
1484 * However, some debugging tools wish to fetch and display all keys.
1485 * To do that, use the TXTRecordGetCount() and TXTRecordGetItemAtIndex() calls.
1486 */
1487
1488 /* TXTRecordContainsKey()
1489 *
1490 * Allows you to determine if a given TXT Record contains a specified key.
1491 *
1492 * txtLen: The size of the received TXT Record.
1493 *
1494 * txtRecord: Pointer to the received TXT Record bytes.
1495 *
1496 * key: A null-terminated ASCII string containing the key name.
1497 *
1498 * return value: Returns 1 if the TXT Record contains the specified key.
1499 * Otherwise, it returns 0.
1500 *
1501 */
1502
1503 int DNSSD_API TXTRecordContainsKey
1504 (
1505 uint16_t txtLen,
1506 const void *txtRecord,
1507 const char *key
1508 );
1509
1510
1511 /* TXTRecordGetValuePtr()
1512 *
1513 * Allows you to retrieve the value for a given key from a TXT Record.
1514 *
1515 * txtLen: The size of the received TXT Record
1516 *
1517 * txtRecord: Pointer to the received TXT Record bytes.
1518 *
1519 * key: A null-terminated ASCII string containing the key name.
1520 *
1521 * valueLen: On output, will be set to the size of the "value" data.
1522 *
1523 * return value: Returns NULL if the key does not exist in this TXT record,
1524 * or exists with no value (to differentiate between
1525 * these two cases use TXTRecordContainsKey()).
1526 * Returns pointer to location within TXT Record bytes
1527 * if the key exists with empty or non-empty value.
1528 * For empty value, valueLen will be zero.
1529 * For non-empty value, valueLen will be length of value data.
1530 */
1531
1532 const void * DNSSD_API TXTRecordGetValuePtr
1533 (
1534 uint16_t txtLen,
1535 const void *txtRecord,
1536 const char *key,
1537 uint8_t *valueLen
1538 );
1539
1540
1541 /* TXTRecordGetCount()
1542 *
1543 * Returns the number of keys stored in the TXT Record. The count
1544 * can be used with TXTRecordGetItemAtIndex() to iterate through the keys.
1545 *
1546 * txtLen: The size of the received TXT Record.
1547 *
1548 * txtRecord: Pointer to the received TXT Record bytes.
1549 *
1550 * return value: Returns the total number of keys in the TXT Record.
1551 *
1552 */
1553
1554 uint16_t DNSSD_API TXTRecordGetCount
1555 (
1556 uint16_t txtLen,
1557 const void *txtRecord
1558 );
1559
1560
1561 /* TXTRecordGetItemAtIndex()
1562 *
1563 * Allows you to retrieve a key name and value pointer, given an index into
1564 * a TXT Record. Legal index values range from zero to TXTRecordGetCount()-1.
1565 * It's also possible to iterate through keys in a TXT record by simply
1566 * calling TXTRecordGetItemAtIndex() repeatedly, beginning with index zero
1567 * and increasing until TXTRecordGetItemAtIndex() returns kDNSServiceErr_Invalid.
1568 *
1569 * On return:
1570 * For keys with no value, *value is set to NULL and *valueLen is zero.
1571 * For keys with empty value, *value is non-NULL and *valueLen is zero.
1572 * For keys with non-empty value, *value is non-NULL and *valueLen is non-zero.
1573 *
1574 * txtLen: The size of the received TXT Record.
1575 *
1576 * txtRecord: Pointer to the received TXT Record bytes.
1577 *
1578 * index: An index into the TXT Record.
1579 *
1580 * keyBufLen: The size of the string buffer being supplied.
1581 *
1582 * key: A string buffer used to store the key name.
1583 * On return, the buffer contains a null-terminated C string
1584 * giving the key name. DNS-SD TXT keys are usually
1585 * 8 characters or less. To hold the maximum possible
1586 * key name, the buffer should be 256 bytes long.
1587 *
1588 * valueLen: On output, will be set to the size of the "value" data.
1589 *
1590 * value: On output, *value is set to point to location within TXT
1591 * Record bytes that holds the value data.
1592 *
1593 * return value: Returns kDNSServiceErr_NoError on success.
1594 * Returns kDNSServiceErr_NoMemory if keyBufLen is too short.
1595 * Returns kDNSServiceErr_Invalid if index is greater than
1596 * TXTRecordGetCount()-1.
1597 */
1598
1599 DNSServiceErrorType DNSSD_API TXTRecordGetItemAtIndex
1600 (
1601 uint16_t txtLen,
1602 const void *txtRecord,
1603 uint16_t index,
1604 uint16_t keyBufLen,
1605 char *key,
1606 uint8_t *valueLen,
1607 const void **value
1608 );
1609
1610 #ifdef __APPLE_API_PRIVATE
1611
1612 /*
1613 * Mac OS X specific functionality
1614 * 3rd party clients of this API should not depend on future support or availability of this routine
1615 */
1616
1617 /* DNSServiceSetDefaultDomainForUser()
1618 *
1619 * Set the default domain for the caller's UID. Future browse and registration
1620 * calls by this user that do not specify an explicit domain will browse and
1621 * register in this wide-area domain in addition to .local. In addition, this
1622 * domain will be returned as a Browse domain via domain enumeration calls.
1623 *
1624 *
1625 * Parameters:
1626 *
1627 * flags: Pass kDNSServiceFlagsAdd to add a domain for a user. Call without
1628 * this flag set to clear a previously added domain.
1629 *
1630 * domain: The domain to be used for the caller's UID.
1631 *
1632 * return value: Returns kDNSServiceErr_NoError on succeses, otherwise returns
1633 * an error code indicating the error that occurred
1634 */
1635
1636 DNSServiceErrorType DNSSD_API DNSServiceSetDefaultDomainForUser
1637 (
1638 DNSServiceFlags flags,
1639 const char *domain
1640 );
1641
1642 #endif //__APPLE_API_PRIVATE
1643
1644 #ifdef __cplusplus
1645 }
1646 #endif
1647
1648 #endif /* _DNS_SD_H */