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