1*4904Srs200217 /* -*- Mode: C; tab-width: 4 -*- 2*4904Srs200217 * 3*4904Srs200217 * Copyright (c) 2003-2004, Apple Computer, Inc. All rights reserved. 4*4904Srs200217 * 5*4904Srs200217 * Redistribution and use in source and binary forms, with or without 6*4904Srs200217 * modification, are permitted provided that the following conditions are met: 7*4904Srs200217 * 8*4904Srs200217 * 1. Redistributions of source code must retain the above copyright notice, 9*4904Srs200217 * this list of conditions and the following disclaimer. 10*4904Srs200217 * 2. Redistributions in binary form must reproduce the above copyright notice, 11*4904Srs200217 * this list of conditions and the following disclaimer in the documentation 12*4904Srs200217 * and/or other materials provided with the distribution. 13*4904Srs200217 * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of its 14*4904Srs200217 * contributors may be used to endorse or promote products derived from this 15*4904Srs200217 * software without specific prior written permission. 16*4904Srs200217 * 17*4904Srs200217 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY 18*4904Srs200217 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19*4904Srs200217 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20*4904Srs200217 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY 21*4904Srs200217 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22*4904Srs200217 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23*4904Srs200217 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24*4904Srs200217 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25*4904Srs200217 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26*4904Srs200217 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27*4904Srs200217 */ 28*4904Srs200217 29*4904Srs200217 #pragma ident "%Z%%M% %I% %E% SMI" 30*4904Srs200217 31*4904Srs200217 #ifndef _DNS_SD_H 32*4904Srs200217 #define _DNS_SD_H 33*4904Srs200217 34*4904Srs200217 #ifdef __cplusplus 35*4904Srs200217 extern "C" { 36*4904Srs200217 #endif 37*4904Srs200217 38*4904Srs200217 /* standard calling convention under Win32 is __stdcall */ 39*4904Srs200217 /* Note: When compiling Intel EFI (Extensible Firmware Interface) under MS Visual Studio, the */ 40*4904Srs200217 /* _WIN32 symbol is defined by the compiler even though it's NOT compiling code for Windows32 */ 41*4904Srs200217 #if defined(_WIN32) && !defined(EFI32) && !defined(EFI64) 42*4904Srs200217 #define DNSSD_API __stdcall 43*4904Srs200217 #else 44*4904Srs200217 #define DNSSD_API 45*4904Srs200217 #endif 46*4904Srs200217 47*4904Srs200217 /* stdint.h does not exist on FreeBSD 4.x; its types are defined in sys/types.h instead */ 48*4904Srs200217 #if defined(__FreeBSD__) && (__FreeBSD__ < 5) 49*4904Srs200217 #include <sys/types.h> 50*4904Srs200217 51*4904Srs200217 /* Likewise, on Sun, standard integer types are in sys/types.h */ 52*4904Srs200217 #elif defined(__sun__) 53*4904Srs200217 #include <sys/types.h> 54*4904Srs200217 55*4904Srs200217 /* EFI does not have stdint.h, or anything else equivalent */ 56*4904Srs200217 #elif defined(EFI32) || defined(EFI64) 57*4904Srs200217 typedef UINT8 uint8_t; 58*4904Srs200217 typedef INT8 int8_t; 59*4904Srs200217 typedef UINT16 uint16_t; 60*4904Srs200217 typedef INT16 int16_t; 61*4904Srs200217 typedef UINT32 uint32_t; 62*4904Srs200217 typedef INT32 int32_t; 63*4904Srs200217 64*4904Srs200217 /* Windows has its own differences */ 65*4904Srs200217 #elif defined(_WIN32) 66*4904Srs200217 #include <windows.h> 67*4904Srs200217 #define _UNUSED 68*4904Srs200217 #define bzero(a, b) memset(a, 0, b) 69*4904Srs200217 #ifndef _MSL_STDINT_H 70*4904Srs200217 typedef UINT8 uint8_t; 71*4904Srs200217 typedef INT8 int8_t; 72*4904Srs200217 typedef UINT16 uint16_t; 73*4904Srs200217 typedef INT16 int16_t; 74*4904Srs200217 typedef UINT32 uint32_t; 75*4904Srs200217 typedef INT32 int32_t; 76*4904Srs200217 #endif 77*4904Srs200217 78*4904Srs200217 /* All other Posix platforms use stdint.h */ 79*4904Srs200217 #else 80*4904Srs200217 #include <stdint.h> 81*4904Srs200217 #include <strings.h> 82*4904Srs200217 #endif 83*4904Srs200217 84*4904Srs200217 /* DNSServiceRef, DNSRecordRef 85*4904Srs200217 * 86*4904Srs200217 * Opaque internal data types. 87*4904Srs200217 * Note: client is responsible for serializing access to these structures if 88*4904Srs200217 * they are shared between concurrent threads. 89*4904Srs200217 */ 90*4904Srs200217 91*4904Srs200217 typedef struct _DNSServiceRef_t *DNSServiceRef; 92*4904Srs200217 typedef struct _DNSRecordRef_t *DNSRecordRef; 93*4904Srs200217 94*4904Srs200217 /* General flags used in functions defined below */ 95*4904Srs200217 enum 96*4904Srs200217 { 97*4904Srs200217 kDNSServiceFlagsMoreComing = 0x1, 98*4904Srs200217 /* MoreComing indicates to a callback that at least one more result is 99*4904Srs200217 * queued and will be delivered following immediately after this one. 100*4904Srs200217 * Applications should not update their UI to display browse 101*4904Srs200217 * results when the MoreComing flag is set, because this would 102*4904Srs200217 * result in a great deal of ugly flickering on the screen. 103*4904Srs200217 * Applications should instead wait until until MoreComing is not set, 104*4904Srs200217 * and then update their UI. 105*4904Srs200217 * When MoreComing is not set, that doesn't mean there will be no more 106*4904Srs200217 * answers EVER, just that there are no more answers immediately 107*4904Srs200217 * available right now at this instant. If more answers become available 108*4904Srs200217 * in the future they will be delivered as usual. 109*4904Srs200217 */ 110*4904Srs200217 111*4904Srs200217 kDNSServiceFlagsAdd = 0x2, 112*4904Srs200217 kDNSServiceFlagsDefault = 0x4, 113*4904Srs200217 /* Flags for domain enumeration and browse/query reply callbacks. 114*4904Srs200217 * "Default" applies only to enumeration and is only valid in 115*4904Srs200217 * conjuction with "Add". An enumeration callback with the "Add" 116*4904Srs200217 * flag NOT set indicates a "Remove", i.e. the domain is no longer 117*4904Srs200217 * valid. 118*4904Srs200217 */ 119*4904Srs200217 120*4904Srs200217 kDNSServiceFlagsNoAutoRename = 0x8, 121*4904Srs200217 /* Flag for specifying renaming behavior on name conflict when registering 122*4904Srs200217 * non-shared records. By default, name conflicts are automatically handled 123*4904Srs200217 * by renaming the service. NoAutoRename overrides this behavior - with this 124*4904Srs200217 * flag set, name conflicts will result in a callback. The NoAutorename flag 125*4904Srs200217 * is only valid if a name is explicitly specified when registering a service 126*4904Srs200217 * (i.e. the default name is not used.) 127*4904Srs200217 */ 128*4904Srs200217 129*4904Srs200217 kDNSServiceFlagsShared = 0x10, 130*4904Srs200217 kDNSServiceFlagsUnique = 0x20, 131*4904Srs200217 /* Flag for registering individual records on a connected 132*4904Srs200217 * DNSServiceRef. Shared indicates that there may be multiple records 133*4904Srs200217 * with this name on the network (e.g. PTR records). Unique indicates that the 134*4904Srs200217 * record's name is to be unique on the network (e.g. SRV records). 135*4904Srs200217 */ 136*4904Srs200217 137*4904Srs200217 kDNSServiceFlagsBrowseDomains = 0x40, 138*4904Srs200217 kDNSServiceFlagsRegistrationDomains = 0x80, 139*4904Srs200217 /* Flags for specifying domain enumeration type in DNSServiceEnumerateDomains. 140*4904Srs200217 * BrowseDomains enumerates domains recommended for browsing, RegistrationDomains 141*4904Srs200217 * enumerates domains recommended for registration. 142*4904Srs200217 */ 143*4904Srs200217 144*4904Srs200217 kDNSServiceFlagsLongLivedQuery = 0x100, 145*4904Srs200217 /* Flag for creating a long-lived unicast query for the DNSServiceQueryRecord call. */ 146*4904Srs200217 147*4904Srs200217 kDNSServiceFlagsAllowRemoteQuery = 0x200, 148*4904Srs200217 /* Flag for creating a record for which we will answer remote queries 149*4904Srs200217 * (queries from hosts more than one hop away; hosts not directly connected to the local link). 150*4904Srs200217 */ 151*4904Srs200217 152*4904Srs200217 kDNSServiceFlagsForceMulticast = 0x400, 153*4904Srs200217 /* Flag for signifying that a query or registration should be performed exclusively via multicast DNS, 154*4904Srs200217 * even for a name in a domain (e.g. foo.apple.com.) that would normally imply unicast DNS. 155*4904Srs200217 */ 156*4904Srs200217 157*4904Srs200217 kDNSServiceFlagsReturnCNAME = 0x800 158*4904Srs200217 /* Flag for returning CNAME records in the DNSServiceQueryRecord call. CNAME records are 159*4904Srs200217 * normally followed without indicating to the client that there was a CNAME record. 160*4904Srs200217 */ 161*4904Srs200217 }; 162*4904Srs200217 163*4904Srs200217 /* 164*4904Srs200217 * The values for DNS Classes and Types are listed in RFC 1035, and are available 165*4904Srs200217 * on every OS in its DNS header file. Unfortunately every OS does not have the 166*4904Srs200217 * same header file containing DNS Class and Type constants, and the names of 167*4904Srs200217 * the constants are not consistent. For example, BIND 8 uses "T_A", 168*4904Srs200217 * BIND 9 uses "ns_t_a", Windows uses "DNS_TYPE_A", etc. 169*4904Srs200217 * For this reason, these constants are also listed here, so that code using 170*4904Srs200217 * the DNS-SD programming APIs can use these constants, so that the same code 171*4904Srs200217 * can compile on all our supported platforms. 172*4904Srs200217 */ 173*4904Srs200217 174*4904Srs200217 enum 175*4904Srs200217 { 176*4904Srs200217 kDNSServiceClass_IN = 1 /* Internet */ 177*4904Srs200217 }; 178*4904Srs200217 179*4904Srs200217 enum 180*4904Srs200217 { 181*4904Srs200217 kDNSServiceType_A = 1, /* Host address. */ 182*4904Srs200217 kDNSServiceType_NS = 2, /* Authoritative server. */ 183*4904Srs200217 kDNSServiceType_MD = 3, /* Mail destination. */ 184*4904Srs200217 kDNSServiceType_MF = 4, /* Mail forwarder. */ 185*4904Srs200217 kDNSServiceType_CNAME = 5, /* Canonical name. */ 186*4904Srs200217 kDNSServiceType_SOA = 6, /* Start of authority zone. */ 187*4904Srs200217 kDNSServiceType_MB = 7, /* Mailbox domain name. */ 188*4904Srs200217 kDNSServiceType_MG = 8, /* Mail group member. */ 189*4904Srs200217 kDNSServiceType_MR = 9, /* Mail rename name. */ 190*4904Srs200217 kDNSServiceType_NULL = 10, /* Null resource record. */ 191*4904Srs200217 kDNSServiceType_WKS = 11, /* Well known service. */ 192*4904Srs200217 kDNSServiceType_PTR = 12, /* Domain name pointer. */ 193*4904Srs200217 kDNSServiceType_HINFO = 13, /* Host information. */ 194*4904Srs200217 kDNSServiceType_MINFO = 14, /* Mailbox information. */ 195*4904Srs200217 kDNSServiceType_MX = 15, /* Mail routing information. */ 196*4904Srs200217 kDNSServiceType_TXT = 16, /* One or more text strings. */ 197*4904Srs200217 kDNSServiceType_RP = 17, /* Responsible person. */ 198*4904Srs200217 kDNSServiceType_AFSDB = 18, /* AFS cell database. */ 199*4904Srs200217 kDNSServiceType_X25 = 19, /* X_25 calling address. */ 200*4904Srs200217 kDNSServiceType_ISDN = 20, /* ISDN calling address. */ 201*4904Srs200217 kDNSServiceType_RT = 21, /* Router. */ 202*4904Srs200217 kDNSServiceType_NSAP = 22, /* NSAP address. */ 203*4904Srs200217 kDNSServiceType_NSAP_PTR = 23, /* Reverse NSAP lookup (deprecated). */ 204*4904Srs200217 kDNSServiceType_SIG = 24, /* Security signature. */ 205*4904Srs200217 kDNSServiceType_KEY = 25, /* Security key. */ 206*4904Srs200217 kDNSServiceType_PX = 26, /* X.400 mail mapping. */ 207*4904Srs200217 kDNSServiceType_GPOS = 27, /* Geographical position (withdrawn). */ 208*4904Srs200217 kDNSServiceType_AAAA = 28, /* IPv6 Address. */ 209*4904Srs200217 kDNSServiceType_LOC = 29, /* Location Information. */ 210*4904Srs200217 kDNSServiceType_NXT = 30, /* Next domain (security). */ 211*4904Srs200217 kDNSServiceType_EID = 31, /* Endpoint identifier. */ 212*4904Srs200217 kDNSServiceType_NIMLOC = 32, /* Nimrod Locator. */ 213*4904Srs200217 kDNSServiceType_SRV = 33, /* Server Selection. */ 214*4904Srs200217 kDNSServiceType_ATMA = 34, /* ATM Address */ 215*4904Srs200217 kDNSServiceType_NAPTR = 35, /* Naming Authority PoinTeR */ 216*4904Srs200217 kDNSServiceType_KX = 36, /* Key Exchange */ 217*4904Srs200217 kDNSServiceType_CERT = 37, /* Certification record */ 218*4904Srs200217 kDNSServiceType_A6 = 38, /* IPv6 Address (deprecated) */ 219*4904Srs200217 kDNSServiceType_DNAME = 39, /* Non-terminal DNAME (for IPv6) */ 220*4904Srs200217 kDNSServiceType_SINK = 40, /* Kitchen sink (experimentatl) */ 221*4904Srs200217 kDNSServiceType_OPT = 41, /* EDNS0 option (meta-RR) */ 222*4904Srs200217 kDNSServiceType_TKEY = 249, /* Transaction key */ 223*4904Srs200217 kDNSServiceType_TSIG = 250, /* Transaction signature. */ 224*4904Srs200217 kDNSServiceType_IXFR = 251, /* Incremental zone transfer. */ 225*4904Srs200217 kDNSServiceType_AXFR = 252, /* Transfer zone of authority. */ 226*4904Srs200217 kDNSServiceType_MAILB = 253, /* Transfer mailbox records. */ 227*4904Srs200217 kDNSServiceType_MAILA = 254, /* Transfer mail agent records. */ 228*4904Srs200217 kDNSServiceType_ANY = 255 /* Wildcard match. */ 229*4904Srs200217 }; 230*4904Srs200217 231*4904Srs200217 232*4904Srs200217 /* possible error code values */ 233*4904Srs200217 enum 234*4904Srs200217 { 235*4904Srs200217 kDNSServiceErr_NoError = 0, 236*4904Srs200217 kDNSServiceErr_Unknown = -65537, /* 0xFFFE FFFF */ 237*4904Srs200217 kDNSServiceErr_NoSuchName = -65538, 238*4904Srs200217 kDNSServiceErr_NoMemory = -65539, 239*4904Srs200217 kDNSServiceErr_BadParam = -65540, 240*4904Srs200217 kDNSServiceErr_BadReference = -65541, 241*4904Srs200217 kDNSServiceErr_BadState = -65542, 242*4904Srs200217 kDNSServiceErr_BadFlags = -65543, 243*4904Srs200217 kDNSServiceErr_Unsupported = -65544, 244*4904Srs200217 kDNSServiceErr_NotInitialized = -65545, 245*4904Srs200217 kDNSServiceErr_AlreadyRegistered = -65547, 246*4904Srs200217 kDNSServiceErr_NameConflict = -65548, 247*4904Srs200217 kDNSServiceErr_Invalid = -65549, 248*4904Srs200217 kDNSServiceErr_Firewall = -65550, 249*4904Srs200217 kDNSServiceErr_Incompatible = -65551, /* client library incompatible with daemon */ 250*4904Srs200217 kDNSServiceErr_BadInterfaceIndex = -65552, 251*4904Srs200217 kDNSServiceErr_Refused = -65553, 252*4904Srs200217 kDNSServiceErr_NoSuchRecord = -65554, 253*4904Srs200217 kDNSServiceErr_NoAuth = -65555, 254*4904Srs200217 kDNSServiceErr_NoSuchKey = -65556, 255*4904Srs200217 kDNSServiceErr_NATTraversal = -65557, 256*4904Srs200217 kDNSServiceErr_DoubleNAT = -65558, 257*4904Srs200217 kDNSServiceErr_BadTime = -65559 258*4904Srs200217 /* mDNS Error codes are in the range 259*4904Srs200217 * FFFE FF00 (-65792) to FFFE FFFF (-65537) */ 260*4904Srs200217 }; 261*4904Srs200217 262*4904Srs200217 263*4904Srs200217 /* Maximum length, in bytes, of a service name represented as a */ 264*4904Srs200217 /* literal C-String, including the terminating NULL at the end. */ 265*4904Srs200217 266*4904Srs200217 #define kDNSServiceMaxServiceName 64 267*4904Srs200217 268*4904Srs200217 /* Maximum length, in bytes, of a domain name represented as an *escaped* C-String */ 269*4904Srs200217 /* including the final trailing dot, and the C-String terminating NULL at the end. */ 270*4904Srs200217 271*4904Srs200217 #define kDNSServiceMaxDomainName 1005 272*4904Srs200217 273*4904Srs200217 /* 274*4904Srs200217 * Notes on DNS Name Escaping 275*4904Srs200217 * -- or -- 276*4904Srs200217 * "Why is kDNSServiceMaxDomainName 1005, when the maximum legal domain name is 255 bytes?" 277*4904Srs200217 * 278*4904Srs200217 * All strings used in DNS-SD are UTF-8 strings. 279*4904Srs200217 * With few exceptions, most are also escaped using standard DNS escaping rules: 280*4904Srs200217 * 281*4904Srs200217 * '\\' represents a single literal '\' in the name 282*4904Srs200217 * '\.' represents a single literal '.' in the name 283*4904Srs200217 * '\ddd', where ddd is a three-digit decimal value from 000 to 255, 284*4904Srs200217 * represents a single literal byte with that value. 285*4904Srs200217 * A bare unescaped '.' is a label separator, marking a boundary between domain and subdomain. 286*4904Srs200217 * 287*4904Srs200217 * The exceptions, that do not use escaping, are the routines where the full 288*4904Srs200217 * DNS name of a resource is broken, for convenience, into servicename/regtype/domain. 289*4904Srs200217 * In these routines, the "servicename" is NOT escaped. It does not need to be, since 290*4904Srs200217 * it is, by definition, just a single literal string. Any characters in that string 291*4904Srs200217 * represent exactly what they are. The "regtype" portion is, technically speaking, 292*4904Srs200217 * escaped, but since legal regtypes are only allowed to contain letters, digits, 293*4904Srs200217 * and hyphens, there is nothing to escape, so the issue is moot. The "domain" 294*4904Srs200217 * portion is also escaped, though most domains in use on the public Internet 295*4904Srs200217 * today, like regtypes, don't contain any characters that need to be escaped. 296*4904Srs200217 * As DNS-SD becomes more popular, rich-text domains for service discovery will 297*4904Srs200217 * become common, so software should be written to cope with domains with escaping. 298*4904Srs200217 * 299*4904Srs200217 * The servicename may be up to 63 bytes of UTF-8 text (not counting the C-String 300*4904Srs200217 * terminating NULL at the end). The regtype is of the form _service._tcp or 301*4904Srs200217 * _service._udp, where the "service" part is 1-14 characters, which may be 302*4904Srs200217 * letters, digits, or hyphens. The domain part of the three-part name may be 303*4904Srs200217 * any legal domain, providing that the resulting servicename+regtype+domain 304*4904Srs200217 * name does not exceed 255 bytes. 305*4904Srs200217 * 306*4904Srs200217 * For most software, these issues are transparent. When browsing, the discovered 307*4904Srs200217 * servicenames should simply be displayed as-is. When resolving, the discovered 308*4904Srs200217 * servicename/regtype/domain are simply passed unchanged to DNSServiceResolve(). 309*4904Srs200217 * When a DNSServiceResolve() succeeds, the returned fullname is already in 310*4904Srs200217 * the correct format to pass to standard system DNS APIs such as res_query(). 311*4904Srs200217 * For converting from servicename/regtype/domain to a single properly-escaped 312*4904Srs200217 * full DNS name, the helper function DNSServiceConstructFullName() is provided. 313*4904Srs200217 * 314*4904Srs200217 * The following (highly contrived) example illustrates the escaping process. 315*4904Srs200217 * Suppose you have an service called "Dr. Smith\Dr. Johnson", of type "_ftp._tcp" 316*4904Srs200217 * in subdomain "4th. Floor" of subdomain "Building 2" of domain "apple.com." 317*4904Srs200217 * The full (escaped) DNS name of this service's SRV record would be: 318*4904Srs200217 * Dr\.\032Smith\\Dr\.\032Johnson._ftp._tcp.4th\.\032Floor.Building\0322.apple.com. 319*4904Srs200217 */ 320*4904Srs200217 321*4904Srs200217 322*4904Srs200217 /* 323*4904Srs200217 * Constants for specifying an interface index 324*4904Srs200217 * 325*4904Srs200217 * Specific interface indexes are identified via a 32-bit unsigned integer returned 326*4904Srs200217 * by the if_nametoindex() family of calls. 327*4904Srs200217 * 328*4904Srs200217 * If the client passes 0 for interface index, that means "do the right thing", 329*4904Srs200217 * which (at present) means, "if the name is in an mDNS local multicast domain 330*4904Srs200217 * (e.g. 'local.', '254.169.in-addr.arpa.', '{8,9,A,B}.E.F.ip6.arpa.') then multicast 331*4904Srs200217 * on all applicable interfaces, otherwise send via unicast to the appropriate 332*4904Srs200217 * DNS server." Normally, most clients will use 0 for interface index to 333*4904Srs200217 * automatically get the default sensible behaviour. 334*4904Srs200217 * 335*4904Srs200217 * If the client passes a positive interface index, then for multicast names that 336*4904Srs200217 * indicates to do the operation only on that one interface. For unicast names the 337*4904Srs200217 * interface index is ignored unless kDNSServiceFlagsForceMulticast is also set. 338*4904Srs200217 * 339*4904Srs200217 * If the client passes kDNSServiceInterfaceIndexLocalOnly when registering 340*4904Srs200217 * a service, then that service will be found *only* by other local clients 341*4904Srs200217 * on the same machine that are browsing using kDNSServiceInterfaceIndexLocalOnly 342*4904Srs200217 * or kDNSServiceInterfaceIndexAny. 343*4904Srs200217 * If a client has a 'private' service, accessible only to other processes 344*4904Srs200217 * running on the same machine, this allows the client to advertise that service 345*4904Srs200217 * in a way such that it does not inadvertently appear in service lists on 346*4904Srs200217 * all the other machines on the network. 347*4904Srs200217 * 348*4904Srs200217 * If the client passes kDNSServiceInterfaceIndexLocalOnly when browsing 349*4904Srs200217 * then it will find *all* records registered on that same local machine. 350*4904Srs200217 * Clients explicitly wishing to discover *only* LocalOnly services can 351*4904Srs200217 * accomplish this by inspecting the interfaceIndex of each service reported 352*4904Srs200217 * to their DNSServiceBrowseReply() callback function, and discarding those 353*4904Srs200217 * where the interface index is not kDNSServiceInterfaceIndexLocalOnly. 354*4904Srs200217 */ 355*4904Srs200217 356*4904Srs200217 #define kDNSServiceInterfaceIndexAny 0 357*4904Srs200217 #define kDNSServiceInterfaceIndexLocalOnly ( (uint32_t) -1 ) 358*4904Srs200217 359*4904Srs200217 360*4904Srs200217 typedef uint32_t DNSServiceFlags; 361*4904Srs200217 typedef int32_t DNSServiceErrorType; 362*4904Srs200217 363*4904Srs200217 364*4904Srs200217 /********************************************************************************************* 365*4904Srs200217 * 366*4904Srs200217 * Unix Domain Socket access, DNSServiceRef deallocation, and data processing functions 367*4904Srs200217 * 368*4904Srs200217 *********************************************************************************************/ 369*4904Srs200217 370*4904Srs200217 371*4904Srs200217 /* DNSServiceRefSockFD() 372*4904Srs200217 * 373*4904Srs200217 * Access underlying Unix domain socket for an initialized DNSServiceRef. 374*4904Srs200217 * The DNS Service Discovery implmementation uses this socket to communicate between 375*4904Srs200217 * the client and the mDNSResponder daemon. The application MUST NOT directly read from 376*4904Srs200217 * or write to this socket. Access to the socket is provided so that it can be used as a 377*4904Srs200217 * run loop source, or in a select() loop: when data is available for reading on the socket, 378*4904Srs200217 * DNSServiceProcessResult() should be called, which will extract the daemon's reply from 379*4904Srs200217 * the socket, and pass it to the appropriate application callback. By using a run loop or 380*4904Srs200217 * select(), results from the daemon can be processed asynchronously. Without using these 381*4904Srs200217 * constructs, DNSServiceProcessResult() will block until the response from the daemon arrives. 382*4904Srs200217 * The client is responsible for ensuring that the data on the socket is processed in a timely 383*4904Srs200217 * fashion - the daemon may terminate its connection with a client that does not clear its 384*4904Srs200217 * socket buffer. 385*4904Srs200217 * 386*4904Srs200217 * sdRef: A DNSServiceRef initialized by any of the DNSService calls. 387*4904Srs200217 * 388*4904Srs200217 * return value: The DNSServiceRef's underlying socket descriptor, or -1 on 389*4904Srs200217 * error. 390*4904Srs200217 */ 391*4904Srs200217 392*4904Srs200217 int DNSSD_API DNSServiceRefSockFD(DNSServiceRef sdRef); 393*4904Srs200217 394*4904Srs200217 395*4904Srs200217 /* DNSServiceProcessResult() 396*4904Srs200217 * 397*4904Srs200217 * Read a reply from the daemon, calling the appropriate application callback. This call will 398*4904Srs200217 * block until the daemon's response is received. Use DNSServiceRefSockFD() in 399*4904Srs200217 * conjunction with a run loop or select() to determine the presence of a response from the 400*4904Srs200217 * server before calling this function to process the reply without blocking. Call this function 401*4904Srs200217 * at any point if it is acceptable to block until the daemon's response arrives. Note that the 402*4904Srs200217 * client is responsible for ensuring that DNSServiceProcessResult() is called whenever there is 403*4904Srs200217 * a reply from the daemon - the daemon may terminate its connection with a client that does not 404*4904Srs200217 * process the daemon's responses. 405*4904Srs200217 * 406*4904Srs200217 * sdRef: A DNSServiceRef initialized by any of the DNSService calls 407*4904Srs200217 * that take a callback parameter. 408*4904Srs200217 * 409*4904Srs200217 * return value: Returns kDNSServiceErr_NoError on success, otherwise returns 410*4904Srs200217 * an error code indicating the specific failure that occurred. 411*4904Srs200217 */ 412*4904Srs200217 413*4904Srs200217 DNSServiceErrorType DNSSD_API DNSServiceProcessResult(DNSServiceRef sdRef); 414*4904Srs200217 415*4904Srs200217 416*4904Srs200217 /* DNSServiceRefDeallocate() 417*4904Srs200217 * 418*4904Srs200217 * Terminate a connection with the daemon and free memory associated with the DNSServiceRef. 419*4904Srs200217 * Any services or records registered with this DNSServiceRef will be deregistered. Any 420*4904Srs200217 * Browse, Resolve, or Query operations called with this reference will be terminated. 421*4904Srs200217 * 422*4904Srs200217 * Note: If the reference's underlying socket is used in a run loop or select() call, it should 423*4904Srs200217 * be removed BEFORE DNSServiceRefDeallocate() is called, as this function closes the reference's 424*4904Srs200217 * socket. 425*4904Srs200217 * 426*4904Srs200217 * Note: If the reference was initialized with DNSServiceCreateConnection(), any DNSRecordRefs 427*4904Srs200217 * created via this reference will be invalidated by this call - the resource records are 428*4904Srs200217 * deregistered, and their DNSRecordRefs may not be used in subsequent functions. Similarly, 429*4904Srs200217 * if the reference was initialized with DNSServiceRegister, and an extra resource record was 430*4904Srs200217 * added to the service via DNSServiceAddRecord(), the DNSRecordRef created by the Add() call 431*4904Srs200217 * is invalidated when this function is called - the DNSRecordRef may not be used in subsequent 432*4904Srs200217 * functions. 433*4904Srs200217 * 434*4904Srs200217 * Note: This call is to be used only with the DNSServiceRef defined by this API. It is 435*4904Srs200217 * not compatible with dns_service_discovery_ref objects defined in the legacy Mach-based 436*4904Srs200217 * DNSServiceDiscovery.h API. 437*4904Srs200217 * 438*4904Srs200217 * sdRef: A DNSServiceRef initialized by any of the DNSService calls. 439*4904Srs200217 * 440*4904Srs200217 */ 441*4904Srs200217 442*4904Srs200217 void DNSSD_API DNSServiceRefDeallocate(DNSServiceRef sdRef); 443*4904Srs200217 444*4904Srs200217 445*4904Srs200217 /********************************************************************************************* 446*4904Srs200217 * 447*4904Srs200217 * Domain Enumeration 448*4904Srs200217 * 449*4904Srs200217 *********************************************************************************************/ 450*4904Srs200217 451*4904Srs200217 /* DNSServiceEnumerateDomains() 452*4904Srs200217 * 453*4904Srs200217 * Asynchronously enumerate domains available for browsing and registration. 454*4904Srs200217 * 455*4904Srs200217 * The enumeration MUST be cancelled via DNSServiceRefDeallocate() when no more domains 456*4904Srs200217 * are to be found. 457*4904Srs200217 * 458*4904Srs200217 * Note that the names returned are (like all of DNS-SD) UTF-8 strings, 459*4904Srs200217 * and are escaped using standard DNS escaping rules. 460*4904Srs200217 * (See "Notes on DNS Name Escaping" earlier in this file for more details.) 461*4904Srs200217 * A graphical browser displaying a hierarchical tree-structured view should cut 462*4904Srs200217 * the names at the bare dots to yield individual labels, then de-escape each 463*4904Srs200217 * label according to the escaping rules, and then display the resulting UTF-8 text. 464*4904Srs200217 * 465*4904Srs200217 * DNSServiceDomainEnumReply Callback Parameters: 466*4904Srs200217 * 467*4904Srs200217 * sdRef: The DNSServiceRef initialized by DNSServiceEnumerateDomains(). 468*4904Srs200217 * 469*4904Srs200217 * flags: Possible values are: 470*4904Srs200217 * kDNSServiceFlagsMoreComing 471*4904Srs200217 * kDNSServiceFlagsAdd 472*4904Srs200217 * kDNSServiceFlagsDefault 473*4904Srs200217 * 474*4904Srs200217 * interfaceIndex: Specifies the interface on which the domain exists. (The index for a given 475*4904Srs200217 * interface is determined via the if_nametoindex() family of calls.) 476*4904Srs200217 * 477*4904Srs200217 * errorCode: Will be kDNSServiceErr_NoError (0) on success, otherwise indicates 478*4904Srs200217 * the failure that occurred (other parameters are undefined if errorCode is nonzero). 479*4904Srs200217 * 480*4904Srs200217 * replyDomain: The name of the domain. 481*4904Srs200217 * 482*4904Srs200217 * context: The context pointer passed to DNSServiceEnumerateDomains. 483*4904Srs200217 * 484*4904Srs200217 */ 485*4904Srs200217 486*4904Srs200217 typedef void (DNSSD_API *DNSServiceDomainEnumReply) 487*4904Srs200217 ( 488*4904Srs200217 DNSServiceRef sdRef, 489*4904Srs200217 DNSServiceFlags flags, 490*4904Srs200217 uint32_t interfaceIndex, 491*4904Srs200217 DNSServiceErrorType errorCode, 492*4904Srs200217 const char *replyDomain, 493*4904Srs200217 void *context 494*4904Srs200217 ); 495*4904Srs200217 496*4904Srs200217 497*4904Srs200217 /* DNSServiceEnumerateDomains() Parameters: 498*4904Srs200217 * 499*4904Srs200217 * 500*4904Srs200217 * sdRef: A pointer to an uninitialized DNSServiceRef. If the call succeeds 501*4904Srs200217 * then it initializes the DNSServiceRef, returns kDNSServiceErr_NoError, 502*4904Srs200217 * and the enumeration operation will run indefinitely until the client 503*4904Srs200217 * terminates it by passing this DNSServiceRef to DNSServiceRefDeallocate(). 504*4904Srs200217 * 505*4904Srs200217 * flags: Possible values are: 506*4904Srs200217 * kDNSServiceFlagsBrowseDomains to enumerate domains recommended for browsing. 507*4904Srs200217 * kDNSServiceFlagsRegistrationDomains to enumerate domains recommended 508*4904Srs200217 * for registration. 509*4904Srs200217 * 510*4904Srs200217 * interfaceIndex: If non-zero, specifies the interface on which to look for domains. 511*4904Srs200217 * (the index for a given interface is determined via the if_nametoindex() 512*4904Srs200217 * family of calls.) Most applications will pass 0 to enumerate domains on 513*4904Srs200217 * all interfaces. See "Constants for specifying an interface index" for more details. 514*4904Srs200217 * 515*4904Srs200217 * callBack: The function to be called when a domain is found or the call asynchronously 516*4904Srs200217 * fails. 517*4904Srs200217 * 518*4904Srs200217 * context: An application context pointer which is passed to the callback function 519*4904Srs200217 * (may be NULL). 520*4904Srs200217 * 521*4904Srs200217 * return value: Returns kDNSServiceErr_NoError on succeses (any subsequent, asynchronous 522*4904Srs200217 * errors are delivered to the callback), otherwise returns an error code indicating 523*4904Srs200217 * the error that occurred (the callback is not invoked and the DNSServiceRef 524*4904Srs200217 * is not initialized.) 525*4904Srs200217 */ 526*4904Srs200217 527*4904Srs200217 DNSServiceErrorType DNSSD_API DNSServiceEnumerateDomains 528*4904Srs200217 ( 529*4904Srs200217 DNSServiceRef *sdRef, 530*4904Srs200217 DNSServiceFlags flags, 531*4904Srs200217 uint32_t interfaceIndex, 532*4904Srs200217 DNSServiceDomainEnumReply callBack, 533*4904Srs200217 void *context /* may be NULL */ 534*4904Srs200217 ); 535*4904Srs200217 536*4904Srs200217 537*4904Srs200217 /********************************************************************************************* 538*4904Srs200217 * 539*4904Srs200217 * Service Registration 540*4904Srs200217 * 541*4904Srs200217 *********************************************************************************************/ 542*4904Srs200217 543*4904Srs200217 /* Register a service that is discovered via Browse() and Resolve() calls. 544*4904Srs200217 * 545*4904Srs200217 * 546*4904Srs200217 * DNSServiceRegisterReply() Callback Parameters: 547*4904Srs200217 * 548*4904Srs200217 * sdRef: The DNSServiceRef initialized by DNSServiceRegister(). 549*4904Srs200217 * 550*4904Srs200217 * flags: Currently unused, reserved for future use. 551*4904Srs200217 * 552*4904Srs200217 * errorCode: Will be kDNSServiceErr_NoError on success, otherwise will 553*4904Srs200217 * indicate the failure that occurred (including name conflicts, 554*4904Srs200217 * if the kDNSServiceFlagsNoAutoRename flag was used when registering.) 555*4904Srs200217 * Other parameters are undefined if errorCode is nonzero. 556*4904Srs200217 * 557*4904Srs200217 * name: The service name registered (if the application did not specify a name in 558*4904Srs200217 * DNSServiceRegister(), this indicates what name was automatically chosen). 559*4904Srs200217 * 560*4904Srs200217 * regtype: The type of service registered, as it was passed to the callout. 561*4904Srs200217 * 562*4904Srs200217 * domain: The domain on which the service was registered (if the application did not 563*4904Srs200217 * specify a domain in DNSServiceRegister(), this indicates the default domain 564*4904Srs200217 * on which the service was registered). 565*4904Srs200217 * 566*4904Srs200217 * context: The context pointer that was passed to the callout. 567*4904Srs200217 * 568*4904Srs200217 */ 569*4904Srs200217 570*4904Srs200217 typedef void (DNSSD_API *DNSServiceRegisterReply) 571*4904Srs200217 ( 572*4904Srs200217 DNSServiceRef sdRef, 573*4904Srs200217 DNSServiceFlags flags, 574*4904Srs200217 DNSServiceErrorType errorCode, 575*4904Srs200217 const char *name, 576*4904Srs200217 const char *regtype, 577*4904Srs200217 const char *domain, 578*4904Srs200217 void *context 579*4904Srs200217 ); 580*4904Srs200217 581*4904Srs200217 582*4904Srs200217 /* DNSServiceRegister() Parameters: 583*4904Srs200217 * 584*4904Srs200217 * sdRef: A pointer to an uninitialized DNSServiceRef. If the call succeeds 585*4904Srs200217 * then it initializes the DNSServiceRef, returns kDNSServiceErr_NoError, 586*4904Srs200217 * and the registration will remain active indefinitely until the client 587*4904Srs200217 * terminates it by passing this DNSServiceRef to DNSServiceRefDeallocate(). 588*4904Srs200217 * 589*4904Srs200217 * interfaceIndex: If non-zero, specifies the interface on which to register the service 590*4904Srs200217 * (the index for a given interface is determined via the if_nametoindex() 591*4904Srs200217 * family of calls.) Most applications will pass 0 to register on all 592*4904Srs200217 * available interfaces. See "Constants for specifying an interface index" for more details. 593*4904Srs200217 * 594*4904Srs200217 * flags: Indicates the renaming behavior on name conflict (most applications 595*4904Srs200217 * will pass 0). See flag definitions above for details. 596*4904Srs200217 * 597*4904Srs200217 * name: If non-NULL, specifies the service name to be registered. 598*4904Srs200217 * Most applications will not specify a name, in which case the computer 599*4904Srs200217 * name is used (this name is communicated to the client via the callback). 600*4904Srs200217 * If a name is specified, it must be 1-63 bytes of UTF-8 text. 601*4904Srs200217 * If the name is longer than 63 bytes it will be automatically truncated 602*4904Srs200217 * to a legal length, unless the NoAutoRename flag is set, 603*4904Srs200217 * in which case kDNSServiceErr_BadParam will be returned. 604*4904Srs200217 * 605*4904Srs200217 * regtype: The service type followed by the protocol, separated by a dot 606*4904Srs200217 * (e.g. "_ftp._tcp"). The service type must be an underscore, followed 607*4904Srs200217 * by 1-14 characters, which may be letters, digits, or hyphens. 608*4904Srs200217 * The transport protocol must be "_tcp" or "_udp". New service types 609*4904Srs200217 * should be registered at <http://www.dns-sd.org/ServiceTypes.html>. 610*4904Srs200217 * 611*4904Srs200217 * domain: If non-NULL, specifies the domain on which to advertise the service. 612*4904Srs200217 * Most applications will not specify a domain, instead automatically 613*4904Srs200217 * registering in the default domain(s). 614*4904Srs200217 * 615*4904Srs200217 * host: If non-NULL, specifies the SRV target host name. Most applications 616*4904Srs200217 * will not specify a host, instead automatically using the machine's 617*4904Srs200217 * default host name(s). Note that specifying a non-NULL host does NOT 618*4904Srs200217 * create an address record for that host - the application is responsible 619*4904Srs200217 * for ensuring that the appropriate address record exists, or creating it 620*4904Srs200217 * via DNSServiceRegisterRecord(). 621*4904Srs200217 * 622*4904Srs200217 * port: The port, in network byte order, on which the service accepts connections. 623*4904Srs200217 * Pass 0 for a "placeholder" service (i.e. a service that will not be discovered 624*4904Srs200217 * by browsing, but will cause a name conflict if another client tries to 625*4904Srs200217 * register that same name). Most clients will not use placeholder services. 626*4904Srs200217 * 627*4904Srs200217 * txtLen: The length of the txtRecord, in bytes. Must be zero if the txtRecord is NULL. 628*4904Srs200217 * 629*4904Srs200217 * txtRecord: The TXT record rdata. A non-NULL txtRecord MUST be a properly formatted DNS 630*4904Srs200217 * TXT record, i.e. <length byte> <data> <length byte> <data> ... 631*4904Srs200217 * Passing NULL for the txtRecord is allowed as a synonym for txtLen=1, txtRecord="", 632*4904Srs200217 * i.e. it creates a TXT record of length one containing a single empty string. 633*4904Srs200217 * RFC 1035 doesn't allow a TXT record to contain *zero* strings, so a single empty 634*4904Srs200217 * string is the smallest legal DNS TXT record. 635*4904Srs200217 * As with the other parameters, the DNSServiceRegister call copies the txtRecord 636*4904Srs200217 * data; e.g. if you allocated the storage for the txtRecord parameter with malloc() 637*4904Srs200217 * then you can safely free that memory right after the DNSServiceRegister call returns. 638*4904Srs200217 * 639*4904Srs200217 * callBack: The function to be called when the registration completes or asynchronously 640*4904Srs200217 * fails. The client MAY pass NULL for the callback - The client will NOT be notified 641*4904Srs200217 * of the default values picked on its behalf, and the client will NOT be notified of any 642*4904Srs200217 * asynchronous errors (e.g. out of memory errors, etc.) that may prevent the registration 643*4904Srs200217 * of the service. The client may NOT pass the NoAutoRename flag if the callback is NULL. 644*4904Srs200217 * The client may still deregister the service at any time via DNSServiceRefDeallocate(). 645*4904Srs200217 * 646*4904Srs200217 * context: An application context pointer which is passed to the callback function 647*4904Srs200217 * (may be NULL). 648*4904Srs200217 * 649*4904Srs200217 * return value: Returns kDNSServiceErr_NoError on succeses (any subsequent, asynchronous 650*4904Srs200217 * errors are delivered to the callback), otherwise returns an error code indicating 651*4904Srs200217 * the error that occurred (the callback is never invoked and the DNSServiceRef 652*4904Srs200217 * is not initialized.) 653*4904Srs200217 */ 654*4904Srs200217 655*4904Srs200217 DNSServiceErrorType DNSSD_API DNSServiceRegister 656*4904Srs200217 ( 657*4904Srs200217 DNSServiceRef *sdRef, 658*4904Srs200217 DNSServiceFlags flags, 659*4904Srs200217 uint32_t interfaceIndex, 660*4904Srs200217 const char *name, /* may be NULL */ 661*4904Srs200217 const char *regtype, 662*4904Srs200217 const char *domain, /* may be NULL */ 663*4904Srs200217 const char *host, /* may be NULL */ 664*4904Srs200217 uint16_t port, 665*4904Srs200217 uint16_t txtLen, 666*4904Srs200217 const void *txtRecord, /* may be NULL */ 667*4904Srs200217 DNSServiceRegisterReply callBack, /* may be NULL */ 668*4904Srs200217 void *context /* may be NULL */ 669*4904Srs200217 ); 670*4904Srs200217 671*4904Srs200217 672*4904Srs200217 /* DNSServiceAddRecord() 673*4904Srs200217 * 674*4904Srs200217 * Add a record to a registered service. The name of the record will be the same as the 675*4904Srs200217 * registered service's name. 676*4904Srs200217 * The record can later be updated or deregistered by passing the RecordRef initialized 677*4904Srs200217 * by this function to DNSServiceUpdateRecord() or DNSServiceRemoveRecord(). 678*4904Srs200217 * 679*4904Srs200217 * Note that the DNSServiceAddRecord/UpdateRecord/RemoveRecord are *NOT* thread-safe 680*4904Srs200217 * with respect to a single DNSServiceRef. If you plan to have multiple threads 681*4904Srs200217 * in your program simultaneously add, update, or remove records from the same 682*4904Srs200217 * DNSServiceRef, then it's the caller's responsibility to use a mutext lock 683*4904Srs200217 * or take similar appropriate precautions to serialize those calls. 684*4904Srs200217 * 685*4904Srs200217 * 686*4904Srs200217 * Parameters; 687*4904Srs200217 * 688*4904Srs200217 * sdRef: A DNSServiceRef initialized by DNSServiceRegister(). 689*4904Srs200217 * 690*4904Srs200217 * RecordRef: A pointer to an uninitialized DNSRecordRef. Upon succesfull completion of this 691*4904Srs200217 * call, this ref may be passed to DNSServiceUpdateRecord() or DNSServiceRemoveRecord(). 692*4904Srs200217 * If the above DNSServiceRef is passed to DNSServiceRefDeallocate(), RecordRef is also 693*4904Srs200217 * invalidated and may not be used further. 694*4904Srs200217 * 695*4904Srs200217 * flags: Currently ignored, reserved for future use. 696*4904Srs200217 * 697*4904Srs200217 * rrtype: The type of the record (e.g. kDNSServiceType_TXT, kDNSServiceType_SRV, etc) 698*4904Srs200217 * 699*4904Srs200217 * rdlen: The length, in bytes, of the rdata. 700*4904Srs200217 * 701*4904Srs200217 * rdata: The raw rdata to be contained in the added resource record. 702*4904Srs200217 * 703*4904Srs200217 * ttl: The time to live of the resource record, in seconds. Pass 0 to use a default value. 704*4904Srs200217 * 705*4904Srs200217 * return value: Returns kDNSServiceErr_NoError on success, otherwise returns an 706*4904Srs200217 * error code indicating the error that occurred (the RecordRef is not initialized). 707*4904Srs200217 */ 708*4904Srs200217 709*4904Srs200217 DNSServiceErrorType DNSSD_API DNSServiceAddRecord 710*4904Srs200217 ( 711*4904Srs200217 DNSServiceRef sdRef, 712*4904Srs200217 DNSRecordRef *RecordRef, 713*4904Srs200217 DNSServiceFlags flags, 714*4904Srs200217 uint16_t rrtype, 715*4904Srs200217 uint16_t rdlen, 716*4904Srs200217 const void *rdata, 717*4904Srs200217 uint32_t ttl 718*4904Srs200217 ); 719*4904Srs200217 720*4904Srs200217 721*4904Srs200217 /* DNSServiceUpdateRecord 722*4904Srs200217 * 723*4904Srs200217 * Update a registered resource record. The record must either be: 724*4904Srs200217 * - The primary txt record of a service registered via DNSServiceRegister() 725*4904Srs200217 * - A record added to a registered service via DNSServiceAddRecord() 726*4904Srs200217 * - An individual record registered by DNSServiceRegisterRecord() 727*4904Srs200217 * 728*4904Srs200217 * 729*4904Srs200217 * Parameters: 730*4904Srs200217 * 731*4904Srs200217 * sdRef: A DNSServiceRef that was initialized by DNSServiceRegister() 732*4904Srs200217 * or DNSServiceCreateConnection(). 733*4904Srs200217 * 734*4904Srs200217 * RecordRef: A DNSRecordRef initialized by DNSServiceAddRecord, or NULL to update the 735*4904Srs200217 * service's primary txt record. 736*4904Srs200217 * 737*4904Srs200217 * flags: Currently ignored, reserved for future use. 738*4904Srs200217 * 739*4904Srs200217 * rdlen: The length, in bytes, of the new rdata. 740*4904Srs200217 * 741*4904Srs200217 * rdata: The new rdata to be contained in the updated resource record. 742*4904Srs200217 * 743*4904Srs200217 * ttl: The time to live of the updated resource record, in seconds. 744*4904Srs200217 * 745*4904Srs200217 * return value: Returns kDNSServiceErr_NoError on success, otherwise returns an 746*4904Srs200217 * error code indicating the error that occurred. 747*4904Srs200217 */ 748*4904Srs200217 749*4904Srs200217 DNSServiceErrorType DNSSD_API DNSServiceUpdateRecord 750*4904Srs200217 ( 751*4904Srs200217 DNSServiceRef sdRef, 752*4904Srs200217 DNSRecordRef RecordRef, /* may be NULL */ 753*4904Srs200217 DNSServiceFlags flags, 754*4904Srs200217 uint16_t rdlen, 755*4904Srs200217 const void *rdata, 756*4904Srs200217 uint32_t ttl 757*4904Srs200217 ); 758*4904Srs200217 759*4904Srs200217 760*4904Srs200217 /* DNSServiceRemoveRecord 761*4904Srs200217 * 762*4904Srs200217 * Remove a record previously added to a service record set via DNSServiceAddRecord(), or deregister 763*4904Srs200217 * an record registered individually via DNSServiceRegisterRecord(). 764*4904Srs200217 * 765*4904Srs200217 * Parameters: 766*4904Srs200217 * 767*4904Srs200217 * sdRef: A DNSServiceRef initialized by DNSServiceRegister() (if the 768*4904Srs200217 * record being removed was registered via DNSServiceAddRecord()) or by 769*4904Srs200217 * DNSServiceCreateConnection() (if the record being removed was registered via 770*4904Srs200217 * DNSServiceRegisterRecord()). 771*4904Srs200217 * 772*4904Srs200217 * recordRef: A DNSRecordRef initialized by a successful call to DNSServiceAddRecord() 773*4904Srs200217 * or DNSServiceRegisterRecord(). 774*4904Srs200217 * 775*4904Srs200217 * flags: Currently ignored, reserved for future use. 776*4904Srs200217 * 777*4904Srs200217 * return value: Returns kDNSServiceErr_NoError on success, otherwise returns an 778*4904Srs200217 * error code indicating the error that occurred. 779*4904Srs200217 */ 780*4904Srs200217 781*4904Srs200217 DNSServiceErrorType DNSSD_API DNSServiceRemoveRecord 782*4904Srs200217 ( 783*4904Srs200217 DNSServiceRef sdRef, 784*4904Srs200217 DNSRecordRef RecordRef, 785*4904Srs200217 DNSServiceFlags flags 786*4904Srs200217 ); 787*4904Srs200217 788*4904Srs200217 789*4904Srs200217 /********************************************************************************************* 790*4904Srs200217 * 791*4904Srs200217 * Service Discovery 792*4904Srs200217 * 793*4904Srs200217 *********************************************************************************************/ 794*4904Srs200217 795*4904Srs200217 /* Browse for instances of a service. 796*4904Srs200217 * 797*4904Srs200217 * 798*4904Srs200217 * DNSServiceBrowseReply() Parameters: 799*4904Srs200217 * 800*4904Srs200217 * sdRef: The DNSServiceRef initialized by DNSServiceBrowse(). 801*4904Srs200217 * 802*4904Srs200217 * flags: Possible values are kDNSServiceFlagsMoreComing and kDNSServiceFlagsAdd. 803*4904Srs200217 * See flag definitions for details. 804*4904Srs200217 * 805*4904Srs200217 * interfaceIndex: The interface on which the service is advertised. This index should 806*4904Srs200217 * be passed to DNSServiceResolve() when resolving the service. 807*4904Srs200217 * 808*4904Srs200217 * errorCode: Will be kDNSServiceErr_NoError (0) on success, otherwise will 809*4904Srs200217 * indicate the failure that occurred. Other parameters are undefined if 810*4904Srs200217 * the errorCode is nonzero. 811*4904Srs200217 * 812*4904Srs200217 * serviceName: The discovered service name. This name should be displayed to the user, 813*4904Srs200217 * and stored for subsequent use in the DNSServiceResolve() call. 814*4904Srs200217 * 815*4904Srs200217 * regtype: The service type, which is usually (but not always) the same as was passed 816*4904Srs200217 * to DNSServiceBrowse(). One case where the discovered service type may 817*4904Srs200217 * not be the same as the requested service type is when using subtypes: 818*4904Srs200217 * The client may want to browse for only those ftp servers that allow 819*4904Srs200217 * anonymous connections. The client will pass the string "_ftp._tcp,_anon" 820*4904Srs200217 * to DNSServiceBrowse(), but the type of the service that's discovered 821*4904Srs200217 * is simply "_ftp._tcp". The regtype for each discovered service instance 822*4904Srs200217 * should be stored along with the name, so that it can be passed to 823*4904Srs200217 * DNSServiceResolve() when the service is later resolved. 824*4904Srs200217 * 825*4904Srs200217 * domain: The domain of the discovered service instance. This may or may not be the 826*4904Srs200217 * same as the domain that was passed to DNSServiceBrowse(). The domain for each 827*4904Srs200217 * discovered service instance should be stored along with the name, so that 828*4904Srs200217 * it can be passed to DNSServiceResolve() when the service is later resolved. 829*4904Srs200217 * 830*4904Srs200217 * context: The context pointer that was passed to the callout. 831*4904Srs200217 * 832*4904Srs200217 */ 833*4904Srs200217 834*4904Srs200217 typedef void (DNSSD_API *DNSServiceBrowseReply) 835*4904Srs200217 ( 836*4904Srs200217 DNSServiceRef sdRef, 837*4904Srs200217 DNSServiceFlags flags, 838*4904Srs200217 uint32_t interfaceIndex, 839*4904Srs200217 DNSServiceErrorType errorCode, 840*4904Srs200217 const char *serviceName, 841*4904Srs200217 const char *regtype, 842*4904Srs200217 const char *replyDomain, 843*4904Srs200217 void *context 844*4904Srs200217 ); 845*4904Srs200217 846*4904Srs200217 847*4904Srs200217 /* DNSServiceBrowse() Parameters: 848*4904Srs200217 * 849*4904Srs200217 * sdRef: A pointer to an uninitialized DNSServiceRef. If the call succeeds 850*4904Srs200217 * then it initializes the DNSServiceRef, returns kDNSServiceErr_NoError, 851*4904Srs200217 * and the browse operation will run indefinitely until the client 852*4904Srs200217 * terminates it by passing this DNSServiceRef to DNSServiceRefDeallocate(). 853*4904Srs200217 * 854*4904Srs200217 * flags: Currently ignored, reserved for future use. 855*4904Srs200217 * 856*4904Srs200217 * interfaceIndex: If non-zero, specifies the interface on which to browse for services 857*4904Srs200217 * (the index for a given interface is determined via the if_nametoindex() 858*4904Srs200217 * family of calls.) Most applications will pass 0 to browse on all available 859*4904Srs200217 * interfaces. See "Constants for specifying an interface index" for more details. 860*4904Srs200217 * 861*4904Srs200217 * regtype: The service type being browsed for followed by the protocol, separated by a 862*4904Srs200217 * dot (e.g. "_ftp._tcp"). The transport protocol must be "_tcp" or "_udp". 863*4904Srs200217 * 864*4904Srs200217 * domain: If non-NULL, specifies the domain on which to browse for services. 865*4904Srs200217 * Most applications will not specify a domain, instead browsing on the 866*4904Srs200217 * default domain(s). 867*4904Srs200217 * 868*4904Srs200217 * callBack: The function to be called when an instance of the service being browsed for 869*4904Srs200217 * is found, or if the call asynchronously fails. 870*4904Srs200217 * 871*4904Srs200217 * context: An application context pointer which is passed to the callback function 872*4904Srs200217 * (may be NULL). 873*4904Srs200217 * 874*4904Srs200217 * return value: Returns kDNSServiceErr_NoError on succeses (any subsequent, asynchronous 875*4904Srs200217 * errors are delivered to the callback), otherwise returns an error code indicating 876*4904Srs200217 * the error that occurred (the callback is not invoked and the DNSServiceRef 877*4904Srs200217 * is not initialized.) 878*4904Srs200217 */ 879*4904Srs200217 880*4904Srs200217 DNSServiceErrorType DNSSD_API DNSServiceBrowse 881*4904Srs200217 ( 882*4904Srs200217 DNSServiceRef *sdRef, 883*4904Srs200217 DNSServiceFlags flags, 884*4904Srs200217 uint32_t interfaceIndex, 885*4904Srs200217 const char *regtype, 886*4904Srs200217 const char *domain, /* may be NULL */ 887*4904Srs200217 DNSServiceBrowseReply callBack, 888*4904Srs200217 void *context /* may be NULL */ 889*4904Srs200217 ); 890*4904Srs200217 891*4904Srs200217 892*4904Srs200217 /* DNSServiceResolve() 893*4904Srs200217 * 894*4904Srs200217 * Resolve a service name discovered via DNSServiceBrowse() to a target host name, port number, and 895*4904Srs200217 * txt record. 896*4904Srs200217 * 897*4904Srs200217 * Note: Applications should NOT use DNSServiceResolve() solely for txt record monitoring - use 898*4904Srs200217 * DNSServiceQueryRecord() instead, as it is more efficient for this task. 899*4904Srs200217 * 900*4904Srs200217 * Note: When the desired results have been returned, the client MUST terminate the resolve by calling 901*4904Srs200217 * DNSServiceRefDeallocate(). 902*4904Srs200217 * 903*4904Srs200217 * Note: DNSServiceResolve() behaves correctly for typical services that have a single SRV record 904*4904Srs200217 * and a single TXT record. To resolve non-standard services with multiple SRV or TXT records, 905*4904Srs200217 * DNSServiceQueryRecord() should be used. 906*4904Srs200217 * 907*4904Srs200217 * DNSServiceResolveReply Callback Parameters: 908*4904Srs200217 * 909*4904Srs200217 * sdRef: The DNSServiceRef initialized by DNSServiceResolve(). 910*4904Srs200217 * 911*4904Srs200217 * flags: Currently unused, reserved for future use. 912*4904Srs200217 * 913*4904Srs200217 * interfaceIndex: The interface on which the service was resolved. 914*4904Srs200217 * 915*4904Srs200217 * errorCode: Will be kDNSServiceErr_NoError (0) on success, otherwise will 916*4904Srs200217 * indicate the failure that occurred. Other parameters are undefined if 917*4904Srs200217 * the errorCode is nonzero. 918*4904Srs200217 * 919*4904Srs200217 * fullname: The full service domain name, in the form <servicename>.<protocol>.<domain>. 920*4904Srs200217 * (This name is escaped following standard DNS rules, making it suitable for 921*4904Srs200217 * passing to standard system DNS APIs such as res_query(), or to the 922*4904Srs200217 * special-purpose functions included in this API that take fullname parameters. 923*4904Srs200217 * See "Notes on DNS Name Escaping" earlier in this file for more details.) 924*4904Srs200217 * 925*4904Srs200217 * hosttarget: The target hostname of the machine providing the service. This name can 926*4904Srs200217 * be passed to functions like gethostbyname() to identify the host's IP address. 927*4904Srs200217 * 928*4904Srs200217 * port: The port, in network byte order, on which connections are accepted for this service. 929*4904Srs200217 * 930*4904Srs200217 * txtLen: The length of the txt record, in bytes. 931*4904Srs200217 * 932*4904Srs200217 * txtRecord: The service's primary txt record, in standard txt record format. 933*4904Srs200217 * 934*4904Srs200217 * context: The context pointer that was passed to the callout. 935*4904Srs200217 * 936*4904Srs200217 * NOTE: In earlier versions of this header file, the txtRecord parameter was declared "const char *" 937*4904Srs200217 * This is incorrect, since it contains length bytes which are values in the range 0 to 255, not -128 to +127. 938*4904Srs200217 * Depending on your compiler settings, this change may cause signed/unsigned mismatch warnings. 939*4904Srs200217 * These should be fixed by updating your own callback function definition to match the corrected 940*4904Srs200217 * function signature using "const unsigned char *txtRecord". Making this change may also fix inadvertent 941*4904Srs200217 * bugs in your callback function, where it could have incorrectly interpreted a length byte with value 250 942*4904Srs200217 * as being -6 instead, with various bad consequences ranging from incorrect operation to software crashes. 943*4904Srs200217 * If you need to maintain portable code that will compile cleanly with both the old and new versions of 944*4904Srs200217 * this header file, you should update your callback function definition to use the correct unsigned value, 945*4904Srs200217 * and then in the place where you pass your callback function to DNSServiceResolve(), use a cast to eliminate 946*4904Srs200217 * the compiler warning, e.g.: 947*4904Srs200217 * DNSServiceResolve(sd, flags, index, name, regtype, domain, (DNSServiceResolveReply)MyCallback, context); 948*4904Srs200217 * This will ensure that your code compiles cleanly without warnings (and more importantly, works correctly) 949*4904Srs200217 * with both the old header and with the new corrected version. 950*4904Srs200217 * 951*4904Srs200217 */ 952*4904Srs200217 953*4904Srs200217 typedef void (DNSSD_API *DNSServiceResolveReply) 954*4904Srs200217 ( 955*4904Srs200217 DNSServiceRef sdRef, 956*4904Srs200217 DNSServiceFlags flags, 957*4904Srs200217 uint32_t interfaceIndex, 958*4904Srs200217 DNSServiceErrorType errorCode, 959*4904Srs200217 const char *fullname, 960*4904Srs200217 const char *hosttarget, 961*4904Srs200217 uint16_t port, 962*4904Srs200217 uint16_t txtLen, 963*4904Srs200217 const unsigned char *txtRecord, 964*4904Srs200217 void *context 965*4904Srs200217 ); 966*4904Srs200217 967*4904Srs200217 968*4904Srs200217 /* DNSServiceResolve() Parameters 969*4904Srs200217 * 970*4904Srs200217 * sdRef: A pointer to an uninitialized DNSServiceRef. If the call succeeds 971*4904Srs200217 * then it initializes the DNSServiceRef, returns kDNSServiceErr_NoError, 972*4904Srs200217 * and the resolve operation will run indefinitely until the client 973*4904Srs200217 * terminates it by passing this DNSServiceRef to DNSServiceRefDeallocate(). 974*4904Srs200217 * 975*4904Srs200217 * flags: Currently ignored, reserved for future use. 976*4904Srs200217 * 977*4904Srs200217 * interfaceIndex: The interface on which to resolve the service. If this resolve call is 978*4904Srs200217 * as a result of a currently active DNSServiceBrowse() operation, then the 979*4904Srs200217 * interfaceIndex should be the index reported in the DNSServiceBrowseReply 980*4904Srs200217 * callback. If this resolve call is using information previously saved 981*4904Srs200217 * (e.g. in a preference file) for later use, then use interfaceIndex 0, because 982*4904Srs200217 * the desired service may now be reachable via a different physical interface. 983*4904Srs200217 * See "Constants for specifying an interface index" for more details. 984*4904Srs200217 * 985*4904Srs200217 * name: The name of the service instance to be resolved, as reported to the 986*4904Srs200217 * DNSServiceBrowseReply() callback. 987*4904Srs200217 * 988*4904Srs200217 * regtype: The type of the service instance to be resolved, as reported to the 989*4904Srs200217 * DNSServiceBrowseReply() callback. 990*4904Srs200217 * 991*4904Srs200217 * domain: The domain of the service instance to be resolved, as reported to the 992*4904Srs200217 * DNSServiceBrowseReply() callback. 993*4904Srs200217 * 994*4904Srs200217 * callBack: The function to be called when a result is found, or if the call 995*4904Srs200217 * asynchronously fails. 996*4904Srs200217 * 997*4904Srs200217 * context: An application context pointer which is passed to the callback function 998*4904Srs200217 * (may be NULL). 999*4904Srs200217 * 1000*4904Srs200217 * return value: Returns kDNSServiceErr_NoError on succeses (any subsequent, asynchronous 1001*4904Srs200217 * errors are delivered to the callback), otherwise returns an error code indicating 1002*4904Srs200217 * the error that occurred (the callback is never invoked and the DNSServiceRef 1003*4904Srs200217 * is not initialized.) 1004*4904Srs200217 */ 1005*4904Srs200217 1006*4904Srs200217 DNSServiceErrorType DNSSD_API DNSServiceResolve 1007*4904Srs200217 ( 1008*4904Srs200217 DNSServiceRef *sdRef, 1009*4904Srs200217 DNSServiceFlags flags, 1010*4904Srs200217 uint32_t interfaceIndex, 1011*4904Srs200217 const char *name, 1012*4904Srs200217 const char *regtype, 1013*4904Srs200217 const char *domain, 1014*4904Srs200217 DNSServiceResolveReply callBack, 1015*4904Srs200217 void *context /* may be NULL */ 1016*4904Srs200217 ); 1017*4904Srs200217 1018*4904Srs200217 1019*4904Srs200217 /********************************************************************************************* 1020*4904Srs200217 * 1021*4904Srs200217 * Special Purpose Calls (most applications will not use these) 1022*4904Srs200217 * 1023*4904Srs200217 *********************************************************************************************/ 1024*4904Srs200217 1025*4904Srs200217 /* DNSServiceCreateConnection() 1026*4904Srs200217 * 1027*4904Srs200217 * Create a connection to the daemon allowing efficient registration of 1028*4904Srs200217 * multiple individual records. 1029*4904Srs200217 * 1030*4904Srs200217 * 1031*4904Srs200217 * Parameters: 1032*4904Srs200217 * 1033*4904Srs200217 * sdRef: A pointer to an uninitialized DNSServiceRef. Deallocating 1034*4904Srs200217 * the reference (via DNSServiceRefDeallocate()) severs the 1035*4904Srs200217 * connection and deregisters all records registered on this connection. 1036*4904Srs200217 * 1037*4904Srs200217 * return value: Returns kDNSServiceErr_NoError on success, otherwise returns 1038*4904Srs200217 * an error code indicating the specific failure that occurred (in which 1039*4904Srs200217 * case the DNSServiceRef is not initialized). 1040*4904Srs200217 */ 1041*4904Srs200217 1042*4904Srs200217 DNSServiceErrorType DNSSD_API DNSServiceCreateConnection(DNSServiceRef *sdRef); 1043*4904Srs200217 1044*4904Srs200217 1045*4904Srs200217 /* DNSServiceRegisterRecord 1046*4904Srs200217 * 1047*4904Srs200217 * Register an individual resource record on a connected DNSServiceRef. 1048*4904Srs200217 * 1049*4904Srs200217 * Note that name conflicts occurring for records registered via this call must be handled 1050*4904Srs200217 * by the client in the callback. 1051*4904Srs200217 * 1052*4904Srs200217 * 1053*4904Srs200217 * DNSServiceRegisterRecordReply() parameters: 1054*4904Srs200217 * 1055*4904Srs200217 * sdRef: The connected DNSServiceRef initialized by 1056*4904Srs200217 * DNSServiceCreateConnection(). 1057*4904Srs200217 * 1058*4904Srs200217 * RecordRef: The DNSRecordRef initialized by DNSServiceRegisterRecord(). If the above 1059*4904Srs200217 * DNSServiceRef is passed to DNSServiceRefDeallocate(), this DNSRecordRef is 1060*4904Srs200217 * invalidated, and may not be used further. 1061*4904Srs200217 * 1062*4904Srs200217 * flags: Currently unused, reserved for future use. 1063*4904Srs200217 * 1064*4904Srs200217 * errorCode: Will be kDNSServiceErr_NoError on success, otherwise will 1065*4904Srs200217 * indicate the failure that occurred (including name conflicts.) 1066*4904Srs200217 * Other parameters are undefined if errorCode is nonzero. 1067*4904Srs200217 * 1068*4904Srs200217 * context: The context pointer that was passed to the callout. 1069*4904Srs200217 * 1070*4904Srs200217 */ 1071*4904Srs200217 1072*4904Srs200217 typedef void (DNSSD_API *DNSServiceRegisterRecordReply) 1073*4904Srs200217 ( 1074*4904Srs200217 DNSServiceRef sdRef, 1075*4904Srs200217 DNSRecordRef RecordRef, 1076*4904Srs200217 DNSServiceFlags flags, 1077*4904Srs200217 DNSServiceErrorType errorCode, 1078*4904Srs200217 void *context 1079*4904Srs200217 ); 1080*4904Srs200217 1081*4904Srs200217 1082*4904Srs200217 /* DNSServiceRegisterRecord() Parameters: 1083*4904Srs200217 * 1084*4904Srs200217 * sdRef: A DNSServiceRef initialized by DNSServiceCreateConnection(). 1085*4904Srs200217 * 1086*4904Srs200217 * RecordRef: A pointer to an uninitialized DNSRecordRef. Upon succesfull completion of this 1087*4904Srs200217 * call, this ref may be passed to DNSServiceUpdateRecord() or DNSServiceRemoveRecord(). 1088*4904Srs200217 * (To deregister ALL records registered on a single connected DNSServiceRef 1089*4904Srs200217 * and deallocate each of their corresponding DNSServiceRecordRefs, call 1090*4904Srs200217 * DNSServiceRefDealloocate()). 1091*4904Srs200217 * 1092*4904Srs200217 * flags: Possible values are kDNSServiceFlagsShared or kDNSServiceFlagsUnique 1093*4904Srs200217 * (see flag type definitions for details). 1094*4904Srs200217 * 1095*4904Srs200217 * interfaceIndex: If non-zero, specifies the interface on which to register the record 1096*4904Srs200217 * (the index for a given interface is determined via the if_nametoindex() 1097*4904Srs200217 * family of calls.) Passing 0 causes the record to be registered on all interfaces. 1098*4904Srs200217 * See "Constants for specifying an interface index" for more details. 1099*4904Srs200217 * 1100*4904Srs200217 * fullname: The full domain name of the resource record. 1101*4904Srs200217 * 1102*4904Srs200217 * rrtype: The numerical type of the resource record (e.g. kDNSServiceType_PTR, kDNSServiceType_SRV, etc) 1103*4904Srs200217 * 1104*4904Srs200217 * rrclass: The class of the resource record (usually kDNSServiceClass_IN) 1105*4904Srs200217 * 1106*4904Srs200217 * rdlen: Length, in bytes, of the rdata. 1107*4904Srs200217 * 1108*4904Srs200217 * rdata: A pointer to the raw rdata, as it is to appear in the DNS record. 1109*4904Srs200217 * 1110*4904Srs200217 * ttl: The time to live of the resource record, in seconds. Pass 0 to use a default value. 1111*4904Srs200217 * 1112*4904Srs200217 * callBack: The function to be called when a result is found, or if the call 1113*4904Srs200217 * asynchronously fails (e.g. because of a name conflict.) 1114*4904Srs200217 * 1115*4904Srs200217 * context: An application context pointer which is passed to the callback function 1116*4904Srs200217 * (may be NULL). 1117*4904Srs200217 * 1118*4904Srs200217 * return value: Returns kDNSServiceErr_NoError on succeses (any subsequent, asynchronous 1119*4904Srs200217 * errors are delivered to the callback), otherwise returns an error code indicating 1120*4904Srs200217 * the error that occurred (the callback is never invoked and the DNSRecordRef is 1121*4904Srs200217 * not initialized.) 1122*4904Srs200217 */ 1123*4904Srs200217 1124*4904Srs200217 DNSServiceErrorType DNSSD_API DNSServiceRegisterRecord 1125*4904Srs200217 ( 1126*4904Srs200217 DNSServiceRef sdRef, 1127*4904Srs200217 DNSRecordRef *RecordRef, 1128*4904Srs200217 DNSServiceFlags flags, 1129*4904Srs200217 uint32_t interfaceIndex, 1130*4904Srs200217 const char *fullname, 1131*4904Srs200217 uint16_t rrtype, 1132*4904Srs200217 uint16_t rrclass, 1133*4904Srs200217 uint16_t rdlen, 1134*4904Srs200217 const void *rdata, 1135*4904Srs200217 uint32_t ttl, 1136*4904Srs200217 DNSServiceRegisterRecordReply callBack, 1137*4904Srs200217 void *context /* may be NULL */ 1138*4904Srs200217 ); 1139*4904Srs200217 1140*4904Srs200217 1141*4904Srs200217 /* DNSServiceQueryRecord 1142*4904Srs200217 * 1143*4904Srs200217 * Query for an arbitrary DNS record. 1144*4904Srs200217 * 1145*4904Srs200217 * 1146*4904Srs200217 * DNSServiceQueryRecordReply() Callback Parameters: 1147*4904Srs200217 * 1148*4904Srs200217 * sdRef: The DNSServiceRef initialized by DNSServiceQueryRecord(). 1149*4904Srs200217 * 1150*4904Srs200217 * flags: Possible values are kDNSServiceFlagsMoreComing and 1151*4904Srs200217 * kDNSServiceFlagsAdd. The Add flag is NOT set for PTR records 1152*4904Srs200217 * with a ttl of 0, i.e. "Remove" events. 1153*4904Srs200217 * 1154*4904Srs200217 * interfaceIndex: The interface on which the query was resolved (the index for a given 1155*4904Srs200217 * interface is determined via the if_nametoindex() family of calls). 1156*4904Srs200217 * See "Constants for specifying an interface index" for more details. 1157*4904Srs200217 * 1158*4904Srs200217 * errorCode: Will be kDNSServiceErr_NoError on success, otherwise will 1159*4904Srs200217 * indicate the failure that occurred. Other parameters are undefined if 1160*4904Srs200217 * errorCode is nonzero. 1161*4904Srs200217 * 1162*4904Srs200217 * fullname: The resource record's full domain name. 1163*4904Srs200217 * 1164*4904Srs200217 * rrtype: The resource record's type (e.g. kDNSServiceType_PTR, kDNSServiceType_SRV, etc) 1165*4904Srs200217 * 1166*4904Srs200217 * rrclass: The class of the resource record (usually kDNSServiceClass_IN). 1167*4904Srs200217 * 1168*4904Srs200217 * rdlen: The length, in bytes, of the resource record rdata. 1169*4904Srs200217 * 1170*4904Srs200217 * rdata: The raw rdata of the resource record. 1171*4904Srs200217 * 1172*4904Srs200217 * ttl: The resource record's time to live, in seconds. 1173*4904Srs200217 * 1174*4904Srs200217 * context: The context pointer that was passed to the callout. 1175*4904Srs200217 * 1176*4904Srs200217 */ 1177*4904Srs200217 1178*4904Srs200217 typedef void (DNSSD_API *DNSServiceQueryRecordReply) 1179*4904Srs200217 ( 1180*4904Srs200217 DNSServiceRef DNSServiceRef, 1181*4904Srs200217 DNSServiceFlags flags, 1182*4904Srs200217 uint32_t interfaceIndex, 1183*4904Srs200217 DNSServiceErrorType errorCode, 1184*4904Srs200217 const char *fullname, 1185*4904Srs200217 uint16_t rrtype, 1186*4904Srs200217 uint16_t rrclass, 1187*4904Srs200217 uint16_t rdlen, 1188*4904Srs200217 const void *rdata, 1189*4904Srs200217 uint32_t ttl, 1190*4904Srs200217 void *context 1191*4904Srs200217 ); 1192*4904Srs200217 1193*4904Srs200217 1194*4904Srs200217 /* DNSServiceQueryRecord() Parameters: 1195*4904Srs200217 * 1196*4904Srs200217 * sdRef: A pointer to an uninitialized DNSServiceRef. If the call succeeds 1197*4904Srs200217 * then it initializes the DNSServiceRef, returns kDNSServiceErr_NoError, 1198*4904Srs200217 * and the query operation will run indefinitely until the client 1199*4904Srs200217 * terminates it by passing this DNSServiceRef to DNSServiceRefDeallocate(). 1200*4904Srs200217 * 1201*4904Srs200217 * flags: Pass kDNSServiceFlagsLongLivedQuery to create a "long-lived" unicast 1202*4904Srs200217 * query in a non-local domain. Without setting this flag, unicast queries 1203*4904Srs200217 * will be one-shot - that is, only answers available at the time of the call 1204*4904Srs200217 * will be returned. By setting this flag, answers (including Add and Remove 1205*4904Srs200217 * events) that become available after the initial call is made will generate 1206*4904Srs200217 * callbacks. This flag has no effect on link-local multicast queries. 1207*4904Srs200217 * 1208*4904Srs200217 * interfaceIndex: If non-zero, specifies the interface on which to issue the query 1209*4904Srs200217 * (the index for a given interface is determined via the if_nametoindex() 1210*4904Srs200217 * family of calls.) Passing 0 causes the name to be queried for on all 1211*4904Srs200217 * interfaces. See "Constants for specifying an interface index" for more details. 1212*4904Srs200217 * 1213*4904Srs200217 * fullname: The full domain name of the resource record to be queried for. 1214*4904Srs200217 * 1215*4904Srs200217 * rrtype: The numerical type of the resource record to be queried for 1216*4904Srs200217 * (e.g. kDNSServiceType_PTR, kDNSServiceType_SRV, etc) 1217*4904Srs200217 * 1218*4904Srs200217 * rrclass: The class of the resource record (usually kDNSServiceClass_IN). 1219*4904Srs200217 * 1220*4904Srs200217 * callBack: The function to be called when a result is found, or if the call 1221*4904Srs200217 * asynchronously fails. 1222*4904Srs200217 * 1223*4904Srs200217 * context: An application context pointer which is passed to the callback function 1224*4904Srs200217 * (may be NULL). 1225*4904Srs200217 * 1226*4904Srs200217 * return value: Returns kDNSServiceErr_NoError on succeses (any subsequent, asynchronous 1227*4904Srs200217 * errors are delivered to the callback), otherwise returns an error code indicating 1228*4904Srs200217 * the error that occurred (the callback is never invoked and the DNSServiceRef 1229*4904Srs200217 * is not initialized.) 1230*4904Srs200217 */ 1231*4904Srs200217 1232*4904Srs200217 DNSServiceErrorType DNSSD_API DNSServiceQueryRecord 1233*4904Srs200217 ( 1234*4904Srs200217 DNSServiceRef *sdRef, 1235*4904Srs200217 DNSServiceFlags flags, 1236*4904Srs200217 uint32_t interfaceIndex, 1237*4904Srs200217 const char *fullname, 1238*4904Srs200217 uint16_t rrtype, 1239*4904Srs200217 uint16_t rrclass, 1240*4904Srs200217 DNSServiceQueryRecordReply callBack, 1241*4904Srs200217 void *context /* may be NULL */ 1242*4904Srs200217 ); 1243*4904Srs200217 1244*4904Srs200217 1245*4904Srs200217 /* DNSServiceReconfirmRecord 1246*4904Srs200217 * 1247*4904Srs200217 * Instruct the daemon to verify the validity of a resource record that appears to 1248*4904Srs200217 * be out of date (e.g. because tcp connection to a service's target failed.) 1249*4904Srs200217 * Causes the record to be flushed from the daemon's cache (as well as all other 1250*4904Srs200217 * daemons' caches on the network) if the record is determined to be invalid. 1251*4904Srs200217 * 1252*4904Srs200217 * Parameters: 1253*4904Srs200217 * 1254*4904Srs200217 * flags: Currently unused, reserved for future use. 1255*4904Srs200217 * 1256*4904Srs200217 * interfaceIndex: If non-zero, specifies the interface of the record in question. 1257*4904Srs200217 * Passing 0 causes all instances of this record to be reconfirmed. 1258*4904Srs200217 * 1259*4904Srs200217 * fullname: The resource record's full domain name. 1260*4904Srs200217 * 1261*4904Srs200217 * rrtype: The resource record's type (e.g. kDNSServiceType_PTR, kDNSServiceType_SRV, etc) 1262*4904Srs200217 * 1263*4904Srs200217 * rrclass: The class of the resource record (usually kDNSServiceClass_IN). 1264*4904Srs200217 * 1265*4904Srs200217 * rdlen: The length, in bytes, of the resource record rdata. 1266*4904Srs200217 * 1267*4904Srs200217 * rdata: The raw rdata of the resource record. 1268*4904Srs200217 * 1269*4904Srs200217 */ 1270*4904Srs200217 1271*4904Srs200217 DNSServiceErrorType DNSSD_API DNSServiceReconfirmRecord 1272*4904Srs200217 ( 1273*4904Srs200217 DNSServiceFlags flags, 1274*4904Srs200217 uint32_t interfaceIndex, 1275*4904Srs200217 const char *fullname, 1276*4904Srs200217 uint16_t rrtype, 1277*4904Srs200217 uint16_t rrclass, 1278*4904Srs200217 uint16_t rdlen, 1279*4904Srs200217 const void *rdata 1280*4904Srs200217 ); 1281*4904Srs200217 1282*4904Srs200217 1283*4904Srs200217 /********************************************************************************************* 1284*4904Srs200217 * 1285*4904Srs200217 * General Utility Functions 1286*4904Srs200217 * 1287*4904Srs200217 *********************************************************************************************/ 1288*4904Srs200217 1289*4904Srs200217 /* DNSServiceConstructFullName() 1290*4904Srs200217 * 1291*4904Srs200217 * Concatenate a three-part domain name (as returned by the above callbacks) into a 1292*4904Srs200217 * properly-escaped full domain name. Note that callbacks in the above functions ALREADY ESCAPE 1293*4904Srs200217 * strings where necessary. 1294*4904Srs200217 * 1295*4904Srs200217 * Parameters: 1296*4904Srs200217 * 1297*4904Srs200217 * fullName: A pointer to a buffer that where the resulting full domain name is to be written. 1298*4904Srs200217 * The buffer must be kDNSServiceMaxDomainName (1005) bytes in length to 1299*4904Srs200217 * accommodate the longest legal domain name without buffer overrun. 1300*4904Srs200217 * 1301*4904Srs200217 * service: The service name - any dots or backslashes must NOT be escaped. 1302*4904Srs200217 * May be NULL (to construct a PTR record name, e.g. 1303*4904Srs200217 * "_ftp._tcp.apple.com."). 1304*4904Srs200217 * 1305*4904Srs200217 * regtype: The service type followed by the protocol, separated by a dot 1306*4904Srs200217 * (e.g. "_ftp._tcp"). 1307*4904Srs200217 * 1308*4904Srs200217 * domain: The domain name, e.g. "apple.com.". Literal dots or backslashes, 1309*4904Srs200217 * if any, must be escaped, e.g. "1st\. Floor.apple.com." 1310*4904Srs200217 * 1311*4904Srs200217 * return value: Returns 0 on success, -1 on error. 1312*4904Srs200217 * 1313*4904Srs200217 */ 1314*4904Srs200217 1315*4904Srs200217 int DNSSD_API DNSServiceConstructFullName 1316*4904Srs200217 ( 1317*4904Srs200217 char *fullName, 1318*4904Srs200217 const char *service, /* may be NULL */ 1319*4904Srs200217 const char *regtype, 1320*4904Srs200217 const char *domain 1321*4904Srs200217 ); 1322*4904Srs200217 1323*4904Srs200217 1324*4904Srs200217 /********************************************************************************************* 1325*4904Srs200217 * 1326*4904Srs200217 * TXT Record Construction Functions 1327*4904Srs200217 * 1328*4904Srs200217 *********************************************************************************************/ 1329*4904Srs200217 1330*4904Srs200217 /* 1331*4904Srs200217 * A typical calling sequence for TXT record construction is something like: 1332*4904Srs200217 * 1333*4904Srs200217 * Client allocates storage for TXTRecord data (e.g. declare buffer on the stack) 1334*4904Srs200217 * TXTRecordCreate(); 1335*4904Srs200217 * TXTRecordSetValue(); 1336*4904Srs200217 * TXTRecordSetValue(); 1337*4904Srs200217 * TXTRecordSetValue(); 1338*4904Srs200217 * ... 1339*4904Srs200217 * DNSServiceRegister( ... TXTRecordGetLength(), TXTRecordGetBytesPtr() ... ); 1340*4904Srs200217 * TXTRecordDeallocate(); 1341*4904Srs200217 * Explicitly deallocate storage for TXTRecord data (if not allocated on the stack) 1342*4904Srs200217 */ 1343*4904Srs200217 1344*4904Srs200217 1345*4904Srs200217 /* TXTRecordRef 1346*4904Srs200217 * 1347*4904Srs200217 * Opaque internal data type. 1348*4904Srs200217 * Note: Represents a DNS-SD TXT record. 1349*4904Srs200217 */ 1350*4904Srs200217 1351*4904Srs200217 typedef union _TXTRecordRef_t { char PrivateData[16]; char *ForceNaturalAlignment; } TXTRecordRef; 1352*4904Srs200217 1353*4904Srs200217 1354*4904Srs200217 /* TXTRecordCreate() 1355*4904Srs200217 * 1356*4904Srs200217 * Creates a new empty TXTRecordRef referencing the specified storage. 1357*4904Srs200217 * 1358*4904Srs200217 * If the buffer parameter is NULL, or the specified storage size is not 1359*4904Srs200217 * large enough to hold a key subsequently added using TXTRecordSetValue(), 1360*4904Srs200217 * then additional memory will be added as needed using malloc(). 1361*4904Srs200217 * 1362*4904Srs200217 * On some platforms, when memory is low, malloc() may fail. In this 1363*4904Srs200217 * case, TXTRecordSetValue() will return kDNSServiceErr_NoMemory, and this 1364*4904Srs200217 * error condition will need to be handled as appropriate by the caller. 1365*4904Srs200217 * 1366*4904Srs200217 * You can avoid the need to handle this error condition if you ensure 1367*4904Srs200217 * that the storage you initially provide is large enough to hold all 1368*4904Srs200217 * the key/value pairs that are to be added to the record. 1369*4904Srs200217 * The caller can precompute the exact length required for all of the 1370*4904Srs200217 * key/value pairs to be added, or simply provide a fixed-sized buffer 1371*4904Srs200217 * known in advance to be large enough. 1372*4904Srs200217 * A no-value (key-only) key requires (1 + key length) bytes. 1373*4904Srs200217 * A key with empty value requires (1 + key length + 1) bytes. 1374*4904Srs200217 * A key with non-empty value requires (1 + key length + 1 + value length). 1375*4904Srs200217 * For most applications, DNS-SD TXT records are generally 1376*4904Srs200217 * less than 100 bytes, so in most cases a simple fixed-sized 1377*4904Srs200217 * 256-byte buffer will be more than sufficient. 1378*4904Srs200217 * Recommended size limits for DNS-SD TXT Records are discussed in 1379*4904Srs200217 * <http://files.dns-sd.org/draft-cheshire-dnsext-dns-sd.txt> 1380*4904Srs200217 * 1381*4904Srs200217 * Note: When passing parameters to and from these TXT record APIs, 1382*4904Srs200217 * the key name does not include the '=' character. The '=' character 1383*4904Srs200217 * is the separator between the key and value in the on-the-wire 1384*4904Srs200217 * packet format; it is not part of either the key or the value. 1385*4904Srs200217 * 1386*4904Srs200217 * txtRecord: A pointer to an uninitialized TXTRecordRef. 1387*4904Srs200217 * 1388*4904Srs200217 * bufferLen: The size of the storage provided in the "buffer" parameter. 1389*4904Srs200217 * 1390*4904Srs200217 * buffer: Optional caller-supplied storage used to hold the TXTRecord data. 1391*4904Srs200217 * This storage must remain valid for as long as 1392*4904Srs200217 * the TXTRecordRef. 1393*4904Srs200217 */ 1394*4904Srs200217 1395*4904Srs200217 void DNSSD_API TXTRecordCreate 1396*4904Srs200217 ( 1397*4904Srs200217 TXTRecordRef *txtRecord, 1398*4904Srs200217 uint16_t bufferLen, 1399*4904Srs200217 void *buffer 1400*4904Srs200217 ); 1401*4904Srs200217 1402*4904Srs200217 1403*4904Srs200217 /* TXTRecordDeallocate() 1404*4904Srs200217 * 1405*4904Srs200217 * Releases any resources allocated in the course of preparing a TXT Record 1406*4904Srs200217 * using TXTRecordCreate()/TXTRecordSetValue()/TXTRecordRemoveValue(). 1407*4904Srs200217 * Ownership of the buffer provided in TXTRecordCreate() returns to the client. 1408*4904Srs200217 * 1409*4904Srs200217 * txtRecord: A TXTRecordRef initialized by calling TXTRecordCreate(). 1410*4904Srs200217 * 1411*4904Srs200217 */ 1412*4904Srs200217 1413*4904Srs200217 void DNSSD_API TXTRecordDeallocate 1414*4904Srs200217 ( 1415*4904Srs200217 TXTRecordRef *txtRecord 1416*4904Srs200217 ); 1417*4904Srs200217 1418*4904Srs200217 1419*4904Srs200217 /* TXTRecordSetValue() 1420*4904Srs200217 * 1421*4904Srs200217 * Adds a key (optionally with value) to a TXTRecordRef. If the "key" already 1422*4904Srs200217 * exists in the TXTRecordRef, then the current value will be replaced with 1423*4904Srs200217 * the new value. 1424*4904Srs200217 * Keys may exist in four states with respect to a given TXT record: 1425*4904Srs200217 * - Absent (key does not appear at all) 1426*4904Srs200217 * - Present with no value ("key" appears alone) 1427*4904Srs200217 * - Present with empty value ("key=" appears in TXT record) 1428*4904Srs200217 * - Present with non-empty value ("key=value" appears in TXT record) 1429*4904Srs200217 * For more details refer to "Data Syntax for DNS-SD TXT Records" in 1430*4904Srs200217 * <http://files.dns-sd.org/draft-cheshire-dnsext-dns-sd.txt> 1431*4904Srs200217 * 1432*4904Srs200217 * txtRecord: A TXTRecordRef initialized by calling TXTRecordCreate(). 1433*4904Srs200217 * 1434*4904Srs200217 * key: A null-terminated string which only contains printable ASCII 1435*4904Srs200217 * values (0x20-0x7E), excluding '=' (0x3D). Keys should be 1436*4904Srs200217 * 8 characters or less (not counting the terminating null). 1437*4904Srs200217 * 1438*4904Srs200217 * valueSize: The size of the value. 1439*4904Srs200217 * 1440*4904Srs200217 * value: Any binary value. For values that represent 1441*4904Srs200217 * textual data, UTF-8 is STRONGLY recommended. 1442*4904Srs200217 * For values that represent textual data, valueSize 1443*4904Srs200217 * should NOT include the terminating null (if any) 1444*4904Srs200217 * at the end of the string. 1445*4904Srs200217 * If NULL, then "key" will be added with no value. 1446*4904Srs200217 * If non-NULL but valueSize is zero, then "key=" will be 1447*4904Srs200217 * added with empty value. 1448*4904Srs200217 * 1449*4904Srs200217 * return value: Returns kDNSServiceErr_NoError on success. 1450*4904Srs200217 * Returns kDNSServiceErr_Invalid if the "key" string contains 1451*4904Srs200217 * illegal characters. 1452*4904Srs200217 * Returns kDNSServiceErr_NoMemory if adding this key would 1453*4904Srs200217 * exceed the available storage. 1454*4904Srs200217 */ 1455*4904Srs200217 1456*4904Srs200217 DNSServiceErrorType DNSSD_API TXTRecordSetValue 1457*4904Srs200217 ( 1458*4904Srs200217 TXTRecordRef *txtRecord, 1459*4904Srs200217 const char *key, 1460*4904Srs200217 uint8_t valueSize, /* may be zero */ 1461*4904Srs200217 const void *value /* may be NULL */ 1462*4904Srs200217 ); 1463*4904Srs200217 1464*4904Srs200217 1465*4904Srs200217 /* TXTRecordRemoveValue() 1466*4904Srs200217 * 1467*4904Srs200217 * Removes a key from a TXTRecordRef. The "key" must be an 1468*4904Srs200217 * ASCII string which exists in the TXTRecordRef. 1469*4904Srs200217 * 1470*4904Srs200217 * txtRecord: A TXTRecordRef initialized by calling TXTRecordCreate(). 1471*4904Srs200217 * 1472*4904Srs200217 * key: A key name which exists in the TXTRecordRef. 1473*4904Srs200217 * 1474*4904Srs200217 * return value: Returns kDNSServiceErr_NoError on success. 1475*4904Srs200217 * Returns kDNSServiceErr_NoSuchKey if the "key" does not 1476*4904Srs200217 * exist in the TXTRecordRef. 1477*4904Srs200217 */ 1478*4904Srs200217 1479*4904Srs200217 DNSServiceErrorType DNSSD_API TXTRecordRemoveValue 1480*4904Srs200217 ( 1481*4904Srs200217 TXTRecordRef *txtRecord, 1482*4904Srs200217 const char *key 1483*4904Srs200217 ); 1484*4904Srs200217 1485*4904Srs200217 1486*4904Srs200217 /* TXTRecordGetLength() 1487*4904Srs200217 * 1488*4904Srs200217 * Allows you to determine the length of the raw bytes within a TXTRecordRef. 1489*4904Srs200217 * 1490*4904Srs200217 * txtRecord: A TXTRecordRef initialized by calling TXTRecordCreate(). 1491*4904Srs200217 * 1492*4904Srs200217 * return value: Returns the size of the raw bytes inside a TXTRecordRef 1493*4904Srs200217 * which you can pass directly to DNSServiceRegister() or 1494*4904Srs200217 * to DNSServiceUpdateRecord(). 1495*4904Srs200217 * Returns 0 if the TXTRecordRef is empty. 1496*4904Srs200217 */ 1497*4904Srs200217 1498*4904Srs200217 uint16_t DNSSD_API TXTRecordGetLength 1499*4904Srs200217 ( 1500*4904Srs200217 const TXTRecordRef *txtRecord 1501*4904Srs200217 ); 1502*4904Srs200217 1503*4904Srs200217 1504*4904Srs200217 /* TXTRecordGetBytesPtr() 1505*4904Srs200217 * 1506*4904Srs200217 * Allows you to retrieve a pointer to the raw bytes within a TXTRecordRef. 1507*4904Srs200217 * 1508*4904Srs200217 * txtRecord: A TXTRecordRef initialized by calling TXTRecordCreate(). 1509*4904Srs200217 * 1510*4904Srs200217 * return value: Returns a pointer to the raw bytes inside the TXTRecordRef 1511*4904Srs200217 * which you can pass directly to DNSServiceRegister() or 1512*4904Srs200217 * to DNSServiceUpdateRecord(). 1513*4904Srs200217 */ 1514*4904Srs200217 1515*4904Srs200217 const void * DNSSD_API TXTRecordGetBytesPtr 1516*4904Srs200217 ( 1517*4904Srs200217 const TXTRecordRef *txtRecord 1518*4904Srs200217 ); 1519*4904Srs200217 1520*4904Srs200217 1521*4904Srs200217 /********************************************************************************************* 1522*4904Srs200217 * 1523*4904Srs200217 * TXT Record Parsing Functions 1524*4904Srs200217 * 1525*4904Srs200217 *********************************************************************************************/ 1526*4904Srs200217 1527*4904Srs200217 /* 1528*4904Srs200217 * A typical calling sequence for TXT record parsing is something like: 1529*4904Srs200217 * 1530*4904Srs200217 * Receive TXT record data in DNSServiceResolve() callback 1531*4904Srs200217 * if (TXTRecordContainsKey(txtLen, txtRecord, "key")) then do something 1532*4904Srs200217 * val1ptr = TXTRecordGetValuePtr(txtLen, txtRecord, "key1", &len1); 1533*4904Srs200217 * val2ptr = TXTRecordGetValuePtr(txtLen, txtRecord, "key2", &len2); 1534*4904Srs200217 * ... 1535*4904Srs200217 * bcopy(val1ptr, myval1, len1); 1536*4904Srs200217 * bcopy(val2ptr, myval2, len2); 1537*4904Srs200217 * ... 1538*4904Srs200217 * return; 1539*4904Srs200217 * 1540*4904Srs200217 * If you wish to retain the values after return from the DNSServiceResolve() 1541*4904Srs200217 * callback, then you need to copy the data to your own storage using bcopy() 1542*4904Srs200217 * or similar, as shown in the example above. 1543*4904Srs200217 * 1544*4904Srs200217 * If for some reason you need to parse a TXT record you built yourself 1545*4904Srs200217 * using the TXT record construction functions above, then you can do 1546*4904Srs200217 * that using TXTRecordGetLength and TXTRecordGetBytesPtr calls: 1547*4904Srs200217 * TXTRecordGetValue(TXTRecordGetLength(x), TXTRecordGetBytesPtr(x), key, &len); 1548*4904Srs200217 * 1549*4904Srs200217 * Most applications only fetch keys they know about from a TXT record and 1550*4904Srs200217 * ignore the rest. 1551*4904Srs200217 * However, some debugging tools wish to fetch and display all keys. 1552*4904Srs200217 * To do that, use the TXTRecordGetCount() and TXTRecordGetItemAtIndex() calls. 1553*4904Srs200217 */ 1554*4904Srs200217 1555*4904Srs200217 /* TXTRecordContainsKey() 1556*4904Srs200217 * 1557*4904Srs200217 * Allows you to determine if a given TXT Record contains a specified key. 1558*4904Srs200217 * 1559*4904Srs200217 * txtLen: The size of the received TXT Record. 1560*4904Srs200217 * 1561*4904Srs200217 * txtRecord: Pointer to the received TXT Record bytes. 1562*4904Srs200217 * 1563*4904Srs200217 * key: A null-terminated ASCII string containing the key name. 1564*4904Srs200217 * 1565*4904Srs200217 * return value: Returns 1 if the TXT Record contains the specified key. 1566*4904Srs200217 * Otherwise, it returns 0. 1567*4904Srs200217 */ 1568*4904Srs200217 1569*4904Srs200217 int DNSSD_API TXTRecordContainsKey 1570*4904Srs200217 ( 1571*4904Srs200217 uint16_t txtLen, 1572*4904Srs200217 const void *txtRecord, 1573*4904Srs200217 const char *key 1574*4904Srs200217 ); 1575*4904Srs200217 1576*4904Srs200217 1577*4904Srs200217 /* TXTRecordGetValuePtr() 1578*4904Srs200217 * 1579*4904Srs200217 * Allows you to retrieve the value for a given key from a TXT Record. 1580*4904Srs200217 * 1581*4904Srs200217 * txtLen: The size of the received TXT Record 1582*4904Srs200217 * 1583*4904Srs200217 * txtRecord: Pointer to the received TXT Record bytes. 1584*4904Srs200217 * 1585*4904Srs200217 * key: A null-terminated ASCII string containing the key name. 1586*4904Srs200217 * 1587*4904Srs200217 * valueLen: On output, will be set to the size of the "value" data. 1588*4904Srs200217 * 1589*4904Srs200217 * return value: Returns NULL if the key does not exist in this TXT record, 1590*4904Srs200217 * or exists with no value (to differentiate between 1591*4904Srs200217 * these two cases use TXTRecordContainsKey()). 1592*4904Srs200217 * Returns pointer to location within TXT Record bytes 1593*4904Srs200217 * if the key exists with empty or non-empty value. 1594*4904Srs200217 * For empty value, valueLen will be zero. 1595*4904Srs200217 * For non-empty value, valueLen will be length of value data. 1596*4904Srs200217 */ 1597*4904Srs200217 1598*4904Srs200217 const void * DNSSD_API TXTRecordGetValuePtr 1599*4904Srs200217 ( 1600*4904Srs200217 uint16_t txtLen, 1601*4904Srs200217 const void *txtRecord, 1602*4904Srs200217 const char *key, 1603*4904Srs200217 uint8_t *valueLen 1604*4904Srs200217 ); 1605*4904Srs200217 1606*4904Srs200217 1607*4904Srs200217 /* TXTRecordGetCount() 1608*4904Srs200217 * 1609*4904Srs200217 * Returns the number of keys stored in the TXT Record. The count 1610*4904Srs200217 * can be used with TXTRecordGetItemAtIndex() to iterate through the keys. 1611*4904Srs200217 * 1612*4904Srs200217 * txtLen: The size of the received TXT Record. 1613*4904Srs200217 * 1614*4904Srs200217 * txtRecord: Pointer to the received TXT Record bytes. 1615*4904Srs200217 * 1616*4904Srs200217 * return value: Returns the total number of keys in the TXT Record. 1617*4904Srs200217 * 1618*4904Srs200217 */ 1619*4904Srs200217 1620*4904Srs200217 uint16_t DNSSD_API TXTRecordGetCount 1621*4904Srs200217 ( 1622*4904Srs200217 uint16_t txtLen, 1623*4904Srs200217 const void *txtRecord 1624*4904Srs200217 ); 1625*4904Srs200217 1626*4904Srs200217 1627*4904Srs200217 /* TXTRecordGetItemAtIndex() 1628*4904Srs200217 * 1629*4904Srs200217 * Allows you to retrieve a key name and value pointer, given an index into 1630*4904Srs200217 * a TXT Record. Legal index values range from zero to TXTRecordGetCount()-1. 1631*4904Srs200217 * It's also possible to iterate through keys in a TXT record by simply 1632*4904Srs200217 * calling TXTRecordGetItemAtIndex() repeatedly, beginning with index zero 1633*4904Srs200217 * and increasing until TXTRecordGetItemAtIndex() returns kDNSServiceErr_Invalid. 1634*4904Srs200217 * 1635*4904Srs200217 * On return: 1636*4904Srs200217 * For keys with no value, *value is set to NULL and *valueLen is zero. 1637*4904Srs200217 * For keys with empty value, *value is non-NULL and *valueLen is zero. 1638*4904Srs200217 * For keys with non-empty value, *value is non-NULL and *valueLen is non-zero. 1639*4904Srs200217 * 1640*4904Srs200217 * txtLen: The size of the received TXT Record. 1641*4904Srs200217 * 1642*4904Srs200217 * txtRecord: Pointer to the received TXT Record bytes. 1643*4904Srs200217 * 1644*4904Srs200217 * index: An index into the TXT Record. 1645*4904Srs200217 * 1646*4904Srs200217 * keyBufLen: The size of the string buffer being supplied. 1647*4904Srs200217 * 1648*4904Srs200217 * key: A string buffer used to store the key name. 1649*4904Srs200217 * On return, the buffer contains a null-terminated C string 1650*4904Srs200217 * giving the key name. DNS-SD TXT keys are usually 1651*4904Srs200217 * 8 characters or less. To hold the maximum possible 1652*4904Srs200217 * key name, the buffer should be 256 bytes long. 1653*4904Srs200217 * 1654*4904Srs200217 * valueLen: On output, will be set to the size of the "value" data. 1655*4904Srs200217 * 1656*4904Srs200217 * value: On output, *value is set to point to location within TXT 1657*4904Srs200217 * Record bytes that holds the value data. 1658*4904Srs200217 * 1659*4904Srs200217 * return value: Returns kDNSServiceErr_NoError on success. 1660*4904Srs200217 * Returns kDNSServiceErr_NoMemory if keyBufLen is too short. 1661*4904Srs200217 * Returns kDNSServiceErr_Invalid if index is greater than 1662*4904Srs200217 * TXTRecordGetCount()-1. 1663*4904Srs200217 */ 1664*4904Srs200217 1665*4904Srs200217 DNSServiceErrorType DNSSD_API TXTRecordGetItemAtIndex 1666*4904Srs200217 ( 1667*4904Srs200217 uint16_t txtLen, 1668*4904Srs200217 const void *txtRecord, 1669*4904Srs200217 uint16_t index, 1670*4904Srs200217 uint16_t keyBufLen, 1671*4904Srs200217 char *key, 1672*4904Srs200217 uint8_t *valueLen, 1673*4904Srs200217 const void **value 1674*4904Srs200217 ); 1675*4904Srs200217 1676*4904Srs200217 #ifdef __APPLE_API_PRIVATE 1677*4904Srs200217 1678*4904Srs200217 /* 1679*4904Srs200217 * Mac OS X specific functionality 1680*4904Srs200217 * 3rd party clients of this API should not depend on future support or availability of this routine 1681*4904Srs200217 */ 1682*4904Srs200217 1683*4904Srs200217 /* DNSServiceSetDefaultDomainForUser() 1684*4904Srs200217 * 1685*4904Srs200217 * Set the default domain for the caller's UID. Future browse and registration 1686*4904Srs200217 * calls by this user that do not specify an explicit domain will browse and 1687*4904Srs200217 * register in this wide-area domain in addition to .local. In addition, this 1688*4904Srs200217 * domain will be returned as a Browse domain via domain enumeration calls. 1689*4904Srs200217 * 1690*4904Srs200217 * 1691*4904Srs200217 * Parameters: 1692*4904Srs200217 * 1693*4904Srs200217 * flags: Pass kDNSServiceFlagsAdd to add a domain for a user. Call without 1694*4904Srs200217 * this flag set to clear a previously added domain. 1695*4904Srs200217 * 1696*4904Srs200217 * domain: The domain to be used for the caller's UID. 1697*4904Srs200217 * 1698*4904Srs200217 * return value: Returns kDNSServiceErr_NoError on succeses, otherwise returns 1699*4904Srs200217 * an error code indicating the error that occurred 1700*4904Srs200217 */ 1701*4904Srs200217 1702*4904Srs200217 DNSServiceErrorType DNSSD_API DNSServiceSetDefaultDomainForUser 1703*4904Srs200217 ( 1704*4904Srs200217 DNSServiceFlags flags, 1705*4904Srs200217 const char *domain 1706*4904Srs200217 ); 1707*4904Srs200217 1708*4904Srs200217 #endif //__APPLE_API_PRIVATE 1709*4904Srs200217 1710*4904Srs200217 // Some C compiler cleverness. We can make the compiler check certain things for us, 1711*4904Srs200217 // and report errors at compile-time if anything is wrong. The usual way to do this would 1712*4904Srs200217 // be to use a run-time "if" statement or the conventional run-time "assert" mechanism, but 1713*4904Srs200217 // then you don't find out what's wrong until you run the software. This way, if the assertion 1714*4904Srs200217 // condition is false, the array size is negative, and the complier complains immediately. 1715*4904Srs200217 1716*4904Srs200217 struct DNS_SD_CompileTimeAssertionChecks 1717*4904Srs200217 { 1718*4904Srs200217 char assert0[(sizeof(union _TXTRecordRef_t) == 16) ? 1 : -1]; 1719*4904Srs200217 }; 1720*4904Srs200217 1721*4904Srs200217 #ifdef __cplusplus 1722*4904Srs200217 } 1723*4904Srs200217 #endif 1724*4904Srs200217 1725*4904Srs200217 #endif /* _DNS_SD_H */ 1726