2 * Copyright (c) 2003 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.2 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
20 * @APPLE_LICENSE_HEADER_END@
26 #include <sys/types.h>
27 #include <sys/socket.h>
29 #include <netinet/in.h>
32 /* DNSServiceRef, DNSRecordRef
34 * Opaque internal data types.
35 * Note: client is responsible for serializing access to these structures if
36 * they are shared between concurrent threads.
39 typedef struct _DNSServiceRef_t
*DNSServiceRef
;
40 typedef struct _DNSRecordRef_t
*DNSRecordRef
;
42 /* General flags used in functions defined below */
45 kDNSServiceFlagsMoreComing
= 1,
46 kDNSServiceFlagsFinished
= 0, /* i.e. bit not set */
47 /* MoreComing indicates to a Browse callback that another result is
48 * queued. Applications should not update their UI to display browse
49 * results when the MoreComing flag is set, instead deferring the update
50 * until the callback's flag is Finished. */
52 kDNSServiceFlagsAdd
= 2,
53 kDNSServiceFlagsDefault
= 4,
54 kDNSServiceFlagsRemove
= 0, /* i.e. bit not set */
55 /* Flags for domain enumeration and browse reply callbacks.
56 * "Default" applies only to enumeration and is only valid in
57 * conjuction with "Add"
60 kDNSServiceFlagsNoAutoRename
= 8,
61 kDNSServiceFlagsAutoRename
= 0, /* i.e. bit not set */
62 /* Flag for specifying renaming behavior on name conflict when registering
63 * non-shared records. NoAutorename is only valid if a name is explicitly
64 * specified when registering a service (ie the default name is not used.)
68 kDNSServiceFlagsShared
= 16,
69 kDNSServiceFlagsUnique
= 32,
70 /* Flag for registering individual records on a connected
71 * DNSServiceRef. Shared indicates that there may be multiple records
72 * with this name on the network (e.g. PTR records). Unique indicates that the
73 * record's name is to be unique on the network (e.g. SRV records).
76 kDNSServiceFlagsBrowseDomains
= 64,
77 kDNSServiceFlagsRegistrationDomains
= 128
78 /* Flags for specifying domain enumeration type in DNSServiceEnumerateDomains.
79 * BrowseDomains enumerates domains recommended for browsing, RegistrationDomains
80 * enumerates domains recommended for registration.
84 /* possible error code values */
87 kDNSServiceErr_NoError
= 0,
88 kDNSServiceErr_Unknown
= -65537, /* 0xFFFE FFFF */
89 kDNSServiceErr_NoSuchName
= -65538,
90 kDNSServiceErr_NoMemory
= -65539,
91 kDNSServiceErr_BadParam
= -65540,
92 kDNSServiceErr_BadReference
= -65541,
93 kDNSServiceErr_BadState
= -65542,
94 kDNSServiceErr_BadFlags
= -65543,
95 kDNSServiceErr_Unsupported
= -65544,
96 kDNSServiceErr_NotInitialized
= -65545,
97 kDNSServiceErr_AlreadyRegistered
= -65547,
98 kDNSServiceErr_NameConflict
= -65548,
99 kDNSServiceErr_Invalid
= -65549,
100 kDNSServiceErr_Incompatible
= -65551, /* client library incompatible with daemon */
101 kDNSServiceErr_BadinterfaceIndex
= -65552
102 /* mDNS Error codes are in the range
103 * FFFE FF00 (-65792) to FFFE FFFF (-65537) */
107 /* Maximum length, in bytes, of a domain name represented as an escaped C-String */
108 #define kDNSServiceMaxDomainName 1005
111 typedef uint32_t DNSServiceFlags
;
112 typedef int32_t DNSServiceErrorType
;
115 /*********************************************************************************************
117 * Unix Domain Socket access, DNSServiceRef deallocation, and data processing functions
119 *********************************************************************************************/
122 /* DNSServiceRefSockFD()
124 * Access underlying Unix domain socket for an initialized DNSServiceRef.
125 * The DNS Service Discovery implmementation uses this socket to communicate between
126 * the client and the mDNSResponder daemon. The application MUST NOT directly read from
127 * or write to this socket. Access to the socket is provided so that it can be used as a
128 * run loop source, or in a select() loop: when data is available for reading on the socket,
129 * DNSServiceProcessResult() should be called, which will extract the daemon's reply from
130 * the socket, and pass it to the appropriate application callback. By using a run loop or
131 * select(), results from the daemon can be processed asynchronously. Without using these
132 * constructs, DNSServiceProcessResult() will block until the response from the daemon arrives.
133 * The client is responsible for ensuring that the data on the socket is processed in a timely
134 * fashion - the daemon may terminate its connection with a client that does not clear its
137 * sdRef: A DNSServiceRef initialized by any of the DNSService calls.
139 * return value: The DNSServiceRef's underlying socket descriptor, or -1 on
143 int DNSServiceRefSockFD(DNSServiceRef sdRef
);
145 /* DNSServiceProcessResult()
147 * Read a reply from the daemon, calling the appropriate application callback. This call will
148 * block until the daemon's response is received. Use DNSServiceRefSockFD() in
149 * conjunction with a run loop or select() to determine the presence of a response from the
150 * server before calling this function to process the reply without blocking. Call this function
151 * at any point if it is acceptable to block until the daemon's response arrives. Note that the
152 * client is responsible for ensuring that DNSServiceProcessResult() is called whenever there is
153 * a reply from the daemon - the daemon may terminate its connection with a client that does not
154 * process the daemon's responses.
156 * sdRef: A DNSServiceRef initialized by any of the DNSService calls
157 * that take a callback parameter.
159 * return value: Returns kDNSServiceErr_NoError on success, otherwise returns
160 * an error code indicating the specific failure that occurred.
163 DNSServiceErrorType
DNSServiceProcessResult(DNSServiceRef sdRef
);
165 /* DNSServiceRefDeallocate()
167 * Terminate a connection with the daemon and free memory associated with the DNSServiceRef.
168 * Any services or records registered with this DNSServiceRef will be deregistered. Any
169 * Browse, Resolve, or Query operations called with this reference will be terminated.
171 * Note: If the reference's underlying socket is used in a run loop or select() call, it should
172 * be removed BEFORE DNSServiceRefDeallocate() is called, as this function closes the reference's
175 * Note: If the reference was initialized with DNSServiceCreateConnection(), any DNSRecordRefs
176 * created via this reference will be invalidated by this call - the resource records are
177 * deregistered, and their DNSRecordRefs may not be used in subsequent functions. Similarly,
178 * if the reference was initialized with DNSServiceRegister, and an extra resource record was
179 * added to the service via DNSServiceAddRecord(), the DNSRecordRef created by the Add() call
180 * is invalidated when this function is called - the DNSRecordRef may not be used in subsequent
183 * Note: This call is to be used only with the DNSServiceRef defined by this API. It is
184 * not compatible with dns_service_discovery_ref objects defined in the legacy Mach-based
185 * DNSServiceDiscovery.h API.
187 * sdRef: A DNSServiceRef initialized by any of the DNSService calls.
191 void DNSServiceRefDeallocate(DNSServiceRef sdRef
);
194 /*********************************************************************************************
198 *********************************************************************************************/
200 /* DNSServiceEnumerateDomains()
202 * Asynchronously enumerate domains available for browsing and registration.
203 * Currently, the only domain returned is "local.", but other domains will be returned in future.
205 * The enumeration MUST be cancelled via DNSServiceRefDeallocate() when no more domains
209 * DNSServiceDomainEnumReply Callback Parameters:
211 * sdRef: The DNSServiceRef initialized by DNSServiceEnumerateDomains().
213 * flags: Possible values are:
218 * interfaceIndex: Specifies the interface on which the domain exists. (The index for a given
219 * interface is determined via the if_nametoindex() family of calls.)
221 * errorCode: Will be kDNSServiceErr_NoError (0) on success, otherwise indicates
222 * the failure that occurred (other parameters are undefined if errorCode is nonzero).
224 * replyDomain: The name of the domain.
226 * context: The context pointer passed to DNSServiceEnumerateDomains.
230 typedef void (*DNSServiceDomainEnumReply
)
233 DNSServiceFlags flags
,
234 uint32_t interfaceIndex
,
235 DNSServiceErrorType errorCode
,
236 const char *replyDomain
,
240 /* DNSServiceEnumerateDomains() Parameters:
243 * sdRef: A pointer to an uninitialized sdRef. May be passed to
244 * DNSServiceRefDeallocate() to cancel the enumeration.
246 * flags: Possible values are:
247 * 0 (BrowseDomains) to enumerate domains recommended for browsing.
248 * 32 (RegistrationDomains) to enumerate domains recommended for registration.
250 * interfaceIndex: If non-zero, specifies the interface on which to look for domains.
251 * (the index for a given interface is determined via the if_nametoindex()
252 * family of calls.) Most applications will pass 0 to enumerate domains on
255 * callBack: The function to be called when a domain is found or the call asynchronously
258 * context: An application context pointer which is passed to the callback function
261 * return value: Returns kDNSServiceErr_NoError on succeses (any subsequent, asynchronous
262 * errors are delivered to the callback), otherwise returns an error code indicating
263 * the error that occurred (the callback is not invoked and the DNSServiceRef
264 * is not initialized.)
267 DNSServiceErrorType DNSServiceEnumerateDomains
269 DNSServiceRef
*sdRef
,
270 DNSServiceFlags flags
,
271 uint32_t interfaceIndex
,
272 DNSServiceDomainEnumReply callBack
,
273 void *context
/* may be NULL */
276 /*********************************************************************************************
278 * Service Registration
280 *********************************************************************************************/
282 /* Register a service that is discovered via Browse() and Resolve() calls.
285 * DNSServiceRegisterReply() Callback Parameters:
287 * sdRef: The DNSServiceRef initialized by DNSServiceRegister().
289 * flags: Currently unused, reserved for future use.
291 * errorCode: Will be kDNSServiceErr_NoError on success, otherwise will
292 * indicate the failure that occurred (including name conflicts, if the
293 * kDNSServiceFlagsNoAutoRenameOnConflict flag was passed to the
294 * callout.) Other parameters are undefined if errorCode is nonzero.
296 * name: The service name registered (if the application did not specify a name in
297 * DNSServiceRegister(), this indicates what name was automatically chosen).
299 * regtype: The type of service registered, as it was passed to the callout.
301 * domain: The domain on which the service was registered (if the application did not
302 * specify a domain in DNSServiceRegister(), this indicates the default domain
303 * on which the service was registered).
305 * context: The context pointer that was passed to the callout.
309 typedef void (*DNSServiceRegisterReply
)
312 DNSServiceFlags flags
,
313 DNSServiceErrorType errorCode
,
320 /* DNSServiceRegister() Parameters:
322 * sdRef: A pointer to an uninitialized sdRef. If this call succeeds, the reference
324 * DNSServiceRefDeallocate() to deregister the service.
326 * interfaceIndex: If non-zero, specifies the interface on which to register the service
327 * (the index for a given interface is determined via the if_nametoindex()
328 * family of calls.) Most applications will pass 0 to register on all
329 * available interfaces. Pass -1 to register a service only on the local
330 * machine (service will not be visible to remote hosts.)
332 * flags: Indicates the renaming behavior on name conflict (most applications
333 * will pass 0). See flag definitions above for details.
335 * name: If non-NULL, specifies the service name to be registered.
336 * Most applications will not specify a name, in which case the
337 * computer name is used (this name is communicated to the client via
340 * regtype: The service type followed by the protocol, separated by a dot
341 * (e.g. "_ftp._tcp"). The transport protocol must be "_tcp" or "_udp".
343 * domain: If non-NULL, specifies the domain on which to advertise the service.
344 * Most applications will not specify a domain, instead automatically
345 * registering in the default domain(s).
347 * host: If non-NULL, specifies the SRV target host name. Most applications
348 * will not specify a host, instead automatically using the machine's
349 * default host name(s). Note that specifying a non-NULL host does NOT
350 * create an address record for that host - the application is responsible
351 * for ensuring that the appropriate address record exists, or creating it
352 * via DNSServiceRegisterRecord().
354 * port: The port on which the service accepts connections. Pass 0 for a
355 * "placeholder" service (i.e. a service that will not be discovered by
356 * browsing, but will cause a name conflict if another client tries to
357 * register that same name.) Most clients will not use placeholder services.
359 * txtLen: The length of the txtRecord, in bytes. Must be zero if the txtRecord is NULL.
361 * txtRecord: The txt record rdata. May be NULL. Note that a non-NULL txtRecord
362 * MUST be a properly formatted DNS TXT record, i.e. <length byte> <data>
363 * <length byte> <data> ...
365 * callBack: The function to be called when the registration completes or asynchronously
366 * fails. The client MAY pass NULL for the callback - The client will NOT be notified
367 * of the default values picked on its behalf, and the client will NOT be notified of any
368 * asynchronous errors (e.g. out of memory errors, etc.) that may prevent the registration
369 * of the service. The client may NOT pass the NoAutoRename flag if the callback is NULL.
370 * The client may still deregister the service at any time via DNSServiceRefDeallocate().
372 * context: An application context pointer which is passed to the callback function
375 * return value: Returns kDNSServiceErr_NoError on succeses (any subsequent, asynchronous
376 * errors are delivered to the callback), otherwise returns an error code indicating
377 * the error that occurred (the callback is never invoked and the DNSServiceRef
378 * is not initialized.)
382 DNSServiceErrorType DNSServiceRegister
384 DNSServiceRef
*sdRef
,
385 DNSServiceFlags flags
,
386 uint32_t interfaceIndex
,
387 const char *name
, /* may be NULL */
389 const char *domain
, /* may be NULL */
390 const char *host
, /* may be NULL */
393 const void *txtRecord
, /* may be NULL */
394 DNSServiceRegisterReply callBack
, /* may be NULL */
395 void *context
/* may be NULL */
398 /* DNSServiceAddRecord()
400 * Add a record to a registered service. The name of the record will be the same as the
401 * registered service's name.
402 * The record can later be updated or deregistered by passing the RecordRef initialized
403 * by this function to DNSServiceUpdateRecord() or DNSServiceRemoveRecord().
408 * sdRef: A DNSServiceRef initialized by DNSServiceRegister().
410 * RecordRef: A pointer to an uninitialized DNSRecordRef. Upon succesfull completion of this
411 * call, this ref may be passed to DNSServiceUpdateRecord() or DNSServiceRemoveRecord().
412 * If the above DNSServiceRef is passed to DNSServiceRefDeallocate(), RecordRef is also
413 * invalidated and may not be used further.
415 * flags: Currently ignored, reserved for future use.
417 * rrtype: The type of the record (e.g. TXT, SRV, etc), as defined in nameser.h.
419 * rdlen: The length, in bytes, of the rdata.
421 * rdata: The raw rdata to be contained in the added resource record.
423 * ttl: The time to live of the resource record, in seconds.
425 * return value: Returns kDNSServiceErr_NoError on success, otherwise returns an
426 * error code indicating the error that occurred (the RecordRef is not initialized).
429 DNSServiceErrorType DNSServiceAddRecord
432 DNSRecordRef
*RecordRef
,
433 DNSServiceFlags flags
,
440 /* DNSServiceUpdateRecord
442 * Update a registered resource record. The record must either be:
443 * - The primary txt record of a service registered via DNSServiceRegister()
444 * - A record added to a registered service via DNSServiceAddRecord()
445 * - An individual record registered by DNSServiceRegisterRecord()
450 * sdRef: A DNSServiceRef that was initialized by DNSServiceRegister()
451 * or DNSServiceCreateConnection().
453 * RecordRef: A DNSRecordRef initialized by DNSServiceAddRecord, or NULL to update the
454 * service's primary txt record.
456 * flags: Currently ignored, reserved for future use.
458 * rdlen: The length, in bytes, of the new rdata.
460 * rdata: The new rdata to be contained in the updated resource record.
462 * ttl: The time to live of the updated resource record, in seconds.
464 * return value: Returns kDNSServiceErr_NoError on success, otherwise returns an
465 * error code indicating the error that occurred.
468 DNSServiceErrorType DNSServiceUpdateRecord
471 DNSRecordRef RecordRef
, /* may be NULL */
472 DNSServiceFlags flags
,
478 /* DNSServiceRemoveRecord
480 * Remove a record previously added to a service record set via DNSServiceAddRecord(), or deregister
481 * an record registered individually via DNSServiceRegisterRecord().
485 * sdRef: A DNSServiceRef initialized by DNSServiceRegister() (if the
486 * record being removed was registered via DNSServiceAddRecord()) or by
487 * DNSServiceCreateConnection() (if the record being removed was registered via
488 * DNSServiceRegisterRecord()).
490 * recordRef: A DNSRecordRef initialized by a successful call to DNSServiceAddRecord()
491 * or DNSServiceRegisterRecord().
493 * flags: Currently ignored, reserved for future use.
495 * return value: Returns kDNSServiceErr_NoError on success, otherwise returns an
496 * error code indicating the error that occurred.
499 DNSServiceErrorType DNSServiceRemoveRecord
502 DNSRecordRef RecordRef
,
503 DNSServiceFlags flags
507 /*********************************************************************************************
511 *********************************************************************************************/
514 /* Browse for instances of a service.
517 * DNSServiceBrowseReply() Parameters:
519 * sdRef: The DNSServiceRef initialized by DNSServiceBrowse().
521 * flags: Possible values are MoreComing and Add/Remove. See flag definitions
524 * interfaceIndex: The interface on which the service is advertised. This index should
525 * be passed to DNSServiceResolve() when resolving the service.
527 * errorCode: Will be kDNSServiceErr_NoError (0) on success, otherwise will
528 * indicate the failure that occurred. Other parameters are undefined if
529 * the errorCode is nonzero.
531 * serviceName: The service name discovered.
533 * regtype: The service type, as passed in to DNSServiceBrowse().
535 * domain: The domain on which the service was discovered (if the application did not
536 * specify a domain in DNSServicBrowse(), this indicates the domain on which the
537 * service was discovered.)
539 * context: The context pointer that was passed to the callout.
543 typedef void (*DNSServiceBrowseReply
)
546 DNSServiceFlags flags
,
547 uint32_t interfaceIndex
,
548 DNSServiceErrorType errorCode
,
549 const char *serviceName
,
551 const char *replyDomain
,
555 /* DNSServiceBrowse() Parameters:
557 * sdRef: A pointer to an uninitialized sdRef. May be passed to
558 * DNSServiceRefDeallocate() to terminate the browse.
560 * flags: Currently ignored, reserved for future use.
562 * interfaceIndex: If non-zero, specifies the interface on which to browse for services
563 * (the index for a given interface is determined via the if_nametoindex()
564 * family of calls.) Most applications will pass 0 to browse on all available
565 * interfaces. Pass -1 to only browse for services provided on the local host.
567 * regtype: The service type being browsed for followed by the protocol, separated by a
568 * dot (e.g. "_ftp._tcp"). The transport protocol must be "_tcp" or "_udp".
570 * domain: If non-NULL, specifies the domain on which to browse for services.
571 * Most applications will not specify a domain, instead browsing on the
574 * callBack: The function to be called when an instance of the service being browsed for
575 * is found, or if the call asynchronously fails.
577 * context: An application context pointer which is passed to the callback function
580 * return value: Returns kDNSServiceErr_NoError on succeses (any subsequent, asynchronous
581 * errors are delivered to the callback), otherwise returns an error code indicating
582 * the error that occurred (the callback is not invoked and the DNSServiceRef
583 * is not initialized.)
586 DNSServiceErrorType DNSServiceBrowse
588 DNSServiceRef
*sdRef
,
589 DNSServiceFlags flags
,
590 uint32_t interfaceIndex
,
592 const char *domain
, /* may be NULL */
593 DNSServiceBrowseReply callBack
,
594 void *context
/* may be NULL */
597 /* DNSServiceResolve()
599 * Resolve a service name discovered via DNSServiceBrowse() to a target host name, port number, and
602 * Note: Applications should NOT use DNSServiceResolve() solely for txt record monitoring - use
603 * DNSServiceQueryRecord() instead, as it is more efficient for this task.
605 * Note: When the desired results have been returned, the client MUST terminate the resolve by calling
606 * DNSServiceRefDeallocate().
608 * Note: DNSServiceResolve() behaves correctly for typical services that have a single SRV record and
609 * a single TXT record (the TXT record may be empty.) To resolve non-standard services with multiple
610 * SRV or TXT records, DNSServiceQueryRecord() should be used.
612 * DNSServiceResolveReply Callback Parameters:
614 * sdRef: The DNSServiceRef initialized by DNSServiceResolve().
616 * flags: Currently unused, reserved for future use.
618 * interfaceIndex: The interface on which the service was resolved.
620 * errorCode: Will be kDNSServiceErr_NoError (0) on success, otherwise will
621 * indicate the failure that occurred. Other parameters are undefined if
622 * the errorCode is nonzero.
624 * fullname: The full service domain name, in the form <servicename>.<protocol>.<domain>.
625 * (Any literal dots (".") are escaped with a backslash ("\."), and literal
626 * backslashes are escaped with a second backslash ("\\"), e.g. a web server
627 * named "Dr. Pepper" would have the fullname "Dr\.\032Pepper._http._tcp.local.").
628 * This is the appropriate format to pass to standard system DNS APIs such as
629 * res_query(), or to the special-purpose functions included in this API that
630 * take fullname parameters.
632 * hosttarget: The target hostname of the machine providing the service. This name can
633 * be passed to functions like gethostbyname() to identify the host's IP address.
635 * port: The port number on which connections are accepted for this service.
637 * txtLen: The length of the txt record, in bytes.
639 * txtRecord: The service's primary txt record, in standard txt record format.
642 * context: The context pointer that was passed to the callout.
646 typedef void (*DNSServiceResolveReply
)
649 DNSServiceFlags flags
,
650 uint32_t interfaceIndex
,
651 DNSServiceErrorType errorCode
,
652 const char *fullname
,
653 const char *hosttarget
,
656 const char *txtRecord
,
660 /* DNSServiceResolve() Parameters
662 * sdRef: A pointer to an uninitialized sdRef. May be passed to
663 * DNSServiceRefDeallocate() to terminate the resolve.
665 * flags: Currently ignored, reserved for future use.
667 * interfaceIndex: The interface on which to resolve the service. The client should
668 * pass the interface on which the servicename was discovered, i.e.
669 * the interfaceIndex passed to the DNSServiceBrowseReply callback,
670 * or 0 to resolve the named service on all available interfaces.
672 * name: The servicename to be resolved.
674 * regtype: The service type being resolved followed by the protocol, separated by a
675 * dot (e.g. "_ftp._tcp"). The transport protocol must be "_tcp" or "_udp".
677 * domain: The domain on which the service is registered, i.e. the domain passed
678 * to the DNSServiceBrowseReply callback.
680 * callBack: The function to be called when a result is found, or if the call
681 * asynchronously fails.
683 * context: An application context pointer which is passed to the callback function
686 * return value: Returns kDNSServiceErr_NoError on succeses (any subsequent, asynchronous
687 * errors are delivered to the callback), otherwise returns an error code indicating
688 * the error that occurred (the callback is never invoked and the DNSServiceRef
689 * is not initialized.)
693 DNSServiceErrorType DNSServiceResolve
695 DNSServiceRef
*sdRef
,
696 DNSServiceFlags flags
,
697 uint32_t interfaceIndex
,
701 DNSServiceResolveReply callBack
,
702 void *context
/* may be NULL */
706 /*********************************************************************************************
708 * Special Purpose Calls (most applications will not use these)
710 *********************************************************************************************/
712 /* DNS Naming Conventions:
714 * The following functions refer to resource records by their full domain name, unlike the above
715 * functions which divide the name into servicename/regtype/domain fields. In the above functions,
716 * a dot (".") is considered to be a literal dot in the servicename field (e.g. "Dr. Pepper") and
717 * a label separator in the regtype ("_ftp._tcp") or domain ("apple.com") fields. Literal dots in
718 * the domain field would be escaped with a backslash, and literal backslashes would be escaped with
719 * a second backslash (this is generally not an issue, as domain names on the Internet today almost
720 * never use characters other than letters, digits, or hyphens, and the dots are label separators.)
721 * Furthermore, this is transparent to the caller, so long as the fields are passed between functions
722 * without manipulation. However, the following, special-purpose calls use a single, full domain name.
723 * As such, all dots are considered to be label separators, unless escaped, and all backslashes are
724 * considered to be escape characters, unless preceded by a second backslash. For example, the name
725 * "Dr. Smith \ Dr. Johnson" could be passed literally as a service name parameter in the above calls,
726 * but in the special purpose call, the dots and backslash would have to be escaped
727 * (e.g. "Dr\. Smith \\ Dr\. Johnson._ftp._tcp.apple.com" for an ftp service on the apple.com domain.)
730 /* DNSServiceConstructFullName()
732 * Concatenate a three-part domain name (as returned by the above callbacks) into a properly-escaped
733 * full domain name. Note that callbacks in the above functions ALREADY ESCAPE strings where necessary.
737 * fullName: A pointer to a buffer that where the resulting full domain name is to be written.
738 * The buffer must be kDNSServiceDiscoveryMaxDomainName (1005) bytes in length to
739 * accommodate the longest legal domain name without buffer overrun.
741 * service: The service name - any dots or slashes must NOT be escaped.
742 * May be NULL (to construct a PTR record name, e.g.
743 * "_ftp._tcp.apple.com").
745 * regtype: The service type followed by the protocol, separated by a dot
746 * (e.g. "_ftp._tcp").
748 * domain: The domain name, e.g. "apple.com". Any literal dots or backslashes
751 * return value: Returns 0 on success, -1 on error.
755 int DNSServiceConstructFullName
758 const char *service
, /* may be NULL */
763 /* DNSServiceCreateConnection()
765 * Create a connection to the daemon allowing efficient registration of
766 * multiple individual records.
771 * sdRef: A pointer to an uninitialized DNSServiceRef. Deallocating
772 * the reference (via DNSServiceRefDeallocate()) severs the
773 * connection and deregisters all records registered on this connection.
775 * return value: Returns kDNSServiceErr_NoError on success, otherwise returns
776 * an error code indicating the specific failure that occurred (in which
777 * case the DNSServiceRef is not initialized).
780 DNSServiceErrorType
DNSServiceCreateConnection(DNSServiceRef
*sdRef
);
783 /* DNSServiceRegisterRecord
785 * Register an individual resource record on a connected DNSServiceRef.
787 * Note that name conflicts occurring for records registered via this call must be handled
788 * by the client in the callback.
791 * DNSServiceRegisterRecordReply() parameters:
793 * sdRef: The connected DNSServiceRef initialized by
794 * DNSServiceDiscoveryConnect().
796 * RecordRef: The DNSRecordRef initialized by DNSServiceRegisterRecord(). If the above
797 * DNSServiceRef is passed to DNSServiceRefDeallocate(), this DNSRecordRef is
798 * invalidated, and may not be used further.
800 * flags: Currently unused, reserved for future use.
802 * errorCode: Will be kDNSServiceErr_NoError on success, otherwise will
803 * indicate the failure that occurred (including name conflicts.)
804 * Other parameters are undefined if errorCode is nonzero.
806 * context: The context pointer that was passed to the callout.
810 typedef void (*DNSServiceRegisterRecordReply
)
813 DNSRecordRef RecordRef
,
814 DNSServiceFlags flags
,
815 DNSServiceErrorType errorCode
,
820 /* DNSServiceRegisterRecord() Parameters:
822 * sdRef: A DNSServiceRef initialized by DNSServiceCreateConnection().
824 * RecordRef: A pointer to an uninitialized DNSRecordRef. Upon succesfull completion of this
825 * call, this ref may be passed to DNSServiceUpdateRecord() or DNSServiceRemoveRecord().
826 * (To deregister ALL records registered on a single connected DNSServiceRef
827 * and deallocate each of their corresponding DNSServiceRecordRefs, call
828 * DNSServiceRefDealloocate()).
830 * flags: Possible values are Shared/Unique (see flag type definitions for details).
832 * interfaceIndex: If non-zero, specifies the interface on which to register the record
833 * (the index for a given interface is determined via the if_nametoindex()
834 * family of calls.) Passing 0 causes the record to be registered on all interfaces.
835 * Passing -1 causes the record to only be visible on the local host.
837 * fullname: The full domain name of the resource record.
839 * rrtype: The numerical type of the resource record (e.g. PTR, SRV, etc), as defined
842 * rrclass: The class of the resource record, as defined in nameser.h (usually 1 for the
845 * rdlen: Length, in bytes, of the rdata.
847 * rdata: A pointer to the raw rdata, as it is to appear in the DNS record.
849 * ttl: The time to live of the resource record, in seconds.
851 * callBack: The function to be called when a result is found, or if the call
852 * asynchronously fails (e.g. because of a name conflict.)
854 * context: An application context pointer which is passed to the callback function
857 * return value: Returns kDNSServiceErr_NoError on succeses (any subsequent, asynchronous
858 * errors are delivered to the callback), otherwise returns an error code indicating
859 * the error that occurred (the callback is never invoked and the DNSRecordRef is
864 DNSServiceErrorType DNSServiceRegisterRecord
867 DNSRecordRef
*RecordRef
,
868 DNSServiceFlags flags
,
869 uint32_t interfaceIndex
,
870 const char *fullname
,
876 DNSServiceRegisterRecordReply callBack
,
877 void *context
/* may be NULL */
881 /* DNSServiceQueryRecord
883 * Query for an arbitrary DNS record.
886 * DNSServiceQueryRecordReply() Callback Parameters:
888 * sdRef: The DNSServiceRef initialized by DNSServiceQueryRecord().
890 * flags: Possible values are Finished/MoreComing.
892 * interfaceIndex: The interface on which the query was resolved (the index for a given
893 * interface is determined via the if_nametoindex() family of calls).
895 * errorCode: Will be kDNSServiceErr_NoError on success, otherwise will
896 * indicate the failure that occurred. Other parameters are undefined if
897 * errorCode is nonzero.
899 * fullname: The resource record's full domain name.
901 * rrtype: The resource record's type (e.g. PTR, SRV, etc) as defined in nameser.h.
903 * rrclass: The class of the resource record, as defined in nameser.h (usually 1).
905 * rdlen: The length, in bytes, of the resource record rdata.
907 * rdata: The raw rdata of the resource record.
909 * ttl: The resource record's time to live, in seconds.
911 * context: The context pointer that was passed to the callout.
915 typedef void (*DNSServiceQueryRecordReply
)
917 DNSServiceRef DNSServiceRef
,
918 DNSServiceFlags flags
,
919 uint32_t interfaceIndex
,
920 DNSServiceErrorType errorCode
,
921 const char *fullname
,
930 /* DNSServiceQueryRecord() Parameters:
932 * sdRef: A pointer to an uninitialized DNSServiceRef.
934 * flags: Currently unused, reserved for future use.
936 * interfaceIndex: If non-zero, specifies the interface on which to issue the query
937 * (the index for a given interface is determined via the if_nametoindex()
938 * family of calls.) Passing 0 causes the name to be queried for on all
939 * interfaces. Passing -1 causes the name to be queried for only on the
942 * fullname: The full domain name of the resource record to be queried for.
944 * rrtype: The numerical type of the resource record to be queried for (e.g. PTR, SRV, etc)
945 * as defined in nameser.h.
947 * rrclass: The class of the resource record, as defined in nameser.h
948 * (usually 1 for the Internet class).
950 * callBack: The function to be called when a result is found, or if the call
951 * asynchronously fails.
953 * context: An application context pointer which is passed to the callback function
956 * return value: Returns kDNSServiceErr_NoError on succeses (any subsequent, asynchronous
957 * errors are delivered to the callback), otherwise returns an error code indicating
958 * the error that occurred (the callback is never invoked and the DNSServiceRef
959 * is not initialized.)
962 DNSServiceErrorType DNSServiceQueryRecord
964 DNSServiceRef
*sdRef
,
965 DNSServiceFlags flags
,
966 uint32_t interfaceIndex
,
967 const char *fullname
,
970 DNSServiceQueryRecordReply callBack
,
971 void *context
/* may be NULL */
974 /* DNSServiceReconfirmRecord
976 * Instruct the daemon to verify the validity of a resource record that appears to
977 * be out of date (e.g. because tcp connection to a service's target failed.)
978 * Causes the record to be flushed from the daemon's cache (as well as all other
979 * daemons' caches on the network) if the record is determined to be invalid.
983 * flags: Currently unused, reserved for future use.
985 * fullname: The resource record's full domain name.
987 * rrtype: The resource record's type (e.g. PTR, SRV, etc) as defined in nameser.h.
989 * rrclass: The class of the resource record, as defined in nameser.h (usually 1).
991 * rdlen: The length, in bytes, of the resource record rdata.
993 * rdata: The raw rdata of the resource record.
997 void DNSServiceReconfirmRecord
999 DNSServiceFlags flags
,
1000 uint32_t interfaceIndex
,
1001 const char *fullname
,