2 * Copyright (c) 2003-2004, Apple Computer, Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are met:
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.
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.
35 /* standard calling convention under Win32 is __stdcall */
37 #define DNSSD_API __stdcall
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>
50 #define bzero(a, b) memset(a, 0, b)
51 typedef UINT8
uint8_t;
53 typedef UINT16
uint16_t;
54 typedef INT16
int16_t;
55 typedef UINT32
uint32_t;
56 typedef INT32
int32_t;
61 /* DNSServiceRef, DNSRecordRef
63 * Opaque internal data types.
64 * Note: client is responsible for serializing access to these structures if
65 * they are shared between concurrent threads.
68 typedef struct _DNSServiceRef_t
*DNSServiceRef
;
69 typedef struct _DNSRecordRef_t
*DNSRecordRef
;
71 /* General flags used in functions defined below */
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.
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
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.)
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).
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.
121 kDNSServiceFlagsLongLivedQuery
= 0x100,
122 /* Flag for creating a long-lived unicast query for the DNSServiceQueryRecord call. */
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).
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.
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.
148 kDNSServiceClass_IN
= 1 /* Internet */
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. */
204 /* possible error code values */
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) */
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 */
238 #define kDNSServiceMaxDomainName 1005
241 * Notes on DNS Name Escaping
243 * "Why is kDNSServiceMaxDomainName 1005, when the maximum legal domain name is 255 bytes?"
245 * All strings used in DNS-SD are UTF-8 strings.
246 * With few exceptions, most are also escaped using standard DNS escaping rules:
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.
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.
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.
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.
283 * Constants for specifying an interface index
285 * Specific interface indexes are identified via a 32-bit unsigned integer returned
286 * by the if_nametoindex() family of calls.
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.
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.
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.
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.
316 #define kDNSServiceInterfaceIndexAny 0
317 #define kDNSServiceInterfaceIndexLocalOnly ( (uint32_t) -1 )
320 typedef uint32_t DNSServiceFlags
;
321 typedef int32_t DNSServiceErrorType
;
324 /*********************************************************************************************
326 * Unix Domain Socket access, DNSServiceRef deallocation, and data processing functions
328 *********************************************************************************************/
331 /* DNSServiceRefSockFD()
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
346 * sdRef: A DNSServiceRef initialized by any of the DNSService calls.
348 * return value: The DNSServiceRef's underlying socket descriptor, or -1 on
352 int DNSSD_API
DNSServiceRefSockFD(DNSServiceRef sdRef
);
355 /* DNSServiceProcessResult()
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.
366 * sdRef: A DNSServiceRef initialized by any of the DNSService calls
367 * that take a callback parameter.
369 * return value: Returns kDNSServiceErr_NoError on success, otherwise returns
370 * an error code indicating the specific failure that occurred.
373 DNSServiceErrorType DNSSD_API
DNSServiceProcessResult(DNSServiceRef sdRef
);
376 /* DNSServiceRefDeallocate()
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.
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
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
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.
398 * sdRef: A DNSServiceRef initialized by any of the DNSService calls.
402 void DNSSD_API
DNSServiceRefDeallocate(DNSServiceRef sdRef
);
405 /*********************************************************************************************
409 *********************************************************************************************/
411 /* DNSServiceEnumerateDomains()
413 * Asynchronously enumerate domains available for browsing and registration.
415 * The enumeration MUST be cancelled via DNSServiceRefDeallocate() when no more domains
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.
425 * DNSServiceDomainEnumReply Callback Parameters:
427 * sdRef: The DNSServiceRef initialized by DNSServiceEnumerateDomains().
429 * flags: Possible values are:
430 * kDNSServiceFlagsMoreComing
431 * kDNSServiceFlagsAdd
432 * kDNSServiceFlagsDefault
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.)
437 * errorCode: Will be kDNSServiceErr_NoError (0) on success, otherwise indicates
438 * the failure that occurred (other parameters are undefined if errorCode is nonzero).
440 * replyDomain: The name of the domain.
442 * context: The context pointer passed to DNSServiceEnumerateDomains.
446 typedef void (DNSSD_API
*DNSServiceDomainEnumReply
)
449 DNSServiceFlags flags
,
450 uint32_t interfaceIndex
,
451 DNSServiceErrorType errorCode
,
452 const char *replyDomain
,
457 /* DNSServiceEnumerateDomains() Parameters:
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().
465 * flags: Possible values are:
466 * kDNSServiceFlagsBrowseDomains to enumerate domains recommended for browsing.
467 * kDNSServiceFlagsRegistrationDomains to enumerate domains recommended
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.
475 * callBack: The function to be called when a domain is found or the call asynchronously
478 * context: An application context pointer which is passed to the callback function
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.)
487 DNSServiceErrorType DNSSD_API DNSServiceEnumerateDomains
489 DNSServiceRef
*sdRef
,
490 DNSServiceFlags flags
,
491 uint32_t interfaceIndex
,
492 DNSServiceDomainEnumReply callBack
,
493 void *context
/* may be NULL */
497 /*********************************************************************************************
499 * Service Registration
501 *********************************************************************************************/
503 /* Register a service that is discovered via Browse() and Resolve() calls.
506 * DNSServiceRegisterReply() Callback Parameters:
508 * sdRef: The DNSServiceRef initialized by DNSServiceRegister().
510 * flags: Currently unused, reserved for future use.
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.
517 * name: The service name registered (if the application did not specify a name in
518 * DNSServiceRegister(), this indicates what name was automatically chosen).
520 * regtype: The type of service registered, as it was passed to the callout.
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).
526 * context: The context pointer that was passed to the callout.
530 typedef void (DNSSD_API
*DNSServiceRegisterReply
)
533 DNSServiceFlags flags
,
534 DNSServiceErrorType errorCode
,
542 /* DNSServiceRegister() Parameters:
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().
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.
554 * flags: Indicates the renaming behavior on name conflict (most applications
555 * will pass 0). See flag definitions above for details.
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
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.
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).
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().
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.
582 * txtLen: The length of the txtRecord, in bytes. Must be zero if the txtRecord is NULL.
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> ...
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().
595 * context: An application context pointer which is passed to the callback function
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.)
605 DNSServiceErrorType DNSSD_API DNSServiceRegister
607 DNSServiceRef
*sdRef
,
608 DNSServiceFlags flags
,
609 uint32_t interfaceIndex
,
610 const char *name
, /* may be NULL */
612 const char *domain
, /* may be NULL */
613 const char *host
, /* may be NULL */
616 const void *txtRecord
, /* may be NULL */
617 DNSServiceRegisterReply callBack
, /* may be NULL */
618 void *context
/* may be NULL */
622 /* DNSServiceAddRecord()
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().
632 * sdRef: A DNSServiceRef initialized by DNSServiceRegister().
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.
639 * flags: Currently ignored, reserved for future use.
641 * rrtype: The type of the record (e.g. kDNSServiceType_TXT, kDNSServiceType_SRV, etc)
643 * rdlen: The length, in bytes, of the rdata.
645 * rdata: The raw rdata to be contained in the added resource record.
647 * ttl: The time to live of the resource record, in seconds. Pass 0 to use a default value.
649 * return value: Returns kDNSServiceErr_NoError on success, otherwise returns an
650 * error code indicating the error that occurred (the RecordRef is not initialized).
653 DNSServiceErrorType DNSSD_API DNSServiceAddRecord
656 DNSRecordRef
*RecordRef
,
657 DNSServiceFlags flags
,
665 /* DNSServiceUpdateRecord
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()
675 * sdRef: A DNSServiceRef that was initialized by DNSServiceRegister()
676 * or DNSServiceCreateConnection().
678 * RecordRef: A DNSRecordRef initialized by DNSServiceAddRecord, or NULL to update the
679 * service's primary txt record.
681 * flags: Currently ignored, reserved for future use.
683 * rdlen: The length, in bytes, of the new rdata.
685 * rdata: The new rdata to be contained in the updated resource record.
687 * ttl: The time to live of the updated resource record, in seconds.
689 * return value: Returns kDNSServiceErr_NoError on success, otherwise returns an
690 * error code indicating the error that occurred.
693 DNSServiceErrorType DNSSD_API DNSServiceUpdateRecord
696 DNSRecordRef RecordRef
, /* may be NULL */
697 DNSServiceFlags flags
,
704 /* DNSServiceRemoveRecord
706 * Remove a record previously added to a service record set via DNSServiceAddRecord(), or deregister
707 * an record registered individually via DNSServiceRegisterRecord().
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()).
716 * recordRef: A DNSRecordRef initialized by a successful call to DNSServiceAddRecord()
717 * or DNSServiceRegisterRecord().
719 * flags: Currently ignored, reserved for future use.
721 * return value: Returns kDNSServiceErr_NoError on success, otherwise returns an
722 * error code indicating the error that occurred.
725 DNSServiceErrorType DNSSD_API DNSServiceRemoveRecord
728 DNSRecordRef RecordRef
,
729 DNSServiceFlags flags
733 /*********************************************************************************************
737 *********************************************************************************************/
739 /* Browse for instances of a service.
742 * DNSServiceBrowseReply() Parameters:
744 * sdRef: The DNSServiceRef initialized by DNSServiceBrowse().
746 * flags: Possible values are kDNSServiceFlagsMoreComing and kDNSServiceFlagsAdd.
747 * See flag definitions for details.
749 * interfaceIndex: The interface on which the service is advertised. This index should
750 * be passed to DNSServiceResolve() when resolving the service.
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.
756 * serviceName: The discovered service name. This name should be displayed to the user,
757 * and stored for subsequent use in the DNSServiceResolve() call.
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.
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.
774 * context: The context pointer that was passed to the callout.
778 typedef void (DNSSD_API
*DNSServiceBrowseReply
)
781 DNSServiceFlags flags
,
782 uint32_t interfaceIndex
,
783 DNSServiceErrorType errorCode
,
784 const char *serviceName
,
786 const char *replyDomain
,
791 /* DNSServiceBrowse() Parameters:
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().
798 * flags: Currently ignored, reserved for future use.
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.
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".
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
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.
815 * context: An application context pointer which is passed to the callback function
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.)
824 DNSServiceErrorType DNSSD_API DNSServiceBrowse
826 DNSServiceRef
*sdRef
,
827 DNSServiceFlags flags
,
828 uint32_t interfaceIndex
,
830 const char *domain
, /* may be NULL */
831 DNSServiceBrowseReply callBack
,
832 void *context
/* may be NULL */
836 /* DNSServiceResolve()
838 * Resolve a service name discovered via DNSServiceBrowse() to a target host name, port number, and
841 * Note: Applications should NOT use DNSServiceResolve() solely for txt record monitoring - use
842 * DNSServiceQueryRecord() instead, as it is more efficient for this task.
844 * Note: When the desired results have been returned, the client MUST terminate the resolve by calling
845 * DNSServiceRefDeallocate().
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.
851 * DNSServiceResolveReply Callback Parameters:
853 * sdRef: The DNSServiceRef initialized by DNSServiceResolve().
855 * flags: Currently unused, reserved for future use.
857 * interfaceIndex: The interface on which the service was resolved.
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.
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.)
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.
872 * port: The port, in network byte order, on which connections are accepted for this service.
874 * txtLen: The length of the txt record, in bytes.
876 * txtRecord: The service's primary txt record, in standard txt record format.
879 * context: The context pointer that was passed to the callout.
883 typedef void (DNSSD_API
*DNSServiceResolveReply
)
886 DNSServiceFlags flags
,
887 uint32_t interfaceIndex
,
888 DNSServiceErrorType errorCode
,
889 const char *fullname
,
890 const char *hosttarget
,
893 const char *txtRecord
,
898 /* DNSServiceResolve() Parameters
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().
905 * flags: Currently ignored, reserved for future use.
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.
915 * name: The name of the service instance to be resolved, as reported to the
916 * DNSServiceBrowseReply() callback.
918 * regtype: The type of the service instance to be resolved, as reported to the
919 * DNSServiceBrowseReply() callback.
921 * domain: The domain of the service instance to be resolved, as reported to the
922 * DNSServiceBrowseReply() callback.
924 * callBack: The function to be called when a result is found, or if the call
925 * asynchronously fails.
927 * context: An application context pointer which is passed to the callback function
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.)
936 DNSServiceErrorType DNSSD_API DNSServiceResolve
938 DNSServiceRef
*sdRef
,
939 DNSServiceFlags flags
,
940 uint32_t interfaceIndex
,
944 DNSServiceResolveReply callBack
,
945 void *context
/* may be NULL */
949 /*********************************************************************************************
951 * Special Purpose Calls (most applications will not use these)
953 *********************************************************************************************/
955 /* DNSServiceCreateConnection()
957 * Create a connection to the daemon allowing efficient registration of
958 * multiple individual records.
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.
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).
972 DNSServiceErrorType DNSSD_API
DNSServiceCreateConnection(DNSServiceRef
*sdRef
);
975 /* DNSServiceRegisterRecord
977 * Register an individual resource record on a connected DNSServiceRef.
979 * Note that name conflicts occurring for records registered via this call must be handled
980 * by the client in the callback.
983 * DNSServiceRegisterRecordReply() parameters:
985 * sdRef: The connected DNSServiceRef initialized by
986 * DNSServiceDiscoveryConnect().
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.
992 * flags: Currently unused, reserved for future use.
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.
998 * context: The context pointer that was passed to the callout.
1002 typedef void (DNSSD_API
*DNSServiceRegisterRecordReply
)
1004 DNSServiceRef sdRef
,
1005 DNSRecordRef RecordRef
,
1006 DNSServiceFlags flags
,
1007 DNSServiceErrorType errorCode
,
1012 /* DNSServiceRegisterRecord() Parameters:
1014 * sdRef: A DNSServiceRef initialized by DNSServiceCreateConnection().
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()).
1022 * flags: Possible values are kDNSServiceFlagsShared or kDNSServiceFlagsUnique
1023 * (see flag type definitions for details).
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.
1030 * fullname: The full domain name of the resource record.
1032 * rrtype: The numerical type of the resource record (e.g. kDNSServiceType_PTR, kDNSServiceType_SRV, etc)
1034 * rrclass: The class of the resource record (usually kDNSServiceClass_IN)
1036 * rdlen: Length, in bytes, of the rdata.
1038 * rdata: A pointer to the raw rdata, as it is to appear in the DNS record.
1040 * ttl: The time to live of the resource record, in seconds. Pass 0 to use a default value.
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.)
1045 * context: An application context pointer which is passed to the callback function
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
1054 DNSServiceErrorType DNSSD_API DNSServiceRegisterRecord
1056 DNSServiceRef sdRef
,
1057 DNSRecordRef
*RecordRef
,
1058 DNSServiceFlags flags
,
1059 uint32_t interfaceIndex
,
1060 const char *fullname
,
1066 DNSServiceRegisterRecordReply callBack
,
1067 void *context
/* may be NULL */
1071 /* DNSServiceQueryRecord
1073 * Query for an arbitrary DNS record.
1076 * DNSServiceQueryRecordReply() Callback Parameters:
1078 * sdRef: The DNSServiceRef initialized by DNSServiceQueryRecord().
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.
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.
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.
1092 * fullname: The resource record's full domain name.
1094 * rrtype: The resource record's type (e.g. kDNSServiceType_PTR, kDNSServiceType_SRV, etc)
1096 * rrclass: The class of the resource record (usually kDNSServiceClass_IN).
1098 * rdlen: The length, in bytes, of the resource record rdata.
1100 * rdata: The raw rdata of the resource record.
1102 * ttl: The resource record's time to live, in seconds.
1104 * context: The context pointer that was passed to the callout.
1108 typedef void (DNSSD_API
*DNSServiceQueryRecordReply
)
1110 DNSServiceRef DNSServiceRef
,
1111 DNSServiceFlags flags
,
1112 uint32_t interfaceIndex
,
1113 DNSServiceErrorType errorCode
,
1114 const char *fullname
,
1124 /* DNSServiceQueryRecord() Parameters:
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().
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.
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.
1143 * fullname: The full domain name of the resource record to be queried for.
1145 * rrtype: The numerical type of the resource record to be queried for
1146 * (e.g. kDNSServiceType_PTR, kDNSServiceType_SRV, etc)
1148 * rrclass: The class of the resource record (usually kDNSServiceClass_IN).
1150 * callBack: The function to be called when a result is found, or if the call
1151 * asynchronously fails.
1153 * context: An application context pointer which is passed to the callback function
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.)
1162 DNSServiceErrorType DNSSD_API DNSServiceQueryRecord
1164 DNSServiceRef
*sdRef
,
1165 DNSServiceFlags flags
,
1166 uint32_t interfaceIndex
,
1167 const char *fullname
,
1170 DNSServiceQueryRecordReply callBack
,
1171 void *context
/* may be NULL */
1175 /* DNSServiceReconfirmRecord
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.
1184 * flags: Currently unused, reserved for future use.
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.
1189 * fullname: The resource record's full domain name.
1191 * rrtype: The resource record's type (e.g. kDNSServiceType_PTR, kDNSServiceType_SRV, etc)
1193 * rrclass: The class of the resource record (usually kDNSServiceClass_IN).
1195 * rdlen: The length, in bytes, of the resource record rdata.
1197 * rdata: The raw rdata of the resource record.
1201 void DNSSD_API DNSServiceReconfirmRecord
1203 DNSServiceFlags flags
,
1204 uint32_t interfaceIndex
,
1205 const char *fullname
,
1213 /*********************************************************************************************
1215 * General Utility Functions
1217 *********************************************************************************************/
1219 /* DNSServiceConstructFullName()
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.
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.
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.").
1235 * regtype: The service type followed by the protocol, separated by a dot
1236 * (e.g. "_ftp._tcp").
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."
1241 * return value: Returns 0 on success, -1 on error.
1245 int DNSSD_API DNSServiceConstructFullName
1248 const char *service
, /* may be NULL */
1249 const char *regtype
,
1254 /*********************************************************************************************
1256 * TXT Record Construction Functions
1258 *********************************************************************************************/
1261 * A typical calling sequence for TXT record construction is something like:
1263 * Client allocates storage for TXTRecord data (e.g. declare buffer on the stack)
1264 * TXTRecordCreate();
1265 * TXTRecordSetValue();
1266 * TXTRecordSetValue();
1267 * TXTRecordSetValue();
1269 * DNSServiceRegister( ... TXTRecordGetLength(), TXTRecordGetBytesPtr() ... );
1270 * TXTRecordDeallocate();
1271 * Explicitly deallocate storage for TXTRecord data (if not allocated on the stack)
1277 * Opaque internal data type.
1278 * Note: Represents a DNS-SD TXT record.
1281 typedef struct _TXTRecordRef_t
{ char privatedata
[16]; } TXTRecordRef
;
1284 /* TXTRecordCreate()
1286 * Creates a new empty TXTRecordRef referencing the specified storage.
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().
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.
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>
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.
1316 * txtRecord: A pointer to an uninitialized TXTRecordRef.
1318 * bufferLen: The size of the storage provided in the "buffer" parameter.
1320 * buffer: The storage used to hold the TXTRecord data.
1321 * This storage must remain valid for as long as
1325 void DNSSD_API TXTRecordCreate
1327 TXTRecordRef
*txtRecord
,
1333 /* TXTRecordDeallocate()
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.
1339 * txtRecord: A TXTRecordRef initialized by calling TXTRecordCreate().
1343 void DNSSD_API TXTRecordDeallocate
1345 TXTRecordRef
*txtRecord
1349 /* TXTRecordSetValue()
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
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>
1362 * txtRecord: A TXTRecordRef initialized by calling TXTRecordCreate().
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).
1368 * valueSize: The size of the value.
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.
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.
1386 DNSServiceErrorType DNSSD_API TXTRecordSetValue
1388 TXTRecordRef
*txtRecord
,
1390 uint8_t valueSize
, /* may be zero */
1391 const void *value
/* may be NULL */
1395 /* TXTRecordRemoveValue()
1397 * Removes a key from a TXTRecordRef. The "key" must be an
1398 * ASCII string which exists in the TXTRecordRef.
1400 * txtRecord: A TXTRecordRef initialized by calling TXTRecordCreate().
1402 * key: A key name which exists in the TXTRecordRef.
1404 * return value: Returns kDNSServiceErr_NoError on success.
1405 * Returns kDNSServiceErr_NoSuchKey if the "key" does not
1406 * exist in the TXTRecordRef.
1410 DNSServiceErrorType DNSSD_API TXTRecordRemoveValue
1412 TXTRecordRef
*txtRecord
,
1417 /* TXTRecordGetLength()
1419 * Allows you to determine the length of the raw bytes within a TXTRecordRef.
1421 * txtRecord: A TXTRecordRef initialized by calling TXTRecordCreate().
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.
1430 uint16_t DNSSD_API TXTRecordGetLength
1432 const TXTRecordRef
*txtRecord
1436 /* TXTRecordGetBytesPtr()
1438 * Allows you to retrieve a pointer to the raw bytes within a TXTRecordRef.
1440 * txtRecord: A TXTRecordRef initialized by calling TXTRecordCreate().
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().
1448 const void * DNSSD_API TXTRecordGetBytesPtr
1450 const TXTRecordRef
*txtRecord
1454 /*********************************************************************************************
1456 * TXT Record Parsing Functions
1458 *********************************************************************************************/
1461 * A typical calling sequence for TXT record parsing is something like:
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);
1468 * bcopy(val1ptr, myval1, len1);
1469 * bcopy(val2ptr, myval2, len2);
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.
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);
1482 * Most applications only fetch keys they know about from a TXT record and
1484 * However, some debugging tools wish to fetch and display all keys.
1485 * To do that, use the TXTRecordGetCount() and TXTRecordGetItemAtIndex() calls.
1488 /* TXTRecordContainsKey()
1490 * Allows you to determine if a given TXT Record contains a specified key.
1492 * txtLen: The size of the received TXT Record.
1494 * txtRecord: Pointer to the received TXT Record bytes.
1496 * key: A null-terminated ASCII string containing the key name.
1498 * return value: Returns 1 if the TXT Record contains the specified key.
1499 * Otherwise, it returns 0.
1503 int DNSSD_API TXTRecordContainsKey
1506 const void *txtRecord
,
1511 /* TXTRecordGetValuePtr()
1513 * Allows you to retrieve the value for a given key from a TXT Record.
1515 * txtLen: The size of the received TXT Record
1517 * txtRecord: Pointer to the received TXT Record bytes.
1519 * key: A null-terminated ASCII string containing the key name.
1521 * valueLen: On output, will be set to the size of the "value" data.
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.
1532 const void * DNSSD_API TXTRecordGetValuePtr
1535 const void *txtRecord
,
1541 /* TXTRecordGetCount()
1543 * Returns the number of keys stored in the TXT Record. The count
1544 * can be used with TXTRecordGetItemAtIndex() to iterate through the keys.
1546 * txtLen: The size of the received TXT Record.
1548 * txtRecord: Pointer to the received TXT Record bytes.
1550 * return value: Returns the total number of keys in the TXT Record.
1554 uint16_t DNSSD_API TXTRecordGetCount
1557 const void *txtRecord
1561 /* TXTRecordGetItemAtIndex()
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.
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.
1574 * txtLen: The size of the received TXT Record.
1576 * txtRecord: Pointer to the received TXT Record bytes.
1578 * index: An index into the TXT Record.
1580 * keyBufLen: The size of the string buffer being supplied.
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.
1588 * valueLen: On output, will be set to the size of the "value" data.
1590 * value: On output, *value is set to point to location within TXT
1591 * Record bytes that holds the value data.
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.
1599 DNSServiceErrorType DNSSD_API TXTRecordGetItemAtIndex
1602 const void *txtRecord
,
1610 #ifdef __APPLE_API_PRIVATE
1613 * Mac OS X specific functionality
1614 * 3rd party clients of this API should not depend on future support or availability of this routine
1617 /* DNSServiceSetDefaultDomainForUser()
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.
1627 * flags: Pass kDNSServiceFlagsAdd to add a domain for a user. Call without
1628 * this flag set to clear a previously added domain.
1630 * domain: The domain to be used for the caller's UID.
1632 * return value: Returns kDNSServiceErr_NoError on succeses, otherwise returns
1633 * an error code indicating the error that occurred
1636 DNSServiceErrorType DNSSD_API DNSServiceSetDefaultDomainForUser
1638 DNSServiceFlags flags
,
1642 #endif //__APPLE_API_PRIVATE
1648 #endif /* _DNS_SD_H */