1 /* -*- Mode: C; tab-width: 4 -*-
3 * Copyright (c) 2002 Apple Computer, Inc. All rights reserved.
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
18 /*! @header DNS Service Discovery (Deprecated Mach-based API)
20 * @discussion This section describes the functions, callbacks, and data structures that
21 * make up the DNS Service Discovery API.
23 * The DNS Service Discovery API is part of Bonjour, Apple's implementation of
24 * zero-configuration networking (ZEROCONF).
26 * Bonjour allows you to register a network service, such as a
27 * printer or file server, so that it can be found by name or browsed
28 * for by service type and domain. Using Bonjour, applications can
29 * discover what services are available on the network, along with
30 * all necessary access information-such as name, IP address, and port
31 * number-for a given service.
33 * In effect, Bonjour combines the functions of a local DNS server
34 * and AppleTalk. Bonjour allows applications to provide user-friendly printer
35 * and server browsing, among other things, over standard IP networks.
36 * This behavior is a result of combining protocols such as multicast and DNS
37 * to add new functionality to the network (such as multicast DNS).
39 * Bonjour gives applications easy access to services over local IP
40 * networks without requiring the service or the application to support
41 * an AppleTalk or a Netbeui stack, and without requiring a DNS server
42 * for the local network.
44 * Note that this API was deprecated in Mac OS X 10.3, and replaced
45 * by the portable cross-platform /usr/include/dns_sd.h API.
48 #ifndef __DNS_SERVICE_DISCOVERY_H
49 #define __DNS_SERVICE_DISCOVERY_H
51 #include <mach/mach_types.h>
53 #include <sys/types.h>
54 #include <sys/socket.h>
55 #include <sys/cdefs.h>
57 #include <netinet/in.h>
59 #include <AvailabilityMacros.h>
63 /* Opaque internal data type */
64 typedef struct _dns_service_discovery_t
* dns_service_discovery_ref
;
66 /* possible reply flags values */
69 kDNSServiceDiscoveryNoFlags
= 0,
70 kDNSServiceDiscoveryMoreRepliesImmediately
= 1 << 0,
74 /* possible error code values */
77 kDNSServiceDiscoveryWaiting
= 1,
78 kDNSServiceDiscoveryNoError
= 0,
79 // mDNS Error codes are in the range
80 // FFFE FF00 (-65792) to FFFE FFFF (-65537)
81 kDNSServiceDiscoveryUnknownErr
= -65537, // 0xFFFE FFFF
82 kDNSServiceDiscoveryNoSuchNameErr
= -65538,
83 kDNSServiceDiscoveryNoMemoryErr
= -65539,
84 kDNSServiceDiscoveryBadParamErr
= -65540,
85 kDNSServiceDiscoveryBadReferenceErr
= -65541,
86 kDNSServiceDiscoveryBadStateErr
= -65542,
87 kDNSServiceDiscoveryBadFlagsErr
= -65543,
88 kDNSServiceDiscoveryUnsupportedErr
= -65544,
89 kDNSServiceDiscoveryNotInitializedErr
= -65545,
90 kDNSServiceDiscoveryNoCache
= -65546,
91 kDNSServiceDiscoveryAlreadyRegistered
= -65547,
92 kDNSServiceDiscoveryNameConflict
= -65548,
93 kDNSServiceDiscoveryInvalid
= -65549,
94 kDNSServiceDiscoveryMemFree
= -65792 // 0xFFFE FF00
95 } DNSServiceRegistrationReplyErrorType
;
97 typedef uint32_t DNSRecordReference
;
101 @function DNSServiceResolver_handleReply
102 @discussion This function should be called with the Mach message sent
103 to the port returned by the call to DNSServiceResolverResolve.
104 The reply message will be interpreted and will result in a
105 call to the specified callout function.
106 @param replyMsg The Mach message.
108 void DNSServiceDiscovery_handleReply(void *replyMsg
);
110 /* Service Registration */
112 typedef void (*DNSServiceRegistrationReply
) (
113 DNSServiceRegistrationReplyErrorType errorCode
,
118 @function DNSServiceRegistrationCreate
119 @discussion Register a named service with DNS Service Discovery
120 @param name The name of this service instance (e.g. "Steve's Printer")
121 @param regtype The service type (e.g. "_printer._tcp." -- see
122 RFC 2782 (DNS SRV) and <http://www.iana.org/assignments/port-numbers>)
123 @param domain The domain in which to register the service (e.g. "apple.com.")
124 @param port The local port on which this service is being offered (in network byte order)
125 @param txtRecord Optional protocol-specific additional information
126 @param callBack The DNSServiceRegistrationReply function to be called
127 @param context A user specified context which will be passed to the callout function.
128 @result A dns_registration_t
130 dns_service_discovery_ref DNSServiceRegistrationCreate
136 const char *txtRecord
,
137 DNSServiceRegistrationReply callBack
,
139 ) AVAILABLE_MAC_OS_X_VERSION_10_2_AND_LATER_BUT_DEPRECATED_IN_MAC_OS_X_VERSION_10_3
;
141 /***************************************************************************/
142 /* DNS Domain Enumeration */
146 DNSServiceDomainEnumerationReplyAddDomain
, // Domain found
147 DNSServiceDomainEnumerationReplyAddDomainDefault
, // Domain found (and should be selected by default)
148 DNSServiceDomainEnumerationReplyRemoveDomain
, // Domain has been removed from network
149 } DNSServiceDomainEnumerationReplyResultType
;
153 DNSServiceDiscoverReplyFlagsFinished
,
154 DNSServiceDiscoverReplyFlagsMoreComing
,
155 } DNSServiceDiscoveryReplyFlags
;
157 typedef void (*DNSServiceDomainEnumerationReply
) (
158 DNSServiceDomainEnumerationReplyResultType resultType
, // One of DNSServiceDomainEnumerationReplyResultType
159 const char *replyDomain
,
160 DNSServiceDiscoveryReplyFlags flags
, // DNS Service Discovery reply flags information
165 @function DNSServiceDomainEnumerationCreate
166 @discussion Asynchronously create a DNS Domain Enumerator
167 @param registrationDomains A boolean indicating whether you are looking
168 for recommended registration domains
169 (e.g. equivalent to the AppleTalk zone list in the AppleTalk Control Panel)
170 or recommended browsing domains
171 (e.g. equivalent to the AppleTalk zone list in the Chooser).
172 @param callBack The function to be called when domains are found or removed
173 @param context A user specified context which will be passed to the callout function.
174 @result A dns_registration_t
176 dns_service_discovery_ref DNSServiceDomainEnumerationCreate
178 int registrationDomains
,
179 DNSServiceDomainEnumerationReply callBack
,
181 ) AVAILABLE_MAC_OS_X_VERSION_10_2_AND_LATER_BUT_DEPRECATED_IN_MAC_OS_X_VERSION_10_3
;
183 /***************************************************************************/
184 /* DNS Service Browser */
188 DNSServiceBrowserReplyAddInstance
, // Instance of service found
189 DNSServiceBrowserReplyRemoveInstance
// Instance has been removed from network
190 } DNSServiceBrowserReplyResultType
;
192 typedef void (*DNSServiceBrowserReply
) (
193 DNSServiceBrowserReplyResultType resultType
, // One of DNSServiceBrowserReplyResultType
194 const char *replyName
,
195 const char *replyType
,
196 const char *replyDomain
,
197 DNSServiceDiscoveryReplyFlags flags
, // DNS Service Discovery reply flags information
202 @function DNSServiceBrowserCreate
203 @discussion Asynchronously create a DNS Service browser
204 @param regtype The type of service
205 @param domain The domain in which to find the service
206 @param callBack The function to be called when service instances are found or removed
207 @param context A user specified context which will be passed to the callout function.
208 @result A dns_registration_t
210 dns_service_discovery_ref DNSServiceBrowserCreate
214 DNSServiceBrowserReply callBack
,
216 ) AVAILABLE_MAC_OS_X_VERSION_10_2_AND_LATER_BUT_DEPRECATED_IN_MAC_OS_X_VERSION_10_3
;
218 /***************************************************************************/
219 /* Resolver requests */
221 typedef void (*DNSServiceResolverReply
) (
222 struct sockaddr
*interface
, // Needed for scoped addresses like link-local
223 struct sockaddr
*address
,
224 const char *txtRecord
,
225 DNSServiceDiscoveryReplyFlags flags
, // DNS Service Discovery reply flags information
230 @function DNSServiceResolverResolve
231 @discussion Resolved a named instance of a service to its address, port, and
232 (optionally) other demultiplexing information contained in the TXT record.
233 @param name The name of the service instance
234 @param regtype The type of service
235 @param domain The domain in which to find the service
236 @param callBack The DNSServiceResolverReply function to be called when the specified
237 address has been resolved.
238 @param context A user specified context which will be passed to the callout function.
239 @result A dns_registration_t
242 dns_service_discovery_ref DNSServiceResolverResolve
247 DNSServiceResolverReply callBack
,
249 ) AVAILABLE_MAC_OS_X_VERSION_10_2_AND_LATER_BUT_DEPRECATED_IN_MAC_OS_X_VERSION_10_3
;
251 /***************************************************************************/
252 /* Mach port accessor and deallocation */
255 @function DNSServiceDiscoveryMachPort
256 @discussion Returns the mach port for a dns_service_discovery_ref
257 @param registration A dns_service_discovery_ref as returned from DNSServiceRegistrationCreate
258 @result A mach reply port which will be sent messages as appropriate.
259 These messages should be passed to the DNSServiceDiscovery_handleReply
260 function. A NULL value indicates that no address was
261 specified or some other error occurred which prevented the
262 resolution from being started.
264 mach_port_t
DNSServiceDiscoveryMachPort(dns_service_discovery_ref dnsServiceDiscovery
) AVAILABLE_MAC_OS_X_VERSION_10_2_AND_LATER_BUT_DEPRECATED_IN_MAC_OS_X_VERSION_10_3
;
267 @function DNSServiceDiscoveryDeallocate
268 @discussion Deallocates the DNS Service Discovery type / closes the connection to the server
269 @param dnsServiceDiscovery A dns_service_discovery_ref as returned from a creation or enumeration call
272 void DNSServiceDiscoveryDeallocate(dns_service_discovery_ref dnsServiceDiscovery
) AVAILABLE_MAC_OS_X_VERSION_10_2_AND_LATER_BUT_DEPRECATED_IN_MAC_OS_X_VERSION_10_3
;
274 /***************************************************************************/
275 /* Registration updating */
279 @function DNSServiceRegistrationAddRecord
280 @discussion Request that the mDNS Responder add the DNS Record of a specific type
281 @param dnsServiceDiscovery A dns_service_discovery_ref as returned from a DNSServiceRegistrationCreate call
282 @param rrtype A standard DNS Resource Record Type, from http://www.iana.org/assignments/dns-parameters
283 @param rdlen Length of the data
284 @param rdata Opaque binary Resource Record data, up to 64 kB.
285 @param ttl time to live for the added record.
286 @result DNSRecordReference An opaque reference that can be passed to the update and remove record calls. If an error occurs, this value will be zero or negative
288 DNSRecordReference
DNSServiceRegistrationAddRecord(dns_service_discovery_ref dnsServiceDiscovery
, uint16_t rrtype
, uint16_t rdlen
, const char *rdata
, uint32_t ttl
) AVAILABLE_MAC_OS_X_VERSION_10_2_AND_LATER_BUT_DEPRECATED_IN_MAC_OS_X_VERSION_10_3
;
291 @function DNSServiceRegistrationUpdateRecord
292 @discussion Request that the mDNS Responder add the DNS Record of a specific type
293 @param dnsServiceDiscovery A dns_service_discovery_ref as returned from a DNSServiceRegistrationCreate call
294 @param dnsRecordReference A dnsRecordReference as returned from a DNSServiceRegistrationAddRecord call
295 @param rdlen Length of the data
296 @param rdata Opaque binary Resource Record data, up to 64 kB.
297 @param ttl time to live for the updated record.
298 @result DNSServiceRegistrationReplyErrorType If an error occurs, this value will be non zero
300 DNSServiceRegistrationReplyErrorType
DNSServiceRegistrationUpdateRecord(dns_service_discovery_ref ref
, DNSRecordReference reference
, uint16_t rdlen
, const char *rdata
, uint32_t ttl
) AVAILABLE_MAC_OS_X_VERSION_10_2_AND_LATER_BUT_DEPRECATED_IN_MAC_OS_X_VERSION_10_3
;
303 @function DNSServiceRegistrationRemoveRecord
304 @discussion Request that the mDNS Responder remove the DNS Record(s) of a specific type
305 @param dnsServiceDiscovery A dns_service_discovery_ref as returned from a DNSServiceRegistrationCreate call
306 @param dnsRecordReference A dnsRecordReference as returned from a DNSServiceRegistrationAddRecord call
307 @result DNSServiceRegistrationReplyErrorType If an error occurs, this value will be non zero
309 DNSServiceRegistrationReplyErrorType
DNSServiceRegistrationRemoveRecord(dns_service_discovery_ref ref
, DNSRecordReference reference
) AVAILABLE_MAC_OS_X_VERSION_10_2_AND_LATER_BUT_DEPRECATED_IN_MAC_OS_X_VERSION_10_3
;
314 #endif /* __DNS_SERVICE_DISCOVERY_H */