/* -*- Mode: C; tab-width: 4 -*-1*2* Copyright (c) 2003-2004, Apple Computer, Inc. All rights reserved.3*4* Redistribution and use in source and binary forms, with or without5* modification, are permitted provided that the following conditions are met:6*7* 1. Redistributions of source code must retain the above copyright notice,8* this list of conditions and the following disclaimer.9* 2. Redistributions in binary form must reproduce the above copyright notice,10* this list of conditions and the following disclaimer in the documentation11* and/or other materials provided with the distribution.12* 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of its13* contributors may be used to endorse or promote products derived from this14* software without specific prior written permission.15*16* THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY17* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED18* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE19* DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY20* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES21* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;22* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND23* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT24* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS25* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.26*/272829/*! @header DNS Service Discovery30*31* @discussion This section describes the functions, callbacks, and data structures32* that make up the DNS Service Discovery API.33*34* The DNS Service Discovery API is part of Bonjour, Apple's implementation35* of zero-configuration networking (ZEROCONF).36*37* Bonjour allows you to register a network service, such as a38* printer or file server, so that it can be found by name or browsed39* for by service type and domain. Using Bonjour, applications can40* discover what services are available on the network, along with41* all the information -- such as name, IP address, and port --42* necessary to access a particular service.43*44* In effect, Bonjour combines the functions of a local DNS server and45* AppleTalk. Bonjour allows applications to provide user-friendly printer46* and server browsing, among other things, over standard IP networks.47* This behavior is a result of combining protocols such as multicast and48* DNS to add new functionality to the network (such as multicast DNS).49*50* Bonjour gives applications easy access to services over local IP51* networks without requiring the service or the application to support52* an AppleTalk or a Netbeui stack, and without requiring a DNS server53* for the local network.54*/555657/* _DNS_SD_H contains the mDNSResponder version number for this header file, formatted as follows:58* Major part of the build number * 10000 +59* minor part of the build number * 10060* For example, Mac OS X 10.4.9 has mDNSResponder-108.4, which would be represented as61* version 1080400. This allows C code to do simple greater-than and less-than comparisons:62* e.g. an application that requires the DNSServiceGetProperty() call (new in mDNSResponder-126) can check:63*64* #if _DNS_SD_H+0 >= 126000065* ... some C code that calls DNSServiceGetProperty() ...66* #endif67*68* The version defined in this header file symbol allows for compile-time69* checking, so that C code building with earlier versions of the header file70* can avoid compile errors trying to use functions that aren't even defined71* in those earlier versions. Similar checks may also be performed at run-time:72* => weak linking -- to avoid link failures if run with an earlier73* version of the library that's missing some desired symbol, or74* => DNSServiceGetProperty(DaemonVersion) -- to verify whether the running daemon75* ("system service" on Windows) meets some required minimum functionality level.76*/7778#ifndef _DNS_SD_H79#define _DNS_SD_H 33310008081#ifdef __cplusplus82extern "C" {83#endif8485/* Set to 1 if libdispatch is supported86* Note: May also be set by project and/or Makefile87*/88#ifndef _DNS_SD_LIBDISPATCH89#define _DNS_SD_LIBDISPATCH 090#endif /* ndef _DNS_SD_LIBDISPATCH */9192/* standard calling convention under Win32 is __stdcall */93/* Note: When compiling Intel EFI (Extensible Firmware Interface) under MS Visual Studio, the */94/* _WIN32 symbol is defined by the compiler even though it's NOT compiling code for Windows32 */95#if defined(_WIN32) && !defined(EFI32) && !defined(EFI64)96#define DNSSD_API __stdcall97#else98#define DNSSD_API99#endif100101/* stdint.h does not exist on FreeBSD 4.x; its types are defined in sys/types.h instead */102#if defined(__FreeBSD__) && (__FreeBSD__ < 5)103#include <sys/types.h>104105/* Likewise, on Sun, standard integer types are in sys/types.h */106#elif defined(__sun__)107#include <sys/types.h>108109/* EFI does not have stdint.h, or anything else equivalent */110#elif defined(EFI32) || defined(EFI64) || defined(EFIX64)111#include "Tiano.h"112#if !defined(_STDINT_H_)113typedef UINT8 uint8_t;114typedef INT8 int8_t;115typedef UINT16 uint16_t;116typedef INT16 int16_t;117typedef UINT32 uint32_t;118typedef INT32 int32_t;119#endif120/* Windows has its own differences */121#elif defined(_WIN32)122#include <windows.h>123#define _UNUSED124#ifndef _MSL_STDINT_H125typedef UINT8 uint8_t;126typedef INT8 int8_t;127typedef UINT16 uint16_t;128typedef INT16 int16_t;129typedef UINT32 uint32_t;130typedef INT32 int32_t;131#endif132133/* All other Posix platforms use stdint.h */134#else135#include <stdint.h>136#endif137138#if _DNS_SD_LIBDISPATCH139#include <dispatch/dispatch.h>140#endif141142/* DNSServiceRef, DNSRecordRef143*144* Opaque internal data types.145* Note: client is responsible for serializing access to these structures if146* they are shared between concurrent threads.147*/148149typedef struct _DNSServiceRef_t *DNSServiceRef;150typedef struct _DNSRecordRef_t *DNSRecordRef;151152struct sockaddr;153154/*! @enum General flags155* Most DNS-SD API functions and callbacks include a DNSServiceFlags parameter.156* As a general rule, any given bit in the 32-bit flags field has a specific fixed meaning,157* regardless of the function or callback being used. For any given function or callback,158* typically only a subset of the possible flags are meaningful, and all others should be zero.159* The discussion section for each API call describes which flags are valid for that call160* and callback. In some cases, for a particular call, it may be that no flags are currently161* defined, in which case the DNSServiceFlags parameter exists purely to allow future expansion.162* In all cases, developers should expect that in future releases, it is possible that new flag163* values will be defined, and write code with this in mind. For example, code that tests164* if (flags == kDNSServiceFlagsAdd) ...165* will fail if, in a future release, another bit in the 32-bit flags field is also set.166* The reliable way to test whether a particular bit is set is not with an equality test,167* but with a bitwise mask:168* if (flags & kDNSServiceFlagsAdd) ...169*/170enum171{172kDNSServiceFlagsMoreComing = 0x1,173/* MoreComing indicates to a callback that at least one more result is174* queued and will be delivered following immediately after this one.175* When the MoreComing flag is set, applications should not immediately176* update their UI, because this can result in a great deal of ugly flickering177* on the screen, and can waste a great deal of CPU time repeatedly updating178* the screen with content that is then immediately erased, over and over.179* Applications should wait until until MoreComing is not set, and then180* update their UI when no more changes are imminent.181* When MoreComing is not set, that doesn't mean there will be no more182* answers EVER, just that there are no more answers immediately183* available right now at this instant. If more answers become available184* in the future they will be delivered as usual.185*/186187kDNSServiceFlagsAdd = 0x2,188kDNSServiceFlagsDefault = 0x4,189/* Flags for domain enumeration and browse/query reply callbacks.190* "Default" applies only to enumeration and is only valid in191* conjunction with "Add". An enumeration callback with the "Add"192* flag NOT set indicates a "Remove", i.e. the domain is no longer193* valid.194*/195196kDNSServiceFlagsNoAutoRename = 0x8,197/* Flag for specifying renaming behavior on name conflict when registering198* non-shared records. By default, name conflicts are automatically handled199* by renaming the service. NoAutoRename overrides this behavior - with this200* flag set, name conflicts will result in a callback. The NoAutorename flag201* is only valid if a name is explicitly specified when registering a service202* (i.e. the default name is not used.)203*/204205kDNSServiceFlagsShared = 0x10,206kDNSServiceFlagsUnique = 0x20,207/* Flag for registering individual records on a connected208* DNSServiceRef. Shared indicates that there may be multiple records209* with this name on the network (e.g. PTR records). Unique indicates that the210* record's name is to be unique on the network (e.g. SRV records).211*/212213kDNSServiceFlagsBrowseDomains = 0x40,214kDNSServiceFlagsRegistrationDomains = 0x80,215/* Flags for specifying domain enumeration type in DNSServiceEnumerateDomains.216* BrowseDomains enumerates domains recommended for browsing, RegistrationDomains217* enumerates domains recommended for registration.218*/219220kDNSServiceFlagsLongLivedQuery = 0x100,221/* Flag for creating a long-lived unicast query for the DNSServiceQueryRecord call. */222223kDNSServiceFlagsAllowRemoteQuery = 0x200,224/* Flag for creating a record for which we will answer remote queries225* (queries from hosts more than one hop away; hosts not directly connected to the local link).226*/227228kDNSServiceFlagsForceMulticast = 0x400,229/* Flag for signifying that a query or registration should be performed exclusively via multicast230* DNS, even for a name in a domain (e.g. foo.apple.com.) that would normally imply unicast DNS.231*/232233kDNSServiceFlagsForce = 0x800,234/* Flag for signifying a "stronger" variant of an operation.235* Currently defined only for DNSServiceReconfirmRecord(), where it forces a record to236* be removed from the cache immediately, instead of querying for a few seconds before237* concluding that the record is no longer valid and then removing it. This flag should238* be used with caution because if a service browsing PTR record is indeed still valid239* on the network, forcing its removal will result in a user-interface flap -- the240* discovered service instance will disappear, and then re-appear moments later.241*/242243kDNSServiceFlagsReturnIntermediates = 0x1000,244/* Flag for returning intermediate results.245* For example, if a query results in an authoritative NXDomain (name does not exist)246* then that result is returned to the client. However the query is not implicitly247* cancelled -- it remains active and if the answer subsequently changes248* (e.g. because a VPN tunnel is subsequently established) then that positive249* result will still be returned to the client.250* Similarly, if a query results in a CNAME record, then in addition to following251* the CNAME referral, the intermediate CNAME result is also returned to the client.252* When this flag is not set, NXDomain errors are not returned, and CNAME records253* are followed silently without informing the client of the intermediate steps.254* (In earlier builds this flag was briefly calledkDNSServiceFlagsReturnCNAME)255*/256257kDNSServiceFlagsNonBrowsable = 0x2000,258/* A service registered with the NonBrowsable flag set can be resolved using259* DNSServiceResolve(), but will not be discoverable using DNSServiceBrowse().260* This is for cases where the name is actually a GUID; it is found by other means;261* there is no end-user benefit to browsing to find a long list of opaque GUIDs.262* Using the NonBrowsable flag creates SRV+TXT without the cost of also advertising263* an associated PTR record.264*/265266kDNSServiceFlagsShareConnection = 0x4000,267/* For efficiency, clients that perform many concurrent operations may want to use a268* single Unix Domain Socket connection with the background daemon, instead of having a269* separate connection for each independent operation. To use this mode, clients first270* call DNSServiceCreateConnection(&MainRef) to initialize the main DNSServiceRef.271* For each subsequent operation that is to share that same connection, the client copies272* the MainRef, and then passes the address of that copy, setting the ShareConnection flag273* to tell the library that this DNSServiceRef is not a typical uninitialized DNSServiceRef;274* it's a copy of an existing DNSServiceRef whose connection information should be reused.275*276* For example:277*278* DNSServiceErrorType error;279* DNSServiceRef MainRef;280* error = DNSServiceCreateConnection(&MainRef);281* if (error) ...282* DNSServiceRef BrowseRef = MainRef; // Important: COPY the primary DNSServiceRef first...283* error = DNSServiceBrowse(&BrowseRef, kDNSServiceFlagsShareConnection, ...); // then use the copy284* if (error) ...285* ...286* DNSServiceRefDeallocate(BrowseRef); // Terminate the browse operation287* DNSServiceRefDeallocate(MainRef); // Terminate the shared connection288*289* Notes:290*291* 1. Collective kDNSServiceFlagsMoreComing flag292* When callbacks are invoked using a shared DNSServiceRef, the293* kDNSServiceFlagsMoreComing flag applies collectively to *all* active294* operations sharing the same parent DNSServiceRef. If the MoreComing flag is295* set it means that there are more results queued on this parent DNSServiceRef,296* but not necessarily more results for this particular callback function.297* The implication of this for client programmers is that when a callback298* is invoked with the MoreComing flag set, the code should update its299* internal data structures with the new result, and set a variable indicating300* that its UI needs to be updated. Then, later when a callback is eventually301* invoked with the MoreComing flag not set, the code should update *all*302* stale UI elements related to that shared parent DNSServiceRef that need303* updating, not just the UI elements related to the particular callback304* that happened to be the last one to be invoked.305*306* 2. Canceling operations and kDNSServiceFlagsMoreComing307* Whenever you cancel any operation for which you had deferred UI updates308* waiting because of a kDNSServiceFlagsMoreComing flag, you should perform309* those deferred UI updates. This is because, after cancelling the operation,310* you can no longer wait for a callback *without* MoreComing set, to tell311* you do perform your deferred UI updates (the operation has been canceled,312* so there will be no more callbacks). An implication of the collective313* kDNSServiceFlagsMoreComing flag for shared connections is that this314* guideline applies more broadly -- any time you cancel an operation on315* a shared connection, you should perform all deferred UI updates for all316* operations sharing that connection. This is because the MoreComing flag317* might have been referring to events coming for the operation you canceled,318* which will now not be coming because the operation has been canceled.319*320* 3. Only share DNSServiceRef's created with DNSServiceCreateConnection321* Calling DNSServiceCreateConnection(&ref) creates a special shareable DNSServiceRef.322* DNSServiceRef's created by other calls like DNSServiceBrowse() or DNSServiceResolve()323* cannot be shared by copying them and using kDNSServiceFlagsShareConnection.324*325* 4. Don't Double-Deallocate326* Calling DNSServiceRefDeallocate(ref) for a particular operation's DNSServiceRef terminates327* just that operation. Calling DNSServiceRefDeallocate(ref) for the main shared DNSServiceRef328* (the parent DNSServiceRef, originally created by DNSServiceCreateConnection(&ref))329* automatically terminates the shared connection and all operations that were still using it.330* After doing this, DO NOT then attempt to deallocate any remaining subordinate DNSServiceRef's.331* The memory used by those subordinate DNSServiceRef's has already been freed, so any attempt332* to do a DNSServiceRefDeallocate (or any other operation) on them will result in accesses333* to freed memory, leading to crashes or other equally undesirable results.334*335* 5. Thread Safety336* The dns_sd.h API does not presuppose any particular threading model, and consequently337* does no locking of its own (which would require linking some specific threading library).338* If client code calls API routines on the same DNSServiceRef concurrently339* from multiple threads, it is the client's responsibility to use a mutext340* lock or take similar appropriate precautions to serialize those calls.341*/342343kDNSServiceFlagsSuppressUnusable = 0x8000,344/*345* This flag is meaningful only in DNSServiceQueryRecord which suppresses unusable queries on the346* wire. If "hostname" is a wide-area unicast DNS hostname (i.e. not a ".local." name)347* but this host has no routable IPv6 address, then the call will not try to look up IPv6 addresses348* for "hostname", since any addresses it found would be unlikely to be of any use anyway. Similarly,349* if this host has no routable IPv4 address, the call will not try to look up IPv4 addresses for350* "hostname".351*/352353kDNSServiceFlagsTimeout = 0x10000,354/*355* When kDNServiceFlagsTimeout is passed to DNSServiceQueryRecord or DNSServiceGetAddrInfo, the query is356* stopped after a certain number of seconds have elapsed. The time at which the query will be stopped357* is determined by the system and cannot be configured by the user. The query will be stopped irrespective358* of whether a response was given earlier or not. When the query is stopped, the callback will be called359* with an error code of kDNSServiceErr_Timeout and a NULL sockaddr will be returned for DNSServiceGetAddrInfo360* and zero length rdata will be returned for DNSServiceQueryRecord.361*/362363kDNSServiceFlagsIncludeP2P = 0x20000,364/*365* Include P2P interfaces when kDNSServiceInterfaceIndexAny is specified.366* By default, specifying kDNSServiceInterfaceIndexAny does not include P2P interfaces.367*/368kDNSServiceFlagsWakeOnResolve = 0x40000369/*370* This flag is meaningful only in DNSServiceResolve. When set, it tries to send a magic packet371* to wake up the client.372*/373};374375/* Possible protocols for DNSServiceNATPortMappingCreate(). */376enum377{378kDNSServiceProtocol_IPv4 = 0x01,379kDNSServiceProtocol_IPv6 = 0x02,380/* 0x04 and 0x08 reserved for future internetwork protocols */381382kDNSServiceProtocol_UDP = 0x10,383kDNSServiceProtocol_TCP = 0x20384/* 0x40 and 0x80 reserved for future transport protocols, e.g. SCTP [RFC 2960]385* or DCCP [RFC 4340]. If future NAT gateways are created that support port386* mappings for these protocols, new constants will be defined here.387*/388};389390/*391* The values for DNS Classes and Types are listed in RFC 1035, and are available392* on every OS in its DNS header file. Unfortunately every OS does not have the393* same header file containing DNS Class and Type constants, and the names of394* the constants are not consistent. For example, BIND 8 uses "T_A",395* BIND 9 uses "ns_t_a", Windows uses "DNS_TYPE_A", etc.396* For this reason, these constants are also listed here, so that code using397* the DNS-SD programming APIs can use these constants, so that the same code398* can compile on all our supported platforms.399*/400401enum402{403kDNSServiceClass_IN = 1 /* Internet */404};405406enum407{408kDNSServiceType_A = 1, /* Host address. */409kDNSServiceType_NS = 2, /* Authoritative server. */410kDNSServiceType_MD = 3, /* Mail destination. */411kDNSServiceType_MF = 4, /* Mail forwarder. */412kDNSServiceType_CNAME = 5, /* Canonical name. */413kDNSServiceType_SOA = 6, /* Start of authority zone. */414kDNSServiceType_MB = 7, /* Mailbox domain name. */415kDNSServiceType_MG = 8, /* Mail group member. */416kDNSServiceType_MR = 9, /* Mail rename name. */417kDNSServiceType_NULL = 10, /* Null resource record. */418kDNSServiceType_WKS = 11, /* Well known service. */419kDNSServiceType_PTR = 12, /* Domain name pointer. */420kDNSServiceType_HINFO = 13, /* Host information. */421kDNSServiceType_MINFO = 14, /* Mailbox information. */422kDNSServiceType_MX = 15, /* Mail routing information. */423kDNSServiceType_TXT = 16, /* One or more text strings (NOT "zero or more..."). */424kDNSServiceType_RP = 17, /* Responsible person. */425kDNSServiceType_AFSDB = 18, /* AFS cell database. */426kDNSServiceType_X25 = 19, /* X_25 calling address. */427kDNSServiceType_ISDN = 20, /* ISDN calling address. */428kDNSServiceType_RT = 21, /* Router. */429kDNSServiceType_NSAP = 22, /* NSAP address. */430kDNSServiceType_NSAP_PTR = 23, /* Reverse NSAP lookup (deprecated). */431kDNSServiceType_SIG = 24, /* Security signature. */432kDNSServiceType_KEY = 25, /* Security key. */433kDNSServiceType_PX = 26, /* X.400 mail mapping. */434kDNSServiceType_GPOS = 27, /* Geographical position (withdrawn). */435kDNSServiceType_AAAA = 28, /* IPv6 Address. */436kDNSServiceType_LOC = 29, /* Location Information. */437kDNSServiceType_NXT = 30, /* Next domain (security). */438kDNSServiceType_EID = 31, /* Endpoint identifier. */439kDNSServiceType_NIMLOC = 32, /* Nimrod Locator. */440kDNSServiceType_SRV = 33, /* Server Selection. */441kDNSServiceType_ATMA = 34, /* ATM Address */442kDNSServiceType_NAPTR = 35, /* Naming Authority PoinTeR */443kDNSServiceType_KX = 36, /* Key Exchange */444kDNSServiceType_CERT = 37, /* Certification record */445kDNSServiceType_A6 = 38, /* IPv6 Address (deprecated) */446kDNSServiceType_DNAME = 39, /* Non-terminal DNAME (for IPv6) */447kDNSServiceType_SINK = 40, /* Kitchen sink (experimental) */448kDNSServiceType_OPT = 41, /* EDNS0 option (meta-RR) */449kDNSServiceType_APL = 42, /* Address Prefix List */450kDNSServiceType_DS = 43, /* Delegation Signer */451kDNSServiceType_SSHFP = 44, /* SSH Key Fingerprint */452kDNSServiceType_IPSECKEY = 45, /* IPSECKEY */453kDNSServiceType_RRSIG = 46, /* RRSIG */454kDNSServiceType_NSEC = 47, /* Denial of Existence */455kDNSServiceType_DNSKEY = 48, /* DNSKEY */456kDNSServiceType_DHCID = 49, /* DHCP Client Identifier */457kDNSServiceType_NSEC3 = 50, /* Hashed Authenticated Denial of Existence */458kDNSServiceType_NSEC3PARAM = 51, /* Hashed Authenticated Denial of Existence */459460kDNSServiceType_HIP = 55, /* Host Identity Protocol */461462kDNSServiceType_SPF = 99, /* Sender Policy Framework for E-Mail */463kDNSServiceType_UINFO = 100, /* IANA-Reserved */464kDNSServiceType_UID = 101, /* IANA-Reserved */465kDNSServiceType_GID = 102, /* IANA-Reserved */466kDNSServiceType_UNSPEC = 103, /* IANA-Reserved */467468kDNSServiceType_TKEY = 249, /* Transaction key */469kDNSServiceType_TSIG = 250, /* Transaction signature. */470kDNSServiceType_IXFR = 251, /* Incremental zone transfer. */471kDNSServiceType_AXFR = 252, /* Transfer zone of authority. */472kDNSServiceType_MAILB = 253, /* Transfer mailbox records. */473kDNSServiceType_MAILA = 254, /* Transfer mail agent records. */474kDNSServiceType_ANY = 255 /* Wildcard match. */475};476477/* possible error code values */478enum479{480kDNSServiceErr_NoError = 0,481kDNSServiceErr_Unknown = -65537, /* 0xFFFE FFFF */482kDNSServiceErr_NoSuchName = -65538,483kDNSServiceErr_NoMemory = -65539,484kDNSServiceErr_BadParam = -65540,485kDNSServiceErr_BadReference = -65541,486kDNSServiceErr_BadState = -65542,487kDNSServiceErr_BadFlags = -65543,488kDNSServiceErr_Unsupported = -65544,489kDNSServiceErr_NotInitialized = -65545,490kDNSServiceErr_AlreadyRegistered = -65547,491kDNSServiceErr_NameConflict = -65548,492kDNSServiceErr_Invalid = -65549,493kDNSServiceErr_Firewall = -65550,494kDNSServiceErr_Incompatible = -65551, /* client library incompatible with daemon */495kDNSServiceErr_BadInterfaceIndex = -65552,496kDNSServiceErr_Refused = -65553,497kDNSServiceErr_NoSuchRecord = -65554,498kDNSServiceErr_NoAuth = -65555,499kDNSServiceErr_NoSuchKey = -65556,500kDNSServiceErr_NATTraversal = -65557,501kDNSServiceErr_DoubleNAT = -65558,502kDNSServiceErr_BadTime = -65559, /* Codes up to here existed in Tiger */503kDNSServiceErr_BadSig = -65560,504kDNSServiceErr_BadKey = -65561,505kDNSServiceErr_Transient = -65562,506kDNSServiceErr_ServiceNotRunning = -65563, /* Background daemon not running */507kDNSServiceErr_NATPortMappingUnsupported = -65564, /* NAT doesn't support NAT-PMP or UPnP */508kDNSServiceErr_NATPortMappingDisabled = -65565, /* NAT supports NAT-PMP or UPnP but it's disabled by the administrator */509kDNSServiceErr_NoRouter = -65566, /* No router currently configured (probably no network connectivity) */510kDNSServiceErr_PollingMode = -65567,511kDNSServiceErr_Timeout = -65568512513/* mDNS Error codes are in the range514* FFFE FF00 (-65792) to FFFE FFFF (-65537) */515};516517/* Maximum length, in bytes, of a service name represented as a */518/* literal C-String, including the terminating NULL at the end. */519520#define kDNSServiceMaxServiceName 64521522/* Maximum length, in bytes, of a domain name represented as an *escaped* C-String */523/* including the final trailing dot, and the C-String terminating NULL at the end. */524525#define kDNSServiceMaxDomainName 1009526527/*528* Notes on DNS Name Escaping529* -- or --530* "Why is kDNSServiceMaxDomainName 1009, when the maximum legal domain name is 256 bytes?"531*532* All strings used in the DNS-SD APIs are UTF-8 strings. Apart from the exceptions noted below,533* the APIs expect the strings to be properly escaped, using the conventional DNS escaping rules:534*535* '\\' represents a single literal '\' in the name536* '\.' represents a single literal '.' in the name537* '\ddd', where ddd is a three-digit decimal value from 000 to 255,538* represents a single literal byte with that value.539* A bare unescaped '.' is a label separator, marking a boundary between domain and subdomain.540*541* The exceptions, that do not use escaping, are the routines where the full542* DNS name of a resource is broken, for convenience, into servicename/regtype/domain.543* In these routines, the "servicename" is NOT escaped. It does not need to be, since544* it is, by definition, just a single literal string. Any characters in that string545* represent exactly what they are. The "regtype" portion is, technically speaking,546* escaped, but since legal regtypes are only allowed to contain letters, digits,547* and hyphens, there is nothing to escape, so the issue is moot. The "domain"548* portion is also escaped, though most domains in use on the public Internet549* today, like regtypes, don't contain any characters that need to be escaped.550* As DNS-SD becomes more popular, rich-text domains for service discovery will551* become common, so software should be written to cope with domains with escaping.552*553* The servicename may be up to 63 bytes of UTF-8 text (not counting the C-String554* terminating NULL at the end). The regtype is of the form _service._tcp or555* _service._udp, where the "service" part is 1-15 characters, which may be556* letters, digits, or hyphens. The domain part of the three-part name may be557* any legal domain, providing that the resulting servicename+regtype+domain558* name does not exceed 256 bytes.559*560* For most software, these issues are transparent. When browsing, the discovered561* servicenames should simply be displayed as-is. When resolving, the discovered562* servicename/regtype/domain are simply passed unchanged to DNSServiceResolve().563* When a DNSServiceResolve() succeeds, the returned fullname is already in564* the correct format to pass to standard system DNS APIs such as res_query().565* For converting from servicename/regtype/domain to a single properly-escaped566* full DNS name, the helper function DNSServiceConstructFullName() is provided.567*568* The following (highly contrived) example illustrates the escaping process.569* Suppose you have an service called "Dr. Smith\Dr. Johnson", of type "_ftp._tcp"570* in subdomain "4th. Floor" of subdomain "Building 2" of domain "apple.com."571* The full (escaped) DNS name of this service's SRV record would be:572* Dr\.\032Smith\\Dr\.\032Johnson._ftp._tcp.4th\.\032Floor.Building\0322.apple.com.573*/574575576/*577* Constants for specifying an interface index578*579* Specific interface indexes are identified via a 32-bit unsigned integer returned580* by the if_nametoindex() family of calls.581*582* If the client passes 0 for interface index, that means "do the right thing",583* which (at present) means, "if the name is in an mDNS local multicast domain584* (e.g. 'local.', '254.169.in-addr.arpa.', '{8,9,A,B}.E.F.ip6.arpa.') then multicast585* on all applicable interfaces, otherwise send via unicast to the appropriate586* DNS server." Normally, most clients will use 0 for interface index to587* automatically get the default sensible behaviour.588*589* If the client passes a positive interface index, then for multicast names that590* indicates to do the operation only on that one interface. For unicast names the591* interface index is ignored unless kDNSServiceFlagsForceMulticast is also set.592*593* If the client passes kDNSServiceInterfaceIndexLocalOnly when registering594* a service, then that service will be found *only* by other local clients595* on the same machine that are browsing using kDNSServiceInterfaceIndexLocalOnly596* or kDNSServiceInterfaceIndexAny.597* If a client has a 'private' service, accessible only to other processes598* running on the same machine, this allows the client to advertise that service599* in a way such that it does not inadvertently appear in service lists on600* all the other machines on the network.601*602* If the client passes kDNSServiceInterfaceIndexLocalOnly when browsing603* then it will find *all* records registered on that same local machine.604* Clients explicitly wishing to discover *only* LocalOnly services can605* accomplish this by inspecting the interfaceIndex of each service reported606* to their DNSServiceBrowseReply() callback function, and discarding those607* where the interface index is not kDNSServiceInterfaceIndexLocalOnly.608*609* kDNSServiceInterfaceIndexP2P is meaningful only in Browse, QueryRecord,610* and Resolve operations. It should not be used in other DNSService APIs.611*612* - If kDNSServiceInterfaceIndexP2P is passed to DNSServiceBrowse or613* DNSServiceQueryRecord, it restricts the operation to P2P.614*615* - If kDNSServiceInterfaceIndexP2P is passed to DNSServiceResolve, it is616* mapped internally to kDNSServiceInterfaceIndexAny, because resolving617* a P2P service may create and/or enable an interface whose index is not618* known a priori. The resolve callback will indicate the index of the619* interface via which the service can be accessed.620*621* If applications pass kDNSServiceInterfaceIndexAny to DNSServiceBrowse622* or DNSServiceQueryRecord, they must set the kDNSServiceFlagsIncludeP2P flag623* to include P2P. In this case, if a service instance or the record being queried624* is found over P2P, the resulting ADD event will indicate kDNSServiceInterfaceIndexP2P625* as the interface index.626*/627628#define kDNSServiceInterfaceIndexAny 0629#define kDNSServiceInterfaceIndexLocalOnly ((uint32_t)-1)630#define kDNSServiceInterfaceIndexUnicast ((uint32_t)-2)631#define kDNSServiceInterfaceIndexP2P ((uint32_t)-3)632633typedef uint32_t DNSServiceFlags;634typedef uint32_t DNSServiceProtocol;635typedef int32_t DNSServiceErrorType;636637638/*********************************************************************************************639*640* Version checking641*642*********************************************************************************************/643644/* DNSServiceGetProperty() Parameters:645*646* property: The requested property.647* Currently the only property defined is kDNSServiceProperty_DaemonVersion.648*649* result: Place to store result.650* For retrieving DaemonVersion, this should be the address of a uint32_t.651*652* size: Pointer to uint32_t containing size of the result location.653* For retrieving DaemonVersion, this should be sizeof(uint32_t).654* On return the uint32_t is updated to the size of the data returned.655* For DaemonVersion, the returned size is always sizeof(uint32_t), but656* future properties could be defined which return variable-sized results.657*658* return value: Returns kDNSServiceErr_NoError on success, or kDNSServiceErr_ServiceNotRunning659* if the daemon (or "system service" on Windows) is not running.660*/661662DNSServiceErrorType DNSSD_API DNSServiceGetProperty663(664const char *property, /* Requested property (i.e. kDNSServiceProperty_DaemonVersion) */665void *result, /* Pointer to place to store result */666uint32_t *size /* size of result location */667);668669/*670* When requesting kDNSServiceProperty_DaemonVersion, the result pointer must point671* to a 32-bit unsigned integer, and the size parameter must be set to sizeof(uint32_t).672*673* On return, the 32-bit unsigned integer contains the version number, formatted as follows:674* Major part of the build number * 10000 +675* minor part of the build number * 100676*677* For example, Mac OS X 10.4.9 has mDNSResponder-108.4, which would be represented as678* version 1080400. This allows applications to do simple greater-than and less-than comparisons:679* e.g. an application that requires at least mDNSResponder-108.4 can check:680*681* if (version >= 1080400) ...682*683* Example usage:684*685* uint32_t version;686* uint32_t size = sizeof(version);687* DNSServiceErrorType err = DNSServiceGetProperty(kDNSServiceProperty_DaemonVersion, &version, &size);688* if (!err) printf("Bonjour version is %d.%d\n", version / 10000, version / 100 % 100);689*/690691#define kDNSServiceProperty_DaemonVersion "DaemonVersion"692693694/*********************************************************************************************695*696* Unix Domain Socket access, DNSServiceRef deallocation, and data processing functions697*698*********************************************************************************************/699700/* DNSServiceRefSockFD()701*702* Access underlying Unix domain socket for an initialized DNSServiceRef.703* The DNS Service Discovery implementation uses this socket to communicate between the client and704* the mDNSResponder daemon. The application MUST NOT directly read from or write to this socket.705* Access to the socket is provided so that it can be used as a kqueue event source, a CFRunLoop706* event source, in a select() loop, etc. When the underlying event management subsystem (kqueue/707* select/CFRunLoop etc.) indicates to the client that data is available for reading on the708* socket, the client should call DNSServiceProcessResult(), which will extract the daemon's709* reply from the socket, and pass it to the appropriate application callback. By using a run710* loop or select(), results from the daemon can be processed asynchronously. Alternatively,711* a client can choose to fork a thread and have it loop calling "DNSServiceProcessResult(ref);"712* If DNSServiceProcessResult() is called when no data is available for reading on the socket, it713* will block until data does become available, and then process the data and return to the caller.714* When data arrives on the socket, the client is responsible for calling DNSServiceProcessResult(ref)715* in a timely fashion -- if the client allows a large backlog of data to build up the daemon716* may terminate the connection.717*718* sdRef: A DNSServiceRef initialized by any of the DNSService calls.719*720* return value: The DNSServiceRef's underlying socket descriptor, or -1 on721* error.722*/723724int DNSSD_API DNSServiceRefSockFD(DNSServiceRef sdRef);725726727/* DNSServiceProcessResult()728*729* Read a reply from the daemon, calling the appropriate application callback. This call will730* block until the daemon's response is received. Use DNSServiceRefSockFD() in731* conjunction with a run loop or select() to determine the presence of a response from the732* server before calling this function to process the reply without blocking. Call this function733* at any point if it is acceptable to block until the daemon's response arrives. Note that the734* client is responsible for ensuring that DNSServiceProcessResult() is called whenever there is735* a reply from the daemon - the daemon may terminate its connection with a client that does not736* process the daemon's responses.737*738* sdRef: A DNSServiceRef initialized by any of the DNSService calls739* that take a callback parameter.740*741* return value: Returns kDNSServiceErr_NoError on success, otherwise returns742* an error code indicating the specific failure that occurred.743*/744745DNSServiceErrorType DNSSD_API DNSServiceProcessResult(DNSServiceRef sdRef);746747748/* DNSServiceRefDeallocate()749*750* Terminate a connection with the daemon and free memory associated with the DNSServiceRef.751* Any services or records registered with this DNSServiceRef will be deregistered. Any752* Browse, Resolve, or Query operations called with this reference will be terminated.753*754* Note: If the reference's underlying socket is used in a run loop or select() call, it should755* be removed BEFORE DNSServiceRefDeallocate() is called, as this function closes the reference's756* socket.757*758* Note: If the reference was initialized with DNSServiceCreateConnection(), any DNSRecordRefs759* created via this reference will be invalidated by this call - the resource records are760* deregistered, and their DNSRecordRefs may not be used in subsequent functions. Similarly,761* if the reference was initialized with DNSServiceRegister, and an extra resource record was762* added to the service via DNSServiceAddRecord(), the DNSRecordRef created by the Add() call763* is invalidated when this function is called - the DNSRecordRef may not be used in subsequent764* functions.765*766* Note: This call is to be used only with the DNSServiceRef defined by this API. It is767* not compatible with dns_service_discovery_ref objects defined in the legacy Mach-based768* DNSServiceDiscovery.h API.769*770* sdRef: A DNSServiceRef initialized by any of the DNSService calls.771*772*/773774void DNSSD_API DNSServiceRefDeallocate(DNSServiceRef sdRef);775776777/*********************************************************************************************778*779* Domain Enumeration780*781*********************************************************************************************/782783/* DNSServiceEnumerateDomains()784*785* Asynchronously enumerate domains available for browsing and registration.786*787* The enumeration MUST be cancelled via DNSServiceRefDeallocate() when no more domains788* are to be found.789*790* Note that the names returned are (like all of DNS-SD) UTF-8 strings,791* and are escaped using standard DNS escaping rules.792* (See "Notes on DNS Name Escaping" earlier in this file for more details.)793* A graphical browser displaying a hierarchical tree-structured view should cut794* the names at the bare dots to yield individual labels, then de-escape each795* label according to the escaping rules, and then display the resulting UTF-8 text.796*797* DNSServiceDomainEnumReply Callback Parameters:798*799* sdRef: The DNSServiceRef initialized by DNSServiceEnumerateDomains().800*801* flags: Possible values are:802* kDNSServiceFlagsMoreComing803* kDNSServiceFlagsAdd804* kDNSServiceFlagsDefault805*806* interfaceIndex: Specifies the interface on which the domain exists. (The index for a given807* interface is determined via the if_nametoindex() family of calls.)808*809* errorCode: Will be kDNSServiceErr_NoError (0) on success, otherwise indicates810* the failure that occurred (other parameters are undefined if errorCode is nonzero).811*812* replyDomain: The name of the domain.813*814* context: The context pointer passed to DNSServiceEnumerateDomains.815*816*/817818typedef void (DNSSD_API *DNSServiceDomainEnumReply)819(820DNSServiceRef sdRef,821DNSServiceFlags flags,822uint32_t interfaceIndex,823DNSServiceErrorType errorCode,824const char *replyDomain,825void *context826);827828829/* DNSServiceEnumerateDomains() Parameters:830*831* sdRef: A pointer to an uninitialized DNSServiceRef. If the call succeeds832* then it initializes the DNSServiceRef, returns kDNSServiceErr_NoError,833* and the enumeration operation will run indefinitely until the client834* terminates it by passing this DNSServiceRef to DNSServiceRefDeallocate().835*836* flags: Possible values are:837* kDNSServiceFlagsBrowseDomains to enumerate domains recommended for browsing.838* kDNSServiceFlagsRegistrationDomains to enumerate domains recommended839* for registration.840*841* interfaceIndex: If non-zero, specifies the interface on which to look for domains.842* (the index for a given interface is determined via the if_nametoindex()843* family of calls.) Most applications will pass 0 to enumerate domains on844* all interfaces. See "Constants for specifying an interface index" for more details.845*846* callBack: The function to be called when a domain is found or the call asynchronously847* fails.848*849* context: An application context pointer which is passed to the callback function850* (may be NULL).851*852* return value: Returns kDNSServiceErr_NoError on success (any subsequent, asynchronous853* errors are delivered to the callback), otherwise returns an error code indicating854* the error that occurred (the callback is not invoked and the DNSServiceRef855* is not initialized).856*/857858DNSServiceErrorType DNSSD_API DNSServiceEnumerateDomains859(860DNSServiceRef *sdRef,861DNSServiceFlags flags,862uint32_t interfaceIndex,863DNSServiceDomainEnumReply callBack,864void *context /* may be NULL */865);866867868/*********************************************************************************************869*870* Service Registration871*872*********************************************************************************************/873874/* Register a service that is discovered via Browse() and Resolve() calls.875*876* DNSServiceRegisterReply() Callback Parameters:877*878* sdRef: The DNSServiceRef initialized by DNSServiceRegister().879*880* flags: When a name is successfully registered, the callback will be881* invoked with the kDNSServiceFlagsAdd flag set. When Wide-Area882* DNS-SD is in use, it is possible for a single service to get883* more than one success callback (e.g. one in the "local" multicast884* DNS domain, and another in a wide-area unicast DNS domain).885* If a successfully-registered name later suffers a name conflict886* or similar problem and has to be deregistered, the callback will887* be invoked with the kDNSServiceFlagsAdd flag not set. The callback888* is *not* invoked in the case where the caller explicitly terminates889* the service registration by calling DNSServiceRefDeallocate(ref);890*891* errorCode: Will be kDNSServiceErr_NoError on success, otherwise will892* indicate the failure that occurred (including name conflicts,893* if the kDNSServiceFlagsNoAutoRename flag was used when registering.)894* Other parameters are undefined if errorCode is nonzero.895*896* name: The service name registered (if the application did not specify a name in897* DNSServiceRegister(), this indicates what name was automatically chosen).898*899* regtype: The type of service registered, as it was passed to the callout.900*901* domain: The domain on which the service was registered (if the application did not902* specify a domain in DNSServiceRegister(), this indicates the default domain903* on which the service was registered).904*905* context: The context pointer that was passed to the callout.906*907*/908909typedef void (DNSSD_API *DNSServiceRegisterReply)910(911DNSServiceRef sdRef,912DNSServiceFlags flags,913DNSServiceErrorType errorCode,914const char *name,915const char *regtype,916const char *domain,917void *context918);919920921/* DNSServiceRegister() Parameters:922*923* sdRef: A pointer to an uninitialized DNSServiceRef. If the call succeeds924* then it initializes the DNSServiceRef, returns kDNSServiceErr_NoError,925* and the registration will remain active indefinitely until the client926* terminates it by passing this DNSServiceRef to DNSServiceRefDeallocate().927*928* interfaceIndex: If non-zero, specifies the interface on which to register the service929* (the index for a given interface is determined via the if_nametoindex()930* family of calls.) Most applications will pass 0 to register on all931* available interfaces. See "Constants for specifying an interface index" for more details.932*933* flags: Indicates the renaming behavior on name conflict (most applications934* will pass 0). See flag definitions above for details.935*936* name: If non-NULL, specifies the service name to be registered.937* Most applications will not specify a name, in which case the computer938* name is used (this name is communicated to the client via the callback).939* If a name is specified, it must be 1-63 bytes of UTF-8 text.940* If the name is longer than 63 bytes it will be automatically truncated941* to a legal length, unless the NoAutoRename flag is set,942* in which case kDNSServiceErr_BadParam will be returned.943*944* regtype: The service type followed by the protocol, separated by a dot945* (e.g. "_ftp._tcp"). The service type must be an underscore, followed946* by 1-15 characters, which may be letters, digits, or hyphens.947* The transport protocol must be "_tcp" or "_udp". New service types948* should be registered at <http://www.dns-sd.org/ServiceTypes.html>.949*950* Additional subtypes of the primary service type (where a service951* type has defined subtypes) follow the primary service type in a952* comma-separated list, with no additional spaces, e.g.953* "_primarytype._tcp,_subtype1,_subtype2,_subtype3"954* Subtypes provide a mechanism for filtered browsing: A client browsing955* for "_primarytype._tcp" will discover all instances of this type;956* a client browsing for "_primarytype._tcp,_subtype2" will discover only957* those instances that were registered with "_subtype2" in their list of958* registered subtypes.959*960* The subtype mechanism can be illustrated with some examples using the961* dns-sd command-line tool:962*963* % dns-sd -R Simple _test._tcp "" 1001 &964* % dns-sd -R Better _test._tcp,HasFeatureA "" 1002 &965* % dns-sd -R Best _test._tcp,HasFeatureA,HasFeatureB "" 1003 &966*967* Now:968* % dns-sd -B _test._tcp # will find all three services969* % dns-sd -B _test._tcp,HasFeatureA # finds "Better" and "Best"970* % dns-sd -B _test._tcp,HasFeatureB # finds only "Best"971*972* Subtype labels may be up to 63 bytes long, and may contain any eight-973* bit byte values, including zero bytes. However, due to the nature of974* using a C-string-based API, conventional DNS escaping must be used for975* dots ('.'), commas (','), backslashes ('\') and zero bytes, as shown below:976*977* % dns-sd -R Test '_test._tcp,s\.one,s\,two,s\\three,s\000four' local 123978*979* domain: If non-NULL, specifies the domain on which to advertise the service.980* Most applications will not specify a domain, instead automatically981* registering in the default domain(s).982*983* host: If non-NULL, specifies the SRV target host name. Most applications984* will not specify a host, instead automatically using the machine's985* default host name(s). Note that specifying a non-NULL host does NOT986* create an address record for that host - the application is responsible987* for ensuring that the appropriate address record exists, or creating it988* via DNSServiceRegisterRecord().989*990* port: The port, in network byte order, on which the service accepts connections.991* Pass 0 for a "placeholder" service (i.e. a service that will not be discovered992* by browsing, but will cause a name conflict if another client tries to993* register that same name). Most clients will not use placeholder services.994*995* txtLen: The length of the txtRecord, in bytes. Must be zero if the txtRecord is NULL.996*997* txtRecord: The TXT record rdata. A non-NULL txtRecord MUST be a properly formatted DNS998* TXT record, i.e. <length byte> <data> <length byte> <data> ...999* Passing NULL for the txtRecord is allowed as a synonym for txtLen=1, txtRecord="",1000* i.e. it creates a TXT record of length one containing a single empty string.1001* RFC 1035 doesn't allow a TXT record to contain *zero* strings, so a single empty1002* string is the smallest legal DNS TXT record.1003* As with the other parameters, the DNSServiceRegister call copies the txtRecord1004* data; e.g. if you allocated the storage for the txtRecord parameter with malloc()1005* then you can safely free that memory right after the DNSServiceRegister call returns.1006*1007* callBack: The function to be called when the registration completes or asynchronously1008* fails. The client MAY pass NULL for the callback - The client will NOT be notified1009* of the default values picked on its behalf, and the client will NOT be notified of any1010* asynchronous errors (e.g. out of memory errors, etc.) that may prevent the registration1011* of the service. The client may NOT pass the NoAutoRename flag if the callback is NULL.1012* The client may still deregister the service at any time via DNSServiceRefDeallocate().1013*1014* context: An application context pointer which is passed to the callback function1015* (may be NULL).1016*1017* return value: Returns kDNSServiceErr_NoError on success (any subsequent, asynchronous1018* errors are delivered to the callback), otherwise returns an error code indicating1019* the error that occurred (the callback is never invoked and the DNSServiceRef1020* is not initialized).1021*/10221023DNSServiceErrorType DNSSD_API DNSServiceRegister1024(1025DNSServiceRef *sdRef,1026DNSServiceFlags flags,1027uint32_t interfaceIndex,1028const char *name, /* may be NULL */1029const char *regtype,1030const char *domain, /* may be NULL */1031const char *host, /* may be NULL */1032uint16_t port, /* In network byte order */1033uint16_t txtLen,1034const void *txtRecord, /* may be NULL */1035DNSServiceRegisterReply callBack, /* may be NULL */1036void *context /* may be NULL */1037);103810391040/* DNSServiceAddRecord()1041*1042* Add a record to a registered service. The name of the record will be the same as the1043* registered service's name.1044* The record can later be updated or deregistered by passing the RecordRef initialized1045* by this function to DNSServiceUpdateRecord() or DNSServiceRemoveRecord().1046*1047* Note that the DNSServiceAddRecord/UpdateRecord/RemoveRecord are *NOT* thread-safe1048* with respect to a single DNSServiceRef. If you plan to have multiple threads1049* in your program simultaneously add, update, or remove records from the same1050* DNSServiceRef, then it's the caller's responsibility to use a mutext lock1051* or take similar appropriate precautions to serialize those calls.1052*1053* Parameters;1054*1055* sdRef: A DNSServiceRef initialized by DNSServiceRegister().1056*1057* RecordRef: A pointer to an uninitialized DNSRecordRef. Upon succesfull completion of this1058* call, this ref may be passed to DNSServiceUpdateRecord() or DNSServiceRemoveRecord().1059* If the above DNSServiceRef is passed to DNSServiceRefDeallocate(), RecordRef is also1060* invalidated and may not be used further.1061*1062* flags: Currently ignored, reserved for future use.1063*1064* rrtype: The type of the record (e.g. kDNSServiceType_TXT, kDNSServiceType_SRV, etc)1065*1066* rdlen: The length, in bytes, of the rdata.1067*1068* rdata: The raw rdata to be contained in the added resource record.1069*1070* ttl: The time to live of the resource record, in seconds.1071* Most clients should pass 0 to indicate that the system should1072* select a sensible default value.1073*1074* return value: Returns kDNSServiceErr_NoError on success, otherwise returns an1075* error code indicating the error that occurred (the RecordRef is not initialized).1076*/10771078DNSServiceErrorType DNSSD_API DNSServiceAddRecord1079(1080DNSServiceRef sdRef,1081DNSRecordRef *RecordRef,1082DNSServiceFlags flags,1083uint16_t rrtype,1084uint16_t rdlen,1085const void *rdata,1086uint32_t ttl1087);108810891090/* DNSServiceUpdateRecord1091*1092* Update a registered resource record. The record must either be:1093* - The primary txt record of a service registered via DNSServiceRegister()1094* - A record added to a registered service via DNSServiceAddRecord()1095* - An individual record registered by DNSServiceRegisterRecord()1096*1097* Parameters:1098*1099* sdRef: A DNSServiceRef that was initialized by DNSServiceRegister()1100* or DNSServiceCreateConnection().1101*1102* RecordRef: A DNSRecordRef initialized by DNSServiceAddRecord, or NULL to update the1103* service's primary txt record.1104*1105* flags: Currently ignored, reserved for future use.1106*1107* rdlen: The length, in bytes, of the new rdata.1108*1109* rdata: The new rdata to be contained in the updated resource record.1110*1111* ttl: The time to live of the updated resource record, in seconds.1112* Most clients should pass 0 to indicate that the system should1113* select a sensible default value.1114*1115* return value: Returns kDNSServiceErr_NoError on success, otherwise returns an1116* error code indicating the error that occurred.1117*/11181119DNSServiceErrorType DNSSD_API DNSServiceUpdateRecord1120(1121DNSServiceRef sdRef,1122DNSRecordRef RecordRef, /* may be NULL */1123DNSServiceFlags flags,1124uint16_t rdlen,1125const void *rdata,1126uint32_t ttl1127);112811291130/* DNSServiceRemoveRecord1131*1132* Remove a record previously added to a service record set via DNSServiceAddRecord(), or deregister1133* an record registered individually via DNSServiceRegisterRecord().1134*1135* Parameters:1136*1137* sdRef: A DNSServiceRef initialized by DNSServiceRegister() (if the1138* record being removed was registered via DNSServiceAddRecord()) or by1139* DNSServiceCreateConnection() (if the record being removed was registered via1140* DNSServiceRegisterRecord()).1141*1142* recordRef: A DNSRecordRef initialized by a successful call to DNSServiceAddRecord()1143* or DNSServiceRegisterRecord().1144*1145* flags: Currently ignored, reserved for future use.1146*1147* return value: Returns kDNSServiceErr_NoError on success, otherwise returns an1148* error code indicating the error that occurred.1149*/11501151DNSServiceErrorType DNSSD_API DNSServiceRemoveRecord1152(1153DNSServiceRef sdRef,1154DNSRecordRef RecordRef,1155DNSServiceFlags flags1156);115711581159/*********************************************************************************************1160*1161* Service Discovery1162*1163*********************************************************************************************/11641165/* Browse for instances of a service.1166*1167* DNSServiceBrowseReply() Parameters:1168*1169* sdRef: The DNSServiceRef initialized by DNSServiceBrowse().1170*1171* flags: Possible values are kDNSServiceFlagsMoreComing and kDNSServiceFlagsAdd.1172* See flag definitions for details.1173*1174* interfaceIndex: The interface on which the service is advertised. This index should1175* be passed to DNSServiceResolve() when resolving the service.1176*1177* errorCode: Will be kDNSServiceErr_NoError (0) on success, otherwise will1178* indicate the failure that occurred. Other parameters are undefined if1179* the errorCode is nonzero.1180*1181* serviceName: The discovered service name. This name should be displayed to the user,1182* and stored for subsequent use in the DNSServiceResolve() call.1183*1184* regtype: The service type, which is usually (but not always) the same as was passed1185* to DNSServiceBrowse(). One case where the discovered service type may1186* not be the same as the requested service type is when using subtypes:1187* The client may want to browse for only those ftp servers that allow1188* anonymous connections. The client will pass the string "_ftp._tcp,_anon"1189* to DNSServiceBrowse(), but the type of the service that's discovered1190* is simply "_ftp._tcp". The regtype for each discovered service instance1191* should be stored along with the name, so that it can be passed to1192* DNSServiceResolve() when the service is later resolved.1193*1194* domain: The domain of the discovered service instance. This may or may not be the1195* same as the domain that was passed to DNSServiceBrowse(). The domain for each1196* discovered service instance should be stored along with the name, so that1197* it can be passed to DNSServiceResolve() when the service is later resolved.1198*1199* context: The context pointer that was passed to the callout.1200*1201*/12021203typedef void (DNSSD_API *DNSServiceBrowseReply)1204(1205DNSServiceRef sdRef,1206DNSServiceFlags flags,1207uint32_t interfaceIndex,1208DNSServiceErrorType errorCode,1209const char *serviceName,1210const char *regtype,1211const char *replyDomain,1212void *context1213);121412151216/* DNSServiceBrowse() Parameters:1217*1218* sdRef: A pointer to an uninitialized DNSServiceRef. If the call succeeds1219* then it initializes the DNSServiceRef, returns kDNSServiceErr_NoError,1220* and the browse operation will run indefinitely until the client1221* terminates it by passing this DNSServiceRef to DNSServiceRefDeallocate().1222*1223* flags: Currently ignored, reserved for future use.1224*1225* interfaceIndex: If non-zero, specifies the interface on which to browse for services1226* (the index for a given interface is determined via the if_nametoindex()1227* family of calls.) Most applications will pass 0 to browse on all available1228* interfaces. See "Constants for specifying an interface index" for more details.1229*1230* regtype: The service type being browsed for followed by the protocol, separated by a1231* dot (e.g. "_ftp._tcp"). The transport protocol must be "_tcp" or "_udp".1232* A client may optionally specify a single subtype to perform filtered browsing:1233* e.g. browsing for "_primarytype._tcp,_subtype" will discover only those1234* instances of "_primarytype._tcp" that were registered specifying "_subtype"1235* in their list of registered subtypes.1236*1237* domain: If non-NULL, specifies the domain on which to browse for services.1238* Most applications will not specify a domain, instead browsing on the1239* default domain(s).1240*1241* callBack: The function to be called when an instance of the service being browsed for1242* is found, or if the call asynchronously fails.1243*1244* context: An application context pointer which is passed to the callback function1245* (may be NULL).1246*1247* return value: Returns kDNSServiceErr_NoError on success (any subsequent, asynchronous1248* errors are delivered to the callback), otherwise returns an error code indicating1249* the error that occurred (the callback is not invoked and the DNSServiceRef1250* is not initialized).1251*/12521253DNSServiceErrorType DNSSD_API DNSServiceBrowse1254(1255DNSServiceRef *sdRef,1256DNSServiceFlags flags,1257uint32_t interfaceIndex,1258const char *regtype,1259const char *domain, /* may be NULL */1260DNSServiceBrowseReply callBack,1261void *context /* may be NULL */1262);126312641265/* DNSServiceResolve()1266*1267* Resolve a service name discovered via DNSServiceBrowse() to a target host name, port number, and1268* txt record.1269*1270* Note: Applications should NOT use DNSServiceResolve() solely for txt record monitoring - use1271* DNSServiceQueryRecord() instead, as it is more efficient for this task.1272*1273* Note: When the desired results have been returned, the client MUST terminate the resolve by calling1274* DNSServiceRefDeallocate().1275*1276* Note: DNSServiceResolve() behaves correctly for typical services that have a single SRV record1277* and a single TXT record. To resolve non-standard services with multiple SRV or TXT records,1278* DNSServiceQueryRecord() should be used.1279*1280* DNSServiceResolveReply Callback Parameters:1281*1282* sdRef: The DNSServiceRef initialized by DNSServiceResolve().1283*1284* flags: Possible values: kDNSServiceFlagsMoreComing1285*1286* interfaceIndex: The interface on which the service was resolved.1287*1288* errorCode: Will be kDNSServiceErr_NoError (0) on success, otherwise will1289* indicate the failure that occurred. Other parameters are undefined if1290* the errorCode is nonzero.1291*1292* fullname: The full service domain name, in the form <servicename>.<protocol>.<domain>.1293* (This name is escaped following standard DNS rules, making it suitable for1294* passing to standard system DNS APIs such as res_query(), or to the1295* special-purpose functions included in this API that take fullname parameters.1296* See "Notes on DNS Name Escaping" earlier in this file for more details.)1297*1298* hosttarget: The target hostname of the machine providing the service. This name can1299* be passed to functions like gethostbyname() to identify the host's IP address.1300*1301* port: The port, in network byte order, on which connections are accepted for this service.1302*1303* txtLen: The length of the txt record, in bytes.1304*1305* txtRecord: The service's primary txt record, in standard txt record format.1306*1307* context: The context pointer that was passed to the callout.1308*1309* NOTE: In earlier versions of this header file, the txtRecord parameter was declared "const char *"1310* This is incorrect, since it contains length bytes which are values in the range 0 to 255, not -128 to +127.1311* Depending on your compiler settings, this change may cause signed/unsigned mismatch warnings.1312* These should be fixed by updating your own callback function definition to match the corrected1313* function signature using "const unsigned char *txtRecord". Making this change may also fix inadvertent1314* bugs in your callback function, where it could have incorrectly interpreted a length byte with value 2501315* as being -6 instead, with various bad consequences ranging from incorrect operation to software crashes.1316* If you need to maintain portable code that will compile cleanly with both the old and new versions of1317* this header file, you should update your callback function definition to use the correct unsigned value,1318* and then in the place where you pass your callback function to DNSServiceResolve(), use a cast to eliminate1319* the compiler warning, e.g.:1320* DNSServiceResolve(sd, flags, index, name, regtype, domain, (DNSServiceResolveReply)MyCallback, context);1321* This will ensure that your code compiles cleanly without warnings (and more importantly, works correctly)1322* with both the old header and with the new corrected version.1323*1324*/13251326typedef void (DNSSD_API *DNSServiceResolveReply)1327(1328DNSServiceRef sdRef,1329DNSServiceFlags flags,1330uint32_t interfaceIndex,1331DNSServiceErrorType errorCode,1332const char *fullname,1333const char *hosttarget,1334uint16_t port, /* In network byte order */1335uint16_t txtLen,1336const unsigned char *txtRecord,1337void *context1338);133913401341/* DNSServiceResolve() Parameters1342*1343* sdRef: A pointer to an uninitialized DNSServiceRef. If the call succeeds1344* then it initializes the DNSServiceRef, returns kDNSServiceErr_NoError,1345* and the resolve operation will run indefinitely until the client1346* terminates it by passing this DNSServiceRef to DNSServiceRefDeallocate().1347*1348* flags: Specifying kDNSServiceFlagsForceMulticast will cause query to be1349* performed with a link-local mDNS query, even if the name is an1350* apparently non-local name (i.e. a name not ending in ".local.")1351*1352* interfaceIndex: The interface on which to resolve the service. If this resolve call is1353* as a result of a currently active DNSServiceBrowse() operation, then the1354* interfaceIndex should be the index reported in the DNSServiceBrowseReply1355* callback. If this resolve call is using information previously saved1356* (e.g. in a preference file) for later use, then use interfaceIndex 0, because1357* the desired service may now be reachable via a different physical interface.1358* See "Constants for specifying an interface index" for more details.1359*1360* name: The name of the service instance to be resolved, as reported to the1361* DNSServiceBrowseReply() callback.1362*1363* regtype: The type of the service instance to be resolved, as reported to the1364* DNSServiceBrowseReply() callback.1365*1366* domain: The domain of the service instance to be resolved, as reported to the1367* DNSServiceBrowseReply() callback.1368*1369* callBack: The function to be called when a result is found, or if the call1370* asynchronously fails.1371*1372* context: An application context pointer which is passed to the callback function1373* (may be NULL).1374*1375* return value: Returns kDNSServiceErr_NoError on success (any subsequent, asynchronous1376* errors are delivered to the callback), otherwise returns an error code indicating1377* the error that occurred (the callback is never invoked and the DNSServiceRef1378* is not initialized).1379*/13801381DNSServiceErrorType DNSSD_API DNSServiceResolve1382(1383DNSServiceRef *sdRef,1384DNSServiceFlags flags,1385uint32_t interfaceIndex,1386const char *name,1387const char *regtype,1388const char *domain,1389DNSServiceResolveReply callBack,1390void *context /* may be NULL */1391);139213931394/*********************************************************************************************1395*1396* Querying Individual Specific Records1397*1398*********************************************************************************************/13991400/* DNSServiceQueryRecord1401*1402* Query for an arbitrary DNS record.1403*1404* DNSServiceQueryRecordReply() Callback Parameters:1405*1406* sdRef: The DNSServiceRef initialized by DNSServiceQueryRecord().1407*1408* flags: Possible values are kDNSServiceFlagsMoreComing and1409* kDNSServiceFlagsAdd. The Add flag is NOT set for PTR records1410* with a ttl of 0, i.e. "Remove" events.1411*1412* interfaceIndex: The interface on which the query was resolved (the index for a given1413* interface is determined via the if_nametoindex() family of calls).1414* See "Constants for specifying an interface index" for more details.1415*1416* errorCode: Will be kDNSServiceErr_NoError on success, otherwise will1417* indicate the failure that occurred. Other parameters are undefined if1418* errorCode is nonzero.1419*1420* fullname: The resource record's full domain name.1421*1422* rrtype: The resource record's type (e.g. kDNSServiceType_PTR, kDNSServiceType_SRV, etc)1423*1424* rrclass: The class of the resource record (usually kDNSServiceClass_IN).1425*1426* rdlen: The length, in bytes, of the resource record rdata.1427*1428* rdata: The raw rdata of the resource record.1429*1430* ttl: If the client wishes to cache the result for performance reasons,1431* the TTL indicates how long the client may legitimately hold onto1432* this result, in seconds. After the TTL expires, the client should1433* consider the result no longer valid, and if it requires this data1434* again, it should be re-fetched with a new query. Of course, this1435* only applies to clients that cancel the asynchronous operation when1436* they get a result. Clients that leave the asynchronous operation1437* running can safely assume that the data remains valid until they1438* get another callback telling them otherwise.1439*1440* context: The context pointer that was passed to the callout.1441*1442*/14431444typedef void (DNSSD_API *DNSServiceQueryRecordReply)1445(1446DNSServiceRef sdRef,1447DNSServiceFlags flags,1448uint32_t interfaceIndex,1449DNSServiceErrorType errorCode,1450const char *fullname,1451uint16_t rrtype,1452uint16_t rrclass,1453uint16_t rdlen,1454const void *rdata,1455uint32_t ttl,1456void *context1457);145814591460/* DNSServiceQueryRecord() Parameters:1461*1462* sdRef: A pointer to an uninitialized DNSServiceRef. If the call succeeds1463* then it initializes the DNSServiceRef, returns kDNSServiceErr_NoError,1464* and the query operation will run indefinitely until the client1465* terminates it by passing this DNSServiceRef to DNSServiceRefDeallocate().1466*1467* flags: kDNSServiceFlagsForceMulticast or kDNSServiceFlagsLongLivedQuery.1468* Pass kDNSServiceFlagsLongLivedQuery to create a "long-lived" unicast1469* query in a non-local domain. Without setting this flag, unicast queries1470* will be one-shot - that is, only answers available at the time of the call1471* will be returned. By setting this flag, answers (including Add and Remove1472* events) that become available after the initial call is made will generate1473* callbacks. This flag has no effect on link-local multicast queries.1474*1475* interfaceIndex: If non-zero, specifies the interface on which to issue the query1476* (the index for a given interface is determined via the if_nametoindex()1477* family of calls.) Passing 0 causes the name to be queried for on all1478* interfaces. See "Constants for specifying an interface index" for more details.1479*1480* fullname: The full domain name of the resource record to be queried for.1481*1482* rrtype: The numerical type of the resource record to be queried for1483* (e.g. kDNSServiceType_PTR, kDNSServiceType_SRV, etc)1484*1485* rrclass: The class of the resource record (usually kDNSServiceClass_IN).1486*1487* callBack: The function to be called when a result is found, or if the call1488* asynchronously fails.1489*1490* context: An application context pointer which is passed to the callback function1491* (may be NULL).1492*1493* return value: Returns kDNSServiceErr_NoError on success (any subsequent, asynchronous1494* errors are delivered to the callback), otherwise returns an error code indicating1495* the error that occurred (the callback is never invoked and the DNSServiceRef1496* is not initialized).1497*/14981499DNSServiceErrorType DNSSD_API DNSServiceQueryRecord1500(1501DNSServiceRef *sdRef,1502DNSServiceFlags flags,1503uint32_t interfaceIndex,1504const char *fullname,1505uint16_t rrtype,1506uint16_t rrclass,1507DNSServiceQueryRecordReply callBack,1508void *context /* may be NULL */1509);151015111512/*********************************************************************************************1513*1514* Unified lookup of both IPv4 and IPv6 addresses for a fully qualified hostname1515*1516*********************************************************************************************/15171518/* DNSServiceGetAddrInfo1519*1520* Queries for the IP address of a hostname by using either Multicast or Unicast DNS.1521*1522* DNSServiceGetAddrInfoReply() parameters:1523*1524* sdRef: The DNSServiceRef initialized by DNSServiceGetAddrInfo().1525*1526* flags: Possible values are kDNSServiceFlagsMoreComing and1527* kDNSServiceFlagsAdd.1528*1529* interfaceIndex: The interface to which the answers pertain.1530*1531* errorCode: Will be kDNSServiceErr_NoError on success, otherwise will1532* indicate the failure that occurred. Other parameters are1533* undefined if errorCode is nonzero.1534*1535* hostname: The fully qualified domain name of the host to be queried for.1536*1537* address: IPv4 or IPv6 address.1538*1539* ttl: If the client wishes to cache the result for performance reasons,1540* the TTL indicates how long the client may legitimately hold onto1541* this result, in seconds. After the TTL expires, the client should1542* consider the result no longer valid, and if it requires this data1543* again, it should be re-fetched with a new query. Of course, this1544* only applies to clients that cancel the asynchronous operation when1545* they get a result. Clients that leave the asynchronous operation1546* running can safely assume that the data remains valid until they1547* get another callback telling them otherwise.1548*1549* context: The context pointer that was passed to the callout.1550*1551*/15521553typedef void (DNSSD_API *DNSServiceGetAddrInfoReply)1554(1555DNSServiceRef sdRef,1556DNSServiceFlags flags,1557uint32_t interfaceIndex,1558DNSServiceErrorType errorCode,1559const char *hostname,1560const struct sockaddr *address,1561uint32_t ttl,1562void *context1563);156415651566/* DNSServiceGetAddrInfo() Parameters:1567*1568* sdRef: A pointer to an uninitialized DNSServiceRef. If the call succeeds then it1569* initializes the DNSServiceRef, returns kDNSServiceErr_NoError, and the query1570* begins and will last indefinitely until the client terminates the query1571* by passing this DNSServiceRef to DNSServiceRefDeallocate().1572*1573* flags: kDNSServiceFlagsForceMulticast or kDNSServiceFlagsLongLivedQuery.1574* Pass kDNSServiceFlagsLongLivedQuery to create a "long-lived" unicast1575* query in a non-local domain. Without setting this flag, unicast queries1576* will be one-shot - that is, only answers available at the time of the call1577* will be returned. By setting this flag, answers (including Add and Remove1578* events) that become available after the initial call is made will generate1579* callbacks. This flag has no effect on link-local multicast queries.1580*1581* interfaceIndex: The interface on which to issue the query. Passing 0 causes the query to be1582* sent on all active interfaces via Multicast or the primary interface via Unicast.1583*1584* protocol: Pass in kDNSServiceProtocol_IPv4 to look up IPv4 addresses, or kDNSServiceProtocol_IPv61585* to look up IPv6 addresses, or both to look up both kinds. If neither flag is1586* set, the system will apply an intelligent heuristic, which is (currently)1587* that it will attempt to look up both, except:1588*1589* * If "hostname" is a wide-area unicast DNS hostname (i.e. not a ".local." name)1590* but this host has no routable IPv6 address, then the call will not try to1591* look up IPv6 addresses for "hostname", since any addresses it found would be1592* unlikely to be of any use anyway. Similarly, if this host has no routable1593* IPv4 address, the call will not try to look up IPv4 addresses for "hostname".1594*1595* hostname: The fully qualified domain name of the host to be queried for.1596*1597* callBack: The function to be called when the query succeeds or fails asynchronously.1598*1599* context: An application context pointer which is passed to the callback function1600* (may be NULL).1601*1602* return value: Returns kDNSServiceErr_NoError on success (any subsequent, asynchronous1603* errors are delivered to the callback), otherwise returns an error code indicating1604* the error that occurred.1605*/16061607DNSServiceErrorType DNSSD_API DNSServiceGetAddrInfo1608(1609DNSServiceRef *sdRef,1610DNSServiceFlags flags,1611uint32_t interfaceIndex,1612DNSServiceProtocol protocol,1613const char *hostname,1614DNSServiceGetAddrInfoReply callBack,1615void *context /* may be NULL */1616);161716181619/*********************************************************************************************1620*1621* Special Purpose Calls:1622* DNSServiceCreateConnection(), DNSServiceRegisterRecord(), DNSServiceReconfirmRecord()1623* (most applications will not use these)1624*1625*********************************************************************************************/16261627/* DNSServiceCreateConnection()1628*1629* Create a connection to the daemon allowing efficient registration of1630* multiple individual records.1631*1632* Parameters:1633*1634* sdRef: A pointer to an uninitialized DNSServiceRef. Deallocating1635* the reference (via DNSServiceRefDeallocate()) severs the1636* connection and deregisters all records registered on this connection.1637*1638* return value: Returns kDNSServiceErr_NoError on success, otherwise returns1639* an error code indicating the specific failure that occurred (in which1640* case the DNSServiceRef is not initialized).1641*/16421643DNSServiceErrorType DNSSD_API DNSServiceCreateConnection(DNSServiceRef *sdRef);164416451646/* DNSServiceRegisterRecord1647*1648* Register an individual resource record on a connected DNSServiceRef.1649*1650* Note that name conflicts occurring for records registered via this call must be handled1651* by the client in the callback.1652*1653* DNSServiceRegisterRecordReply() parameters:1654*1655* sdRef: The connected DNSServiceRef initialized by1656* DNSServiceCreateConnection().1657*1658* RecordRef: The DNSRecordRef initialized by DNSServiceRegisterRecord(). If the above1659* DNSServiceRef is passed to DNSServiceRefDeallocate(), this DNSRecordRef is1660* invalidated, and may not be used further.1661*1662* flags: Currently unused, reserved for future use.1663*1664* errorCode: Will be kDNSServiceErr_NoError on success, otherwise will1665* indicate the failure that occurred (including name conflicts.)1666* Other parameters are undefined if errorCode is nonzero.1667*1668* context: The context pointer that was passed to the callout.1669*1670*/16711672typedef void (DNSSD_API *DNSServiceRegisterRecordReply)1673(1674DNSServiceRef sdRef,1675DNSRecordRef RecordRef,1676DNSServiceFlags flags,1677DNSServiceErrorType errorCode,1678void *context1679);168016811682/* DNSServiceRegisterRecord() Parameters:1683*1684* sdRef: A DNSServiceRef initialized by DNSServiceCreateConnection().1685*1686* RecordRef: A pointer to an uninitialized DNSRecordRef. Upon succesfull completion of this1687* call, this ref may be passed to DNSServiceUpdateRecord() or DNSServiceRemoveRecord().1688* (To deregister ALL records registered on a single connected DNSServiceRef1689* and deallocate each of their corresponding DNSServiceRecordRefs, call1690* DNSServiceRefDeallocate()).1691*1692* flags: Possible values are kDNSServiceFlagsShared or kDNSServiceFlagsUnique1693* (see flag type definitions for details).1694*1695* interfaceIndex: If non-zero, specifies the interface on which to register the record1696* (the index for a given interface is determined via the if_nametoindex()1697* family of calls.) Passing 0 causes the record to be registered on all interfaces.1698* See "Constants for specifying an interface index" for more details.1699*1700* fullname: The full domain name of the resource record.1701*1702* rrtype: The numerical type of the resource record (e.g. kDNSServiceType_PTR, kDNSServiceType_SRV, etc)1703*1704* rrclass: The class of the resource record (usually kDNSServiceClass_IN)1705*1706* rdlen: Length, in bytes, of the rdata.1707*1708* rdata: A pointer to the raw rdata, as it is to appear in the DNS record.1709*1710* ttl: The time to live of the resource record, in seconds.1711* Most clients should pass 0 to indicate that the system should1712* select a sensible default value.1713*1714* callBack: The function to be called when a result is found, or if the call1715* asynchronously fails (e.g. because of a name conflict.)1716*1717* context: An application context pointer which is passed to the callback function1718* (may be NULL).1719*1720* return value: Returns kDNSServiceErr_NoError on success (any subsequent, asynchronous1721* errors are delivered to the callback), otherwise returns an error code indicating1722* the error that occurred (the callback is never invoked and the DNSRecordRef is1723* not initialized).1724*/17251726DNSServiceErrorType DNSSD_API DNSServiceRegisterRecord1727(1728DNSServiceRef sdRef,1729DNSRecordRef *RecordRef,1730DNSServiceFlags flags,1731uint32_t interfaceIndex,1732const char *fullname,1733uint16_t rrtype,1734uint16_t rrclass,1735uint16_t rdlen,1736const void *rdata,1737uint32_t ttl,1738DNSServiceRegisterRecordReply callBack,1739void *context /* may be NULL */1740);174117421743/* DNSServiceReconfirmRecord1744*1745* Instruct the daemon to verify the validity of a resource record that appears1746* to be out of date (e.g. because TCP connection to a service's target failed.)1747* Causes the record to be flushed from the daemon's cache (as well as all other1748* daemons' caches on the network) if the record is determined to be invalid.1749* Use this routine conservatively. Reconfirming a record necessarily consumes1750* network bandwidth, so this should not be done indiscriminately.1751*1752* Parameters:1753*1754* flags: Pass kDNSServiceFlagsForce to force immediate deletion of record,1755* instead of after some number of reconfirmation queries have gone unanswered.1756*1757* interfaceIndex: Specifies the interface of the record in question.1758* The caller must specify the interface.1759* This API (by design) causes increased network traffic, so it requires1760* the caller to be precise about which record should be reconfirmed.1761* It is not possible to pass zero for the interface index to perform1762* a "wildcard" reconfirmation, where *all* matching records are reconfirmed.1763*1764* fullname: The resource record's full domain name.1765*1766* rrtype: The resource record's type (e.g. kDNSServiceType_PTR, kDNSServiceType_SRV, etc)1767*1768* rrclass: The class of the resource record (usually kDNSServiceClass_IN).1769*1770* rdlen: The length, in bytes, of the resource record rdata.1771*1772* rdata: The raw rdata of the resource record.1773*1774*/17751776DNSServiceErrorType DNSSD_API DNSServiceReconfirmRecord1777(1778DNSServiceFlags flags,1779uint32_t interfaceIndex,1780const char *fullname,1781uint16_t rrtype,1782uint16_t rrclass,1783uint16_t rdlen,1784const void *rdata1785);178617871788/*********************************************************************************************1789*1790* NAT Port Mapping1791*1792*********************************************************************************************/17931794/* DNSServiceNATPortMappingCreate1795*1796* Request a port mapping in the NAT gateway, which maps a port on the local machine1797* to an external port on the NAT. The NAT should support either the NAT-PMP or the UPnP IGD1798* protocol for this API to create a successful mapping.1799*1800* The port mapping will be renewed indefinitely until the client process exits, or1801* explicitly terminates the port mapping request by calling DNSServiceRefDeallocate().1802* The client callback will be invoked, informing the client of the NAT gateway's1803* external IP address and the external port that has been allocated for this client.1804* The client should then record this external IP address and port using whatever1805* directory service mechanism it is using to enable peers to connect to it.1806* (Clients advertising services using Wide-Area DNS-SD DO NOT need to use this API1807* -- when a client calls DNSServiceRegister() NAT mappings are automatically created1808* and the external IP address and port for the service are recorded in the global DNS.1809* Only clients using some directory mechanism other than Wide-Area DNS-SD need to use1810* this API to explicitly map their own ports.)1811*1812* It's possible that the client callback could be called multiple times, for example1813* if the NAT gateway's IP address changes, or if a configuration change results in a1814* different external port being mapped for this client. Over the lifetime of any long-lived1815* port mapping, the client should be prepared to handle these notifications of changes1816* in the environment, and should update its recorded address and/or port as appropriate.1817*1818* NOTE: There are two unusual aspects of how the DNSServiceNATPortMappingCreate API works,1819* which were intentionally designed to help simplify client code:1820*1821* 1. It's not an error to request a NAT mapping when the machine is not behind a NAT gateway.1822* In other NAT mapping APIs, if you request a NAT mapping and the machine is not behind a NAT1823* gateway, then the API returns an error code -- it can't get you a NAT mapping if there's no1824* NAT gateway. The DNSServiceNATPortMappingCreate API takes a different view. Working out1825* whether or not you need a NAT mapping can be tricky and non-obvious, particularly on1826* a machine with multiple active network interfaces. Rather than make every client recreate1827* this logic for deciding whether a NAT mapping is required, the PortMapping API does that1828* work for you. If the client calls the PortMapping API when the machine already has a1829* routable public IP address, then instead of complaining about it and giving an error,1830* the PortMapping API just invokes your callback, giving the machine's public address1831* and your own port number. This means you don't need to write code to work out whether1832* your client needs to call the PortMapping API -- just call it anyway, and if it wasn't1833* necessary, no harm is done:1834*1835* - If the machine already has a routable public IP address, then your callback1836* will just be invoked giving your own address and port.1837* - If a NAT mapping is required and obtained, then your callback will be invoked1838* giving you the external address and port.1839* - If a NAT mapping is required but not obtained from the local NAT gateway,1840* or the machine has no network connectivity, then your callback will be1841* invoked giving zero address and port.1842*1843* 2. In other NAT mapping APIs, if a laptop computer is put to sleep and woken up on a new1844* network, it's the client's job to notice this, and work out whether a NAT mapping1845* is required on the new network, and make a new NAT mapping request if necessary.1846* The DNSServiceNATPortMappingCreate API does this for you, automatically.1847* The client just needs to make one call to the PortMapping API, and its callback will1848* be invoked any time the mapping state changes. This property complements point (1) above.1849* If the client didn't make a NAT mapping request just because it determined that one was1850* not required at that particular moment in time, the client would then have to monitor1851* for network state changes to determine if a NAT port mapping later became necessary.1852* By unconditionally making a NAT mapping request, even when a NAT mapping not to be1853* necessary, the PortMapping API will then begin monitoring network state changes on behalf of1854* the client, and if a NAT mapping later becomes necessary, it will automatically create a NAT1855* mapping and inform the client with a new callback giving the new address and port information.1856*1857* DNSServiceNATPortMappingReply() parameters:1858*1859* sdRef: The DNSServiceRef initialized by DNSServiceNATPortMappingCreate().1860*1861* flags: Currently unused, reserved for future use.1862*1863* interfaceIndex: The interface through which the NAT gateway is reached.1864*1865* errorCode: Will be kDNSServiceErr_NoError on success.1866* Will be kDNSServiceErr_DoubleNAT when the NAT gateway is itself behind one or1867* more layers of NAT, in which case the other parameters have the defined values.1868* For other failures, will indicate the failure that occurred, and the other1869* parameters are undefined.1870*1871* externalAddress: Four byte IPv4 address in network byte order.1872*1873* protocol: Will be kDNSServiceProtocol_UDP or kDNSServiceProtocol_TCP or both.1874*1875* internalPort: The port on the local machine that was mapped.1876*1877* externalPort: The actual external port in the NAT gateway that was mapped.1878* This is likely to be different than the requested external port.1879*1880* ttl: The lifetime of the NAT port mapping created on the gateway.1881* This controls how quickly stale mappings will be garbage-collected1882* if the client machine crashes, suffers a power failure, is disconnected1883* from the network, or suffers some other unfortunate demise which1884* causes it to vanish without explicitly removing its NAT port mapping.1885* It's possible that the ttl value will differ from the requested ttl value.1886*1887* context: The context pointer that was passed to the callout.1888*1889*/18901891typedef void (DNSSD_API *DNSServiceNATPortMappingReply)1892(1893DNSServiceRef sdRef,1894DNSServiceFlags flags,1895uint32_t interfaceIndex,1896DNSServiceErrorType errorCode,1897uint32_t externalAddress, /* four byte IPv4 address in network byte order */1898DNSServiceProtocol protocol,1899uint16_t internalPort, /* In network byte order */1900uint16_t externalPort, /* In network byte order and may be different than the requested port */1901uint32_t ttl, /* may be different than the requested ttl */1902void *context1903);190419051906/* DNSServiceNATPortMappingCreate() Parameters:1907*1908* sdRef: A pointer to an uninitialized DNSServiceRef. If the call succeeds then it1909* initializes the DNSServiceRef, returns kDNSServiceErr_NoError, and the nat1910* port mapping will last indefinitely until the client terminates the port1911* mapping request by passing this DNSServiceRef to DNSServiceRefDeallocate().1912*1913* flags: Currently ignored, reserved for future use.1914*1915* interfaceIndex: The interface on which to create port mappings in a NAT gateway. Passing 0 causes1916* the port mapping request to be sent on the primary interface.1917*1918* protocol: To request a port mapping, pass in kDNSServiceProtocol_UDP, or kDNSServiceProtocol_TCP,1919* or (kDNSServiceProtocol_UDP | kDNSServiceProtocol_TCP) to map both.1920* The local listening port number must also be specified in the internalPort parameter.1921* To just discover the NAT gateway's external IP address, pass zero for protocol,1922* internalPort, externalPort and ttl.1923*1924* internalPort: The port number in network byte order on the local machine which is listening for packets.1925*1926* externalPort: The requested external port in network byte order in the NAT gateway that you would1927* like to map to the internal port. Pass 0 if you don't care which external port is chosen for you.1928*1929* ttl: The requested renewal period of the NAT port mapping, in seconds.1930* If the client machine crashes, suffers a power failure, is disconnected from1931* the network, or suffers some other unfortunate demise which causes it to vanish1932* unexpectedly without explicitly removing its NAT port mappings, then the NAT gateway1933* will garbage-collect old stale NAT port mappings when their lifetime expires.1934* Requesting a short TTL causes such orphaned mappings to be garbage-collected1935* more promptly, but consumes system resources and network bandwidth with1936* frequent renewal packets to keep the mapping from expiring.1937* Requesting a long TTL is more efficient on the network, but in the event of the1938* client vanishing, stale NAT port mappings will not be garbage-collected as quickly.1939* Most clients should pass 0 to use a system-wide default value.1940*1941* callBack: The function to be called when the port mapping request succeeds or fails asynchronously.1942*1943* context: An application context pointer which is passed to the callback function1944* (may be NULL).1945*1946* return value: Returns kDNSServiceErr_NoError on success (any subsequent, asynchronous1947* errors are delivered to the callback), otherwise returns an error code indicating1948* the error that occurred.1949*1950* If you don't actually want a port mapped, and are just calling the API1951* because you want to find out the NAT's external IP address (e.g. for UI1952* display) then pass zero for protocol, internalPort, externalPort and ttl.1953*/19541955DNSServiceErrorType DNSSD_API DNSServiceNATPortMappingCreate1956(1957DNSServiceRef *sdRef,1958DNSServiceFlags flags,1959uint32_t interfaceIndex,1960DNSServiceProtocol protocol, /* TCP and/or UDP */1961uint16_t internalPort, /* network byte order */1962uint16_t externalPort, /* network byte order */1963uint32_t ttl, /* time to live in seconds */1964DNSServiceNATPortMappingReply callBack,1965void *context /* may be NULL */1966);196719681969/*********************************************************************************************1970*1971* General Utility Functions1972*1973*********************************************************************************************/19741975/* DNSServiceConstructFullName()1976*1977* Concatenate a three-part domain name (as returned by the above callbacks) into a1978* properly-escaped full domain name. Note that callbacks in the above functions ALREADY ESCAPE1979* strings where necessary.1980*1981* Parameters:1982*1983* fullName: A pointer to a buffer that where the resulting full domain name is to be written.1984* The buffer must be kDNSServiceMaxDomainName (1009) bytes in length to1985* accommodate the longest legal domain name without buffer overrun.1986*1987* service: The service name - any dots or backslashes must NOT be escaped.1988* May be NULL (to construct a PTR record name, e.g.1989* "_ftp._tcp.apple.com.").1990*1991* regtype: The service type followed by the protocol, separated by a dot1992* (e.g. "_ftp._tcp").1993*1994* domain: The domain name, e.g. "apple.com.". Literal dots or backslashes,1995* if any, must be escaped, e.g. "1st\. Floor.apple.com."1996*1997* return value: Returns kDNSServiceErr_NoError (0) on success, kDNSServiceErr_BadParam on error.1998*1999*/20002001DNSServiceErrorType DNSSD_API DNSServiceConstructFullName2002(2003char * const fullName,2004const char * const service, /* may be NULL */2005const char * const regtype,2006const char * const domain2007);200820092010/*********************************************************************************************2011*2012* TXT Record Construction Functions2013*2014*********************************************************************************************/20152016/*2017* A typical calling sequence for TXT record construction is something like:2018*2019* Client allocates storage for TXTRecord data (e.g. declare buffer on the stack)2020* TXTRecordCreate();2021* TXTRecordSetValue();2022* TXTRecordSetValue();2023* TXTRecordSetValue();2024* ...2025* DNSServiceRegister( ... TXTRecordGetLength(), TXTRecordGetBytesPtr() ... );2026* TXTRecordDeallocate();2027* Explicitly deallocate storage for TXTRecord data (if not allocated on the stack)2028*/202920302031/* TXTRecordRef2032*2033* Opaque internal data type.2034* Note: Represents a DNS-SD TXT record.2035*/20362037typedef union _TXTRecordRef_t { char PrivateData[16]; char *ForceNaturalAlignment; } TXTRecordRef;203820392040/* TXTRecordCreate()2041*2042* Creates a new empty TXTRecordRef referencing the specified storage.2043*2044* If the buffer parameter is NULL, or the specified storage size is not2045* large enough to hold a key subsequently added using TXTRecordSetValue(),2046* then additional memory will be added as needed using malloc().2047*2048* On some platforms, when memory is low, malloc() may fail. In this2049* case, TXTRecordSetValue() will return kDNSServiceErr_NoMemory, and this2050* error condition will need to be handled as appropriate by the caller.2051*2052* You can avoid the need to handle this error condition if you ensure2053* that the storage you initially provide is large enough to hold all2054* the key/value pairs that are to be added to the record.2055* The caller can precompute the exact length required for all of the2056* key/value pairs to be added, or simply provide a fixed-sized buffer2057* known in advance to be large enough.2058* A no-value (key-only) key requires (1 + key length) bytes.2059* A key with empty value requires (1 + key length + 1) bytes.2060* A key with non-empty value requires (1 + key length + 1 + value length).2061* For most applications, DNS-SD TXT records are generally2062* less than 100 bytes, so in most cases a simple fixed-sized2063* 256-byte buffer will be more than sufficient.2064* Recommended size limits for DNS-SD TXT Records are discussed in2065* <http://files.dns-sd.org/draft-cheshire-dnsext-dns-sd.txt>2066*2067* Note: When passing parameters to and from these TXT record APIs,2068* the key name does not include the '=' character. The '=' character2069* is the separator between the key and value in the on-the-wire2070* packet format; it is not part of either the key or the value.2071*2072* txtRecord: A pointer to an uninitialized TXTRecordRef.2073*2074* bufferLen: The size of the storage provided in the "buffer" parameter.2075*2076* buffer: Optional caller-supplied storage used to hold the TXTRecord data.2077* This storage must remain valid for as long as2078* the TXTRecordRef.2079*/20802081void DNSSD_API TXTRecordCreate2082(2083TXTRecordRef *txtRecord,2084uint16_t bufferLen,2085void *buffer2086);208720882089/* TXTRecordDeallocate()2090*2091* Releases any resources allocated in the course of preparing a TXT Record2092* using TXTRecordCreate()/TXTRecordSetValue()/TXTRecordRemoveValue().2093* Ownership of the buffer provided in TXTRecordCreate() returns to the client.2094*2095* txtRecord: A TXTRecordRef initialized by calling TXTRecordCreate().2096*2097*/20982099void DNSSD_API TXTRecordDeallocate2100(2101TXTRecordRef *txtRecord2102);210321042105/* TXTRecordSetValue()2106*2107* Adds a key (optionally with value) to a TXTRecordRef. If the "key" already2108* exists in the TXTRecordRef, then the current value will be replaced with2109* the new value.2110* Keys may exist in four states with respect to a given TXT record:2111* - Absent (key does not appear at all)2112* - Present with no value ("key" appears alone)2113* - Present with empty value ("key=" appears in TXT record)2114* - Present with non-empty value ("key=value" appears in TXT record)2115* For more details refer to "Data Syntax for DNS-SD TXT Records" in2116* <http://files.dns-sd.org/draft-cheshire-dnsext-dns-sd.txt>2117*2118* txtRecord: A TXTRecordRef initialized by calling TXTRecordCreate().2119*2120* key: A null-terminated string which only contains printable ASCII2121* values (0x20-0x7E), excluding '=' (0x3D). Keys should be2122* 9 characters or fewer (not counting the terminating null).2123*2124* valueSize: The size of the value.2125*2126* value: Any binary value. For values that represent2127* textual data, UTF-8 is STRONGLY recommended.2128* For values that represent textual data, valueSize2129* should NOT include the terminating null (if any)2130* at the end of the string.2131* If NULL, then "key" will be added with no value.2132* If non-NULL but valueSize is zero, then "key=" will be2133* added with empty value.2134*2135* return value: Returns kDNSServiceErr_NoError on success.2136* Returns kDNSServiceErr_Invalid if the "key" string contains2137* illegal characters.2138* Returns kDNSServiceErr_NoMemory if adding this key would2139* exceed the available storage.2140*/21412142DNSServiceErrorType DNSSD_API TXTRecordSetValue2143(2144TXTRecordRef *txtRecord,2145const char *key,2146uint8_t valueSize, /* may be zero */2147const void *value /* may be NULL */2148);214921502151/* TXTRecordRemoveValue()2152*2153* Removes a key from a TXTRecordRef. The "key" must be an2154* ASCII string which exists in the TXTRecordRef.2155*2156* txtRecord: A TXTRecordRef initialized by calling TXTRecordCreate().2157*2158* key: A key name which exists in the TXTRecordRef.2159*2160* return value: Returns kDNSServiceErr_NoError on success.2161* Returns kDNSServiceErr_NoSuchKey if the "key" does not2162* exist in the TXTRecordRef.2163*/21642165DNSServiceErrorType DNSSD_API TXTRecordRemoveValue2166(2167TXTRecordRef *txtRecord,2168const char *key2169);217021712172/* TXTRecordGetLength()2173*2174* Allows you to determine the length of the raw bytes within a TXTRecordRef.2175*2176* txtRecord: A TXTRecordRef initialized by calling TXTRecordCreate().2177*2178* return value: Returns the size of the raw bytes inside a TXTRecordRef2179* which you can pass directly to DNSServiceRegister() or2180* to DNSServiceUpdateRecord().2181* Returns 0 if the TXTRecordRef is empty.2182*/21832184uint16_t DNSSD_API TXTRecordGetLength2185(2186const TXTRecordRef *txtRecord2187);218821892190/* TXTRecordGetBytesPtr()2191*2192* Allows you to retrieve a pointer to the raw bytes within a TXTRecordRef.2193*2194* txtRecord: A TXTRecordRef initialized by calling TXTRecordCreate().2195*2196* return value: Returns a pointer to the raw bytes inside the TXTRecordRef2197* which you can pass directly to DNSServiceRegister() or2198* to DNSServiceUpdateRecord().2199*/22002201const void * DNSSD_API TXTRecordGetBytesPtr2202(2203const TXTRecordRef *txtRecord2204);220522062207/*********************************************************************************************2208*2209* TXT Record Parsing Functions2210*2211*********************************************************************************************/22122213/*2214* A typical calling sequence for TXT record parsing is something like:2215*2216* Receive TXT record data in DNSServiceResolve() callback2217* if (TXTRecordContainsKey(txtLen, txtRecord, "key")) then do something2218* val1ptr = TXTRecordGetValuePtr(txtLen, txtRecord, "key1", &len1);2219* val2ptr = TXTRecordGetValuePtr(txtLen, txtRecord, "key2", &len2);2220* ...2221* memcpy(myval1, val1ptr, len1);2222* memcpy(myval2, val2ptr, len2);2223* ...2224* return;2225*2226* If you wish to retain the values after return from the DNSServiceResolve()2227* callback, then you need to copy the data to your own storage using memcpy()2228* or similar, as shown in the example above.2229*2230* If for some reason you need to parse a TXT record you built yourself2231* using the TXT record construction functions above, then you can do2232* that using TXTRecordGetLength and TXTRecordGetBytesPtr calls:2233* TXTRecordGetValue(TXTRecordGetLength(x), TXTRecordGetBytesPtr(x), key, &len);2234*2235* Most applications only fetch keys they know about from a TXT record and2236* ignore the rest.2237* However, some debugging tools wish to fetch and display all keys.2238* To do that, use the TXTRecordGetCount() and TXTRecordGetItemAtIndex() calls.2239*/22402241/* TXTRecordContainsKey()2242*2243* Allows you to determine if a given TXT Record contains a specified key.2244*2245* txtLen: The size of the received TXT Record.2246*2247* txtRecord: Pointer to the received TXT Record bytes.2248*2249* key: A null-terminated ASCII string containing the key name.2250*2251* return value: Returns 1 if the TXT Record contains the specified key.2252* Otherwise, it returns 0.2253*/22542255int DNSSD_API TXTRecordContainsKey2256(2257uint16_t txtLen,2258const void *txtRecord,2259const char *key2260);226122622263/* TXTRecordGetValuePtr()2264*2265* Allows you to retrieve the value for a given key from a TXT Record.2266*2267* txtLen: The size of the received TXT Record2268*2269* txtRecord: Pointer to the received TXT Record bytes.2270*2271* key: A null-terminated ASCII string containing the key name.2272*2273* valueLen: On output, will be set to the size of the "value" data.2274*2275* return value: Returns NULL if the key does not exist in this TXT record,2276* or exists with no value (to differentiate between2277* these two cases use TXTRecordContainsKey()).2278* Returns pointer to location within TXT Record bytes2279* if the key exists with empty or non-empty value.2280* For empty value, valueLen will be zero.2281* For non-empty value, valueLen will be length of value data.2282*/22832284const void * DNSSD_API TXTRecordGetValuePtr2285(2286uint16_t txtLen,2287const void *txtRecord,2288const char *key,2289uint8_t *valueLen2290);229122922293/* TXTRecordGetCount()2294*2295* Returns the number of keys stored in the TXT Record. The count2296* can be used with TXTRecordGetItemAtIndex() to iterate through the keys.2297*2298* txtLen: The size of the received TXT Record.2299*2300* txtRecord: Pointer to the received TXT Record bytes.2301*2302* return value: Returns the total number of keys in the TXT Record.2303*2304*/23052306uint16_t DNSSD_API TXTRecordGetCount2307(2308uint16_t txtLen,2309const void *txtRecord2310);231123122313/* TXTRecordGetItemAtIndex()2314*2315* Allows you to retrieve a key name and value pointer, given an index into2316* a TXT Record. Legal index values range from zero to TXTRecordGetCount()-1.2317* It's also possible to iterate through keys in a TXT record by simply2318* calling TXTRecordGetItemAtIndex() repeatedly, beginning with index zero2319* and increasing until TXTRecordGetItemAtIndex() returns kDNSServiceErr_Invalid.2320*2321* On return:2322* For keys with no value, *value is set to NULL and *valueLen is zero.2323* For keys with empty value, *value is non-NULL and *valueLen is zero.2324* For keys with non-empty value, *value is non-NULL and *valueLen is non-zero.2325*2326* txtLen: The size of the received TXT Record.2327*2328* txtRecord: Pointer to the received TXT Record bytes.2329*2330* itemIndex: An index into the TXT Record.2331*2332* keyBufLen: The size of the string buffer being supplied.2333*2334* key: A string buffer used to store the key name.2335* On return, the buffer contains a null-terminated C string2336* giving the key name. DNS-SD TXT keys are usually2337* 9 characters or fewer. To hold the maximum possible2338* key name, the buffer should be 256 bytes long.2339*2340* valueLen: On output, will be set to the size of the "value" data.2341*2342* value: On output, *value is set to point to location within TXT2343* Record bytes that holds the value data.2344*2345* return value: Returns kDNSServiceErr_NoError on success.2346* Returns kDNSServiceErr_NoMemory if keyBufLen is too short.2347* Returns kDNSServiceErr_Invalid if index is greater than2348* TXTRecordGetCount()-1.2349*/23502351DNSServiceErrorType DNSSD_API TXTRecordGetItemAtIndex2352(2353uint16_t txtLen,2354const void *txtRecord,2355uint16_t itemIndex,2356uint16_t keyBufLen,2357char *key,2358uint8_t *valueLen,2359const void **value2360);23612362#if _DNS_SD_LIBDISPATCH2363/*2364* DNSServiceSetDispatchQueue2365*2366* Allows you to schedule a DNSServiceRef on a serial dispatch queue for receiving asynchronous2367* callbacks. It's the clients responsibility to ensure that the provided dispatch queue is running.2368*2369* A typical application that uses CFRunLoopRun or dispatch_main on its main thread will2370* usually schedule DNSServiceRefs on its main queue (which is always a serial queue)2371* using "DNSServiceSetDispatchQueue(sdref, dispatch_get_main_queue());"2372*2373* If there is any error during the processing of events, the application callback will2374* be called with an error code. For shared connections, each subordinate DNSServiceRef2375* will get its own error callback. Currently these error callbacks only happen2376* if the mDNSResponder daemon is manually terminated or crashes, and the error2377* code in this case is kDNSServiceErr_ServiceNotRunning. The application must call2378* DNSServiceRefDeallocate to free the DNSServiceRef when it gets such an error code.2379* These error callbacks are rare and should not normally happen on customer machines,2380* but application code should be written defensively to handle such error callbacks2381* gracefully if they occur.2382*2383* After using DNSServiceSetDispatchQueue on a DNSServiceRef, calling DNSServiceProcessResult2384* on the same DNSServiceRef will result in undefined behavior and should be avoided.2385*2386* Once the application successfully schedules a DNSServiceRef on a serial dispatch queue using2387* DNSServiceSetDispatchQueue, it cannot remove the DNSServiceRef from the dispatch queue, or use2388* DNSServiceSetDispatchQueue a second time to schedule the DNSServiceRef onto a different serial dispatch2389* queue. Once scheduled onto a dispatch queue a DNSServiceRef will deliver events to that queue until2390* the application no longer requires that operation and terminates it using DNSServiceRefDeallocate.2391*2392* service: DNSServiceRef that was allocated and returned to the application, when the2393* application calls one of the DNSService API.2394*2395* queue: dispatch queue where the application callback will be scheduled2396*2397* return value: Returns kDNSServiceErr_NoError on success.2398* Returns kDNSServiceErr_NoMemory if it cannot create a dispatch source2399* Returns kDNSServiceErr_BadParam if the service param is invalid or the2400* queue param is invalid2401*/24022403DNSServiceErrorType DNSSD_API DNSServiceSetDispatchQueue2404(2405DNSServiceRef service,2406dispatch_queue_t queue2407);2408#endif //_DNS_SD_LIBDISPATCH24092410#ifdef __APPLE_API_PRIVATE24112412#define kDNSServiceCompPrivateDNS "PrivateDNS"2413#define kDNSServiceCompMulticastDNS "MulticastDNS"24142415#endif //__APPLE_API_PRIVATE24162417/* Some C compiler cleverness. We can make the compiler check certain things for us,2418* and report errors at compile-time if anything is wrong. The usual way to do this would2419* be to use a run-time "if" statement or the conventional run-time "assert" mechanism, but2420* then you don't find out what's wrong until you run the software. This way, if the assertion2421* condition is false, the array size is negative, and the complier complains immediately.2422*/24232424struct CompileTimeAssertionChecks_DNS_SD2425{2426char assert0[(sizeof(union _TXTRecordRef_t) == 16) ? 1 : -1];2427};24282429#ifdef __cplusplus2430}2431#endif24322433#endif /* _DNS_SD_H */243424352436