2 * Copyright (c) 2002-2004 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@
25 Change History (most recent first):
27 $Log: DNSServiceDiscovery.h,v $
28 Revision 1.4 2004/05/06 18:42:58 ksekar
29 General dns_sd.h API cleanup, including the following radars:
30 <rdar://problem/3592068>: Remove flags with zero value
31 <rdar://problem/3479569>: Passing in NULL causes a crash.
33 Revision 1.3 2004/01/30 02:56:34 bradley
34 Updated to support full Unicode display. Added support for all services on www.dns-sd.org.
36 Revision 1.2 2003/08/20 07:06:34 bradley
37 Update to APSL 2.0. Updated change history to match other mDNSResponder files.
39 Revision 1.1 2003/08/20 06:04:45 bradley
40 Platform-neutral DNSServices-based emulation layer for the Mac OS X DNSServiceDiscovery API.
44 //---------------------------------------------------------------------------------------------------------------------------
45 /*! @header DNSServiceDiscovery
47 @abstract DNSServiceDiscovery emulation using DNSServices.
50 #ifndef __DNS_SERVICE_DISCOVERY__
51 #define __DNS_SERVICE_DISCOVERY__
57 #include <mach/mach_types.h>
59 #include <sys/types.h>
60 #include <sys/socket.h>
61 #include <sys/cdefs.h>
63 #include <netinet/in.h>
65 #elif( defined( __MWERKS__ ) )
69 #elif( defined( _MSC_VER ) )
71 typedef signed char int8_t; // C99 stdint.h not supported in VC++/VS.NET yet.
72 typedef unsigned char uint8_t; // C99 stdint.h not supported in VC++/VS.NET yet.
73 typedef signed short int16_t; // C99 stdint.h not supported in VC++/VS.NET yet.
74 typedef unsigned short uint16_t; // C99 stdint.h not supported in VC++/VS.NET yet.
75 typedef signed long int32_t; // C99 stdint.h not supported in VC++/VS.NET yet.
76 typedef unsigned long uint32_t; // C99 stdint.h not supported in VC++/VS.NET yet.
84 // Note: The following is mostly copied from DNSServiceDiscovery.h.
86 // Compatibility types.
89 typedef int mach_port_t
;
92 //---------------------------------------------------------------------------------------------------------------------------
93 /*! @typedef dns_service_discovery_ref
95 @abstract Reference to a DNS Service Discovery object.
98 typedef struct _dns_service_discovery_t
* dns_service_discovery_ref
;
100 //---------------------------------------------------------------------------------------------------------------------------
101 /*! @enum DNSServiceRegistrationReplyErrorType
103 @abstract Error codes.
108 kDNSServiceDiscoveryWaiting
= 1,
109 kDNSServiceDiscoveryNoError
= 0,
111 // mDNS Error codes are in the range
112 // FFFE FF00 (-65792) to FFFE FFFF (-65537)
114 kDNSServiceDiscoveryUnknownErr
= -65537, // 0xFFFE FFFF
115 kDNSServiceDiscoveryNoSuchNameErr
= -65538,
116 kDNSServiceDiscoveryNoMemoryErr
= -65539,
117 kDNSServiceDiscoveryBadParamErr
= -65540,
118 kDNSServiceDiscoveryBadReferenceErr
= -65541,
119 kDNSServiceDiscoveryBadStateErr
= -65542,
120 kDNSServiceDiscoveryBadFlagsErr
= -65543,
121 kDNSServiceDiscoveryUnsupportedErr
= -65544,
122 kDNSServiceDiscoveryNotInitializedErr
= -65545,
123 kDNSServiceDiscoveryNoCache
= -65546,
124 kDNSServiceDiscoveryAlreadyRegistered
= -65547,
125 kDNSServiceDiscoveryNameConflict
= -65548,
126 kDNSServiceDiscoveryInvalid
= -65549,
127 kDNSServiceDiscoveryMemFree
= -65792 // 0xFFFE FF00
129 } DNSServiceRegistrationReplyErrorType
;
131 typedef uint32_t DNSRecordReference
;
133 //---------------------------------------------------------------------------------------------------------------------------
135 @function DNSServiceResolver_handleReply
137 @param replyMsg The Mach message.
141 This function should be called with the Mach message sent to the port returned by the call to DNSServiceResolverResolve.
142 The reply message will be interpreted and will result in a call to the specified callout function.
145 void DNSServiceDiscovery_handleReply( void *replyMsg
);
147 /* Service Registration */
149 typedef void (*DNSServiceRegistrationReply
) (
150 DNSServiceRegistrationReplyErrorType errorCode
,
155 @function DNSServiceRegistrationCreate
156 @description Register a named service with DNS Service Discovery
157 @param name The name of this service instance (e.g. "Steve's Printer")
158 @param regtype The service type (e.g. "_printer._tcp." -- see
159 RFC 2782 (DNS SRV) and <http://www.iana.org/assignments/port-numbers>)
160 @param domain The domain in which to register the service (e.g. "apple.com.")
161 @param port The local port on which this service is being offered (in network byte order)
162 @param txtRecord Optional protocol-specific additional information
163 @param callBack The DNSServiceRegistrationReply function to be called
164 @param context A user specified context which will be passed to the callout function.
165 @result A dns_registration_t
167 dns_service_discovery_ref DNSServiceRegistrationCreate
173 const char *txtRecord
,
174 DNSServiceRegistrationReply callBack
,
178 /***************************************************************************/
179 /* DNS Domain Enumeration */
183 DNSServiceDomainEnumerationReplyAddDomain
, // Domain found
184 DNSServiceDomainEnumerationReplyAddDomainDefault
, // Domain found (and should be selected by default)
185 DNSServiceDomainEnumerationReplyRemoveDomain
, // Domain has been removed from network
186 } DNSServiceDomainEnumerationReplyResultType
;
190 DNSServiceDiscoverReplyFlagsMoreComing
,
191 } DNSServiceDiscoveryReplyFlags
;
193 typedef void (*DNSServiceDomainEnumerationReply
) (
194 DNSServiceDomainEnumerationReplyResultType resultType
, // One of DNSServiceDomainEnumerationReplyResultType
195 const char *replyDomain
,
196 DNSServiceDiscoveryReplyFlags flags
, // DNS Service Discovery reply flags information
201 @function DNSServiceDomainEnumerationCreate
202 @description Asynchronously create a DNS Domain Enumerator
203 @param registrationDomains A boolean indicating whether you are looking
204 for recommended registration domains
205 (e.g. equivalent to the AppleTalk zone list in the AppleTalk Control Panel)
206 or recommended browsing domains
207 (e.g. equivalent to the AppleTalk zone list in the Chooser).
208 @param callBack The function to be called when domains are found or removed
209 @param context A user specified context which will be passed to the callout function.
210 @result A dns_registration_t
212 dns_service_discovery_ref DNSServiceDomainEnumerationCreate
214 int registrationDomains
,
215 DNSServiceDomainEnumerationReply callBack
,
219 /***************************************************************************/
220 /* DNS Service Browser */
224 DNSServiceBrowserReplyAddInstance
, // Instance of service found
225 DNSServiceBrowserReplyRemoveInstance
// Instance has been removed from network
226 } DNSServiceBrowserReplyResultType
;
228 typedef void (*DNSServiceBrowserReply
) (
229 DNSServiceBrowserReplyResultType resultType
, // One of DNSServiceBrowserReplyResultType
230 const char *replyName
,
231 const char *replyType
,
232 const char *replyDomain
,
233 DNSServiceDiscoveryReplyFlags flags
, // DNS Service Discovery reply flags information
238 @function DNSServiceBrowserCreate
239 @description Asynchronously create a DNS Service browser
240 @param regtype The type of service
241 @param domain The domain in which to find the service
242 @param callBack The function to be called when service instances are found or removed
243 @param context A user specified context which will be passed to the callout function.
244 @result A dns_registration_t
246 dns_service_discovery_ref DNSServiceBrowserCreate
250 DNSServiceBrowserReply callBack
,
254 /***************************************************************************/
255 /* Resolver requests */
257 typedef void (*DNSServiceResolverReply
) (
258 struct sockaddr
*interfaceAddr
, // Needed for scoped addresses like link-local
259 struct sockaddr
*address
,
260 const char *txtRecord
,
261 DNSServiceDiscoveryReplyFlags flags
, // DNS Service Discovery reply flags information
266 @function DNSServiceResolverResolve
267 @description Resolved a named instance of a service to its address, port, and
268 (optionally) other demultiplexing information contained in the TXT record.
269 @param name The name of the service instance
270 @param regtype The type of service
271 @param domain The domain in which to find the service
272 @param callBack The DNSServiceResolverReply function to be called when the specified
273 address has been resolved.
274 @param context A user specified context which will be passed to the callout function.
275 @result A dns_registration_t
278 dns_service_discovery_ref DNSServiceResolverResolve
283 DNSServiceResolverReply callBack
,
287 /***************************************************************************/
288 /* Mach port accessor and deallocation */
291 @function DNSServiceDiscoveryMachPort
292 @description Returns the mach port for a dns_service_discovery_ref
293 @param registration A dns_service_discovery_ref as returned from DNSServiceRegistrationCreate
294 @result A mach reply port which will be sent messages as appropriate.
295 These messages should be passed to the DNSServiceDiscovery_handleReply
296 function. A NULL value indicates that no address was
297 specified or some other error occurred which prevented the
298 resolution from being started.
300 mach_port_t
DNSServiceDiscoveryMachPort(dns_service_discovery_ref dnsServiceDiscovery
);
303 @function DNSServiceDiscoveryDeallocate
304 @description Deallocates the DNS Service Discovery type / closes the connection to the server
305 @param dnsServiceDiscovery A dns_service_discovery_ref as returned from a creation or enumeration call
308 void DNSServiceDiscoveryDeallocate(dns_service_discovery_ref dnsServiceDiscovery
);
310 /***************************************************************************/
311 /* Registration updating */
315 @function DNSServiceRegistrationAddRecord
316 @description Request that the mDNS Responder add the DNS Record of a specific type
317 @param dnsServiceDiscovery A dns_service_discovery_ref as returned from a DNSServiceRegistrationCreate call
318 @param rrtype A standard DNS Resource Record Type, from http://www.iana.org/assignments/dns-parameters
319 @param rdlen Length of the data
320 @param rdata Opaque binary Resource Record data, up to 64 kB.
321 @param ttl time to live for the added record.
322 @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
324 DNSRecordReference
DNSServiceRegistrationAddRecord(dns_service_discovery_ref dnsServiceDiscovery
, uint16_t rrtype
, uint16_t rdlen
, const char *rdata
, uint32_t ttl
);
327 @function DNSServiceRegistrationUpdateRecord
328 @description Request that the mDNS Responder add the DNS Record of a specific type
329 @param dnsServiceDiscovery A dns_service_discovery_ref as returned from a DNSServiceRegistrationCreate call
330 @param dnsRecordReference A dnsRecordReference as returned from a DNSServiceRegistrationAddRecord call
331 @param rdlen Length of the data
332 @param rdata Opaque binary Resource Record data, up to 64 kB.
333 @param ttl time to live for the updated record.
334 @result DNSServiceRegistrationReplyErrorType If an error occurs, this value will be non zero
336 DNSServiceRegistrationReplyErrorType
DNSServiceRegistrationUpdateRecord(dns_service_discovery_ref ref
, DNSRecordReference reference
, uint16_t rdlen
, const char *rdata
, uint32_t ttl
);
339 @function DNSServiceRegistrationRemoveRecord
340 @description Request that the mDNS Responder remove the DNS Record(s) of a specific type
341 @param dnsServiceDiscovery A dns_service_discovery_ref as returned from a DNSServiceRegistrationCreate call
342 @param dnsRecordReference A dnsRecordReference as returned from a DNSServiceRegistrationAddRecord call
343 @result DNSServiceRegistrationReplyErrorType If an error occurs, this value will be non zero
346 DNSServiceRegistrationReplyErrorType
DNSServiceRegistrationRemoveRecord(dns_service_discovery_ref ref
, DNSRecordReference reference
);
352 #endif // __DNS_SERVICE_DISCOVERY__