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)
52 typedef UINT8
uint8_t;
54 typedef UINT16
uint16_t;
55 typedef INT16
int16_t;
56 typedef UINT32
uint32_t;
57 typedef INT32
int32_t;
63 /* DNSServiceRef, DNSRecordRef
65 * Opaque internal data types.
66 * Note: client is responsible for serializing access to these structures if
67 * they are shared between concurrent threads.
70 typedef struct _DNSServiceRef_t
*DNSServiceRef
;
71 typedef struct _DNSRecordRef_t
*DNSRecordRef
;
73 /* General flags used in functions defined below */
76 kDNSServiceFlagsMoreComing
= 0x1,
77 /* MoreComing indicates to a callback that at least one more result is
78 * queued and will be delivered following immediately after this one.
79 * Applications should not update their UI to display browse
80 * results when the MoreComing flag is set, because this would
81 * result in a great deal of ugly flickering on the screen.
82 * Applications should instead wait until until MoreComing is not set,
83 * and then update their UI.
84 * When MoreComing is not set, that doesn't mean there will be no more
85 * answers EVER, just that there are no more answers immediately
86 * available right now at this instant. If more answers become available
87 * in the future they will be delivered as usual.
90 kDNSServiceFlagsAdd
= 0x2,
91 kDNSServiceFlagsDefault
= 0x4,
92 /* Flags for domain enumeration and browse/query reply callbacks.
93 * "Default" applies only to enumeration and is only valid in
94 * conjuction with "Add". An enumeration callback with the "Add"
95 * flag NOT set indicates a "Remove", i.e. the domain is no longer
99 kDNSServiceFlagsNoAutoRename
= 0x8,
100 /* Flag for specifying renaming behavior on name conflict when registering
101 * non-shared records. By default, name conflicts are automatically handled
102 * by renaming the service. NoAutoRename overrides this behavior - with this
103 * flag set, name conflicts will result in a callback. The NoAutorename flag
104 * is only valid if a name is explicitly specified when registering a service
105 * (i.e. the default name is not used.)
108 kDNSServiceFlagsShared
= 0x10,
109 kDNSServiceFlagsUnique
= 0x20,
110 /* Flag for registering individual records on a connected
111 * DNSServiceRef. Shared indicates that there may be multiple records
112 * with this name on the network (e.g. PTR records). Unique indicates that the
113 * record's name is to be unique on the network (e.g. SRV records).
116 kDNSServiceFlagsBrowseDomains
= 0x40,
117 kDNSServiceFlagsRegistrationDomains
= 0x80,
118 /* Flags for specifying domain enumeration type in DNSServiceEnumerateDomains.
119 * BrowseDomains enumerates domains recommended for browsing, RegistrationDomains
120 * enumerates domains recommended for registration.
123 kDNSServiceFlagsLongLivedQuery
= 0x100,
124 /* Flag for creating a long-lived unicast query for the DNSServiceQueryRecord call. */
126 kDNSServiceFlagsAllowRemoteQuery
= 0x200,
127 /* Flag for creating a record for which we will answer remote queries
128 * (queries from hosts more than one hop away; hosts not directly connected to the local link).
131 kDNSServiceFlagsForceMulticast
= 0x400
132 /* Flag for signifying that a query or registration should be performed exclusively via multicast DNS,
133 * even for a name in a domain (e.g. foo.apple.com.) that would normally imply unicast DNS.
138 * The values for DNS Classes and Types are listed in RFC 1035, and are available
139 * on every OS in its DNS header file. Unfortunately every OS does not have the
140 * same header file containing DNS Class and Type constants, and the names of
141 * the constants are not consistent. For example, BIND 8 uses "T_A",
142 * BIND 9 uses "ns_t_a", Windows uses "DNS_TYPE_A", etc.
143 * For this reason, these constants are also listed here, so that code using
144 * the DNS-SD programming APIs can use these constants, so that the same code
145 * can compile on all our supported platforms.
150 kDNSServiceClass_IN
= 1 /* Internet */
155 kDNSServiceType_A
= 1, /* Host address. */
156 kDNSServiceType_NS
= 2, /* Authoritative server. */
157 kDNSServiceType_MD
= 3, /* Mail destination. */
158 kDNSServiceType_MF
= 4, /* Mail forwarder. */
159 kDNSServiceType_CNAME
= 5, /* Canonical name. */
160 kDNSServiceType_SOA
= 6, /* Start of authority zone. */
161 kDNSServiceType_MB
= 7, /* Mailbox domain name. */
162 kDNSServiceType_MG
= 8, /* Mail group member. */
163 kDNSServiceType_MR
= 9, /* Mail rename name. */
164 kDNSServiceType_NULL
= 10, /* Null resource record. */
165 kDNSServiceType_WKS
= 11, /* Well known service. */
166 kDNSServiceType_PTR
= 12, /* Domain name pointer. */
167 kDNSServiceType_HINFO
= 13, /* Host information. */
168 kDNSServiceType_MINFO
= 14, /* Mailbox information. */
169 kDNSServiceType_MX
= 15, /* Mail routing information. */
170 kDNSServiceType_TXT
= 16, /* One or more text strings. */
171 kDNSServiceType_RP
= 17, /* Responsible person. */
172 kDNSServiceType_AFSDB
= 18, /* AFS cell database. */
173 kDNSServiceType_X25
= 19, /* X_25 calling address. */
174 kDNSServiceType_ISDN
= 20, /* ISDN calling address. */
175 kDNSServiceType_RT
= 21, /* Router. */
176 kDNSServiceType_NSAP
= 22, /* NSAP address. */
177 kDNSServiceType_NSAP_PTR
= 23, /* Reverse NSAP lookup (deprecated). */
178 kDNSServiceType_SIG
= 24, /* Security signature. */
179 kDNSServiceType_KEY
= 25, /* Security key. */
180 kDNSServiceType_PX
= 26, /* X.400 mail mapping. */
181 kDNSServiceType_GPOS
= 27, /* Geographical position (withdrawn). */
182 kDNSServiceType_AAAA
= 28, /* Ip6 Address. */
183 kDNSServiceType_LOC
= 29, /* Location Information. */
184 kDNSServiceType_NXT
= 30, /* Next domain (security). */
185 kDNSServiceType_EID
= 31, /* Endpoint identifier. */
186 kDNSServiceType_NIMLOC
= 32, /* Nimrod Locator. */
187 kDNSServiceType_SRV
= 33, /* Server Selection. */
188 kDNSServiceType_ATMA
= 34, /* ATM Address */
189 kDNSServiceType_NAPTR
= 35, /* Naming Authority PoinTeR */
190 kDNSServiceType_KX
= 36, /* Key Exchange */
191 kDNSServiceType_CERT
= 37, /* Certification record */
192 kDNSServiceType_A6
= 38, /* IPv6 address (deprecates AAAA) */
193 kDNSServiceType_DNAME
= 39, /* Non-terminal DNAME (for IPv6) */
194 kDNSServiceType_SINK
= 40, /* Kitchen sink (experimentatl) */
195 kDNSServiceType_OPT
= 41, /* EDNS0 option (meta-RR) */
196 kDNSServiceType_TKEY
= 249, /* Transaction key */
197 kDNSServiceType_TSIG
= 250, /* Transaction signature. */
198 kDNSServiceType_IXFR
= 251, /* Incremental zone transfer. */
199 kDNSServiceType_AXFR
= 252, /* Transfer zone of authority. */
200 kDNSServiceType_MAILB
= 253, /* Transfer mailbox records. */
201 kDNSServiceType_MAILA
= 254, /* Transfer mail agent records. */
202 kDNSServiceType_ANY
= 255 /* Wildcard match. */
206 /* possible error code values */
209 kDNSServiceErr_NoError
= 0,
210 kDNSServiceErr_Unknown
= -65537, /* 0xFFFE FFFF */
211 kDNSServiceErr_NoSuchName
= -65538,
212 kDNSServiceErr_NoMemory
= -65539,
213 kDNSServiceErr_BadParam
= -65540,
214 kDNSServiceErr_BadReference
= -65541,
215 kDNSServiceErr_BadState
= -65542,
216 kDNSServiceErr_BadFlags
= -65543,
217 kDNSServiceErr_Unsupported
= -65544,
218 kDNSServiceErr_NotInitialized
= -65545,
219 kDNSServiceErr_AlreadyRegistered
= -65547,
220 kDNSServiceErr_NameConflict
= -65548,
221 kDNSServiceErr_Invalid
= -65549,
222 kDNSServiceErr_Firewall
= -65550,
223 kDNSServiceErr_Incompatible
= -65551, /* client library incompatible with daemon */
224 kDNSServiceErr_BadInterfaceIndex
= -65552,
225 kDNSServiceErr_Refused
= -65553,
226 kDNSServiceErr_NoSuchRecord
= -65554,
227 kDNSServiceErr_NoAuth
= -65555,
228 kDNSServiceErr_NoSuchKey
= -65556,
229 kDNSServiceErr_NATTraversal
= -65557,
230 kDNSServiceErr_DoubleNAT
= -65558,
231 kDNSServiceErr_BadTime
= -65559
232 /* mDNS Error codes are in the range
233 * FFFE FF00 (-65792) to FFFE FFFF (-65537) */
237 /* Maximum length, in bytes, of a service name represented as a */
238 /* literal C-String, including the terminating NULL at the end. */
240 #define kDNSServiceMaxServiceName 64
242 /* Maximum length, in bytes, of a domain name represented as an *escaped* C-String */
243 /* including the final trailing dot, and the C-String terminating NULL at the end. */
245 #define kDNSServiceMaxDomainName 1005
248 * Notes on DNS Name Escaping
250 * "Why is kDNSServiceMaxDomainName 1005, when the maximum legal domain name is 255 bytes?"
252 * All strings used in DNS-SD are UTF-8 strings.
253 * With few exceptions, most are also escaped using standard DNS escaping rules:
255 * '\\' represents a single literal '\' in the name
256 * '\.' represents a single literal '.' in the name
257 * '\ddd', where ddd is a three-digit decimal value from 000 to 255,
258 * represents a single literal byte with that value.
259 * A bare unescaped '.' is a label separator, marking a boundary between domain and subdomain.
261 * The exceptions, that do not use escaping, are the routines where the full
262 * DNS name of a resource is broken, for convenience, into servicename/regtype/domain.
263 * In these routines, the "servicename" is NOT escaped. It does not need to be, since
264 * it is, by definition, just a single literal string. Any characters in that string
265 * represent exactly what they are. The "regtype" portion is, technically speaking,
266 * escaped, but since legal regtypes are only allowed to contain letters, digits,
267 * and hyphens, there is nothing to escape, so the issue is moot. The "domain"
268 * portion is also escaped, though most domains in use on the public Internet
269 * today, like regtypes, don't contain any characters that need to be escaped.
270 * As DNS-SD becomes more popular, rich-text domains for service discovery will
271 * become common, so software should be written to cope with domains with escaping.
273 * The servicename may be up to 63 bytes of UTF-8 text (not counting the C-String
274 * terminating NULL at the end). The regtype is of the form _service._tcp or
275 * _service._udp, where the "service" part is 1-14 characters, which may be
276 * letters, digits, or hyphens. The domain part of the three-part name may be
277 * any legal domain, providing that the resulting servicename+regtype+domain
278 * name does not exceed 255 bytes.
280 * For most software, these issues are transparent. When browsing, the discovered
281 * servicenames should simply be displayed as-is. When resolving, the discovered
282 * servicename/regtype/domain are simply passed unchanged to DNSServiceResolve().
283 * When a DNSServiceResolve() succeeds, the returned fullname is already in
284 * the correct format to pass to standard system DNS APIs such as res_query().
285 * For converting from servicename/regtype/domain to a single properly-escaped
286 * full DNS name, the helper function DNSServiceConstructFullName() is provided.
288 * The following (highly contrived) example illustrates the escaping process.
289 * Suppose you have an service called "Dr. Smith\Dr. Johnson", of type "_ftp._tcp"
290 * in subdomain "4th. Floor" of subdomain "Building 2" of domain "apple.com."
291 * The full (escaped) DNS name of this service's SRV record would be:
292 * Dr\.\032Smith\\Dr\.\032Johnson._ftp._tcp.4th\.\032Floor.Building\0322.apple.com.
297 * Constants for specifying an interface index
299 * Specific interface indexes are identified via a 32-bit unsigned integer returned
300 * by the if_nametoindex() family of calls.
302 * If the client passes 0 for interface index, that means "do the right thing",
303 * which (at present) means, "if the name is in an mDNS local multicast domain
304 * (e.g. 'local.', '254.169.in-addr.arpa.', '0.8.E.F.ip6.arpa.') then multicast
305 * on all applicable interfaces, otherwise send via unicast to the appropriate
306 * DNS server." Normally, most clients will use 0 for interface index to
307 * automatically get the default sensible behaviour.
309 * If the client passes a positive interface index, then for multicast names that
310 * indicates to do the operation only on that one interface. For unicast names the
311 * interface index is ignored unless kDNSServiceFlagsForceMulticast is also set.
313 * If the client passes kDNSServiceInterfaceIndexLocalOnly when registering
314 * a service, then that service will be found *only* by other local clients
315 * on the same machine that are browsing using kDNSServiceInterfaceIndexLocalOnly
316 * or kDNSServiceInterfaceIndexAny.
317 * If a client has a 'private' service, accessible only to other processes
318 * running on the same machine, this allows the client to advertise that service
319 * in a way such that it does not inadvertently appear in service lists on
320 * all the other machines on the network.
322 * If the client passes kDNSServiceInterfaceIndexLocalOnly when browsing
323 * then it will find *all* records registered on that same local machine.
324 * Clients explicitly wishing to discover *only* LocalOnly services can
325 * accomplish this by inspecting the interfaceIndex of each service reported
326 * to their DNSServiceBrowseReply() callback function, and discarding those
327 * where the interface index is not kDNSServiceInterfaceIndexLocalOnly.
330 #define kDNSServiceInterfaceIndexAny 0
331 #define kDNSServiceInterfaceIndexLocalOnly ( (uint32_t) -1 )
334 typedef uint32_t DNSServiceFlags
;
335 typedef int32_t DNSServiceErrorType
;
338 /*********************************************************************************************
340 * Unix Domain Socket access, DNSServiceRef deallocation, and data processing functions
342 *********************************************************************************************/
345 /* DNSServiceRefSockFD()
347 * Access underlying Unix domain socket for an initialized DNSServiceRef.
348 * The DNS Service Discovery implmementation uses this socket to communicate between
349 * the client and the mDNSResponder daemon. The application MUST NOT directly read from
350 * or write to this socket. Access to the socket is provided so that it can be used as a
351 * run loop source, or in a select() loop: when data is available for reading on the socket,
352 * DNSServiceProcessResult() should be called, which will extract the daemon's reply from
353 * the socket, and pass it to the appropriate application callback. By using a run loop or
354 * select(), results from the daemon can be processed asynchronously. Without using these
355 * constructs, DNSServiceProcessResult() will block until the response from the daemon arrives.
356 * The client is responsible for ensuring that the data on the socket is processed in a timely
357 * fashion - the daemon may terminate its connection with a client that does not clear its
360 * sdRef: A DNSServiceRef initialized by any of the DNSService calls.
362 * return value: The DNSServiceRef's underlying socket descriptor, or -1 on
366 int DNSSD_API
DNSServiceRefSockFD(DNSServiceRef sdRef
);
369 /* DNSServiceProcessResult()
371 * Read a reply from the daemon, calling the appropriate application callback. This call will
372 * block until the daemon's response is received. Use DNSServiceRefSockFD() in
373 * conjunction with a run loop or select() to determine the presence of a response from the
374 * server before calling this function to process the reply without blocking. Call this function
375 * at any point if it is acceptable to block until the daemon's response arrives. Note that the
376 * client is responsible for ensuring that DNSServiceProcessResult() is called whenever there is
377 * a reply from the daemon - the daemon may terminate its connection with a client that does not
378 * process the daemon's responses.
380 * sdRef: A DNSServiceRef initialized by any of the DNSService calls
381 * that take a callback parameter.
383 * return value: Returns kDNSServiceErr_NoError on success, otherwise returns
384 * an error code indicating the specific failure that occurred.
387 DNSServiceErrorType DNSSD_API
DNSServiceProcessResult(DNSServiceRef sdRef
);
390 /* DNSServiceRefDeallocate()
392 * Terminate a connection with the daemon and free memory associated with the DNSServiceRef.
393 * Any services or records registered with this DNSServiceRef will be deregistered. Any
394 * Browse, Resolve, or Query operations called with this reference will be terminated.
396 * Note: If the reference's underlying socket is used in a run loop or select() call, it should
397 * be removed BEFORE DNSServiceRefDeallocate() is called, as this function closes the reference's
400 * Note: If the reference was initialized with DNSServiceCreateConnection(), any DNSRecordRefs
401 * created via this reference will be invalidated by this call - the resource records are
402 * deregistered, and their DNSRecordRefs may not be used in subsequent functions. Similarly,
403 * if the reference was initialized with DNSServiceRegister, and an extra resource record was
404 * added to the service via DNSServiceAddRecord(), the DNSRecordRef created by the Add() call
405 * is invalidated when this function is called - the DNSRecordRef may not be used in subsequent
408 * Note: This call is to be used only with the DNSServiceRef defined by this API. It is
409 * not compatible with dns_service_discovery_ref objects defined in the legacy Mach-based
410 * DNSServiceDiscovery.h API.
412 * sdRef: A DNSServiceRef initialized by any of the DNSService calls.
416 void DNSSD_API
DNSServiceRefDeallocate(DNSServiceRef sdRef
);
419 /*********************************************************************************************
423 *********************************************************************************************/
425 /* DNSServiceEnumerateDomains()
427 * Asynchronously enumerate domains available for browsing and registration.
429 * The enumeration MUST be cancelled via DNSServiceRefDeallocate() when no more domains
432 * Note that the names returned are (like all of DNS-SD) UTF-8 strings,
433 * and are escaped using standard DNS escaping rules.
434 * (See "Notes on DNS Name Escaping" earlier in this file for more details.)
435 * A graphical browser displaying a hierarchical tree-structured view should cut
436 * the names at the bare dots to yield individual labels, then de-escape each
437 * label according to the escaping rules, and then display the resulting UTF-8 text.
439 * DNSServiceDomainEnumReply Callback Parameters:
441 * sdRef: The DNSServiceRef initialized by DNSServiceEnumerateDomains().
443 * flags: Possible values are:
444 * kDNSServiceFlagsMoreComing
445 * kDNSServiceFlagsAdd
446 * kDNSServiceFlagsDefault
448 * interfaceIndex: Specifies the interface on which the domain exists. (The index for a given
449 * interface is determined via the if_nametoindex() family of calls.)
451 * errorCode: Will be kDNSServiceErr_NoError (0) on success, otherwise indicates
452 * the failure that occurred (other parameters are undefined if errorCode is nonzero).
454 * replyDomain: The name of the domain.
456 * context: The context pointer passed to DNSServiceEnumerateDomains.
460 typedef void (DNSSD_API
*DNSServiceDomainEnumReply
)
463 DNSServiceFlags flags
,
464 uint32_t interfaceIndex
,
465 DNSServiceErrorType errorCode
,
466 const char *replyDomain
,
471 /* DNSServiceEnumerateDomains() Parameters:
474 * sdRef: A pointer to an uninitialized DNSServiceRef. If the call succeeds
475 * then it initializes the DNSServiceRef, returns kDNSServiceErr_NoError,
476 * and the enumeration operation will run indefinitely until the client
477 * terminates it by passing this DNSServiceRef to DNSServiceRefDeallocate().
479 * flags: Possible values are:
480 * kDNSServiceFlagsBrowseDomains to enumerate domains recommended for browsing.
481 * kDNSServiceFlagsRegistrationDomains to enumerate domains recommended
484 * interfaceIndex: If non-zero, specifies the interface on which to look for domains.
485 * (the index for a given interface is determined via the if_nametoindex()
486 * family of calls.) Most applications will pass 0 to enumerate domains on
487 * all interfaces. See "Constants for specifying an interface index" for more details.
489 * callBack: The function to be called when a domain is found or the call asynchronously
492 * context: An application context pointer which is passed to the callback function
495 * return value: Returns kDNSServiceErr_NoError on succeses (any subsequent, asynchronous
496 * errors are delivered to the callback), otherwise returns an error code indicating
497 * the error that occurred (the callback is not invoked and the DNSServiceRef
498 * is not initialized.)
501 DNSServiceErrorType DNSSD_API DNSServiceEnumerateDomains
503 DNSServiceRef
*sdRef
,
504 DNSServiceFlags flags
,
505 uint32_t interfaceIndex
,
506 DNSServiceDomainEnumReply callBack
,
507 void *context
/* may be NULL */
511 /*********************************************************************************************
513 * Service Registration
515 *********************************************************************************************/
517 /* Register a service that is discovered via Browse() and Resolve() calls.
520 * DNSServiceRegisterReply() Callback Parameters:
522 * sdRef: The DNSServiceRef initialized by DNSServiceRegister().
524 * flags: Currently unused, reserved for future use.
526 * errorCode: Will be kDNSServiceErr_NoError on success, otherwise will
527 * indicate the failure that occurred (including name conflicts,
528 * if the kDNSServiceFlagsNoAutoRename flag was used when registering.)
529 * Other parameters are undefined if errorCode is nonzero.
531 * name: The service name registered (if the application did not specify a name in
532 * DNSServiceRegister(), this indicates what name was automatically chosen).
534 * regtype: The type of service registered, as it was passed to the callout.
536 * domain: The domain on which the service was registered (if the application did not
537 * specify a domain in DNSServiceRegister(), this indicates the default domain
538 * on which the service was registered).
540 * context: The context pointer that was passed to the callout.
544 typedef void (DNSSD_API
*DNSServiceRegisterReply
)
547 DNSServiceFlags flags
,
548 DNSServiceErrorType errorCode
,
556 /* DNSServiceRegister() Parameters:
558 * sdRef: A pointer to an uninitialized DNSServiceRef. If the call succeeds
559 * then it initializes the DNSServiceRef, returns kDNSServiceErr_NoError,
560 * and the registration will remain active indefinitely until the client
561 * terminates it by passing this DNSServiceRef to DNSServiceRefDeallocate().
563 * interfaceIndex: If non-zero, specifies the interface on which to register the service
564 * (the index for a given interface is determined via the if_nametoindex()
565 * family of calls.) Most applications will pass 0 to register on all
566 * available interfaces. See "Constants for specifying an interface index" for more details.
568 * flags: Indicates the renaming behavior on name conflict (most applications
569 * will pass 0). See flag definitions above for details.
571 * name: If non-NULL, specifies the service name to be registered.
572 * Most applications will not specify a name, in which case the computer
573 * name is used (this name is communicated to the client via the callback).
574 * If a name is specified, it must be 1-63 bytes of UTF-8 text.
575 * If the name is longer than 63 bytes it will be automatically truncated
576 * to a legal length, unless the NoAutoRename flag is set,
577 * in which case kDNSServiceErr_BadParam will be returned.
579 * regtype: The service type followed by the protocol, separated by a dot
580 * (e.g. "_ftp._tcp"). The service type must be an underscore, followed
581 * by 1-14 characters, which may be letters, digits, or hyphens.
582 * The transport protocol must be "_tcp" or "_udp". New service types
583 * should be registered at <http://www.dns-sd.org/ServiceTypes.html>.
585 * domain: If non-NULL, specifies the domain on which to advertise the service.
586 * Most applications will not specify a domain, instead automatically
587 * registering in the default domain(s).
589 * host: If non-NULL, specifies the SRV target host name. Most applications
590 * will not specify a host, instead automatically using the machine's
591 * default host name(s). Note that specifying a non-NULL host does NOT
592 * create an address record for that host - the application is responsible
593 * for ensuring that the appropriate address record exists, or creating it
594 * via DNSServiceRegisterRecord().
596 * port: The port, in network byte order, on which the service accepts connections.
597 * Pass 0 for a "placeholder" service (i.e. a service that will not be discovered
598 * by browsing, but will cause a name conflict if another client tries to
599 * register that same name). Most clients will not use placeholder services.
601 * txtLen: The length of the txtRecord, in bytes. Must be zero if the txtRecord is NULL.
603 * txtRecord: The TXT record rdata. A non-NULL txtRecord MUST be a properly formatted DNS
604 * TXT record, i.e. <length byte> <data> <length byte> <data> ...
605 * Passing NULL for the txtRecord is allowed as a synonym for txtLen=1, txtRecord="",
606 * i.e. it creates a TXT record of length one containing a single empty string.
607 * RFC 1035 doesn't allow a TXT record to contain *zero* strings, so a single empty
608 * string is the smallest legal DNS TXT record.
610 * callBack: The function to be called when the registration completes or asynchronously
611 * fails. The client MAY pass NULL for the callback - The client will NOT be notified
612 * of the default values picked on its behalf, and the client will NOT be notified of any
613 * asynchronous errors (e.g. out of memory errors, etc.) that may prevent the registration
614 * of the service. The client may NOT pass the NoAutoRename flag if the callback is NULL.
615 * The client may still deregister the service at any time via DNSServiceRefDeallocate().
617 * context: An application context pointer which is passed to the callback function
620 * return value: Returns kDNSServiceErr_NoError on succeses (any subsequent, asynchronous
621 * errors are delivered to the callback), otherwise returns an error code indicating
622 * the error that occurred (the callback is never invoked and the DNSServiceRef
623 * is not initialized.)
627 DNSServiceErrorType DNSSD_API DNSServiceRegister
629 DNSServiceRef
*sdRef
,
630 DNSServiceFlags flags
,
631 uint32_t interfaceIndex
,
632 const char *name
, /* may be NULL */
634 const char *domain
, /* may be NULL */
635 const char *host
, /* may be NULL */
638 const void *txtRecord
, /* may be NULL */
639 DNSServiceRegisterReply callBack
, /* may be NULL */
640 void *context
/* may be NULL */
644 /* DNSServiceAddRecord()
646 * Add a record to a registered service. The name of the record will be the same as the
647 * registered service's name.
648 * The record can later be updated or deregistered by passing the RecordRef initialized
649 * by this function to DNSServiceUpdateRecord() or DNSServiceRemoveRecord().
654 * sdRef: A DNSServiceRef initialized by DNSServiceRegister().
656 * RecordRef: A pointer to an uninitialized DNSRecordRef. Upon succesfull completion of this
657 * call, this ref may be passed to DNSServiceUpdateRecord() or DNSServiceRemoveRecord().
658 * If the above DNSServiceRef is passed to DNSServiceRefDeallocate(), RecordRef is also
659 * invalidated and may not be used further.
661 * flags: Currently ignored, reserved for future use.
663 * rrtype: The type of the record (e.g. kDNSServiceType_TXT, kDNSServiceType_SRV, etc)
665 * rdlen: The length, in bytes, of the rdata.
667 * rdata: The raw rdata to be contained in the added resource record.
669 * ttl: The time to live of the resource record, in seconds. Pass 0 to use a default value.
671 * return value: Returns kDNSServiceErr_NoError on success, otherwise returns an
672 * error code indicating the error that occurred (the RecordRef is not initialized).
675 DNSServiceErrorType DNSSD_API DNSServiceAddRecord
678 DNSRecordRef
*RecordRef
,
679 DNSServiceFlags flags
,
687 /* DNSServiceUpdateRecord
689 * Update a registered resource record. The record must either be:
690 * - The primary txt record of a service registered via DNSServiceRegister()
691 * - A record added to a registered service via DNSServiceAddRecord()
692 * - An individual record registered by DNSServiceRegisterRecord()
697 * sdRef: A DNSServiceRef that was initialized by DNSServiceRegister()
698 * or DNSServiceCreateConnection().
700 * RecordRef: A DNSRecordRef initialized by DNSServiceAddRecord, or NULL to update the
701 * service's primary txt record.
703 * flags: Currently ignored, reserved for future use.
705 * rdlen: The length, in bytes, of the new rdata.
707 * rdata: The new rdata to be contained in the updated resource record.
709 * ttl: The time to live of the updated resource record, in seconds.
711 * return value: Returns kDNSServiceErr_NoError on success, otherwise returns an
712 * error code indicating the error that occurred.
715 DNSServiceErrorType DNSSD_API DNSServiceUpdateRecord
718 DNSRecordRef RecordRef
, /* may be NULL */
719 DNSServiceFlags flags
,
726 /* DNSServiceRemoveRecord
728 * Remove a record previously added to a service record set via DNSServiceAddRecord(), or deregister
729 * an record registered individually via DNSServiceRegisterRecord().
733 * sdRef: A DNSServiceRef initialized by DNSServiceRegister() (if the
734 * record being removed was registered via DNSServiceAddRecord()) or by
735 * DNSServiceCreateConnection() (if the record being removed was registered via
736 * DNSServiceRegisterRecord()).
738 * recordRef: A DNSRecordRef initialized by a successful call to DNSServiceAddRecord()
739 * or DNSServiceRegisterRecord().
741 * flags: Currently ignored, reserved for future use.
743 * return value: Returns kDNSServiceErr_NoError on success, otherwise returns an
744 * error code indicating the error that occurred.
747 DNSServiceErrorType DNSSD_API DNSServiceRemoveRecord
750 DNSRecordRef RecordRef
,
751 DNSServiceFlags flags
755 /*********************************************************************************************
759 *********************************************************************************************/
761 /* Browse for instances of a service.
764 * DNSServiceBrowseReply() Parameters:
766 * sdRef: The DNSServiceRef initialized by DNSServiceBrowse().
768 * flags: Possible values are kDNSServiceFlagsMoreComing and kDNSServiceFlagsAdd.
769 * See flag definitions for details.
771 * interfaceIndex: The interface on which the service is advertised. This index should
772 * be passed to DNSServiceResolve() when resolving the service.
774 * errorCode: Will be kDNSServiceErr_NoError (0) on success, otherwise will
775 * indicate the failure that occurred. Other parameters are undefined if
776 * the errorCode is nonzero.
778 * serviceName: The discovered service name. This name should be displayed to the user,
779 * and stored for subsequent use in the DNSServiceResolve() call.
781 * regtype: The service type, which is usually (but not always) the same as was passed
782 * to DNSServiceBrowse(). One case where the discovered service type may
783 * not be the same as the requested service type is when using subtypes:
784 * The client may want to browse for only those ftp servers that allow
785 * anonymous connections. The client will pass the string "_ftp._tcp,_anon"
786 * to DNSServiceBrowse(), but the type of the service that's discovered
787 * is simply "_ftp._tcp". The regtype for each discovered service instance
788 * should be stored along with the name, so that it can be passed to
789 * DNSServiceResolve() when the service is later resolved.
791 * domain: The domain of the discovered service instance. This may or may not be the
792 * same as the domain that was passed to DNSServiceBrowse(). The domain for each
793 * discovered service instance should be stored along with the name, so that
794 * it can be passed to DNSServiceResolve() when the service is later resolved.
796 * context: The context pointer that was passed to the callout.
800 typedef void (DNSSD_API
*DNSServiceBrowseReply
)
803 DNSServiceFlags flags
,
804 uint32_t interfaceIndex
,
805 DNSServiceErrorType errorCode
,
806 const char *serviceName
,
808 const char *replyDomain
,
813 /* DNSServiceBrowse() Parameters:
815 * sdRef: A pointer to an uninitialized DNSServiceRef. If the call succeeds
816 * then it initializes the DNSServiceRef, returns kDNSServiceErr_NoError,
817 * and the browse operation will run indefinitely until the client
818 * terminates it by passing this DNSServiceRef to DNSServiceRefDeallocate().
820 * flags: Currently ignored, reserved for future use.
822 * interfaceIndex: If non-zero, specifies the interface on which to browse for services
823 * (the index for a given interface is determined via the if_nametoindex()
824 * family of calls.) Most applications will pass 0 to browse on all available
825 * interfaces. See "Constants for specifying an interface index" for more details.
827 * regtype: The service type being browsed for followed by the protocol, separated by a
828 * dot (e.g. "_ftp._tcp"). The transport protocol must be "_tcp" or "_udp".
830 * domain: If non-NULL, specifies the domain on which to browse for services.
831 * Most applications will not specify a domain, instead browsing on the
834 * callBack: The function to be called when an instance of the service being browsed for
835 * is found, or if the call asynchronously fails.
837 * context: An application context pointer which is passed to the callback function
840 * return value: Returns kDNSServiceErr_NoError on succeses (any subsequent, asynchronous
841 * errors are delivered to the callback), otherwise returns an error code indicating
842 * the error that occurred (the callback is not invoked and the DNSServiceRef
843 * is not initialized.)
846 DNSServiceErrorType DNSSD_API DNSServiceBrowse
848 DNSServiceRef
*sdRef
,
849 DNSServiceFlags flags
,
850 uint32_t interfaceIndex
,
852 const char *domain
, /* may be NULL */
853 DNSServiceBrowseReply callBack
,
854 void *context
/* may be NULL */
858 /* DNSServiceResolve()
860 * Resolve a service name discovered via DNSServiceBrowse() to a target host name, port number, and
863 * Note: Applications should NOT use DNSServiceResolve() solely for txt record monitoring - use
864 * DNSServiceQueryRecord() instead, as it is more efficient for this task.
866 * Note: When the desired results have been returned, the client MUST terminate the resolve by calling
867 * DNSServiceRefDeallocate().
869 * Note: DNSServiceResolve() behaves correctly for typical services that have a single SRV record
870 * and a single TXT record. To resolve non-standard services with multiple SRV or TXT records,
871 * DNSServiceQueryRecord() should be used.
873 * DNSServiceResolveReply Callback Parameters:
875 * sdRef: The DNSServiceRef initialized by DNSServiceResolve().
877 * flags: Currently unused, reserved for future use.
879 * interfaceIndex: The interface on which the service was resolved.
881 * errorCode: Will be kDNSServiceErr_NoError (0) on success, otherwise will
882 * indicate the failure that occurred. Other parameters are undefined if
883 * the errorCode is nonzero.
885 * fullname: The full service domain name, in the form <servicename>.<protocol>.<domain>.
886 * (This name is escaped following standard DNS rules, making it suitable for
887 * passing to standard system DNS APIs such as res_query(), or to the
888 * special-purpose functions included in this API that take fullname parameters.
889 * See "Notes on DNS Name Escaping" earlier in this file for more details.)
891 * hosttarget: The target hostname of the machine providing the service. This name can
892 * be passed to functions like gethostbyname() to identify the host's IP address.
894 * port: The port, in network byte order, on which connections are accepted for this service.
896 * txtLen: The length of the txt record, in bytes.
898 * txtRecord: The service's primary txt record, in standard txt record format.
901 * context: The context pointer that was passed to the callout.
905 typedef void (DNSSD_API
*DNSServiceResolveReply
)
908 DNSServiceFlags flags
,
909 uint32_t interfaceIndex
,
910 DNSServiceErrorType errorCode
,
911 const char *fullname
,
912 const char *hosttarget
,
915 const char *txtRecord
,
920 /* DNSServiceResolve() Parameters
922 * sdRef: A pointer to an uninitialized DNSServiceRef. If the call succeeds
923 * then it initializes the DNSServiceRef, returns kDNSServiceErr_NoError,
924 * and the resolve operation will run indefinitely until the client
925 * terminates it by passing this DNSServiceRef to DNSServiceRefDeallocate().
927 * flags: Currently ignored, reserved for future use.
929 * interfaceIndex: The interface on which to resolve the service. If this resolve call is
930 * as a result of a currently active DNSServiceBrowse() operation, then the
931 * interfaceIndex should be the index reported in the DNSServiceBrowseReply
932 * callback. If this resolve call is using information previously saved
933 * (e.g. in a preference file) for later use, then use interfaceIndex 0, because
934 * the desired service may now be reachable via a different physical interface.
935 * See "Constants for specifying an interface index" for more details.
937 * name: The name of the service instance to be resolved, as reported to the
938 * DNSServiceBrowseReply() callback.
940 * regtype: The type of the service instance to be resolved, as reported to the
941 * DNSServiceBrowseReply() callback.
943 * domain: The domain of the service instance to be resolved, as reported to the
944 * DNSServiceBrowseReply() callback.
946 * callBack: The function to be called when a result is found, or if the call
947 * asynchronously fails.
949 * context: An application context pointer which is passed to the callback function
952 * return value: Returns kDNSServiceErr_NoError on succeses (any subsequent, asynchronous
953 * errors are delivered to the callback), otherwise returns an error code indicating
954 * the error that occurred (the callback is never invoked and the DNSServiceRef
955 * is not initialized.)
958 DNSServiceErrorType DNSSD_API DNSServiceResolve
960 DNSServiceRef
*sdRef
,
961 DNSServiceFlags flags
,
962 uint32_t interfaceIndex
,
966 DNSServiceResolveReply callBack
,
967 void *context
/* may be NULL */
971 /*********************************************************************************************
973 * Special Purpose Calls (most applications will not use these)
975 *********************************************************************************************/
977 /* DNSServiceCreateConnection()
979 * Create a connection to the daemon allowing efficient registration of
980 * multiple individual records.
985 * sdRef: A pointer to an uninitialized DNSServiceRef. Deallocating
986 * the reference (via DNSServiceRefDeallocate()) severs the
987 * connection and deregisters all records registered on this connection.
989 * return value: Returns kDNSServiceErr_NoError on success, otherwise returns
990 * an error code indicating the specific failure that occurred (in which
991 * case the DNSServiceRef is not initialized).
994 DNSServiceErrorType DNSSD_API
DNSServiceCreateConnection(DNSServiceRef
*sdRef
);
997 /* DNSServiceRegisterRecord
999 * Register an individual resource record on a connected DNSServiceRef.
1001 * Note that name conflicts occurring for records registered via this call must be handled
1002 * by the client in the callback.
1005 * DNSServiceRegisterRecordReply() parameters:
1007 * sdRef: The connected DNSServiceRef initialized by
1008 * DNSServiceDiscoveryConnect().
1010 * RecordRef: The DNSRecordRef initialized by DNSServiceRegisterRecord(). If the above
1011 * DNSServiceRef is passed to DNSServiceRefDeallocate(), this DNSRecordRef is
1012 * invalidated, and may not be used further.
1014 * flags: Currently unused, reserved for future use.
1016 * errorCode: Will be kDNSServiceErr_NoError on success, otherwise will
1017 * indicate the failure that occurred (including name conflicts.)
1018 * Other parameters are undefined if errorCode is nonzero.
1020 * context: The context pointer that was passed to the callout.
1024 typedef void (DNSSD_API
*DNSServiceRegisterRecordReply
)
1026 DNSServiceRef sdRef
,
1027 DNSRecordRef RecordRef
,
1028 DNSServiceFlags flags
,
1029 DNSServiceErrorType errorCode
,
1034 /* DNSServiceRegisterRecord() Parameters:
1036 * sdRef: A DNSServiceRef initialized by DNSServiceCreateConnection().
1038 * RecordRef: A pointer to an uninitialized DNSRecordRef. Upon succesfull completion of this
1039 * call, this ref may be passed to DNSServiceUpdateRecord() or DNSServiceRemoveRecord().
1040 * (To deregister ALL records registered on a single connected DNSServiceRef
1041 * and deallocate each of their corresponding DNSServiceRecordRefs, call
1042 * DNSServiceRefDealloocate()).
1044 * flags: Possible values are kDNSServiceFlagsShared or kDNSServiceFlagsUnique
1045 * (see flag type definitions for details).
1047 * interfaceIndex: If non-zero, specifies the interface on which to register the record
1048 * (the index for a given interface is determined via the if_nametoindex()
1049 * family of calls.) Passing 0 causes the record to be registered on all interfaces.
1050 * See "Constants for specifying an interface index" for more details.
1052 * fullname: The full domain name of the resource record.
1054 * rrtype: The numerical type of the resource record (e.g. kDNSServiceType_PTR, kDNSServiceType_SRV, etc)
1056 * rrclass: The class of the resource record (usually kDNSServiceClass_IN)
1058 * rdlen: Length, in bytes, of the rdata.
1060 * rdata: A pointer to the raw rdata, as it is to appear in the DNS record.
1062 * ttl: The time to live of the resource record, in seconds. Pass 0 to use a default value.
1064 * callBack: The function to be called when a result is found, or if the call
1065 * asynchronously fails (e.g. because of a name conflict.)
1067 * context: An application context pointer which is passed to the callback function
1070 * return value: Returns kDNSServiceErr_NoError on succeses (any subsequent, asynchronous
1071 * errors are delivered to the callback), otherwise returns an error code indicating
1072 * the error that occurred (the callback is never invoked and the DNSRecordRef is
1076 DNSServiceErrorType DNSSD_API DNSServiceRegisterRecord
1078 DNSServiceRef sdRef
,
1079 DNSRecordRef
*RecordRef
,
1080 DNSServiceFlags flags
,
1081 uint32_t interfaceIndex
,
1082 const char *fullname
,
1088 DNSServiceRegisterRecordReply callBack
,
1089 void *context
/* may be NULL */
1093 /* DNSServiceQueryRecord
1095 * Query for an arbitrary DNS record.
1098 * DNSServiceQueryRecordReply() Callback Parameters:
1100 * sdRef: The DNSServiceRef initialized by DNSServiceQueryRecord().
1102 * flags: Possible values are kDNSServiceFlagsMoreComing and
1103 * kDNSServiceFlagsAdd. The Add flag is NOT set for PTR records
1104 * with a ttl of 0, i.e. "Remove" events.
1106 * interfaceIndex: The interface on which the query was resolved (the index for a given
1107 * interface is determined via the if_nametoindex() family of calls).
1108 * See "Constants for specifying an interface index" for more details.
1110 * errorCode: Will be kDNSServiceErr_NoError on success, otherwise will
1111 * indicate the failure that occurred. Other parameters are undefined if
1112 * errorCode is nonzero.
1114 * fullname: The resource record's full domain name.
1116 * rrtype: The resource record's type (e.g. kDNSServiceType_PTR, kDNSServiceType_SRV, etc)
1118 * rrclass: The class of the resource record (usually kDNSServiceClass_IN).
1120 * rdlen: The length, in bytes, of the resource record rdata.
1122 * rdata: The raw rdata of the resource record.
1124 * ttl: The resource record's time to live, in seconds.
1126 * context: The context pointer that was passed to the callout.
1130 typedef void (DNSSD_API
*DNSServiceQueryRecordReply
)
1132 DNSServiceRef DNSServiceRef
,
1133 DNSServiceFlags flags
,
1134 uint32_t interfaceIndex
,
1135 DNSServiceErrorType errorCode
,
1136 const char *fullname
,
1146 /* DNSServiceQueryRecord() Parameters:
1148 * sdRef: A pointer to an uninitialized DNSServiceRef. If the call succeeds
1149 * then it initializes the DNSServiceRef, returns kDNSServiceErr_NoError,
1150 * and the query operation will run indefinitely until the client
1151 * terminates it by passing this DNSServiceRef to DNSServiceRefDeallocate().
1153 * flags: Pass kDNSServiceFlagsLongLivedQuery to create a "long-lived" unicast
1154 * query in a non-local domain. Without setting this flag, unicast queries
1155 * will be one-shot - that is, only answers available at the time of the call
1156 * will be returned. By setting this flag, answers (including Add and Remove
1157 * events) that become available after the initial call is made will generate
1158 * callbacks. This flag has no effect on link-local multicast queries.
1160 * interfaceIndex: If non-zero, specifies the interface on which to issue the query
1161 * (the index for a given interface is determined via the if_nametoindex()
1162 * family of calls.) Passing 0 causes the name to be queried for on all
1163 * interfaces. See "Constants for specifying an interface index" for more details.
1165 * fullname: The full domain name of the resource record to be queried for.
1167 * rrtype: The numerical type of the resource record to be queried for
1168 * (e.g. kDNSServiceType_PTR, kDNSServiceType_SRV, etc)
1170 * rrclass: The class of the resource record (usually kDNSServiceClass_IN).
1172 * callBack: The function to be called when a result is found, or if the call
1173 * asynchronously fails.
1175 * context: An application context pointer which is passed to the callback function
1178 * return value: Returns kDNSServiceErr_NoError on succeses (any subsequent, asynchronous
1179 * errors are delivered to the callback), otherwise returns an error code indicating
1180 * the error that occurred (the callback is never invoked and the DNSServiceRef
1181 * is not initialized.)
1184 DNSServiceErrorType DNSSD_API DNSServiceQueryRecord
1186 DNSServiceRef
*sdRef
,
1187 DNSServiceFlags flags
,
1188 uint32_t interfaceIndex
,
1189 const char *fullname
,
1192 DNSServiceQueryRecordReply callBack
,
1193 void *context
/* may be NULL */
1197 /* DNSServiceReconfirmRecord
1199 * Instruct the daemon to verify the validity of a resource record that appears to
1200 * be out of date (e.g. because tcp connection to a service's target failed.)
1201 * Causes the record to be flushed from the daemon's cache (as well as all other
1202 * daemons' caches on the network) if the record is determined to be invalid.
1206 * flags: Currently unused, reserved for future use.
1208 * interfaceIndex: If non-zero, specifies the interface of the record in question.
1209 * Passing 0 causes all instances of this record to be reconfirmed.
1211 * fullname: The resource record's full domain name.
1213 * rrtype: The resource record's type (e.g. kDNSServiceType_PTR, kDNSServiceType_SRV, etc)
1215 * rrclass: The class of the resource record (usually kDNSServiceClass_IN).
1217 * rdlen: The length, in bytes, of the resource record rdata.
1219 * rdata: The raw rdata of the resource record.
1223 void DNSSD_API DNSServiceReconfirmRecord
1225 DNSServiceFlags flags
,
1226 uint32_t interfaceIndex
,
1227 const char *fullname
,
1235 /*********************************************************************************************
1237 * General Utility Functions
1239 *********************************************************************************************/
1241 /* DNSServiceConstructFullName()
1243 * Concatenate a three-part domain name (as returned by the above callbacks) into a
1244 * properly-escaped full domain name. Note that callbacks in the above functions ALREADY ESCAPE
1245 * strings where necessary.
1249 * fullName: A pointer to a buffer that where the resulting full domain name is to be written.
1250 * The buffer must be kDNSServiceMaxDomainName (1005) bytes in length to
1251 * accommodate the longest legal domain name without buffer overrun.
1253 * service: The service name - any dots or backslashes must NOT be escaped.
1254 * May be NULL (to construct a PTR record name, e.g.
1255 * "_ftp._tcp.apple.com.").
1257 * regtype: The service type followed by the protocol, separated by a dot
1258 * (e.g. "_ftp._tcp").
1260 * domain: The domain name, e.g. "apple.com.". Literal dots or backslashes,
1261 * if any, must be escaped, e.g. "1st\. Floor.apple.com."
1263 * return value: Returns 0 on success, -1 on error.
1267 int DNSSD_API DNSServiceConstructFullName
1270 const char *service
, /* may be NULL */
1271 const char *regtype
,
1276 /*********************************************************************************************
1278 * TXT Record Construction Functions
1280 *********************************************************************************************/
1283 * A typical calling sequence for TXT record construction is something like:
1285 * Client allocates storage for TXTRecord data (e.g. declare buffer on the stack)
1286 * TXTRecordCreate();
1287 * TXTRecordSetValue();
1288 * TXTRecordSetValue();
1289 * TXTRecordSetValue();
1291 * DNSServiceRegister( ... TXTRecordGetLength(), TXTRecordGetBytesPtr() ... );
1292 * TXTRecordDeallocate();
1293 * Explicitly deallocate storage for TXTRecord data (if not allocated on the stack)
1299 * Opaque internal data type.
1300 * Note: Represents a DNS-SD TXT record.
1303 typedef union _TXTRecordRef_t
{ char PrivateData
[16]; char *ForceNaturalAlignment
; } TXTRecordRef
;
1306 /* TXTRecordCreate()
1308 * Creates a new empty TXTRecordRef referencing the specified storage.
1310 * If the buffer parameter is NULL, or the specified storage size is not
1311 * large enough to hold a key subsequently added using TXTRecordSetValue(),
1312 * then additional memory will be added as needed using malloc().
1314 * On some platforms, when memory is low, malloc() may fail. In this
1315 * case, TXTRecordSetValue() will return kDNSServiceErr_NoMemory, and this
1316 * error condition will need to be handled as appropriate by the caller.
1318 * You can avoid the need to handle this error condition if you ensure
1319 * that the storage you initially provide is large enough to hold all
1320 * the key/value pairs that are to be added to the record.
1321 * The caller can precompute the exact length required for all of the
1322 * key/value pairs to be added, or simply provide a fixed-sized buffer
1323 * known in advance to be large enough.
1324 * A no-value (key-only) key requires (1 + key length) bytes.
1325 * A key with empty value requires (1 + key length + 1) bytes.
1326 * A key with non-empty value requires (1 + key length + 1 + value length).
1327 * For most applications, DNS-SD TXT records are generally
1328 * less than 100 bytes, so in most cases a simple fixed-sized
1329 * 256-byte buffer will be more than sufficient.
1330 * Recommended size limits for DNS-SD TXT Records are discussed in
1331 * <http://files.dns-sd.org/draft-cheshire-dnsext-dns-sd.txt>
1333 * Note: When passing parameters to and from these TXT record APIs,
1334 * the key name does not include the '=' character. The '=' character
1335 * is the separator between the key and value in the on-the-wire
1336 * packet format; it is not part of either the key or the value.
1338 * txtRecord: A pointer to an uninitialized TXTRecordRef.
1340 * bufferLen: The size of the storage provided in the "buffer" parameter.
1342 * buffer: Optional caller-supplied storage used to hold the TXTRecord data.
1343 * This storage must remain valid for as long as
1347 void DNSSD_API TXTRecordCreate
1349 TXTRecordRef
*txtRecord
,
1355 /* TXTRecordDeallocate()
1357 * Releases any resources allocated in the course of preparing a TXT Record
1358 * using TXTRecordCreate()/TXTRecordSetValue()/TXTRecordRemoveValue().
1359 * Ownership of the buffer provided in TXTRecordCreate() returns to the client.
1361 * txtRecord: A TXTRecordRef initialized by calling TXTRecordCreate().
1365 void DNSSD_API TXTRecordDeallocate
1367 TXTRecordRef
*txtRecord
1371 /* TXTRecordSetValue()
1373 * Adds a key (optionally with value) to a TXTRecordRef. If the "key" already
1374 * exists in the TXTRecordRef, then the current value will be replaced with
1376 * Keys may exist in four states with respect to a given TXT record:
1377 * - Absent (key does not appear at all)
1378 * - Present with no value ("key" appears alone)
1379 * - Present with empty value ("key=" appears in TXT record)
1380 * - Present with non-empty value ("key=value" appears in TXT record)
1381 * For more details refer to "Data Syntax for DNS-SD TXT Records" in
1382 * <http://files.dns-sd.org/draft-cheshire-dnsext-dns-sd.txt>
1384 * txtRecord: A TXTRecordRef initialized by calling TXTRecordCreate().
1386 * key: A null-terminated string which only contains printable ASCII
1387 * values (0x20-0x7E), excluding '=' (0x3D). Keys should be
1388 * 8 characters or less (not counting the terminating null).
1390 * valueSize: The size of the value.
1392 * value: Any binary value. For values that represent
1393 * textual data, UTF-8 is STRONGLY recommended.
1394 * For values that represent textual data, valueSize
1395 * should NOT include the terminating null (if any)
1396 * at the end of the string.
1397 * If NULL, then "key" will be added with no value.
1398 * If non-NULL but valueSize is zero, then "key=" will be
1399 * added with empty value.
1401 * return value: Returns kDNSServiceErr_NoError on success.
1402 * Returns kDNSServiceErr_Invalid if the "key" string contains
1403 * illegal characters.
1404 * Returns kDNSServiceErr_NoMemory if adding this key would
1405 * exceed the available storage.
1408 DNSServiceErrorType DNSSD_API TXTRecordSetValue
1410 TXTRecordRef
*txtRecord
,
1412 uint8_t valueSize
, /* may be zero */
1413 const void *value
/* may be NULL */
1417 /* TXTRecordRemoveValue()
1419 * Removes a key from a TXTRecordRef. The "key" must be an
1420 * ASCII string which exists in the TXTRecordRef.
1422 * txtRecord: A TXTRecordRef initialized by calling TXTRecordCreate().
1424 * key: A key name which exists in the TXTRecordRef.
1426 * return value: Returns kDNSServiceErr_NoError on success.
1427 * Returns kDNSServiceErr_NoSuchKey if the "key" does not
1428 * exist in the TXTRecordRef.
1432 DNSServiceErrorType DNSSD_API TXTRecordRemoveValue
1434 TXTRecordRef
*txtRecord
,
1439 /* TXTRecordGetLength()
1441 * Allows you to determine the length of the raw bytes within a TXTRecordRef.
1443 * txtRecord: A TXTRecordRef initialized by calling TXTRecordCreate().
1445 * return value: Returns the size of the raw bytes inside a TXTRecordRef
1446 * which you can pass directly to DNSServiceRegister() or
1447 * to DNSServiceUpdateRecord().
1448 * Returns 0 if the TXTRecordRef is empty.
1452 uint16_t DNSSD_API TXTRecordGetLength
1454 const TXTRecordRef
*txtRecord
1458 /* TXTRecordGetBytesPtr()
1460 * Allows you to retrieve a pointer to the raw bytes within a TXTRecordRef.
1462 * txtRecord: A TXTRecordRef initialized by calling TXTRecordCreate().
1464 * return value: Returns a pointer to the raw bytes inside the TXTRecordRef
1465 * which you can pass directly to DNSServiceRegister() or
1466 * to DNSServiceUpdateRecord().
1470 const void * DNSSD_API TXTRecordGetBytesPtr
1472 const TXTRecordRef
*txtRecord
1476 /*********************************************************************************************
1478 * TXT Record Parsing Functions
1480 *********************************************************************************************/
1483 * A typical calling sequence for TXT record parsing is something like:
1485 * Receive TXT record data in DNSServiceResolve() callback
1486 * if (TXTRecordContainsKey(txtLen, txtRecord, "key")) then do something
1487 * val1ptr = TXTRecordGetValuePtr(txtLen, txtRecord, "key1", &len1);
1488 * val2ptr = TXTRecordGetValuePtr(txtLen, txtRecord, "key2", &len2);
1490 * bcopy(val1ptr, myval1, len1);
1491 * bcopy(val2ptr, myval2, len2);
1495 * If you wish to retain the values after return from the DNSServiceResolve()
1496 * callback, then you need to copy the data to your own storage using bcopy()
1497 * or similar, as shown in the example above.
1499 * If for some reason you need to parse a TXT record you built yourself
1500 * using the TXT record construction functions above, then you can do
1501 * that using TXTRecordGetLength and TXTRecordGetBytesPtr calls:
1502 * TXTRecordGetValue(TXTRecordGetLength(x), TXTRecordGetBytesPtr(x), key, &len);
1504 * Most applications only fetch keys they know about from a TXT record and
1506 * However, some debugging tools wish to fetch and display all keys.
1507 * To do that, use the TXTRecordGetCount() and TXTRecordGetItemAtIndex() calls.
1510 /* TXTRecordContainsKey()
1512 * Allows you to determine if a given TXT Record contains a specified key.
1514 * txtLen: The size of the received TXT Record.
1516 * txtRecord: Pointer to the received TXT Record bytes.
1518 * key: A null-terminated ASCII string containing the key name.
1520 * return value: Returns 1 if the TXT Record contains the specified key.
1521 * Otherwise, it returns 0.
1525 int DNSSD_API TXTRecordContainsKey
1528 const void *txtRecord
,
1533 /* TXTRecordGetValuePtr()
1535 * Allows you to retrieve the value for a given key from a TXT Record.
1537 * txtLen: The size of the received TXT Record
1539 * txtRecord: Pointer to the received TXT Record bytes.
1541 * key: A null-terminated ASCII string containing the key name.
1543 * valueLen: On output, will be set to the size of the "value" data.
1545 * return value: Returns NULL if the key does not exist in this TXT record,
1546 * or exists with no value (to differentiate between
1547 * these two cases use TXTRecordContainsKey()).
1548 * Returns pointer to location within TXT Record bytes
1549 * if the key exists with empty or non-empty value.
1550 * For empty value, valueLen will be zero.
1551 * For non-empty value, valueLen will be length of value data.
1554 const void * DNSSD_API TXTRecordGetValuePtr
1557 const void *txtRecord
,
1563 /* TXTRecordGetCount()
1565 * Returns the number of keys stored in the TXT Record. The count
1566 * can be used with TXTRecordGetItemAtIndex() to iterate through the keys.
1568 * txtLen: The size of the received TXT Record.
1570 * txtRecord: Pointer to the received TXT Record bytes.
1572 * return value: Returns the total number of keys in the TXT Record.
1576 uint16_t DNSSD_API TXTRecordGetCount
1579 const void *txtRecord
1583 /* TXTRecordGetItemAtIndex()
1585 * Allows you to retrieve a key name and value pointer, given an index into
1586 * a TXT Record. Legal index values range from zero to TXTRecordGetCount()-1.
1587 * It's also possible to iterate through keys in a TXT record by simply
1588 * calling TXTRecordGetItemAtIndex() repeatedly, beginning with index zero
1589 * and increasing until TXTRecordGetItemAtIndex() returns kDNSServiceErr_Invalid.
1592 * For keys with no value, *value is set to NULL and *valueLen is zero.
1593 * For keys with empty value, *value is non-NULL and *valueLen is zero.
1594 * For keys with non-empty value, *value is non-NULL and *valueLen is non-zero.
1596 * txtLen: The size of the received TXT Record.
1598 * txtRecord: Pointer to the received TXT Record bytes.
1600 * index: An index into the TXT Record.
1602 * keyBufLen: The size of the string buffer being supplied.
1604 * key: A string buffer used to store the key name.
1605 * On return, the buffer contains a null-terminated C string
1606 * giving the key name. DNS-SD TXT keys are usually
1607 * 8 characters or less. To hold the maximum possible
1608 * key name, the buffer should be 256 bytes long.
1610 * valueLen: On output, will be set to the size of the "value" data.
1612 * value: On output, *value is set to point to location within TXT
1613 * Record bytes that holds the value data.
1615 * return value: Returns kDNSServiceErr_NoError on success.
1616 * Returns kDNSServiceErr_NoMemory if keyBufLen is too short.
1617 * Returns kDNSServiceErr_Invalid if index is greater than
1618 * TXTRecordGetCount()-1.
1621 DNSServiceErrorType DNSSD_API TXTRecordGetItemAtIndex
1624 const void *txtRecord
,
1632 #ifdef __APPLE_API_PRIVATE
1635 * Mac OS X specific functionality
1636 * 3rd party clients of this API should not depend on future support or availability of this routine
1639 /* DNSServiceSetDefaultDomainForUser()
1641 * Set the default domain for the caller's UID. Future browse and registration
1642 * calls by this user that do not specify an explicit domain will browse and
1643 * register in this wide-area domain in addition to .local. In addition, this
1644 * domain will be returned as a Browse domain via domain enumeration calls.
1649 * flags: Pass kDNSServiceFlagsAdd to add a domain for a user. Call without
1650 * this flag set to clear a previously added domain.
1652 * domain: The domain to be used for the caller's UID.
1654 * return value: Returns kDNSServiceErr_NoError on succeses, otherwise returns
1655 * an error code indicating the error that occurred
1658 DNSServiceErrorType DNSSD_API DNSServiceSetDefaultDomainForUser
1660 DNSServiceFlags flags
,
1664 #endif //__APPLE_API_PRIVATE
1666 // Some C compiler cleverness. We can make the compiler check certain things for us,
1667 // and report errors at compile-time if anything is wrong. The usual way to do this would
1668 // be to use a run-time "if" statement or the conventional run-time "assert" mechanism, but
1669 // then you don't find out what's wrong until you run the software. This way, if the assertion
1670 // condition is false, the array size is negative, and the complier complains immediately.
1672 struct DNS_SD_CompileTimeAssertionChecks
1674 char assert0
[(sizeof(union _TXTRecordRef_t
) == 16) ? 1 : -1];
1681 #endif /* _DNS_SD_H */