2 * Copyright (c) 2003 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
23 * @APPLE_LICENSE_HEADER_END@
29 #include <sys/types.h>
30 #include <sys/socket.h>
32 #include <netinet/in.h>
35 /* DNSServiceRef, DNSRecordRef
37 * Opaque internal data types.
38 * Note: client is responsible for serializing access to these structures if
39 * they are shared between concurrent threads.
42 typedef struct _DNSServiceRef_t
*DNSServiceRef
;
43 typedef struct _DNSRecordRef_t
*DNSRecordRef
;
45 /* General flags used in functions defined below */
48 kDNSServiceFlagsMoreComing
= 1,
49 kDNSServiceFlagsFinished
= 0, /* i.e. bit not set */
50 /* MoreComing indicates to a Browse callback that another result is
51 * queued. Applications should not update their UI to display browse
52 * results when the MoreComing flag is set, instead deferring the update
53 * until the callback's flag is Finished. */
55 kDNSServiceFlagsAdd
= 2,
56 kDNSServiceFlagsDefault
= 4,
57 kDNSServiceFlagsRemove
= 0, /* i.e. bit not set */
58 /* Flags for domain enumeration and browse reply callbacks.
59 * "Default" applies only to enumeration and is only valid in
60 * conjuction with "Add"
63 kDNSServiceFlagsNoAutoRename
= 8,
64 kDNSServiceFlagsAutoRename
= 0, /* i.e. bit not set */
65 /* Flag for specifying renaming behavior on name conflict when registering
66 * non-shared records. NoAutorename is only valid if a name is explicitly
67 * specified when registering a service (ie the default name is not used.)
71 kDNSServiceFlagsShared
= 16,
72 kDNSServiceFlagsUnique
= 32,
73 /* Flag for registering individual records on a connected
74 * DNSServiceRef. Shared indicates that there may be multiple records
75 * with this name on the network (e.g. PTR records). Unique indicates that the
76 * record's name is to be unique on the network (e.g. SRV records).
79 kDNSServiceFlagsBrowseDomains
= 64,
80 kDNSServiceFlagsRegistrationDomains
= 128
81 /* Flags for specifying domain enumeration type in DNSServiceEnumerateDomains.
82 * BrowseDomains enumerates domains recommended for browsing, RegistrationDomains
83 * enumerates domains recommended for registration.
87 /* possible error code values */
90 kDNSServiceErr_NoError
= 0,
91 kDNSServiceErr_Unknown
= -65537, /* 0xFFFE FFFF */
92 kDNSServiceErr_NoSuchName
= -65538,
93 kDNSServiceErr_NoMemory
= -65539,
94 kDNSServiceErr_BadParam
= -65540,
95 kDNSServiceErr_BadReference
= -65541,
96 kDNSServiceErr_BadState
= -65542,
97 kDNSServiceErr_BadFlags
= -65543,
98 kDNSServiceErr_Unsupported
= -65544,
99 kDNSServiceErr_NotInitialized
= -65545,
100 kDNSServiceErr_AlreadyRegistered
= -65547,
101 kDNSServiceErr_NameConflict
= -65548,
102 kDNSServiceErr_Invalid
= -65549,
103 kDNSServiceErr_Incompatible
= -65551, /* client library incompatible with daemon */
104 kDNSServiceErr_BadinterfaceIndex
= -65552
105 /* mDNS Error codes are in the range
106 * FFFE FF00 (-65792) to FFFE FFFF (-65537) */
110 /* Maximum length, in bytes, of a domain name represented as an escaped C-String */
111 #define kDNSServiceMaxDomainName 1005
114 typedef uint32_t DNSServiceFlags
;
115 typedef int32_t DNSServiceErrorType
;
118 /*********************************************************************************************
120 * Unix Domain Socket access, DNSServiceRef deallocation, and data processing functions
122 *********************************************************************************************/
125 /* DNSServiceRefSockFD()
127 * Access underlying Unix domain socket for an initialized DNSServiceRef.
128 * The DNS Service Discovery implmementation uses this socket to communicate between
129 * the client and the mDNSResponder daemon. The application MUST NOT directly read from
130 * or write to this socket. Access to the socket is provided so that it can be used as a
131 * run loop source, or in a select() loop: when data is available for reading on the socket,
132 * DNSServiceProcessResult() should be called, which will extract the daemon's reply from
133 * the socket, and pass it to the appropriate application callback. By using a run loop or
134 * select(), results from the daemon can be processed asynchronously. Without using these
135 * constructs, DNSServiceProcessResult() will block until the response from the daemon arrives.
136 * The client is responsible for ensuring that the data on the socket is processed in a timely
137 * fashion - the daemon may terminate its connection with a client that does not clear its
140 * sdRef: A DNSServiceRef initialized by any of the DNSService calls.
142 * return value: The DNSServiceRef's underlying socket descriptor, or -1 on
146 int DNSServiceRefSockFD(DNSServiceRef sdRef
);
148 /* DNSServiceProcessResult()
150 * Read a reply from the daemon, calling the appropriate application callback. This call will
151 * block until the daemon's response is received. Use DNSServiceRefSockFD() in
152 * conjunction with a run loop or select() to determine the presence of a response from the
153 * server before calling this function to process the reply without blocking. Call this function
154 * at any point if it is acceptable to block until the daemon's response arrives. Note that the
155 * client is responsible for ensuring that DNSServiceProcessResult() is called whenever there is
156 * a reply from the daemon - the daemon may terminate its connection with a client that does not
157 * process the daemon's responses.
159 * sdRef: A DNSServiceRef initialized by any of the DNSService calls
160 * that take a callback parameter.
162 * return value: Returns kDNSServiceErr_NoError on success, otherwise returns
163 * an error code indicating the specific failure that occurred.
166 DNSServiceErrorType
DNSServiceProcessResult(DNSServiceRef sdRef
);
168 /* DNSServiceRefDeallocate()
170 * Terminate a connection with the daemon and free memory associated with the DNSServiceRef.
171 * Any services or records registered with this DNSServiceRef will be deregistered. Any
172 * Browse, Resolve, or Query operations called with this reference will be terminated.
174 * Note: If the reference's underlying socket is used in a run loop or select() call, it should
175 * be removed BEFORE DNSServiceRefDeallocate() is called, as this function closes the reference's
178 * Note: If the reference was initialized with DNSServiceCreateConnection(), any DNSRecordRefs
179 * created via this reference will be invalidated by this call - the resource records are
180 * deregistered, and their DNSRecordRefs may not be used in subsequent functions. Similarly,
181 * if the reference was initialized with DNSServiceRegister, and an extra resource record was
182 * added to the service via DNSServiceAddRecord(), the DNSRecordRef created by the Add() call
183 * is invalidated when this function is called - the DNSRecordRef may not be used in subsequent
186 * Note: This call is to be used only with the DNSServiceRef defined by this API. It is
187 * not compatible with dns_service_discovery_ref objects defined in the legacy Mach-based
188 * DNSServiceDiscovery.h API.
190 * sdRef: A DNSServiceRef initialized by any of the DNSService calls.
194 void DNSServiceRefDeallocate(DNSServiceRef sdRef
);
197 /*********************************************************************************************
201 *********************************************************************************************/
203 /* DNSServiceEnumerateDomains()
205 * Asynchronously enumerate domains available for browsing and registration.
206 * Currently, the only domain returned is "local.", but other domains will be returned in future.
208 * The enumeration MUST be cancelled via DNSServiceRefDeallocate() when no more domains
212 * DNSServiceDomainEnumReply Callback Parameters:
214 * sdRef: The DNSServiceRef initialized by DNSServiceEnumerateDomains().
216 * flags: Possible values are:
221 * interfaceIndex: Specifies the interface on which the domain exists. (The index for a given
222 * interface is determined via the if_nametoindex() family of calls.)
224 * errorCode: Will be kDNSServiceErr_NoError (0) on success, otherwise indicates
225 * the failure that occurred (other parameters are undefined if errorCode is nonzero).
227 * replyDomain: The name of the domain.
229 * context: The context pointer passed to DNSServiceEnumerateDomains.
233 typedef void (*DNSServiceDomainEnumReply
)
236 DNSServiceFlags flags
,
237 uint32_t interfaceIndex
,
238 DNSServiceErrorType errorCode
,
239 const char *replyDomain
,
243 /* DNSServiceEnumerateDomains() Parameters:
246 * sdRef: A pointer to an uninitialized sdRef. May be passed to
247 * DNSServiceRefDeallocate() to cancel the enumeration.
249 * flags: Possible values are:
250 * 0 (BrowseDomains) to enumerate domains recommended for browsing.
251 * 32 (RegistrationDomains) to enumerate domains recommended for registration.
253 * interfaceIndex: If non-zero, specifies the interface on which to look for domains.
254 * (the index for a given interface is determined via the if_nametoindex()
255 * family of calls.) Most applications will pass 0 to enumerate domains on
258 * callBack: The function to be called when a domain is found or the call asynchronously
261 * context: An application context pointer which is passed to the callback function
264 * return value: Returns kDNSServiceErr_NoError on succeses (any subsequent, asynchronous
265 * errors are delivered to the callback), otherwise returns an error code indicating
266 * the error that occurred (the callback is not invoked and the DNSServiceRef
267 * is not initialized.)
270 DNSServiceErrorType DNSServiceEnumerateDomains
272 DNSServiceRef
*sdRef
,
273 DNSServiceFlags flags
,
274 uint32_t interfaceIndex
,
275 DNSServiceDomainEnumReply callBack
,
276 void *context
/* may be NULL */
279 /*********************************************************************************************
281 * Service Registration
283 *********************************************************************************************/
285 /* Register a service that is discovered via Browse() and Resolve() calls.
288 * DNSServiceRegisterReply() Callback Parameters:
290 * sdRef: The DNSServiceRef initialized by DNSServiceRegister().
292 * flags: Currently unused, reserved for future use.
294 * errorCode: Will be kDNSServiceErr_NoError on success, otherwise will
295 * indicate the failure that occurred (including name conflicts, if the
296 * kDNSServiceFlagsNoAutoRenameOnConflict flag was passed to the
297 * callout.) Other parameters are undefined if errorCode is nonzero.
299 * name: The service name registered (if the application did not specify a name in
300 * DNSServiceRegister(), this indicates what name was automatically chosen).
302 * regtype: The type of service registered, as it was passed to the callout.
304 * domain: The domain on which the service was registered (if the application did not
305 * specify a domain in DNSServiceRegister(), this indicates the default domain
306 * on which the service was registered).
308 * context: The context pointer that was passed to the callout.
312 typedef void (*DNSServiceRegisterReply
)
315 DNSServiceFlags flags
,
316 DNSServiceErrorType errorCode
,
323 /* DNSServiceRegister() Parameters:
325 * sdRef: A pointer to an uninitialized sdRef. If this call succeeds, the reference
327 * DNSServiceRefDeallocate() to deregister the service.
329 * interfaceIndex: If non-zero, specifies the interface on which to register the service
330 * (the index for a given interface is determined via the if_nametoindex()
331 * family of calls.) Most applications will pass 0 to register on all
332 * available interfaces. Pass -1 to register a service only on the local
333 * machine (service will not be visible to remote hosts.)
335 * flags: Indicates the renaming behavior on name conflict (most applications
336 * will pass 0). See flag definitions above for details.
338 * name: If non-NULL, specifies the service name to be registered.
339 * Most applications will not specify a name, in which case the
340 * computer name is used (this name is communicated to the client via
343 * regtype: The service type followed by the protocol, separated by a dot
344 * (e.g. "_ftp._tcp"). The transport protocol must be "_tcp" or "_udp".
346 * domain: If non-NULL, specifies the domain on which to advertise the service.
347 * Most applications will not specify a domain, instead automatically
348 * registering in the default domain(s).
350 * host: If non-NULL, specifies the SRV target host name. Most applications
351 * will not specify a host, instead automatically using the machine's
352 * default host name(s). Note that specifying a non-NULL host does NOT
353 * create an address record for that host - the application is responsible
354 * for ensuring that the appropriate address record exists, or creating it
355 * via DNSServiceRegisterRecord().
357 * port: The port on which the service accepts connections. Pass 0 for a
358 * "placeholder" service (i.e. a service that will not be discovered by
359 * browsing, but will cause a name conflict if another client tries to
360 * register that same name.) Most clients will not use placeholder services.
362 * txtLen: The length of the txtRecord, in bytes. Must be zero if the txtRecord is NULL.
364 * txtRecord: The txt record rdata. May be NULL. Note that a non-NULL txtRecord
365 * MUST be a properly formatted DNS TXT record, i.e. <length byte> <data>
366 * <length byte> <data> ...
368 * callBack: The function to be called when the registration completes or asynchronously
369 * fails. The client MAY pass NULL for the callback - The client will NOT be notified
370 * of the default values picked on its behalf, and the client will NOT be notified of any
371 * asynchronous errors (e.g. out of memory errors, etc.) that may prevent the registration
372 * of the service. The client may NOT pass the NoAutoRename flag if the callback is NULL.
373 * The client may still deregister the service at any time via DNSServiceRefDeallocate().
375 * context: An application context pointer which is passed to the callback function
378 * return value: Returns kDNSServiceErr_NoError on succeses (any subsequent, asynchronous
379 * errors are delivered to the callback), otherwise returns an error code indicating
380 * the error that occurred (the callback is never invoked and the DNSServiceRef
381 * is not initialized.)
385 DNSServiceErrorType DNSServiceRegister
387 DNSServiceRef
*sdRef
,
388 DNSServiceFlags flags
,
389 uint32_t interfaceIndex
,
390 const char *name
, /* may be NULL */
392 const char *domain
, /* may be NULL */
393 const char *host
, /* may be NULL */
396 const void *txtRecord
, /* may be NULL */
397 DNSServiceRegisterReply callBack
, /* may be NULL */
398 void *context
/* may be NULL */
401 /* DNSServiceAddRecord()
403 * Add a record to a registered service. The name of the record will be the same as the
404 * registered service's name.
405 * The record can later be updated or deregistered by passing the RecordRef initialized
406 * by this function to DNSServiceUpdateRecord() or DNSServiceRemoveRecord().
411 * sdRef: A DNSServiceRef initialized by DNSServiceRegister().
413 * RecordRef: A pointer to an uninitialized DNSRecordRef. Upon succesfull completion of this
414 * call, this ref may be passed to DNSServiceUpdateRecord() or DNSServiceRemoveRecord().
415 * If the above DNSServiceRef is passed to DNSServiceRefDeallocate(), RecordRef is also
416 * invalidated and may not be used further.
418 * flags: Currently ignored, reserved for future use.
420 * rrtype: The type of the record (e.g. TXT, SRV, etc), as defined in nameser.h.
422 * rdlen: The length, in bytes, of the rdata.
424 * rdata: The raw rdata to be contained in the added resource record.
426 * ttl: The time to live of the resource record, in seconds.
428 * return value: Returns kDNSServiceErr_NoError on success, otherwise returns an
429 * error code indicating the error that occurred (the RecordRef is not initialized).
432 DNSServiceErrorType DNSServiceAddRecord
435 DNSRecordRef
*RecordRef
,
436 DNSServiceFlags flags
,
443 /* DNSServiceUpdateRecord
445 * Update a registered resource record. The record must either be:
446 * - The primary txt record of a service registered via DNSServiceRegister()
447 * - A record added to a registered service via DNSServiceAddRecord()
448 * - An individual record registered by DNSServiceRegisterRecord()
453 * sdRef: A DNSServiceRef that was initialized by DNSServiceRegister()
454 * or DNSServiceCreateConnection().
456 * RecordRef: A DNSRecordRef initialized by DNSServiceAddRecord, or NULL to update the
457 * service's primary txt record.
459 * flags: Currently ignored, reserved for future use.
461 * rdlen: The length, in bytes, of the new rdata.
463 * rdata: The new rdata to be contained in the updated resource record.
465 * ttl: The time to live of the updated resource record, in seconds.
467 * return value: Returns kDNSServiceErr_NoError on success, otherwise returns an
468 * error code indicating the error that occurred.
471 DNSServiceErrorType DNSServiceUpdateRecord
474 DNSRecordRef RecordRef
, /* may be NULL */
475 DNSServiceFlags flags
,
481 /* DNSServiceRemoveRecord
483 * Remove a record previously added to a service record set via DNSServiceAddRecord(), or deregister
484 * an record registered individually via DNSServiceRegisterRecord().
488 * sdRef: A DNSServiceRef initialized by DNSServiceRegister() (if the
489 * record being removed was registered via DNSServiceAddRecord()) or by
490 * DNSServiceCreateConnection() (if the record being removed was registered via
491 * DNSServiceRegisterRecord()).
493 * recordRef: A DNSRecordRef initialized by a successful call to DNSServiceAddRecord()
494 * or DNSServiceRegisterRecord().
496 * flags: Currently ignored, reserved for future use.
498 * return value: Returns kDNSServiceErr_NoError on success, otherwise returns an
499 * error code indicating the error that occurred.
502 DNSServiceErrorType DNSServiceRemoveRecord
505 DNSRecordRef RecordRef
,
506 DNSServiceFlags flags
510 /*********************************************************************************************
514 *********************************************************************************************/
517 /* Browse for instances of a service.
520 * DNSServiceBrowseReply() Parameters:
522 * sdRef: The DNSServiceRef initialized by DNSServiceBrowse().
524 * flags: Possible values are MoreComing and Add/Remove. See flag definitions
527 * interfaceIndex: The interface on which the service is advertised. This index should
528 * be passed to DNSServiceResolve() when resolving the service.
530 * errorCode: Will be kDNSServiceErr_NoError (0) on success, otherwise will
531 * indicate the failure that occurred. Other parameters are undefined if
532 * the errorCode is nonzero.
534 * serviceName: The service name discovered.
536 * regtype: The service type, as passed in to DNSServiceBrowse().
538 * domain: The domain on which the service was discovered (if the application did not
539 * specify a domain in DNSServicBrowse(), this indicates the domain on which the
540 * service was discovered.)
542 * context: The context pointer that was passed to the callout.
546 typedef void (*DNSServiceBrowseReply
)
549 DNSServiceFlags flags
,
550 uint32_t interfaceIndex
,
551 DNSServiceErrorType errorCode
,
552 const char *serviceName
,
554 const char *replyDomain
,
558 /* DNSServiceBrowse() Parameters:
560 * sdRef: A pointer to an uninitialized sdRef. May be passed to
561 * DNSServiceRefDeallocate() to terminate the browse.
563 * flags: Currently ignored, reserved for future use.
565 * interfaceIndex: If non-zero, specifies the interface on which to browse for services
566 * (the index for a given interface is determined via the if_nametoindex()
567 * family of calls.) Most applications will pass 0 to browse on all available
568 * interfaces. Pass -1 to only browse for services provided on the local host.
570 * regtype: The service type being browsed for followed by the protocol, separated by a
571 * dot (e.g. "_ftp._tcp"). The transport protocol must be "_tcp" or "_udp".
573 * domain: If non-NULL, specifies the domain on which to browse for services.
574 * Most applications will not specify a domain, instead browsing on the
577 * callBack: The function to be called when an instance of the service being browsed for
578 * is found, or if the call asynchronously fails.
580 * context: An application context pointer which is passed to the callback function
583 * return value: Returns kDNSServiceErr_NoError on succeses (any subsequent, asynchronous
584 * errors are delivered to the callback), otherwise returns an error code indicating
585 * the error that occurred (the callback is not invoked and the DNSServiceRef
586 * is not initialized.)
589 DNSServiceErrorType DNSServiceBrowse
591 DNSServiceRef
*sdRef
,
592 DNSServiceFlags flags
,
593 uint32_t interfaceIndex
,
595 const char *domain
, /* may be NULL */
596 DNSServiceBrowseReply callBack
,
597 void *context
/* may be NULL */
600 /* DNSServiceResolve()
602 * Resolve a service name discovered via DNSServiceBrowse() to a target host name, port number, and
605 * Note: Applications should NOT use DNSServiceResolve() solely for txt record monitoring - use
606 * DNSServiceQueryRecord() instead, as it is more efficient for this task.
608 * Note: When the desired results have been returned, the client MUST terminate the resolve by calling
609 * DNSServiceRefDeallocate().
611 * Note: DNSServiceResolve() behaves correctly for typical services that have a single SRV record and
612 * a single TXT record (the TXT record may be empty.) To resolve non-standard services with multiple
613 * SRV or TXT records, DNSServiceQueryRecord() should be used.
615 * DNSServiceResolveReply Callback Parameters:
617 * sdRef: The DNSServiceRef initialized by DNSServiceResolve().
619 * flags: Currently unused, reserved for future use.
621 * interfaceIndex: The interface on which the service was resolved.
623 * errorCode: Will be kDNSServiceErr_NoError (0) on success, otherwise will
624 * indicate the failure that occurred. Other parameters are undefined if
625 * the errorCode is nonzero.
627 * fullname: The full service domain name, in the form <servicename>.<protocol>.<domain>.
628 * (Any literal dots (".") are escaped with a backslash ("\."), and literal
629 * backslashes are escaped with a second backslash ("\\"), e.g. a web server
630 * named "Dr. Pepper" would have the fullname "Dr\.\032Pepper._http._tcp.local.").
631 * This is the appropriate format to pass to standard system DNS APIs such as
632 * res_query(), or to the special-purpose functions included in this API that
633 * take fullname parameters.
635 * hosttarget: The target hostname of the machine providing the service. This name can
636 * be passed to functions like gethostbyname() to identify the host's IP address.
638 * port: The port number on which connections are accepted for this service.
640 * txtLen: The length of the txt record, in bytes.
642 * txtRecord: The service's primary txt record, in standard txt record format.
645 * context: The context pointer that was passed to the callout.
649 typedef void (*DNSServiceResolveReply
)
652 DNSServiceFlags flags
,
653 uint32_t interfaceIndex
,
654 DNSServiceErrorType errorCode
,
655 const char *fullname
,
656 const char *hosttarget
,
659 const char *txtRecord
,
663 /* DNSServiceResolve() Parameters
665 * sdRef: A pointer to an uninitialized sdRef. May be passed to
666 * DNSServiceRefDeallocate() to terminate the resolve.
668 * flags: Currently ignored, reserved for future use.
670 * interfaceIndex: The interface on which to resolve the service. The client should
671 * pass the interface on which the servicename was discovered, i.e.
672 * the interfaceIndex passed to the DNSServiceBrowseReply callback,
673 * or 0 to resolve the named service on all available interfaces.
675 * name: The servicename to be resolved.
677 * regtype: The service type being resolved followed by the protocol, separated by a
678 * dot (e.g. "_ftp._tcp"). The transport protocol must be "_tcp" or "_udp".
680 * domain: The domain on which the service is registered, i.e. the domain passed
681 * to the DNSServiceBrowseReply callback.
683 * callBack: The function to be called when a result is found, or if the call
684 * asynchronously fails.
686 * context: An application context pointer which is passed to the callback function
689 * return value: Returns kDNSServiceErr_NoError on succeses (any subsequent, asynchronous
690 * errors are delivered to the callback), otherwise returns an error code indicating
691 * the error that occurred (the callback is never invoked and the DNSServiceRef
692 * is not initialized.)
696 DNSServiceErrorType DNSServiceResolve
698 DNSServiceRef
*sdRef
,
699 DNSServiceFlags flags
,
700 uint32_t interfaceIndex
,
704 DNSServiceResolveReply callBack
,
705 void *context
/* may be NULL */
709 /*********************************************************************************************
711 * Special Purpose Calls (most applications will not use these)
713 *********************************************************************************************/
715 /* DNS Naming Conventions:
717 * The following functions refer to resource records by their full domain name, unlike the above
718 * functions which divide the name into servicename/regtype/domain fields. In the above functions,
719 * a dot (".") is considered to be a literal dot in the servicename field (e.g. "Dr. Pepper") and
720 * a label separator in the regtype ("_ftp._tcp") or domain ("apple.com") fields. Literal dots in
721 * the domain field would be escaped with a backslash, and literal backslashes would be escaped with
722 * a second backslash (this is generally not an issue, as domain names on the Internet today almost
723 * never use characters other than letters, digits, or hyphens, and the dots are label separators.)
724 * Furthermore, this is transparent to the caller, so long as the fields are passed between functions
725 * without manipulation. However, the following, special-purpose calls use a single, full domain name.
726 * As such, all dots are considered to be label separators, unless escaped, and all backslashes are
727 * considered to be escape characters, unless preceded by a second backslash. For example, the name
728 * "Dr. Smith \ Dr. Johnson" could be passed literally as a service name parameter in the above calls,
729 * but in the special purpose call, the dots and backslash would have to be escaped
730 * (e.g. "Dr\. Smith \\ Dr\. Johnson._ftp._tcp.apple.com" for an ftp service on the apple.com domain.)
733 /* DNSServiceConstructFullName()
735 * Concatenate a three-part domain name (as returned by the above callbacks) into a properly-escaped
736 * full domain name. Note that callbacks in the above functions ALREADY ESCAPE strings where necessary.
740 * fullName: A pointer to a buffer that where the resulting full domain name is to be written.
741 * The buffer must be kDNSServiceDiscoveryMaxDomainName (1005) bytes in length to
742 * accommodate the longest legal domain name without buffer overrun.
744 * service: The service name - any dots or slashes must NOT be escaped.
745 * May be NULL (to construct a PTR record name, e.g.
746 * "_ftp._tcp.apple.com").
748 * regtype: The service type followed by the protocol, separated by a dot
749 * (e.g. "_ftp._tcp").
751 * domain: The domain name, e.g. "apple.com". Any literal dots or backslashes
754 * return value: Returns 0 on success, -1 on error.
758 int DNSServiceConstructFullName
761 const char *service
, /* may be NULL */
766 /* DNSServiceCreateConnection()
768 * Create a connection to the daemon allowing efficient registration of
769 * multiple individual records.
774 * sdRef: A pointer to an uninitialized DNSServiceRef. Deallocating
775 * the reference (via DNSServiceRefDeallocate()) severs the
776 * connection and deregisters all records registered on this connection.
778 * return value: Returns kDNSServiceErr_NoError on success, otherwise returns
779 * an error code indicating the specific failure that occurred (in which
780 * case the DNSServiceRef is not initialized).
783 DNSServiceErrorType
DNSServiceCreateConnection(DNSServiceRef
*sdRef
);
786 /* DNSServiceRegisterRecord
788 * Register an individual resource record on a connected DNSServiceRef.
790 * Note that name conflicts occurring for records registered via this call must be handled
791 * by the client in the callback.
794 * DNSServiceRegisterRecordReply() parameters:
796 * sdRef: The connected DNSServiceRef initialized by
797 * DNSServiceDiscoveryConnect().
799 * RecordRef: The DNSRecordRef initialized by DNSServiceRegisterRecord(). If the above
800 * DNSServiceRef is passed to DNSServiceRefDeallocate(), this DNSRecordRef is
801 * invalidated, and may not be used further.
803 * flags: Currently unused, reserved for future use.
805 * errorCode: Will be kDNSServiceErr_NoError on success, otherwise will
806 * indicate the failure that occurred (including name conflicts.)
807 * Other parameters are undefined if errorCode is nonzero.
809 * context: The context pointer that was passed to the callout.
813 typedef void (*DNSServiceRegisterRecordReply
)
816 DNSRecordRef RecordRef
,
817 DNSServiceFlags flags
,
818 DNSServiceErrorType errorCode
,
823 /* DNSServiceRegisterRecord() Parameters:
825 * sdRef: A DNSServiceRef initialized by DNSServiceCreateConnection().
827 * RecordRef: A pointer to an uninitialized DNSRecordRef. Upon succesfull completion of this
828 * call, this ref may be passed to DNSServiceUpdateRecord() or DNSServiceRemoveRecord().
829 * (To deregister ALL records registered on a single connected DNSServiceRef
830 * and deallocate each of their corresponding DNSServiceRecordRefs, call
831 * DNSServiceRefDealloocate()).
833 * flags: Possible values are Shared/Unique (see flag type definitions for details).
835 * interfaceIndex: If non-zero, specifies the interface on which to register the record
836 * (the index for a given interface is determined via the if_nametoindex()
837 * family of calls.) Passing 0 causes the record to be registered on all interfaces.
838 * Passing -1 causes the record to only be visible on the local host.
840 * fullname: The full domain name of the resource record.
842 * rrtype: The numerical type of the resource record (e.g. PTR, SRV, etc), as defined
845 * rrclass: The class of the resource record, as defined in nameser.h (usually 1 for the
848 * rdlen: Length, in bytes, of the rdata.
850 * rdata: A pointer to the raw rdata, as it is to appear in the DNS record.
852 * ttl: The time to live of the resource record, in seconds.
854 * callBack: The function to be called when a result is found, or if the call
855 * asynchronously fails (e.g. because of a name conflict.)
857 * context: An application context pointer which is passed to the callback function
860 * return value: Returns kDNSServiceErr_NoError on succeses (any subsequent, asynchronous
861 * errors are delivered to the callback), otherwise returns an error code indicating
862 * the error that occurred (the callback is never invoked and the DNSRecordRef is
867 DNSServiceErrorType DNSServiceRegisterRecord
870 DNSRecordRef
*RecordRef
,
871 DNSServiceFlags flags
,
872 uint32_t interfaceIndex
,
873 const char *fullname
,
879 DNSServiceRegisterRecordReply callBack
,
880 void *context
/* may be NULL */
884 /* DNSServiceQueryRecord
886 * Query for an arbitrary DNS record.
889 * DNSServiceQueryRecordReply() Callback Parameters:
891 * sdRef: The DNSServiceRef initialized by DNSServiceQueryRecord().
893 * flags: Possible values are Finished/MoreComing.
895 * interfaceIndex: The interface on which the query was resolved (the index for a given
896 * interface is determined via the if_nametoindex() family of calls).
898 * errorCode: Will be kDNSServiceErr_NoError on success, otherwise will
899 * indicate the failure that occurred. Other parameters are undefined if
900 * errorCode is nonzero.
902 * fullname: The resource record's full domain name.
904 * rrtype: The resource record's type (e.g. PTR, SRV, etc) as defined in nameser.h.
906 * rrclass: The class of the resource record, as defined in nameser.h (usually 1).
908 * rdlen: The length, in bytes, of the resource record rdata.
910 * rdata: The raw rdata of the resource record.
912 * ttl: The resource record's time to live, in seconds.
914 * context: The context pointer that was passed to the callout.
918 typedef void (*DNSServiceQueryRecordReply
)
920 DNSServiceRef DNSServiceRef
,
921 DNSServiceFlags flags
,
922 uint32_t interfaceIndex
,
923 DNSServiceErrorType errorCode
,
924 const char *fullname
,
933 /* DNSServiceQueryRecord() Parameters:
935 * sdRef: A pointer to an uninitialized DNSServiceRef.
937 * flags: Currently unused, reserved for future use.
939 * interfaceIndex: If non-zero, specifies the interface on which to issue the query
940 * (the index for a given interface is determined via the if_nametoindex()
941 * family of calls.) Passing 0 causes the name to be queried for on all
942 * interfaces. Passing -1 causes the name to be queried for only on the
945 * fullname: The full domain name of the resource record to be queried for.
947 * rrtype: The numerical type of the resource record to be queried for (e.g. PTR, SRV, etc)
948 * as defined in nameser.h.
950 * rrclass: The class of the resource record, as defined in nameser.h
951 * (usually 1 for the Internet class).
953 * callBack: The function to be called when a result is found, or if the call
954 * asynchronously fails.
956 * context: An application context pointer which is passed to the callback function
959 * return value: Returns kDNSServiceErr_NoError on succeses (any subsequent, asynchronous
960 * errors are delivered to the callback), otherwise returns an error code indicating
961 * the error that occurred (the callback is never invoked and the DNSServiceRef
962 * is not initialized.)
965 DNSServiceErrorType DNSServiceQueryRecord
967 DNSServiceRef
*sdRef
,
968 DNSServiceFlags flags
,
969 uint32_t interfaceIndex
,
970 const char *fullname
,
973 DNSServiceQueryRecordReply callBack
,
974 void *context
/* may be NULL */
977 /* DNSServiceReconfirmRecord
979 * Instruct the daemon to verify the validity of a resource record that appears to
980 * be out of date (e.g. because tcp connection to a service's target failed.)
981 * Causes the record to be flushed from the daemon's cache (as well as all other
982 * daemons' caches on the network) if the record is determined to be invalid.
986 * flags: Currently unused, reserved for future use.
988 * fullname: The resource record's full domain name.
990 * rrtype: The resource record's type (e.g. PTR, SRV, etc) as defined in nameser.h.
992 * rrclass: The class of the resource record, as defined in nameser.h (usually 1).
994 * rdlen: The length, in bytes, of the resource record rdata.
996 * rdata: The raw rdata of the resource record.
1000 void DNSServiceReconfirmRecord
1002 DNSServiceFlags flags
,
1003 uint32_t interfaceIndex
,
1004 const char *fullname
,