| 1 | /* -*- Mode: C; tab-width: 4 -*- |
| 2 | * |
| 3 | * Copyright (c) 2003-2004, Apple Computer, Inc. All rights reserved. |
| 4 | * |
| 5 | * Redistribution and use in source and binary forms, with or without |
| 6 | * modification, are permitted provided that the following conditions are met: |
| 7 | * |
| 8 | * 1. Redistributions of source code must retain the above copyright notice, |
| 9 | * this list of conditions and the following disclaimer. |
| 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
| 11 | * this list of conditions and the following disclaimer in the documentation |
| 12 | * and/or other materials provided with the distribution. |
| 13 | * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of its |
| 14 | * contributors may be used to endorse or promote products derived from this |
| 15 | * software without specific prior written permission. |
| 16 | * |
| 17 | * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY |
| 18 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 19 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 20 | * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY |
| 21 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 22 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 23 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
| 24 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 26 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | */ |
| 28 | |
| 29 | |
| 30 | /*! @header DNS Service Discovery |
| 31 | * |
| 32 | * @discussion This section describes the functions, callbacks, and data structures |
| 33 | * that make up the DNS Service Discovery API. |
| 34 | * |
| 35 | * The DNS Service Discovery API is part of Bonjour, Apple's implementation |
| 36 | * of zero-configuration networking (ZEROCONF). |
| 37 | * |
| 38 | * Bonjour allows you to register a network service, such as a |
| 39 | * printer or file server, so that it can be found by name or browsed |
| 40 | * for by service type and domain. Using Bonjour, applications can |
| 41 | * discover what services are available on the network, along with |
| 42 | * all the information -- such as name, IP address, and port -- |
| 43 | * necessary to access a particular service. |
| 44 | * |
| 45 | * In effect, Bonjour combines the functions of a local DNS server and |
| 46 | * AppleTalk. Bonjour allows applications to provide user-friendly printer |
| 47 | * and server browsing, among other things, over standard IP networks. |
| 48 | * This behavior is a result of combining protocols such as multicast and |
| 49 | * DNS to add new functionality to the network (such as multicast DNS). |
| 50 | * |
| 51 | * Bonjour gives applications easy access to services over local IP |
| 52 | * networks without requiring the service or the application to support |
| 53 | * an AppleTalk or a Netbeui stack, and without requiring a DNS server |
| 54 | * for the local network. |
| 55 | */ |
| 56 | |
| 57 | |
| 58 | /* _DNS_SD_H contains the mDNSResponder version number for this header file, formatted as follows: |
| 59 | * Major part of the build number * 10000 + |
| 60 | * minor part of the build number * 100 |
| 61 | * For example, Mac OS X 10.4.9 has mDNSResponder-108.4, which would be represented as |
| 62 | * version 1080400. This allows C code to do simple greater-than and less-than comparisons: |
| 63 | * e.g. an application that requires the DNSServiceGetProperty() call (new in mDNSResponder-126) can check: |
| 64 | * |
| 65 | * #if _DNS_SD_H+0 >= 1260000 |
| 66 | * ... some C code that calls DNSServiceGetProperty() ... |
| 67 | * #endif |
| 68 | * |
| 69 | * The version defined in this header file symbol allows for compile-time |
| 70 | * checking, so that C code building with earlier versions of the header file |
| 71 | * can avoid compile errors trying to use functions that aren't even defined |
| 72 | * in those earlier versions. Similar checks may also be performed at run-time: |
| 73 | * => weak linking -- to avoid link failures if run with an earlier |
| 74 | * version of the library that's missing some desired symbol, or |
| 75 | * => DNSServiceGetProperty(DaemonVersion) -- to verify whether the running daemon |
| 76 | * ("system service" on Windows) meets some required minimum functionality level. |
| 77 | */ |
| 78 | |
| 79 | #ifndef _DNS_SD_TYPES_H |
| 80 | #define _DNS_SD_TYPES_H 3200500 |
| 81 | |
| 82 | #ifdef __cplusplus |
| 83 | extern "C" { |
| 84 | #endif |
| 85 | |
| 86 | /* Set to 1 if libdispatch is supported |
| 87 | * Note: May also be set by project and/or Makefile |
| 88 | */ |
| 89 | #ifndef _DNS_SD_LIBDISPATCH |
| 90 | #define _DNS_SD_LIBDISPATCH 0 |
| 91 | #endif /* ndef _DNS_SD_LIBDISPATCH */ |
| 92 | |
| 93 | /* standard calling convention under Win32 is __stdcall */ |
| 94 | /* Note: When compiling Intel EFI (Extensible Firmware Interface) under MS Visual Studio, the */ |
| 95 | /* _WIN32 symbol is defined by the compiler even though it's NOT compiling code for Windows32 */ |
| 96 | #if defined(_WIN32) && !defined(EFI32) && !defined(EFI64) |
| 97 | #define DNSSD_API __stdcall |
| 98 | #else |
| 99 | #define DNSSD_API |
| 100 | #endif |
| 101 | |
| 102 | /* stdint.h does not exist on FreeBSD 4.x; its types are defined in sys/types.h instead */ |
| 103 | #if defined(__FreeBSD__) && (__FreeBSD__ < 5) |
| 104 | #include <sys/types.h> |
| 105 | |
| 106 | /* Likewise, on Sun, standard integer types are in sys/types.h */ |
| 107 | #elif defined(__sun__) |
| 108 | #include <sys/types.h> |
| 109 | |
| 110 | /* EFI does not have stdint.h, or anything else equivalent */ |
| 111 | #elif defined(EFI32) || defined(EFI64) || defined(EFIX64) |
| 112 | #include "Tiano.h" |
| 113 | #if !defined(_STDINT_H_) |
| 114 | typedef UINT8 uint8_t; |
| 115 | typedef INT8 int8_t; |
| 116 | typedef UINT16 uint16_t; |
| 117 | typedef INT16 int16_t; |
| 118 | typedef UINT32 uint32_t; |
| 119 | typedef INT32 int32_t; |
| 120 | #endif |
| 121 | /* Windows has its own differences */ |
| 122 | #elif defined(_WIN32) |
| 123 | #include <windows.h> |
| 124 | #define _UNUSED |
| 125 | #ifndef _MSL_STDINT_H |
| 126 | typedef UINT8 uint8_t; |
| 127 | typedef INT8 int8_t; |
| 128 | typedef UINT16 uint16_t; |
| 129 | typedef INT16 int16_t; |
| 130 | typedef UINT32 uint32_t; |
| 131 | typedef INT32 int32_t; |
| 132 | #endif |
| 133 | |
| 134 | /* All other Posix platforms use stdint.h */ |
| 135 | #else |
| 136 | #include <stdint.h> |
| 137 | #endif |
| 138 | |
| 139 | #if _DNS_SD_LIBDISPATCH |
| 140 | #include <dispatch/dispatch.h> |
| 141 | #endif |
| 142 | |
| 143 | /* DNSServiceRef, DNSRecordRef |
| 144 | * |
| 145 | * Opaque internal data types. |
| 146 | * Note: client is responsible for serializing access to these structures if |
| 147 | * they are shared between concurrent threads. |
| 148 | */ |
| 149 | |
| 150 | typedef struct _DNSServiceRef_t *DNSServiceRef; |
| 151 | typedef struct _DNSRecordRef_t *DNSRecordRef; |
| 152 | |
| 153 | struct sockaddr; |
| 154 | |
| 155 | /*! @enum General flags |
| 156 | * Most DNS-SD API functions and callbacks include a DNSServiceFlags parameter. |
| 157 | * As a general rule, any given bit in the 32-bit flags field has a specific fixed meaning, |
| 158 | * regardless of the function or callback being used. For any given function or callback, |
| 159 | * typically only a subset of the possible flags are meaningful, and all others should be zero. |
| 160 | * The discussion section for each API call describes which flags are valid for that call |
| 161 | * and callback. In some cases, for a particular call, it may be that no flags are currently |
| 162 | * defined, in which case the DNSServiceFlags parameter exists purely to allow future expansion. |
| 163 | * In all cases, developers should expect that in future releases, it is possible that new flag |
| 164 | * values will be defined, and write code with this in mind. For example, code that tests |
| 165 | * if (flags == kDNSServiceFlagsAdd) ... |
| 166 | * will fail if, in a future release, another bit in the 32-bit flags field is also set. |
| 167 | * The reliable way to test whether a particular bit is set is not with an equality test, |
| 168 | * but with a bitwise mask: |
| 169 | * if (flags & kDNSServiceFlagsAdd) ... |
| 170 | */ |
| 171 | enum |
| 172 | { |
| 173 | kDNSServiceFlagsMoreComing = 0x1, |
| 174 | /* MoreComing indicates to a callback that at least one more result is |
| 175 | * queued and will be delivered following immediately after this one. |
| 176 | * When the MoreComing flag is set, applications should not immediately |
| 177 | * update their UI, because this can result in a great deal of ugly flickering |
| 178 | * on the screen, and can waste a great deal of CPU time repeatedly updating |
| 179 | * the screen with content that is then immediately erased, over and over. |
| 180 | * Applications should wait until until MoreComing is not set, and then |
| 181 | * update their UI when no more changes are imminent. |
| 182 | * When MoreComing is not set, that doesn't mean there will be no more |
| 183 | * answers EVER, just that there are no more answers immediately |
| 184 | * available right now at this instant. If more answers become available |
| 185 | * in the future they will be delivered as usual. |
| 186 | */ |
| 187 | |
| 188 | kDNSServiceFlagsAdd = 0x2, |
| 189 | kDNSServiceFlagsDefault = 0x4, |
| 190 | /* Flags for domain enumeration and browse/query reply callbacks. |
| 191 | * "Default" applies only to enumeration and is only valid in |
| 192 | * conjunction with "Add". An enumeration callback with the "Add" |
| 193 | * flag NOT set indicates a "Remove", i.e. the domain is no longer |
| 194 | * valid. |
| 195 | */ |
| 196 | |
| 197 | kDNSServiceFlagsNoAutoRename = 0x8, |
| 198 | /* Flag for specifying renaming behavior on name conflict when registering |
| 199 | * non-shared records. By default, name conflicts are automatically handled |
| 200 | * by renaming the service. NoAutoRename overrides this behavior - with this |
| 201 | * flag set, name conflicts will result in a callback. The NoAutorename flag |
| 202 | * is only valid if a name is explicitly specified when registering a service |
| 203 | * (i.e. the default name is not used.) |
| 204 | */ |
| 205 | |
| 206 | kDNSServiceFlagsShared = 0x10, |
| 207 | kDNSServiceFlagsUnique = 0x20, |
| 208 | /* Flag for registering individual records on a connected |
| 209 | * DNSServiceRef. Shared indicates that there may be multiple records |
| 210 | * with this name on the network (e.g. PTR records). Unique indicates that the |
| 211 | * record's name is to be unique on the network (e.g. SRV records). |
| 212 | */ |
| 213 | |
| 214 | kDNSServiceFlagsBrowseDomains = 0x40, |
| 215 | kDNSServiceFlagsRegistrationDomains = 0x80, |
| 216 | /* Flags for specifying domain enumeration type in DNSServiceEnumerateDomains. |
| 217 | * BrowseDomains enumerates domains recommended for browsing, RegistrationDomains |
| 218 | * enumerates domains recommended for registration. |
| 219 | */ |
| 220 | |
| 221 | kDNSServiceFlagsLongLivedQuery = 0x100, |
| 222 | /* Flag for creating a long-lived unicast query for the DNSServiceQueryRecord call. */ |
| 223 | |
| 224 | kDNSServiceFlagsAllowRemoteQuery = 0x200, |
| 225 | /* Flag for creating a record for which we will answer remote queries |
| 226 | * (queries from hosts more than one hop away; hosts not directly connected to the local link). |
| 227 | */ |
| 228 | |
| 229 | kDNSServiceFlagsForceMulticast = 0x400, |
| 230 | /* Flag for signifying that a query or registration should be performed exclusively via multicast |
| 231 | * DNS, even for a name in a domain (e.g. foo.apple.com.) that would normally imply unicast DNS. |
| 232 | */ |
| 233 | |
| 234 | kDNSServiceFlagsForce = 0x800, |
| 235 | /* Flag for signifying a "stronger" variant of an operation. |
| 236 | * Currently defined only for DNSServiceReconfirmRecord(), where it forces a record to |
| 237 | * be removed from the cache immediately, instead of querying for a few seconds before |
| 238 | * concluding that the record is no longer valid and then removing it. This flag should |
| 239 | * be used with caution because if a service browsing PTR record is indeed still valid |
| 240 | * on the network, forcing its removal will result in a user-interface flap -- the |
| 241 | * discovered service instance will disappear, and then re-appear moments later. |
| 242 | */ |
| 243 | |
| 244 | kDNSServiceFlagsReturnIntermediates = 0x1000, |
| 245 | /* Flag for returning intermediate results. |
| 246 | * For example, if a query results in an authoritative NXDomain (name does not exist) |
| 247 | * then that result is returned to the client. However the query is not implicitly |
| 248 | * cancelled -- it remains active and if the answer subsequently changes |
| 249 | * (e.g. because a VPN tunnel is subsequently established) then that positive |
| 250 | * result will still be returned to the client. |
| 251 | * Similarly, if a query results in a CNAME record, then in addition to following |
| 252 | * the CNAME referral, the intermediate CNAME result is also returned to the client. |
| 253 | * When this flag is not set, NXDomain errors are not returned, and CNAME records |
| 254 | * are followed silently without informing the client of the intermediate steps. |
| 255 | * (In earlier builds this flag was briefly calledkDNSServiceFlagsReturnCNAME) |
| 256 | */ |
| 257 | |
| 258 | kDNSServiceFlagsNonBrowsable = 0x2000, |
| 259 | /* A service registered with the NonBrowsable flag set can be resolved using |
| 260 | * DNSServiceResolve(), but will not be discoverable using DNSServiceBrowse(). |
| 261 | * This is for cases where the name is actually a GUID; it is found by other means; |
| 262 | * there is no end-user benefit to browsing to find a long list of opaque GUIDs. |
| 263 | * Using the NonBrowsable flag creates SRV+TXT without the cost of also advertising |
| 264 | * an associated PTR record. |
| 265 | */ |
| 266 | |
| 267 | kDNSServiceFlagsShareConnection = 0x4000, |
| 268 | /* For efficiency, clients that perform many concurrent operations may want to use a |
| 269 | * single Unix Domain Socket connection with the background daemon, instead of having a |
| 270 | * separate connection for each independent operation. To use this mode, clients first |
| 271 | * call DNSServiceCreateConnection(&MainRef) to initialize the main DNSServiceRef. |
| 272 | * For each subsequent operation that is to share that same connection, the client copies |
| 273 | * the MainRef, and then passes the address of that copy, setting the ShareConnection flag |
| 274 | * to tell the library that this DNSServiceRef is not a typical uninitialized DNSServiceRef; |
| 275 | * it's a copy of an existing DNSServiceRef whose connection information should be reused. |
| 276 | * |
| 277 | * For example: |
| 278 | * |
| 279 | * DNSServiceErrorType error; |
| 280 | * DNSServiceRef MainRef; |
| 281 | * error = DNSServiceCreateConnection(&MainRef); |
| 282 | * if (error) ... |
| 283 | * DNSServiceRef BrowseRef = MainRef; // Important: COPY the primary DNSServiceRef first... |
| 284 | * error = DNSServiceBrowse(&BrowseRef, kDNSServiceFlagsShareConnection, ...); // then use the copy |
| 285 | * if (error) ... |
| 286 | * ... |
| 287 | * DNSServiceRefDeallocate(BrowseRef); // Terminate the browse operation |
| 288 | * DNSServiceRefDeallocate(MainRef); // Terminate the shared connection |
| 289 | * |
| 290 | * Notes: |
| 291 | * |
| 292 | * 1. Collective kDNSServiceFlagsMoreComing flag |
| 293 | * When callbacks are invoked using a shared DNSServiceRef, the |
| 294 | * kDNSServiceFlagsMoreComing flag applies collectively to *all* active |
| 295 | * operations sharing the same parent DNSServiceRef. If the MoreComing flag is |
| 296 | * set it means that there are more results queued on this parent DNSServiceRef, |
| 297 | * but not necessarily more results for this particular callback function. |
| 298 | * The implication of this for client programmers is that when a callback |
| 299 | * is invoked with the MoreComing flag set, the code should update its |
| 300 | * internal data structures with the new result, and set a variable indicating |
| 301 | * that its UI needs to be updated. Then, later when a callback is eventually |
| 302 | * invoked with the MoreComing flag not set, the code should update *all* |
| 303 | * stale UI elements related to that shared parent DNSServiceRef that need |
| 304 | * updating, not just the UI elements related to the particular callback |
| 305 | * that happened to be the last one to be invoked. |
| 306 | * |
| 307 | * 2. Canceling operations and kDNSServiceFlagsMoreComing |
| 308 | * Whenever you cancel any operation for which you had deferred UI updates |
| 309 | * waiting because of a kDNSServiceFlagsMoreComing flag, you should perform |
| 310 | * those deferred UI updates. This is because, after cancelling the operation, |
| 311 | * you can no longer wait for a callback *without* MoreComing set, to tell |
| 312 | * you do perform your deferred UI updates (the operation has been canceled, |
| 313 | * so there will be no more callbacks). An implication of the collective |
| 314 | * kDNSServiceFlagsMoreComing flag for shared connections is that this |
| 315 | * guideline applies more broadly -- any time you cancel an operation on |
| 316 | * a shared connection, you should perform all deferred UI updates for all |
| 317 | * operations sharing that connection. This is because the MoreComing flag |
| 318 | * might have been referring to events coming for the operation you canceled, |
| 319 | * which will now not be coming because the operation has been canceled. |
| 320 | * |
| 321 | * 3. Only share DNSServiceRef's created with DNSServiceCreateConnection |
| 322 | * Calling DNSServiceCreateConnection(&ref) creates a special shareable DNSServiceRef. |
| 323 | * DNSServiceRef's created by other calls like DNSServiceBrowse() or DNSServiceResolve() |
| 324 | * cannot be shared by copying them and using kDNSServiceFlagsShareConnection. |
| 325 | * |
| 326 | * 4. Don't Double-Deallocate |
| 327 | * Calling DNSServiceRefDeallocate(ref) for a particular operation's DNSServiceRef terminates |
| 328 | * just that operation. Calling DNSServiceRefDeallocate(ref) for the main shared DNSServiceRef |
| 329 | * (the parent DNSServiceRef, originally created by DNSServiceCreateConnection(&ref)) |
| 330 | * automatically terminates the shared connection and all operations that were still using it. |
| 331 | * After doing this, DO NOT then attempt to deallocate any remaining subordinate DNSServiceRef's. |
| 332 | * The memory used by those subordinate DNSServiceRef's has already been freed, so any attempt |
| 333 | * to do a DNSServiceRefDeallocate (or any other operation) on them will result in accesses |
| 334 | * to freed memory, leading to crashes or other equally undesirable results. |
| 335 | * |
| 336 | * 5. Thread Safety |
| 337 | * The dns_sd.h API does not presuppose any particular threading model, and consequently |
| 338 | * does no locking of its own (which would require linking some specific threading library). |
| 339 | * If client code calls API routines on the same DNSServiceRef concurrently |
| 340 | * from multiple threads, it is the client's responsibility to use a mutext |
| 341 | * lock or take similar appropriate precautions to serialize those calls. |
| 342 | */ |
| 343 | |
| 344 | kDNSServiceFlagsSuppressUnusable = 0x8000, |
| 345 | /* |
| 346 | * This flag is meaningful only in DNSServiceQueryRecord which suppresses unusable queries on the |
| 347 | * wire. If "hostname" is a wide-area unicast DNS hostname (i.e. not a ".local." name) |
| 348 | * but this host has no routable IPv6 address, then the call will not try to look up IPv6 addresses |
| 349 | * for "hostname", since any addresses it found would be unlikely to be of any use anyway. Similarly, |
| 350 | * if this host has no routable IPv4 address, the call will not try to look up IPv4 addresses for |
| 351 | * "hostname". |
| 352 | */ |
| 353 | |
| 354 | kDNSServiceFlagsTimeout = 0x10000, |
| 355 | /* |
| 356 | * When kDNServiceFlagsTimeout is passed to DNSServiceQueryRecord or DNSServiceGetAddrInfo, the query is |
| 357 | * stopped after a certain number of seconds have elapsed. The time at which the query will be stopped |
| 358 | * is determined by the system and cannot be configured by the user. The query will be stopped irrespective |
| 359 | * of whether a response was given earlier or not. When the query is stopped, the callback will be called |
| 360 | * with an error code of kDNSServiceErr_Timeout and a NULL sockaddr will be returned for DNSServiceGetAddrInfo |
| 361 | * and zero length rdata will be returned for DNSServiceQueryRecord. |
| 362 | */ |
| 363 | |
| 364 | kDNSServiceFlagsIncludeP2P = 0x20000, |
| 365 | /* |
| 366 | * Include P2P interfaces when kDNSServiceInterfaceIndexAny is specified. |
| 367 | * By default, specifying kDNSServiceInterfaceIndexAny does not include P2P interfaces. |
| 368 | */ |
| 369 | kDNSServiceFlagsWakeOnResolve = 0x40000 |
| 370 | /* |
| 371 | * This flag is meaningful only in DNSServiceResolve. When set, it tries to send a magic packet |
| 372 | * to wake up the client. |
| 373 | */ |
| 374 | }; |
| 375 | |
| 376 | /* Possible protocols for DNSServiceNATPortMappingCreate(). */ |
| 377 | enum |
| 378 | { |
| 379 | kDNSServiceProtocol_IPv4 = 0x01, |
| 380 | kDNSServiceProtocol_IPv6 = 0x02, |
| 381 | /* 0x04 and 0x08 reserved for future internetwork protocols */ |
| 382 | |
| 383 | kDNSServiceProtocol_UDP = 0x10, |
| 384 | kDNSServiceProtocol_TCP = 0x20 |
| 385 | /* 0x40 and 0x80 reserved for future transport protocols, e.g. SCTP [RFC 2960] |
| 386 | * or DCCP [RFC 4340]. If future NAT gateways are created that support port |
| 387 | * mappings for these protocols, new constants will be defined here. |
| 388 | */ |
| 389 | }; |
| 390 | |
| 391 | /* |
| 392 | * The values for DNS Classes and Types are listed in RFC 1035, and are available |
| 393 | * on every OS in its DNS header file. Unfortunately every OS does not have the |
| 394 | * same header file containing DNS Class and Type constants, and the names of |
| 395 | * the constants are not consistent. For example, BIND 8 uses "T_A", |
| 396 | * BIND 9 uses "ns_t_a", Windows uses "DNS_TYPE_A", etc. |
| 397 | * For this reason, these constants are also listed here, so that code using |
| 398 | * the DNS-SD programming APIs can use these constants, so that the same code |
| 399 | * can compile on all our supported platforms. |
| 400 | */ |
| 401 | |
| 402 | enum |
| 403 | { |
| 404 | kDNSServiceClass_IN = 1 /* Internet */ |
| 405 | }; |
| 406 | |
| 407 | enum |
| 408 | { |
| 409 | kDNSServiceType_A = 1, /* Host address. */ |
| 410 | kDNSServiceType_NS = 2, /* Authoritative server. */ |
| 411 | kDNSServiceType_MD = 3, /* Mail destination. */ |
| 412 | kDNSServiceType_MF = 4, /* Mail forwarder. */ |
| 413 | kDNSServiceType_CNAME = 5, /* Canonical name. */ |
| 414 | kDNSServiceType_SOA = 6, /* Start of authority zone. */ |
| 415 | kDNSServiceType_MB = 7, /* Mailbox domain name. */ |
| 416 | kDNSServiceType_MG = 8, /* Mail group member. */ |
| 417 | kDNSServiceType_MR = 9, /* Mail rename name. */ |
| 418 | kDNSServiceType_NULL = 10, /* Null resource record. */ |
| 419 | kDNSServiceType_WKS = 11, /* Well known service. */ |
| 420 | kDNSServiceType_PTR = 12, /* Domain name pointer. */ |
| 421 | kDNSServiceType_HINFO = 13, /* Host information. */ |
| 422 | kDNSServiceType_MINFO = 14, /* Mailbox information. */ |
| 423 | kDNSServiceType_MX = 15, /* Mail routing information. */ |
| 424 | kDNSServiceType_TXT = 16, /* One or more text strings (NOT "zero or more..."). */ |
| 425 | kDNSServiceType_RP = 17, /* Responsible person. */ |
| 426 | kDNSServiceType_AFSDB = 18, /* AFS cell database. */ |
| 427 | kDNSServiceType_X25 = 19, /* X_25 calling address. */ |
| 428 | kDNSServiceType_ISDN = 20, /* ISDN calling address. */ |
| 429 | kDNSServiceType_RT = 21, /* Router. */ |
| 430 | kDNSServiceType_NSAP = 22, /* NSAP address. */ |
| 431 | kDNSServiceType_NSAP_PTR = 23, /* Reverse NSAP lookup (deprecated). */ |
| 432 | kDNSServiceType_SIG = 24, /* Security signature. */ |
| 433 | kDNSServiceType_KEY = 25, /* Security key. */ |
| 434 | kDNSServiceType_PX = 26, /* X.400 mail mapping. */ |
| 435 | kDNSServiceType_GPOS = 27, /* Geographical position (withdrawn). */ |
| 436 | kDNSServiceType_AAAA = 28, /* IPv6 Address. */ |
| 437 | kDNSServiceType_LOC = 29, /* Location Information. */ |
| 438 | kDNSServiceType_NXT = 30, /* Next domain (security). */ |
| 439 | kDNSServiceType_EID = 31, /* Endpoint identifier. */ |
| 440 | kDNSServiceType_NIMLOC = 32, /* Nimrod Locator. */ |
| 441 | kDNSServiceType_SRV = 33, /* Server Selection. */ |
| 442 | kDNSServiceType_ATMA = 34, /* ATM Address */ |
| 443 | kDNSServiceType_NAPTR = 35, /* Naming Authority PoinTeR */ |
| 444 | kDNSServiceType_KX = 36, /* Key Exchange */ |
| 445 | kDNSServiceType_CERT = 37, /* Certification record */ |
| 446 | kDNSServiceType_A6 = 38, /* IPv6 Address (deprecated) */ |
| 447 | kDNSServiceType_DNAME = 39, /* Non-terminal DNAME (for IPv6) */ |
| 448 | kDNSServiceType_SINK = 40, /* Kitchen sink (experimental) */ |
| 449 | kDNSServiceType_OPT = 41, /* EDNS0 option (meta-RR) */ |
| 450 | kDNSServiceType_APL = 42, /* Address Prefix List */ |
| 451 | kDNSServiceType_DS = 43, /* Delegation Signer */ |
| 452 | kDNSServiceType_SSHFP = 44, /* SSH Key Fingerprint */ |
| 453 | kDNSServiceType_IPSECKEY = 45, /* IPSECKEY */ |
| 454 | kDNSServiceType_RRSIG = 46, /* RRSIG */ |
| 455 | kDNSServiceType_NSEC = 47, /* Denial of Existence */ |
| 456 | kDNSServiceType_DNSKEY = 48, /* DNSKEY */ |
| 457 | kDNSServiceType_DHCID = 49, /* DHCP Client Identifier */ |
| 458 | kDNSServiceType_NSEC3 = 50, /* Hashed Authenticated Denial of Existence */ |
| 459 | kDNSServiceType_NSEC3PARAM = 51, /* Hashed Authenticated Denial of Existence */ |
| 460 | |
| 461 | kDNSServiceType_HIP = 55, /* Host Identity Protocol */ |
| 462 | |
| 463 | kDNSServiceType_SPF = 99, /* Sender Policy Framework for E-Mail */ |
| 464 | kDNSServiceType_UINFO = 100, /* IANA-Reserved */ |
| 465 | kDNSServiceType_UID = 101, /* IANA-Reserved */ |
| 466 | kDNSServiceType_GID = 102, /* IANA-Reserved */ |
| 467 | kDNSServiceType_UNSPEC = 103, /* IANA-Reserved */ |
| 468 | |
| 469 | kDNSServiceType_TKEY = 249, /* Transaction key */ |
| 470 | kDNSServiceType_TSIG = 250, /* Transaction signature. */ |
| 471 | kDNSServiceType_IXFR = 251, /* Incremental zone transfer. */ |
| 472 | kDNSServiceType_AXFR = 252, /* Transfer zone of authority. */ |
| 473 | kDNSServiceType_MAILB = 253, /* Transfer mailbox records. */ |
| 474 | kDNSServiceType_MAILA = 254, /* Transfer mail agent records. */ |
| 475 | kDNSServiceType_ANY = 255 /* Wildcard match. */ |
| 476 | }; |
| 477 | |
| 478 | /* possible error code values */ |
| 479 | enum |
| 480 | { |
| 481 | kDNSServiceErr_NoError = 0, |
| 482 | kDNSServiceErr_Unknown = -65537, /* 0xFFFE FFFF */ |
| 483 | kDNSServiceErr_NoSuchName = -65538, |
| 484 | kDNSServiceErr_NoMemory = -65539, |
| 485 | kDNSServiceErr_BadParam = -65540, |
| 486 | kDNSServiceErr_BadReference = -65541, |
| 487 | kDNSServiceErr_BadState = -65542, |
| 488 | kDNSServiceErr_BadFlags = -65543, |
| 489 | kDNSServiceErr_Unsupported = -65544, |
| 490 | kDNSServiceErr_NotInitialized = -65545, |
| 491 | kDNSServiceErr_AlreadyRegistered = -65547, |
| 492 | kDNSServiceErr_NameConflict = -65548, |
| 493 | kDNSServiceErr_Invalid = -65549, |
| 494 | kDNSServiceErr_Firewall = -65550, |
| 495 | kDNSServiceErr_Incompatible = -65551, /* client library incompatible with daemon */ |
| 496 | kDNSServiceErr_BadInterfaceIndex = -65552, |
| 497 | kDNSServiceErr_Refused = -65553, |
| 498 | kDNSServiceErr_NoSuchRecord = -65554, |
| 499 | kDNSServiceErr_NoAuth = -65555, |
| 500 | kDNSServiceErr_NoSuchKey = -65556, |
| 501 | kDNSServiceErr_NATTraversal = -65557, |
| 502 | kDNSServiceErr_DoubleNAT = -65558, |
| 503 | kDNSServiceErr_BadTime = -65559, /* Codes up to here existed in Tiger */ |
| 504 | kDNSServiceErr_BadSig = -65560, |
| 505 | kDNSServiceErr_BadKey = -65561, |
| 506 | kDNSServiceErr_Transient = -65562, |
| 507 | kDNSServiceErr_ServiceNotRunning = -65563, /* Background daemon not running */ |
| 508 | kDNSServiceErr_NATPortMappingUnsupported = -65564, /* NAT doesn't support NAT-PMP or UPnP */ |
| 509 | kDNSServiceErr_NATPortMappingDisabled = -65565, /* NAT supports NAT-PMP or UPnP but it's disabled by the administrator */ |
| 510 | kDNSServiceErr_NoRouter = -65566, /* No router currently configured (probably no network connectivity) */ |
| 511 | kDNSServiceErr_PollingMode = -65567, |
| 512 | kDNSServiceErr_Timeout = -65568 |
| 513 | |
| 514 | /* mDNS Error codes are in the range |
| 515 | * FFFE FF00 (-65792) to FFFE FFFF (-65537) */ |
| 516 | }; |
| 517 | |
| 518 | /* Maximum length, in bytes, of a service name represented as a */ |
| 519 | /* literal C-String, including the terminating NULL at the end. */ |
| 520 | |
| 521 | #define kDNSServiceMaxServiceName 64 |
| 522 | |
| 523 | /* Maximum length, in bytes, of a domain name represented as an *escaped* C-String */ |
| 524 | /* including the final trailing dot, and the C-String terminating NULL at the end. */ |
| 525 | |
| 526 | #define kDNSServiceMaxDomainName 1009 |
| 527 | |
| 528 | /* |
| 529 | * Notes on DNS Name Escaping |
| 530 | * -- or -- |
| 531 | * "Why is kDNSServiceMaxDomainName 1009, when the maximum legal domain name is 256 bytes?" |
| 532 | * |
| 533 | * All strings used in the DNS-SD APIs are UTF-8 strings. Apart from the exceptions noted below, |
| 534 | * the APIs expect the strings to be properly escaped, using the conventional DNS escaping rules: |
| 535 | * |
| 536 | * '\\' represents a single literal '\' in the name |
| 537 | * '\.' represents a single literal '.' in the name |
| 538 | * '\ddd', where ddd is a three-digit decimal value from 000 to 255, |
| 539 | * represents a single literal byte with that value. |
| 540 | * A bare unescaped '.' is a label separator, marking a boundary between domain and subdomain. |
| 541 | * |
| 542 | * The exceptions, that do not use escaping, are the routines where the full |
| 543 | * DNS name of a resource is broken, for convenience, into servicename/regtype/domain. |
| 544 | * In these routines, the "servicename" is NOT escaped. It does not need to be, since |
| 545 | * it is, by definition, just a single literal string. Any characters in that string |
| 546 | * represent exactly what they are. The "regtype" portion is, technically speaking, |
| 547 | * escaped, but since legal regtypes are only allowed to contain letters, digits, |
| 548 | * and hyphens, there is nothing to escape, so the issue is moot. The "domain" |
| 549 | * portion is also escaped, though most domains in use on the public Internet |
| 550 | * today, like regtypes, don't contain any characters that need to be escaped. |
| 551 | * As DNS-SD becomes more popular, rich-text domains for service discovery will |
| 552 | * become common, so software should be written to cope with domains with escaping. |
| 553 | * |
| 554 | * The servicename may be up to 63 bytes of UTF-8 text (not counting the C-String |
| 555 | * terminating NULL at the end). The regtype is of the form _service._tcp or |
| 556 | * _service._udp, where the "service" part is 1-15 characters, which may be |
| 557 | * letters, digits, or hyphens. The domain part of the three-part name may be |
| 558 | * any legal domain, providing that the resulting servicename+regtype+domain |
| 559 | * name does not exceed 256 bytes. |
| 560 | * |
| 561 | * For most software, these issues are transparent. When browsing, the discovered |
| 562 | * servicenames should simply be displayed as-is. When resolving, the discovered |
| 563 | * servicename/regtype/domain are simply passed unchanged to DNSServiceResolve(). |
| 564 | * When a DNSServiceResolve() succeeds, the returned fullname is already in |
| 565 | * the correct format to pass to standard system DNS APIs such as res_query(). |
| 566 | * For converting from servicename/regtype/domain to a single properly-escaped |
| 567 | * full DNS name, the helper function DNSServiceConstructFullName() is provided. |
| 568 | * |
| 569 | * The following (highly contrived) example illustrates the escaping process. |
| 570 | * Suppose you have an service called "Dr. Smith\Dr. Johnson", of type "_ftp._tcp" |
| 571 | * in subdomain "4th. Floor" of subdomain "Building 2" of domain "apple.com." |
| 572 | * The full (escaped) DNS name of this service's SRV record would be: |
| 573 | * Dr\.\032Smith\\Dr\.\032Johnson._ftp._tcp.4th\.\032Floor.Building\0322.apple.com. |
| 574 | */ |
| 575 | |
| 576 | |
| 577 | /* |
| 578 | * Constants for specifying an interface index |
| 579 | * |
| 580 | * Specific interface indexes are identified via a 32-bit unsigned integer returned |
| 581 | * by the if_nametoindex() family of calls. |
| 582 | * |
| 583 | * If the client passes 0 for interface index, that means "do the right thing", |
| 584 | * which (at present) means, "if the name is in an mDNS local multicast domain |
| 585 | * (e.g. 'local.', '254.169.in-addr.arpa.', '{8,9,A,B}.E.F.ip6.arpa.') then multicast |
| 586 | * on all applicable interfaces, otherwise send via unicast to the appropriate |
| 587 | * DNS server." Normally, most clients will use 0 for interface index to |
| 588 | * automatically get the default sensible behaviour. |
| 589 | * |
| 590 | * If the client passes a positive interface index, then for multicast names that |
| 591 | * indicates to do the operation only on that one interface. For unicast names the |
| 592 | * interface index is ignored unless kDNSServiceFlagsForceMulticast is also set. |
| 593 | * |
| 594 | * If the client passes kDNSServiceInterfaceIndexLocalOnly when registering |
| 595 | * a service, then that service will be found *only* by other local clients |
| 596 | * on the same machine that are browsing using kDNSServiceInterfaceIndexLocalOnly |
| 597 | * or kDNSServiceInterfaceIndexAny. |
| 598 | * If a client has a 'private' service, accessible only to other processes |
| 599 | * running on the same machine, this allows the client to advertise that service |
| 600 | * in a way such that it does not inadvertently appear in service lists on |
| 601 | * all the other machines on the network. |
| 602 | * |
| 603 | * If the client passes kDNSServiceInterfaceIndexLocalOnly when browsing |
| 604 | * then it will find *all* records registered on that same local machine. |
| 605 | * Clients explicitly wishing to discover *only* LocalOnly services can |
| 606 | * accomplish this by inspecting the interfaceIndex of each service reported |
| 607 | * to their DNSServiceBrowseReply() callback function, and discarding those |
| 608 | * where the interface index is not kDNSServiceInterfaceIndexLocalOnly. |
| 609 | * |
| 610 | * kDNSServiceInterfaceIndexP2P is meaningful only in Browse, QueryRecord, |
| 611 | * and Resolve operations. It should not be used in other DNSService APIs. |
| 612 | * |
| 613 | * - If kDNSServiceInterfaceIndexP2P is passed to DNSServiceBrowse or |
| 614 | * DNSServiceQueryRecord, it restricts the operation to P2P. |
| 615 | * |
| 616 | * - If kDNSServiceInterfaceIndexP2P is passed to DNSServiceResolve, it is |
| 617 | * mapped internally to kDNSServiceInterfaceIndexAny, because resolving |
| 618 | * a P2P service may create and/or enable an interface whose index is not |
| 619 | * known a priori. The resolve callback will indicate the index of the |
| 620 | * interface via which the service can be accessed. |
| 621 | * |
| 622 | * If applications pass kDNSServiceInterfaceIndexAny to DNSServiceBrowse |
| 623 | * or DNSServiceQueryRecord, they must set the kDNSServiceFlagsIncludeP2P flag |
| 624 | * to include P2P. In this case, if a service instance or the record being queried |
| 625 | * is found over P2P, the resulting ADD event will indicate kDNSServiceInterfaceIndexP2P |
| 626 | * as the interface index. |
| 627 | */ |
| 628 | |
| 629 | #define kDNSServiceInterfaceIndexAny 0 |
| 630 | #define kDNSServiceInterfaceIndexLocalOnly ((uint32_t)-1) |
| 631 | #define kDNSServiceInterfaceIndexUnicast ((uint32_t)-2) |
| 632 | #define kDNSServiceInterfaceIndexP2P ((uint32_t)-3) |
| 633 | |
| 634 | typedef uint32_t DNSServiceFlags; |
| 635 | typedef uint32_t DNSServiceProtocol; |
| 636 | typedef int32_t DNSServiceErrorType; |
| 637 | |
| 638 | /* |
| 639 | * When requesting kDNSServiceProperty_DaemonVersion, the result pointer must point |
| 640 | * to a 32-bit unsigned integer, and the size parameter must be set to sizeof(uint32_t). |
| 641 | * |
| 642 | * On return, the 32-bit unsigned integer contains the version number, formatted as follows: |
| 643 | * Major part of the build number * 10000 + |
| 644 | * minor part of the build number * 100 |
| 645 | * |
| 646 | * For example, Mac OS X 10.4.9 has mDNSResponder-108.4, which would be represented as |
| 647 | * version 1080400. This allows applications to do simple greater-than and less-than comparisons: |
| 648 | * e.g. an application that requires at least mDNSResponder-108.4 can check: |
| 649 | * |
| 650 | * if (version >= 1080400) ... |
| 651 | * |
| 652 | * Example usage: |
| 653 | * |
| 654 | * uint32_t version; |
| 655 | * uint32_t size = sizeof(version); |
| 656 | * DNSServiceErrorType err = DNSServiceGetProperty(kDNSServiceProperty_DaemonVersion, &version, &size); |
| 657 | * if (!err) printf("Bonjour version is %d.%d\n", version / 10000, version / 100 % 100); |
| 658 | */ |
| 659 | |
| 660 | #define kDNSServiceProperty_DaemonVersion "DaemonVersion" |
| 661 | |
| 662 | |
| 663 | /* DNSServiceEnumerateDomains() |
| 664 | * |
| 665 | * Asynchronously enumerate domains available for browsing and registration. |
| 666 | * |
| 667 | * The enumeration MUST be cancelled via DNSServiceRefDeallocate() when no more domains |
| 668 | * are to be found. |
| 669 | * |
| 670 | * Note that the names returned are (like all of DNS-SD) UTF-8 strings, |
| 671 | * and are escaped using standard DNS escaping rules. |
| 672 | * (See "Notes on DNS Name Escaping" earlier in this file for more details.) |
| 673 | * A graphical browser displaying a hierarchical tree-structured view should cut |
| 674 | * the names at the bare dots to yield individual labels, then de-escape each |
| 675 | * label according to the escaping rules, and then display the resulting UTF-8 text. |
| 676 | * |
| 677 | * DNSServiceDomainEnumReply Callback Parameters: |
| 678 | * |
| 679 | * sdRef: The DNSServiceRef initialized by DNSServiceEnumerateDomains(). |
| 680 | * |
| 681 | * flags: Possible values are: |
| 682 | * kDNSServiceFlagsMoreComing |
| 683 | * kDNSServiceFlagsAdd |
| 684 | * kDNSServiceFlagsDefault |
| 685 | * |
| 686 | * interfaceIndex: Specifies the interface on which the domain exists. (The index for a given |
| 687 | * interface is determined via the if_nametoindex() family of calls.) |
| 688 | * |
| 689 | * errorCode: Will be kDNSServiceErr_NoError (0) on success, otherwise indicates |
| 690 | * the failure that occurred (other parameters are undefined if errorCode is nonzero). |
| 691 | * |
| 692 | * replyDomain: The name of the domain. |
| 693 | * |
| 694 | * context: The context pointer passed to DNSServiceEnumerateDomains. |
| 695 | * |
| 696 | */ |
| 697 | |
| 698 | typedef void (DNSSD_API *DNSServiceDomainEnumReply) |
| 699 | ( |
| 700 | DNSServiceRef sdRef, |
| 701 | DNSServiceFlags flags, |
| 702 | uint32_t interfaceIndex, |
| 703 | DNSServiceErrorType errorCode, |
| 704 | const char *replyDomain, |
| 705 | void *context |
| 706 | ); |
| 707 | |
| 708 | |
| 709 | /* Register a service that is discovered via Browse() and Resolve() calls. |
| 710 | * |
| 711 | * DNSServiceRegisterReply() Callback Parameters: |
| 712 | * |
| 713 | * sdRef: The DNSServiceRef initialized by DNSServiceRegister(). |
| 714 | * |
| 715 | * flags: When a name is successfully registered, the callback will be |
| 716 | * invoked with the kDNSServiceFlagsAdd flag set. When Wide-Area |
| 717 | * DNS-SD is in use, it is possible for a single service to get |
| 718 | * more than one success callback (e.g. one in the "local" multicast |
| 719 | * DNS domain, and another in a wide-area unicast DNS domain). |
| 720 | * If a successfully-registered name later suffers a name conflict |
| 721 | * or similar problem and has to be deregistered, the callback will |
| 722 | * be invoked with the kDNSServiceFlagsAdd flag not set. The callback |
| 723 | * is *not* invoked in the case where the caller explicitly terminates |
| 724 | * the service registration by calling DNSServiceRefDeallocate(ref); |
| 725 | * |
| 726 | * errorCode: Will be kDNSServiceErr_NoError on success, otherwise will |
| 727 | * indicate the failure that occurred (including name conflicts, |
| 728 | * if the kDNSServiceFlagsNoAutoRename flag was used when registering.) |
| 729 | * Other parameters are undefined if errorCode is nonzero. |
| 730 | * |
| 731 | * name: The service name registered (if the application did not specify a name in |
| 732 | * DNSServiceRegister(), this indicates what name was automatically chosen). |
| 733 | * |
| 734 | * regtype: The type of service registered, as it was passed to the callout. |
| 735 | * |
| 736 | * domain: The domain on which the service was registered (if the application did not |
| 737 | * specify a domain in DNSServiceRegister(), this indicates the default domain |
| 738 | * on which the service was registered). |
| 739 | * |
| 740 | * context: The context pointer that was passed to the callout. |
| 741 | * |
| 742 | */ |
| 743 | |
| 744 | typedef void (DNSSD_API *DNSServiceRegisterReply) |
| 745 | ( |
| 746 | DNSServiceRef sdRef, |
| 747 | DNSServiceFlags flags, |
| 748 | DNSServiceErrorType errorCode, |
| 749 | const char *name, |
| 750 | const char *regtype, |
| 751 | const char *domain, |
| 752 | void *context |
| 753 | ); |
| 754 | |
| 755 | |
| 756 | /* Browse for instances of a service. |
| 757 | * |
| 758 | * DNSServiceBrowseReply() Parameters: |
| 759 | * |
| 760 | * sdRef: The DNSServiceRef initialized by DNSServiceBrowse(). |
| 761 | * |
| 762 | * flags: Possible values are kDNSServiceFlagsMoreComing and kDNSServiceFlagsAdd. |
| 763 | * See flag definitions for details. |
| 764 | * |
| 765 | * interfaceIndex: The interface on which the service is advertised. This index should |
| 766 | * be passed to DNSServiceResolve() when resolving the service. |
| 767 | * |
| 768 | * errorCode: Will be kDNSServiceErr_NoError (0) on success, otherwise will |
| 769 | * indicate the failure that occurred. Other parameters are undefined if |
| 770 | * the errorCode is nonzero. |
| 771 | * |
| 772 | * serviceName: The discovered service name. This name should be displayed to the user, |
| 773 | * and stored for subsequent use in the DNSServiceResolve() call. |
| 774 | * |
| 775 | * regtype: The service type, which is usually (but not always) the same as was passed |
| 776 | * to DNSServiceBrowse(). One case where the discovered service type may |
| 777 | * not be the same as the requested service type is when using subtypes: |
| 778 | * The client may want to browse for only those ftp servers that allow |
| 779 | * anonymous connections. The client will pass the string "_ftp._tcp,_anon" |
| 780 | * to DNSServiceBrowse(), but the type of the service that's discovered |
| 781 | * is simply "_ftp._tcp". The regtype for each discovered service instance |
| 782 | * should be stored along with the name, so that it can be passed to |
| 783 | * DNSServiceResolve() when the service is later resolved. |
| 784 | * |
| 785 | * domain: The domain of the discovered service instance. This may or may not be the |
| 786 | * same as the domain that was passed to DNSServiceBrowse(). The domain for each |
| 787 | * discovered service instance should be stored along with the name, so that |
| 788 | * it can be passed to DNSServiceResolve() when the service is later resolved. |
| 789 | * |
| 790 | * context: The context pointer that was passed to the callout. |
| 791 | * |
| 792 | */ |
| 793 | |
| 794 | typedef void (DNSSD_API *DNSServiceBrowseReply) |
| 795 | ( |
| 796 | DNSServiceRef sdRef, |
| 797 | DNSServiceFlags flags, |
| 798 | uint32_t interfaceIndex, |
| 799 | DNSServiceErrorType errorCode, |
| 800 | const char *serviceName, |
| 801 | const char *regtype, |
| 802 | const char *replyDomain, |
| 803 | void *context |
| 804 | ); |
| 805 | |
| 806 | |
| 807 | |
| 808 | /* DNSServiceResolve() |
| 809 | * |
| 810 | * Resolve a service name discovered via DNSServiceBrowse() to a target host name, port number, and |
| 811 | * txt record. |
| 812 | * |
| 813 | * Note: Applications should NOT use DNSServiceResolve() solely for txt record monitoring - use |
| 814 | * DNSServiceQueryRecord() instead, as it is more efficient for this task. |
| 815 | * |
| 816 | * Note: When the desired results have been returned, the client MUST terminate the resolve by calling |
| 817 | * DNSServiceRefDeallocate(). |
| 818 | * |
| 819 | * Note: DNSServiceResolve() behaves correctly for typical services that have a single SRV record |
| 820 | * and a single TXT record. To resolve non-standard services with multiple SRV or TXT records, |
| 821 | * DNSServiceQueryRecord() should be used. |
| 822 | * |
| 823 | * DNSServiceResolveReply Callback Parameters: |
| 824 | * |
| 825 | * sdRef: The DNSServiceRef initialized by DNSServiceResolve(). |
| 826 | * |
| 827 | * flags: Possible values: kDNSServiceFlagsMoreComing |
| 828 | * |
| 829 | * interfaceIndex: The interface on which the service was resolved. |
| 830 | * |
| 831 | * errorCode: Will be kDNSServiceErr_NoError (0) on success, otherwise will |
| 832 | * indicate the failure that occurred. Other parameters are undefined if |
| 833 | * the errorCode is nonzero. |
| 834 | * |
| 835 | * fullname: The full service domain name, in the form <servicename>.<protocol>.<domain>. |
| 836 | * (This name is escaped following standard DNS rules, making it suitable for |
| 837 | * passing to standard system DNS APIs such as res_query(), or to the |
| 838 | * special-purpose functions included in this API that take fullname parameters. |
| 839 | * See "Notes on DNS Name Escaping" earlier in this file for more details.) |
| 840 | * |
| 841 | * hosttarget: The target hostname of the machine providing the service. This name can |
| 842 | * be passed to functions like gethostbyname() to identify the host's IP address. |
| 843 | * |
| 844 | * port: The port, in network byte order, on which connections are accepted for this service. |
| 845 | * |
| 846 | * txtLen: The length of the txt record, in bytes. |
| 847 | * |
| 848 | * txtRecord: The service's primary txt record, in standard txt record format. |
| 849 | * |
| 850 | * context: The context pointer that was passed to the callout. |
| 851 | * |
| 852 | * NOTE: In earlier versions of this header file, the txtRecord parameter was declared "const char *" |
| 853 | * This is incorrect, since it contains length bytes which are values in the range 0 to 255, not -128 to +127. |
| 854 | * Depending on your compiler settings, this change may cause signed/unsigned mismatch warnings. |
| 855 | * These should be fixed by updating your own callback function definition to match the corrected |
| 856 | * function signature using "const unsigned char *txtRecord". Making this change may also fix inadvertent |
| 857 | * bugs in your callback function, where it could have incorrectly interpreted a length byte with value 250 |
| 858 | * as being -6 instead, with various bad consequences ranging from incorrect operation to software crashes. |
| 859 | * If you need to maintain portable code that will compile cleanly with both the old and new versions of |
| 860 | * this header file, you should update your callback function definition to use the correct unsigned value, |
| 861 | * and then in the place where you pass your callback function to DNSServiceResolve(), use a cast to eliminate |
| 862 | * the compiler warning, e.g.: |
| 863 | * DNSServiceResolve(sd, flags, index, name, regtype, domain, (DNSServiceResolveReply)MyCallback, context); |
| 864 | * This will ensure that your code compiles cleanly without warnings (and more importantly, works correctly) |
| 865 | * with both the old header and with the new corrected version. |
| 866 | * |
| 867 | */ |
| 868 | |
| 869 | typedef void (DNSSD_API *DNSServiceResolveReply) |
| 870 | ( |
| 871 | DNSServiceRef sdRef, |
| 872 | DNSServiceFlags flags, |
| 873 | uint32_t interfaceIndex, |
| 874 | DNSServiceErrorType errorCode, |
| 875 | const char *fullname, |
| 876 | const char *hosttarget, |
| 877 | uint16_t port, /* In network byte order */ |
| 878 | uint16_t txtLen, |
| 879 | const unsigned char *txtRecord, |
| 880 | void *context |
| 881 | ); |
| 882 | |
| 883 | |
| 884 | /* DNSServiceQueryRecord |
| 885 | * |
| 886 | * Query for an arbitrary DNS record. |
| 887 | * |
| 888 | * DNSServiceQueryRecordReply() Callback Parameters: |
| 889 | * |
| 890 | * sdRef: The DNSServiceRef initialized by DNSServiceQueryRecord(). |
| 891 | * |
| 892 | * flags: Possible values are kDNSServiceFlagsMoreComing and |
| 893 | * kDNSServiceFlagsAdd. The Add flag is NOT set for PTR records |
| 894 | * with a ttl of 0, i.e. "Remove" events. |
| 895 | * |
| 896 | * interfaceIndex: The interface on which the query was resolved (the index for a given |
| 897 | * interface is determined via the if_nametoindex() family of calls). |
| 898 | * See "Constants for specifying an interface index" for more details. |
| 899 | * |
| 900 | * errorCode: Will be kDNSServiceErr_NoError on success, otherwise will |
| 901 | * indicate the failure that occurred. Other parameters are undefined if |
| 902 | * errorCode is nonzero. |
| 903 | * |
| 904 | * fullname: The resource record's full domain name. |
| 905 | * |
| 906 | * rrtype: The resource record's type (e.g. kDNSServiceType_PTR, kDNSServiceType_SRV, etc) |
| 907 | * |
| 908 | * rrclass: The class of the resource record (usually kDNSServiceClass_IN). |
| 909 | * |
| 910 | * rdlen: The length, in bytes, of the resource record rdata. |
| 911 | * |
| 912 | * rdata: The raw rdata of the resource record. |
| 913 | * |
| 914 | * ttl: If the client wishes to cache the result for performance reasons, |
| 915 | * the TTL indicates how long the client may legitimately hold onto |
| 916 | * this result, in seconds. After the TTL expires, the client should |
| 917 | * consider the result no longer valid, and if it requires this data |
| 918 | * again, it should be re-fetched with a new query. Of course, this |
| 919 | * only applies to clients that cancel the asynchronous operation when |
| 920 | * they get a result. Clients that leave the asynchronous operation |
| 921 | * running can safely assume that the data remains valid until they |
| 922 | * get another callback telling them otherwise. |
| 923 | * |
| 924 | * context: The context pointer that was passed to the callout. |
| 925 | * |
| 926 | */ |
| 927 | |
| 928 | typedef void (DNSSD_API *DNSServiceQueryRecordReply) |
| 929 | ( |
| 930 | DNSServiceRef sdRef, |
| 931 | DNSServiceFlags flags, |
| 932 | uint32_t interfaceIndex, |
| 933 | DNSServiceErrorType errorCode, |
| 934 | const char *fullname, |
| 935 | uint16_t rrtype, |
| 936 | uint16_t rrclass, |
| 937 | uint16_t rdlen, |
| 938 | const void *rdata, |
| 939 | uint32_t ttl, |
| 940 | void *context |
| 941 | ); |
| 942 | |
| 943 | /* DNSServiceGetAddrInfo |
| 944 | * |
| 945 | * Queries for the IP address of a hostname by using either Multicast or Unicast DNS. |
| 946 | * |
| 947 | * DNSServiceGetAddrInfoReply() parameters: |
| 948 | * |
| 949 | * sdRef: The DNSServiceRef initialized by DNSServiceGetAddrInfo(). |
| 950 | * |
| 951 | * flags: Possible values are kDNSServiceFlagsMoreComing and |
| 952 | * kDNSServiceFlagsAdd. |
| 953 | * |
| 954 | * interfaceIndex: The interface to which the answers pertain. |
| 955 | * |
| 956 | * errorCode: Will be kDNSServiceErr_NoError on success, otherwise will |
| 957 | * indicate the failure that occurred. Other parameters are |
| 958 | * undefined if errorCode is nonzero. |
| 959 | * |
| 960 | * hostname: The fully qualified domain name of the host to be queried for. |
| 961 | * |
| 962 | * address: IPv4 or IPv6 address. |
| 963 | * |
| 964 | * ttl: If the client wishes to cache the result for performance reasons, |
| 965 | * the TTL indicates how long the client may legitimately hold onto |
| 966 | * this result, in seconds. After the TTL expires, the client should |
| 967 | * consider the result no longer valid, and if it requires this data |
| 968 | * again, it should be re-fetched with a new query. Of course, this |
| 969 | * only applies to clients that cancel the asynchronous operation when |
| 970 | * they get a result. Clients that leave the asynchronous operation |
| 971 | * running can safely assume that the data remains valid until they |
| 972 | * get another callback telling them otherwise. |
| 973 | * |
| 974 | * context: The context pointer that was passed to the callout. |
| 975 | * |
| 976 | */ |
| 977 | |
| 978 | typedef void (DNSSD_API *DNSServiceGetAddrInfoReply) |
| 979 | ( |
| 980 | DNSServiceRef sdRef, |
| 981 | DNSServiceFlags flags, |
| 982 | uint32_t interfaceIndex, |
| 983 | DNSServiceErrorType errorCode, |
| 984 | const char *hostname, |
| 985 | const struct sockaddr *address, |
| 986 | uint32_t ttl, |
| 987 | void *context |
| 988 | ); |
| 989 | |
| 990 | |
| 991 | |
| 992 | /* DNSServiceRegisterRecord |
| 993 | * |
| 994 | * Register an individual resource record on a connected DNSServiceRef. |
| 995 | * |
| 996 | * Note that name conflicts occurring for records registered via this call must be handled |
| 997 | * by the client in the callback. |
| 998 | * |
| 999 | * DNSServiceRegisterRecordReply() parameters: |
| 1000 | * |
| 1001 | * sdRef: The connected DNSServiceRef initialized by |
| 1002 | * DNSServiceCreateConnection(). |
| 1003 | * |
| 1004 | * RecordRef: The DNSRecordRef initialized by DNSServiceRegisterRecord(). If the above |
| 1005 | * DNSServiceRef is passed to DNSServiceRefDeallocate(), this DNSRecordRef is |
| 1006 | * invalidated, and may not be used further. |
| 1007 | * |
| 1008 | * flags: Currently unused, reserved for future use. |
| 1009 | * |
| 1010 | * errorCode: Will be kDNSServiceErr_NoError on success, otherwise will |
| 1011 | * indicate the failure that occurred (including name conflicts.) |
| 1012 | * Other parameters are undefined if errorCode is nonzero. |
| 1013 | * |
| 1014 | * context: The context pointer that was passed to the callout. |
| 1015 | * |
| 1016 | */ |
| 1017 | |
| 1018 | typedef void (DNSSD_API *DNSServiceRegisterRecordReply) |
| 1019 | ( |
| 1020 | DNSServiceRef sdRef, |
| 1021 | DNSRecordRef RecordRef, |
| 1022 | DNSServiceFlags flags, |
| 1023 | DNSServiceErrorType errorCode, |
| 1024 | void *context |
| 1025 | ); |
| 1026 | |
| 1027 | |
| 1028 | /* DNSServiceNATPortMappingCreate |
| 1029 | * |
| 1030 | * Request a port mapping in the NAT gateway, which maps a port on the local machine |
| 1031 | * to an external port on the NAT. The NAT should support either the NAT-PMP or the UPnP IGD |
| 1032 | * protocol for this API to create a successful mapping. |
| 1033 | * |
| 1034 | * The port mapping will be renewed indefinitely until the client process exits, or |
| 1035 | * explicitly terminates the port mapping request by calling DNSServiceRefDeallocate(). |
| 1036 | * The client callback will be invoked, informing the client of the NAT gateway's |
| 1037 | * external IP address and the external port that has been allocated for this client. |
| 1038 | * The client should then record this external IP address and port using whatever |
| 1039 | * directory service mechanism it is using to enable peers to connect to it. |
| 1040 | * (Clients advertising services using Wide-Area DNS-SD DO NOT need to use this API |
| 1041 | * -- when a client calls DNSServiceRegister() NAT mappings are automatically created |
| 1042 | * and the external IP address and port for the service are recorded in the global DNS. |
| 1043 | * Only clients using some directory mechanism other than Wide-Area DNS-SD need to use |
| 1044 | * this API to explicitly map their own ports.) |
| 1045 | * |
| 1046 | * It's possible that the client callback could be called multiple times, for example |
| 1047 | * if the NAT gateway's IP address changes, or if a configuration change results in a |
| 1048 | * different external port being mapped for this client. Over the lifetime of any long-lived |
| 1049 | * port mapping, the client should be prepared to handle these notifications of changes |
| 1050 | * in the environment, and should update its recorded address and/or port as appropriate. |
| 1051 | * |
| 1052 | * NOTE: There are two unusual aspects of how the DNSServiceNATPortMappingCreate API works, |
| 1053 | * which were intentionally designed to help simplify client code: |
| 1054 | * |
| 1055 | * 1. It's not an error to request a NAT mapping when the machine is not behind a NAT gateway. |
| 1056 | * In other NAT mapping APIs, if you request a NAT mapping and the machine is not behind a NAT |
| 1057 | * gateway, then the API returns an error code -- it can't get you a NAT mapping if there's no |
| 1058 | * NAT gateway. The DNSServiceNATPortMappingCreate API takes a different view. Working out |
| 1059 | * whether or not you need a NAT mapping can be tricky and non-obvious, particularly on |
| 1060 | * a machine with multiple active network interfaces. Rather than make every client recreate |
| 1061 | * this logic for deciding whether a NAT mapping is required, the PortMapping API does that |
| 1062 | * work for you. If the client calls the PortMapping API when the machine already has a |
| 1063 | * routable public IP address, then instead of complaining about it and giving an error, |
| 1064 | * the PortMapping API just invokes your callback, giving the machine's public address |
| 1065 | * and your own port number. This means you don't need to write code to work out whether |
| 1066 | * your client needs to call the PortMapping API -- just call it anyway, and if it wasn't |
| 1067 | * necessary, no harm is done: |
| 1068 | * |
| 1069 | * - If the machine already has a routable public IP address, then your callback |
| 1070 | * will just be invoked giving your own address and port. |
| 1071 | * - If a NAT mapping is required and obtained, then your callback will be invoked |
| 1072 | * giving you the external address and port. |
| 1073 | * - If a NAT mapping is required but not obtained from the local NAT gateway, |
| 1074 | * or the machine has no network connectivity, then your callback will be |
| 1075 | * invoked giving zero address and port. |
| 1076 | * |
| 1077 | * 2. In other NAT mapping APIs, if a laptop computer is put to sleep and woken up on a new |
| 1078 | * network, it's the client's job to notice this, and work out whether a NAT mapping |
| 1079 | * is required on the new network, and make a new NAT mapping request if necessary. |
| 1080 | * The DNSServiceNATPortMappingCreate API does this for you, automatically. |
| 1081 | * The client just needs to make one call to the PortMapping API, and its callback will |
| 1082 | * be invoked any time the mapping state changes. This property complements point (1) above. |
| 1083 | * If the client didn't make a NAT mapping request just because it determined that one was |
| 1084 | * not required at that particular moment in time, the client would then have to monitor |
| 1085 | * for network state changes to determine if a NAT port mapping later became necessary. |
| 1086 | * By unconditionally making a NAT mapping request, even when a NAT mapping not to be |
| 1087 | * necessary, the PortMapping API will then begin monitoring network state changes on behalf of |
| 1088 | * the client, and if a NAT mapping later becomes necessary, it will automatically create a NAT |
| 1089 | * mapping and inform the client with a new callback giving the new address and port information. |
| 1090 | * |
| 1091 | * DNSServiceNATPortMappingReply() parameters: |
| 1092 | * |
| 1093 | * sdRef: The DNSServiceRef initialized by DNSServiceNATPortMappingCreate(). |
| 1094 | * |
| 1095 | * flags: Currently unused, reserved for future use. |
| 1096 | * |
| 1097 | * interfaceIndex: The interface through which the NAT gateway is reached. |
| 1098 | * |
| 1099 | * errorCode: Will be kDNSServiceErr_NoError on success. |
| 1100 | * Will be kDNSServiceErr_DoubleNAT when the NAT gateway is itself behind one or |
| 1101 | * more layers of NAT, in which case the other parameters have the defined values. |
| 1102 | * For other failures, will indicate the failure that occurred, and the other |
| 1103 | * parameters are undefined. |
| 1104 | * |
| 1105 | * externalAddress: Four byte IPv4 address in network byte order. |
| 1106 | * |
| 1107 | * protocol: Will be kDNSServiceProtocol_UDP or kDNSServiceProtocol_TCP or both. |
| 1108 | * |
| 1109 | * internalPort: The port on the local machine that was mapped. |
| 1110 | * |
| 1111 | * externalPort: The actual external port in the NAT gateway that was mapped. |
| 1112 | * This is likely to be different than the requested external port. |
| 1113 | * |
| 1114 | * ttl: The lifetime of the NAT port mapping created on the gateway. |
| 1115 | * This controls how quickly stale mappings will be garbage-collected |
| 1116 | * if the client machine crashes, suffers a power failure, is disconnected |
| 1117 | * from the network, or suffers some other unfortunate demise which |
| 1118 | * causes it to vanish without explicitly removing its NAT port mapping. |
| 1119 | * It's possible that the ttl value will differ from the requested ttl value. |
| 1120 | * |
| 1121 | * context: The context pointer that was passed to the callout. |
| 1122 | * |
| 1123 | */ |
| 1124 | |
| 1125 | typedef void (DNSSD_API *DNSServiceNATPortMappingReply) |
| 1126 | ( |
| 1127 | DNSServiceRef sdRef, |
| 1128 | DNSServiceFlags flags, |
| 1129 | uint32_t interfaceIndex, |
| 1130 | DNSServiceErrorType errorCode, |
| 1131 | uint32_t externalAddress, /* four byte IPv4 address in network byte order */ |
| 1132 | DNSServiceProtocol protocol, |
| 1133 | uint16_t internalPort, /* In network byte order */ |
| 1134 | uint16_t externalPort, /* In network byte order and may be different than the requested port */ |
| 1135 | uint32_t ttl, /* may be different than the requested ttl */ |
| 1136 | void *context |
| 1137 | ); |
| 1138 | |
| 1139 | |
| 1140 | |
| 1141 | /* TXTRecordRef |
| 1142 | * |
| 1143 | * Opaque internal data type. |
| 1144 | * Note: Represents a DNS-SD TXT record. |
| 1145 | */ |
| 1146 | |
| 1147 | typedef union _TXTRecordRef_t { char PrivateData[16]; char *ForceNaturalAlignment; } TXTRecordRef; |
| 1148 | |
| 1149 | |
| 1150 | #ifdef __cplusplus |
| 1151 | } |
| 1152 | #endif |
| 1153 | |
| 1154 | #endif |