1*5e7646d2SAndroid Build Coastguard Worker /* -*- Mode: C; tab-width: 4 -*- 2*5e7646d2SAndroid Build Coastguard Worker * 3*5e7646d2SAndroid Build Coastguard Worker * Copyright (c) 2003-2004, Apple Computer, Inc. All rights reserved. 4*5e7646d2SAndroid Build Coastguard Worker * 5*5e7646d2SAndroid Build Coastguard Worker * Redistribution and use in source and binary forms, with or without 6*5e7646d2SAndroid Build Coastguard Worker * modification, are permitted provided that the following conditions are met: 7*5e7646d2SAndroid Build Coastguard Worker * 8*5e7646d2SAndroid Build Coastguard Worker * 1. Redistributions of source code must retain the above copyright notice, 9*5e7646d2SAndroid Build Coastguard Worker * this list of conditions and the following disclaimer. 10*5e7646d2SAndroid Build Coastguard Worker * 2. Redistributions in binary form must reproduce the above copyright notice, 11*5e7646d2SAndroid Build Coastguard Worker * this list of conditions and the following disclaimer in the documentation 12*5e7646d2SAndroid Build Coastguard Worker * and/or other materials provided with the distribution. 13*5e7646d2SAndroid Build Coastguard Worker * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of its 14*5e7646d2SAndroid Build Coastguard Worker * contributors may be used to endorse or promote products derived from this 15*5e7646d2SAndroid Build Coastguard Worker * software without specific prior written permission. 16*5e7646d2SAndroid Build Coastguard Worker * 17*5e7646d2SAndroid Build Coastguard Worker * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY 18*5e7646d2SAndroid Build Coastguard Worker * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19*5e7646d2SAndroid Build Coastguard Worker * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20*5e7646d2SAndroid Build Coastguard Worker * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY 21*5e7646d2SAndroid Build Coastguard Worker * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22*5e7646d2SAndroid Build Coastguard Worker * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23*5e7646d2SAndroid Build Coastguard Worker * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24*5e7646d2SAndroid Build Coastguard Worker * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25*5e7646d2SAndroid Build Coastguard Worker * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26*5e7646d2SAndroid Build Coastguard Worker * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27*5e7646d2SAndroid Build Coastguard Worker */ 28*5e7646d2SAndroid Build Coastguard Worker 29*5e7646d2SAndroid Build Coastguard Worker 30*5e7646d2SAndroid Build Coastguard Worker /*! @header DNS Service Discovery 31*5e7646d2SAndroid Build Coastguard Worker * 32*5e7646d2SAndroid Build Coastguard Worker * @discussion This section describes the functions, callbacks, and data structures 33*5e7646d2SAndroid Build Coastguard Worker * that make up the DNS Service Discovery API. 34*5e7646d2SAndroid Build Coastguard Worker * 35*5e7646d2SAndroid Build Coastguard Worker * The DNS Service Discovery API is part of Bonjour, Apple's implementation 36*5e7646d2SAndroid Build Coastguard Worker * of zero-configuration networking (ZEROCONF). 37*5e7646d2SAndroid Build Coastguard Worker * 38*5e7646d2SAndroid Build Coastguard Worker * Bonjour allows you to register a network service, such as a 39*5e7646d2SAndroid Build Coastguard Worker * printer or file server, so that it can be found by name or browsed 40*5e7646d2SAndroid Build Coastguard Worker * for by service type and domain. Using Bonjour, applications can 41*5e7646d2SAndroid Build Coastguard Worker * discover what services are available on the network, along with 42*5e7646d2SAndroid Build Coastguard Worker * all the information -- such as name, IP address, and port -- 43*5e7646d2SAndroid Build Coastguard Worker * necessary to access a particular service. 44*5e7646d2SAndroid Build Coastguard Worker * 45*5e7646d2SAndroid Build Coastguard Worker * In effect, Bonjour combines the functions of a local DNS server and 46*5e7646d2SAndroid Build Coastguard Worker * AppleTalk. Bonjour allows applications to provide user-friendly printer 47*5e7646d2SAndroid Build Coastguard Worker * and server browsing, among other things, over standard IP networks. 48*5e7646d2SAndroid Build Coastguard Worker * This behavior is a result of combining protocols such as multicast and 49*5e7646d2SAndroid Build Coastguard Worker * DNS to add new functionality to the network (such as multicast DNS). 50*5e7646d2SAndroid Build Coastguard Worker * 51*5e7646d2SAndroid Build Coastguard Worker * Bonjour gives applications easy access to services over local IP 52*5e7646d2SAndroid Build Coastguard Worker * networks without requiring the service or the application to support 53*5e7646d2SAndroid Build Coastguard Worker * an AppleTalk or a Netbeui stack, and without requiring a DNS server 54*5e7646d2SAndroid Build Coastguard Worker * for the local network. 55*5e7646d2SAndroid Build Coastguard Worker */ 56*5e7646d2SAndroid Build Coastguard Worker 57*5e7646d2SAndroid Build Coastguard Worker 58*5e7646d2SAndroid Build Coastguard Worker /* _DNS_SD_H contains the mDNSResponder version number for this header file, formatted as follows: 59*5e7646d2SAndroid Build Coastguard Worker * Major part of the build number * 10000 + 60*5e7646d2SAndroid Build Coastguard Worker * minor part of the build number * 100 61*5e7646d2SAndroid Build Coastguard Worker * For example, Mac OS X 10.4.9 has mDNSResponder-108.4, which would be represented as 62*5e7646d2SAndroid Build Coastguard Worker * version 1080400. This allows C code to do simple greater-than and less-than comparisons: 63*5e7646d2SAndroid Build Coastguard Worker * e.g. an application that requires the DNSServiceGetProperty() call (new in mDNSResponder-126) can check: 64*5e7646d2SAndroid Build Coastguard Worker * 65*5e7646d2SAndroid Build Coastguard Worker * #if _DNS_SD_H+0 >= 1260000 66*5e7646d2SAndroid Build Coastguard Worker * ... some C code that calls DNSServiceGetProperty() ... 67*5e7646d2SAndroid Build Coastguard Worker * #endif 68*5e7646d2SAndroid Build Coastguard Worker * 69*5e7646d2SAndroid Build Coastguard Worker * The version defined in this header file symbol allows for compile-time 70*5e7646d2SAndroid Build Coastguard Worker * checking, so that C code building with earlier versions of the header file 71*5e7646d2SAndroid Build Coastguard Worker * can avoid compile errors trying to use functions that aren't even defined 72*5e7646d2SAndroid Build Coastguard Worker * in those earlier versions. Similar checks may also be performed at run-time: 73*5e7646d2SAndroid Build Coastguard Worker * => weak linking -- to avoid link failures if run with an earlier 74*5e7646d2SAndroid Build Coastguard Worker * version of the library that's missing some desired symbol, or 75*5e7646d2SAndroid Build Coastguard Worker * => DNSServiceGetProperty(DaemonVersion) -- to verify whether the running daemon 76*5e7646d2SAndroid Build Coastguard Worker * ("system service" on Windows) meets some required minimum functionality level. 77*5e7646d2SAndroid Build Coastguard Worker */ 78*5e7646d2SAndroid Build Coastguard Worker 79*5e7646d2SAndroid Build Coastguard Worker #ifndef _DNS_SD_H 80*5e7646d2SAndroid Build Coastguard Worker #define _DNS_SD_H 3331000 81*5e7646d2SAndroid Build Coastguard Worker 82*5e7646d2SAndroid Build Coastguard Worker #ifdef __cplusplus 83*5e7646d2SAndroid Build Coastguard Worker extern "C" { 84*5e7646d2SAndroid Build Coastguard Worker #endif 85*5e7646d2SAndroid Build Coastguard Worker 86*5e7646d2SAndroid Build Coastguard Worker /* Set to 1 if libdispatch is supported 87*5e7646d2SAndroid Build Coastguard Worker * Note: May also be set by project and/or Makefile 88*5e7646d2SAndroid Build Coastguard Worker */ 89*5e7646d2SAndroid Build Coastguard Worker #ifndef _DNS_SD_LIBDISPATCH 90*5e7646d2SAndroid Build Coastguard Worker #define _DNS_SD_LIBDISPATCH 0 91*5e7646d2SAndroid Build Coastguard Worker #endif /* ndef _DNS_SD_LIBDISPATCH */ 92*5e7646d2SAndroid Build Coastguard Worker 93*5e7646d2SAndroid Build Coastguard Worker /* standard calling convention under Win32 is __stdcall */ 94*5e7646d2SAndroid Build Coastguard Worker /* Note: When compiling Intel EFI (Extensible Firmware Interface) under MS Visual Studio, the */ 95*5e7646d2SAndroid Build Coastguard Worker /* _WIN32 symbol is defined by the compiler even though it's NOT compiling code for Windows32 */ 96*5e7646d2SAndroid Build Coastguard Worker #if defined(_WIN32) && !defined(EFI32) && !defined(EFI64) 97*5e7646d2SAndroid Build Coastguard Worker #define DNSSD_API __stdcall 98*5e7646d2SAndroid Build Coastguard Worker #else 99*5e7646d2SAndroid Build Coastguard Worker #define DNSSD_API 100*5e7646d2SAndroid Build Coastguard Worker #endif 101*5e7646d2SAndroid Build Coastguard Worker 102*5e7646d2SAndroid Build Coastguard Worker /* stdint.h does not exist on FreeBSD 4.x; its types are defined in sys/types.h instead */ 103*5e7646d2SAndroid Build Coastguard Worker #if defined(__FreeBSD__) && (__FreeBSD__ < 5) 104*5e7646d2SAndroid Build Coastguard Worker #include <sys/types.h> 105*5e7646d2SAndroid Build Coastguard Worker 106*5e7646d2SAndroid Build Coastguard Worker /* Likewise, on Sun, standard integer types are in sys/types.h */ 107*5e7646d2SAndroid Build Coastguard Worker #elif defined(__sun__) 108*5e7646d2SAndroid Build Coastguard Worker #include <sys/types.h> 109*5e7646d2SAndroid Build Coastguard Worker 110*5e7646d2SAndroid Build Coastguard Worker /* EFI does not have stdint.h, or anything else equivalent */ 111*5e7646d2SAndroid Build Coastguard Worker #elif defined(EFI32) || defined(EFI64) || defined(EFIX64) 112*5e7646d2SAndroid Build Coastguard Worker #include "Tiano.h" 113*5e7646d2SAndroid Build Coastguard Worker #if !defined(_STDINT_H_) 114*5e7646d2SAndroid Build Coastguard Worker typedef UINT8 uint8_t; 115*5e7646d2SAndroid Build Coastguard Worker typedef INT8 int8_t; 116*5e7646d2SAndroid Build Coastguard Worker typedef UINT16 uint16_t; 117*5e7646d2SAndroid Build Coastguard Worker typedef INT16 int16_t; 118*5e7646d2SAndroid Build Coastguard Worker typedef UINT32 uint32_t; 119*5e7646d2SAndroid Build Coastguard Worker typedef INT32 int32_t; 120*5e7646d2SAndroid Build Coastguard Worker #endif 121*5e7646d2SAndroid Build Coastguard Worker /* Windows has its own differences */ 122*5e7646d2SAndroid Build Coastguard Worker #elif defined(_WIN32) 123*5e7646d2SAndroid Build Coastguard Worker #include <windows.h> 124*5e7646d2SAndroid Build Coastguard Worker #define _UNUSED 125*5e7646d2SAndroid Build Coastguard Worker #ifndef _MSL_STDINT_H 126*5e7646d2SAndroid Build Coastguard Worker typedef UINT8 uint8_t; 127*5e7646d2SAndroid Build Coastguard Worker typedef INT8 int8_t; 128*5e7646d2SAndroid Build Coastguard Worker typedef UINT16 uint16_t; 129*5e7646d2SAndroid Build Coastguard Worker typedef INT16 int16_t; 130*5e7646d2SAndroid Build Coastguard Worker typedef UINT32 uint32_t; 131*5e7646d2SAndroid Build Coastguard Worker typedef INT32 int32_t; 132*5e7646d2SAndroid Build Coastguard Worker #endif 133*5e7646d2SAndroid Build Coastguard Worker 134*5e7646d2SAndroid Build Coastguard Worker /* All other Posix platforms use stdint.h */ 135*5e7646d2SAndroid Build Coastguard Worker #else 136*5e7646d2SAndroid Build Coastguard Worker #include <stdint.h> 137*5e7646d2SAndroid Build Coastguard Worker #endif 138*5e7646d2SAndroid Build Coastguard Worker 139*5e7646d2SAndroid Build Coastguard Worker #if _DNS_SD_LIBDISPATCH 140*5e7646d2SAndroid Build Coastguard Worker #include <dispatch/dispatch.h> 141*5e7646d2SAndroid Build Coastguard Worker #endif 142*5e7646d2SAndroid Build Coastguard Worker 143*5e7646d2SAndroid Build Coastguard Worker /* DNSServiceRef, DNSRecordRef 144*5e7646d2SAndroid Build Coastguard Worker * 145*5e7646d2SAndroid Build Coastguard Worker * Opaque internal data types. 146*5e7646d2SAndroid Build Coastguard Worker * Note: client is responsible for serializing access to these structures if 147*5e7646d2SAndroid Build Coastguard Worker * they are shared between concurrent threads. 148*5e7646d2SAndroid Build Coastguard Worker */ 149*5e7646d2SAndroid Build Coastguard Worker 150*5e7646d2SAndroid Build Coastguard Worker typedef struct _DNSServiceRef_t *DNSServiceRef; 151*5e7646d2SAndroid Build Coastguard Worker typedef struct _DNSRecordRef_t *DNSRecordRef; 152*5e7646d2SAndroid Build Coastguard Worker 153*5e7646d2SAndroid Build Coastguard Worker struct sockaddr; 154*5e7646d2SAndroid Build Coastguard Worker 155*5e7646d2SAndroid Build Coastguard Worker /*! @enum General flags 156*5e7646d2SAndroid Build Coastguard Worker * Most DNS-SD API functions and callbacks include a DNSServiceFlags parameter. 157*5e7646d2SAndroid Build Coastguard Worker * As a general rule, any given bit in the 32-bit flags field has a specific fixed meaning, 158*5e7646d2SAndroid Build Coastguard Worker * regardless of the function or callback being used. For any given function or callback, 159*5e7646d2SAndroid Build Coastguard Worker * typically only a subset of the possible flags are meaningful, and all others should be zero. 160*5e7646d2SAndroid Build Coastguard Worker * The discussion section for each API call describes which flags are valid for that call 161*5e7646d2SAndroid Build Coastguard Worker * and callback. In some cases, for a particular call, it may be that no flags are currently 162*5e7646d2SAndroid Build Coastguard Worker * defined, in which case the DNSServiceFlags parameter exists purely to allow future expansion. 163*5e7646d2SAndroid Build Coastguard Worker * In all cases, developers should expect that in future releases, it is possible that new flag 164*5e7646d2SAndroid Build Coastguard Worker * values will be defined, and write code with this in mind. For example, code that tests 165*5e7646d2SAndroid Build Coastguard Worker * if (flags == kDNSServiceFlagsAdd) ... 166*5e7646d2SAndroid Build Coastguard Worker * will fail if, in a future release, another bit in the 32-bit flags field is also set. 167*5e7646d2SAndroid Build Coastguard Worker * The reliable way to test whether a particular bit is set is not with an equality test, 168*5e7646d2SAndroid Build Coastguard Worker * but with a bitwise mask: 169*5e7646d2SAndroid Build Coastguard Worker * if (flags & kDNSServiceFlagsAdd) ... 170*5e7646d2SAndroid Build Coastguard Worker */ 171*5e7646d2SAndroid Build Coastguard Worker enum 172*5e7646d2SAndroid Build Coastguard Worker { 173*5e7646d2SAndroid Build Coastguard Worker kDNSServiceFlagsMoreComing = 0x1, 174*5e7646d2SAndroid Build Coastguard Worker /* MoreComing indicates to a callback that at least one more result is 175*5e7646d2SAndroid Build Coastguard Worker * queued and will be delivered following immediately after this one. 176*5e7646d2SAndroid Build Coastguard Worker * When the MoreComing flag is set, applications should not immediately 177*5e7646d2SAndroid Build Coastguard Worker * update their UI, because this can result in a great deal of ugly flickering 178*5e7646d2SAndroid Build Coastguard Worker * on the screen, and can waste a great deal of CPU time repeatedly updating 179*5e7646d2SAndroid Build Coastguard Worker * the screen with content that is then immediately erased, over and over. 180*5e7646d2SAndroid Build Coastguard Worker * Applications should wait until until MoreComing is not set, and then 181*5e7646d2SAndroid Build Coastguard Worker * update their UI when no more changes are imminent. 182*5e7646d2SAndroid Build Coastguard Worker * When MoreComing is not set, that doesn't mean there will be no more 183*5e7646d2SAndroid Build Coastguard Worker * answers EVER, just that there are no more answers immediately 184*5e7646d2SAndroid Build Coastguard Worker * available right now at this instant. If more answers become available 185*5e7646d2SAndroid Build Coastguard Worker * in the future they will be delivered as usual. 186*5e7646d2SAndroid Build Coastguard Worker */ 187*5e7646d2SAndroid Build Coastguard Worker 188*5e7646d2SAndroid Build Coastguard Worker kDNSServiceFlagsAdd = 0x2, 189*5e7646d2SAndroid Build Coastguard Worker kDNSServiceFlagsDefault = 0x4, 190*5e7646d2SAndroid Build Coastguard Worker /* Flags for domain enumeration and browse/query reply callbacks. 191*5e7646d2SAndroid Build Coastguard Worker * "Default" applies only to enumeration and is only valid in 192*5e7646d2SAndroid Build Coastguard Worker * conjunction with "Add". An enumeration callback with the "Add" 193*5e7646d2SAndroid Build Coastguard Worker * flag NOT set indicates a "Remove", i.e. the domain is no longer 194*5e7646d2SAndroid Build Coastguard Worker * valid. 195*5e7646d2SAndroid Build Coastguard Worker */ 196*5e7646d2SAndroid Build Coastguard Worker 197*5e7646d2SAndroid Build Coastguard Worker kDNSServiceFlagsNoAutoRename = 0x8, 198*5e7646d2SAndroid Build Coastguard Worker /* Flag for specifying renaming behavior on name conflict when registering 199*5e7646d2SAndroid Build Coastguard Worker * non-shared records. By default, name conflicts are automatically handled 200*5e7646d2SAndroid Build Coastguard Worker * by renaming the service. NoAutoRename overrides this behavior - with this 201*5e7646d2SAndroid Build Coastguard Worker * flag set, name conflicts will result in a callback. The NoAutorename flag 202*5e7646d2SAndroid Build Coastguard Worker * is only valid if a name is explicitly specified when registering a service 203*5e7646d2SAndroid Build Coastguard Worker * (i.e. the default name is not used.) 204*5e7646d2SAndroid Build Coastguard Worker */ 205*5e7646d2SAndroid Build Coastguard Worker 206*5e7646d2SAndroid Build Coastguard Worker kDNSServiceFlagsShared = 0x10, 207*5e7646d2SAndroid Build Coastguard Worker kDNSServiceFlagsUnique = 0x20, 208*5e7646d2SAndroid Build Coastguard Worker /* Flag for registering individual records on a connected 209*5e7646d2SAndroid Build Coastguard Worker * DNSServiceRef. Shared indicates that there may be multiple records 210*5e7646d2SAndroid Build Coastguard Worker * with this name on the network (e.g. PTR records). Unique indicates that the 211*5e7646d2SAndroid Build Coastguard Worker * record's name is to be unique on the network (e.g. SRV records). 212*5e7646d2SAndroid Build Coastguard Worker */ 213*5e7646d2SAndroid Build Coastguard Worker 214*5e7646d2SAndroid Build Coastguard Worker kDNSServiceFlagsBrowseDomains = 0x40, 215*5e7646d2SAndroid Build Coastguard Worker kDNSServiceFlagsRegistrationDomains = 0x80, 216*5e7646d2SAndroid Build Coastguard Worker /* Flags for specifying domain enumeration type in DNSServiceEnumerateDomains. 217*5e7646d2SAndroid Build Coastguard Worker * BrowseDomains enumerates domains recommended for browsing, RegistrationDomains 218*5e7646d2SAndroid Build Coastguard Worker * enumerates domains recommended for registration. 219*5e7646d2SAndroid Build Coastguard Worker */ 220*5e7646d2SAndroid Build Coastguard Worker 221*5e7646d2SAndroid Build Coastguard Worker kDNSServiceFlagsLongLivedQuery = 0x100, 222*5e7646d2SAndroid Build Coastguard Worker /* Flag for creating a long-lived unicast query for the DNSServiceQueryRecord call. */ 223*5e7646d2SAndroid Build Coastguard Worker 224*5e7646d2SAndroid Build Coastguard Worker kDNSServiceFlagsAllowRemoteQuery = 0x200, 225*5e7646d2SAndroid Build Coastguard Worker /* Flag for creating a record for which we will answer remote queries 226*5e7646d2SAndroid Build Coastguard Worker * (queries from hosts more than one hop away; hosts not directly connected to the local link). 227*5e7646d2SAndroid Build Coastguard Worker */ 228*5e7646d2SAndroid Build Coastguard Worker 229*5e7646d2SAndroid Build Coastguard Worker kDNSServiceFlagsForceMulticast = 0x400, 230*5e7646d2SAndroid Build Coastguard Worker /* Flag for signifying that a query or registration should be performed exclusively via multicast 231*5e7646d2SAndroid Build Coastguard Worker * DNS, even for a name in a domain (e.g. foo.apple.com.) that would normally imply unicast DNS. 232*5e7646d2SAndroid Build Coastguard Worker */ 233*5e7646d2SAndroid Build Coastguard Worker 234*5e7646d2SAndroid Build Coastguard Worker kDNSServiceFlagsForce = 0x800, 235*5e7646d2SAndroid Build Coastguard Worker /* Flag for signifying a "stronger" variant of an operation. 236*5e7646d2SAndroid Build Coastguard Worker * Currently defined only for DNSServiceReconfirmRecord(), where it forces a record to 237*5e7646d2SAndroid Build Coastguard Worker * be removed from the cache immediately, instead of querying for a few seconds before 238*5e7646d2SAndroid Build Coastguard Worker * concluding that the record is no longer valid and then removing it. This flag should 239*5e7646d2SAndroid Build Coastguard Worker * be used with caution because if a service browsing PTR record is indeed still valid 240*5e7646d2SAndroid Build Coastguard Worker * on the network, forcing its removal will result in a user-interface flap -- the 241*5e7646d2SAndroid Build Coastguard Worker * discovered service instance will disappear, and then re-appear moments later. 242*5e7646d2SAndroid Build Coastguard Worker */ 243*5e7646d2SAndroid Build Coastguard Worker 244*5e7646d2SAndroid Build Coastguard Worker kDNSServiceFlagsReturnIntermediates = 0x1000, 245*5e7646d2SAndroid Build Coastguard Worker /* Flag for returning intermediate results. 246*5e7646d2SAndroid Build Coastguard Worker * For example, if a query results in an authoritative NXDomain (name does not exist) 247*5e7646d2SAndroid Build Coastguard Worker * then that result is returned to the client. However the query is not implicitly 248*5e7646d2SAndroid Build Coastguard Worker * cancelled -- it remains active and if the answer subsequently changes 249*5e7646d2SAndroid Build Coastguard Worker * (e.g. because a VPN tunnel is subsequently established) then that positive 250*5e7646d2SAndroid Build Coastguard Worker * result will still be returned to the client. 251*5e7646d2SAndroid Build Coastguard Worker * Similarly, if a query results in a CNAME record, then in addition to following 252*5e7646d2SAndroid Build Coastguard Worker * the CNAME referral, the intermediate CNAME result is also returned to the client. 253*5e7646d2SAndroid Build Coastguard Worker * When this flag is not set, NXDomain errors are not returned, and CNAME records 254*5e7646d2SAndroid Build Coastguard Worker * are followed silently without informing the client of the intermediate steps. 255*5e7646d2SAndroid Build Coastguard Worker * (In earlier builds this flag was briefly calledkDNSServiceFlagsReturnCNAME) 256*5e7646d2SAndroid Build Coastguard Worker */ 257*5e7646d2SAndroid Build Coastguard Worker 258*5e7646d2SAndroid Build Coastguard Worker kDNSServiceFlagsNonBrowsable = 0x2000, 259*5e7646d2SAndroid Build Coastguard Worker /* A service registered with the NonBrowsable flag set can be resolved using 260*5e7646d2SAndroid Build Coastguard Worker * DNSServiceResolve(), but will not be discoverable using DNSServiceBrowse(). 261*5e7646d2SAndroid Build Coastguard Worker * This is for cases where the name is actually a GUID; it is found by other means; 262*5e7646d2SAndroid Build Coastguard Worker * there is no end-user benefit to browsing to find a long list of opaque GUIDs. 263*5e7646d2SAndroid Build Coastguard Worker * Using the NonBrowsable flag creates SRV+TXT without the cost of also advertising 264*5e7646d2SAndroid Build Coastguard Worker * an associated PTR record. 265*5e7646d2SAndroid Build Coastguard Worker */ 266*5e7646d2SAndroid Build Coastguard Worker 267*5e7646d2SAndroid Build Coastguard Worker kDNSServiceFlagsShareConnection = 0x4000, 268*5e7646d2SAndroid Build Coastguard Worker /* For efficiency, clients that perform many concurrent operations may want to use a 269*5e7646d2SAndroid Build Coastguard Worker * single Unix Domain Socket connection with the background daemon, instead of having a 270*5e7646d2SAndroid Build Coastguard Worker * separate connection for each independent operation. To use this mode, clients first 271*5e7646d2SAndroid Build Coastguard Worker * call DNSServiceCreateConnection(&MainRef) to initialize the main DNSServiceRef. 272*5e7646d2SAndroid Build Coastguard Worker * For each subsequent operation that is to share that same connection, the client copies 273*5e7646d2SAndroid Build Coastguard Worker * the MainRef, and then passes the address of that copy, setting the ShareConnection flag 274*5e7646d2SAndroid Build Coastguard Worker * to tell the library that this DNSServiceRef is not a typical uninitialized DNSServiceRef; 275*5e7646d2SAndroid Build Coastguard Worker * it's a copy of an existing DNSServiceRef whose connection information should be reused. 276*5e7646d2SAndroid Build Coastguard Worker * 277*5e7646d2SAndroid Build Coastguard Worker * For example: 278*5e7646d2SAndroid Build Coastguard Worker * 279*5e7646d2SAndroid Build Coastguard Worker * DNSServiceErrorType error; 280*5e7646d2SAndroid Build Coastguard Worker * DNSServiceRef MainRef; 281*5e7646d2SAndroid Build Coastguard Worker * error = DNSServiceCreateConnection(&MainRef); 282*5e7646d2SAndroid Build Coastguard Worker * if (error) ... 283*5e7646d2SAndroid Build Coastguard Worker * DNSServiceRef BrowseRef = MainRef; // Important: COPY the primary DNSServiceRef first... 284*5e7646d2SAndroid Build Coastguard Worker * error = DNSServiceBrowse(&BrowseRef, kDNSServiceFlagsShareConnection, ...); // then use the copy 285*5e7646d2SAndroid Build Coastguard Worker * if (error) ... 286*5e7646d2SAndroid Build Coastguard Worker * ... 287*5e7646d2SAndroid Build Coastguard Worker * DNSServiceRefDeallocate(BrowseRef); // Terminate the browse operation 288*5e7646d2SAndroid Build Coastguard Worker * DNSServiceRefDeallocate(MainRef); // Terminate the shared connection 289*5e7646d2SAndroid Build Coastguard Worker * 290*5e7646d2SAndroid Build Coastguard Worker * Notes: 291*5e7646d2SAndroid Build Coastguard Worker * 292*5e7646d2SAndroid Build Coastguard Worker * 1. Collective kDNSServiceFlagsMoreComing flag 293*5e7646d2SAndroid Build Coastguard Worker * When callbacks are invoked using a shared DNSServiceRef, the 294*5e7646d2SAndroid Build Coastguard Worker * kDNSServiceFlagsMoreComing flag applies collectively to *all* active 295*5e7646d2SAndroid Build Coastguard Worker * operations sharing the same parent DNSServiceRef. If the MoreComing flag is 296*5e7646d2SAndroid Build Coastguard Worker * set it means that there are more results queued on this parent DNSServiceRef, 297*5e7646d2SAndroid Build Coastguard Worker * but not necessarily more results for this particular callback function. 298*5e7646d2SAndroid Build Coastguard Worker * The implication of this for client programmers is that when a callback 299*5e7646d2SAndroid Build Coastguard Worker * is invoked with the MoreComing flag set, the code should update its 300*5e7646d2SAndroid Build Coastguard Worker * internal data structures with the new result, and set a variable indicating 301*5e7646d2SAndroid Build Coastguard Worker * that its UI needs to be updated. Then, later when a callback is eventually 302*5e7646d2SAndroid Build Coastguard Worker * invoked with the MoreComing flag not set, the code should update *all* 303*5e7646d2SAndroid Build Coastguard Worker * stale UI elements related to that shared parent DNSServiceRef that need 304*5e7646d2SAndroid Build Coastguard Worker * updating, not just the UI elements related to the particular callback 305*5e7646d2SAndroid Build Coastguard Worker * that happened to be the last one to be invoked. 306*5e7646d2SAndroid Build Coastguard Worker * 307*5e7646d2SAndroid Build Coastguard Worker * 2. Canceling operations and kDNSServiceFlagsMoreComing 308*5e7646d2SAndroid Build Coastguard Worker * Whenever you cancel any operation for which you had deferred UI updates 309*5e7646d2SAndroid Build Coastguard Worker * waiting because of a kDNSServiceFlagsMoreComing flag, you should perform 310*5e7646d2SAndroid Build Coastguard Worker * those deferred UI updates. This is because, after cancelling the operation, 311*5e7646d2SAndroid Build Coastguard Worker * you can no longer wait for a callback *without* MoreComing set, to tell 312*5e7646d2SAndroid Build Coastguard Worker * you do perform your deferred UI updates (the operation has been canceled, 313*5e7646d2SAndroid Build Coastguard Worker * so there will be no more callbacks). An implication of the collective 314*5e7646d2SAndroid Build Coastguard Worker * kDNSServiceFlagsMoreComing flag for shared connections is that this 315*5e7646d2SAndroid Build Coastguard Worker * guideline applies more broadly -- any time you cancel an operation on 316*5e7646d2SAndroid Build Coastguard Worker * a shared connection, you should perform all deferred UI updates for all 317*5e7646d2SAndroid Build Coastguard Worker * operations sharing that connection. This is because the MoreComing flag 318*5e7646d2SAndroid Build Coastguard Worker * might have been referring to events coming for the operation you canceled, 319*5e7646d2SAndroid Build Coastguard Worker * which will now not be coming because the operation has been canceled. 320*5e7646d2SAndroid Build Coastguard Worker * 321*5e7646d2SAndroid Build Coastguard Worker * 3. Only share DNSServiceRef's created with DNSServiceCreateConnection 322*5e7646d2SAndroid Build Coastguard Worker * Calling DNSServiceCreateConnection(&ref) creates a special shareable DNSServiceRef. 323*5e7646d2SAndroid Build Coastguard Worker * DNSServiceRef's created by other calls like DNSServiceBrowse() or DNSServiceResolve() 324*5e7646d2SAndroid Build Coastguard Worker * cannot be shared by copying them and using kDNSServiceFlagsShareConnection. 325*5e7646d2SAndroid Build Coastguard Worker * 326*5e7646d2SAndroid Build Coastguard Worker * 4. Don't Double-Deallocate 327*5e7646d2SAndroid Build Coastguard Worker * Calling DNSServiceRefDeallocate(ref) for a particular operation's DNSServiceRef terminates 328*5e7646d2SAndroid Build Coastguard Worker * just that operation. Calling DNSServiceRefDeallocate(ref) for the main shared DNSServiceRef 329*5e7646d2SAndroid Build Coastguard Worker * (the parent DNSServiceRef, originally created by DNSServiceCreateConnection(&ref)) 330*5e7646d2SAndroid Build Coastguard Worker * automatically terminates the shared connection and all operations that were still using it. 331*5e7646d2SAndroid Build Coastguard Worker * After doing this, DO NOT then attempt to deallocate any remaining subordinate DNSServiceRef's. 332*5e7646d2SAndroid Build Coastguard Worker * The memory used by those subordinate DNSServiceRef's has already been freed, so any attempt 333*5e7646d2SAndroid Build Coastguard Worker * to do a DNSServiceRefDeallocate (or any other operation) on them will result in accesses 334*5e7646d2SAndroid Build Coastguard Worker * to freed memory, leading to crashes or other equally undesirable results. 335*5e7646d2SAndroid Build Coastguard Worker * 336*5e7646d2SAndroid Build Coastguard Worker * 5. Thread Safety 337*5e7646d2SAndroid Build Coastguard Worker * The dns_sd.h API does not presuppose any particular threading model, and consequently 338*5e7646d2SAndroid Build Coastguard Worker * does no locking of its own (which would require linking some specific threading library). 339*5e7646d2SAndroid Build Coastguard Worker * If client code calls API routines on the same DNSServiceRef concurrently 340*5e7646d2SAndroid Build Coastguard Worker * from multiple threads, it is the client's responsibility to use a mutext 341*5e7646d2SAndroid Build Coastguard Worker * lock or take similar appropriate precautions to serialize those calls. 342*5e7646d2SAndroid Build Coastguard Worker */ 343*5e7646d2SAndroid Build Coastguard Worker 344*5e7646d2SAndroid Build Coastguard Worker kDNSServiceFlagsSuppressUnusable = 0x8000, 345*5e7646d2SAndroid Build Coastguard Worker /* 346*5e7646d2SAndroid Build Coastguard Worker * This flag is meaningful only in DNSServiceQueryRecord which suppresses unusable queries on the 347*5e7646d2SAndroid Build Coastguard Worker * wire. If "hostname" is a wide-area unicast DNS hostname (i.e. not a ".local." name) 348*5e7646d2SAndroid Build Coastguard Worker * but this host has no routable IPv6 address, then the call will not try to look up IPv6 addresses 349*5e7646d2SAndroid Build Coastguard Worker * for "hostname", since any addresses it found would be unlikely to be of any use anyway. Similarly, 350*5e7646d2SAndroid Build Coastguard Worker * if this host has no routable IPv4 address, the call will not try to look up IPv4 addresses for 351*5e7646d2SAndroid Build Coastguard Worker * "hostname". 352*5e7646d2SAndroid Build Coastguard Worker */ 353*5e7646d2SAndroid Build Coastguard Worker 354*5e7646d2SAndroid Build Coastguard Worker kDNSServiceFlagsTimeout = 0x10000, 355*5e7646d2SAndroid Build Coastguard Worker /* 356*5e7646d2SAndroid Build Coastguard Worker * When kDNServiceFlagsTimeout is passed to DNSServiceQueryRecord or DNSServiceGetAddrInfo, the query is 357*5e7646d2SAndroid Build Coastguard Worker * stopped after a certain number of seconds have elapsed. The time at which the query will be stopped 358*5e7646d2SAndroid Build Coastguard Worker * is determined by the system and cannot be configured by the user. The query will be stopped irrespective 359*5e7646d2SAndroid Build Coastguard Worker * of whether a response was given earlier or not. When the query is stopped, the callback will be called 360*5e7646d2SAndroid Build Coastguard Worker * with an error code of kDNSServiceErr_Timeout and a NULL sockaddr will be returned for DNSServiceGetAddrInfo 361*5e7646d2SAndroid Build Coastguard Worker * and zero length rdata will be returned for DNSServiceQueryRecord. 362*5e7646d2SAndroid Build Coastguard Worker */ 363*5e7646d2SAndroid Build Coastguard Worker 364*5e7646d2SAndroid Build Coastguard Worker kDNSServiceFlagsIncludeP2P = 0x20000, 365*5e7646d2SAndroid Build Coastguard Worker /* 366*5e7646d2SAndroid Build Coastguard Worker * Include P2P interfaces when kDNSServiceInterfaceIndexAny is specified. 367*5e7646d2SAndroid Build Coastguard Worker * By default, specifying kDNSServiceInterfaceIndexAny does not include P2P interfaces. 368*5e7646d2SAndroid Build Coastguard Worker */ 369*5e7646d2SAndroid Build Coastguard Worker kDNSServiceFlagsWakeOnResolve = 0x40000 370*5e7646d2SAndroid Build Coastguard Worker /* 371*5e7646d2SAndroid Build Coastguard Worker * This flag is meaningful only in DNSServiceResolve. When set, it tries to send a magic packet 372*5e7646d2SAndroid Build Coastguard Worker * to wake up the client. 373*5e7646d2SAndroid Build Coastguard Worker */ 374*5e7646d2SAndroid Build Coastguard Worker }; 375*5e7646d2SAndroid Build Coastguard Worker 376*5e7646d2SAndroid Build Coastguard Worker /* Possible protocols for DNSServiceNATPortMappingCreate(). */ 377*5e7646d2SAndroid Build Coastguard Worker enum 378*5e7646d2SAndroid Build Coastguard Worker { 379*5e7646d2SAndroid Build Coastguard Worker kDNSServiceProtocol_IPv4 = 0x01, 380*5e7646d2SAndroid Build Coastguard Worker kDNSServiceProtocol_IPv6 = 0x02, 381*5e7646d2SAndroid Build Coastguard Worker /* 0x04 and 0x08 reserved for future internetwork protocols */ 382*5e7646d2SAndroid Build Coastguard Worker 383*5e7646d2SAndroid Build Coastguard Worker kDNSServiceProtocol_UDP = 0x10, 384*5e7646d2SAndroid Build Coastguard Worker kDNSServiceProtocol_TCP = 0x20 385*5e7646d2SAndroid Build Coastguard Worker /* 0x40 and 0x80 reserved for future transport protocols, e.g. SCTP [RFC 2960] 386*5e7646d2SAndroid Build Coastguard Worker * or DCCP [RFC 4340]. If future NAT gateways are created that support port 387*5e7646d2SAndroid Build Coastguard Worker * mappings for these protocols, new constants will be defined here. 388*5e7646d2SAndroid Build Coastguard Worker */ 389*5e7646d2SAndroid Build Coastguard Worker }; 390*5e7646d2SAndroid Build Coastguard Worker 391*5e7646d2SAndroid Build Coastguard Worker /* 392*5e7646d2SAndroid Build Coastguard Worker * The values for DNS Classes and Types are listed in RFC 1035, and are available 393*5e7646d2SAndroid Build Coastguard Worker * on every OS in its DNS header file. Unfortunately every OS does not have the 394*5e7646d2SAndroid Build Coastguard Worker * same header file containing DNS Class and Type constants, and the names of 395*5e7646d2SAndroid Build Coastguard Worker * the constants are not consistent. For example, BIND 8 uses "T_A", 396*5e7646d2SAndroid Build Coastguard Worker * BIND 9 uses "ns_t_a", Windows uses "DNS_TYPE_A", etc. 397*5e7646d2SAndroid Build Coastguard Worker * For this reason, these constants are also listed here, so that code using 398*5e7646d2SAndroid Build Coastguard Worker * the DNS-SD programming APIs can use these constants, so that the same code 399*5e7646d2SAndroid Build Coastguard Worker * can compile on all our supported platforms. 400*5e7646d2SAndroid Build Coastguard Worker */ 401*5e7646d2SAndroid Build Coastguard Worker 402*5e7646d2SAndroid Build Coastguard Worker enum 403*5e7646d2SAndroid Build Coastguard Worker { 404*5e7646d2SAndroid Build Coastguard Worker kDNSServiceClass_IN = 1 /* Internet */ 405*5e7646d2SAndroid Build Coastguard Worker }; 406*5e7646d2SAndroid Build Coastguard Worker 407*5e7646d2SAndroid Build Coastguard Worker enum 408*5e7646d2SAndroid Build Coastguard Worker { 409*5e7646d2SAndroid Build Coastguard Worker kDNSServiceType_A = 1, /* Host address. */ 410*5e7646d2SAndroid Build Coastguard Worker kDNSServiceType_NS = 2, /* Authoritative server. */ 411*5e7646d2SAndroid Build Coastguard Worker kDNSServiceType_MD = 3, /* Mail destination. */ 412*5e7646d2SAndroid Build Coastguard Worker kDNSServiceType_MF = 4, /* Mail forwarder. */ 413*5e7646d2SAndroid Build Coastguard Worker kDNSServiceType_CNAME = 5, /* Canonical name. */ 414*5e7646d2SAndroid Build Coastguard Worker kDNSServiceType_SOA = 6, /* Start of authority zone. */ 415*5e7646d2SAndroid Build Coastguard Worker kDNSServiceType_MB = 7, /* Mailbox domain name. */ 416*5e7646d2SAndroid Build Coastguard Worker kDNSServiceType_MG = 8, /* Mail group member. */ 417*5e7646d2SAndroid Build Coastguard Worker kDNSServiceType_MR = 9, /* Mail rename name. */ 418*5e7646d2SAndroid Build Coastguard Worker kDNSServiceType_NULL = 10, /* Null resource record. */ 419*5e7646d2SAndroid Build Coastguard Worker kDNSServiceType_WKS = 11, /* Well known service. */ 420*5e7646d2SAndroid Build Coastguard Worker kDNSServiceType_PTR = 12, /* Domain name pointer. */ 421*5e7646d2SAndroid Build Coastguard Worker kDNSServiceType_HINFO = 13, /* Host information. */ 422*5e7646d2SAndroid Build Coastguard Worker kDNSServiceType_MINFO = 14, /* Mailbox information. */ 423*5e7646d2SAndroid Build Coastguard Worker kDNSServiceType_MX = 15, /* Mail routing information. */ 424*5e7646d2SAndroid Build Coastguard Worker kDNSServiceType_TXT = 16, /* One or more text strings (NOT "zero or more..."). */ 425*5e7646d2SAndroid Build Coastguard Worker kDNSServiceType_RP = 17, /* Responsible person. */ 426*5e7646d2SAndroid Build Coastguard Worker kDNSServiceType_AFSDB = 18, /* AFS cell database. */ 427*5e7646d2SAndroid Build Coastguard Worker kDNSServiceType_X25 = 19, /* X_25 calling address. */ 428*5e7646d2SAndroid Build Coastguard Worker kDNSServiceType_ISDN = 20, /* ISDN calling address. */ 429*5e7646d2SAndroid Build Coastguard Worker kDNSServiceType_RT = 21, /* Router. */ 430*5e7646d2SAndroid Build Coastguard Worker kDNSServiceType_NSAP = 22, /* NSAP address. */ 431*5e7646d2SAndroid Build Coastguard Worker kDNSServiceType_NSAP_PTR = 23, /* Reverse NSAP lookup (deprecated). */ 432*5e7646d2SAndroid Build Coastguard Worker kDNSServiceType_SIG = 24, /* Security signature. */ 433*5e7646d2SAndroid Build Coastguard Worker kDNSServiceType_KEY = 25, /* Security key. */ 434*5e7646d2SAndroid Build Coastguard Worker kDNSServiceType_PX = 26, /* X.400 mail mapping. */ 435*5e7646d2SAndroid Build Coastguard Worker kDNSServiceType_GPOS = 27, /* Geographical position (withdrawn). */ 436*5e7646d2SAndroid Build Coastguard Worker kDNSServiceType_AAAA = 28, /* IPv6 Address. */ 437*5e7646d2SAndroid Build Coastguard Worker kDNSServiceType_LOC = 29, /* Location Information. */ 438*5e7646d2SAndroid Build Coastguard Worker kDNSServiceType_NXT = 30, /* Next domain (security). */ 439*5e7646d2SAndroid Build Coastguard Worker kDNSServiceType_EID = 31, /* Endpoint identifier. */ 440*5e7646d2SAndroid Build Coastguard Worker kDNSServiceType_NIMLOC = 32, /* Nimrod Locator. */ 441*5e7646d2SAndroid Build Coastguard Worker kDNSServiceType_SRV = 33, /* Server Selection. */ 442*5e7646d2SAndroid Build Coastguard Worker kDNSServiceType_ATMA = 34, /* ATM Address */ 443*5e7646d2SAndroid Build Coastguard Worker kDNSServiceType_NAPTR = 35, /* Naming Authority PoinTeR */ 444*5e7646d2SAndroid Build Coastguard Worker kDNSServiceType_KX = 36, /* Key Exchange */ 445*5e7646d2SAndroid Build Coastguard Worker kDNSServiceType_CERT = 37, /* Certification record */ 446*5e7646d2SAndroid Build Coastguard Worker kDNSServiceType_A6 = 38, /* IPv6 Address (deprecated) */ 447*5e7646d2SAndroid Build Coastguard Worker kDNSServiceType_DNAME = 39, /* Non-terminal DNAME (for IPv6) */ 448*5e7646d2SAndroid Build Coastguard Worker kDNSServiceType_SINK = 40, /* Kitchen sink (experimental) */ 449*5e7646d2SAndroid Build Coastguard Worker kDNSServiceType_OPT = 41, /* EDNS0 option (meta-RR) */ 450*5e7646d2SAndroid Build Coastguard Worker kDNSServiceType_APL = 42, /* Address Prefix List */ 451*5e7646d2SAndroid Build Coastguard Worker kDNSServiceType_DS = 43, /* Delegation Signer */ 452*5e7646d2SAndroid Build Coastguard Worker kDNSServiceType_SSHFP = 44, /* SSH Key Fingerprint */ 453*5e7646d2SAndroid Build Coastguard Worker kDNSServiceType_IPSECKEY = 45, /* IPSECKEY */ 454*5e7646d2SAndroid Build Coastguard Worker kDNSServiceType_RRSIG = 46, /* RRSIG */ 455*5e7646d2SAndroid Build Coastguard Worker kDNSServiceType_NSEC = 47, /* Denial of Existence */ 456*5e7646d2SAndroid Build Coastguard Worker kDNSServiceType_DNSKEY = 48, /* DNSKEY */ 457*5e7646d2SAndroid Build Coastguard Worker kDNSServiceType_DHCID = 49, /* DHCP Client Identifier */ 458*5e7646d2SAndroid Build Coastguard Worker kDNSServiceType_NSEC3 = 50, /* Hashed Authenticated Denial of Existence */ 459*5e7646d2SAndroid Build Coastguard Worker kDNSServiceType_NSEC3PARAM = 51, /* Hashed Authenticated Denial of Existence */ 460*5e7646d2SAndroid Build Coastguard Worker 461*5e7646d2SAndroid Build Coastguard Worker kDNSServiceType_HIP = 55, /* Host Identity Protocol */ 462*5e7646d2SAndroid Build Coastguard Worker 463*5e7646d2SAndroid Build Coastguard Worker kDNSServiceType_SPF = 99, /* Sender Policy Framework for E-Mail */ 464*5e7646d2SAndroid Build Coastguard Worker kDNSServiceType_UINFO = 100, /* IANA-Reserved */ 465*5e7646d2SAndroid Build Coastguard Worker kDNSServiceType_UID = 101, /* IANA-Reserved */ 466*5e7646d2SAndroid Build Coastguard Worker kDNSServiceType_GID = 102, /* IANA-Reserved */ 467*5e7646d2SAndroid Build Coastguard Worker kDNSServiceType_UNSPEC = 103, /* IANA-Reserved */ 468*5e7646d2SAndroid Build Coastguard Worker 469*5e7646d2SAndroid Build Coastguard Worker kDNSServiceType_TKEY = 249, /* Transaction key */ 470*5e7646d2SAndroid Build Coastguard Worker kDNSServiceType_TSIG = 250, /* Transaction signature. */ 471*5e7646d2SAndroid Build Coastguard Worker kDNSServiceType_IXFR = 251, /* Incremental zone transfer. */ 472*5e7646d2SAndroid Build Coastguard Worker kDNSServiceType_AXFR = 252, /* Transfer zone of authority. */ 473*5e7646d2SAndroid Build Coastguard Worker kDNSServiceType_MAILB = 253, /* Transfer mailbox records. */ 474*5e7646d2SAndroid Build Coastguard Worker kDNSServiceType_MAILA = 254, /* Transfer mail agent records. */ 475*5e7646d2SAndroid Build Coastguard Worker kDNSServiceType_ANY = 255 /* Wildcard match. */ 476*5e7646d2SAndroid Build Coastguard Worker }; 477*5e7646d2SAndroid Build Coastguard Worker 478*5e7646d2SAndroid Build Coastguard Worker /* possible error code values */ 479*5e7646d2SAndroid Build Coastguard Worker enum 480*5e7646d2SAndroid Build Coastguard Worker { 481*5e7646d2SAndroid Build Coastguard Worker kDNSServiceErr_NoError = 0, 482*5e7646d2SAndroid Build Coastguard Worker kDNSServiceErr_Unknown = -65537, /* 0xFFFE FFFF */ 483*5e7646d2SAndroid Build Coastguard Worker kDNSServiceErr_NoSuchName = -65538, 484*5e7646d2SAndroid Build Coastguard Worker kDNSServiceErr_NoMemory = -65539, 485*5e7646d2SAndroid Build Coastguard Worker kDNSServiceErr_BadParam = -65540, 486*5e7646d2SAndroid Build Coastguard Worker kDNSServiceErr_BadReference = -65541, 487*5e7646d2SAndroid Build Coastguard Worker kDNSServiceErr_BadState = -65542, 488*5e7646d2SAndroid Build Coastguard Worker kDNSServiceErr_BadFlags = -65543, 489*5e7646d2SAndroid Build Coastguard Worker kDNSServiceErr_Unsupported = -65544, 490*5e7646d2SAndroid Build Coastguard Worker kDNSServiceErr_NotInitialized = -65545, 491*5e7646d2SAndroid Build Coastguard Worker kDNSServiceErr_AlreadyRegistered = -65547, 492*5e7646d2SAndroid Build Coastguard Worker kDNSServiceErr_NameConflict = -65548, 493*5e7646d2SAndroid Build Coastguard Worker kDNSServiceErr_Invalid = -65549, 494*5e7646d2SAndroid Build Coastguard Worker kDNSServiceErr_Firewall = -65550, 495*5e7646d2SAndroid Build Coastguard Worker kDNSServiceErr_Incompatible = -65551, /* client library incompatible with daemon */ 496*5e7646d2SAndroid Build Coastguard Worker kDNSServiceErr_BadInterfaceIndex = -65552, 497*5e7646d2SAndroid Build Coastguard Worker kDNSServiceErr_Refused = -65553, 498*5e7646d2SAndroid Build Coastguard Worker kDNSServiceErr_NoSuchRecord = -65554, 499*5e7646d2SAndroid Build Coastguard Worker kDNSServiceErr_NoAuth = -65555, 500*5e7646d2SAndroid Build Coastguard Worker kDNSServiceErr_NoSuchKey = -65556, 501*5e7646d2SAndroid Build Coastguard Worker kDNSServiceErr_NATTraversal = -65557, 502*5e7646d2SAndroid Build Coastguard Worker kDNSServiceErr_DoubleNAT = -65558, 503*5e7646d2SAndroid Build Coastguard Worker kDNSServiceErr_BadTime = -65559, /* Codes up to here existed in Tiger */ 504*5e7646d2SAndroid Build Coastguard Worker kDNSServiceErr_BadSig = -65560, 505*5e7646d2SAndroid Build Coastguard Worker kDNSServiceErr_BadKey = -65561, 506*5e7646d2SAndroid Build Coastguard Worker kDNSServiceErr_Transient = -65562, 507*5e7646d2SAndroid Build Coastguard Worker kDNSServiceErr_ServiceNotRunning = -65563, /* Background daemon not running */ 508*5e7646d2SAndroid Build Coastguard Worker kDNSServiceErr_NATPortMappingUnsupported = -65564, /* NAT doesn't support NAT-PMP or UPnP */ 509*5e7646d2SAndroid Build Coastguard Worker kDNSServiceErr_NATPortMappingDisabled = -65565, /* NAT supports NAT-PMP or UPnP but it's disabled by the administrator */ 510*5e7646d2SAndroid Build Coastguard Worker kDNSServiceErr_NoRouter = -65566, /* No router currently configured (probably no network connectivity) */ 511*5e7646d2SAndroid Build Coastguard Worker kDNSServiceErr_PollingMode = -65567, 512*5e7646d2SAndroid Build Coastguard Worker kDNSServiceErr_Timeout = -65568 513*5e7646d2SAndroid Build Coastguard Worker 514*5e7646d2SAndroid Build Coastguard Worker /* mDNS Error codes are in the range 515*5e7646d2SAndroid Build Coastguard Worker * FFFE FF00 (-65792) to FFFE FFFF (-65537) */ 516*5e7646d2SAndroid Build Coastguard Worker }; 517*5e7646d2SAndroid Build Coastguard Worker 518*5e7646d2SAndroid Build Coastguard Worker /* Maximum length, in bytes, of a service name represented as a */ 519*5e7646d2SAndroid Build Coastguard Worker /* literal C-String, including the terminating NULL at the end. */ 520*5e7646d2SAndroid Build Coastguard Worker 521*5e7646d2SAndroid Build Coastguard Worker #define kDNSServiceMaxServiceName 64 522*5e7646d2SAndroid Build Coastguard Worker 523*5e7646d2SAndroid Build Coastguard Worker /* Maximum length, in bytes, of a domain name represented as an *escaped* C-String */ 524*5e7646d2SAndroid Build Coastguard Worker /* including the final trailing dot, and the C-String terminating NULL at the end. */ 525*5e7646d2SAndroid Build Coastguard Worker 526*5e7646d2SAndroid Build Coastguard Worker #define kDNSServiceMaxDomainName 1009 527*5e7646d2SAndroid Build Coastguard Worker 528*5e7646d2SAndroid Build Coastguard Worker /* 529*5e7646d2SAndroid Build Coastguard Worker * Notes on DNS Name Escaping 530*5e7646d2SAndroid Build Coastguard Worker * -- or -- 531*5e7646d2SAndroid Build Coastguard Worker * "Why is kDNSServiceMaxDomainName 1009, when the maximum legal domain name is 256 bytes?" 532*5e7646d2SAndroid Build Coastguard Worker * 533*5e7646d2SAndroid Build Coastguard Worker * All strings used in the DNS-SD APIs are UTF-8 strings. Apart from the exceptions noted below, 534*5e7646d2SAndroid Build Coastguard Worker * the APIs expect the strings to be properly escaped, using the conventional DNS escaping rules: 535*5e7646d2SAndroid Build Coastguard Worker * 536*5e7646d2SAndroid Build Coastguard Worker * '\\' represents a single literal '\' in the name 537*5e7646d2SAndroid Build Coastguard Worker * '\.' represents a single literal '.' in the name 538*5e7646d2SAndroid Build Coastguard Worker * '\ddd', where ddd is a three-digit decimal value from 000 to 255, 539*5e7646d2SAndroid Build Coastguard Worker * represents a single literal byte with that value. 540*5e7646d2SAndroid Build Coastguard Worker * A bare unescaped '.' is a label separator, marking a boundary between domain and subdomain. 541*5e7646d2SAndroid Build Coastguard Worker * 542*5e7646d2SAndroid Build Coastguard Worker * The exceptions, that do not use escaping, are the routines where the full 543*5e7646d2SAndroid Build Coastguard Worker * DNS name of a resource is broken, for convenience, into servicename/regtype/domain. 544*5e7646d2SAndroid Build Coastguard Worker * In these routines, the "servicename" is NOT escaped. It does not need to be, since 545*5e7646d2SAndroid Build Coastguard Worker * it is, by definition, just a single literal string. Any characters in that string 546*5e7646d2SAndroid Build Coastguard Worker * represent exactly what they are. The "regtype" portion is, technically speaking, 547*5e7646d2SAndroid Build Coastguard Worker * escaped, but since legal regtypes are only allowed to contain letters, digits, 548*5e7646d2SAndroid Build Coastguard Worker * and hyphens, there is nothing to escape, so the issue is moot. The "domain" 549*5e7646d2SAndroid Build Coastguard Worker * portion is also escaped, though most domains in use on the public Internet 550*5e7646d2SAndroid Build Coastguard Worker * today, like regtypes, don't contain any characters that need to be escaped. 551*5e7646d2SAndroid Build Coastguard Worker * As DNS-SD becomes more popular, rich-text domains for service discovery will 552*5e7646d2SAndroid Build Coastguard Worker * become common, so software should be written to cope with domains with escaping. 553*5e7646d2SAndroid Build Coastguard Worker * 554*5e7646d2SAndroid Build Coastguard Worker * The servicename may be up to 63 bytes of UTF-8 text (not counting the C-String 555*5e7646d2SAndroid Build Coastguard Worker * terminating NULL at the end). The regtype is of the form _service._tcp or 556*5e7646d2SAndroid Build Coastguard Worker * _service._udp, where the "service" part is 1-15 characters, which may be 557*5e7646d2SAndroid Build Coastguard Worker * letters, digits, or hyphens. The domain part of the three-part name may be 558*5e7646d2SAndroid Build Coastguard Worker * any legal domain, providing that the resulting servicename+regtype+domain 559*5e7646d2SAndroid Build Coastguard Worker * name does not exceed 256 bytes. 560*5e7646d2SAndroid Build Coastguard Worker * 561*5e7646d2SAndroid Build Coastguard Worker * For most software, these issues are transparent. When browsing, the discovered 562*5e7646d2SAndroid Build Coastguard Worker * servicenames should simply be displayed as-is. When resolving, the discovered 563*5e7646d2SAndroid Build Coastguard Worker * servicename/regtype/domain are simply passed unchanged to DNSServiceResolve(). 564*5e7646d2SAndroid Build Coastguard Worker * When a DNSServiceResolve() succeeds, the returned fullname is already in 565*5e7646d2SAndroid Build Coastguard Worker * the correct format to pass to standard system DNS APIs such as res_query(). 566*5e7646d2SAndroid Build Coastguard Worker * For converting from servicename/regtype/domain to a single properly-escaped 567*5e7646d2SAndroid Build Coastguard Worker * full DNS name, the helper function DNSServiceConstructFullName() is provided. 568*5e7646d2SAndroid Build Coastguard Worker * 569*5e7646d2SAndroid Build Coastguard Worker * The following (highly contrived) example illustrates the escaping process. 570*5e7646d2SAndroid Build Coastguard Worker * Suppose you have an service called "Dr. Smith\Dr. Johnson", of type "_ftp._tcp" 571*5e7646d2SAndroid Build Coastguard Worker * in subdomain "4th. Floor" of subdomain "Building 2" of domain "apple.com." 572*5e7646d2SAndroid Build Coastguard Worker * The full (escaped) DNS name of this service's SRV record would be: 573*5e7646d2SAndroid Build Coastguard Worker * Dr\.\032Smith\\Dr\.\032Johnson._ftp._tcp.4th\.\032Floor.Building\0322.apple.com. 574*5e7646d2SAndroid Build Coastguard Worker */ 575*5e7646d2SAndroid Build Coastguard Worker 576*5e7646d2SAndroid Build Coastguard Worker 577*5e7646d2SAndroid Build Coastguard Worker /* 578*5e7646d2SAndroid Build Coastguard Worker * Constants for specifying an interface index 579*5e7646d2SAndroid Build Coastguard Worker * 580*5e7646d2SAndroid Build Coastguard Worker * Specific interface indexes are identified via a 32-bit unsigned integer returned 581*5e7646d2SAndroid Build Coastguard Worker * by the if_nametoindex() family of calls. 582*5e7646d2SAndroid Build Coastguard Worker * 583*5e7646d2SAndroid Build Coastguard Worker * If the client passes 0 for interface index, that means "do the right thing", 584*5e7646d2SAndroid Build Coastguard Worker * which (at present) means, "if the name is in an mDNS local multicast domain 585*5e7646d2SAndroid Build Coastguard Worker * (e.g. 'local.', '254.169.in-addr.arpa.', '{8,9,A,B}.E.F.ip6.arpa.') then multicast 586*5e7646d2SAndroid Build Coastguard Worker * on all applicable interfaces, otherwise send via unicast to the appropriate 587*5e7646d2SAndroid Build Coastguard Worker * DNS server." Normally, most clients will use 0 for interface index to 588*5e7646d2SAndroid Build Coastguard Worker * automatically get the default sensible behaviour. 589*5e7646d2SAndroid Build Coastguard Worker * 590*5e7646d2SAndroid Build Coastguard Worker * If the client passes a positive interface index, then for multicast names that 591*5e7646d2SAndroid Build Coastguard Worker * indicates to do the operation only on that one interface. For unicast names the 592*5e7646d2SAndroid Build Coastguard Worker * interface index is ignored unless kDNSServiceFlagsForceMulticast is also set. 593*5e7646d2SAndroid Build Coastguard Worker * 594*5e7646d2SAndroid Build Coastguard Worker * If the client passes kDNSServiceInterfaceIndexLocalOnly when registering 595*5e7646d2SAndroid Build Coastguard Worker * a service, then that service will be found *only* by other local clients 596*5e7646d2SAndroid Build Coastguard Worker * on the same machine that are browsing using kDNSServiceInterfaceIndexLocalOnly 597*5e7646d2SAndroid Build Coastguard Worker * or kDNSServiceInterfaceIndexAny. 598*5e7646d2SAndroid Build Coastguard Worker * If a client has a 'private' service, accessible only to other processes 599*5e7646d2SAndroid Build Coastguard Worker * running on the same machine, this allows the client to advertise that service 600*5e7646d2SAndroid Build Coastguard Worker * in a way such that it does not inadvertently appear in service lists on 601*5e7646d2SAndroid Build Coastguard Worker * all the other machines on the network. 602*5e7646d2SAndroid Build Coastguard Worker * 603*5e7646d2SAndroid Build Coastguard Worker * If the client passes kDNSServiceInterfaceIndexLocalOnly when browsing 604*5e7646d2SAndroid Build Coastguard Worker * then it will find *all* records registered on that same local machine. 605*5e7646d2SAndroid Build Coastguard Worker * Clients explicitly wishing to discover *only* LocalOnly services can 606*5e7646d2SAndroid Build Coastguard Worker * accomplish this by inspecting the interfaceIndex of each service reported 607*5e7646d2SAndroid Build Coastguard Worker * to their DNSServiceBrowseReply() callback function, and discarding those 608*5e7646d2SAndroid Build Coastguard Worker * where the interface index is not kDNSServiceInterfaceIndexLocalOnly. 609*5e7646d2SAndroid Build Coastguard Worker * 610*5e7646d2SAndroid Build Coastguard Worker * kDNSServiceInterfaceIndexP2P is meaningful only in Browse, QueryRecord, 611*5e7646d2SAndroid Build Coastguard Worker * and Resolve operations. It should not be used in other DNSService APIs. 612*5e7646d2SAndroid Build Coastguard Worker * 613*5e7646d2SAndroid Build Coastguard Worker * - If kDNSServiceInterfaceIndexP2P is passed to DNSServiceBrowse or 614*5e7646d2SAndroid Build Coastguard Worker * DNSServiceQueryRecord, it restricts the operation to P2P. 615*5e7646d2SAndroid Build Coastguard Worker * 616*5e7646d2SAndroid Build Coastguard Worker * - If kDNSServiceInterfaceIndexP2P is passed to DNSServiceResolve, it is 617*5e7646d2SAndroid Build Coastguard Worker * mapped internally to kDNSServiceInterfaceIndexAny, because resolving 618*5e7646d2SAndroid Build Coastguard Worker * a P2P service may create and/or enable an interface whose index is not 619*5e7646d2SAndroid Build Coastguard Worker * known a priori. The resolve callback will indicate the index of the 620*5e7646d2SAndroid Build Coastguard Worker * interface via which the service can be accessed. 621*5e7646d2SAndroid Build Coastguard Worker * 622*5e7646d2SAndroid Build Coastguard Worker * If applications pass kDNSServiceInterfaceIndexAny to DNSServiceBrowse 623*5e7646d2SAndroid Build Coastguard Worker * or DNSServiceQueryRecord, they must set the kDNSServiceFlagsIncludeP2P flag 624*5e7646d2SAndroid Build Coastguard Worker * to include P2P. In this case, if a service instance or the record being queried 625*5e7646d2SAndroid Build Coastguard Worker * is found over P2P, the resulting ADD event will indicate kDNSServiceInterfaceIndexP2P 626*5e7646d2SAndroid Build Coastguard Worker * as the interface index. 627*5e7646d2SAndroid Build Coastguard Worker */ 628*5e7646d2SAndroid Build Coastguard Worker 629*5e7646d2SAndroid Build Coastguard Worker #define kDNSServiceInterfaceIndexAny 0 630*5e7646d2SAndroid Build Coastguard Worker #define kDNSServiceInterfaceIndexLocalOnly ((uint32_t)-1) 631*5e7646d2SAndroid Build Coastguard Worker #define kDNSServiceInterfaceIndexUnicast ((uint32_t)-2) 632*5e7646d2SAndroid Build Coastguard Worker #define kDNSServiceInterfaceIndexP2P ((uint32_t)-3) 633*5e7646d2SAndroid Build Coastguard Worker 634*5e7646d2SAndroid Build Coastguard Worker typedef uint32_t DNSServiceFlags; 635*5e7646d2SAndroid Build Coastguard Worker typedef uint32_t DNSServiceProtocol; 636*5e7646d2SAndroid Build Coastguard Worker typedef int32_t DNSServiceErrorType; 637*5e7646d2SAndroid Build Coastguard Worker 638*5e7646d2SAndroid Build Coastguard Worker 639*5e7646d2SAndroid Build Coastguard Worker /********************************************************************************************* 640*5e7646d2SAndroid Build Coastguard Worker * 641*5e7646d2SAndroid Build Coastguard Worker * Version checking 642*5e7646d2SAndroid Build Coastguard Worker * 643*5e7646d2SAndroid Build Coastguard Worker *********************************************************************************************/ 644*5e7646d2SAndroid Build Coastguard Worker 645*5e7646d2SAndroid Build Coastguard Worker /* DNSServiceGetProperty() Parameters: 646*5e7646d2SAndroid Build Coastguard Worker * 647*5e7646d2SAndroid Build Coastguard Worker * property: The requested property. 648*5e7646d2SAndroid Build Coastguard Worker * Currently the only property defined is kDNSServiceProperty_DaemonVersion. 649*5e7646d2SAndroid Build Coastguard Worker * 650*5e7646d2SAndroid Build Coastguard Worker * result: Place to store result. 651*5e7646d2SAndroid Build Coastguard Worker * For retrieving DaemonVersion, this should be the address of a uint32_t. 652*5e7646d2SAndroid Build Coastguard Worker * 653*5e7646d2SAndroid Build Coastguard Worker * size: Pointer to uint32_t containing size of the result location. 654*5e7646d2SAndroid Build Coastguard Worker * For retrieving DaemonVersion, this should be sizeof(uint32_t). 655*5e7646d2SAndroid Build Coastguard Worker * On return the uint32_t is updated to the size of the data returned. 656*5e7646d2SAndroid Build Coastguard Worker * For DaemonVersion, the returned size is always sizeof(uint32_t), but 657*5e7646d2SAndroid Build Coastguard Worker * future properties could be defined which return variable-sized results. 658*5e7646d2SAndroid Build Coastguard Worker * 659*5e7646d2SAndroid Build Coastguard Worker * return value: Returns kDNSServiceErr_NoError on success, or kDNSServiceErr_ServiceNotRunning 660*5e7646d2SAndroid Build Coastguard Worker * if the daemon (or "system service" on Windows) is not running. 661*5e7646d2SAndroid Build Coastguard Worker */ 662*5e7646d2SAndroid Build Coastguard Worker 663*5e7646d2SAndroid Build Coastguard Worker DNSServiceErrorType DNSSD_API DNSServiceGetProperty 664*5e7646d2SAndroid Build Coastguard Worker ( 665*5e7646d2SAndroid Build Coastguard Worker const char *property, /* Requested property (i.e. kDNSServiceProperty_DaemonVersion) */ 666*5e7646d2SAndroid Build Coastguard Worker void *result, /* Pointer to place to store result */ 667*5e7646d2SAndroid Build Coastguard Worker uint32_t *size /* size of result location */ 668*5e7646d2SAndroid Build Coastguard Worker ); 669*5e7646d2SAndroid Build Coastguard Worker 670*5e7646d2SAndroid Build Coastguard Worker /* 671*5e7646d2SAndroid Build Coastguard Worker * When requesting kDNSServiceProperty_DaemonVersion, the result pointer must point 672*5e7646d2SAndroid Build Coastguard Worker * to a 32-bit unsigned integer, and the size parameter must be set to sizeof(uint32_t). 673*5e7646d2SAndroid Build Coastguard Worker * 674*5e7646d2SAndroid Build Coastguard Worker * On return, the 32-bit unsigned integer contains the version number, formatted as follows: 675*5e7646d2SAndroid Build Coastguard Worker * Major part of the build number * 10000 + 676*5e7646d2SAndroid Build Coastguard Worker * minor part of the build number * 100 677*5e7646d2SAndroid Build Coastguard Worker * 678*5e7646d2SAndroid Build Coastguard Worker * For example, Mac OS X 10.4.9 has mDNSResponder-108.4, which would be represented as 679*5e7646d2SAndroid Build Coastguard Worker * version 1080400. This allows applications to do simple greater-than and less-than comparisons: 680*5e7646d2SAndroid Build Coastguard Worker * e.g. an application that requires at least mDNSResponder-108.4 can check: 681*5e7646d2SAndroid Build Coastguard Worker * 682*5e7646d2SAndroid Build Coastguard Worker * if (version >= 1080400) ... 683*5e7646d2SAndroid Build Coastguard Worker * 684*5e7646d2SAndroid Build Coastguard Worker * Example usage: 685*5e7646d2SAndroid Build Coastguard Worker * 686*5e7646d2SAndroid Build Coastguard Worker * uint32_t version; 687*5e7646d2SAndroid Build Coastguard Worker * uint32_t size = sizeof(version); 688*5e7646d2SAndroid Build Coastguard Worker * DNSServiceErrorType err = DNSServiceGetProperty(kDNSServiceProperty_DaemonVersion, &version, &size); 689*5e7646d2SAndroid Build Coastguard Worker * if (!err) printf("Bonjour version is %d.%d\n", version / 10000, version / 100 % 100); 690*5e7646d2SAndroid Build Coastguard Worker */ 691*5e7646d2SAndroid Build Coastguard Worker 692*5e7646d2SAndroid Build Coastguard Worker #define kDNSServiceProperty_DaemonVersion "DaemonVersion" 693*5e7646d2SAndroid Build Coastguard Worker 694*5e7646d2SAndroid Build Coastguard Worker 695*5e7646d2SAndroid Build Coastguard Worker /********************************************************************************************* 696*5e7646d2SAndroid Build Coastguard Worker * 697*5e7646d2SAndroid Build Coastguard Worker * Unix Domain Socket access, DNSServiceRef deallocation, and data processing functions 698*5e7646d2SAndroid Build Coastguard Worker * 699*5e7646d2SAndroid Build Coastguard Worker *********************************************************************************************/ 700*5e7646d2SAndroid Build Coastguard Worker 701*5e7646d2SAndroid Build Coastguard Worker /* DNSServiceRefSockFD() 702*5e7646d2SAndroid Build Coastguard Worker * 703*5e7646d2SAndroid Build Coastguard Worker * Access underlying Unix domain socket for an initialized DNSServiceRef. 704*5e7646d2SAndroid Build Coastguard Worker * The DNS Service Discovery implementation uses this socket to communicate between the client and 705*5e7646d2SAndroid Build Coastguard Worker * the mDNSResponder daemon. The application MUST NOT directly read from or write to this socket. 706*5e7646d2SAndroid Build Coastguard Worker * Access to the socket is provided so that it can be used as a kqueue event source, a CFRunLoop 707*5e7646d2SAndroid Build Coastguard Worker * event source, in a select() loop, etc. When the underlying event management subsystem (kqueue/ 708*5e7646d2SAndroid Build Coastguard Worker * select/CFRunLoop etc.) indicates to the client that data is available for reading on the 709*5e7646d2SAndroid Build Coastguard Worker * socket, the client should call DNSServiceProcessResult(), which will extract the daemon's 710*5e7646d2SAndroid Build Coastguard Worker * reply from the socket, and pass it to the appropriate application callback. By using a run 711*5e7646d2SAndroid Build Coastguard Worker * loop or select(), results from the daemon can be processed asynchronously. Alternatively, 712*5e7646d2SAndroid Build Coastguard Worker * a client can choose to fork a thread and have it loop calling "DNSServiceProcessResult(ref);" 713*5e7646d2SAndroid Build Coastguard Worker * If DNSServiceProcessResult() is called when no data is available for reading on the socket, it 714*5e7646d2SAndroid Build Coastguard Worker * will block until data does become available, and then process the data and return to the caller. 715*5e7646d2SAndroid Build Coastguard Worker * When data arrives on the socket, the client is responsible for calling DNSServiceProcessResult(ref) 716*5e7646d2SAndroid Build Coastguard Worker * in a timely fashion -- if the client allows a large backlog of data to build up the daemon 717*5e7646d2SAndroid Build Coastguard Worker * may terminate the connection. 718*5e7646d2SAndroid Build Coastguard Worker * 719*5e7646d2SAndroid Build Coastguard Worker * sdRef: A DNSServiceRef initialized by any of the DNSService calls. 720*5e7646d2SAndroid Build Coastguard Worker * 721*5e7646d2SAndroid Build Coastguard Worker * return value: The DNSServiceRef's underlying socket descriptor, or -1 on 722*5e7646d2SAndroid Build Coastguard Worker * error. 723*5e7646d2SAndroid Build Coastguard Worker */ 724*5e7646d2SAndroid Build Coastguard Worker 725*5e7646d2SAndroid Build Coastguard Worker int DNSSD_API DNSServiceRefSockFD(DNSServiceRef sdRef); 726*5e7646d2SAndroid Build Coastguard Worker 727*5e7646d2SAndroid Build Coastguard Worker 728*5e7646d2SAndroid Build Coastguard Worker /* DNSServiceProcessResult() 729*5e7646d2SAndroid Build Coastguard Worker * 730*5e7646d2SAndroid Build Coastguard Worker * Read a reply from the daemon, calling the appropriate application callback. This call will 731*5e7646d2SAndroid Build Coastguard Worker * block until the daemon's response is received. Use DNSServiceRefSockFD() in 732*5e7646d2SAndroid Build Coastguard Worker * conjunction with a run loop or select() to determine the presence of a response from the 733*5e7646d2SAndroid Build Coastguard Worker * server before calling this function to process the reply without blocking. Call this function 734*5e7646d2SAndroid Build Coastguard Worker * at any point if it is acceptable to block until the daemon's response arrives. Note that the 735*5e7646d2SAndroid Build Coastguard Worker * client is responsible for ensuring that DNSServiceProcessResult() is called whenever there is 736*5e7646d2SAndroid Build Coastguard Worker * a reply from the daemon - the daemon may terminate its connection with a client that does not 737*5e7646d2SAndroid Build Coastguard Worker * process the daemon's responses. 738*5e7646d2SAndroid Build Coastguard Worker * 739*5e7646d2SAndroid Build Coastguard Worker * sdRef: A DNSServiceRef initialized by any of the DNSService calls 740*5e7646d2SAndroid Build Coastguard Worker * that take a callback parameter. 741*5e7646d2SAndroid Build Coastguard Worker * 742*5e7646d2SAndroid Build Coastguard Worker * return value: Returns kDNSServiceErr_NoError on success, otherwise returns 743*5e7646d2SAndroid Build Coastguard Worker * an error code indicating the specific failure that occurred. 744*5e7646d2SAndroid Build Coastguard Worker */ 745*5e7646d2SAndroid Build Coastguard Worker 746*5e7646d2SAndroid Build Coastguard Worker DNSServiceErrorType DNSSD_API DNSServiceProcessResult(DNSServiceRef sdRef); 747*5e7646d2SAndroid Build Coastguard Worker 748*5e7646d2SAndroid Build Coastguard Worker 749*5e7646d2SAndroid Build Coastguard Worker /* DNSServiceRefDeallocate() 750*5e7646d2SAndroid Build Coastguard Worker * 751*5e7646d2SAndroid Build Coastguard Worker * Terminate a connection with the daemon and free memory associated with the DNSServiceRef. 752*5e7646d2SAndroid Build Coastguard Worker * Any services or records registered with this DNSServiceRef will be deregistered. Any 753*5e7646d2SAndroid Build Coastguard Worker * Browse, Resolve, or Query operations called with this reference will be terminated. 754*5e7646d2SAndroid Build Coastguard Worker * 755*5e7646d2SAndroid Build Coastguard Worker * Note: If the reference's underlying socket is used in a run loop or select() call, it should 756*5e7646d2SAndroid Build Coastguard Worker * be removed BEFORE DNSServiceRefDeallocate() is called, as this function closes the reference's 757*5e7646d2SAndroid Build Coastguard Worker * socket. 758*5e7646d2SAndroid Build Coastguard Worker * 759*5e7646d2SAndroid Build Coastguard Worker * Note: If the reference was initialized with DNSServiceCreateConnection(), any DNSRecordRefs 760*5e7646d2SAndroid Build Coastguard Worker * created via this reference will be invalidated by this call - the resource records are 761*5e7646d2SAndroid Build Coastguard Worker * deregistered, and their DNSRecordRefs may not be used in subsequent functions. Similarly, 762*5e7646d2SAndroid Build Coastguard Worker * if the reference was initialized with DNSServiceRegister, and an extra resource record was 763*5e7646d2SAndroid Build Coastguard Worker * added to the service via DNSServiceAddRecord(), the DNSRecordRef created by the Add() call 764*5e7646d2SAndroid Build Coastguard Worker * is invalidated when this function is called - the DNSRecordRef may not be used in subsequent 765*5e7646d2SAndroid Build Coastguard Worker * functions. 766*5e7646d2SAndroid Build Coastguard Worker * 767*5e7646d2SAndroid Build Coastguard Worker * Note: This call is to be used only with the DNSServiceRef defined by this API. It is 768*5e7646d2SAndroid Build Coastguard Worker * not compatible with dns_service_discovery_ref objects defined in the legacy Mach-based 769*5e7646d2SAndroid Build Coastguard Worker * DNSServiceDiscovery.h API. 770*5e7646d2SAndroid Build Coastguard Worker * 771*5e7646d2SAndroid Build Coastguard Worker * sdRef: A DNSServiceRef initialized by any of the DNSService calls. 772*5e7646d2SAndroid Build Coastguard Worker * 773*5e7646d2SAndroid Build Coastguard Worker */ 774*5e7646d2SAndroid Build Coastguard Worker 775*5e7646d2SAndroid Build Coastguard Worker void DNSSD_API DNSServiceRefDeallocate(DNSServiceRef sdRef); 776*5e7646d2SAndroid Build Coastguard Worker 777*5e7646d2SAndroid Build Coastguard Worker 778*5e7646d2SAndroid Build Coastguard Worker /********************************************************************************************* 779*5e7646d2SAndroid Build Coastguard Worker * 780*5e7646d2SAndroid Build Coastguard Worker * Domain Enumeration 781*5e7646d2SAndroid Build Coastguard Worker * 782*5e7646d2SAndroid Build Coastguard Worker *********************************************************************************************/ 783*5e7646d2SAndroid Build Coastguard Worker 784*5e7646d2SAndroid Build Coastguard Worker /* DNSServiceEnumerateDomains() 785*5e7646d2SAndroid Build Coastguard Worker * 786*5e7646d2SAndroid Build Coastguard Worker * Asynchronously enumerate domains available for browsing and registration. 787*5e7646d2SAndroid Build Coastguard Worker * 788*5e7646d2SAndroid Build Coastguard Worker * The enumeration MUST be cancelled via DNSServiceRefDeallocate() when no more domains 789*5e7646d2SAndroid Build Coastguard Worker * are to be found. 790*5e7646d2SAndroid Build Coastguard Worker * 791*5e7646d2SAndroid Build Coastguard Worker * Note that the names returned are (like all of DNS-SD) UTF-8 strings, 792*5e7646d2SAndroid Build Coastguard Worker * and are escaped using standard DNS escaping rules. 793*5e7646d2SAndroid Build Coastguard Worker * (See "Notes on DNS Name Escaping" earlier in this file for more details.) 794*5e7646d2SAndroid Build Coastguard Worker * A graphical browser displaying a hierarchical tree-structured view should cut 795*5e7646d2SAndroid Build Coastguard Worker * the names at the bare dots to yield individual labels, then de-escape each 796*5e7646d2SAndroid Build Coastguard Worker * label according to the escaping rules, and then display the resulting UTF-8 text. 797*5e7646d2SAndroid Build Coastguard Worker * 798*5e7646d2SAndroid Build Coastguard Worker * DNSServiceDomainEnumReply Callback Parameters: 799*5e7646d2SAndroid Build Coastguard Worker * 800*5e7646d2SAndroid Build Coastguard Worker * sdRef: The DNSServiceRef initialized by DNSServiceEnumerateDomains(). 801*5e7646d2SAndroid Build Coastguard Worker * 802*5e7646d2SAndroid Build Coastguard Worker * flags: Possible values are: 803*5e7646d2SAndroid Build Coastguard Worker * kDNSServiceFlagsMoreComing 804*5e7646d2SAndroid Build Coastguard Worker * kDNSServiceFlagsAdd 805*5e7646d2SAndroid Build Coastguard Worker * kDNSServiceFlagsDefault 806*5e7646d2SAndroid Build Coastguard Worker * 807*5e7646d2SAndroid Build Coastguard Worker * interfaceIndex: Specifies the interface on which the domain exists. (The index for a given 808*5e7646d2SAndroid Build Coastguard Worker * interface is determined via the if_nametoindex() family of calls.) 809*5e7646d2SAndroid Build Coastguard Worker * 810*5e7646d2SAndroid Build Coastguard Worker * errorCode: Will be kDNSServiceErr_NoError (0) on success, otherwise indicates 811*5e7646d2SAndroid Build Coastguard Worker * the failure that occurred (other parameters are undefined if errorCode is nonzero). 812*5e7646d2SAndroid Build Coastguard Worker * 813*5e7646d2SAndroid Build Coastguard Worker * replyDomain: The name of the domain. 814*5e7646d2SAndroid Build Coastguard Worker * 815*5e7646d2SAndroid Build Coastguard Worker * context: The context pointer passed to DNSServiceEnumerateDomains. 816*5e7646d2SAndroid Build Coastguard Worker * 817*5e7646d2SAndroid Build Coastguard Worker */ 818*5e7646d2SAndroid Build Coastguard Worker 819*5e7646d2SAndroid Build Coastguard Worker typedef void (DNSSD_API *DNSServiceDomainEnumReply) 820*5e7646d2SAndroid Build Coastguard Worker ( 821*5e7646d2SAndroid Build Coastguard Worker DNSServiceRef sdRef, 822*5e7646d2SAndroid Build Coastguard Worker DNSServiceFlags flags, 823*5e7646d2SAndroid Build Coastguard Worker uint32_t interfaceIndex, 824*5e7646d2SAndroid Build Coastguard Worker DNSServiceErrorType errorCode, 825*5e7646d2SAndroid Build Coastguard Worker const char *replyDomain, 826*5e7646d2SAndroid Build Coastguard Worker void *context 827*5e7646d2SAndroid Build Coastguard Worker ); 828*5e7646d2SAndroid Build Coastguard Worker 829*5e7646d2SAndroid Build Coastguard Worker 830*5e7646d2SAndroid Build Coastguard Worker /* DNSServiceEnumerateDomains() Parameters: 831*5e7646d2SAndroid Build Coastguard Worker * 832*5e7646d2SAndroid Build Coastguard Worker * sdRef: A pointer to an uninitialized DNSServiceRef. If the call succeeds 833*5e7646d2SAndroid Build Coastguard Worker * then it initializes the DNSServiceRef, returns kDNSServiceErr_NoError, 834*5e7646d2SAndroid Build Coastguard Worker * and the enumeration operation will run indefinitely until the client 835*5e7646d2SAndroid Build Coastguard Worker * terminates it by passing this DNSServiceRef to DNSServiceRefDeallocate(). 836*5e7646d2SAndroid Build Coastguard Worker * 837*5e7646d2SAndroid Build Coastguard Worker * flags: Possible values are: 838*5e7646d2SAndroid Build Coastguard Worker * kDNSServiceFlagsBrowseDomains to enumerate domains recommended for browsing. 839*5e7646d2SAndroid Build Coastguard Worker * kDNSServiceFlagsRegistrationDomains to enumerate domains recommended 840*5e7646d2SAndroid Build Coastguard Worker * for registration. 841*5e7646d2SAndroid Build Coastguard Worker * 842*5e7646d2SAndroid Build Coastguard Worker * interfaceIndex: If non-zero, specifies the interface on which to look for domains. 843*5e7646d2SAndroid Build Coastguard Worker * (the index for a given interface is determined via the if_nametoindex() 844*5e7646d2SAndroid Build Coastguard Worker * family of calls.) Most applications will pass 0 to enumerate domains on 845*5e7646d2SAndroid Build Coastguard Worker * all interfaces. See "Constants for specifying an interface index" for more details. 846*5e7646d2SAndroid Build Coastguard Worker * 847*5e7646d2SAndroid Build Coastguard Worker * callBack: The function to be called when a domain is found or the call asynchronously 848*5e7646d2SAndroid Build Coastguard Worker * fails. 849*5e7646d2SAndroid Build Coastguard Worker * 850*5e7646d2SAndroid Build Coastguard Worker * context: An application context pointer which is passed to the callback function 851*5e7646d2SAndroid Build Coastguard Worker * (may be NULL). 852*5e7646d2SAndroid Build Coastguard Worker * 853*5e7646d2SAndroid Build Coastguard Worker * return value: Returns kDNSServiceErr_NoError on success (any subsequent, asynchronous 854*5e7646d2SAndroid Build Coastguard Worker * errors are delivered to the callback), otherwise returns an error code indicating 855*5e7646d2SAndroid Build Coastguard Worker * the error that occurred (the callback is not invoked and the DNSServiceRef 856*5e7646d2SAndroid Build Coastguard Worker * is not initialized). 857*5e7646d2SAndroid Build Coastguard Worker */ 858*5e7646d2SAndroid Build Coastguard Worker 859*5e7646d2SAndroid Build Coastguard Worker DNSServiceErrorType DNSSD_API DNSServiceEnumerateDomains 860*5e7646d2SAndroid Build Coastguard Worker ( 861*5e7646d2SAndroid Build Coastguard Worker DNSServiceRef *sdRef, 862*5e7646d2SAndroid Build Coastguard Worker DNSServiceFlags flags, 863*5e7646d2SAndroid Build Coastguard Worker uint32_t interfaceIndex, 864*5e7646d2SAndroid Build Coastguard Worker DNSServiceDomainEnumReply callBack, 865*5e7646d2SAndroid Build Coastguard Worker void *context /* may be NULL */ 866*5e7646d2SAndroid Build Coastguard Worker ); 867*5e7646d2SAndroid Build Coastguard Worker 868*5e7646d2SAndroid Build Coastguard Worker 869*5e7646d2SAndroid Build Coastguard Worker /********************************************************************************************* 870*5e7646d2SAndroid Build Coastguard Worker * 871*5e7646d2SAndroid Build Coastguard Worker * Service Registration 872*5e7646d2SAndroid Build Coastguard Worker * 873*5e7646d2SAndroid Build Coastguard Worker *********************************************************************************************/ 874*5e7646d2SAndroid Build Coastguard Worker 875*5e7646d2SAndroid Build Coastguard Worker /* Register a service that is discovered via Browse() and Resolve() calls. 876*5e7646d2SAndroid Build Coastguard Worker * 877*5e7646d2SAndroid Build Coastguard Worker * DNSServiceRegisterReply() Callback Parameters: 878*5e7646d2SAndroid Build Coastguard Worker * 879*5e7646d2SAndroid Build Coastguard Worker * sdRef: The DNSServiceRef initialized by DNSServiceRegister(). 880*5e7646d2SAndroid Build Coastguard Worker * 881*5e7646d2SAndroid Build Coastguard Worker * flags: When a name is successfully registered, the callback will be 882*5e7646d2SAndroid Build Coastguard Worker * invoked with the kDNSServiceFlagsAdd flag set. When Wide-Area 883*5e7646d2SAndroid Build Coastguard Worker * DNS-SD is in use, it is possible for a single service to get 884*5e7646d2SAndroid Build Coastguard Worker * more than one success callback (e.g. one in the "local" multicast 885*5e7646d2SAndroid Build Coastguard Worker * DNS domain, and another in a wide-area unicast DNS domain). 886*5e7646d2SAndroid Build Coastguard Worker * If a successfully-registered name later suffers a name conflict 887*5e7646d2SAndroid Build Coastguard Worker * or similar problem and has to be deregistered, the callback will 888*5e7646d2SAndroid Build Coastguard Worker * be invoked with the kDNSServiceFlagsAdd flag not set. The callback 889*5e7646d2SAndroid Build Coastguard Worker * is *not* invoked in the case where the caller explicitly terminates 890*5e7646d2SAndroid Build Coastguard Worker * the service registration by calling DNSServiceRefDeallocate(ref); 891*5e7646d2SAndroid Build Coastguard Worker * 892*5e7646d2SAndroid Build Coastguard Worker * errorCode: Will be kDNSServiceErr_NoError on success, otherwise will 893*5e7646d2SAndroid Build Coastguard Worker * indicate the failure that occurred (including name conflicts, 894*5e7646d2SAndroid Build Coastguard Worker * if the kDNSServiceFlagsNoAutoRename flag was used when registering.) 895*5e7646d2SAndroid Build Coastguard Worker * Other parameters are undefined if errorCode is nonzero. 896*5e7646d2SAndroid Build Coastguard Worker * 897*5e7646d2SAndroid Build Coastguard Worker * name: The service name registered (if the application did not specify a name in 898*5e7646d2SAndroid Build Coastguard Worker * DNSServiceRegister(), this indicates what name was automatically chosen). 899*5e7646d2SAndroid Build Coastguard Worker * 900*5e7646d2SAndroid Build Coastguard Worker * regtype: The type of service registered, as it was passed to the callout. 901*5e7646d2SAndroid Build Coastguard Worker * 902*5e7646d2SAndroid Build Coastguard Worker * domain: The domain on which the service was registered (if the application did not 903*5e7646d2SAndroid Build Coastguard Worker * specify a domain in DNSServiceRegister(), this indicates the default domain 904*5e7646d2SAndroid Build Coastguard Worker * on which the service was registered). 905*5e7646d2SAndroid Build Coastguard Worker * 906*5e7646d2SAndroid Build Coastguard Worker * context: The context pointer that was passed to the callout. 907*5e7646d2SAndroid Build Coastguard Worker * 908*5e7646d2SAndroid Build Coastguard Worker */ 909*5e7646d2SAndroid Build Coastguard Worker 910*5e7646d2SAndroid Build Coastguard Worker typedef void (DNSSD_API *DNSServiceRegisterReply) 911*5e7646d2SAndroid Build Coastguard Worker ( 912*5e7646d2SAndroid Build Coastguard Worker DNSServiceRef sdRef, 913*5e7646d2SAndroid Build Coastguard Worker DNSServiceFlags flags, 914*5e7646d2SAndroid Build Coastguard Worker DNSServiceErrorType errorCode, 915*5e7646d2SAndroid Build Coastguard Worker const char *name, 916*5e7646d2SAndroid Build Coastguard Worker const char *regtype, 917*5e7646d2SAndroid Build Coastguard Worker const char *domain, 918*5e7646d2SAndroid Build Coastguard Worker void *context 919*5e7646d2SAndroid Build Coastguard Worker ); 920*5e7646d2SAndroid Build Coastguard Worker 921*5e7646d2SAndroid Build Coastguard Worker 922*5e7646d2SAndroid Build Coastguard Worker /* DNSServiceRegister() Parameters: 923*5e7646d2SAndroid Build Coastguard Worker * 924*5e7646d2SAndroid Build Coastguard Worker * sdRef: A pointer to an uninitialized DNSServiceRef. If the call succeeds 925*5e7646d2SAndroid Build Coastguard Worker * then it initializes the DNSServiceRef, returns kDNSServiceErr_NoError, 926*5e7646d2SAndroid Build Coastguard Worker * and the registration will remain active indefinitely until the client 927*5e7646d2SAndroid Build Coastguard Worker * terminates it by passing this DNSServiceRef to DNSServiceRefDeallocate(). 928*5e7646d2SAndroid Build Coastguard Worker * 929*5e7646d2SAndroid Build Coastguard Worker * interfaceIndex: If non-zero, specifies the interface on which to register the service 930*5e7646d2SAndroid Build Coastguard Worker * (the index for a given interface is determined via the if_nametoindex() 931*5e7646d2SAndroid Build Coastguard Worker * family of calls.) Most applications will pass 0 to register on all 932*5e7646d2SAndroid Build Coastguard Worker * available interfaces. See "Constants for specifying an interface index" for more details. 933*5e7646d2SAndroid Build Coastguard Worker * 934*5e7646d2SAndroid Build Coastguard Worker * flags: Indicates the renaming behavior on name conflict (most applications 935*5e7646d2SAndroid Build Coastguard Worker * will pass 0). See flag definitions above for details. 936*5e7646d2SAndroid Build Coastguard Worker * 937*5e7646d2SAndroid Build Coastguard Worker * name: If non-NULL, specifies the service name to be registered. 938*5e7646d2SAndroid Build Coastguard Worker * Most applications will not specify a name, in which case the computer 939*5e7646d2SAndroid Build Coastguard Worker * name is used (this name is communicated to the client via the callback). 940*5e7646d2SAndroid Build Coastguard Worker * If a name is specified, it must be 1-63 bytes of UTF-8 text. 941*5e7646d2SAndroid Build Coastguard Worker * If the name is longer than 63 bytes it will be automatically truncated 942*5e7646d2SAndroid Build Coastguard Worker * to a legal length, unless the NoAutoRename flag is set, 943*5e7646d2SAndroid Build Coastguard Worker * in which case kDNSServiceErr_BadParam will be returned. 944*5e7646d2SAndroid Build Coastguard Worker * 945*5e7646d2SAndroid Build Coastguard Worker * regtype: The service type followed by the protocol, separated by a dot 946*5e7646d2SAndroid Build Coastguard Worker * (e.g. "_ftp._tcp"). The service type must be an underscore, followed 947*5e7646d2SAndroid Build Coastguard Worker * by 1-15 characters, which may be letters, digits, or hyphens. 948*5e7646d2SAndroid Build Coastguard Worker * The transport protocol must be "_tcp" or "_udp". New service types 949*5e7646d2SAndroid Build Coastguard Worker * should be registered at <http://www.dns-sd.org/ServiceTypes.html>. 950*5e7646d2SAndroid Build Coastguard Worker * 951*5e7646d2SAndroid Build Coastguard Worker * Additional subtypes of the primary service type (where a service 952*5e7646d2SAndroid Build Coastguard Worker * type has defined subtypes) follow the primary service type in a 953*5e7646d2SAndroid Build Coastguard Worker * comma-separated list, with no additional spaces, e.g. 954*5e7646d2SAndroid Build Coastguard Worker * "_primarytype._tcp,_subtype1,_subtype2,_subtype3" 955*5e7646d2SAndroid Build Coastguard Worker * Subtypes provide a mechanism for filtered browsing: A client browsing 956*5e7646d2SAndroid Build Coastguard Worker * for "_primarytype._tcp" will discover all instances of this type; 957*5e7646d2SAndroid Build Coastguard Worker * a client browsing for "_primarytype._tcp,_subtype2" will discover only 958*5e7646d2SAndroid Build Coastguard Worker * those instances that were registered with "_subtype2" in their list of 959*5e7646d2SAndroid Build Coastguard Worker * registered subtypes. 960*5e7646d2SAndroid Build Coastguard Worker * 961*5e7646d2SAndroid Build Coastguard Worker * The subtype mechanism can be illustrated with some examples using the 962*5e7646d2SAndroid Build Coastguard Worker * dns-sd command-line tool: 963*5e7646d2SAndroid Build Coastguard Worker * 964*5e7646d2SAndroid Build Coastguard Worker * % dns-sd -R Simple _test._tcp "" 1001 & 965*5e7646d2SAndroid Build Coastguard Worker * % dns-sd -R Better _test._tcp,HasFeatureA "" 1002 & 966*5e7646d2SAndroid Build Coastguard Worker * % dns-sd -R Best _test._tcp,HasFeatureA,HasFeatureB "" 1003 & 967*5e7646d2SAndroid Build Coastguard Worker * 968*5e7646d2SAndroid Build Coastguard Worker * Now: 969*5e7646d2SAndroid Build Coastguard Worker * % dns-sd -B _test._tcp # will find all three services 970*5e7646d2SAndroid Build Coastguard Worker * % dns-sd -B _test._tcp,HasFeatureA # finds "Better" and "Best" 971*5e7646d2SAndroid Build Coastguard Worker * % dns-sd -B _test._tcp,HasFeatureB # finds only "Best" 972*5e7646d2SAndroid Build Coastguard Worker * 973*5e7646d2SAndroid Build Coastguard Worker * Subtype labels may be up to 63 bytes long, and may contain any eight- 974*5e7646d2SAndroid Build Coastguard Worker * bit byte values, including zero bytes. However, due to the nature of 975*5e7646d2SAndroid Build Coastguard Worker * using a C-string-based API, conventional DNS escaping must be used for 976*5e7646d2SAndroid Build Coastguard Worker * dots ('.'), commas (','), backslashes ('\') and zero bytes, as shown below: 977*5e7646d2SAndroid Build Coastguard Worker * 978*5e7646d2SAndroid Build Coastguard Worker * % dns-sd -R Test '_test._tcp,s\.one,s\,two,s\\three,s\000four' local 123 979*5e7646d2SAndroid Build Coastguard Worker * 980*5e7646d2SAndroid Build Coastguard Worker * domain: If non-NULL, specifies the domain on which to advertise the service. 981*5e7646d2SAndroid Build Coastguard Worker * Most applications will not specify a domain, instead automatically 982*5e7646d2SAndroid Build Coastguard Worker * registering in the default domain(s). 983*5e7646d2SAndroid Build Coastguard Worker * 984*5e7646d2SAndroid Build Coastguard Worker * host: If non-NULL, specifies the SRV target host name. Most applications 985*5e7646d2SAndroid Build Coastguard Worker * will not specify a host, instead automatically using the machine's 986*5e7646d2SAndroid Build Coastguard Worker * default host name(s). Note that specifying a non-NULL host does NOT 987*5e7646d2SAndroid Build Coastguard Worker * create an address record for that host - the application is responsible 988*5e7646d2SAndroid Build Coastguard Worker * for ensuring that the appropriate address record exists, or creating it 989*5e7646d2SAndroid Build Coastguard Worker * via DNSServiceRegisterRecord(). 990*5e7646d2SAndroid Build Coastguard Worker * 991*5e7646d2SAndroid Build Coastguard Worker * port: The port, in network byte order, on which the service accepts connections. 992*5e7646d2SAndroid Build Coastguard Worker * Pass 0 for a "placeholder" service (i.e. a service that will not be discovered 993*5e7646d2SAndroid Build Coastguard Worker * by browsing, but will cause a name conflict if another client tries to 994*5e7646d2SAndroid Build Coastguard Worker * register that same name). Most clients will not use placeholder services. 995*5e7646d2SAndroid Build Coastguard Worker * 996*5e7646d2SAndroid Build Coastguard Worker * txtLen: The length of the txtRecord, in bytes. Must be zero if the txtRecord is NULL. 997*5e7646d2SAndroid Build Coastguard Worker * 998*5e7646d2SAndroid Build Coastguard Worker * txtRecord: The TXT record rdata. A non-NULL txtRecord MUST be a properly formatted DNS 999*5e7646d2SAndroid Build Coastguard Worker * TXT record, i.e. <length byte> <data> <length byte> <data> ... 1000*5e7646d2SAndroid Build Coastguard Worker * Passing NULL for the txtRecord is allowed as a synonym for txtLen=1, txtRecord="", 1001*5e7646d2SAndroid Build Coastguard Worker * i.e. it creates a TXT record of length one containing a single empty string. 1002*5e7646d2SAndroid Build Coastguard Worker * RFC 1035 doesn't allow a TXT record to contain *zero* strings, so a single empty 1003*5e7646d2SAndroid Build Coastguard Worker * string is the smallest legal DNS TXT record. 1004*5e7646d2SAndroid Build Coastguard Worker * As with the other parameters, the DNSServiceRegister call copies the txtRecord 1005*5e7646d2SAndroid Build Coastguard Worker * data; e.g. if you allocated the storage for the txtRecord parameter with malloc() 1006*5e7646d2SAndroid Build Coastguard Worker * then you can safely free that memory right after the DNSServiceRegister call returns. 1007*5e7646d2SAndroid Build Coastguard Worker * 1008*5e7646d2SAndroid Build Coastguard Worker * callBack: The function to be called when the registration completes or asynchronously 1009*5e7646d2SAndroid Build Coastguard Worker * fails. The client MAY pass NULL for the callback - The client will NOT be notified 1010*5e7646d2SAndroid Build Coastguard Worker * of the default values picked on its behalf, and the client will NOT be notified of any 1011*5e7646d2SAndroid Build Coastguard Worker * asynchronous errors (e.g. out of memory errors, etc.) that may prevent the registration 1012*5e7646d2SAndroid Build Coastguard Worker * of the service. The client may NOT pass the NoAutoRename flag if the callback is NULL. 1013*5e7646d2SAndroid Build Coastguard Worker * The client may still deregister the service at any time via DNSServiceRefDeallocate(). 1014*5e7646d2SAndroid Build Coastguard Worker * 1015*5e7646d2SAndroid Build Coastguard Worker * context: An application context pointer which is passed to the callback function 1016*5e7646d2SAndroid Build Coastguard Worker * (may be NULL). 1017*5e7646d2SAndroid Build Coastguard Worker * 1018*5e7646d2SAndroid Build Coastguard Worker * return value: Returns kDNSServiceErr_NoError on success (any subsequent, asynchronous 1019*5e7646d2SAndroid Build Coastguard Worker * errors are delivered to the callback), otherwise returns an error code indicating 1020*5e7646d2SAndroid Build Coastguard Worker * the error that occurred (the callback is never invoked and the DNSServiceRef 1021*5e7646d2SAndroid Build Coastguard Worker * is not initialized). 1022*5e7646d2SAndroid Build Coastguard Worker */ 1023*5e7646d2SAndroid Build Coastguard Worker 1024*5e7646d2SAndroid Build Coastguard Worker DNSServiceErrorType DNSSD_API DNSServiceRegister 1025*5e7646d2SAndroid Build Coastguard Worker ( 1026*5e7646d2SAndroid Build Coastguard Worker DNSServiceRef *sdRef, 1027*5e7646d2SAndroid Build Coastguard Worker DNSServiceFlags flags, 1028*5e7646d2SAndroid Build Coastguard Worker uint32_t interfaceIndex, 1029*5e7646d2SAndroid Build Coastguard Worker const char *name, /* may be NULL */ 1030*5e7646d2SAndroid Build Coastguard Worker const char *regtype, 1031*5e7646d2SAndroid Build Coastguard Worker const char *domain, /* may be NULL */ 1032*5e7646d2SAndroid Build Coastguard Worker const char *host, /* may be NULL */ 1033*5e7646d2SAndroid Build Coastguard Worker uint16_t port, /* In network byte order */ 1034*5e7646d2SAndroid Build Coastguard Worker uint16_t txtLen, 1035*5e7646d2SAndroid Build Coastguard Worker const void *txtRecord, /* may be NULL */ 1036*5e7646d2SAndroid Build Coastguard Worker DNSServiceRegisterReply callBack, /* may be NULL */ 1037*5e7646d2SAndroid Build Coastguard Worker void *context /* may be NULL */ 1038*5e7646d2SAndroid Build Coastguard Worker ); 1039*5e7646d2SAndroid Build Coastguard Worker 1040*5e7646d2SAndroid Build Coastguard Worker 1041*5e7646d2SAndroid Build Coastguard Worker /* DNSServiceAddRecord() 1042*5e7646d2SAndroid Build Coastguard Worker * 1043*5e7646d2SAndroid Build Coastguard Worker * Add a record to a registered service. The name of the record will be the same as the 1044*5e7646d2SAndroid Build Coastguard Worker * registered service's name. 1045*5e7646d2SAndroid Build Coastguard Worker * The record can later be updated or deregistered by passing the RecordRef initialized 1046*5e7646d2SAndroid Build Coastguard Worker * by this function to DNSServiceUpdateRecord() or DNSServiceRemoveRecord(). 1047*5e7646d2SAndroid Build Coastguard Worker * 1048*5e7646d2SAndroid Build Coastguard Worker * Note that the DNSServiceAddRecord/UpdateRecord/RemoveRecord are *NOT* thread-safe 1049*5e7646d2SAndroid Build Coastguard Worker * with respect to a single DNSServiceRef. If you plan to have multiple threads 1050*5e7646d2SAndroid Build Coastguard Worker * in your program simultaneously add, update, or remove records from the same 1051*5e7646d2SAndroid Build Coastguard Worker * DNSServiceRef, then it's the caller's responsibility to use a mutext lock 1052*5e7646d2SAndroid Build Coastguard Worker * or take similar appropriate precautions to serialize those calls. 1053*5e7646d2SAndroid Build Coastguard Worker * 1054*5e7646d2SAndroid Build Coastguard Worker * Parameters; 1055*5e7646d2SAndroid Build Coastguard Worker * 1056*5e7646d2SAndroid Build Coastguard Worker * sdRef: A DNSServiceRef initialized by DNSServiceRegister(). 1057*5e7646d2SAndroid Build Coastguard Worker * 1058*5e7646d2SAndroid Build Coastguard Worker * RecordRef: A pointer to an uninitialized DNSRecordRef. Upon succesfull completion of this 1059*5e7646d2SAndroid Build Coastguard Worker * call, this ref may be passed to DNSServiceUpdateRecord() or DNSServiceRemoveRecord(). 1060*5e7646d2SAndroid Build Coastguard Worker * If the above DNSServiceRef is passed to DNSServiceRefDeallocate(), RecordRef is also 1061*5e7646d2SAndroid Build Coastguard Worker * invalidated and may not be used further. 1062*5e7646d2SAndroid Build Coastguard Worker * 1063*5e7646d2SAndroid Build Coastguard Worker * flags: Currently ignored, reserved for future use. 1064*5e7646d2SAndroid Build Coastguard Worker * 1065*5e7646d2SAndroid Build Coastguard Worker * rrtype: The type of the record (e.g. kDNSServiceType_TXT, kDNSServiceType_SRV, etc) 1066*5e7646d2SAndroid Build Coastguard Worker * 1067*5e7646d2SAndroid Build Coastguard Worker * rdlen: The length, in bytes, of the rdata. 1068*5e7646d2SAndroid Build Coastguard Worker * 1069*5e7646d2SAndroid Build Coastguard Worker * rdata: The raw rdata to be contained in the added resource record. 1070*5e7646d2SAndroid Build Coastguard Worker * 1071*5e7646d2SAndroid Build Coastguard Worker * ttl: The time to live of the resource record, in seconds. 1072*5e7646d2SAndroid Build Coastguard Worker * Most clients should pass 0 to indicate that the system should 1073*5e7646d2SAndroid Build Coastguard Worker * select a sensible default value. 1074*5e7646d2SAndroid Build Coastguard Worker * 1075*5e7646d2SAndroid Build Coastguard Worker * return value: Returns kDNSServiceErr_NoError on success, otherwise returns an 1076*5e7646d2SAndroid Build Coastguard Worker * error code indicating the error that occurred (the RecordRef is not initialized). 1077*5e7646d2SAndroid Build Coastguard Worker */ 1078*5e7646d2SAndroid Build Coastguard Worker 1079*5e7646d2SAndroid Build Coastguard Worker DNSServiceErrorType DNSSD_API DNSServiceAddRecord 1080*5e7646d2SAndroid Build Coastguard Worker ( 1081*5e7646d2SAndroid Build Coastguard Worker DNSServiceRef sdRef, 1082*5e7646d2SAndroid Build Coastguard Worker DNSRecordRef *RecordRef, 1083*5e7646d2SAndroid Build Coastguard Worker DNSServiceFlags flags, 1084*5e7646d2SAndroid Build Coastguard Worker uint16_t rrtype, 1085*5e7646d2SAndroid Build Coastguard Worker uint16_t rdlen, 1086*5e7646d2SAndroid Build Coastguard Worker const void *rdata, 1087*5e7646d2SAndroid Build Coastguard Worker uint32_t ttl 1088*5e7646d2SAndroid Build Coastguard Worker ); 1089*5e7646d2SAndroid Build Coastguard Worker 1090*5e7646d2SAndroid Build Coastguard Worker 1091*5e7646d2SAndroid Build Coastguard Worker /* DNSServiceUpdateRecord 1092*5e7646d2SAndroid Build Coastguard Worker * 1093*5e7646d2SAndroid Build Coastguard Worker * Update a registered resource record. The record must either be: 1094*5e7646d2SAndroid Build Coastguard Worker * - The primary txt record of a service registered via DNSServiceRegister() 1095*5e7646d2SAndroid Build Coastguard Worker * - A record added to a registered service via DNSServiceAddRecord() 1096*5e7646d2SAndroid Build Coastguard Worker * - An individual record registered by DNSServiceRegisterRecord() 1097*5e7646d2SAndroid Build Coastguard Worker * 1098*5e7646d2SAndroid Build Coastguard Worker * Parameters: 1099*5e7646d2SAndroid Build Coastguard Worker * 1100*5e7646d2SAndroid Build Coastguard Worker * sdRef: A DNSServiceRef that was initialized by DNSServiceRegister() 1101*5e7646d2SAndroid Build Coastguard Worker * or DNSServiceCreateConnection(). 1102*5e7646d2SAndroid Build Coastguard Worker * 1103*5e7646d2SAndroid Build Coastguard Worker * RecordRef: A DNSRecordRef initialized by DNSServiceAddRecord, or NULL to update the 1104*5e7646d2SAndroid Build Coastguard Worker * service's primary txt record. 1105*5e7646d2SAndroid Build Coastguard Worker * 1106*5e7646d2SAndroid Build Coastguard Worker * flags: Currently ignored, reserved for future use. 1107*5e7646d2SAndroid Build Coastguard Worker * 1108*5e7646d2SAndroid Build Coastguard Worker * rdlen: The length, in bytes, of the new rdata. 1109*5e7646d2SAndroid Build Coastguard Worker * 1110*5e7646d2SAndroid Build Coastguard Worker * rdata: The new rdata to be contained in the updated resource record. 1111*5e7646d2SAndroid Build Coastguard Worker * 1112*5e7646d2SAndroid Build Coastguard Worker * ttl: The time to live of the updated resource record, in seconds. 1113*5e7646d2SAndroid Build Coastguard Worker * Most clients should pass 0 to indicate that the system should 1114*5e7646d2SAndroid Build Coastguard Worker * select a sensible default value. 1115*5e7646d2SAndroid Build Coastguard Worker * 1116*5e7646d2SAndroid Build Coastguard Worker * return value: Returns kDNSServiceErr_NoError on success, otherwise returns an 1117*5e7646d2SAndroid Build Coastguard Worker * error code indicating the error that occurred. 1118*5e7646d2SAndroid Build Coastguard Worker */ 1119*5e7646d2SAndroid Build Coastguard Worker 1120*5e7646d2SAndroid Build Coastguard Worker DNSServiceErrorType DNSSD_API DNSServiceUpdateRecord 1121*5e7646d2SAndroid Build Coastguard Worker ( 1122*5e7646d2SAndroid Build Coastguard Worker DNSServiceRef sdRef, 1123*5e7646d2SAndroid Build Coastguard Worker DNSRecordRef RecordRef, /* may be NULL */ 1124*5e7646d2SAndroid Build Coastguard Worker DNSServiceFlags flags, 1125*5e7646d2SAndroid Build Coastguard Worker uint16_t rdlen, 1126*5e7646d2SAndroid Build Coastguard Worker const void *rdata, 1127*5e7646d2SAndroid Build Coastguard Worker uint32_t ttl 1128*5e7646d2SAndroid Build Coastguard Worker ); 1129*5e7646d2SAndroid Build Coastguard Worker 1130*5e7646d2SAndroid Build Coastguard Worker 1131*5e7646d2SAndroid Build Coastguard Worker /* DNSServiceRemoveRecord 1132*5e7646d2SAndroid Build Coastguard Worker * 1133*5e7646d2SAndroid Build Coastguard Worker * Remove a record previously added to a service record set via DNSServiceAddRecord(), or deregister 1134*5e7646d2SAndroid Build Coastguard Worker * an record registered individually via DNSServiceRegisterRecord(). 1135*5e7646d2SAndroid Build Coastguard Worker * 1136*5e7646d2SAndroid Build Coastguard Worker * Parameters: 1137*5e7646d2SAndroid Build Coastguard Worker * 1138*5e7646d2SAndroid Build Coastguard Worker * sdRef: A DNSServiceRef initialized by DNSServiceRegister() (if the 1139*5e7646d2SAndroid Build Coastguard Worker * record being removed was registered via DNSServiceAddRecord()) or by 1140*5e7646d2SAndroid Build Coastguard Worker * DNSServiceCreateConnection() (if the record being removed was registered via 1141*5e7646d2SAndroid Build Coastguard Worker * DNSServiceRegisterRecord()). 1142*5e7646d2SAndroid Build Coastguard Worker * 1143*5e7646d2SAndroid Build Coastguard Worker * recordRef: A DNSRecordRef initialized by a successful call to DNSServiceAddRecord() 1144*5e7646d2SAndroid Build Coastguard Worker * or DNSServiceRegisterRecord(). 1145*5e7646d2SAndroid Build Coastguard Worker * 1146*5e7646d2SAndroid Build Coastguard Worker * flags: Currently ignored, reserved for future use. 1147*5e7646d2SAndroid Build Coastguard Worker * 1148*5e7646d2SAndroid Build Coastguard Worker * return value: Returns kDNSServiceErr_NoError on success, otherwise returns an 1149*5e7646d2SAndroid Build Coastguard Worker * error code indicating the error that occurred. 1150*5e7646d2SAndroid Build Coastguard Worker */ 1151*5e7646d2SAndroid Build Coastguard Worker 1152*5e7646d2SAndroid Build Coastguard Worker DNSServiceErrorType DNSSD_API DNSServiceRemoveRecord 1153*5e7646d2SAndroid Build Coastguard Worker ( 1154*5e7646d2SAndroid Build Coastguard Worker DNSServiceRef sdRef, 1155*5e7646d2SAndroid Build Coastguard Worker DNSRecordRef RecordRef, 1156*5e7646d2SAndroid Build Coastguard Worker DNSServiceFlags flags 1157*5e7646d2SAndroid Build Coastguard Worker ); 1158*5e7646d2SAndroid Build Coastguard Worker 1159*5e7646d2SAndroid Build Coastguard Worker 1160*5e7646d2SAndroid Build Coastguard Worker /********************************************************************************************* 1161*5e7646d2SAndroid Build Coastguard Worker * 1162*5e7646d2SAndroid Build Coastguard Worker * Service Discovery 1163*5e7646d2SAndroid Build Coastguard Worker * 1164*5e7646d2SAndroid Build Coastguard Worker *********************************************************************************************/ 1165*5e7646d2SAndroid Build Coastguard Worker 1166*5e7646d2SAndroid Build Coastguard Worker /* Browse for instances of a service. 1167*5e7646d2SAndroid Build Coastguard Worker * 1168*5e7646d2SAndroid Build Coastguard Worker * DNSServiceBrowseReply() Parameters: 1169*5e7646d2SAndroid Build Coastguard Worker * 1170*5e7646d2SAndroid Build Coastguard Worker * sdRef: The DNSServiceRef initialized by DNSServiceBrowse(). 1171*5e7646d2SAndroid Build Coastguard Worker * 1172*5e7646d2SAndroid Build Coastguard Worker * flags: Possible values are kDNSServiceFlagsMoreComing and kDNSServiceFlagsAdd. 1173*5e7646d2SAndroid Build Coastguard Worker * See flag definitions for details. 1174*5e7646d2SAndroid Build Coastguard Worker * 1175*5e7646d2SAndroid Build Coastguard Worker * interfaceIndex: The interface on which the service is advertised. This index should 1176*5e7646d2SAndroid Build Coastguard Worker * be passed to DNSServiceResolve() when resolving the service. 1177*5e7646d2SAndroid Build Coastguard Worker * 1178*5e7646d2SAndroid Build Coastguard Worker * errorCode: Will be kDNSServiceErr_NoError (0) on success, otherwise will 1179*5e7646d2SAndroid Build Coastguard Worker * indicate the failure that occurred. Other parameters are undefined if 1180*5e7646d2SAndroid Build Coastguard Worker * the errorCode is nonzero. 1181*5e7646d2SAndroid Build Coastguard Worker * 1182*5e7646d2SAndroid Build Coastguard Worker * serviceName: The discovered service name. This name should be displayed to the user, 1183*5e7646d2SAndroid Build Coastguard Worker * and stored for subsequent use in the DNSServiceResolve() call. 1184*5e7646d2SAndroid Build Coastguard Worker * 1185*5e7646d2SAndroid Build Coastguard Worker * regtype: The service type, which is usually (but not always) the same as was passed 1186*5e7646d2SAndroid Build Coastguard Worker * to DNSServiceBrowse(). One case where the discovered service type may 1187*5e7646d2SAndroid Build Coastguard Worker * not be the same as the requested service type is when using subtypes: 1188*5e7646d2SAndroid Build Coastguard Worker * The client may want to browse for only those ftp servers that allow 1189*5e7646d2SAndroid Build Coastguard Worker * anonymous connections. The client will pass the string "_ftp._tcp,_anon" 1190*5e7646d2SAndroid Build Coastguard Worker * to DNSServiceBrowse(), but the type of the service that's discovered 1191*5e7646d2SAndroid Build Coastguard Worker * is simply "_ftp._tcp". The regtype for each discovered service instance 1192*5e7646d2SAndroid Build Coastguard Worker * should be stored along with the name, so that it can be passed to 1193*5e7646d2SAndroid Build Coastguard Worker * DNSServiceResolve() when the service is later resolved. 1194*5e7646d2SAndroid Build Coastguard Worker * 1195*5e7646d2SAndroid Build Coastguard Worker * domain: The domain of the discovered service instance. This may or may not be the 1196*5e7646d2SAndroid Build Coastguard Worker * same as the domain that was passed to DNSServiceBrowse(). The domain for each 1197*5e7646d2SAndroid Build Coastguard Worker * discovered service instance should be stored along with the name, so that 1198*5e7646d2SAndroid Build Coastguard Worker * it can be passed to DNSServiceResolve() when the service is later resolved. 1199*5e7646d2SAndroid Build Coastguard Worker * 1200*5e7646d2SAndroid Build Coastguard Worker * context: The context pointer that was passed to the callout. 1201*5e7646d2SAndroid Build Coastguard Worker * 1202*5e7646d2SAndroid Build Coastguard Worker */ 1203*5e7646d2SAndroid Build Coastguard Worker 1204*5e7646d2SAndroid Build Coastguard Worker typedef void (DNSSD_API *DNSServiceBrowseReply) 1205*5e7646d2SAndroid Build Coastguard Worker ( 1206*5e7646d2SAndroid Build Coastguard Worker DNSServiceRef sdRef, 1207*5e7646d2SAndroid Build Coastguard Worker DNSServiceFlags flags, 1208*5e7646d2SAndroid Build Coastguard Worker uint32_t interfaceIndex, 1209*5e7646d2SAndroid Build Coastguard Worker DNSServiceErrorType errorCode, 1210*5e7646d2SAndroid Build Coastguard Worker const char *serviceName, 1211*5e7646d2SAndroid Build Coastguard Worker const char *regtype, 1212*5e7646d2SAndroid Build Coastguard Worker const char *replyDomain, 1213*5e7646d2SAndroid Build Coastguard Worker void *context 1214*5e7646d2SAndroid Build Coastguard Worker ); 1215*5e7646d2SAndroid Build Coastguard Worker 1216*5e7646d2SAndroid Build Coastguard Worker 1217*5e7646d2SAndroid Build Coastguard Worker /* DNSServiceBrowse() Parameters: 1218*5e7646d2SAndroid Build Coastguard Worker * 1219*5e7646d2SAndroid Build Coastguard Worker * sdRef: A pointer to an uninitialized DNSServiceRef. If the call succeeds 1220*5e7646d2SAndroid Build Coastguard Worker * then it initializes the DNSServiceRef, returns kDNSServiceErr_NoError, 1221*5e7646d2SAndroid Build Coastguard Worker * and the browse operation will run indefinitely until the client 1222*5e7646d2SAndroid Build Coastguard Worker * terminates it by passing this DNSServiceRef to DNSServiceRefDeallocate(). 1223*5e7646d2SAndroid Build Coastguard Worker * 1224*5e7646d2SAndroid Build Coastguard Worker * flags: Currently ignored, reserved for future use. 1225*5e7646d2SAndroid Build Coastguard Worker * 1226*5e7646d2SAndroid Build Coastguard Worker * interfaceIndex: If non-zero, specifies the interface on which to browse for services 1227*5e7646d2SAndroid Build Coastguard Worker * (the index for a given interface is determined via the if_nametoindex() 1228*5e7646d2SAndroid Build Coastguard Worker * family of calls.) Most applications will pass 0 to browse on all available 1229*5e7646d2SAndroid Build Coastguard Worker * interfaces. See "Constants for specifying an interface index" for more details. 1230*5e7646d2SAndroid Build Coastguard Worker * 1231*5e7646d2SAndroid Build Coastguard Worker * regtype: The service type being browsed for followed by the protocol, separated by a 1232*5e7646d2SAndroid Build Coastguard Worker * dot (e.g. "_ftp._tcp"). The transport protocol must be "_tcp" or "_udp". 1233*5e7646d2SAndroid Build Coastguard Worker * A client may optionally specify a single subtype to perform filtered browsing: 1234*5e7646d2SAndroid Build Coastguard Worker * e.g. browsing for "_primarytype._tcp,_subtype" will discover only those 1235*5e7646d2SAndroid Build Coastguard Worker * instances of "_primarytype._tcp" that were registered specifying "_subtype" 1236*5e7646d2SAndroid Build Coastguard Worker * in their list of registered subtypes. 1237*5e7646d2SAndroid Build Coastguard Worker * 1238*5e7646d2SAndroid Build Coastguard Worker * domain: If non-NULL, specifies the domain on which to browse for services. 1239*5e7646d2SAndroid Build Coastguard Worker * Most applications will not specify a domain, instead browsing on the 1240*5e7646d2SAndroid Build Coastguard Worker * default domain(s). 1241*5e7646d2SAndroid Build Coastguard Worker * 1242*5e7646d2SAndroid Build Coastguard Worker * callBack: The function to be called when an instance of the service being browsed for 1243*5e7646d2SAndroid Build Coastguard Worker * is found, or if the call asynchronously fails. 1244*5e7646d2SAndroid Build Coastguard Worker * 1245*5e7646d2SAndroid Build Coastguard Worker * context: An application context pointer which is passed to the callback function 1246*5e7646d2SAndroid Build Coastguard Worker * (may be NULL). 1247*5e7646d2SAndroid Build Coastguard Worker * 1248*5e7646d2SAndroid Build Coastguard Worker * return value: Returns kDNSServiceErr_NoError on success (any subsequent, asynchronous 1249*5e7646d2SAndroid Build Coastguard Worker * errors are delivered to the callback), otherwise returns an error code indicating 1250*5e7646d2SAndroid Build Coastguard Worker * the error that occurred (the callback is not invoked and the DNSServiceRef 1251*5e7646d2SAndroid Build Coastguard Worker * is not initialized). 1252*5e7646d2SAndroid Build Coastguard Worker */ 1253*5e7646d2SAndroid Build Coastguard Worker 1254*5e7646d2SAndroid Build Coastguard Worker DNSServiceErrorType DNSSD_API DNSServiceBrowse 1255*5e7646d2SAndroid Build Coastguard Worker ( 1256*5e7646d2SAndroid Build Coastguard Worker DNSServiceRef *sdRef, 1257*5e7646d2SAndroid Build Coastguard Worker DNSServiceFlags flags, 1258*5e7646d2SAndroid Build Coastguard Worker uint32_t interfaceIndex, 1259*5e7646d2SAndroid Build Coastguard Worker const char *regtype, 1260*5e7646d2SAndroid Build Coastguard Worker const char *domain, /* may be NULL */ 1261*5e7646d2SAndroid Build Coastguard Worker DNSServiceBrowseReply callBack, 1262*5e7646d2SAndroid Build Coastguard Worker void *context /* may be NULL */ 1263*5e7646d2SAndroid Build Coastguard Worker ); 1264*5e7646d2SAndroid Build Coastguard Worker 1265*5e7646d2SAndroid Build Coastguard Worker 1266*5e7646d2SAndroid Build Coastguard Worker /* DNSServiceResolve() 1267*5e7646d2SAndroid Build Coastguard Worker * 1268*5e7646d2SAndroid Build Coastguard Worker * Resolve a service name discovered via DNSServiceBrowse() to a target host name, port number, and 1269*5e7646d2SAndroid Build Coastguard Worker * txt record. 1270*5e7646d2SAndroid Build Coastguard Worker * 1271*5e7646d2SAndroid Build Coastguard Worker * Note: Applications should NOT use DNSServiceResolve() solely for txt record monitoring - use 1272*5e7646d2SAndroid Build Coastguard Worker * DNSServiceQueryRecord() instead, as it is more efficient for this task. 1273*5e7646d2SAndroid Build Coastguard Worker * 1274*5e7646d2SAndroid Build Coastguard Worker * Note: When the desired results have been returned, the client MUST terminate the resolve by calling 1275*5e7646d2SAndroid Build Coastguard Worker * DNSServiceRefDeallocate(). 1276*5e7646d2SAndroid Build Coastguard Worker * 1277*5e7646d2SAndroid Build Coastguard Worker * Note: DNSServiceResolve() behaves correctly for typical services that have a single SRV record 1278*5e7646d2SAndroid Build Coastguard Worker * and a single TXT record. To resolve non-standard services with multiple SRV or TXT records, 1279*5e7646d2SAndroid Build Coastguard Worker * DNSServiceQueryRecord() should be used. 1280*5e7646d2SAndroid Build Coastguard Worker * 1281*5e7646d2SAndroid Build Coastguard Worker * DNSServiceResolveReply Callback Parameters: 1282*5e7646d2SAndroid Build Coastguard Worker * 1283*5e7646d2SAndroid Build Coastguard Worker * sdRef: The DNSServiceRef initialized by DNSServiceResolve(). 1284*5e7646d2SAndroid Build Coastguard Worker * 1285*5e7646d2SAndroid Build Coastguard Worker * flags: Possible values: kDNSServiceFlagsMoreComing 1286*5e7646d2SAndroid Build Coastguard Worker * 1287*5e7646d2SAndroid Build Coastguard Worker * interfaceIndex: The interface on which the service was resolved. 1288*5e7646d2SAndroid Build Coastguard Worker * 1289*5e7646d2SAndroid Build Coastguard Worker * errorCode: Will be kDNSServiceErr_NoError (0) on success, otherwise will 1290*5e7646d2SAndroid Build Coastguard Worker * indicate the failure that occurred. Other parameters are undefined if 1291*5e7646d2SAndroid Build Coastguard Worker * the errorCode is nonzero. 1292*5e7646d2SAndroid Build Coastguard Worker * 1293*5e7646d2SAndroid Build Coastguard Worker * fullname: The full service domain name, in the form <servicename>.<protocol>.<domain>. 1294*5e7646d2SAndroid Build Coastguard Worker * (This name is escaped following standard DNS rules, making it suitable for 1295*5e7646d2SAndroid Build Coastguard Worker * passing to standard system DNS APIs such as res_query(), or to the 1296*5e7646d2SAndroid Build Coastguard Worker * special-purpose functions included in this API that take fullname parameters. 1297*5e7646d2SAndroid Build Coastguard Worker * See "Notes on DNS Name Escaping" earlier in this file for more details.) 1298*5e7646d2SAndroid Build Coastguard Worker * 1299*5e7646d2SAndroid Build Coastguard Worker * hosttarget: The target hostname of the machine providing the service. This name can 1300*5e7646d2SAndroid Build Coastguard Worker * be passed to functions like gethostbyname() to identify the host's IP address. 1301*5e7646d2SAndroid Build Coastguard Worker * 1302*5e7646d2SAndroid Build Coastguard Worker * port: The port, in network byte order, on which connections are accepted for this service. 1303*5e7646d2SAndroid Build Coastguard Worker * 1304*5e7646d2SAndroid Build Coastguard Worker * txtLen: The length of the txt record, in bytes. 1305*5e7646d2SAndroid Build Coastguard Worker * 1306*5e7646d2SAndroid Build Coastguard Worker * txtRecord: The service's primary txt record, in standard txt record format. 1307*5e7646d2SAndroid Build Coastguard Worker * 1308*5e7646d2SAndroid Build Coastguard Worker * context: The context pointer that was passed to the callout. 1309*5e7646d2SAndroid Build Coastguard Worker * 1310*5e7646d2SAndroid Build Coastguard Worker * NOTE: In earlier versions of this header file, the txtRecord parameter was declared "const char *" 1311*5e7646d2SAndroid Build Coastguard Worker * This is incorrect, since it contains length bytes which are values in the range 0 to 255, not -128 to +127. 1312*5e7646d2SAndroid Build Coastguard Worker * Depending on your compiler settings, this change may cause signed/unsigned mismatch warnings. 1313*5e7646d2SAndroid Build Coastguard Worker * These should be fixed by updating your own callback function definition to match the corrected 1314*5e7646d2SAndroid Build Coastguard Worker * function signature using "const unsigned char *txtRecord". Making this change may also fix inadvertent 1315*5e7646d2SAndroid Build Coastguard Worker * bugs in your callback function, where it could have incorrectly interpreted a length byte with value 250 1316*5e7646d2SAndroid Build Coastguard Worker * as being -6 instead, with various bad consequences ranging from incorrect operation to software crashes. 1317*5e7646d2SAndroid Build Coastguard Worker * If you need to maintain portable code that will compile cleanly with both the old and new versions of 1318*5e7646d2SAndroid Build Coastguard Worker * this header file, you should update your callback function definition to use the correct unsigned value, 1319*5e7646d2SAndroid Build Coastguard Worker * and then in the place where you pass your callback function to DNSServiceResolve(), use a cast to eliminate 1320*5e7646d2SAndroid Build Coastguard Worker * the compiler warning, e.g.: 1321*5e7646d2SAndroid Build Coastguard Worker * DNSServiceResolve(sd, flags, index, name, regtype, domain, (DNSServiceResolveReply)MyCallback, context); 1322*5e7646d2SAndroid Build Coastguard Worker * This will ensure that your code compiles cleanly without warnings (and more importantly, works correctly) 1323*5e7646d2SAndroid Build Coastguard Worker * with both the old header and with the new corrected version. 1324*5e7646d2SAndroid Build Coastguard Worker * 1325*5e7646d2SAndroid Build Coastguard Worker */ 1326*5e7646d2SAndroid Build Coastguard Worker 1327*5e7646d2SAndroid Build Coastguard Worker typedef void (DNSSD_API *DNSServiceResolveReply) 1328*5e7646d2SAndroid Build Coastguard Worker ( 1329*5e7646d2SAndroid Build Coastguard Worker DNSServiceRef sdRef, 1330*5e7646d2SAndroid Build Coastguard Worker DNSServiceFlags flags, 1331*5e7646d2SAndroid Build Coastguard Worker uint32_t interfaceIndex, 1332*5e7646d2SAndroid Build Coastguard Worker DNSServiceErrorType errorCode, 1333*5e7646d2SAndroid Build Coastguard Worker const char *fullname, 1334*5e7646d2SAndroid Build Coastguard Worker const char *hosttarget, 1335*5e7646d2SAndroid Build Coastguard Worker uint16_t port, /* In network byte order */ 1336*5e7646d2SAndroid Build Coastguard Worker uint16_t txtLen, 1337*5e7646d2SAndroid Build Coastguard Worker const unsigned char *txtRecord, 1338*5e7646d2SAndroid Build Coastguard Worker void *context 1339*5e7646d2SAndroid Build Coastguard Worker ); 1340*5e7646d2SAndroid Build Coastguard Worker 1341*5e7646d2SAndroid Build Coastguard Worker 1342*5e7646d2SAndroid Build Coastguard Worker /* DNSServiceResolve() Parameters 1343*5e7646d2SAndroid Build Coastguard Worker * 1344*5e7646d2SAndroid Build Coastguard Worker * sdRef: A pointer to an uninitialized DNSServiceRef. If the call succeeds 1345*5e7646d2SAndroid Build Coastguard Worker * then it initializes the DNSServiceRef, returns kDNSServiceErr_NoError, 1346*5e7646d2SAndroid Build Coastguard Worker * and the resolve operation will run indefinitely until the client 1347*5e7646d2SAndroid Build Coastguard Worker * terminates it by passing this DNSServiceRef to DNSServiceRefDeallocate(). 1348*5e7646d2SAndroid Build Coastguard Worker * 1349*5e7646d2SAndroid Build Coastguard Worker * flags: Specifying kDNSServiceFlagsForceMulticast will cause query to be 1350*5e7646d2SAndroid Build Coastguard Worker * performed with a link-local mDNS query, even if the name is an 1351*5e7646d2SAndroid Build Coastguard Worker * apparently non-local name (i.e. a name not ending in ".local.") 1352*5e7646d2SAndroid Build Coastguard Worker * 1353*5e7646d2SAndroid Build Coastguard Worker * interfaceIndex: The interface on which to resolve the service. If this resolve call is 1354*5e7646d2SAndroid Build Coastguard Worker * as a result of a currently active DNSServiceBrowse() operation, then the 1355*5e7646d2SAndroid Build Coastguard Worker * interfaceIndex should be the index reported in the DNSServiceBrowseReply 1356*5e7646d2SAndroid Build Coastguard Worker * callback. If this resolve call is using information previously saved 1357*5e7646d2SAndroid Build Coastguard Worker * (e.g. in a preference file) for later use, then use interfaceIndex 0, because 1358*5e7646d2SAndroid Build Coastguard Worker * the desired service may now be reachable via a different physical interface. 1359*5e7646d2SAndroid Build Coastguard Worker * See "Constants for specifying an interface index" for more details. 1360*5e7646d2SAndroid Build Coastguard Worker * 1361*5e7646d2SAndroid Build Coastguard Worker * name: The name of the service instance to be resolved, as reported to the 1362*5e7646d2SAndroid Build Coastguard Worker * DNSServiceBrowseReply() callback. 1363*5e7646d2SAndroid Build Coastguard Worker * 1364*5e7646d2SAndroid Build Coastguard Worker * regtype: The type of the service instance to be resolved, as reported to the 1365*5e7646d2SAndroid Build Coastguard Worker * DNSServiceBrowseReply() callback. 1366*5e7646d2SAndroid Build Coastguard Worker * 1367*5e7646d2SAndroid Build Coastguard Worker * domain: The domain of the service instance to be resolved, as reported to the 1368*5e7646d2SAndroid Build Coastguard Worker * DNSServiceBrowseReply() callback. 1369*5e7646d2SAndroid Build Coastguard Worker * 1370*5e7646d2SAndroid Build Coastguard Worker * callBack: The function to be called when a result is found, or if the call 1371*5e7646d2SAndroid Build Coastguard Worker * asynchronously fails. 1372*5e7646d2SAndroid Build Coastguard Worker * 1373*5e7646d2SAndroid Build Coastguard Worker * context: An application context pointer which is passed to the callback function 1374*5e7646d2SAndroid Build Coastguard Worker * (may be NULL). 1375*5e7646d2SAndroid Build Coastguard Worker * 1376*5e7646d2SAndroid Build Coastguard Worker * return value: Returns kDNSServiceErr_NoError on success (any subsequent, asynchronous 1377*5e7646d2SAndroid Build Coastguard Worker * errors are delivered to the callback), otherwise returns an error code indicating 1378*5e7646d2SAndroid Build Coastguard Worker * the error that occurred (the callback is never invoked and the DNSServiceRef 1379*5e7646d2SAndroid Build Coastguard Worker * is not initialized). 1380*5e7646d2SAndroid Build Coastguard Worker */ 1381*5e7646d2SAndroid Build Coastguard Worker 1382*5e7646d2SAndroid Build Coastguard Worker DNSServiceErrorType DNSSD_API DNSServiceResolve 1383*5e7646d2SAndroid Build Coastguard Worker ( 1384*5e7646d2SAndroid Build Coastguard Worker DNSServiceRef *sdRef, 1385*5e7646d2SAndroid Build Coastguard Worker DNSServiceFlags flags, 1386*5e7646d2SAndroid Build Coastguard Worker uint32_t interfaceIndex, 1387*5e7646d2SAndroid Build Coastguard Worker const char *name, 1388*5e7646d2SAndroid Build Coastguard Worker const char *regtype, 1389*5e7646d2SAndroid Build Coastguard Worker const char *domain, 1390*5e7646d2SAndroid Build Coastguard Worker DNSServiceResolveReply callBack, 1391*5e7646d2SAndroid Build Coastguard Worker void *context /* may be NULL */ 1392*5e7646d2SAndroid Build Coastguard Worker ); 1393*5e7646d2SAndroid Build Coastguard Worker 1394*5e7646d2SAndroid Build Coastguard Worker 1395*5e7646d2SAndroid Build Coastguard Worker /********************************************************************************************* 1396*5e7646d2SAndroid Build Coastguard Worker * 1397*5e7646d2SAndroid Build Coastguard Worker * Querying Individual Specific Records 1398*5e7646d2SAndroid Build Coastguard Worker * 1399*5e7646d2SAndroid Build Coastguard Worker *********************************************************************************************/ 1400*5e7646d2SAndroid Build Coastguard Worker 1401*5e7646d2SAndroid Build Coastguard Worker /* DNSServiceQueryRecord 1402*5e7646d2SAndroid Build Coastguard Worker * 1403*5e7646d2SAndroid Build Coastguard Worker * Query for an arbitrary DNS record. 1404*5e7646d2SAndroid Build Coastguard Worker * 1405*5e7646d2SAndroid Build Coastguard Worker * DNSServiceQueryRecordReply() Callback Parameters: 1406*5e7646d2SAndroid Build Coastguard Worker * 1407*5e7646d2SAndroid Build Coastguard Worker * sdRef: The DNSServiceRef initialized by DNSServiceQueryRecord(). 1408*5e7646d2SAndroid Build Coastguard Worker * 1409*5e7646d2SAndroid Build Coastguard Worker * flags: Possible values are kDNSServiceFlagsMoreComing and 1410*5e7646d2SAndroid Build Coastguard Worker * kDNSServiceFlagsAdd. The Add flag is NOT set for PTR records 1411*5e7646d2SAndroid Build Coastguard Worker * with a ttl of 0, i.e. "Remove" events. 1412*5e7646d2SAndroid Build Coastguard Worker * 1413*5e7646d2SAndroid Build Coastguard Worker * interfaceIndex: The interface on which the query was resolved (the index for a given 1414*5e7646d2SAndroid Build Coastguard Worker * interface is determined via the if_nametoindex() family of calls). 1415*5e7646d2SAndroid Build Coastguard Worker * See "Constants for specifying an interface index" for more details. 1416*5e7646d2SAndroid Build Coastguard Worker * 1417*5e7646d2SAndroid Build Coastguard Worker * errorCode: Will be kDNSServiceErr_NoError on success, otherwise will 1418*5e7646d2SAndroid Build Coastguard Worker * indicate the failure that occurred. Other parameters are undefined if 1419*5e7646d2SAndroid Build Coastguard Worker * errorCode is nonzero. 1420*5e7646d2SAndroid Build Coastguard Worker * 1421*5e7646d2SAndroid Build Coastguard Worker * fullname: The resource record's full domain name. 1422*5e7646d2SAndroid Build Coastguard Worker * 1423*5e7646d2SAndroid Build Coastguard Worker * rrtype: The resource record's type (e.g. kDNSServiceType_PTR, kDNSServiceType_SRV, etc) 1424*5e7646d2SAndroid Build Coastguard Worker * 1425*5e7646d2SAndroid Build Coastguard Worker * rrclass: The class of the resource record (usually kDNSServiceClass_IN). 1426*5e7646d2SAndroid Build Coastguard Worker * 1427*5e7646d2SAndroid Build Coastguard Worker * rdlen: The length, in bytes, of the resource record rdata. 1428*5e7646d2SAndroid Build Coastguard Worker * 1429*5e7646d2SAndroid Build Coastguard Worker * rdata: The raw rdata of the resource record. 1430*5e7646d2SAndroid Build Coastguard Worker * 1431*5e7646d2SAndroid Build Coastguard Worker * ttl: If the client wishes to cache the result for performance reasons, 1432*5e7646d2SAndroid Build Coastguard Worker * the TTL indicates how long the client may legitimately hold onto 1433*5e7646d2SAndroid Build Coastguard Worker * this result, in seconds. After the TTL expires, the client should 1434*5e7646d2SAndroid Build Coastguard Worker * consider the result no longer valid, and if it requires this data 1435*5e7646d2SAndroid Build Coastguard Worker * again, it should be re-fetched with a new query. Of course, this 1436*5e7646d2SAndroid Build Coastguard Worker * only applies to clients that cancel the asynchronous operation when 1437*5e7646d2SAndroid Build Coastguard Worker * they get a result. Clients that leave the asynchronous operation 1438*5e7646d2SAndroid Build Coastguard Worker * running can safely assume that the data remains valid until they 1439*5e7646d2SAndroid Build Coastguard Worker * get another callback telling them otherwise. 1440*5e7646d2SAndroid Build Coastguard Worker * 1441*5e7646d2SAndroid Build Coastguard Worker * context: The context pointer that was passed to the callout. 1442*5e7646d2SAndroid Build Coastguard Worker * 1443*5e7646d2SAndroid Build Coastguard Worker */ 1444*5e7646d2SAndroid Build Coastguard Worker 1445*5e7646d2SAndroid Build Coastguard Worker typedef void (DNSSD_API *DNSServiceQueryRecordReply) 1446*5e7646d2SAndroid Build Coastguard Worker ( 1447*5e7646d2SAndroid Build Coastguard Worker DNSServiceRef sdRef, 1448*5e7646d2SAndroid Build Coastguard Worker DNSServiceFlags flags, 1449*5e7646d2SAndroid Build Coastguard Worker uint32_t interfaceIndex, 1450*5e7646d2SAndroid Build Coastguard Worker DNSServiceErrorType errorCode, 1451*5e7646d2SAndroid Build Coastguard Worker const char *fullname, 1452*5e7646d2SAndroid Build Coastguard Worker uint16_t rrtype, 1453*5e7646d2SAndroid Build Coastguard Worker uint16_t rrclass, 1454*5e7646d2SAndroid Build Coastguard Worker uint16_t rdlen, 1455*5e7646d2SAndroid Build Coastguard Worker const void *rdata, 1456*5e7646d2SAndroid Build Coastguard Worker uint32_t ttl, 1457*5e7646d2SAndroid Build Coastguard Worker void *context 1458*5e7646d2SAndroid Build Coastguard Worker ); 1459*5e7646d2SAndroid Build Coastguard Worker 1460*5e7646d2SAndroid Build Coastguard Worker 1461*5e7646d2SAndroid Build Coastguard Worker /* DNSServiceQueryRecord() Parameters: 1462*5e7646d2SAndroid Build Coastguard Worker * 1463*5e7646d2SAndroid Build Coastguard Worker * sdRef: A pointer to an uninitialized DNSServiceRef. If the call succeeds 1464*5e7646d2SAndroid Build Coastguard Worker * then it initializes the DNSServiceRef, returns kDNSServiceErr_NoError, 1465*5e7646d2SAndroid Build Coastguard Worker * and the query operation will run indefinitely until the client 1466*5e7646d2SAndroid Build Coastguard Worker * terminates it by passing this DNSServiceRef to DNSServiceRefDeallocate(). 1467*5e7646d2SAndroid Build Coastguard Worker * 1468*5e7646d2SAndroid Build Coastguard Worker * flags: kDNSServiceFlagsForceMulticast or kDNSServiceFlagsLongLivedQuery. 1469*5e7646d2SAndroid Build Coastguard Worker * Pass kDNSServiceFlagsLongLivedQuery to create a "long-lived" unicast 1470*5e7646d2SAndroid Build Coastguard Worker * query in a non-local domain. Without setting this flag, unicast queries 1471*5e7646d2SAndroid Build Coastguard Worker * will be one-shot - that is, only answers available at the time of the call 1472*5e7646d2SAndroid Build Coastguard Worker * will be returned. By setting this flag, answers (including Add and Remove 1473*5e7646d2SAndroid Build Coastguard Worker * events) that become available after the initial call is made will generate 1474*5e7646d2SAndroid Build Coastguard Worker * callbacks. This flag has no effect on link-local multicast queries. 1475*5e7646d2SAndroid Build Coastguard Worker * 1476*5e7646d2SAndroid Build Coastguard Worker * interfaceIndex: If non-zero, specifies the interface on which to issue the query 1477*5e7646d2SAndroid Build Coastguard Worker * (the index for a given interface is determined via the if_nametoindex() 1478*5e7646d2SAndroid Build Coastguard Worker * family of calls.) Passing 0 causes the name to be queried for on all 1479*5e7646d2SAndroid Build Coastguard Worker * interfaces. See "Constants for specifying an interface index" for more details. 1480*5e7646d2SAndroid Build Coastguard Worker * 1481*5e7646d2SAndroid Build Coastguard Worker * fullname: The full domain name of the resource record to be queried for. 1482*5e7646d2SAndroid Build Coastguard Worker * 1483*5e7646d2SAndroid Build Coastguard Worker * rrtype: The numerical type of the resource record to be queried for 1484*5e7646d2SAndroid Build Coastguard Worker * (e.g. kDNSServiceType_PTR, kDNSServiceType_SRV, etc) 1485*5e7646d2SAndroid Build Coastguard Worker * 1486*5e7646d2SAndroid Build Coastguard Worker * rrclass: The class of the resource record (usually kDNSServiceClass_IN). 1487*5e7646d2SAndroid Build Coastguard Worker * 1488*5e7646d2SAndroid Build Coastguard Worker * callBack: The function to be called when a result is found, or if the call 1489*5e7646d2SAndroid Build Coastguard Worker * asynchronously fails. 1490*5e7646d2SAndroid Build Coastguard Worker * 1491*5e7646d2SAndroid Build Coastguard Worker * context: An application context pointer which is passed to the callback function 1492*5e7646d2SAndroid Build Coastguard Worker * (may be NULL). 1493*5e7646d2SAndroid Build Coastguard Worker * 1494*5e7646d2SAndroid Build Coastguard Worker * return value: Returns kDNSServiceErr_NoError on success (any subsequent, asynchronous 1495*5e7646d2SAndroid Build Coastguard Worker * errors are delivered to the callback), otherwise returns an error code indicating 1496*5e7646d2SAndroid Build Coastguard Worker * the error that occurred (the callback is never invoked and the DNSServiceRef 1497*5e7646d2SAndroid Build Coastguard Worker * is not initialized). 1498*5e7646d2SAndroid Build Coastguard Worker */ 1499*5e7646d2SAndroid Build Coastguard Worker 1500*5e7646d2SAndroid Build Coastguard Worker DNSServiceErrorType DNSSD_API DNSServiceQueryRecord 1501*5e7646d2SAndroid Build Coastguard Worker ( 1502*5e7646d2SAndroid Build Coastguard Worker DNSServiceRef *sdRef, 1503*5e7646d2SAndroid Build Coastguard Worker DNSServiceFlags flags, 1504*5e7646d2SAndroid Build Coastguard Worker uint32_t interfaceIndex, 1505*5e7646d2SAndroid Build Coastguard Worker const char *fullname, 1506*5e7646d2SAndroid Build Coastguard Worker uint16_t rrtype, 1507*5e7646d2SAndroid Build Coastguard Worker uint16_t rrclass, 1508*5e7646d2SAndroid Build Coastguard Worker DNSServiceQueryRecordReply callBack, 1509*5e7646d2SAndroid Build Coastguard Worker void *context /* may be NULL */ 1510*5e7646d2SAndroid Build Coastguard Worker ); 1511*5e7646d2SAndroid Build Coastguard Worker 1512*5e7646d2SAndroid Build Coastguard Worker 1513*5e7646d2SAndroid Build Coastguard Worker /********************************************************************************************* 1514*5e7646d2SAndroid Build Coastguard Worker * 1515*5e7646d2SAndroid Build Coastguard Worker * Unified lookup of both IPv4 and IPv6 addresses for a fully qualified hostname 1516*5e7646d2SAndroid Build Coastguard Worker * 1517*5e7646d2SAndroid Build Coastguard Worker *********************************************************************************************/ 1518*5e7646d2SAndroid Build Coastguard Worker 1519*5e7646d2SAndroid Build Coastguard Worker /* DNSServiceGetAddrInfo 1520*5e7646d2SAndroid Build Coastguard Worker * 1521*5e7646d2SAndroid Build Coastguard Worker * Queries for the IP address of a hostname by using either Multicast or Unicast DNS. 1522*5e7646d2SAndroid Build Coastguard Worker * 1523*5e7646d2SAndroid Build Coastguard Worker * DNSServiceGetAddrInfoReply() parameters: 1524*5e7646d2SAndroid Build Coastguard Worker * 1525*5e7646d2SAndroid Build Coastguard Worker * sdRef: The DNSServiceRef initialized by DNSServiceGetAddrInfo(). 1526*5e7646d2SAndroid Build Coastguard Worker * 1527*5e7646d2SAndroid Build Coastguard Worker * flags: Possible values are kDNSServiceFlagsMoreComing and 1528*5e7646d2SAndroid Build Coastguard Worker * kDNSServiceFlagsAdd. 1529*5e7646d2SAndroid Build Coastguard Worker * 1530*5e7646d2SAndroid Build Coastguard Worker * interfaceIndex: The interface to which the answers pertain. 1531*5e7646d2SAndroid Build Coastguard Worker * 1532*5e7646d2SAndroid Build Coastguard Worker * errorCode: Will be kDNSServiceErr_NoError on success, otherwise will 1533*5e7646d2SAndroid Build Coastguard Worker * indicate the failure that occurred. Other parameters are 1534*5e7646d2SAndroid Build Coastguard Worker * undefined if errorCode is nonzero. 1535*5e7646d2SAndroid Build Coastguard Worker * 1536*5e7646d2SAndroid Build Coastguard Worker * hostname: The fully qualified domain name of the host to be queried for. 1537*5e7646d2SAndroid Build Coastguard Worker * 1538*5e7646d2SAndroid Build Coastguard Worker * address: IPv4 or IPv6 address. 1539*5e7646d2SAndroid Build Coastguard Worker * 1540*5e7646d2SAndroid Build Coastguard Worker * ttl: If the client wishes to cache the result for performance reasons, 1541*5e7646d2SAndroid Build Coastguard Worker * the TTL indicates how long the client may legitimately hold onto 1542*5e7646d2SAndroid Build Coastguard Worker * this result, in seconds. After the TTL expires, the client should 1543*5e7646d2SAndroid Build Coastguard Worker * consider the result no longer valid, and if it requires this data 1544*5e7646d2SAndroid Build Coastguard Worker * again, it should be re-fetched with a new query. Of course, this 1545*5e7646d2SAndroid Build Coastguard Worker * only applies to clients that cancel the asynchronous operation when 1546*5e7646d2SAndroid Build Coastguard Worker * they get a result. Clients that leave the asynchronous operation 1547*5e7646d2SAndroid Build Coastguard Worker * running can safely assume that the data remains valid until they 1548*5e7646d2SAndroid Build Coastguard Worker * get another callback telling them otherwise. 1549*5e7646d2SAndroid Build Coastguard Worker * 1550*5e7646d2SAndroid Build Coastguard Worker * context: The context pointer that was passed to the callout. 1551*5e7646d2SAndroid Build Coastguard Worker * 1552*5e7646d2SAndroid Build Coastguard Worker */ 1553*5e7646d2SAndroid Build Coastguard Worker 1554*5e7646d2SAndroid Build Coastguard Worker typedef void (DNSSD_API *DNSServiceGetAddrInfoReply) 1555*5e7646d2SAndroid Build Coastguard Worker ( 1556*5e7646d2SAndroid Build Coastguard Worker DNSServiceRef sdRef, 1557*5e7646d2SAndroid Build Coastguard Worker DNSServiceFlags flags, 1558*5e7646d2SAndroid Build Coastguard Worker uint32_t interfaceIndex, 1559*5e7646d2SAndroid Build Coastguard Worker DNSServiceErrorType errorCode, 1560*5e7646d2SAndroid Build Coastguard Worker const char *hostname, 1561*5e7646d2SAndroid Build Coastguard Worker const struct sockaddr *address, 1562*5e7646d2SAndroid Build Coastguard Worker uint32_t ttl, 1563*5e7646d2SAndroid Build Coastguard Worker void *context 1564*5e7646d2SAndroid Build Coastguard Worker ); 1565*5e7646d2SAndroid Build Coastguard Worker 1566*5e7646d2SAndroid Build Coastguard Worker 1567*5e7646d2SAndroid Build Coastguard Worker /* DNSServiceGetAddrInfo() Parameters: 1568*5e7646d2SAndroid Build Coastguard Worker * 1569*5e7646d2SAndroid Build Coastguard Worker * sdRef: A pointer to an uninitialized DNSServiceRef. If the call succeeds then it 1570*5e7646d2SAndroid Build Coastguard Worker * initializes the DNSServiceRef, returns kDNSServiceErr_NoError, and the query 1571*5e7646d2SAndroid Build Coastguard Worker * begins and will last indefinitely until the client terminates the query 1572*5e7646d2SAndroid Build Coastguard Worker * by passing this DNSServiceRef to DNSServiceRefDeallocate(). 1573*5e7646d2SAndroid Build Coastguard Worker * 1574*5e7646d2SAndroid Build Coastguard Worker * flags: kDNSServiceFlagsForceMulticast or kDNSServiceFlagsLongLivedQuery. 1575*5e7646d2SAndroid Build Coastguard Worker * Pass kDNSServiceFlagsLongLivedQuery to create a "long-lived" unicast 1576*5e7646d2SAndroid Build Coastguard Worker * query in a non-local domain. Without setting this flag, unicast queries 1577*5e7646d2SAndroid Build Coastguard Worker * will be one-shot - that is, only answers available at the time of the call 1578*5e7646d2SAndroid Build Coastguard Worker * will be returned. By setting this flag, answers (including Add and Remove 1579*5e7646d2SAndroid Build Coastguard Worker * events) that become available after the initial call is made will generate 1580*5e7646d2SAndroid Build Coastguard Worker * callbacks. This flag has no effect on link-local multicast queries. 1581*5e7646d2SAndroid Build Coastguard Worker * 1582*5e7646d2SAndroid Build Coastguard Worker * interfaceIndex: The interface on which to issue the query. Passing 0 causes the query to be 1583*5e7646d2SAndroid Build Coastguard Worker * sent on all active interfaces via Multicast or the primary interface via Unicast. 1584*5e7646d2SAndroid Build Coastguard Worker * 1585*5e7646d2SAndroid Build Coastguard Worker * protocol: Pass in kDNSServiceProtocol_IPv4 to look up IPv4 addresses, or kDNSServiceProtocol_IPv6 1586*5e7646d2SAndroid Build Coastguard Worker * to look up IPv6 addresses, or both to look up both kinds. If neither flag is 1587*5e7646d2SAndroid Build Coastguard Worker * set, the system will apply an intelligent heuristic, which is (currently) 1588*5e7646d2SAndroid Build Coastguard Worker * that it will attempt to look up both, except: 1589*5e7646d2SAndroid Build Coastguard Worker * 1590*5e7646d2SAndroid Build Coastguard Worker * * If "hostname" is a wide-area unicast DNS hostname (i.e. not a ".local." name) 1591*5e7646d2SAndroid Build Coastguard Worker * but this host has no routable IPv6 address, then the call will not try to 1592*5e7646d2SAndroid Build Coastguard Worker * look up IPv6 addresses for "hostname", since any addresses it found would be 1593*5e7646d2SAndroid Build Coastguard Worker * unlikely to be of any use anyway. Similarly, if this host has no routable 1594*5e7646d2SAndroid Build Coastguard Worker * IPv4 address, the call will not try to look up IPv4 addresses for "hostname". 1595*5e7646d2SAndroid Build Coastguard Worker * 1596*5e7646d2SAndroid Build Coastguard Worker * hostname: The fully qualified domain name of the host to be queried for. 1597*5e7646d2SAndroid Build Coastguard Worker * 1598*5e7646d2SAndroid Build Coastguard Worker * callBack: The function to be called when the query succeeds or fails asynchronously. 1599*5e7646d2SAndroid Build Coastguard Worker * 1600*5e7646d2SAndroid Build Coastguard Worker * context: An application context pointer which is passed to the callback function 1601*5e7646d2SAndroid Build Coastguard Worker * (may be NULL). 1602*5e7646d2SAndroid Build Coastguard Worker * 1603*5e7646d2SAndroid Build Coastguard Worker * return value: Returns kDNSServiceErr_NoError on success (any subsequent, asynchronous 1604*5e7646d2SAndroid Build Coastguard Worker * errors are delivered to the callback), otherwise returns an error code indicating 1605*5e7646d2SAndroid Build Coastguard Worker * the error that occurred. 1606*5e7646d2SAndroid Build Coastguard Worker */ 1607*5e7646d2SAndroid Build Coastguard Worker 1608*5e7646d2SAndroid Build Coastguard Worker DNSServiceErrorType DNSSD_API DNSServiceGetAddrInfo 1609*5e7646d2SAndroid Build Coastguard Worker ( 1610*5e7646d2SAndroid Build Coastguard Worker DNSServiceRef *sdRef, 1611*5e7646d2SAndroid Build Coastguard Worker DNSServiceFlags flags, 1612*5e7646d2SAndroid Build Coastguard Worker uint32_t interfaceIndex, 1613*5e7646d2SAndroid Build Coastguard Worker DNSServiceProtocol protocol, 1614*5e7646d2SAndroid Build Coastguard Worker const char *hostname, 1615*5e7646d2SAndroid Build Coastguard Worker DNSServiceGetAddrInfoReply callBack, 1616*5e7646d2SAndroid Build Coastguard Worker void *context /* may be NULL */ 1617*5e7646d2SAndroid Build Coastguard Worker ); 1618*5e7646d2SAndroid Build Coastguard Worker 1619*5e7646d2SAndroid Build Coastguard Worker 1620*5e7646d2SAndroid Build Coastguard Worker /********************************************************************************************* 1621*5e7646d2SAndroid Build Coastguard Worker * 1622*5e7646d2SAndroid Build Coastguard Worker * Special Purpose Calls: 1623*5e7646d2SAndroid Build Coastguard Worker * DNSServiceCreateConnection(), DNSServiceRegisterRecord(), DNSServiceReconfirmRecord() 1624*5e7646d2SAndroid Build Coastguard Worker * (most applications will not use these) 1625*5e7646d2SAndroid Build Coastguard Worker * 1626*5e7646d2SAndroid Build Coastguard Worker *********************************************************************************************/ 1627*5e7646d2SAndroid Build Coastguard Worker 1628*5e7646d2SAndroid Build Coastguard Worker /* DNSServiceCreateConnection() 1629*5e7646d2SAndroid Build Coastguard Worker * 1630*5e7646d2SAndroid Build Coastguard Worker * Create a connection to the daemon allowing efficient registration of 1631*5e7646d2SAndroid Build Coastguard Worker * multiple individual records. 1632*5e7646d2SAndroid Build Coastguard Worker * 1633*5e7646d2SAndroid Build Coastguard Worker * Parameters: 1634*5e7646d2SAndroid Build Coastguard Worker * 1635*5e7646d2SAndroid Build Coastguard Worker * sdRef: A pointer to an uninitialized DNSServiceRef. Deallocating 1636*5e7646d2SAndroid Build Coastguard Worker * the reference (via DNSServiceRefDeallocate()) severs the 1637*5e7646d2SAndroid Build Coastguard Worker * connection and deregisters all records registered on this connection. 1638*5e7646d2SAndroid Build Coastguard Worker * 1639*5e7646d2SAndroid Build Coastguard Worker * return value: Returns kDNSServiceErr_NoError on success, otherwise returns 1640*5e7646d2SAndroid Build Coastguard Worker * an error code indicating the specific failure that occurred (in which 1641*5e7646d2SAndroid Build Coastguard Worker * case the DNSServiceRef is not initialized). 1642*5e7646d2SAndroid Build Coastguard Worker */ 1643*5e7646d2SAndroid Build Coastguard Worker 1644*5e7646d2SAndroid Build Coastguard Worker DNSServiceErrorType DNSSD_API DNSServiceCreateConnection(DNSServiceRef *sdRef); 1645*5e7646d2SAndroid Build Coastguard Worker 1646*5e7646d2SAndroid Build Coastguard Worker 1647*5e7646d2SAndroid Build Coastguard Worker /* DNSServiceRegisterRecord 1648*5e7646d2SAndroid Build Coastguard Worker * 1649*5e7646d2SAndroid Build Coastguard Worker * Register an individual resource record on a connected DNSServiceRef. 1650*5e7646d2SAndroid Build Coastguard Worker * 1651*5e7646d2SAndroid Build Coastguard Worker * Note that name conflicts occurring for records registered via this call must be handled 1652*5e7646d2SAndroid Build Coastguard Worker * by the client in the callback. 1653*5e7646d2SAndroid Build Coastguard Worker * 1654*5e7646d2SAndroid Build Coastguard Worker * DNSServiceRegisterRecordReply() parameters: 1655*5e7646d2SAndroid Build Coastguard Worker * 1656*5e7646d2SAndroid Build Coastguard Worker * sdRef: The connected DNSServiceRef initialized by 1657*5e7646d2SAndroid Build Coastguard Worker * DNSServiceCreateConnection(). 1658*5e7646d2SAndroid Build Coastguard Worker * 1659*5e7646d2SAndroid Build Coastguard Worker * RecordRef: The DNSRecordRef initialized by DNSServiceRegisterRecord(). If the above 1660*5e7646d2SAndroid Build Coastguard Worker * DNSServiceRef is passed to DNSServiceRefDeallocate(), this DNSRecordRef is 1661*5e7646d2SAndroid Build Coastguard Worker * invalidated, and may not be used further. 1662*5e7646d2SAndroid Build Coastguard Worker * 1663*5e7646d2SAndroid Build Coastguard Worker * flags: Currently unused, reserved for future use. 1664*5e7646d2SAndroid Build Coastguard Worker * 1665*5e7646d2SAndroid Build Coastguard Worker * errorCode: Will be kDNSServiceErr_NoError on success, otherwise will 1666*5e7646d2SAndroid Build Coastguard Worker * indicate the failure that occurred (including name conflicts.) 1667*5e7646d2SAndroid Build Coastguard Worker * Other parameters are undefined if errorCode is nonzero. 1668*5e7646d2SAndroid Build Coastguard Worker * 1669*5e7646d2SAndroid Build Coastguard Worker * context: The context pointer that was passed to the callout. 1670*5e7646d2SAndroid Build Coastguard Worker * 1671*5e7646d2SAndroid Build Coastguard Worker */ 1672*5e7646d2SAndroid Build Coastguard Worker 1673*5e7646d2SAndroid Build Coastguard Worker typedef void (DNSSD_API *DNSServiceRegisterRecordReply) 1674*5e7646d2SAndroid Build Coastguard Worker ( 1675*5e7646d2SAndroid Build Coastguard Worker DNSServiceRef sdRef, 1676*5e7646d2SAndroid Build Coastguard Worker DNSRecordRef RecordRef, 1677*5e7646d2SAndroid Build Coastguard Worker DNSServiceFlags flags, 1678*5e7646d2SAndroid Build Coastguard Worker DNSServiceErrorType errorCode, 1679*5e7646d2SAndroid Build Coastguard Worker void *context 1680*5e7646d2SAndroid Build Coastguard Worker ); 1681*5e7646d2SAndroid Build Coastguard Worker 1682*5e7646d2SAndroid Build Coastguard Worker 1683*5e7646d2SAndroid Build Coastguard Worker /* DNSServiceRegisterRecord() Parameters: 1684*5e7646d2SAndroid Build Coastguard Worker * 1685*5e7646d2SAndroid Build Coastguard Worker * sdRef: A DNSServiceRef initialized by DNSServiceCreateConnection(). 1686*5e7646d2SAndroid Build Coastguard Worker * 1687*5e7646d2SAndroid Build Coastguard Worker * RecordRef: A pointer to an uninitialized DNSRecordRef. Upon succesfull completion of this 1688*5e7646d2SAndroid Build Coastguard Worker * call, this ref may be passed to DNSServiceUpdateRecord() or DNSServiceRemoveRecord(). 1689*5e7646d2SAndroid Build Coastguard Worker * (To deregister ALL records registered on a single connected DNSServiceRef 1690*5e7646d2SAndroid Build Coastguard Worker * and deallocate each of their corresponding DNSServiceRecordRefs, call 1691*5e7646d2SAndroid Build Coastguard Worker * DNSServiceRefDeallocate()). 1692*5e7646d2SAndroid Build Coastguard Worker * 1693*5e7646d2SAndroid Build Coastguard Worker * flags: Possible values are kDNSServiceFlagsShared or kDNSServiceFlagsUnique 1694*5e7646d2SAndroid Build Coastguard Worker * (see flag type definitions for details). 1695*5e7646d2SAndroid Build Coastguard Worker * 1696*5e7646d2SAndroid Build Coastguard Worker * interfaceIndex: If non-zero, specifies the interface on which to register the record 1697*5e7646d2SAndroid Build Coastguard Worker * (the index for a given interface is determined via the if_nametoindex() 1698*5e7646d2SAndroid Build Coastguard Worker * family of calls.) Passing 0 causes the record to be registered on all interfaces. 1699*5e7646d2SAndroid Build Coastguard Worker * See "Constants for specifying an interface index" for more details. 1700*5e7646d2SAndroid Build Coastguard Worker * 1701*5e7646d2SAndroid Build Coastguard Worker * fullname: The full domain name of the resource record. 1702*5e7646d2SAndroid Build Coastguard Worker * 1703*5e7646d2SAndroid Build Coastguard Worker * rrtype: The numerical type of the resource record (e.g. kDNSServiceType_PTR, kDNSServiceType_SRV, etc) 1704*5e7646d2SAndroid Build Coastguard Worker * 1705*5e7646d2SAndroid Build Coastguard Worker * rrclass: The class of the resource record (usually kDNSServiceClass_IN) 1706*5e7646d2SAndroid Build Coastguard Worker * 1707*5e7646d2SAndroid Build Coastguard Worker * rdlen: Length, in bytes, of the rdata. 1708*5e7646d2SAndroid Build Coastguard Worker * 1709*5e7646d2SAndroid Build Coastguard Worker * rdata: A pointer to the raw rdata, as it is to appear in the DNS record. 1710*5e7646d2SAndroid Build Coastguard Worker * 1711*5e7646d2SAndroid Build Coastguard Worker * ttl: The time to live of the resource record, in seconds. 1712*5e7646d2SAndroid Build Coastguard Worker * Most clients should pass 0 to indicate that the system should 1713*5e7646d2SAndroid Build Coastguard Worker * select a sensible default value. 1714*5e7646d2SAndroid Build Coastguard Worker * 1715*5e7646d2SAndroid Build Coastguard Worker * callBack: The function to be called when a result is found, or if the call 1716*5e7646d2SAndroid Build Coastguard Worker * asynchronously fails (e.g. because of a name conflict.) 1717*5e7646d2SAndroid Build Coastguard Worker * 1718*5e7646d2SAndroid Build Coastguard Worker * context: An application context pointer which is passed to the callback function 1719*5e7646d2SAndroid Build Coastguard Worker * (may be NULL). 1720*5e7646d2SAndroid Build Coastguard Worker * 1721*5e7646d2SAndroid Build Coastguard Worker * return value: Returns kDNSServiceErr_NoError on success (any subsequent, asynchronous 1722*5e7646d2SAndroid Build Coastguard Worker * errors are delivered to the callback), otherwise returns an error code indicating 1723*5e7646d2SAndroid Build Coastguard Worker * the error that occurred (the callback is never invoked and the DNSRecordRef is 1724*5e7646d2SAndroid Build Coastguard Worker * not initialized). 1725*5e7646d2SAndroid Build Coastguard Worker */ 1726*5e7646d2SAndroid Build Coastguard Worker 1727*5e7646d2SAndroid Build Coastguard Worker DNSServiceErrorType DNSSD_API DNSServiceRegisterRecord 1728*5e7646d2SAndroid Build Coastguard Worker ( 1729*5e7646d2SAndroid Build Coastguard Worker DNSServiceRef sdRef, 1730*5e7646d2SAndroid Build Coastguard Worker DNSRecordRef *RecordRef, 1731*5e7646d2SAndroid Build Coastguard Worker DNSServiceFlags flags, 1732*5e7646d2SAndroid Build Coastguard Worker uint32_t interfaceIndex, 1733*5e7646d2SAndroid Build Coastguard Worker const char *fullname, 1734*5e7646d2SAndroid Build Coastguard Worker uint16_t rrtype, 1735*5e7646d2SAndroid Build Coastguard Worker uint16_t rrclass, 1736*5e7646d2SAndroid Build Coastguard Worker uint16_t rdlen, 1737*5e7646d2SAndroid Build Coastguard Worker const void *rdata, 1738*5e7646d2SAndroid Build Coastguard Worker uint32_t ttl, 1739*5e7646d2SAndroid Build Coastguard Worker DNSServiceRegisterRecordReply callBack, 1740*5e7646d2SAndroid Build Coastguard Worker void *context /* may be NULL */ 1741*5e7646d2SAndroid Build Coastguard Worker ); 1742*5e7646d2SAndroid Build Coastguard Worker 1743*5e7646d2SAndroid Build Coastguard Worker 1744*5e7646d2SAndroid Build Coastguard Worker /* DNSServiceReconfirmRecord 1745*5e7646d2SAndroid Build Coastguard Worker * 1746*5e7646d2SAndroid Build Coastguard Worker * Instruct the daemon to verify the validity of a resource record that appears 1747*5e7646d2SAndroid Build Coastguard Worker * to be out of date (e.g. because TCP connection to a service's target failed.) 1748*5e7646d2SAndroid Build Coastguard Worker * Causes the record to be flushed from the daemon's cache (as well as all other 1749*5e7646d2SAndroid Build Coastguard Worker * daemons' caches on the network) if the record is determined to be invalid. 1750*5e7646d2SAndroid Build Coastguard Worker * Use this routine conservatively. Reconfirming a record necessarily consumes 1751*5e7646d2SAndroid Build Coastguard Worker * network bandwidth, so this should not be done indiscriminately. 1752*5e7646d2SAndroid Build Coastguard Worker * 1753*5e7646d2SAndroid Build Coastguard Worker * Parameters: 1754*5e7646d2SAndroid Build Coastguard Worker * 1755*5e7646d2SAndroid Build Coastguard Worker * flags: Pass kDNSServiceFlagsForce to force immediate deletion of record, 1756*5e7646d2SAndroid Build Coastguard Worker * instead of after some number of reconfirmation queries have gone unanswered. 1757*5e7646d2SAndroid Build Coastguard Worker * 1758*5e7646d2SAndroid Build Coastguard Worker * interfaceIndex: Specifies the interface of the record in question. 1759*5e7646d2SAndroid Build Coastguard Worker * The caller must specify the interface. 1760*5e7646d2SAndroid Build Coastguard Worker * This API (by design) causes increased network traffic, so it requires 1761*5e7646d2SAndroid Build Coastguard Worker * the caller to be precise about which record should be reconfirmed. 1762*5e7646d2SAndroid Build Coastguard Worker * It is not possible to pass zero for the interface index to perform 1763*5e7646d2SAndroid Build Coastguard Worker * a "wildcard" reconfirmation, where *all* matching records are reconfirmed. 1764*5e7646d2SAndroid Build Coastguard Worker * 1765*5e7646d2SAndroid Build Coastguard Worker * fullname: The resource record's full domain name. 1766*5e7646d2SAndroid Build Coastguard Worker * 1767*5e7646d2SAndroid Build Coastguard Worker * rrtype: The resource record's type (e.g. kDNSServiceType_PTR, kDNSServiceType_SRV, etc) 1768*5e7646d2SAndroid Build Coastguard Worker * 1769*5e7646d2SAndroid Build Coastguard Worker * rrclass: The class of the resource record (usually kDNSServiceClass_IN). 1770*5e7646d2SAndroid Build Coastguard Worker * 1771*5e7646d2SAndroid Build Coastguard Worker * rdlen: The length, in bytes, of the resource record rdata. 1772*5e7646d2SAndroid Build Coastguard Worker * 1773*5e7646d2SAndroid Build Coastguard Worker * rdata: The raw rdata of the resource record. 1774*5e7646d2SAndroid Build Coastguard Worker * 1775*5e7646d2SAndroid Build Coastguard Worker */ 1776*5e7646d2SAndroid Build Coastguard Worker 1777*5e7646d2SAndroid Build Coastguard Worker DNSServiceErrorType DNSSD_API DNSServiceReconfirmRecord 1778*5e7646d2SAndroid Build Coastguard Worker ( 1779*5e7646d2SAndroid Build Coastguard Worker DNSServiceFlags flags, 1780*5e7646d2SAndroid Build Coastguard Worker uint32_t interfaceIndex, 1781*5e7646d2SAndroid Build Coastguard Worker const char *fullname, 1782*5e7646d2SAndroid Build Coastguard Worker uint16_t rrtype, 1783*5e7646d2SAndroid Build Coastguard Worker uint16_t rrclass, 1784*5e7646d2SAndroid Build Coastguard Worker uint16_t rdlen, 1785*5e7646d2SAndroid Build Coastguard Worker const void *rdata 1786*5e7646d2SAndroid Build Coastguard Worker ); 1787*5e7646d2SAndroid Build Coastguard Worker 1788*5e7646d2SAndroid Build Coastguard Worker 1789*5e7646d2SAndroid Build Coastguard Worker /********************************************************************************************* 1790*5e7646d2SAndroid Build Coastguard Worker * 1791*5e7646d2SAndroid Build Coastguard Worker * NAT Port Mapping 1792*5e7646d2SAndroid Build Coastguard Worker * 1793*5e7646d2SAndroid Build Coastguard Worker *********************************************************************************************/ 1794*5e7646d2SAndroid Build Coastguard Worker 1795*5e7646d2SAndroid Build Coastguard Worker /* DNSServiceNATPortMappingCreate 1796*5e7646d2SAndroid Build Coastguard Worker * 1797*5e7646d2SAndroid Build Coastguard Worker * Request a port mapping in the NAT gateway, which maps a port on the local machine 1798*5e7646d2SAndroid Build Coastguard Worker * to an external port on the NAT. The NAT should support either the NAT-PMP or the UPnP IGD 1799*5e7646d2SAndroid Build Coastguard Worker * protocol for this API to create a successful mapping. 1800*5e7646d2SAndroid Build Coastguard Worker * 1801*5e7646d2SAndroid Build Coastguard Worker * The port mapping will be renewed indefinitely until the client process exits, or 1802*5e7646d2SAndroid Build Coastguard Worker * explicitly terminates the port mapping request by calling DNSServiceRefDeallocate(). 1803*5e7646d2SAndroid Build Coastguard Worker * The client callback will be invoked, informing the client of the NAT gateway's 1804*5e7646d2SAndroid Build Coastguard Worker * external IP address and the external port that has been allocated for this client. 1805*5e7646d2SAndroid Build Coastguard Worker * The client should then record this external IP address and port using whatever 1806*5e7646d2SAndroid Build Coastguard Worker * directory service mechanism it is using to enable peers to connect to it. 1807*5e7646d2SAndroid Build Coastguard Worker * (Clients advertising services using Wide-Area DNS-SD DO NOT need to use this API 1808*5e7646d2SAndroid Build Coastguard Worker * -- when a client calls DNSServiceRegister() NAT mappings are automatically created 1809*5e7646d2SAndroid Build Coastguard Worker * and the external IP address and port for the service are recorded in the global DNS. 1810*5e7646d2SAndroid Build Coastguard Worker * Only clients using some directory mechanism other than Wide-Area DNS-SD need to use 1811*5e7646d2SAndroid Build Coastguard Worker * this API to explicitly map their own ports.) 1812*5e7646d2SAndroid Build Coastguard Worker * 1813*5e7646d2SAndroid Build Coastguard Worker * It's possible that the client callback could be called multiple times, for example 1814*5e7646d2SAndroid Build Coastguard Worker * if the NAT gateway's IP address changes, or if a configuration change results in a 1815*5e7646d2SAndroid Build Coastguard Worker * different external port being mapped for this client. Over the lifetime of any long-lived 1816*5e7646d2SAndroid Build Coastguard Worker * port mapping, the client should be prepared to handle these notifications of changes 1817*5e7646d2SAndroid Build Coastguard Worker * in the environment, and should update its recorded address and/or port as appropriate. 1818*5e7646d2SAndroid Build Coastguard Worker * 1819*5e7646d2SAndroid Build Coastguard Worker * NOTE: There are two unusual aspects of how the DNSServiceNATPortMappingCreate API works, 1820*5e7646d2SAndroid Build Coastguard Worker * which were intentionally designed to help simplify client code: 1821*5e7646d2SAndroid Build Coastguard Worker * 1822*5e7646d2SAndroid Build Coastguard Worker * 1. It's not an error to request a NAT mapping when the machine is not behind a NAT gateway. 1823*5e7646d2SAndroid Build Coastguard Worker * In other NAT mapping APIs, if you request a NAT mapping and the machine is not behind a NAT 1824*5e7646d2SAndroid Build Coastguard Worker * gateway, then the API returns an error code -- it can't get you a NAT mapping if there's no 1825*5e7646d2SAndroid Build Coastguard Worker * NAT gateway. The DNSServiceNATPortMappingCreate API takes a different view. Working out 1826*5e7646d2SAndroid Build Coastguard Worker * whether or not you need a NAT mapping can be tricky and non-obvious, particularly on 1827*5e7646d2SAndroid Build Coastguard Worker * a machine with multiple active network interfaces. Rather than make every client recreate 1828*5e7646d2SAndroid Build Coastguard Worker * this logic for deciding whether a NAT mapping is required, the PortMapping API does that 1829*5e7646d2SAndroid Build Coastguard Worker * work for you. If the client calls the PortMapping API when the machine already has a 1830*5e7646d2SAndroid Build Coastguard Worker * routable public IP address, then instead of complaining about it and giving an error, 1831*5e7646d2SAndroid Build Coastguard Worker * the PortMapping API just invokes your callback, giving the machine's public address 1832*5e7646d2SAndroid Build Coastguard Worker * and your own port number. This means you don't need to write code to work out whether 1833*5e7646d2SAndroid Build Coastguard Worker * your client needs to call the PortMapping API -- just call it anyway, and if it wasn't 1834*5e7646d2SAndroid Build Coastguard Worker * necessary, no harm is done: 1835*5e7646d2SAndroid Build Coastguard Worker * 1836*5e7646d2SAndroid Build Coastguard Worker * - If the machine already has a routable public IP address, then your callback 1837*5e7646d2SAndroid Build Coastguard Worker * will just be invoked giving your own address and port. 1838*5e7646d2SAndroid Build Coastguard Worker * - If a NAT mapping is required and obtained, then your callback will be invoked 1839*5e7646d2SAndroid Build Coastguard Worker * giving you the external address and port. 1840*5e7646d2SAndroid Build Coastguard Worker * - If a NAT mapping is required but not obtained from the local NAT gateway, 1841*5e7646d2SAndroid Build Coastguard Worker * or the machine has no network connectivity, then your callback will be 1842*5e7646d2SAndroid Build Coastguard Worker * invoked giving zero address and port. 1843*5e7646d2SAndroid Build Coastguard Worker * 1844*5e7646d2SAndroid Build Coastguard Worker * 2. In other NAT mapping APIs, if a laptop computer is put to sleep and woken up on a new 1845*5e7646d2SAndroid Build Coastguard Worker * network, it's the client's job to notice this, and work out whether a NAT mapping 1846*5e7646d2SAndroid Build Coastguard Worker * is required on the new network, and make a new NAT mapping request if necessary. 1847*5e7646d2SAndroid Build Coastguard Worker * The DNSServiceNATPortMappingCreate API does this for you, automatically. 1848*5e7646d2SAndroid Build Coastguard Worker * The client just needs to make one call to the PortMapping API, and its callback will 1849*5e7646d2SAndroid Build Coastguard Worker * be invoked any time the mapping state changes. This property complements point (1) above. 1850*5e7646d2SAndroid Build Coastguard Worker * If the client didn't make a NAT mapping request just because it determined that one was 1851*5e7646d2SAndroid Build Coastguard Worker * not required at that particular moment in time, the client would then have to monitor 1852*5e7646d2SAndroid Build Coastguard Worker * for network state changes to determine if a NAT port mapping later became necessary. 1853*5e7646d2SAndroid Build Coastguard Worker * By unconditionally making a NAT mapping request, even when a NAT mapping not to be 1854*5e7646d2SAndroid Build Coastguard Worker * necessary, the PortMapping API will then begin monitoring network state changes on behalf of 1855*5e7646d2SAndroid Build Coastguard Worker * the client, and if a NAT mapping later becomes necessary, it will automatically create a NAT 1856*5e7646d2SAndroid Build Coastguard Worker * mapping and inform the client with a new callback giving the new address and port information. 1857*5e7646d2SAndroid Build Coastguard Worker * 1858*5e7646d2SAndroid Build Coastguard Worker * DNSServiceNATPortMappingReply() parameters: 1859*5e7646d2SAndroid Build Coastguard Worker * 1860*5e7646d2SAndroid Build Coastguard Worker * sdRef: The DNSServiceRef initialized by DNSServiceNATPortMappingCreate(). 1861*5e7646d2SAndroid Build Coastguard Worker * 1862*5e7646d2SAndroid Build Coastguard Worker * flags: Currently unused, reserved for future use. 1863*5e7646d2SAndroid Build Coastguard Worker * 1864*5e7646d2SAndroid Build Coastguard Worker * interfaceIndex: The interface through which the NAT gateway is reached. 1865*5e7646d2SAndroid Build Coastguard Worker * 1866*5e7646d2SAndroid Build Coastguard Worker * errorCode: Will be kDNSServiceErr_NoError on success. 1867*5e7646d2SAndroid Build Coastguard Worker * Will be kDNSServiceErr_DoubleNAT when the NAT gateway is itself behind one or 1868*5e7646d2SAndroid Build Coastguard Worker * more layers of NAT, in which case the other parameters have the defined values. 1869*5e7646d2SAndroid Build Coastguard Worker * For other failures, will indicate the failure that occurred, and the other 1870*5e7646d2SAndroid Build Coastguard Worker * parameters are undefined. 1871*5e7646d2SAndroid Build Coastguard Worker * 1872*5e7646d2SAndroid Build Coastguard Worker * externalAddress: Four byte IPv4 address in network byte order. 1873*5e7646d2SAndroid Build Coastguard Worker * 1874*5e7646d2SAndroid Build Coastguard Worker * protocol: Will be kDNSServiceProtocol_UDP or kDNSServiceProtocol_TCP or both. 1875*5e7646d2SAndroid Build Coastguard Worker * 1876*5e7646d2SAndroid Build Coastguard Worker * internalPort: The port on the local machine that was mapped. 1877*5e7646d2SAndroid Build Coastguard Worker * 1878*5e7646d2SAndroid Build Coastguard Worker * externalPort: The actual external port in the NAT gateway that was mapped. 1879*5e7646d2SAndroid Build Coastguard Worker * This is likely to be different than the requested external port. 1880*5e7646d2SAndroid Build Coastguard Worker * 1881*5e7646d2SAndroid Build Coastguard Worker * ttl: The lifetime of the NAT port mapping created on the gateway. 1882*5e7646d2SAndroid Build Coastguard Worker * This controls how quickly stale mappings will be garbage-collected 1883*5e7646d2SAndroid Build Coastguard Worker * if the client machine crashes, suffers a power failure, is disconnected 1884*5e7646d2SAndroid Build Coastguard Worker * from the network, or suffers some other unfortunate demise which 1885*5e7646d2SAndroid Build Coastguard Worker * causes it to vanish without explicitly removing its NAT port mapping. 1886*5e7646d2SAndroid Build Coastguard Worker * It's possible that the ttl value will differ from the requested ttl value. 1887*5e7646d2SAndroid Build Coastguard Worker * 1888*5e7646d2SAndroid Build Coastguard Worker * context: The context pointer that was passed to the callout. 1889*5e7646d2SAndroid Build Coastguard Worker * 1890*5e7646d2SAndroid Build Coastguard Worker */ 1891*5e7646d2SAndroid Build Coastguard Worker 1892*5e7646d2SAndroid Build Coastguard Worker typedef void (DNSSD_API *DNSServiceNATPortMappingReply) 1893*5e7646d2SAndroid Build Coastguard Worker ( 1894*5e7646d2SAndroid Build Coastguard Worker DNSServiceRef sdRef, 1895*5e7646d2SAndroid Build Coastguard Worker DNSServiceFlags flags, 1896*5e7646d2SAndroid Build Coastguard Worker uint32_t interfaceIndex, 1897*5e7646d2SAndroid Build Coastguard Worker DNSServiceErrorType errorCode, 1898*5e7646d2SAndroid Build Coastguard Worker uint32_t externalAddress, /* four byte IPv4 address in network byte order */ 1899*5e7646d2SAndroid Build Coastguard Worker DNSServiceProtocol protocol, 1900*5e7646d2SAndroid Build Coastguard Worker uint16_t internalPort, /* In network byte order */ 1901*5e7646d2SAndroid Build Coastguard Worker uint16_t externalPort, /* In network byte order and may be different than the requested port */ 1902*5e7646d2SAndroid Build Coastguard Worker uint32_t ttl, /* may be different than the requested ttl */ 1903*5e7646d2SAndroid Build Coastguard Worker void *context 1904*5e7646d2SAndroid Build Coastguard Worker ); 1905*5e7646d2SAndroid Build Coastguard Worker 1906*5e7646d2SAndroid Build Coastguard Worker 1907*5e7646d2SAndroid Build Coastguard Worker /* DNSServiceNATPortMappingCreate() Parameters: 1908*5e7646d2SAndroid Build Coastguard Worker * 1909*5e7646d2SAndroid Build Coastguard Worker * sdRef: A pointer to an uninitialized DNSServiceRef. If the call succeeds then it 1910*5e7646d2SAndroid Build Coastguard Worker * initializes the DNSServiceRef, returns kDNSServiceErr_NoError, and the nat 1911*5e7646d2SAndroid Build Coastguard Worker * port mapping will last indefinitely until the client terminates the port 1912*5e7646d2SAndroid Build Coastguard Worker * mapping request by passing this DNSServiceRef to DNSServiceRefDeallocate(). 1913*5e7646d2SAndroid Build Coastguard Worker * 1914*5e7646d2SAndroid Build Coastguard Worker * flags: Currently ignored, reserved for future use. 1915*5e7646d2SAndroid Build Coastguard Worker * 1916*5e7646d2SAndroid Build Coastguard Worker * interfaceIndex: The interface on which to create port mappings in a NAT gateway. Passing 0 causes 1917*5e7646d2SAndroid Build Coastguard Worker * the port mapping request to be sent on the primary interface. 1918*5e7646d2SAndroid Build Coastguard Worker * 1919*5e7646d2SAndroid Build Coastguard Worker * protocol: To request a port mapping, pass in kDNSServiceProtocol_UDP, or kDNSServiceProtocol_TCP, 1920*5e7646d2SAndroid Build Coastguard Worker * or (kDNSServiceProtocol_UDP | kDNSServiceProtocol_TCP) to map both. 1921*5e7646d2SAndroid Build Coastguard Worker * The local listening port number must also be specified in the internalPort parameter. 1922*5e7646d2SAndroid Build Coastguard Worker * To just discover the NAT gateway's external IP address, pass zero for protocol, 1923*5e7646d2SAndroid Build Coastguard Worker * internalPort, externalPort and ttl. 1924*5e7646d2SAndroid Build Coastguard Worker * 1925*5e7646d2SAndroid Build Coastguard Worker * internalPort: The port number in network byte order on the local machine which is listening for packets. 1926*5e7646d2SAndroid Build Coastguard Worker * 1927*5e7646d2SAndroid Build Coastguard Worker * externalPort: The requested external port in network byte order in the NAT gateway that you would 1928*5e7646d2SAndroid Build Coastguard Worker * like to map to the internal port. Pass 0 if you don't care which external port is chosen for you. 1929*5e7646d2SAndroid Build Coastguard Worker * 1930*5e7646d2SAndroid Build Coastguard Worker * ttl: The requested renewal period of the NAT port mapping, in seconds. 1931*5e7646d2SAndroid Build Coastguard Worker * If the client machine crashes, suffers a power failure, is disconnected from 1932*5e7646d2SAndroid Build Coastguard Worker * the network, or suffers some other unfortunate demise which causes it to vanish 1933*5e7646d2SAndroid Build Coastguard Worker * unexpectedly without explicitly removing its NAT port mappings, then the NAT gateway 1934*5e7646d2SAndroid Build Coastguard Worker * will garbage-collect old stale NAT port mappings when their lifetime expires. 1935*5e7646d2SAndroid Build Coastguard Worker * Requesting a short TTL causes such orphaned mappings to be garbage-collected 1936*5e7646d2SAndroid Build Coastguard Worker * more promptly, but consumes system resources and network bandwidth with 1937*5e7646d2SAndroid Build Coastguard Worker * frequent renewal packets to keep the mapping from expiring. 1938*5e7646d2SAndroid Build Coastguard Worker * Requesting a long TTL is more efficient on the network, but in the event of the 1939*5e7646d2SAndroid Build Coastguard Worker * client vanishing, stale NAT port mappings will not be garbage-collected as quickly. 1940*5e7646d2SAndroid Build Coastguard Worker * Most clients should pass 0 to use a system-wide default value. 1941*5e7646d2SAndroid Build Coastguard Worker * 1942*5e7646d2SAndroid Build Coastguard Worker * callBack: The function to be called when the port mapping request succeeds or fails asynchronously. 1943*5e7646d2SAndroid Build Coastguard Worker * 1944*5e7646d2SAndroid Build Coastguard Worker * context: An application context pointer which is passed to the callback function 1945*5e7646d2SAndroid Build Coastguard Worker * (may be NULL). 1946*5e7646d2SAndroid Build Coastguard Worker * 1947*5e7646d2SAndroid Build Coastguard Worker * return value: Returns kDNSServiceErr_NoError on success (any subsequent, asynchronous 1948*5e7646d2SAndroid Build Coastguard Worker * errors are delivered to the callback), otherwise returns an error code indicating 1949*5e7646d2SAndroid Build Coastguard Worker * the error that occurred. 1950*5e7646d2SAndroid Build Coastguard Worker * 1951*5e7646d2SAndroid Build Coastguard Worker * If you don't actually want a port mapped, and are just calling the API 1952*5e7646d2SAndroid Build Coastguard Worker * because you want to find out the NAT's external IP address (e.g. for UI 1953*5e7646d2SAndroid Build Coastguard Worker * display) then pass zero for protocol, internalPort, externalPort and ttl. 1954*5e7646d2SAndroid Build Coastguard Worker */ 1955*5e7646d2SAndroid Build Coastguard Worker 1956*5e7646d2SAndroid Build Coastguard Worker DNSServiceErrorType DNSSD_API DNSServiceNATPortMappingCreate 1957*5e7646d2SAndroid Build Coastguard Worker ( 1958*5e7646d2SAndroid Build Coastguard Worker DNSServiceRef *sdRef, 1959*5e7646d2SAndroid Build Coastguard Worker DNSServiceFlags flags, 1960*5e7646d2SAndroid Build Coastguard Worker uint32_t interfaceIndex, 1961*5e7646d2SAndroid Build Coastguard Worker DNSServiceProtocol protocol, /* TCP and/or UDP */ 1962*5e7646d2SAndroid Build Coastguard Worker uint16_t internalPort, /* network byte order */ 1963*5e7646d2SAndroid Build Coastguard Worker uint16_t externalPort, /* network byte order */ 1964*5e7646d2SAndroid Build Coastguard Worker uint32_t ttl, /* time to live in seconds */ 1965*5e7646d2SAndroid Build Coastguard Worker DNSServiceNATPortMappingReply callBack, 1966*5e7646d2SAndroid Build Coastguard Worker void *context /* may be NULL */ 1967*5e7646d2SAndroid Build Coastguard Worker ); 1968*5e7646d2SAndroid Build Coastguard Worker 1969*5e7646d2SAndroid Build Coastguard Worker 1970*5e7646d2SAndroid Build Coastguard Worker /********************************************************************************************* 1971*5e7646d2SAndroid Build Coastguard Worker * 1972*5e7646d2SAndroid Build Coastguard Worker * General Utility Functions 1973*5e7646d2SAndroid Build Coastguard Worker * 1974*5e7646d2SAndroid Build Coastguard Worker *********************************************************************************************/ 1975*5e7646d2SAndroid Build Coastguard Worker 1976*5e7646d2SAndroid Build Coastguard Worker /* DNSServiceConstructFullName() 1977*5e7646d2SAndroid Build Coastguard Worker * 1978*5e7646d2SAndroid Build Coastguard Worker * Concatenate a three-part domain name (as returned by the above callbacks) into a 1979*5e7646d2SAndroid Build Coastguard Worker * properly-escaped full domain name. Note that callbacks in the above functions ALREADY ESCAPE 1980*5e7646d2SAndroid Build Coastguard Worker * strings where necessary. 1981*5e7646d2SAndroid Build Coastguard Worker * 1982*5e7646d2SAndroid Build Coastguard Worker * Parameters: 1983*5e7646d2SAndroid Build Coastguard Worker * 1984*5e7646d2SAndroid Build Coastguard Worker * fullName: A pointer to a buffer that where the resulting full domain name is to be written. 1985*5e7646d2SAndroid Build Coastguard Worker * The buffer must be kDNSServiceMaxDomainName (1009) bytes in length to 1986*5e7646d2SAndroid Build Coastguard Worker * accommodate the longest legal domain name without buffer overrun. 1987*5e7646d2SAndroid Build Coastguard Worker * 1988*5e7646d2SAndroid Build Coastguard Worker * service: The service name - any dots or backslashes must NOT be escaped. 1989*5e7646d2SAndroid Build Coastguard Worker * May be NULL (to construct a PTR record name, e.g. 1990*5e7646d2SAndroid Build Coastguard Worker * "_ftp._tcp.apple.com."). 1991*5e7646d2SAndroid Build Coastguard Worker * 1992*5e7646d2SAndroid Build Coastguard Worker * regtype: The service type followed by the protocol, separated by a dot 1993*5e7646d2SAndroid Build Coastguard Worker * (e.g. "_ftp._tcp"). 1994*5e7646d2SAndroid Build Coastguard Worker * 1995*5e7646d2SAndroid Build Coastguard Worker * domain: The domain name, e.g. "apple.com.". Literal dots or backslashes, 1996*5e7646d2SAndroid Build Coastguard Worker * if any, must be escaped, e.g. "1st\. Floor.apple.com." 1997*5e7646d2SAndroid Build Coastguard Worker * 1998*5e7646d2SAndroid Build Coastguard Worker * return value: Returns kDNSServiceErr_NoError (0) on success, kDNSServiceErr_BadParam on error. 1999*5e7646d2SAndroid Build Coastguard Worker * 2000*5e7646d2SAndroid Build Coastguard Worker */ 2001*5e7646d2SAndroid Build Coastguard Worker 2002*5e7646d2SAndroid Build Coastguard Worker DNSServiceErrorType DNSSD_API DNSServiceConstructFullName 2003*5e7646d2SAndroid Build Coastguard Worker ( 2004*5e7646d2SAndroid Build Coastguard Worker char * const fullName, 2005*5e7646d2SAndroid Build Coastguard Worker const char * const service, /* may be NULL */ 2006*5e7646d2SAndroid Build Coastguard Worker const char * const regtype, 2007*5e7646d2SAndroid Build Coastguard Worker const char * const domain 2008*5e7646d2SAndroid Build Coastguard Worker ); 2009*5e7646d2SAndroid Build Coastguard Worker 2010*5e7646d2SAndroid Build Coastguard Worker 2011*5e7646d2SAndroid Build Coastguard Worker /********************************************************************************************* 2012*5e7646d2SAndroid Build Coastguard Worker * 2013*5e7646d2SAndroid Build Coastguard Worker * TXT Record Construction Functions 2014*5e7646d2SAndroid Build Coastguard Worker * 2015*5e7646d2SAndroid Build Coastguard Worker *********************************************************************************************/ 2016*5e7646d2SAndroid Build Coastguard Worker 2017*5e7646d2SAndroid Build Coastguard Worker /* 2018*5e7646d2SAndroid Build Coastguard Worker * A typical calling sequence for TXT record construction is something like: 2019*5e7646d2SAndroid Build Coastguard Worker * 2020*5e7646d2SAndroid Build Coastguard Worker * Client allocates storage for TXTRecord data (e.g. declare buffer on the stack) 2021*5e7646d2SAndroid Build Coastguard Worker * TXTRecordCreate(); 2022*5e7646d2SAndroid Build Coastguard Worker * TXTRecordSetValue(); 2023*5e7646d2SAndroid Build Coastguard Worker * TXTRecordSetValue(); 2024*5e7646d2SAndroid Build Coastguard Worker * TXTRecordSetValue(); 2025*5e7646d2SAndroid Build Coastguard Worker * ... 2026*5e7646d2SAndroid Build Coastguard Worker * DNSServiceRegister( ... TXTRecordGetLength(), TXTRecordGetBytesPtr() ... ); 2027*5e7646d2SAndroid Build Coastguard Worker * TXTRecordDeallocate(); 2028*5e7646d2SAndroid Build Coastguard Worker * Explicitly deallocate storage for TXTRecord data (if not allocated on the stack) 2029*5e7646d2SAndroid Build Coastguard Worker */ 2030*5e7646d2SAndroid Build Coastguard Worker 2031*5e7646d2SAndroid Build Coastguard Worker 2032*5e7646d2SAndroid Build Coastguard Worker /* TXTRecordRef 2033*5e7646d2SAndroid Build Coastguard Worker * 2034*5e7646d2SAndroid Build Coastguard Worker * Opaque internal data type. 2035*5e7646d2SAndroid Build Coastguard Worker * Note: Represents a DNS-SD TXT record. 2036*5e7646d2SAndroid Build Coastguard Worker */ 2037*5e7646d2SAndroid Build Coastguard Worker 2038*5e7646d2SAndroid Build Coastguard Worker typedef union _TXTRecordRef_t { char PrivateData[16]; char *ForceNaturalAlignment; } TXTRecordRef; 2039*5e7646d2SAndroid Build Coastguard Worker 2040*5e7646d2SAndroid Build Coastguard Worker 2041*5e7646d2SAndroid Build Coastguard Worker /* TXTRecordCreate() 2042*5e7646d2SAndroid Build Coastguard Worker * 2043*5e7646d2SAndroid Build Coastguard Worker * Creates a new empty TXTRecordRef referencing the specified storage. 2044*5e7646d2SAndroid Build Coastguard Worker * 2045*5e7646d2SAndroid Build Coastguard Worker * If the buffer parameter is NULL, or the specified storage size is not 2046*5e7646d2SAndroid Build Coastguard Worker * large enough to hold a key subsequently added using TXTRecordSetValue(), 2047*5e7646d2SAndroid Build Coastguard Worker * then additional memory will be added as needed using malloc(). 2048*5e7646d2SAndroid Build Coastguard Worker * 2049*5e7646d2SAndroid Build Coastguard Worker * On some platforms, when memory is low, malloc() may fail. In this 2050*5e7646d2SAndroid Build Coastguard Worker * case, TXTRecordSetValue() will return kDNSServiceErr_NoMemory, and this 2051*5e7646d2SAndroid Build Coastguard Worker * error condition will need to be handled as appropriate by the caller. 2052*5e7646d2SAndroid Build Coastguard Worker * 2053*5e7646d2SAndroid Build Coastguard Worker * You can avoid the need to handle this error condition if you ensure 2054*5e7646d2SAndroid Build Coastguard Worker * that the storage you initially provide is large enough to hold all 2055*5e7646d2SAndroid Build Coastguard Worker * the key/value pairs that are to be added to the record. 2056*5e7646d2SAndroid Build Coastguard Worker * The caller can precompute the exact length required for all of the 2057*5e7646d2SAndroid Build Coastguard Worker * key/value pairs to be added, or simply provide a fixed-sized buffer 2058*5e7646d2SAndroid Build Coastguard Worker * known in advance to be large enough. 2059*5e7646d2SAndroid Build Coastguard Worker * A no-value (key-only) key requires (1 + key length) bytes. 2060*5e7646d2SAndroid Build Coastguard Worker * A key with empty value requires (1 + key length + 1) bytes. 2061*5e7646d2SAndroid Build Coastguard Worker * A key with non-empty value requires (1 + key length + 1 + value length). 2062*5e7646d2SAndroid Build Coastguard Worker * For most applications, DNS-SD TXT records are generally 2063*5e7646d2SAndroid Build Coastguard Worker * less than 100 bytes, so in most cases a simple fixed-sized 2064*5e7646d2SAndroid Build Coastguard Worker * 256-byte buffer will be more than sufficient. 2065*5e7646d2SAndroid Build Coastguard Worker * Recommended size limits for DNS-SD TXT Records are discussed in 2066*5e7646d2SAndroid Build Coastguard Worker * <http://files.dns-sd.org/draft-cheshire-dnsext-dns-sd.txt> 2067*5e7646d2SAndroid Build Coastguard Worker * 2068*5e7646d2SAndroid Build Coastguard Worker * Note: When passing parameters to and from these TXT record APIs, 2069*5e7646d2SAndroid Build Coastguard Worker * the key name does not include the '=' character. The '=' character 2070*5e7646d2SAndroid Build Coastguard Worker * is the separator between the key and value in the on-the-wire 2071*5e7646d2SAndroid Build Coastguard Worker * packet format; it is not part of either the key or the value. 2072*5e7646d2SAndroid Build Coastguard Worker * 2073*5e7646d2SAndroid Build Coastguard Worker * txtRecord: A pointer to an uninitialized TXTRecordRef. 2074*5e7646d2SAndroid Build Coastguard Worker * 2075*5e7646d2SAndroid Build Coastguard Worker * bufferLen: The size of the storage provided in the "buffer" parameter. 2076*5e7646d2SAndroid Build Coastguard Worker * 2077*5e7646d2SAndroid Build Coastguard Worker * buffer: Optional caller-supplied storage used to hold the TXTRecord data. 2078*5e7646d2SAndroid Build Coastguard Worker * This storage must remain valid for as long as 2079*5e7646d2SAndroid Build Coastguard Worker * the TXTRecordRef. 2080*5e7646d2SAndroid Build Coastguard Worker */ 2081*5e7646d2SAndroid Build Coastguard Worker 2082*5e7646d2SAndroid Build Coastguard Worker void DNSSD_API TXTRecordCreate 2083*5e7646d2SAndroid Build Coastguard Worker ( 2084*5e7646d2SAndroid Build Coastguard Worker TXTRecordRef *txtRecord, 2085*5e7646d2SAndroid Build Coastguard Worker uint16_t bufferLen, 2086*5e7646d2SAndroid Build Coastguard Worker void *buffer 2087*5e7646d2SAndroid Build Coastguard Worker ); 2088*5e7646d2SAndroid Build Coastguard Worker 2089*5e7646d2SAndroid Build Coastguard Worker 2090*5e7646d2SAndroid Build Coastguard Worker /* TXTRecordDeallocate() 2091*5e7646d2SAndroid Build Coastguard Worker * 2092*5e7646d2SAndroid Build Coastguard Worker * Releases any resources allocated in the course of preparing a TXT Record 2093*5e7646d2SAndroid Build Coastguard Worker * using TXTRecordCreate()/TXTRecordSetValue()/TXTRecordRemoveValue(). 2094*5e7646d2SAndroid Build Coastguard Worker * Ownership of the buffer provided in TXTRecordCreate() returns to the client. 2095*5e7646d2SAndroid Build Coastguard Worker * 2096*5e7646d2SAndroid Build Coastguard Worker * txtRecord: A TXTRecordRef initialized by calling TXTRecordCreate(). 2097*5e7646d2SAndroid Build Coastguard Worker * 2098*5e7646d2SAndroid Build Coastguard Worker */ 2099*5e7646d2SAndroid Build Coastguard Worker 2100*5e7646d2SAndroid Build Coastguard Worker void DNSSD_API TXTRecordDeallocate 2101*5e7646d2SAndroid Build Coastguard Worker ( 2102*5e7646d2SAndroid Build Coastguard Worker TXTRecordRef *txtRecord 2103*5e7646d2SAndroid Build Coastguard Worker ); 2104*5e7646d2SAndroid Build Coastguard Worker 2105*5e7646d2SAndroid Build Coastguard Worker 2106*5e7646d2SAndroid Build Coastguard Worker /* TXTRecordSetValue() 2107*5e7646d2SAndroid Build Coastguard Worker * 2108*5e7646d2SAndroid Build Coastguard Worker * Adds a key (optionally with value) to a TXTRecordRef. If the "key" already 2109*5e7646d2SAndroid Build Coastguard Worker * exists in the TXTRecordRef, then the current value will be replaced with 2110*5e7646d2SAndroid Build Coastguard Worker * the new value. 2111*5e7646d2SAndroid Build Coastguard Worker * Keys may exist in four states with respect to a given TXT record: 2112*5e7646d2SAndroid Build Coastguard Worker * - Absent (key does not appear at all) 2113*5e7646d2SAndroid Build Coastguard Worker * - Present with no value ("key" appears alone) 2114*5e7646d2SAndroid Build Coastguard Worker * - Present with empty value ("key=" appears in TXT record) 2115*5e7646d2SAndroid Build Coastguard Worker * - Present with non-empty value ("key=value" appears in TXT record) 2116*5e7646d2SAndroid Build Coastguard Worker * For more details refer to "Data Syntax for DNS-SD TXT Records" in 2117*5e7646d2SAndroid Build Coastguard Worker * <http://files.dns-sd.org/draft-cheshire-dnsext-dns-sd.txt> 2118*5e7646d2SAndroid Build Coastguard Worker * 2119*5e7646d2SAndroid Build Coastguard Worker * txtRecord: A TXTRecordRef initialized by calling TXTRecordCreate(). 2120*5e7646d2SAndroid Build Coastguard Worker * 2121*5e7646d2SAndroid Build Coastguard Worker * key: A null-terminated string which only contains printable ASCII 2122*5e7646d2SAndroid Build Coastguard Worker * values (0x20-0x7E), excluding '=' (0x3D). Keys should be 2123*5e7646d2SAndroid Build Coastguard Worker * 9 characters or fewer (not counting the terminating null). 2124*5e7646d2SAndroid Build Coastguard Worker * 2125*5e7646d2SAndroid Build Coastguard Worker * valueSize: The size of the value. 2126*5e7646d2SAndroid Build Coastguard Worker * 2127*5e7646d2SAndroid Build Coastguard Worker * value: Any binary value. For values that represent 2128*5e7646d2SAndroid Build Coastguard Worker * textual data, UTF-8 is STRONGLY recommended. 2129*5e7646d2SAndroid Build Coastguard Worker * For values that represent textual data, valueSize 2130*5e7646d2SAndroid Build Coastguard Worker * should NOT include the terminating null (if any) 2131*5e7646d2SAndroid Build Coastguard Worker * at the end of the string. 2132*5e7646d2SAndroid Build Coastguard Worker * If NULL, then "key" will be added with no value. 2133*5e7646d2SAndroid Build Coastguard Worker * If non-NULL but valueSize is zero, then "key=" will be 2134*5e7646d2SAndroid Build Coastguard Worker * added with empty value. 2135*5e7646d2SAndroid Build Coastguard Worker * 2136*5e7646d2SAndroid Build Coastguard Worker * return value: Returns kDNSServiceErr_NoError on success. 2137*5e7646d2SAndroid Build Coastguard Worker * Returns kDNSServiceErr_Invalid if the "key" string contains 2138*5e7646d2SAndroid Build Coastguard Worker * illegal characters. 2139*5e7646d2SAndroid Build Coastguard Worker * Returns kDNSServiceErr_NoMemory if adding this key would 2140*5e7646d2SAndroid Build Coastguard Worker * exceed the available storage. 2141*5e7646d2SAndroid Build Coastguard Worker */ 2142*5e7646d2SAndroid Build Coastguard Worker 2143*5e7646d2SAndroid Build Coastguard Worker DNSServiceErrorType DNSSD_API TXTRecordSetValue 2144*5e7646d2SAndroid Build Coastguard Worker ( 2145*5e7646d2SAndroid Build Coastguard Worker TXTRecordRef *txtRecord, 2146*5e7646d2SAndroid Build Coastguard Worker const char *key, 2147*5e7646d2SAndroid Build Coastguard Worker uint8_t valueSize, /* may be zero */ 2148*5e7646d2SAndroid Build Coastguard Worker const void *value /* may be NULL */ 2149*5e7646d2SAndroid Build Coastguard Worker ); 2150*5e7646d2SAndroid Build Coastguard Worker 2151*5e7646d2SAndroid Build Coastguard Worker 2152*5e7646d2SAndroid Build Coastguard Worker /* TXTRecordRemoveValue() 2153*5e7646d2SAndroid Build Coastguard Worker * 2154*5e7646d2SAndroid Build Coastguard Worker * Removes a key from a TXTRecordRef. The "key" must be an 2155*5e7646d2SAndroid Build Coastguard Worker * ASCII string which exists in the TXTRecordRef. 2156*5e7646d2SAndroid Build Coastguard Worker * 2157*5e7646d2SAndroid Build Coastguard Worker * txtRecord: A TXTRecordRef initialized by calling TXTRecordCreate(). 2158*5e7646d2SAndroid Build Coastguard Worker * 2159*5e7646d2SAndroid Build Coastguard Worker * key: A key name which exists in the TXTRecordRef. 2160*5e7646d2SAndroid Build Coastguard Worker * 2161*5e7646d2SAndroid Build Coastguard Worker * return value: Returns kDNSServiceErr_NoError on success. 2162*5e7646d2SAndroid Build Coastguard Worker * Returns kDNSServiceErr_NoSuchKey if the "key" does not 2163*5e7646d2SAndroid Build Coastguard Worker * exist in the TXTRecordRef. 2164*5e7646d2SAndroid Build Coastguard Worker */ 2165*5e7646d2SAndroid Build Coastguard Worker 2166*5e7646d2SAndroid Build Coastguard Worker DNSServiceErrorType DNSSD_API TXTRecordRemoveValue 2167*5e7646d2SAndroid Build Coastguard Worker ( 2168*5e7646d2SAndroid Build Coastguard Worker TXTRecordRef *txtRecord, 2169*5e7646d2SAndroid Build Coastguard Worker const char *key 2170*5e7646d2SAndroid Build Coastguard Worker ); 2171*5e7646d2SAndroid Build Coastguard Worker 2172*5e7646d2SAndroid Build Coastguard Worker 2173*5e7646d2SAndroid Build Coastguard Worker /* TXTRecordGetLength() 2174*5e7646d2SAndroid Build Coastguard Worker * 2175*5e7646d2SAndroid Build Coastguard Worker * Allows you to determine the length of the raw bytes within a TXTRecordRef. 2176*5e7646d2SAndroid Build Coastguard Worker * 2177*5e7646d2SAndroid Build Coastguard Worker * txtRecord: A TXTRecordRef initialized by calling TXTRecordCreate(). 2178*5e7646d2SAndroid Build Coastguard Worker * 2179*5e7646d2SAndroid Build Coastguard Worker * return value: Returns the size of the raw bytes inside a TXTRecordRef 2180*5e7646d2SAndroid Build Coastguard Worker * which you can pass directly to DNSServiceRegister() or 2181*5e7646d2SAndroid Build Coastguard Worker * to DNSServiceUpdateRecord(). 2182*5e7646d2SAndroid Build Coastguard Worker * Returns 0 if the TXTRecordRef is empty. 2183*5e7646d2SAndroid Build Coastguard Worker */ 2184*5e7646d2SAndroid Build Coastguard Worker 2185*5e7646d2SAndroid Build Coastguard Worker uint16_t DNSSD_API TXTRecordGetLength 2186*5e7646d2SAndroid Build Coastguard Worker ( 2187*5e7646d2SAndroid Build Coastguard Worker const TXTRecordRef *txtRecord 2188*5e7646d2SAndroid Build Coastguard Worker ); 2189*5e7646d2SAndroid Build Coastguard Worker 2190*5e7646d2SAndroid Build Coastguard Worker 2191*5e7646d2SAndroid Build Coastguard Worker /* TXTRecordGetBytesPtr() 2192*5e7646d2SAndroid Build Coastguard Worker * 2193*5e7646d2SAndroid Build Coastguard Worker * Allows you to retrieve a pointer to the raw bytes within a TXTRecordRef. 2194*5e7646d2SAndroid Build Coastguard Worker * 2195*5e7646d2SAndroid Build Coastguard Worker * txtRecord: A TXTRecordRef initialized by calling TXTRecordCreate(). 2196*5e7646d2SAndroid Build Coastguard Worker * 2197*5e7646d2SAndroid Build Coastguard Worker * return value: Returns a pointer to the raw bytes inside the TXTRecordRef 2198*5e7646d2SAndroid Build Coastguard Worker * which you can pass directly to DNSServiceRegister() or 2199*5e7646d2SAndroid Build Coastguard Worker * to DNSServiceUpdateRecord(). 2200*5e7646d2SAndroid Build Coastguard Worker */ 2201*5e7646d2SAndroid Build Coastguard Worker 2202*5e7646d2SAndroid Build Coastguard Worker const void * DNSSD_API TXTRecordGetBytesPtr 2203*5e7646d2SAndroid Build Coastguard Worker ( 2204*5e7646d2SAndroid Build Coastguard Worker const TXTRecordRef *txtRecord 2205*5e7646d2SAndroid Build Coastguard Worker ); 2206*5e7646d2SAndroid Build Coastguard Worker 2207*5e7646d2SAndroid Build Coastguard Worker 2208*5e7646d2SAndroid Build Coastguard Worker /********************************************************************************************* 2209*5e7646d2SAndroid Build Coastguard Worker * 2210*5e7646d2SAndroid Build Coastguard Worker * TXT Record Parsing Functions 2211*5e7646d2SAndroid Build Coastguard Worker * 2212*5e7646d2SAndroid Build Coastguard Worker *********************************************************************************************/ 2213*5e7646d2SAndroid Build Coastguard Worker 2214*5e7646d2SAndroid Build Coastguard Worker /* 2215*5e7646d2SAndroid Build Coastguard Worker * A typical calling sequence for TXT record parsing is something like: 2216*5e7646d2SAndroid Build Coastguard Worker * 2217*5e7646d2SAndroid Build Coastguard Worker * Receive TXT record data in DNSServiceResolve() callback 2218*5e7646d2SAndroid Build Coastguard Worker * if (TXTRecordContainsKey(txtLen, txtRecord, "key")) then do something 2219*5e7646d2SAndroid Build Coastguard Worker * val1ptr = TXTRecordGetValuePtr(txtLen, txtRecord, "key1", &len1); 2220*5e7646d2SAndroid Build Coastguard Worker * val2ptr = TXTRecordGetValuePtr(txtLen, txtRecord, "key2", &len2); 2221*5e7646d2SAndroid Build Coastguard Worker * ... 2222*5e7646d2SAndroid Build Coastguard Worker * memcpy(myval1, val1ptr, len1); 2223*5e7646d2SAndroid Build Coastguard Worker * memcpy(myval2, val2ptr, len2); 2224*5e7646d2SAndroid Build Coastguard Worker * ... 2225*5e7646d2SAndroid Build Coastguard Worker * return; 2226*5e7646d2SAndroid Build Coastguard Worker * 2227*5e7646d2SAndroid Build Coastguard Worker * If you wish to retain the values after return from the DNSServiceResolve() 2228*5e7646d2SAndroid Build Coastguard Worker * callback, then you need to copy the data to your own storage using memcpy() 2229*5e7646d2SAndroid Build Coastguard Worker * or similar, as shown in the example above. 2230*5e7646d2SAndroid Build Coastguard Worker * 2231*5e7646d2SAndroid Build Coastguard Worker * If for some reason you need to parse a TXT record you built yourself 2232*5e7646d2SAndroid Build Coastguard Worker * using the TXT record construction functions above, then you can do 2233*5e7646d2SAndroid Build Coastguard Worker * that using TXTRecordGetLength and TXTRecordGetBytesPtr calls: 2234*5e7646d2SAndroid Build Coastguard Worker * TXTRecordGetValue(TXTRecordGetLength(x), TXTRecordGetBytesPtr(x), key, &len); 2235*5e7646d2SAndroid Build Coastguard Worker * 2236*5e7646d2SAndroid Build Coastguard Worker * Most applications only fetch keys they know about from a TXT record and 2237*5e7646d2SAndroid Build Coastguard Worker * ignore the rest. 2238*5e7646d2SAndroid Build Coastguard Worker * However, some debugging tools wish to fetch and display all keys. 2239*5e7646d2SAndroid Build Coastguard Worker * To do that, use the TXTRecordGetCount() and TXTRecordGetItemAtIndex() calls. 2240*5e7646d2SAndroid Build Coastguard Worker */ 2241*5e7646d2SAndroid Build Coastguard Worker 2242*5e7646d2SAndroid Build Coastguard Worker /* TXTRecordContainsKey() 2243*5e7646d2SAndroid Build Coastguard Worker * 2244*5e7646d2SAndroid Build Coastguard Worker * Allows you to determine if a given TXT Record contains a specified key. 2245*5e7646d2SAndroid Build Coastguard Worker * 2246*5e7646d2SAndroid Build Coastguard Worker * txtLen: The size of the received TXT Record. 2247*5e7646d2SAndroid Build Coastguard Worker * 2248*5e7646d2SAndroid Build Coastguard Worker * txtRecord: Pointer to the received TXT Record bytes. 2249*5e7646d2SAndroid Build Coastguard Worker * 2250*5e7646d2SAndroid Build Coastguard Worker * key: A null-terminated ASCII string containing the key name. 2251*5e7646d2SAndroid Build Coastguard Worker * 2252*5e7646d2SAndroid Build Coastguard Worker * return value: Returns 1 if the TXT Record contains the specified key. 2253*5e7646d2SAndroid Build Coastguard Worker * Otherwise, it returns 0. 2254*5e7646d2SAndroid Build Coastguard Worker */ 2255*5e7646d2SAndroid Build Coastguard Worker 2256*5e7646d2SAndroid Build Coastguard Worker int DNSSD_API TXTRecordContainsKey 2257*5e7646d2SAndroid Build Coastguard Worker ( 2258*5e7646d2SAndroid Build Coastguard Worker uint16_t txtLen, 2259*5e7646d2SAndroid Build Coastguard Worker const void *txtRecord, 2260*5e7646d2SAndroid Build Coastguard Worker const char *key 2261*5e7646d2SAndroid Build Coastguard Worker ); 2262*5e7646d2SAndroid Build Coastguard Worker 2263*5e7646d2SAndroid Build Coastguard Worker 2264*5e7646d2SAndroid Build Coastguard Worker /* TXTRecordGetValuePtr() 2265*5e7646d2SAndroid Build Coastguard Worker * 2266*5e7646d2SAndroid Build Coastguard Worker * Allows you to retrieve the value for a given key from a TXT Record. 2267*5e7646d2SAndroid Build Coastguard Worker * 2268*5e7646d2SAndroid Build Coastguard Worker * txtLen: The size of the received TXT Record 2269*5e7646d2SAndroid Build Coastguard Worker * 2270*5e7646d2SAndroid Build Coastguard Worker * txtRecord: Pointer to the received TXT Record bytes. 2271*5e7646d2SAndroid Build Coastguard Worker * 2272*5e7646d2SAndroid Build Coastguard Worker * key: A null-terminated ASCII string containing the key name. 2273*5e7646d2SAndroid Build Coastguard Worker * 2274*5e7646d2SAndroid Build Coastguard Worker * valueLen: On output, will be set to the size of the "value" data. 2275*5e7646d2SAndroid Build Coastguard Worker * 2276*5e7646d2SAndroid Build Coastguard Worker * return value: Returns NULL if the key does not exist in this TXT record, 2277*5e7646d2SAndroid Build Coastguard Worker * or exists with no value (to differentiate between 2278*5e7646d2SAndroid Build Coastguard Worker * these two cases use TXTRecordContainsKey()). 2279*5e7646d2SAndroid Build Coastguard Worker * Returns pointer to location within TXT Record bytes 2280*5e7646d2SAndroid Build Coastguard Worker * if the key exists with empty or non-empty value. 2281*5e7646d2SAndroid Build Coastguard Worker * For empty value, valueLen will be zero. 2282*5e7646d2SAndroid Build Coastguard Worker * For non-empty value, valueLen will be length of value data. 2283*5e7646d2SAndroid Build Coastguard Worker */ 2284*5e7646d2SAndroid Build Coastguard Worker 2285*5e7646d2SAndroid Build Coastguard Worker const void * DNSSD_API TXTRecordGetValuePtr 2286*5e7646d2SAndroid Build Coastguard Worker ( 2287*5e7646d2SAndroid Build Coastguard Worker uint16_t txtLen, 2288*5e7646d2SAndroid Build Coastguard Worker const void *txtRecord, 2289*5e7646d2SAndroid Build Coastguard Worker const char *key, 2290*5e7646d2SAndroid Build Coastguard Worker uint8_t *valueLen 2291*5e7646d2SAndroid Build Coastguard Worker ); 2292*5e7646d2SAndroid Build Coastguard Worker 2293*5e7646d2SAndroid Build Coastguard Worker 2294*5e7646d2SAndroid Build Coastguard Worker /* TXTRecordGetCount() 2295*5e7646d2SAndroid Build Coastguard Worker * 2296*5e7646d2SAndroid Build Coastguard Worker * Returns the number of keys stored in the TXT Record. The count 2297*5e7646d2SAndroid Build Coastguard Worker * can be used with TXTRecordGetItemAtIndex() to iterate through the keys. 2298*5e7646d2SAndroid Build Coastguard Worker * 2299*5e7646d2SAndroid Build Coastguard Worker * txtLen: The size of the received TXT Record. 2300*5e7646d2SAndroid Build Coastguard Worker * 2301*5e7646d2SAndroid Build Coastguard Worker * txtRecord: Pointer to the received TXT Record bytes. 2302*5e7646d2SAndroid Build Coastguard Worker * 2303*5e7646d2SAndroid Build Coastguard Worker * return value: Returns the total number of keys in the TXT Record. 2304*5e7646d2SAndroid Build Coastguard Worker * 2305*5e7646d2SAndroid Build Coastguard Worker */ 2306*5e7646d2SAndroid Build Coastguard Worker 2307*5e7646d2SAndroid Build Coastguard Worker uint16_t DNSSD_API TXTRecordGetCount 2308*5e7646d2SAndroid Build Coastguard Worker ( 2309*5e7646d2SAndroid Build Coastguard Worker uint16_t txtLen, 2310*5e7646d2SAndroid Build Coastguard Worker const void *txtRecord 2311*5e7646d2SAndroid Build Coastguard Worker ); 2312*5e7646d2SAndroid Build Coastguard Worker 2313*5e7646d2SAndroid Build Coastguard Worker 2314*5e7646d2SAndroid Build Coastguard Worker /* TXTRecordGetItemAtIndex() 2315*5e7646d2SAndroid Build Coastguard Worker * 2316*5e7646d2SAndroid Build Coastguard Worker * Allows you to retrieve a key name and value pointer, given an index into 2317*5e7646d2SAndroid Build Coastguard Worker * a TXT Record. Legal index values range from zero to TXTRecordGetCount()-1. 2318*5e7646d2SAndroid Build Coastguard Worker * It's also possible to iterate through keys in a TXT record by simply 2319*5e7646d2SAndroid Build Coastguard Worker * calling TXTRecordGetItemAtIndex() repeatedly, beginning with index zero 2320*5e7646d2SAndroid Build Coastguard Worker * and increasing until TXTRecordGetItemAtIndex() returns kDNSServiceErr_Invalid. 2321*5e7646d2SAndroid Build Coastguard Worker * 2322*5e7646d2SAndroid Build Coastguard Worker * On return: 2323*5e7646d2SAndroid Build Coastguard Worker * For keys with no value, *value is set to NULL and *valueLen is zero. 2324*5e7646d2SAndroid Build Coastguard Worker * For keys with empty value, *value is non-NULL and *valueLen is zero. 2325*5e7646d2SAndroid Build Coastguard Worker * For keys with non-empty value, *value is non-NULL and *valueLen is non-zero. 2326*5e7646d2SAndroid Build Coastguard Worker * 2327*5e7646d2SAndroid Build Coastguard Worker * txtLen: The size of the received TXT Record. 2328*5e7646d2SAndroid Build Coastguard Worker * 2329*5e7646d2SAndroid Build Coastguard Worker * txtRecord: Pointer to the received TXT Record bytes. 2330*5e7646d2SAndroid Build Coastguard Worker * 2331*5e7646d2SAndroid Build Coastguard Worker * itemIndex: An index into the TXT Record. 2332*5e7646d2SAndroid Build Coastguard Worker * 2333*5e7646d2SAndroid Build Coastguard Worker * keyBufLen: The size of the string buffer being supplied. 2334*5e7646d2SAndroid Build Coastguard Worker * 2335*5e7646d2SAndroid Build Coastguard Worker * key: A string buffer used to store the key name. 2336*5e7646d2SAndroid Build Coastguard Worker * On return, the buffer contains a null-terminated C string 2337*5e7646d2SAndroid Build Coastguard Worker * giving the key name. DNS-SD TXT keys are usually 2338*5e7646d2SAndroid Build Coastguard Worker * 9 characters or fewer. To hold the maximum possible 2339*5e7646d2SAndroid Build Coastguard Worker * key name, the buffer should be 256 bytes long. 2340*5e7646d2SAndroid Build Coastguard Worker * 2341*5e7646d2SAndroid Build Coastguard Worker * valueLen: On output, will be set to the size of the "value" data. 2342*5e7646d2SAndroid Build Coastguard Worker * 2343*5e7646d2SAndroid Build Coastguard Worker * value: On output, *value is set to point to location within TXT 2344*5e7646d2SAndroid Build Coastguard Worker * Record bytes that holds the value data. 2345*5e7646d2SAndroid Build Coastguard Worker * 2346*5e7646d2SAndroid Build Coastguard Worker * return value: Returns kDNSServiceErr_NoError on success. 2347*5e7646d2SAndroid Build Coastguard Worker * Returns kDNSServiceErr_NoMemory if keyBufLen is too short. 2348*5e7646d2SAndroid Build Coastguard Worker * Returns kDNSServiceErr_Invalid if index is greater than 2349*5e7646d2SAndroid Build Coastguard Worker * TXTRecordGetCount()-1. 2350*5e7646d2SAndroid Build Coastguard Worker */ 2351*5e7646d2SAndroid Build Coastguard Worker 2352*5e7646d2SAndroid Build Coastguard Worker DNSServiceErrorType DNSSD_API TXTRecordGetItemAtIndex 2353*5e7646d2SAndroid Build Coastguard Worker ( 2354*5e7646d2SAndroid Build Coastguard Worker uint16_t txtLen, 2355*5e7646d2SAndroid Build Coastguard Worker const void *txtRecord, 2356*5e7646d2SAndroid Build Coastguard Worker uint16_t itemIndex, 2357*5e7646d2SAndroid Build Coastguard Worker uint16_t keyBufLen, 2358*5e7646d2SAndroid Build Coastguard Worker char *key, 2359*5e7646d2SAndroid Build Coastguard Worker uint8_t *valueLen, 2360*5e7646d2SAndroid Build Coastguard Worker const void **value 2361*5e7646d2SAndroid Build Coastguard Worker ); 2362*5e7646d2SAndroid Build Coastguard Worker 2363*5e7646d2SAndroid Build Coastguard Worker #if _DNS_SD_LIBDISPATCH 2364*5e7646d2SAndroid Build Coastguard Worker /* 2365*5e7646d2SAndroid Build Coastguard Worker * DNSServiceSetDispatchQueue 2366*5e7646d2SAndroid Build Coastguard Worker * 2367*5e7646d2SAndroid Build Coastguard Worker * Allows you to schedule a DNSServiceRef on a serial dispatch queue for receiving asynchronous 2368*5e7646d2SAndroid Build Coastguard Worker * callbacks. It's the clients responsibility to ensure that the provided dispatch queue is running. 2369*5e7646d2SAndroid Build Coastguard Worker * 2370*5e7646d2SAndroid Build Coastguard Worker * A typical application that uses CFRunLoopRun or dispatch_main on its main thread will 2371*5e7646d2SAndroid Build Coastguard Worker * usually schedule DNSServiceRefs on its main queue (which is always a serial queue) 2372*5e7646d2SAndroid Build Coastguard Worker * using "DNSServiceSetDispatchQueue(sdref, dispatch_get_main_queue());" 2373*5e7646d2SAndroid Build Coastguard Worker * 2374*5e7646d2SAndroid Build Coastguard Worker * If there is any error during the processing of events, the application callback will 2375*5e7646d2SAndroid Build Coastguard Worker * be called with an error code. For shared connections, each subordinate DNSServiceRef 2376*5e7646d2SAndroid Build Coastguard Worker * will get its own error callback. Currently these error callbacks only happen 2377*5e7646d2SAndroid Build Coastguard Worker * if the mDNSResponder daemon is manually terminated or crashes, and the error 2378*5e7646d2SAndroid Build Coastguard Worker * code in this case is kDNSServiceErr_ServiceNotRunning. The application must call 2379*5e7646d2SAndroid Build Coastguard Worker * DNSServiceRefDeallocate to free the DNSServiceRef when it gets such an error code. 2380*5e7646d2SAndroid Build Coastguard Worker * These error callbacks are rare and should not normally happen on customer machines, 2381*5e7646d2SAndroid Build Coastguard Worker * but application code should be written defensively to handle such error callbacks 2382*5e7646d2SAndroid Build Coastguard Worker * gracefully if they occur. 2383*5e7646d2SAndroid Build Coastguard Worker * 2384*5e7646d2SAndroid Build Coastguard Worker * After using DNSServiceSetDispatchQueue on a DNSServiceRef, calling DNSServiceProcessResult 2385*5e7646d2SAndroid Build Coastguard Worker * on the same DNSServiceRef will result in undefined behavior and should be avoided. 2386*5e7646d2SAndroid Build Coastguard Worker * 2387*5e7646d2SAndroid Build Coastguard Worker * Once the application successfully schedules a DNSServiceRef on a serial dispatch queue using 2388*5e7646d2SAndroid Build Coastguard Worker * DNSServiceSetDispatchQueue, it cannot remove the DNSServiceRef from the dispatch queue, or use 2389*5e7646d2SAndroid Build Coastguard Worker * DNSServiceSetDispatchQueue a second time to schedule the DNSServiceRef onto a different serial dispatch 2390*5e7646d2SAndroid Build Coastguard Worker * queue. Once scheduled onto a dispatch queue a DNSServiceRef will deliver events to that queue until 2391*5e7646d2SAndroid Build Coastguard Worker * the application no longer requires that operation and terminates it using DNSServiceRefDeallocate. 2392*5e7646d2SAndroid Build Coastguard Worker * 2393*5e7646d2SAndroid Build Coastguard Worker * service: DNSServiceRef that was allocated and returned to the application, when the 2394*5e7646d2SAndroid Build Coastguard Worker * application calls one of the DNSService API. 2395*5e7646d2SAndroid Build Coastguard Worker * 2396*5e7646d2SAndroid Build Coastguard Worker * queue: dispatch queue where the application callback will be scheduled 2397*5e7646d2SAndroid Build Coastguard Worker * 2398*5e7646d2SAndroid Build Coastguard Worker * return value: Returns kDNSServiceErr_NoError on success. 2399*5e7646d2SAndroid Build Coastguard Worker * Returns kDNSServiceErr_NoMemory if it cannot create a dispatch source 2400*5e7646d2SAndroid Build Coastguard Worker * Returns kDNSServiceErr_BadParam if the service param is invalid or the 2401*5e7646d2SAndroid Build Coastguard Worker * queue param is invalid 2402*5e7646d2SAndroid Build Coastguard Worker */ 2403*5e7646d2SAndroid Build Coastguard Worker 2404*5e7646d2SAndroid Build Coastguard Worker DNSServiceErrorType DNSSD_API DNSServiceSetDispatchQueue 2405*5e7646d2SAndroid Build Coastguard Worker ( 2406*5e7646d2SAndroid Build Coastguard Worker DNSServiceRef service, 2407*5e7646d2SAndroid Build Coastguard Worker dispatch_queue_t queue 2408*5e7646d2SAndroid Build Coastguard Worker ); 2409*5e7646d2SAndroid Build Coastguard Worker #endif //_DNS_SD_LIBDISPATCH 2410*5e7646d2SAndroid Build Coastguard Worker 2411*5e7646d2SAndroid Build Coastguard Worker #ifdef __APPLE_API_PRIVATE 2412*5e7646d2SAndroid Build Coastguard Worker 2413*5e7646d2SAndroid Build Coastguard Worker #define kDNSServiceCompPrivateDNS "PrivateDNS" 2414*5e7646d2SAndroid Build Coastguard Worker #define kDNSServiceCompMulticastDNS "MulticastDNS" 2415*5e7646d2SAndroid Build Coastguard Worker 2416*5e7646d2SAndroid Build Coastguard Worker #endif //__APPLE_API_PRIVATE 2417*5e7646d2SAndroid Build Coastguard Worker 2418*5e7646d2SAndroid Build Coastguard Worker /* Some C compiler cleverness. We can make the compiler check certain things for us, 2419*5e7646d2SAndroid Build Coastguard Worker * and report errors at compile-time if anything is wrong. The usual way to do this would 2420*5e7646d2SAndroid Build Coastguard Worker * be to use a run-time "if" statement or the conventional run-time "assert" mechanism, but 2421*5e7646d2SAndroid Build Coastguard Worker * then you don't find out what's wrong until you run the software. This way, if the assertion 2422*5e7646d2SAndroid Build Coastguard Worker * condition is false, the array size is negative, and the complier complains immediately. 2423*5e7646d2SAndroid Build Coastguard Worker */ 2424*5e7646d2SAndroid Build Coastguard Worker 2425*5e7646d2SAndroid Build Coastguard Worker struct CompileTimeAssertionChecks_DNS_SD 2426*5e7646d2SAndroid Build Coastguard Worker { 2427*5e7646d2SAndroid Build Coastguard Worker char assert0[(sizeof(union _TXTRecordRef_t) == 16) ? 1 : -1]; 2428*5e7646d2SAndroid Build Coastguard Worker }; 2429*5e7646d2SAndroid Build Coastguard Worker 2430*5e7646d2SAndroid Build Coastguard Worker #ifdef __cplusplus 2431*5e7646d2SAndroid Build Coastguard Worker } 2432*5e7646d2SAndroid Build Coastguard Worker #endif 2433*5e7646d2SAndroid Build Coastguard Worker 2434*5e7646d2SAndroid Build Coastguard Worker #endif /* _DNS_SD_H */ 2435