2 * Copyright (c) 2002-2004 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
23 Change History (most recent first):
25 $Log: DNSServices.h,v $
26 Revision 1.11 2004/07/13 21:24:28 rpantos
27 Fix for <rdar://problem/3701120>.
29 Revision 1.10 2004/01/30 02:56:34 bradley
30 Updated to support full Unicode display. Added support for all services on www.dns-sd.org.
32 Revision 1.9 2003/10/31 12:16:03 bradley
33 Added support for providing the resolved host name to the callback.
35 Revision 1.8 2003/08/20 06:44:24 bradley
36 Updated to latest internal version of the mDNSCore code: Added support for interface
37 specific registrations; Added support for no-such-service registrations; Added support for host
38 name registrations; Added support for host proxy and service proxy registrations; Added support for
39 registration record updates (e.g. TXT record updates); Added support for using either a single C
40 string TXT record, a raw, pre-formatted TXT record potentially containing multiple character string
41 entries, or a C-string containing a Mac OS X-style \001-delimited set of TXT record character
42 strings; Added support in resolve callbacks for providing both a simplified C-string for TXT records
43 and a ptr/size for the raw TXT record data; Added utility routines for dynamically building TXT
44 records from a variety of sources (\001-delimited, individual strings, etc.) and converting TXT
45 records to various formats for use in apps; Added utility routines to validate DNS names, DNS
46 service types, and TXT records; Moved to portable address representation unions (byte-stream vs host
47 order integer) for consistency, to avoid swapping between host and network byte order, and for IPv6
48 support; Removed dependence on modified mDNSCore: define structures and prototypes locally; Added
49 support for automatically renaming services on name conflicts; Detect and correct TXT records from
50 old versions of mDNS that treated a TXT record as an arbitrary block of data, but prevent other
51 malformed TXT records from being accepted; Added many more error codes; Added complete HeaderDoc for
52 all constants, structures, typedefs, macros, and functions. Various other minor cleanup and fixes.
54 Revision 1.7 2003/08/12 19:56:29 cheshire
57 Revision 1.6 2003/07/02 21:20:10 cheshire
58 <rdar://problem/3313413> Update copyright notices, etc., in source code comments
60 Revision 1.5 2003/03/22 02:57:45 cheshire
61 Updated mDNSWindows to use new "mDNS_Execute" model (see "mDNSCore/Implementer Notes.txt")
63 Revision 1.4 2003/02/20 00:59:05 cheshire
64 Brought Windows code up to date so it complies with
65 Josh Graessley's interface changes for IPv6 support.
66 (Actual support for IPv6 on Windows will come later.)
68 Revision 1.3 2002/09/21 20:44:57 zarzycki
71 Revision 1.2 2002/09/20 05:58:02 bradley
72 DNS Services for Windows
76 //---------------------------------------------------------------------------------------------------------------------------
77 /*! @header DNSServices
79 @abstract DNS Services interfaces.
83 DNS Services provides DNS service registration, domain and service discovery, and name resolving services.
86 #ifndef __DNS_SERVICES__
87 #define __DNS_SERVICES__
96 #pragma mark == General ==
99 //---------------------------------------------------------------------------------------------------------------------------
100 /*! @defined dns_check_compile_time
102 @abstract Performs a compile-time check of something such as the size of an int.
106 This declares a unique array with a size that is determined by dividing 1 by the result of the compile-time expression
107 passed to the macro. If the expression evaluates to 0, this expression results in a divide by zero, which is illegal
108 and generates a compile-time error.
112 dns_check_compile_time( sizeof( int ) == 4 );
114 Note: This only works with compile-time expressions.
115 Note: This only works in places where extern declarations are allowed (e.g. global scope).
119 <http://www.jaggersoft.com/pubs/CVu11_3.html>
120 <http://www.jaggersoft.com/pubs/CVu11_5.html>
122 Note: The following macros differ from the macros on the www.jaggersoft.com web site because those versions do not
123 work with GCC due to GCC allow a zero-length array. Using a divide-by-zero condition turned out to be more portable.
126 #define dns_check_compile_time( X ) extern int dns_unique_name[ 1 / (int)( ( X ) ) ]
128 #define dns_unique_name dns_make_name_wrapper( __LINE__ )
129 #define dns_make_name_wrapper( X ) dns_make_name( X )
130 #define dns_make_name( X ) dns_check_compile_time_ ## X
132 //---------------------------------------------------------------------------------------------------------------------------
133 /*! @defined dns_check_compile_time_code
135 @abstract Perform a compile-time check, suitable for placement in code, of something such as the size of an int.
139 This creates a switch statement with an existing case for 0 and an additional case using the result of a
140 compile-time expression. A switch statement cannot have two case labels with the same constant so if the
141 compile-time expression evaluates to 0, it is illegal and generates a compile-time error. If the compile-time
142 expression does not evaluate to 0, the resulting value is used as the case label and it compiles without error.
146 dns_check_compile_time_code( sizeof( int ) == 4 );
148 Note: This only works with compile-time expressions.
149 Note: This does not work in a global scope so it must be inside a function.
153 <http://www.jaggersoft.com/pubs/CVu11_3.html>
154 <http://www.jaggersoft.com/pubs/CVu11_5.html>
157 #define dns_check_compile_time_code( X ) switch( 0 ) { case 0: case X:; }
159 //---------------------------------------------------------------------------------------------------------------------------
160 /*! @defined DNS_LOCAL
162 @abstract Macro to make variables and functions static when debugging is off, but exported when debugging is on.
166 Rather than using "static" directly, using this macros allows you to access these variables external while
167 debugging without being penalized for production builds.
173 #define DNS_LOCAL static
176 //---------------------------------------------------------------------------------------------------------------------------
177 /*! @defined DNS_EXPORT
179 @abstract Macro to provide a visual clue that a variable or function is globally visible.
184 //---------------------------------------------------------------------------------------------------------------------------
185 /*! @defined DNS_DEBUG_USE_ONLY
186 @abstract Macro to mark a variable as unused when debugging is turned off.
189 Variables are sometimes needed only for debugging. When debugging is turned off, these debug-only variables
190 generate compiler warnings about unused variables. To eliminate these warnings, use the DNS_DEBUG_USE_ONLY macro
191 to indicate the variables are for debugging only.
195 #define DNS_DEBUG_USE_ONLY( X )
197 #define DNS_DEBUG_USE_ONLY( X ) (void)( X )
200 //---------------------------------------------------------------------------------------------------------------------------
201 /*! @defined DNS_UNUSED
202 @abstract Macro to mark a variable as unused.
205 There is no universally supported pragma/attribute for indicating a variable is unused. DNS_UNUSED lets
206 indicate a variable is unused in a manner that is supported by most compilers.
209 #define DNS_UNUSED( X ) (void)( X )
211 //---------------------------------------------------------------------------------------------------------------------------
212 /*! @typedef DNSUInt8
214 @abstract 8-bit unsigned data type.
217 typedef unsigned char DNSUInt8
;
219 dns_check_compile_time( sizeof( DNSUInt8
) == 1 );
221 //---------------------------------------------------------------------------------------------------------------------------
222 /*! @typedef DNSUInt16
224 @abstract 16-bit unsigned data type.
227 typedef unsigned short DNSUInt16
;
229 dns_check_compile_time( sizeof( DNSUInt16
) == 2 );
231 //---------------------------------------------------------------------------------------------------------------------------
232 /*! @typedef DNSUInt32
234 @abstract 32-bit unsigned data type.
237 typedef unsigned long DNSUInt32
;
239 dns_check_compile_time( sizeof( DNSUInt32
) == 4 );
241 //---------------------------------------------------------------------------------------------------------------------------
242 /*! @typedef DNSSInt32
244 @abstract 32-bit signed data type.
247 typedef signed long DNSSInt32
;
249 dns_check_compile_time( sizeof( DNSSInt32
) == 4 );
252 //---------------------------------------------------------------------------------------------------------------------------
253 /*! @typedef DNSOpaque16
255 @abstract 16-bit opaque data type with 8-bit and 16-bit accessors.
258 typedef union DNSOpaque16 DNSOpaque16
;
265 //---------------------------------------------------------------------------------------------------------------------------
266 /*! @typedef DNSOpaque32
268 @abstract 32-bit opaque data type with 8-bit, 16-bit, and 32-bit accessors.
271 typedef union DNSOpaque32 DNSOpaque32
;
279 //---------------------------------------------------------------------------------------------------------------------------
280 /*! @typedef DNSOpaque128
282 @abstract 128-bit opaque data type with 8-bit, 16-bit, and 32-bit accessors.
285 typedef union DNSOpaque128 DNSOpaque128
;
293 //---------------------------------------------------------------------------------------------------------------------------
294 /*! @typedef DNSCount
296 @abstract Count of at least 32-bits.
299 typedef DNSUInt32 DNSCount
;
302 #pragma mark == Errors ==
305 //---------------------------------------------------------------------------------------------------------------------------
308 @abstract DNS Service status code.
310 @constant kDNSNoErr (0) Success. No error occurred.
311 @constant kDNSUnknownErr (-65537) An unknown error occurred.
312 @constant kDNSNoSuchNameErr (-65538) The name could not be found on the network.
313 @constant kDNSNoMemoryErr (-65539) Not enough memory was available.
314 @constant kDNSBadParamErr (-65540) A invalid or inappropriate parameter was specified.
315 @constant kDNSBadReferenceErr (-65541) A invalid or inappropriate reference was specified.
316 @constant kDNSBadStateErr (-65542) The current state does not allow the specified operation.
317 @constant kDNSBadFlagsErr (-65543) An invalid, inappropriate, or unsupported flag was specified.
318 @constant kDNSUnsupportedErr (-65544) The specified feature is not currently supported.
319 @constant kDNSNotInitializedErr (-65545) DNS Service has not been initialized.
320 @constant kDNSNoCacheErr (-65546) No cache was specified.
321 @constant kDNSAlreadyRegisteredErr (-65547) Service or host name is already registered.
322 @constant kDNSNameConflictErr (-65548) Name conflicts with another on the network.
323 @constant kDNSInvalidErr (-65549) A general error to indicate something is invalid.
324 @constant kDNSGrowCache (-65550) Cache needs to be grown (not used).
325 @constant kDNSIncompatibleErr (-65551) Version is incompatible.
327 @constant kDNSSizeErr (-65600) Size was too small or too big.
328 @constant kDNSMismatchErr (-65601) A data, version, etc. mismatch occurred.
329 @constant kDNSReadErr (-65602) Read failed.
330 @constant kDNSWriteErr (-65603) Write failed.
331 @constant kDNSCanceledErr (-65604) Operation was canceled.
332 @constant kDNSTimeoutErr (-65605) Operation timed out.
333 @constant kDNSConnectionErr (-65606) A disconnect or other connection error occurred.
334 @constant kDNSInUseErr (-65607) Object is in use (e.g. cannot reuse active param blocks).
335 @constant kDNSNoResourcesErr (-65608) Resources unavailable to perform the operation.
336 @constant kDNSEndingErr (-65609) Connection, session, or something is ending.
338 @constant kDNSConfigChanged (-65791) Configuration changed (not used).
339 @constant kDNSMemFree (-65792) Memory can be freed.
342 typedef DNSSInt32 DNSStatus
;
347 // DNS Services error codes are in the range FFFE FF00 (-65792) to FFFE FFFF (-65537).
349 kDNSStartErr
= -65537, // 0xFFFE FFFF
351 kDNSUnknownErr
= -65537,
352 kDNSNoSuchNameErr
= -65538,
353 kDNSNoMemoryErr
= -65539,
354 kDNSBadParamErr
= -65540,
355 kDNSBadReferenceErr
= -65541,
356 kDNSBadStateErr
= -65542,
357 kDNSBadFlagsErr
= -65543,
358 kDNSUnsupportedErr
= -65544,
359 kDNSNotInitializedErr
= -65545,
360 kDNSNoCacheErr
= -65546,
361 kDNSAlreadyRegisteredErr
= -65547,
362 kDNSNameConflictErr
= -65548,
363 kDNSInvalidErr
= -65549,
364 kDNSGrowCache
= -65550, // Reserved for mDNSCore
365 kDNSIncompatibleErr
= -65551,
367 kDNSSizeErr
= -65600,
368 kDNSMismatchErr
= -65601,
369 kDNSReadErr
= -65602,
370 kDNSWriteErr
= -65603,
371 kDNSCanceledErr
= -65604,
372 kDNSTimeoutErr
= -65605,
373 kDNSConnectionErr
= -65606,
374 kDNSInUseErr
= -65607,
375 kDNSNoResourcesErr
= -65608,
376 kDNSEndingErr
= -65609,
378 kDNSConfigChanged
= -65791, // Reserved for mDNSCore
379 kDNSMemFree
= -65792, // Reserved for mDNSCore
381 kDNSEndErr
= -65792 // 0xFFFE FF00
384 //---------------------------------------------------------------------------------------------------------------------------
387 @abstract Flags used control DNS Services.
389 @constant kDNSFlagAdvertise
390 Indicates that interfaces should be advertised on the network. Software that only performs searches
391 do not need to set this flag.
394 typedef DNSUInt32 DNSFlags
;
397 kDNSFlagAdvertise
= ( 1 << 0 )
400 //---------------------------------------------------------------------------------------------------------------------------
403 @abstract UDP/TCP port for DNS services.
405 @constant kDNSPortInvalid
408 @constant kDNSPortUnicastDNS
409 TCP/UDP port for normal unicast DNS (see RFC 1035).
411 @constant kDNSPortMulticastDNS
412 TCP/UDP port for Multicast DNS (see <http://www.multicastdns.org/>).
415 typedef DNSUInt16 DNSPort
;
419 kDNSPortUnicastDNS
= 53,
420 kDNSPortMulticastDNS
= 5353
423 //---------------------------------------------------------------------------------------------------------------------------
424 /*! @enum DNSNetworkAddressType
426 @abstract Type of address data within a DNSNetworkAddress.
428 @constant kDNSNetworkAddressTypeInvalid
431 @constant kDNSNetworkAddressTypeIPv4
434 @constant kDNSNetworkAddressTypeIPv6
438 typedef DNSUInt32 DNSNetworkAddressType
;
440 #define kDNSNetworkAddressTypeInvalid 0
441 #define kDNSNetworkAddressTypeIPv4 4
442 #define kDNSNetworkAddressTypeIPv6 6
443 #define kDNSNetworkAddressTypeAny 0xFFFFFFFF
445 //---------------------------------------------------------------------------------------------------------------------------
446 /*! @struct DNSNetworkAddressIPv4
449 32-bit IPv4 address in network byte order.
452 16-bit port number in network byte order.
455 typedef struct DNSNetworkAddressIPv4 DNSNetworkAddressIPv4
;
456 struct DNSNetworkAddressIPv4
462 //---------------------------------------------------------------------------------------------------------------------------
463 /*! @struct DNSNetworkAddressIPv6
466 128-bit IPv6 address in network byte order.
469 16-bit port number in network byte order.
472 typedef struct DNSNetworkAddressIPv6 DNSNetworkAddressIPv6
;
473 struct DNSNetworkAddressIPv6
479 //---------------------------------------------------------------------------------------------------------------------------
480 /*! @struct DNSNetworkAddress
483 Type of data contained within the address structure.
489 Reserved data (pads structure to allow for future growth). Unused portions must be zero.
492 typedef struct DNSNetworkAddress DNSNetworkAddress
;
493 struct DNSNetworkAddress
495 DNSNetworkAddressType addressType
;
498 DNSNetworkAddressIPv4 ipv4
;
499 DNSNetworkAddressIPv6 ipv6
;
503 //---------------------------------------------------------------------------------------------------------------------------
504 /*! @defined kDNSLocalDomain
506 @abstract Local DNS domain name (local.).
509 #define kDNSLocalDomain "local."
511 //---------------------------------------------------------------------------------------------------------------------------
512 /*! @function DNSServicesInitialize
514 @abstract Initializes DNS Services. This must be called before DNS Services functions can be used.
517 Flags to control DNS Services.
519 @param inCacheEntryCount
520 Number of entries in the DNS record cache. Specify 0 to use the default.
522 @result Error code indicating failure reason or kDNSNoErr if successful.
525 DNSStatus
DNSServicesInitialize( DNSFlags inFlags
, DNSCount inCacheEntryCount
);
527 //---------------------------------------------------------------------------------------------------------------------------
528 /*! @function DNSServicesFinalize
530 @abstract Finalizes DNS Services. No DNS Services functions may be called after this function is called.
533 void DNSServicesFinalize( void );
536 #pragma mark == Resolving ==
539 //===========================================================================================================================
541 //===========================================================================================================================
543 //---------------------------------------------------------------------------------------------------------------------------
544 /*! @typedef DNSBrowserRef
546 @abstract Reference to a DNS browser object.
550 A browser object is typically used by a graphical user application in a manner similar to the Macintosh "Chooser"
551 application. The application creates a browser object then starts domain and/or service searches to begin browsing.
552 When domains and/or services are found, added, or removed, the application is notified via a callback routine.
555 typedef struct DNSBrowser
* DNSBrowserRef
;
557 //---------------------------------------------------------------------------------------------------------------------------
558 /*! @typedef DNSResolverRef
560 @abstract Reference to a DNS resolver object.
564 A resolver object is used to resolve service names to IP addresses.
567 typedef struct DNSResolver
* DNSResolverRef
;
569 //---------------------------------------------------------------------------------------------------------------------------
570 /*! @enum DNSResolverFlags
572 @abstract Flags used to control resolve operations.
574 @constant kDNSResolverFlagOneShot
575 Used to indicate the resolver object should be automatically released after the first resolve.
577 @constant kDNSResolverFlagOnlyIfUnique
578 Used to indicate the resolver object should only be created if it is unique. This makes it easy for
579 resolver management to be handled automatically. For example, some software needs to keep active
580 resolving operations open constantly to detect things like the IP address changing (e.g. if
581 displaying it to the user), but when a service goes away then comes back, a new resolver object
582 will often be created, leaving two resolvers for the same name.
584 @constant kDNSResolverFlagAutoReleaseByName
585 Used to indicate the resolver object should be automatically released when the service name
586 that is associated with it is no longer on the network. When a service is added to the network,
587 a resolver object may be created and kept around to detect things like IP address changes. When
588 the service goes off the network, this option causes the resolver associated with that service
589 name to be automatically released.
592 typedef DNSUInt32 DNSResolverFlags
;
595 kDNSResolverFlagOneShot
= ( 1 << 0 ),
596 kDNSResolverFlagOnlyIfUnique
= ( 1 << 1 ),
597 kDNSResolverFlagAutoReleaseByName
= ( 1 << 2 )
600 //---------------------------------------------------------------------------------------------------------------------------
601 /*! @enum DNSResolverEventType
603 @abstract Type of resolver event being delivered.
605 @constant kDNSResolverEventTypeInvalid
606 Invalid event type. Here for completeness.
608 @constant kDNSResolverEventTypeRelease
609 Object is being released. No additional data is associated with this event.
611 @constant kDNSResolverEventTypeResolved
615 typedef long DNSResolverEventType
;
618 kDNSResolverEventTypeInvalid
= 0,
619 kDNSResolverEventTypeRelease
= 1,
620 kDNSResolverEventTypeResolved
= 10
623 //---------------------------------------------------------------------------------------------------------------------------
624 /*! @struct DNSResolverEventResolveData
626 @abstract Data structure passed to callback routine when a resolve-related event occurs.
629 Ptr to UTF-8 string containing the resolved name of the service.
632 Ptr to UTF-8 string containing the resolved type of the service.
635 Ptr to UTF-8 string containing the resolved domain of the service.
638 Network interface that received the event.
641 Network interface that received the event. May be empty if interface is no longer available.
644 IP of network interface that received the event. May be invalid if interface is no longer available.
647 Network address of the service. Used to communicate with the service.
650 Ptr to UTF-8 string containing any additional text information supplied by the service provider.
653 Flags used to augment the event data.
656 Ptr to raw TXT record data. May be needed if a custom TXT record format is used.
658 @field textRecordRawSize
659 Number of bytes in raw TXT record. May be needed if a custom TXT record format is used.
662 Host name of the resolved service.
665 typedef struct DNSResolverEventResolveData DNSResolverEventResolveData
;
666 struct DNSResolverEventResolveData
672 const char * interfaceName
;
673 DNSNetworkAddress interfaceIP
;
674 DNSNetworkAddress address
;
675 const char * textRecord
;
676 DNSResolverFlags flags
;
677 const void * textRecordRaw
;
678 DNSCount textRecordRawSize
;
679 const char * hostName
;
682 //---------------------------------------------------------------------------------------------------------------------------
683 /*! @struct DNSResolverEvent
685 @abstract Data structure passed to callback routines when a resolver event occurs.
688 Type of event. The type determines which portion of the data union to use. Types and data union
689 fields are named such as the data union field is the same as the event type. For example, a
690 "resolved" event type (kDNSResolverEventTypeResolved) would refer to data union field "resolved".
693 Data associated with kDNSResolverEventTypeResolved event.
696 typedef struct DNSResolverEvent DNSResolverEvent
;
697 struct DNSResolverEvent
699 DNSResolverEventType type
;
703 DNSResolverEventResolveData resolved
;
708 //---------------------------------------------------------------------------------------------------------------------------
709 /*! @function DNSResolverCallBack
711 @abstract CallBack routine used to indicate a resolver event.
714 User-supplied context for callback (specified when browser is created).
717 Reference to resolver object generating the event.
723 Data associated with the event.
727 ( *DNSResolverCallBack
)(
729 DNSResolverRef inRef
,
730 DNSStatus inStatusCode
,
731 const DNSResolverEvent
* inEvent
);
733 //---------------------------------------------------------------------------------------------------------------------------
734 /*! @function DNSResolverCreate
736 @abstract Creates a resolver object and start resolving a service name.
739 Flags to control the resolving process.
742 Ptr to UTF-8 string containing the service name to resolve (e.g. "My Printer").
745 Ptr to UTF-8 string containing the service type of the service to resolve (e.g. "_printer._tcp").
748 Ptr to UTF-8 string containing the domain of the service to resolve (e.g. "apple.com"). Use NULL
749 to indicate the local domain.
752 CallBack routine to call when a resolver event occurs.
754 @param inCallBackContext
755 Context pointer to pass to CallBack routine when an event occurs. Not inspected by DNS Services.
758 Reference to browser object related to this resolver. If a browser object is specified and is
759 later released, this resolver object will automatically be released too. May be null.
762 Ptr to receive reference to resolver object. If the kDNSResolverFlagOnlyIfUnique flag is specified
763 and there is already a resolver for the name, a NULL reference is returned in this parameter to let
764 the caller know that no resolver was created. May be null.
766 @result Error code indicating failure reason or kDNSNoErr if successful.
771 DNSResolverFlags inFlags
,
774 const char * inDomain
,
775 DNSResolverCallBack inCallBack
,
776 void * inCallBackContext
,
777 DNSBrowserRef inOwner
,
778 DNSResolverRef
* outRef
);
780 //---------------------------------------------------------------------------------------------------------------------------
781 /*! @function DNSResolverRelease
783 @abstract Releases a resolver object.
786 Reference to the resolver object to release.
789 Flags to control the release process.
791 @result Error code indicating failure reason or kDNSNoErr if successful.
794 DNSStatus
DNSResolverRelease( DNSResolverRef inRef
, DNSResolverFlags inFlags
);
797 #pragma mark == Browsing ==
800 //===========================================================================================================================
802 //===========================================================================================================================
804 //---------------------------------------------------------------------------------------------------------------------------
805 /*! @enum DNSBrowserFlags
807 @abstract Flags used to control browser operations.
809 @constant kDNSBrowserFlagRegistrationDomainsOnly
810 Used to indicate the client is browsing only for domains to publish services. When the client wishes
811 to publish a service, a domain browse operation would be started, with this flag specified, to find
812 the domain used to register the service. Only valid when passed to DNSBrowserStartDomainSearch.
814 @constant kDNSBrowserFlagAutoResolve
815 Used to indicate discovered names should be automatically resolved. This eliminates the need to
816 manually create a resolver to get the IP address and other information. Only valid when passed to
817 DNSBrowserStartServiceSearch. When this option is used, it is important to avoid manually resolving
818 names because this option causes DNS Services to automatically resolve and multiple resolvers for
819 the same name will lead to unnecessary network bandwidth usage. It is also important to note that
820 the notification behavior of the browser is otherwise not affected by this option so browser callback
821 will still receive the same add/remove domain/service events it normally would.
824 typedef DNSUInt32 DNSBrowserFlags
;
827 kDNSBrowserFlagRegistrationDomainsOnly
= ( 1 << 0 ),
828 kDNSBrowserFlagAutoResolve
= ( 1 << 1 )
831 //---------------------------------------------------------------------------------------------------------------------------
832 /*! @enum DNSBrowserEventType
834 @abstract Type of browser event being delivered.
836 @constant kDNSBrowserEventTypeInvalid
837 Invalid event type. Here for completeness.
839 @constant kDNSBrowserEventTypeRelease
840 Object is being released. No additional data is associated with this event.
842 @constant kDNSBrowserEventTypeAddDomain
845 @constant kDNSBrowserEventTypeAddDefaultDomain
846 Default domain added/found. This domain should be selected as the default.
848 @constant kDNSBrowserEventTypeRemoveDomain
851 @constant kDNSBrowserEventTypeAddService
854 @constant kDNSBrowserEventTypeRemoveService
857 @constant kDNSBrowserEventTypeResolved
858 Name resolved. This is only delivered if the kDNSBrowserFlagAutoResolve option is used with
859 DNSBrowserStartServiceSearch.
862 typedef long DNSBrowserEventType
;
865 kDNSBrowserEventTypeInvalid
= 0,
866 kDNSBrowserEventTypeRelease
= 1,
867 kDNSBrowserEventTypeAddDomain
= 10,
868 kDNSBrowserEventTypeAddDefaultDomain
= 11,
869 kDNSBrowserEventTypeRemoveDomain
= 12,
870 kDNSBrowserEventTypeAddService
= 20,
871 kDNSBrowserEventTypeRemoveService
= 21,
872 kDNSBrowserEventTypeResolved
= 30
875 //---------------------------------------------------------------------------------------------------------------------------
876 /*! @struct DNSBrowserEventDomainData
878 @abstract Data structure referenced by callback routines when a domain-related event occurs.
881 Network interface that received the event.
884 Network interface that received the event. May be empty if interface is no longer available.
887 IP of network interface that received the event. May be invalid if interface is no longer available.
890 Ptr to UTF-8 string containing the domain name. NULL if no domain name is available or applicable.
893 Flags used to augment the event data.
896 typedef struct DNSBrowserEventDomainData DNSBrowserEventDomainData
;
897 struct DNSBrowserEventDomainData
900 const char * interfaceName
;
901 DNSNetworkAddress interfaceIP
;
903 DNSBrowserFlags flags
;
906 //---------------------------------------------------------------------------------------------------------------------------
907 /*! @struct DNSBrowserEventServiceData
909 @abstract Data structure passed to callback routines when a service-related event occurs.
912 Network interface that received the event.
915 Network interface that received the event. May be empty if interface is no longer available.
918 IP of network interface that received the event. May be invalid if interface is no longer available.
921 Ptr to UTF-8 string containing the service name. NULL if no service name is available or applicable.
924 Ptr to UTF-8 string containing the service type. NULL if no service type is available or applicable.
927 Ptr to UTF-8 string containing the domain name. NULL if no domain name is available or applicable.
930 Flags used to augment the event data.
933 typedef struct DNSBrowserEventServiceData DNSBrowserEventServiceData
;
934 struct DNSBrowserEventServiceData
937 const char * interfaceName
;
938 DNSNetworkAddress interfaceIP
;
942 DNSBrowserFlags flags
;
945 //---------------------------------------------------------------------------------------------------------------------------
946 /*! @struct DNSBrowserEvent
948 @abstract Data structure passed to callback routines when a browser event occurs.
951 Type of event. The type determines which portion of the data union to use. Types and data union
952 fields are named such as the data union field is the same as the event type. For example, an
953 "add domain" event type (kDNSBrowserEventTypeAddDomain) would refer to data union field "addDomain".
956 Data associated with kDNSBrowserEventTypeAddDomain event.
958 @field addDefaultDomain
959 Data associated with kDNSBrowserEventTypeAddDefaultDomain event.
962 Data associated with kDNSBrowserEventTypeRemoveDomain event.
965 Data associated with kDNSBrowserEventTypeAddService event.
968 Data associated with kDNSBrowserEventTypeRemoveService event.
971 Data associated with kDNSBrowserEventTypeResolved event.
974 typedef struct DNSBrowserEvent DNSBrowserEvent
;
975 struct DNSBrowserEvent
977 DNSBrowserEventType type
;
981 DNSBrowserEventDomainData addDomain
;
982 DNSBrowserEventDomainData addDefaultDomain
;
983 DNSBrowserEventDomainData removeDomain
;
984 DNSBrowserEventServiceData addService
;
985 DNSBrowserEventServiceData removeService
;
986 const DNSResolverEventResolveData
* resolved
;
991 //---------------------------------------------------------------------------------------------------------------------------
992 /*! @function DNSBrowserCallBack
994 @abstract CallBack routine used to indicate a browser event.
997 User-supplied context for callback (specified when browser is created).
1000 Reference to browser object generating the event.
1003 Status of the event.
1006 Data associated with the event.
1010 ( *DNSBrowserCallBack
)(
1012 DNSBrowserRef inRef
,
1013 DNSStatus inStatusCode
,
1014 const DNSBrowserEvent
* inEvent
);
1016 //---------------------------------------------------------------------------------------------------------------------------
1017 /*! @function DNSBrowserCreate
1019 @abstract Creates a browser object.
1022 Flags to control the creation process.
1025 CallBack routine to call when a browser event occurs.
1027 @param inCallBackContext
1028 Context pointer to pass to CallBack routine when an event occurs. Not inspected by DNS Services.
1031 Ptr to receive reference to the created browser object. May be null.
1033 @result Error code indicating failure reason or kDNSNoErr if successful.
1038 DNSBrowserFlags inFlags
,
1039 DNSBrowserCallBack inCallBack
,
1040 void * inCallBackContext
,
1041 DNSBrowserRef
* outRef
);
1043 //---------------------------------------------------------------------------------------------------------------------------
1044 /*! @function DNSBrowserRelease
1046 @abstract Releases a browser object.
1049 Reference to the browser object to release.
1052 Flags to control the release process.
1054 @result Error code indicating failure reason or kDNSNoErr if successful.
1057 DNSStatus
DNSBrowserRelease( DNSBrowserRef inRef
, DNSBrowserFlags inFlags
);
1059 //---------------------------------------------------------------------------------------------------------------------------
1060 /*! @function DNSBrowserStartDomainSearch
1062 @abstract Starts a domain name search.
1065 Reference to browser object to start the search on.
1068 Flags to control the search process.
1070 @result Error code indicating failure reason or kDNSNoErr if successful.
1073 DNSStatus
DNSBrowserStartDomainSearch( DNSBrowserRef inRef
, DNSBrowserFlags inFlags
);
1075 //---------------------------------------------------------------------------------------------------------------------------
1076 /*! @function DNSBrowserStopDomainSearch
1078 @abstract Stops a domain name search.
1081 Reference to browser object to stop the search on.
1084 Flags to control the stopping process.
1086 @result Error code indicating failure reason or kDNSNoErr if successful.
1089 DNSStatus
DNSBrowserStopDomainSearch( DNSBrowserRef inRef
, DNSBrowserFlags inFlags
);
1091 //---------------------------------------------------------------------------------------------------------------------------
1092 /*! @function DNSBrowserStartServiceSearch
1094 @abstract Starts a service search.
1097 Reference to browser object to start the search on.
1100 Flags to control the search process.
1103 Ptr to UTF-8 string containing the service type to search for (e.g. "_printer._tcp").
1106 Ptr to UTF-8 string containing the domain to search in (e.g. "apple.com"). Use NULL to indicate
1109 @result Error code indicating failure reason or kDNSNoErr if successful.
1113 DNSBrowserStartServiceSearch(
1114 DNSBrowserRef inRef
,
1115 DNSBrowserFlags inFlags
,
1116 const char * inType
,
1117 const char * inDomain
);
1119 //---------------------------------------------------------------------------------------------------------------------------
1120 /*! @function DNSBrowserStopServiceSearch
1122 @abstract Stops a service search.
1125 Reference to browser object to stop the search on.
1128 Flags to control the stopping process.
1130 @result Error code indicating failure reason or kDNSNoErr if successful.
1133 DNSStatus
DNSBrowserStopServiceSearch( DNSBrowserRef inRef
, DNSBrowserFlags inFlags
);
1136 #pragma mark == Registration ==
1139 //===========================================================================================================================
1141 //===========================================================================================================================
1143 //---------------------------------------------------------------------------------------------------------------------------
1144 /*! @typedef DNSRegistrationRef
1146 @abstract Reference to a DNS registration object.
1149 typedef struct DNSRegistration
* DNSRegistrationRef
;
1151 //---------------------------------------------------------------------------------------------------------------------------
1152 /*! @typedef DNSRegistrationRecordRef
1154 @abstract Reference to a DNS record object.
1157 typedef struct DNSRegistrationRecord
* DNSRegistrationRecordRef
;
1159 //---------------------------------------------------------------------------------------------------------------------------
1160 /*! @enum DNSRegistrationFlags
1162 @abstract Flags used to control registration operations.
1164 @constant kDNSRegistrationFlagPreFormattedTextRecord
1165 Text record is pre-formatted and should be used directly without interpretation.
1167 @constant kDNSRegistrationFlagAutoRenameOnConflict
1168 Automatically uniquely rename and re-register the service when a name conflict occurs.
1171 typedef DNSUInt32 DNSRegistrationFlags
;
1174 kDNSRegistrationFlagPreFormattedTextRecord
= ( 1 << 0 ),
1175 kDNSRegistrationFlagAutoRenameOnConflict
= ( 1 << 1 )
1178 //---------------------------------------------------------------------------------------------------------------------------
1179 /*! @enum DNSRecordFlags
1181 @abstract Flags used to control record operations.
1184 typedef DNSUInt32 DNSRecordFlags
;
1186 //---------------------------------------------------------------------------------------------------------------------------
1187 /*! @enum DNSRegistrationEventType
1189 @abstract Type of registration event being delivered.
1191 @constant kDNSResolverEventTypeInvalid
1192 Invalid event type. Here for completeness.
1194 @constant kDNSRegistrationEventTypeRelease
1195 Object is being released. No additional data is associated with this event.
1197 @constant kDNSRegistrationEventTypeRegistered
1198 Name has been successfully registered.
1200 @constant kDNSRegistrationEventTypeNameCollision
1201 Name collision. The registration is no longer valid. A new registration must be created if needed.
1204 typedef long DNSRegistrationEventType
;
1207 kDNSRegistrationEventTypeInvalid
= 0,
1208 kDNSRegistrationEventTypeRelease
= 1,
1209 kDNSRegistrationEventTypeRegistered
= 10,
1210 kDNSRegistrationEventTypeNameCollision
= 11
1213 //---------------------------------------------------------------------------------------------------------------------------
1214 /*! @struct DNSRegistrationEvent
1216 @abstract Data structure passed to callback routines when a registration event occurs.
1219 Type of event. The type determines which portion of the data union to use. Types and data union
1220 fields are named such as the data union field is the same as the event type.
1223 Reserved for future use.
1226 typedef struct DNSRegistrationEvent DNSRegistrationEvent
;
1227 struct DNSRegistrationEvent
1229 DNSRegistrationEventType type
;
1238 //---------------------------------------------------------------------------------------------------------------------------
1239 /*! @function DNSRegistrationCallBack
1241 @abstract CallBack routine used to indicate a registration event.
1244 User-supplied context for callback (specified when registration is created).
1247 Reference to registration object generating the event.
1250 Status of the event.
1253 Data associated with the event.
1257 ( *DNSRegistrationCallBack
)(
1259 DNSRegistrationRef inRef
,
1260 DNSStatus inStatusCode
,
1261 const DNSRegistrationEvent
* inEvent
);
1263 //---------------------------------------------------------------------------------------------------------------------------
1264 /*! @function DNSRegistrationCreate
1266 @abstract Creates a registration object and publish the registration.
1269 Flags to control the registration process.
1272 Ptr to UTF-8 string containing the service name to register (e.g. "My Printer").
1275 Ptr to UTF-8 string containing the service type of the service to registration (e.g. "_printer._tcp").
1278 Ptr to UTF-8 string containing the domain of the service to register (e.g. "apple.com"). Use NULL
1279 to indicate the local domain.
1282 TCP/UDP port where the service is being offered (e.g. 80 for an HTTP service).
1285 Ptr to UTF-8 string containing any additional text to provide when the service is resolved.
1287 @param inTextRecordSize
1288 Size to text record.
1291 Name of the host to associate with the registration. Use NULL to use the default host name.
1293 @field inInterfaceName
1294 Name of an interface to restrict service registration to. Use NULL to register service on all interfaces.
1297 CallBack routine to call when a registration event occurs.
1299 @param inCallBackContext
1300 Context pointer to pass to CallBack routine when an event occurs. Not inspected by DNS Services.
1303 Ptr to receive reference to registration object. May be null.
1305 @result Error code indicating failure reason or kDNSNoErr if successful.
1309 DNSRegistrationCreate(
1310 DNSRegistrationFlags inFlags
,
1311 const char * inName
,
1312 const char * inType
,
1313 const char * inDomain
,
1315 const void * inTextRecord
,
1316 DNSCount inTextRecordSize
,
1317 const char * inHost
,
1318 const char * inInterfaceName
,
1319 DNSRegistrationCallBack inCallBack
,
1320 void * inCallBackContext
,
1321 DNSRegistrationRef
* outRef
);
1323 //---------------------------------------------------------------------------------------------------------------------------
1324 /*! @function DNSNoSuchServiceRegistrationCreate
1326 @abstract Creates a registration object and publish the registration to assert non-existence of a particular service.
1329 Flags to control the registration process.
1332 Ptr to UTF-8 string containing the service name to register (e.g. "My Printer").
1335 Ptr to UTF-8 string containing the service type of the service to registration (e.g. "_printer._tcp").
1338 Ptr to UTF-8 string containing the domain of the service to register (e.g. "apple.com"). Use NULL
1339 to indicate the local domain.
1341 @field inInterfaceName
1342 Name of an interface to restrict service registration to. Use NULL to register service on all interfaces.
1345 CallBack routine to call when a registration event occurs.
1347 @param inCallBackContext
1348 Context pointer to pass to CallBack routine when an event occurs. Not inspected by DNS Services.
1351 Ptr to receive reference to registration object. May be null.
1353 @result Error code indicating failure reason or kDNSNoErr if successful.
1357 DNSNoSuchServiceRegistrationCreate(
1358 DNSRegistrationFlags inFlags
,
1359 const char * inName
,
1360 const char * inType
,
1361 const char * inDomain
,
1362 const char * inInterfaceName
,
1363 DNSRegistrationCallBack inCallBack
,
1364 void * inCallBackContext
,
1365 DNSRegistrationRef
* outRef
);
1367 //---------------------------------------------------------------------------------------------------------------------------
1368 /*! @function DNSRegistrationRelease
1370 @abstract Releases a registration object.
1373 Reference to the registration object to release.
1376 Flags to control the release process.
1378 @result Error code indicating failure reason or kDNSNoErr if successful.
1381 DNSStatus
DNSRegistrationRelease( DNSRegistrationRef inRef
, DNSRegistrationFlags inFlags
);
1383 //---------------------------------------------------------------------------------------------------------------------------
1384 /*! @function DNSRegistrationUpdate
1386 @abstract Updates an individual record for a registration.
1389 Reference to the registration object to update.
1392 Record to update. Use NULL for the standard TXT record.
1398 Size of new record data.
1401 New time-to-live (TTL) in seconds for the updated data (e.g. 120 for 2 minutes).
1403 @result Error code indicating failure reason or kDNSNoErr if successful.
1407 DNSRegistrationUpdate(
1408 DNSRegistrationRef inRef
,
1409 DNSRecordFlags inFlags
,
1410 DNSRegistrationRecordRef inRecord
,
1411 const void * inData
,
1413 DNSUInt32 inNewTTL
);
1416 #pragma mark == Domain Registration ==
1419 //===========================================================================================================================
1420 // Domain Registration
1421 //===========================================================================================================================
1423 //---------------------------------------------------------------------------------------------------------------------------
1424 /*! @typedef DNSDomainRegistrationRef
1426 @abstract Reference to a DNS registration object.
1429 typedef struct DNSDomainRegistration
* DNSDomainRegistrationRef
;
1431 //---------------------------------------------------------------------------------------------------------------------------
1432 /*! @enum DNSDomainRegistrationFlags
1434 @abstract Flags used to control registration operations.
1437 typedef DNSUInt32 DNSDomainRegistrationFlags
;
1440 kDNSDomainRegistrationFlagNone
= 0
1443 //---------------------------------------------------------------------------------------------------------------------------
1444 /*! @enum DNSDomainRegistrationType
1446 @abstract Type of domain registration.
1448 @constant kDNSDomainRegistrationTypeBrowse
1449 Registration for domain browsing.
1451 @constant kDNSDomainRegistrationTypeBrowseDefault
1452 Registration for the domain browsing domain.
1454 @constant kDNSDomainRegistrationTypeRegistration
1455 Registration for domain registration.
1457 @constant kDNSDomainRegistrationTypeRegistrationDefault
1458 Registration for the domain registration domain.
1461 typedef DNSUInt32 DNSDomainRegistrationType
;
1464 kDNSDomainRegistrationTypeBrowse
= 0,
1465 kDNSDomainRegistrationTypeBrowseDefault
= 1,
1466 kDNSDomainRegistrationTypeRegistration
= 2,
1467 kDNSDomainRegistrationTypeRegistrationDefault
= 3,
1469 kDNSDomainRegistrationTypeMax
= 4
1472 //---------------------------------------------------------------------------------------------------------------------------
1473 /*! @function DNSDomainRegistrationCreate
1475 @abstract Creates a domain registration object and publish the domain.
1478 Flags to control the registration process.
1481 Ptr to string containing the domain name to register (e.g. "apple.com").
1484 Type of domain registration.
1487 Ptr to receive reference to domain registration object. May be null.
1489 @result Error code indicating failure reason or kDNSNoErr if successful.
1493 DNSDomainRegistrationCreate(
1494 DNSDomainRegistrationFlags inFlags
,
1495 const char * inName
,
1496 DNSDomainRegistrationType inType
,
1497 DNSDomainRegistrationRef
* outRef
);
1499 //---------------------------------------------------------------------------------------------------------------------------
1500 /*! @function DNSDomainRegistrationRelease
1502 @abstract Releases a domain registration object.
1505 Reference to the domain registration object to release.
1508 Flags to control the release process.
1510 @result Error code indicating failure reason or kDNSNoErr if successful.
1513 DNSStatus
DNSDomainRegistrationRelease( DNSDomainRegistrationRef inRef
, DNSDomainRegistrationFlags inFlags
);
1516 #pragma mark == Host Registration ==
1519 //===========================================================================================================================
1520 // Host Registration
1521 //===========================================================================================================================
1523 //---------------------------------------------------------------------------------------------------------------------------
1524 /*! @typedef DNSHostRegistrationRef
1526 @abstract Reference to a DNS host registration object.
1529 typedef struct DNSHostRegistration
* DNSHostRegistrationRef
;
1531 //---------------------------------------------------------------------------------------------------------------------------
1532 /*! @enum DNSHostRegistrationFlags
1534 @abstract Flags used to control registration operations.
1536 @constant kDNSHostRegistrationFlagOnlyIfNotFound
1537 Only creates the object and registers the host if it was not already found in the list.
1539 @constant kDNSHostRegistrationFlagAutoRenameOnConflict
1540 Automatically uniquely rename and re-register the host when a name conflict occurs.
1544 typedef DNSUInt32 DNSHostRegistrationFlags
;
1547 kDNSHostRegistrationFlagNone
= 0,
1548 kDNSHostRegistrationFlagOnlyIfNotFound
= ( 1 << 0 ),
1549 kDNSHostRegistrationFlagAutoRenameOnConflict
= ( 1 << 1 )
1552 //---------------------------------------------------------------------------------------------------------------------------
1553 /*! @function DNSHostRegistrationCallBack
1555 @abstract CallBack routine used to indicate a host registration event.
1558 User-supplied context for callback (specified when browser is created).
1561 Reference to resolver object generating the event.
1564 Status of the event.
1567 Data associated with the event.
1571 ( *DNSHostRegistrationCallBack
)(
1573 DNSHostRegistrationRef inRef
,
1574 DNSStatus inStatusCode
,
1577 //---------------------------------------------------------------------------------------------------------------------------
1578 /*! @function DNSHostRegistrationCreate
1580 @abstract Creates a host registration object and publishes the host.
1583 Flags to control the registration process.
1586 Name of the host to register (e.g. "My Web Server").
1589 Domain of the host to register (e.g. "apple.com"). Use NULL to indicate the local domain.
1592 IP address of host to register.
1594 @field inInterfaceName
1595 Name of an interface to restrict registration to. Use NULL to register on all interfaces.
1598 CallBack routine to call when an event occurs.
1600 @param inCallBackContext
1601 Context pointer to pass to callback routine when an event occurs. Not inspected by DNS Services.
1604 Ptr to receive reference to host registration object. May be null.
1606 @result Error code indicating failure reason or kDNSNoErr if successful.
1610 DNSHostRegistrationCreate(
1611 DNSHostRegistrationFlags inFlags
,
1612 const char * inName
,
1613 const char * inDomain
,
1614 const DNSNetworkAddress
* inAddr
,
1615 const char * inInterfaceName
,
1616 DNSHostRegistrationCallBack inCallBack
,
1617 void * inCallBackContext
,
1618 DNSHostRegistrationRef
* outRef
);
1620 //---------------------------------------------------------------------------------------------------------------------------
1621 /*! @function DNSHostRegistrationRelease
1623 @abstract Releases a host registration object.
1626 Reference to the host registration object to release.
1629 Flags to control the release process.
1631 @result Error code indicating failure reason or kDNSNoErr if successful.
1634 DNSStatus
DNSHostRegistrationRelease( DNSHostRegistrationRef inRef
, DNSHostRegistrationFlags inFlags
);
1637 #pragma mark == Utilities ==
1640 //---------------------------------------------------------------------------------------------------------------------------
1641 /*! @defined kDNSTextRecordNoValue
1643 @abstract Value to use when no value is desired for a name/value pair (e.g. "color" instead of "color=").
1646 #define kDNSTextRecordNoValue ( (const void *) -1 )
1648 //---------------------------------------------------------------------------------------------------------------------------
1649 /*! @defined kDNSTextRecordStringNoValue
1651 @abstract Value to use when no value is desired for a name/value pair (e.g. "color" instead of "color=").
1654 #define kDNSTextRecordStringNoValue ( (const char *) -1 )
1656 //---------------------------------------------------------------------------------------------------------------------------
1657 /*! @defined kDNSTextRecordNoValue
1659 @abstract Size value to use when no value is desired for a name/value pair (e.g. "color" instead of "color=").
1662 #define kDNSTextRecordNoSize ( (size_t) -1 )
1664 //---------------------------------------------------------------------------------------------------------------------------
1665 /*! @function DNSDynamicTextRecordBuildEscaped
1667 @abstract Builds a TXT record from a string with \001 escape sequences to separate strings within the TXT record.
1669 @param inFormat C-string TXT record with \001 escape sequences as record separators.
1670 @param outTextRecord Receives a ptr to a built TXT record. Must free with DNSDynamicTextRecordRelease.
1671 @param outSize Receive actual size of the built TXT record. Use NULL if you don't need the size.
1673 @result Error code indicating failure reason or kDNSNoErr if successful.
1677 A DNS TXT record consists of a packed array of length-prefixed strings with each string being up to 255 characters.
1678 To allow this to be described with a null-terminated C-string, a special escape sequence of \001 is used to separate
1679 individual character strings within the C-string.
1681 For example, to represent the following 3 segments "test1=1", "test2=2", and "test3=3", you would use the following:
1688 err = DNSDynamicTextRecordBuildEscaped( "test1=1\001test2=2\001test3=3", &txt, &size );
1689 require_noerr( err, exit );
1694 DNSDynamicTextRecordRelease( txt );
1697 DNSStatus
DNSDynamicTextRecordBuildEscaped( const char *inFormat
, void *outTextRecord
, size_t *outSize
);
1699 //---------------------------------------------------------------------------------------------------------------------------
1700 /*! @function DNSDynamicTextRecordAppendCString
1702 @abstract Appends a name/value pair with the value being a C-string to a dynamic DNS TXT record data section.
1704 @param ioTxt Input: Ptr to a ptr to TXT record to append to.
1705 Output: Receives newly allocated ptr to the new TXT record.
1706 Note: Use a ptr to NULL the first time this is called.
1708 @param ioTxtSize Input: Ptr to size of existing TXT record.
1709 Output: Receives new size of TXT record.
1711 @param inName C-string name in the name/value pair (e.g. "path" for HTTP).
1713 @param inValue C-string value in the name/value pair (e.g. "/index.html for HTTP).
1715 @result Error code indicating failure reason or kDNSNoErr if successful.
1719 This can be used to easily build dynamically-resized TXT records containing multiple name/value pairs of C-strings.
1720 For example, the following adds "name=Ryknow", "age=30", and "job=Musician":
1728 err = DNSDynamicTextRecordAppendCString( &txt, &size, "name", "Ryknow" );
1729 require_noerr( err, exit );
1731 err = DNSDynamicTextRecordAppendCString( &txt, &size, "age", "30" );
1732 require_noerr( err, exit );
1734 err = DNSDynamicTextRecordAppendCString( &txt, &size, "job", "Musician" );
1735 require_noerr( err, exit );
1740 DNSDynamicTextRecordRelease( txt );
1743 DNSStatus
DNSDynamicTextRecordAppendCString( void *ioTxt
, size_t *ioTxtSize
, const char *inName
, const char *inValue
);
1745 //---------------------------------------------------------------------------------------------------------------------------
1746 /*! @function DNSDynamicTextRecordAppendData
1748 @abstract Appends a name/value pair to a dynamic DNS TXT record data section.
1750 @param ioTxt Input: Ptr to a ptr to TXT record to append to.
1751 Output: Receives newly allocated ptr to the new TXT record.
1752 Note: Use a ptr to NULL the first time this is called.
1754 @param ioTxtSize Input: Ptr to size of existing TXT record.
1755 Output: Receives new size of TXT record.
1757 @param inName C-string name in the name/value pair (e.g. "path" for HTTP).
1759 @param inValue Value data to associate with the name. Use kDNSTextRecordNoValue for no value.
1761 @param inValueSize Size of value data. Use kDNSTextRecordNoSize for no value.
1763 @result Error code indicating failure reason or kDNSNoErr if successful.
1767 DNSDynamicTextRecordAppendData(
1770 const char * inName
,
1771 const void * inValue
,
1772 size_t inValueSize
);
1774 //---------------------------------------------------------------------------------------------------------------------------
1775 /*! @function DNSDynamicTextRecordRelease
1777 @abstract Releases a dynamically allocated TXT record.
1779 @param inTxt Dynamic TXT record to release.
1783 This API may only be used with TXT records generated with DNSDynamicTextRecordAppendCString and
1784 DNSDynamicTextRecordAppendData.
1787 void DNSDynamicTextRecordRelease( void *inTxt
);
1789 //---------------------------------------------------------------------------------------------------------------------------
1790 /*! @function DNSTextRecordAppendCString
1792 @abstract Appends a name/value pair with the value being a C-string to DNS TXT record data section.
1794 @param inTxt TXT record to append to.
1795 @param inTxtSize Size of existing TXT record.
1796 @param inTxtMaxSize Maximum size of TXT record (i.e. size of buffer).
1797 @param inName C-string name in the name/value pair (e.g. "path" for HTTP).
1798 @param inValue C-string value in the name/value pair (e.g. "/index.html for HTTP).
1799 @param outTxtSize Receives resulting size of TXT record. Pass NULL if not needed.
1801 @result Error code indicating failure reason or kDNSNoErr if successful.
1805 This can be used to easily build TXT records containing multiple name/value pairs of C-strings. For example, the
1806 following adds "name=Ryknow", "age=30", and "job=Musician":
1808 DNSUInt8 txt[ 256 ];
1813 err = DNSTextRecordAppendCString( txt, size, sizeof( txt ), "name", "Ryknow", &size );
1814 require_noerr( err, exit );
1816 err = DNSTextRecordAppendCString( txt, size, sizeof( txt ), "age", "30", &size );
1817 require_noerr( err, exit );
1819 err = DNSTextRecordAppendCString( txt, size, sizeof( txt ), "job", "Musician", &size );
1820 require_noerr( err, exit );
1824 DNSTextRecordAppendCString(
1827 size_t inTxtMaxSize
,
1828 const char * inName
,
1829 const char * inValue
,
1830 size_t * outTxtSize
);
1832 //---------------------------------------------------------------------------------------------------------------------------
1833 /*! @function DNSTextRecordAppendData
1835 @abstract Appends a name/value pair to a DNS TXT record data section.
1837 @param inTxt TXT record to append to.
1838 @param inTxtSize Size of existing TXT record.
1839 @param inTxtMaxSize Maximum size of TXT record (i.e. size of buffer).
1840 @param inName C-string name in the name/value pair (e.g. "path" for HTTP).
1841 @param inValue Value data to associate with the name. Use kDNSTextRecordNoValue for no value.
1842 @param inValueSize Size of value data. Use kDNSTextRecordNoSize for no value.
1843 @param outTxtSize Receives resulting size of TXT record. Pass NULL if not needed.
1845 @result Error code indicating failure reason or kDNSNoErr if successful.
1849 DNSTextRecordAppendData(
1852 size_t inTxtMaxSize
,
1853 const char * inName
,
1854 const void * inValue
,
1856 size_t * outTxtSize
);
1858 //---------------------------------------------------------------------------------------------------------------------------
1859 /*! @function DNSTextRecordEscape
1861 @abstract Converts a raw TXT record into a single, null-terminated string with \001 to delimit records.
1863 @param inTextRecord Raw TXT record to escape.
1864 @param inTextSize Number of bytes in the raw TXT record to escape.
1865 @param outEscapedString Receives ptr to escaped, \001-delimited, null-terminated string.
1867 @result Error code indicating failure reason or kDNSNoErr if successful.
1870 DNSStatus
DNSTextRecordEscape( const void *inTextRecord
, size_t inTextSize
, char **outEscapedString
);
1872 //---------------------------------------------------------------------------------------------------------------------------
1873 /*! @function DNSNameValidate
1875 @abstract Validates a DNS name for correctness.
1877 @param inName C-string DNS name to validate.
1879 @result Error code indicating failure reason or kDNSNoErr if valid.
1882 DNSStatus
DNSNameValidate( const char *inName
);
1884 //---------------------------------------------------------------------------------------------------------------------------
1885 /*! @function DNSServiceTypeValidate
1887 @abstract Validates a service type for correctness.
1889 @param inServiceType C-string service type to validate.
1891 @result Error code indicating failure reason or kDNSNoErr if valid.
1894 DNSStatus
DNSServiceTypeValidate( const char *inServiceType
);
1896 //---------------------------------------------------------------------------------------------------------------------------
1897 /*! @function DNSTextRecordValidate
1899 @abstract Validates a text record for correctness and optionally builds the TXT reocrd, and returns the actual size.
1901 @param inText C-string TXT record to validate. Use \001 escape sequence as record separator.
1902 @param inMaxSize Maximum size of the TXT record. Use a large number if a max size is not appropriate.
1903 @param outRecord Buffer to receive built TXT record. Use NULL if you don't need a built TXT record.
1904 @param outActualSize Ptr to receive actual size of TXT record. Use NULL if you don't need the actual size.
1906 @result Error code indicating failure reason or kDNSNoErr if valid.
1910 A DNS TXT record consists of a packed array of length-prefixed strings with each string being up to 255 characters.
1911 To allow this to be described with a null-terminated C-string, a special escape sequence of \001 is used to separate
1912 individual character strings within the C-string.
1914 For example, to represent the following 3 segments "test1=1", "test2=2", and "test3=3", you would use the following:
1916 "test1=1\001test2=2\001test3=3"
1919 DNSStatus
DNSTextRecordValidate( const char *inText
, size_t inMaxSize
, void *outRecord
, size_t *outActualSize
);
1925 #endif // __DNS_SERVICES__