| 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_H |
| 80 | #define _DNS_SD_H 3200500 |
| 81 | |
| 82 | #include "dns_sd_types.h" |
| 83 | /********************************************************************************************* |
| 84 | * |
| 85 | * Version checking |
| 86 | * |
| 87 | *********************************************************************************************/ |
| 88 | |
| 89 | /* DNSServiceGetProperty() Parameters: |
| 90 | * |
| 91 | * property: The requested property. |
| 92 | * Currently the only property defined is kDNSServiceProperty_DaemonVersion. |
| 93 | * |
| 94 | * result: Place to store result. |
| 95 | * For retrieving DaemonVersion, this should be the address of a uint32_t. |
| 96 | * |
| 97 | * size: Pointer to uint32_t containing size of the result location. |
| 98 | * For retrieving DaemonVersion, this should be sizeof(uint32_t). |
| 99 | * On return the uint32_t is updated to the size of the data returned. |
| 100 | * For DaemonVersion, the returned size is always sizeof(uint32_t), but |
| 101 | * future properties could be defined which return variable-sized results. |
| 102 | * |
| 103 | * return value: Returns kDNSServiceErr_NoError on success, or kDNSServiceErr_ServiceNotRunning |
| 104 | * if the daemon (or "system service" on Windows) is not running. |
| 105 | */ |
| 106 | |
| 107 | DNSServiceErrorType DNSSD_API DNSServiceGetProperty |
| 108 | ( |
| 109 | const char *property, /* Requested property (i.e. kDNSServiceProperty_DaemonVersion) */ |
| 110 | void *result, /* Pointer to place to store result */ |
| 111 | uint32_t *size /* size of result location */ |
| 112 | ); |
| 113 | |
| 114 | |
| 115 | /********************************************************************************************* |
| 116 | * |
| 117 | * Unix Domain Socket access, DNSServiceRef deallocation, and data processing functions |
| 118 | * |
| 119 | *********************************************************************************************/ |
| 120 | |
| 121 | /* DNSServiceRefSockFD() |
| 122 | * |
| 123 | * Access underlying Unix domain socket for an initialized DNSServiceRef. |
| 124 | * The DNS Service Discovery implementation uses this socket to communicate between the client and |
| 125 | * the mDNSResponder daemon. The application MUST NOT directly read from or write to this socket. |
| 126 | * Access to the socket is provided so that it can be used as a kqueue event source, a CFRunLoop |
| 127 | * event source, in a select() loop, etc. When the underlying event management subsystem (kqueue/ |
| 128 | * select/CFRunLoop etc.) indicates to the client that data is available for reading on the |
| 129 | * socket, the client should call DNSServiceProcessResult(), which will extract the daemon's |
| 130 | * reply from the socket, and pass it to the appropriate application callback. By using a run |
| 131 | * loop or select(), results from the daemon can be processed asynchronously. Alternatively, |
| 132 | * a client can choose to fork a thread and have it loop calling "DNSServiceProcessResult(ref);" |
| 133 | * If DNSServiceProcessResult() is called when no data is available for reading on the socket, it |
| 134 | * will block until data does become available, and then process the data and return to the caller. |
| 135 | * When data arrives on the socket, the client is responsible for calling DNSServiceProcessResult(ref) |
| 136 | * in a timely fashion -- if the client allows a large backlog of data to build up the daemon |
| 137 | * may terminate the connection. |
| 138 | * |
| 139 | * sdRef: A DNSServiceRef initialized by any of the DNSService calls. |
| 140 | * |
| 141 | * return value: The DNSServiceRef's underlying socket descriptor, or -1 on |
| 142 | * error. |
| 143 | */ |
| 144 | |
| 145 | int DNSSD_API DNSServiceRefSockFD(DNSServiceRef sdRef); |
| 146 | |
| 147 | |
| 148 | /* DNSServiceProcessResult() |
| 149 | * |
| 150 | * Read a reply from the daemon, calling the appropriate application callback. This call will |
| 151 | * block until the daemon's response is received. Use DNSServiceRefSockFD() in |
| 152 | * conjunction with a run loop or select() to determine the presence of a response from the |
| 153 | * server before calling this function to process the reply without blocking. Call this function |
| 154 | * at any point if it is acceptable to block until the daemon's response arrives. Note that the |
| 155 | * client is responsible for ensuring that DNSServiceProcessResult() is called whenever there is |
| 156 | * a reply from the daemon - the daemon may terminate its connection with a client that does not |
| 157 | * process the daemon's responses. |
| 158 | * |
| 159 | * sdRef: A DNSServiceRef initialized by any of the DNSService calls |
| 160 | * that take a callback parameter. |
| 161 | * |
| 162 | * return value: Returns kDNSServiceErr_NoError on success, otherwise returns |
| 163 | * an error code indicating the specific failure that occurred. |
| 164 | */ |
| 165 | |
| 166 | DNSServiceErrorType DNSSD_API DNSServiceProcessResult(DNSServiceRef sdRef); |
| 167 | |
| 168 | |
| 169 | /* DNSServiceRefDeallocate() |
| 170 | * |
| 171 | * Terminate a connection with the daemon and free memory associated with the DNSServiceRef. |
| 172 | * Any services or records registered with this DNSServiceRef will be deregistered. Any |
| 173 | * Browse, Resolve, or Query operations called with this reference will be terminated. |
| 174 | * |
| 175 | * Note: If the reference's underlying socket is used in a run loop or select() call, it should |
| 176 | * be removed BEFORE DNSServiceRefDeallocate() is called, as this function closes the reference's |
| 177 | * socket. |
| 178 | * |
| 179 | * Note: If the reference was initialized with DNSServiceCreateConnection(), any DNSRecordRefs |
| 180 | * created via this reference will be invalidated by this call - the resource records are |
| 181 | * deregistered, and their DNSRecordRefs may not be used in subsequent functions. Similarly, |
| 182 | * if the reference was initialized with DNSServiceRegister, and an extra resource record was |
| 183 | * added to the service via DNSServiceAddRecord(), the DNSRecordRef created by the Add() call |
| 184 | * is invalidated when this function is called - the DNSRecordRef may not be used in subsequent |
| 185 | * functions. |
| 186 | * |
| 187 | * Note: This call is to be used only with the DNSServiceRef defined by this API. It is |
| 188 | * not compatible with dns_service_discovery_ref objects defined in the legacy Mach-based |
| 189 | * DNSServiceDiscovery.h API. |
| 190 | * |
| 191 | * sdRef: A DNSServiceRef initialized by any of the DNSService calls. |
| 192 | * |
| 193 | */ |
| 194 | |
| 195 | void DNSSD_API DNSServiceRefDeallocate(DNSServiceRef sdRef); |
| 196 | |
| 197 | |
| 198 | /********************************************************************************************* |
| 199 | * |
| 200 | * Domain Enumeration |
| 201 | * |
| 202 | *********************************************************************************************/ |
| 203 | |
| 204 | |
| 205 | /* DNSServiceEnumerateDomains() Parameters: |
| 206 | * |
| 207 | * sdRef: A pointer to an uninitialized DNSServiceRef. If the call succeeds |
| 208 | * then it initializes the DNSServiceRef, returns kDNSServiceErr_NoError, |
| 209 | * and the enumeration operation will run indefinitely until the client |
| 210 | * terminates it by passing this DNSServiceRef to DNSServiceRefDeallocate(). |
| 211 | * |
| 212 | * flags: Possible values are: |
| 213 | * kDNSServiceFlagsBrowseDomains to enumerate domains recommended for browsing. |
| 214 | * kDNSServiceFlagsRegistrationDomains to enumerate domains recommended |
| 215 | * for registration. |
| 216 | * |
| 217 | * interfaceIndex: If non-zero, specifies the interface on which to look for domains. |
| 218 | * (the index for a given interface is determined via the if_nametoindex() |
| 219 | * family of calls.) Most applications will pass 0 to enumerate domains on |
| 220 | * all interfaces. See "Constants for specifying an interface index" for more details. |
| 221 | * |
| 222 | * callBack: The function to be called when a domain is found or the call asynchronously |
| 223 | * fails. |
| 224 | * |
| 225 | * context: An application context pointer which is passed to the callback function |
| 226 | * (may be NULL). |
| 227 | * |
| 228 | * return value: Returns kDNSServiceErr_NoError on success (any subsequent, asynchronous |
| 229 | * errors are delivered to the callback), otherwise returns an error code indicating |
| 230 | * the error that occurred (the callback is not invoked and the DNSServiceRef |
| 231 | * is not initialized). |
| 232 | */ |
| 233 | |
| 234 | DNSServiceErrorType DNSSD_API DNSServiceEnumerateDomains |
| 235 | ( |
| 236 | DNSServiceRef *sdRef, |
| 237 | DNSServiceFlags flags, |
| 238 | uint32_t interfaceIndex, |
| 239 | DNSServiceDomainEnumReply callBack, |
| 240 | void *context /* may be NULL */ |
| 241 | ); |
| 242 | |
| 243 | |
| 244 | /********************************************************************************************* |
| 245 | * |
| 246 | * Service Registration |
| 247 | * |
| 248 | *********************************************************************************************/ |
| 249 | |
| 250 | /* DNSServiceRegister() Parameters: |
| 251 | * |
| 252 | * sdRef: A pointer to an uninitialized DNSServiceRef. If the call succeeds |
| 253 | * then it initializes the DNSServiceRef, returns kDNSServiceErr_NoError, |
| 254 | * and the registration will remain active indefinitely until the client |
| 255 | * terminates it by passing this DNSServiceRef to DNSServiceRefDeallocate(). |
| 256 | * |
| 257 | * interfaceIndex: If non-zero, specifies the interface on which to register the service |
| 258 | * (the index for a given interface is determined via the if_nametoindex() |
| 259 | * family of calls.) Most applications will pass 0 to register on all |
| 260 | * available interfaces. See "Constants for specifying an interface index" for more details. |
| 261 | * |
| 262 | * flags: Indicates the renaming behavior on name conflict (most applications |
| 263 | * will pass 0). See flag definitions above for details. |
| 264 | * |
| 265 | * name: If non-NULL, specifies the service name to be registered. |
| 266 | * Most applications will not specify a name, in which case the computer |
| 267 | * name is used (this name is communicated to the client via the callback). |
| 268 | * If a name is specified, it must be 1-63 bytes of UTF-8 text. |
| 269 | * If the name is longer than 63 bytes it will be automatically truncated |
| 270 | * to a legal length, unless the NoAutoRename flag is set, |
| 271 | * in which case kDNSServiceErr_BadParam will be returned. |
| 272 | * |
| 273 | * regtype: The service type followed by the protocol, separated by a dot |
| 274 | * (e.g. "_ftp._tcp"). The service type must be an underscore, followed |
| 275 | * by 1-15 characters, which may be letters, digits, or hyphens. |
| 276 | * The transport protocol must be "_tcp" or "_udp". New service types |
| 277 | * should be registered at <http://www.dns-sd.org/ServiceTypes.html>. |
| 278 | * |
| 279 | * Additional subtypes of the primary service type (where a service |
| 280 | * type has defined subtypes) follow the primary service type in a |
| 281 | * comma-separated list, with no additional spaces, e.g. |
| 282 | * "_primarytype._tcp,_subtype1,_subtype2,_subtype3" |
| 283 | * Subtypes provide a mechanism for filtered browsing: A client browsing |
| 284 | * for "_primarytype._tcp" will discover all instances of this type; |
| 285 | * a client browsing for "_primarytype._tcp,_subtype2" will discover only |
| 286 | * those instances that were registered with "_subtype2" in their list of |
| 287 | * registered subtypes. |
| 288 | * |
| 289 | * The subtype mechanism can be illustrated with some examples using the |
| 290 | * dns-sd command-line tool: |
| 291 | * |
| 292 | * % dns-sd -R Simple _test._tcp "" 1001 & |
| 293 | * % dns-sd -R Better _test._tcp,HasFeatureA "" 1002 & |
| 294 | * % dns-sd -R Best _test._tcp,HasFeatureA,HasFeatureB "" 1003 & |
| 295 | * |
| 296 | * Now: |
| 297 | * % dns-sd -B _test._tcp # will find all three services |
| 298 | * % dns-sd -B _test._tcp,HasFeatureA # finds "Better" and "Best" |
| 299 | * % dns-sd -B _test._tcp,HasFeatureB # finds only "Best" |
| 300 | * |
| 301 | * Subtype labels may be up to 63 bytes long, and may contain any eight- |
| 302 | * bit byte values, including zero bytes. However, due to the nature of |
| 303 | * using a C-string-based API, conventional DNS escaping must be used for |
| 304 | * dots ('.'), commas (','), backslashes ('\') and zero bytes, as shown below: |
| 305 | * |
| 306 | * % dns-sd -R Test '_test._tcp,s\.one,s\,two,s\\three,s\000four' local 123 |
| 307 | * |
| 308 | * domain: If non-NULL, specifies the domain on which to advertise the service. |
| 309 | * Most applications will not specify a domain, instead automatically |
| 310 | * registering in the default domain(s). |
| 311 | * |
| 312 | * host: If non-NULL, specifies the SRV target host name. Most applications |
| 313 | * will not specify a host, instead automatically using the machine's |
| 314 | * default host name(s). Note that specifying a non-NULL host does NOT |
| 315 | * create an address record for that host - the application is responsible |
| 316 | * for ensuring that the appropriate address record exists, or creating it |
| 317 | * via DNSServiceRegisterRecord(). |
| 318 | * |
| 319 | * port: The port, in network byte order, on which the service accepts connections. |
| 320 | * Pass 0 for a "placeholder" service (i.e. a service that will not be discovered |
| 321 | * by browsing, but will cause a name conflict if another client tries to |
| 322 | * register that same name). Most clients will not use placeholder services. |
| 323 | * |
| 324 | * txtLen: The length of the txtRecord, in bytes. Must be zero if the txtRecord is NULL. |
| 325 | * |
| 326 | * txtRecord: The TXT record rdata. A non-NULL txtRecord MUST be a properly formatted DNS |
| 327 | * TXT record, i.e. <length byte> <data> <length byte> <data> ... |
| 328 | * Passing NULL for the txtRecord is allowed as a synonym for txtLen=1, txtRecord="", |
| 329 | * i.e. it creates a TXT record of length one containing a single empty string. |
| 330 | * RFC 1035 doesn't allow a TXT record to contain *zero* strings, so a single empty |
| 331 | * string is the smallest legal DNS TXT record. |
| 332 | * As with the other parameters, the DNSServiceRegister call copies the txtRecord |
| 333 | * data; e.g. if you allocated the storage for the txtRecord parameter with malloc() |
| 334 | * then you can safely free that memory right after the DNSServiceRegister call returns. |
| 335 | * |
| 336 | * callBack: The function to be called when the registration completes or asynchronously |
| 337 | * fails. The client MAY pass NULL for the callback - The client will NOT be notified |
| 338 | * of the default values picked on its behalf, and the client will NOT be notified of any |
| 339 | * asynchronous errors (e.g. out of memory errors, etc.) that may prevent the registration |
| 340 | * of the service. The client may NOT pass the NoAutoRename flag if the callback is NULL. |
| 341 | * The client may still deregister the service at any time via DNSServiceRefDeallocate(). |
| 342 | * |
| 343 | * context: An application context pointer which is passed to the callback function |
| 344 | * (may be NULL). |
| 345 | * |
| 346 | * return value: Returns kDNSServiceErr_NoError on success (any subsequent, asynchronous |
| 347 | * errors are delivered to the callback), otherwise returns an error code indicating |
| 348 | * the error that occurred (the callback is never invoked and the DNSServiceRef |
| 349 | * is not initialized). |
| 350 | */ |
| 351 | |
| 352 | DNSServiceErrorType DNSSD_API DNSServiceRegister |
| 353 | ( |
| 354 | DNSServiceRef *sdRef, |
| 355 | DNSServiceFlags flags, |
| 356 | uint32_t interfaceIndex, |
| 357 | const char *name, /* may be NULL */ |
| 358 | const char *regtype, |
| 359 | const char *domain, /* may be NULL */ |
| 360 | const char *host, /* may be NULL */ |
| 361 | uint16_t port, /* In network byte order */ |
| 362 | uint16_t txtLen, |
| 363 | const void *txtRecord, /* may be NULL */ |
| 364 | DNSServiceRegisterReply callBack, /* may be NULL */ |
| 365 | void *context /* may be NULL */ |
| 366 | ); |
| 367 | |
| 368 | |
| 369 | /* DNSServiceAddRecord() |
| 370 | * |
| 371 | * Add a record to a registered service. The name of the record will be the same as the |
| 372 | * registered service's name. |
| 373 | * The record can later be updated or deregistered by passing the RecordRef initialized |
| 374 | * by this function to DNSServiceUpdateRecord() or DNSServiceRemoveRecord(). |
| 375 | * |
| 376 | * Note that the DNSServiceAddRecord/UpdateRecord/RemoveRecord are *NOT* thread-safe |
| 377 | * with respect to a single DNSServiceRef. If you plan to have multiple threads |
| 378 | * in your program simultaneously add, update, or remove records from the same |
| 379 | * DNSServiceRef, then it's the caller's responsibility to use a mutext lock |
| 380 | * or take similar appropriate precautions to serialize those calls. |
| 381 | * |
| 382 | * Parameters; |
| 383 | * |
| 384 | * sdRef: A DNSServiceRef initialized by DNSServiceRegister(). |
| 385 | * |
| 386 | * RecordRef: A pointer to an uninitialized DNSRecordRef. Upon succesfull completion of this |
| 387 | * call, this ref may be passed to DNSServiceUpdateRecord() or DNSServiceRemoveRecord(). |
| 388 | * If the above DNSServiceRef is passed to DNSServiceRefDeallocate(), RecordRef is also |
| 389 | * invalidated and may not be used further. |
| 390 | * |
| 391 | * flags: Currently ignored, reserved for future use. |
| 392 | * |
| 393 | * rrtype: The type of the record (e.g. kDNSServiceType_TXT, kDNSServiceType_SRV, etc) |
| 394 | * |
| 395 | * rdlen: The length, in bytes, of the rdata. |
| 396 | * |
| 397 | * rdata: The raw rdata to be contained in the added resource record. |
| 398 | * |
| 399 | * ttl: The time to live of the resource record, in seconds. |
| 400 | * Most clients should pass 0 to indicate that the system should |
| 401 | * select a sensible default value. |
| 402 | * |
| 403 | * return value: Returns kDNSServiceErr_NoError on success, otherwise returns an |
| 404 | * error code indicating the error that occurred (the RecordRef is not initialized). |
| 405 | */ |
| 406 | |
| 407 | DNSServiceErrorType DNSSD_API DNSServiceAddRecord |
| 408 | ( |
| 409 | DNSServiceRef sdRef, |
| 410 | DNSRecordRef *RecordRef, |
| 411 | DNSServiceFlags flags, |
| 412 | uint16_t rrtype, |
| 413 | uint16_t rdlen, |
| 414 | const void *rdata, |
| 415 | uint32_t ttl |
| 416 | ); |
| 417 | |
| 418 | |
| 419 | /* DNSServiceUpdateRecord |
| 420 | * |
| 421 | * Update a registered resource record. The record must either be: |
| 422 | * - The primary txt record of a service registered via DNSServiceRegister() |
| 423 | * - A record added to a registered service via DNSServiceAddRecord() |
| 424 | * - An individual record registered by DNSServiceRegisterRecord() |
| 425 | * |
| 426 | * Parameters: |
| 427 | * |
| 428 | * sdRef: A DNSServiceRef that was initialized by DNSServiceRegister() |
| 429 | * or DNSServiceCreateConnection(). |
| 430 | * |
| 431 | * RecordRef: A DNSRecordRef initialized by DNSServiceAddRecord, or NULL to update the |
| 432 | * service's primary txt record. |
| 433 | * |
| 434 | * flags: Currently ignored, reserved for future use. |
| 435 | * |
| 436 | * rdlen: The length, in bytes, of the new rdata. |
| 437 | * |
| 438 | * rdata: The new rdata to be contained in the updated resource record. |
| 439 | * |
| 440 | * ttl: The time to live of the updated resource record, in seconds. |
| 441 | * Most clients should pass 0 to indicate that the system should |
| 442 | * select a sensible default value. |
| 443 | * |
| 444 | * return value: Returns kDNSServiceErr_NoError on success, otherwise returns an |
| 445 | * error code indicating the error that occurred. |
| 446 | */ |
| 447 | |
| 448 | DNSServiceErrorType DNSSD_API DNSServiceUpdateRecord |
| 449 | ( |
| 450 | DNSServiceRef sdRef, |
| 451 | DNSRecordRef RecordRef, /* may be NULL */ |
| 452 | DNSServiceFlags flags, |
| 453 | uint16_t rdlen, |
| 454 | const void *rdata, |
| 455 | uint32_t ttl |
| 456 | ); |
| 457 | |
| 458 | |
| 459 | /* DNSServiceRemoveRecord |
| 460 | * |
| 461 | * Remove a record previously added to a service record set via DNSServiceAddRecord(), or deregister |
| 462 | * an record registered individually via DNSServiceRegisterRecord(). |
| 463 | * |
| 464 | * Parameters: |
| 465 | * |
| 466 | * sdRef: A DNSServiceRef initialized by DNSServiceRegister() (if the |
| 467 | * record being removed was registered via DNSServiceAddRecord()) or by |
| 468 | * DNSServiceCreateConnection() (if the record being removed was registered via |
| 469 | * DNSServiceRegisterRecord()). |
| 470 | * |
| 471 | * recordRef: A DNSRecordRef initialized by a successful call to DNSServiceAddRecord() |
| 472 | * or DNSServiceRegisterRecord(). |
| 473 | * |
| 474 | * flags: Currently ignored, reserved for future use. |
| 475 | * |
| 476 | * return value: Returns kDNSServiceErr_NoError on success, otherwise returns an |
| 477 | * error code indicating the error that occurred. |
| 478 | */ |
| 479 | |
| 480 | DNSServiceErrorType DNSSD_API DNSServiceRemoveRecord |
| 481 | ( |
| 482 | DNSServiceRef sdRef, |
| 483 | DNSRecordRef RecordRef, |
| 484 | DNSServiceFlags flags |
| 485 | ); |
| 486 | |
| 487 | |
| 488 | /********************************************************************************************* |
| 489 | * |
| 490 | * Service Discovery |
| 491 | * |
| 492 | *********************************************************************************************/ |
| 493 | |
| 494 | /* DNSServiceBrowse() Parameters: |
| 495 | * |
| 496 | * sdRef: A pointer to an uninitialized DNSServiceRef. If the call succeeds |
| 497 | * then it initializes the DNSServiceRef, returns kDNSServiceErr_NoError, |
| 498 | * and the browse operation will run indefinitely until the client |
| 499 | * terminates it by passing this DNSServiceRef to DNSServiceRefDeallocate(). |
| 500 | * |
| 501 | * flags: Currently ignored, reserved for future use. |
| 502 | * |
| 503 | * interfaceIndex: If non-zero, specifies the interface on which to browse for services |
| 504 | * (the index for a given interface is determined via the if_nametoindex() |
| 505 | * family of calls.) Most applications will pass 0 to browse on all available |
| 506 | * interfaces. See "Constants for specifying an interface index" for more details. |
| 507 | * |
| 508 | * regtype: The service type being browsed for followed by the protocol, separated by a |
| 509 | * dot (e.g. "_ftp._tcp"). The transport protocol must be "_tcp" or "_udp". |
| 510 | * A client may optionally specify a single subtype to perform filtered browsing: |
| 511 | * e.g. browsing for "_primarytype._tcp,_subtype" will discover only those |
| 512 | * instances of "_primarytype._tcp" that were registered specifying "_subtype" |
| 513 | * in their list of registered subtypes. |
| 514 | * |
| 515 | * domain: If non-NULL, specifies the domain on which to browse for services. |
| 516 | * Most applications will not specify a domain, instead browsing on the |
| 517 | * default domain(s). |
| 518 | * |
| 519 | * callBack: The function to be called when an instance of the service being browsed for |
| 520 | * is found, or if the call asynchronously fails. |
| 521 | * |
| 522 | * context: An application context pointer which is passed to the callback function |
| 523 | * (may be NULL). |
| 524 | * |
| 525 | * return value: Returns kDNSServiceErr_NoError on success (any subsequent, asynchronous |
| 526 | * errors are delivered to the callback), otherwise returns an error code indicating |
| 527 | * the error that occurred (the callback is not invoked and the DNSServiceRef |
| 528 | * is not initialized). |
| 529 | */ |
| 530 | |
| 531 | DNSServiceErrorType DNSSD_API DNSServiceBrowse |
| 532 | ( |
| 533 | DNSServiceRef *sdRef, |
| 534 | DNSServiceFlags flags, |
| 535 | uint32_t interfaceIndex, |
| 536 | const char *regtype, |
| 537 | const char *domain, /* may be NULL */ |
| 538 | DNSServiceBrowseReply callBack, |
| 539 | void *context /* may be NULL */ |
| 540 | ); |
| 541 | |
| 542 | /* DNSServiceResolve() Parameters |
| 543 | * |
| 544 | * sdRef: A pointer to an uninitialized DNSServiceRef. If the call succeeds |
| 545 | * then it initializes the DNSServiceRef, returns kDNSServiceErr_NoError, |
| 546 | * and the resolve operation will run indefinitely until the client |
| 547 | * terminates it by passing this DNSServiceRef to DNSServiceRefDeallocate(). |
| 548 | * |
| 549 | * flags: Specifying kDNSServiceFlagsForceMulticast will cause query to be |
| 550 | * performed with a link-local mDNS query, even if the name is an |
| 551 | * apparently non-local name (i.e. a name not ending in ".local.") |
| 552 | * |
| 553 | * interfaceIndex: The interface on which to resolve the service. If this resolve call is |
| 554 | * as a result of a currently active DNSServiceBrowse() operation, then the |
| 555 | * interfaceIndex should be the index reported in the DNSServiceBrowseReply |
| 556 | * callback. If this resolve call is using information previously saved |
| 557 | * (e.g. in a preference file) for later use, then use interfaceIndex 0, because |
| 558 | * the desired service may now be reachable via a different physical interface. |
| 559 | * See "Constants for specifying an interface index" for more details. |
| 560 | * |
| 561 | * name: The name of the service instance to be resolved, as reported to the |
| 562 | * DNSServiceBrowseReply() callback. |
| 563 | * |
| 564 | * regtype: The type of the service instance to be resolved, as reported to the |
| 565 | * DNSServiceBrowseReply() callback. |
| 566 | * |
| 567 | * domain: The domain of the service instance to be resolved, as reported to the |
| 568 | * DNSServiceBrowseReply() callback. |
| 569 | * |
| 570 | * callBack: The function to be called when a result is found, or if the call |
| 571 | * asynchronously fails. |
| 572 | * |
| 573 | * context: An application context pointer which is passed to the callback function |
| 574 | * (may be NULL). |
| 575 | * |
| 576 | * return value: Returns kDNSServiceErr_NoError on success (any subsequent, asynchronous |
| 577 | * errors are delivered to the callback), otherwise returns an error code indicating |
| 578 | * the error that occurred (the callback is never invoked and the DNSServiceRef |
| 579 | * is not initialized). |
| 580 | */ |
| 581 | |
| 582 | DNSServiceErrorType DNSSD_API DNSServiceResolve |
| 583 | ( |
| 584 | DNSServiceRef *sdRef, |
| 585 | DNSServiceFlags flags, |
| 586 | uint32_t interfaceIndex, |
| 587 | const char *name, |
| 588 | const char *regtype, |
| 589 | const char *domain, |
| 590 | DNSServiceResolveReply callBack, |
| 591 | void *context /* may be NULL */ |
| 592 | ); |
| 593 | |
| 594 | |
| 595 | /********************************************************************************************* |
| 596 | * |
| 597 | * Querying Individual Specific Records |
| 598 | * |
| 599 | *********************************************************************************************/ |
| 600 | |
| 601 | /* DNSServiceQueryRecord() Parameters: |
| 602 | * |
| 603 | * sdRef: A pointer to an uninitialized DNSServiceRef. If the call succeeds |
| 604 | * then it initializes the DNSServiceRef, returns kDNSServiceErr_NoError, |
| 605 | * and the query operation will run indefinitely until the client |
| 606 | * terminates it by passing this DNSServiceRef to DNSServiceRefDeallocate(). |
| 607 | * |
| 608 | * flags: kDNSServiceFlagsForceMulticast or kDNSServiceFlagsLongLivedQuery. |
| 609 | * Pass kDNSServiceFlagsLongLivedQuery to create a "long-lived" unicast |
| 610 | * query in a non-local domain. Without setting this flag, unicast queries |
| 611 | * will be one-shot - that is, only answers available at the time of the call |
| 612 | * will be returned. By setting this flag, answers (including Add and Remove |
| 613 | * events) that become available after the initial call is made will generate |
| 614 | * callbacks. This flag has no effect on link-local multicast queries. |
| 615 | * |
| 616 | * interfaceIndex: If non-zero, specifies the interface on which to issue the query |
| 617 | * (the index for a given interface is determined via the if_nametoindex() |
| 618 | * family of calls.) Passing 0 causes the name to be queried for on all |
| 619 | * interfaces. See "Constants for specifying an interface index" for more details. |
| 620 | * |
| 621 | * fullname: The full domain name of the resource record to be queried for. |
| 622 | * |
| 623 | * rrtype: The numerical type of the resource record to be queried for |
| 624 | * (e.g. kDNSServiceType_PTR, kDNSServiceType_SRV, etc) |
| 625 | * |
| 626 | * rrclass: The class of the resource record (usually kDNSServiceClass_IN). |
| 627 | * |
| 628 | * callBack: The function to be called when a result is found, or if the call |
| 629 | * asynchronously fails. |
| 630 | * |
| 631 | * context: An application context pointer which is passed to the callback function |
| 632 | * (may be NULL). |
| 633 | * |
| 634 | * return value: Returns kDNSServiceErr_NoError on success (any subsequent, asynchronous |
| 635 | * errors are delivered to the callback), otherwise returns an error code indicating |
| 636 | * the error that occurred (the callback is never invoked and the DNSServiceRef |
| 637 | * is not initialized). |
| 638 | */ |
| 639 | |
| 640 | DNSServiceErrorType DNSSD_API DNSServiceQueryRecord |
| 641 | ( |
| 642 | DNSServiceRef *sdRef, |
| 643 | DNSServiceFlags flags, |
| 644 | uint32_t interfaceIndex, |
| 645 | const char *fullname, |
| 646 | uint16_t rrtype, |
| 647 | uint16_t rrclass, |
| 648 | DNSServiceQueryRecordReply callBack, |
| 649 | void *context /* may be NULL */ |
| 650 | ); |
| 651 | |
| 652 | |
| 653 | /********************************************************************************************* |
| 654 | * |
| 655 | * Unified lookup of both IPv4 and IPv6 addresses for a fully qualified hostname |
| 656 | * |
| 657 | *********************************************************************************************/ |
| 658 | |
| 659 | /* DNSServiceGetAddrInfo() Parameters: |
| 660 | * |
| 661 | * sdRef: A pointer to an uninitialized DNSServiceRef. If the call succeeds then it |
| 662 | * initializes the DNSServiceRef, returns kDNSServiceErr_NoError, and the query |
| 663 | * begins and will last indefinitely until the client terminates the query |
| 664 | * by passing this DNSServiceRef to DNSServiceRefDeallocate(). |
| 665 | * |
| 666 | * flags: kDNSServiceFlagsForceMulticast or kDNSServiceFlagsLongLivedQuery. |
| 667 | * Pass kDNSServiceFlagsLongLivedQuery to create a "long-lived" unicast |
| 668 | * query in a non-local domain. Without setting this flag, unicast queries |
| 669 | * will be one-shot - that is, only answers available at the time of the call |
| 670 | * will be returned. By setting this flag, answers (including Add and Remove |
| 671 | * events) that become available after the initial call is made will generate |
| 672 | * callbacks. This flag has no effect on link-local multicast queries. |
| 673 | * |
| 674 | * interfaceIndex: The interface on which to issue the query. Passing 0 causes the query to be |
| 675 | * sent on all active interfaces via Multicast or the primary interface via Unicast. |
| 676 | * |
| 677 | * protocol: Pass in kDNSServiceProtocol_IPv4 to look up IPv4 addresses, or kDNSServiceProtocol_IPv6 |
| 678 | * to look up IPv6 addresses, or both to look up both kinds. If neither flag is |
| 679 | * set, the system will apply an intelligent heuristic, which is (currently) |
| 680 | * that it will attempt to look up both, except: |
| 681 | * |
| 682 | * * If "hostname" is a wide-area unicast DNS hostname (i.e. not a ".local." name) |
| 683 | * but this host has no routable IPv6 address, then the call will not try to |
| 684 | * look up IPv6 addresses for "hostname", since any addresses it found would be |
| 685 | * unlikely to be of any use anyway. Similarly, if this host has no routable |
| 686 | * IPv4 address, the call will not try to look up IPv4 addresses for "hostname". |
| 687 | * |
| 688 | * hostname: The fully qualified domain name of the host to be queried for. |
| 689 | * |
| 690 | * callBack: The function to be called when the query succeeds or fails asynchronously. |
| 691 | * |
| 692 | * context: An application context pointer which is passed to the callback function |
| 693 | * (may be NULL). |
| 694 | * |
| 695 | * return value: Returns kDNSServiceErr_NoError on success (any subsequent, asynchronous |
| 696 | * errors are delivered to the callback), otherwise returns an error code indicating |
| 697 | * the error that occurred. |
| 698 | */ |
| 699 | |
| 700 | DNSServiceErrorType DNSSD_API DNSServiceGetAddrInfo |
| 701 | ( |
| 702 | DNSServiceRef *sdRef, |
| 703 | DNSServiceFlags flags, |
| 704 | uint32_t interfaceIndex, |
| 705 | DNSServiceProtocol protocol, |
| 706 | const char *hostname, |
| 707 | DNSServiceGetAddrInfoReply callBack, |
| 708 | void *context /* may be NULL */ |
| 709 | ); |
| 710 | |
| 711 | |
| 712 | /********************************************************************************************* |
| 713 | * |
| 714 | * Special Purpose Calls: |
| 715 | * DNSServiceCreateConnection(), DNSServiceRegisterRecord(), DNSServiceReconfirmRecord() |
| 716 | * (most applications will not use these) |
| 717 | * |
| 718 | *********************************************************************************************/ |
| 719 | |
| 720 | /* DNSServiceCreateConnection() |
| 721 | * |
| 722 | * Create a connection to the daemon allowing efficient registration of |
| 723 | * multiple individual records. |
| 724 | * |
| 725 | * Parameters: |
| 726 | * |
| 727 | * sdRef: A pointer to an uninitialized DNSServiceRef. Deallocating |
| 728 | * the reference (via DNSServiceRefDeallocate()) severs the |
| 729 | * connection and deregisters all records registered on this connection. |
| 730 | * |
| 731 | * return value: Returns kDNSServiceErr_NoError on success, otherwise returns |
| 732 | * an error code indicating the specific failure that occurred (in which |
| 733 | * case the DNSServiceRef is not initialized). |
| 734 | */ |
| 735 | |
| 736 | DNSServiceErrorType DNSSD_API DNSServiceCreateConnection(DNSServiceRef *sdRef); |
| 737 | |
| 738 | /* DNSServiceRegisterRecord() Parameters: |
| 739 | * |
| 740 | * sdRef: A DNSServiceRef initialized by DNSServiceCreateConnection(). |
| 741 | * |
| 742 | * RecordRef: A pointer to an uninitialized DNSRecordRef. Upon succesfull completion of this |
| 743 | * call, this ref may be passed to DNSServiceUpdateRecord() or DNSServiceRemoveRecord(). |
| 744 | * (To deregister ALL records registered on a single connected DNSServiceRef |
| 745 | * and deallocate each of their corresponding DNSServiceRecordRefs, call |
| 746 | * DNSServiceRefDeallocate()). |
| 747 | * |
| 748 | * flags: Possible values are kDNSServiceFlagsShared or kDNSServiceFlagsUnique |
| 749 | * (see flag type definitions for details). |
| 750 | * |
| 751 | * interfaceIndex: If non-zero, specifies the interface on which to register the record |
| 752 | * (the index for a given interface is determined via the if_nametoindex() |
| 753 | * family of calls.) Passing 0 causes the record to be registered on all interfaces. |
| 754 | * See "Constants for specifying an interface index" for more details. |
| 755 | * |
| 756 | * fullname: The full domain name of the resource record. |
| 757 | * |
| 758 | * rrtype: The numerical type of the resource record (e.g. kDNSServiceType_PTR, kDNSServiceType_SRV, etc) |
| 759 | * |
| 760 | * rrclass: The class of the resource record (usually kDNSServiceClass_IN) |
| 761 | * |
| 762 | * rdlen: Length, in bytes, of the rdata. |
| 763 | * |
| 764 | * rdata: A pointer to the raw rdata, as it is to appear in the DNS record. |
| 765 | * |
| 766 | * ttl: The time to live of the resource record, in seconds. |
| 767 | * Most clients should pass 0 to indicate that the system should |
| 768 | * select a sensible default value. |
| 769 | * |
| 770 | * callBack: The function to be called when a result is found, or if the call |
| 771 | * asynchronously fails (e.g. because of a name conflict.) |
| 772 | * |
| 773 | * context: An application context pointer which is passed to the callback function |
| 774 | * (may be NULL). |
| 775 | * |
| 776 | * return value: Returns kDNSServiceErr_NoError on success (any subsequent, asynchronous |
| 777 | * errors are delivered to the callback), otherwise returns an error code indicating |
| 778 | * the error that occurred (the callback is never invoked and the DNSRecordRef is |
| 779 | * not initialized). |
| 780 | */ |
| 781 | |
| 782 | DNSServiceErrorType DNSSD_API DNSServiceRegisterRecord |
| 783 | ( |
| 784 | DNSServiceRef sdRef, |
| 785 | DNSRecordRef *RecordRef, |
| 786 | DNSServiceFlags flags, |
| 787 | uint32_t interfaceIndex, |
| 788 | const char *fullname, |
| 789 | uint16_t rrtype, |
| 790 | uint16_t rrclass, |
| 791 | uint16_t rdlen, |
| 792 | const void *rdata, |
| 793 | uint32_t ttl, |
| 794 | DNSServiceRegisterRecordReply callBack, |
| 795 | void *context /* may be NULL */ |
| 796 | ); |
| 797 | |
| 798 | |
| 799 | /* DNSServiceReconfirmRecord |
| 800 | * |
| 801 | * Instruct the daemon to verify the validity of a resource record that appears |
| 802 | * to be out of date (e.g. because TCP connection to a service's target failed.) |
| 803 | * Causes the record to be flushed from the daemon's cache (as well as all other |
| 804 | * daemons' caches on the network) if the record is determined to be invalid. |
| 805 | * Use this routine conservatively. Reconfirming a record necessarily consumes |
| 806 | * network bandwidth, so this should not be done indiscriminately. |
| 807 | * |
| 808 | * Parameters: |
| 809 | * |
| 810 | * flags: Pass kDNSServiceFlagsForce to force immediate deletion of record, |
| 811 | * instead of after some number of reconfirmation queries have gone unanswered. |
| 812 | * |
| 813 | * interfaceIndex: Specifies the interface of the record in question. |
| 814 | * The caller must specify the interface. |
| 815 | * This API (by design) causes increased network traffic, so it requires |
| 816 | * the caller to be precise about which record should be reconfirmed. |
| 817 | * It is not possible to pass zero for the interface index to perform |
| 818 | * a "wildcard" reconfirmation, where *all* matching records are reconfirmed. |
| 819 | * |
| 820 | * fullname: The resource record's full domain name. |
| 821 | * |
| 822 | * rrtype: The resource record's type (e.g. kDNSServiceType_PTR, kDNSServiceType_SRV, etc) |
| 823 | * |
| 824 | * rrclass: The class of the resource record (usually kDNSServiceClass_IN). |
| 825 | * |
| 826 | * rdlen: The length, in bytes, of the resource record rdata. |
| 827 | * |
| 828 | * rdata: The raw rdata of the resource record. |
| 829 | * |
| 830 | */ |
| 831 | |
| 832 | DNSServiceErrorType DNSSD_API DNSServiceReconfirmRecord |
| 833 | ( |
| 834 | DNSServiceFlags flags, |
| 835 | uint32_t interfaceIndex, |
| 836 | const char *fullname, |
| 837 | uint16_t rrtype, |
| 838 | uint16_t rrclass, |
| 839 | uint16_t rdlen, |
| 840 | const void *rdata |
| 841 | ); |
| 842 | |
| 843 | |
| 844 | /********************************************************************************************* |
| 845 | * |
| 846 | * NAT Port Mapping |
| 847 | * |
| 848 | *********************************************************************************************/ |
| 849 | |
| 850 | /* DNSServiceNATPortMappingCreate() Parameters: |
| 851 | * |
| 852 | * sdRef: A pointer to an uninitialized DNSServiceRef. If the call succeeds then it |
| 853 | * initializes the DNSServiceRef, returns kDNSServiceErr_NoError, and the nat |
| 854 | * port mapping will last indefinitely until the client terminates the port |
| 855 | * mapping request by passing this DNSServiceRef to DNSServiceRefDeallocate(). |
| 856 | * |
| 857 | * flags: Currently ignored, reserved for future use. |
| 858 | * |
| 859 | * interfaceIndex: The interface on which to create port mappings in a NAT gateway. Passing 0 causes |
| 860 | * the port mapping request to be sent on the primary interface. |
| 861 | * |
| 862 | * protocol: To request a port mapping, pass in kDNSServiceProtocol_UDP, or kDNSServiceProtocol_TCP, |
| 863 | * or (kDNSServiceProtocol_UDP | kDNSServiceProtocol_TCP) to map both. |
| 864 | * The local listening port number must also be specified in the internalPort parameter. |
| 865 | * To just discover the NAT gateway's external IP address, pass zero for protocol, |
| 866 | * internalPort, externalPort and ttl. |
| 867 | * |
| 868 | * internalPort: The port number in network byte order on the local machine which is listening for packets. |
| 869 | * |
| 870 | * externalPort: The requested external port in network byte order in the NAT gateway that you would |
| 871 | * like to map to the internal port. Pass 0 if you don't care which external port is chosen for you. |
| 872 | * |
| 873 | * ttl: The requested renewal period of the NAT port mapping, in seconds. |
| 874 | * If the client machine crashes, suffers a power failure, is disconnected from |
| 875 | * the network, or suffers some other unfortunate demise which causes it to vanish |
| 876 | * unexpectedly without explicitly removing its NAT port mappings, then the NAT gateway |
| 877 | * will garbage-collect old stale NAT port mappings when their lifetime expires. |
| 878 | * Requesting a short TTL causes such orphaned mappings to be garbage-collected |
| 879 | * more promptly, but consumes system resources and network bandwidth with |
| 880 | * frequent renewal packets to keep the mapping from expiring. |
| 881 | * Requesting a long TTL is more efficient on the network, but in the event of the |
| 882 | * client vanishing, stale NAT port mappings will not be garbage-collected as quickly. |
| 883 | * Most clients should pass 0 to use a system-wide default value. |
| 884 | * |
| 885 | * callBack: The function to be called when the port mapping request succeeds or fails asynchronously. |
| 886 | * |
| 887 | * context: An application context pointer which is passed to the callback function |
| 888 | * (may be NULL). |
| 889 | * |
| 890 | * return value: Returns kDNSServiceErr_NoError on success (any subsequent, asynchronous |
| 891 | * errors are delivered to the callback), otherwise returns an error code indicating |
| 892 | * the error that occurred. |
| 893 | * |
| 894 | * If you don't actually want a port mapped, and are just calling the API |
| 895 | * because you want to find out the NAT's external IP address (e.g. for UI |
| 896 | * display) then pass zero for protocol, internalPort, externalPort and ttl. |
| 897 | */ |
| 898 | |
| 899 | DNSServiceErrorType DNSSD_API DNSServiceNATPortMappingCreate |
| 900 | ( |
| 901 | DNSServiceRef *sdRef, |
| 902 | DNSServiceFlags flags, |
| 903 | uint32_t interfaceIndex, |
| 904 | DNSServiceProtocol protocol, /* TCP and/or UDP */ |
| 905 | uint16_t internalPort, /* network byte order */ |
| 906 | uint16_t externalPort, /* network byte order */ |
| 907 | uint32_t ttl, /* time to live in seconds */ |
| 908 | DNSServiceNATPortMappingReply callBack, |
| 909 | void *context /* may be NULL */ |
| 910 | ); |
| 911 | |
| 912 | |
| 913 | /********************************************************************************************* |
| 914 | * |
| 915 | * General Utility Functions |
| 916 | * |
| 917 | *********************************************************************************************/ |
| 918 | |
| 919 | /* DNSServiceConstructFullName() |
| 920 | * |
| 921 | * Concatenate a three-part domain name (as returned by the above callbacks) into a |
| 922 | * properly-escaped full domain name. Note that callbacks in the above functions ALREADY ESCAPE |
| 923 | * strings where necessary. |
| 924 | * |
| 925 | * Parameters: |
| 926 | * |
| 927 | * fullName: A pointer to a buffer that where the resulting full domain name is to be written. |
| 928 | * The buffer must be kDNSServiceMaxDomainName (1009) bytes in length to |
| 929 | * accommodate the longest legal domain name without buffer overrun. |
| 930 | * |
| 931 | * service: The service name - any dots or backslashes must NOT be escaped. |
| 932 | * May be NULL (to construct a PTR record name, e.g. |
| 933 | * "_ftp._tcp.apple.com."). |
| 934 | * |
| 935 | * regtype: The service type followed by the protocol, separated by a dot |
| 936 | * (e.g. "_ftp._tcp"). |
| 937 | * |
| 938 | * domain: The domain name, e.g. "apple.com.". Literal dots or backslashes, |
| 939 | * if any, must be escaped, e.g. "1st\. Floor.apple.com." |
| 940 | * |
| 941 | * return value: Returns kDNSServiceErr_NoError (0) on success, kDNSServiceErr_BadParam on error. |
| 942 | * |
| 943 | */ |
| 944 | |
| 945 | DNSServiceErrorType DNSSD_API DNSServiceConstructFullName |
| 946 | ( |
| 947 | char * const fullName, |
| 948 | const char * const service, /* may be NULL */ |
| 949 | const char * const regtype, |
| 950 | const char * const domain |
| 951 | ); |
| 952 | |
| 953 | |
| 954 | /********************************************************************************************* |
| 955 | * |
| 956 | * TXT Record Construction Functions |
| 957 | * |
| 958 | *********************************************************************************************/ |
| 959 | |
| 960 | /* |
| 961 | * A typical calling sequence for TXT record construction is something like: |
| 962 | * |
| 963 | * Client allocates storage for TXTRecord data (e.g. declare buffer on the stack) |
| 964 | * TXTRecordCreate(); |
| 965 | * TXTRecordSetValue(); |
| 966 | * TXTRecordSetValue(); |
| 967 | * TXTRecordSetValue(); |
| 968 | * ... |
| 969 | * DNSServiceRegister( ... TXTRecordGetLength(), TXTRecordGetBytesPtr() ... ); |
| 970 | * TXTRecordDeallocate(); |
| 971 | * Explicitly deallocate storage for TXTRecord data (if not allocated on the stack) |
| 972 | */ |
| 973 | |
| 974 | |
| 975 | /* TXTRecordCreate() |
| 976 | * |
| 977 | * Creates a new empty TXTRecordRef referencing the specified storage. |
| 978 | * |
| 979 | * If the buffer parameter is NULL, or the specified storage size is not |
| 980 | * large enough to hold a key subsequently added using TXTRecordSetValue(), |
| 981 | * then additional memory will be added as needed using malloc(). |
| 982 | * |
| 983 | * On some platforms, when memory is low, malloc() may fail. In this |
| 984 | * case, TXTRecordSetValue() will return kDNSServiceErr_NoMemory, and this |
| 985 | * error condition will need to be handled as appropriate by the caller. |
| 986 | * |
| 987 | * You can avoid the need to handle this error condition if you ensure |
| 988 | * that the storage you initially provide is large enough to hold all |
| 989 | * the key/value pairs that are to be added to the record. |
| 990 | * The caller can precompute the exact length required for all of the |
| 991 | * key/value pairs to be added, or simply provide a fixed-sized buffer |
| 992 | * known in advance to be large enough. |
| 993 | * A no-value (key-only) key requires (1 + key length) bytes. |
| 994 | * A key with empty value requires (1 + key length + 1) bytes. |
| 995 | * A key with non-empty value requires (1 + key length + 1 + value length). |
| 996 | * For most applications, DNS-SD TXT records are generally |
| 997 | * less than 100 bytes, so in most cases a simple fixed-sized |
| 998 | * 256-byte buffer will be more than sufficient. |
| 999 | * Recommended size limits for DNS-SD TXT Records are discussed in |
| 1000 | * <http://files.dns-sd.org/draft-cheshire-dnsext-dns-sd.txt> |
| 1001 | * |
| 1002 | * Note: When passing parameters to and from these TXT record APIs, |
| 1003 | * the key name does not include the '=' character. The '=' character |
| 1004 | * is the separator between the key and value in the on-the-wire |
| 1005 | * packet format; it is not part of either the key or the value. |
| 1006 | * |
| 1007 | * txtRecord: A pointer to an uninitialized TXTRecordRef. |
| 1008 | * |
| 1009 | * bufferLen: The size of the storage provided in the "buffer" parameter. |
| 1010 | * |
| 1011 | * buffer: Optional caller-supplied storage used to hold the TXTRecord data. |
| 1012 | * This storage must remain valid for as long as |
| 1013 | * the TXTRecordRef. |
| 1014 | */ |
| 1015 | |
| 1016 | void DNSSD_API TXTRecordCreate |
| 1017 | ( |
| 1018 | TXTRecordRef *txtRecord, |
| 1019 | uint16_t bufferLen, |
| 1020 | void *buffer |
| 1021 | ); |
| 1022 | |
| 1023 | |
| 1024 | /* TXTRecordDeallocate() |
| 1025 | * |
| 1026 | * Releases any resources allocated in the course of preparing a TXT Record |
| 1027 | * using TXTRecordCreate()/TXTRecordSetValue()/TXTRecordRemoveValue(). |
| 1028 | * Ownership of the buffer provided in TXTRecordCreate() returns to the client. |
| 1029 | * |
| 1030 | * txtRecord: A TXTRecordRef initialized by calling TXTRecordCreate(). |
| 1031 | * |
| 1032 | */ |
| 1033 | |
| 1034 | void DNSSD_API TXTRecordDeallocate |
| 1035 | ( |
| 1036 | TXTRecordRef *txtRecord |
| 1037 | ); |
| 1038 | |
| 1039 | |
| 1040 | /* TXTRecordSetValue() |
| 1041 | * |
| 1042 | * Adds a key (optionally with value) to a TXTRecordRef. If the "key" already |
| 1043 | * exists in the TXTRecordRef, then the current value will be replaced with |
| 1044 | * the new value. |
| 1045 | * Keys may exist in four states with respect to a given TXT record: |
| 1046 | * - Absent (key does not appear at all) |
| 1047 | * - Present with no value ("key" appears alone) |
| 1048 | * - Present with empty value ("key=" appears in TXT record) |
| 1049 | * - Present with non-empty value ("key=value" appears in TXT record) |
| 1050 | * For more details refer to "Data Syntax for DNS-SD TXT Records" in |
| 1051 | * <http://files.dns-sd.org/draft-cheshire-dnsext-dns-sd.txt> |
| 1052 | * |
| 1053 | * txtRecord: A TXTRecordRef initialized by calling TXTRecordCreate(). |
| 1054 | * |
| 1055 | * key: A null-terminated string which only contains printable ASCII |
| 1056 | * values (0x20-0x7E), excluding '=' (0x3D). Keys should be |
| 1057 | * 9 characters or fewer (not counting the terminating null). |
| 1058 | * |
| 1059 | * valueSize: The size of the value. |
| 1060 | * |
| 1061 | * value: Any binary value. For values that represent |
| 1062 | * textual data, UTF-8 is STRONGLY recommended. |
| 1063 | * For values that represent textual data, valueSize |
| 1064 | * should NOT include the terminating null (if any) |
| 1065 | * at the end of the string. |
| 1066 | * If NULL, then "key" will be added with no value. |
| 1067 | * If non-NULL but valueSize is zero, then "key=" will be |
| 1068 | * added with empty value. |
| 1069 | * |
| 1070 | * return value: Returns kDNSServiceErr_NoError on success. |
| 1071 | * Returns kDNSServiceErr_Invalid if the "key" string contains |
| 1072 | * illegal characters. |
| 1073 | * Returns kDNSServiceErr_NoMemory if adding this key would |
| 1074 | * exceed the available storage. |
| 1075 | */ |
| 1076 | |
| 1077 | DNSServiceErrorType DNSSD_API TXTRecordSetValue |
| 1078 | ( |
| 1079 | TXTRecordRef *txtRecord, |
| 1080 | const char *key, |
| 1081 | uint8_t valueSize, /* may be zero */ |
| 1082 | const void *value /* may be NULL */ |
| 1083 | ); |
| 1084 | |
| 1085 | |
| 1086 | /* TXTRecordRemoveValue() |
| 1087 | * |
| 1088 | * Removes a key from a TXTRecordRef. The "key" must be an |
| 1089 | * ASCII string which exists in the TXTRecordRef. |
| 1090 | * |
| 1091 | * txtRecord: A TXTRecordRef initialized by calling TXTRecordCreate(). |
| 1092 | * |
| 1093 | * key: A key name which exists in the TXTRecordRef. |
| 1094 | * |
| 1095 | * return value: Returns kDNSServiceErr_NoError on success. |
| 1096 | * Returns kDNSServiceErr_NoSuchKey if the "key" does not |
| 1097 | * exist in the TXTRecordRef. |
| 1098 | */ |
| 1099 | |
| 1100 | DNSServiceErrorType DNSSD_API TXTRecordRemoveValue |
| 1101 | ( |
| 1102 | TXTRecordRef *txtRecord, |
| 1103 | const char *key |
| 1104 | ); |
| 1105 | |
| 1106 | |
| 1107 | /* TXTRecordGetLength() |
| 1108 | * |
| 1109 | * Allows you to determine the length of the raw bytes within a TXTRecordRef. |
| 1110 | * |
| 1111 | * txtRecord: A TXTRecordRef initialized by calling TXTRecordCreate(). |
| 1112 | * |
| 1113 | * return value: Returns the size of the raw bytes inside a TXTRecordRef |
| 1114 | * which you can pass directly to DNSServiceRegister() or |
| 1115 | * to DNSServiceUpdateRecord(). |
| 1116 | * Returns 0 if the TXTRecordRef is empty. |
| 1117 | */ |
| 1118 | |
| 1119 | uint16_t DNSSD_API TXTRecordGetLength |
| 1120 | ( |
| 1121 | const TXTRecordRef *txtRecord |
| 1122 | ); |
| 1123 | |
| 1124 | |
| 1125 | /* TXTRecordGetBytesPtr() |
| 1126 | * |
| 1127 | * Allows you to retrieve a pointer to the raw bytes within a TXTRecordRef. |
| 1128 | * |
| 1129 | * txtRecord: A TXTRecordRef initialized by calling TXTRecordCreate(). |
| 1130 | * |
| 1131 | * return value: Returns a pointer to the raw bytes inside the TXTRecordRef |
| 1132 | * which you can pass directly to DNSServiceRegister() or |
| 1133 | * to DNSServiceUpdateRecord(). |
| 1134 | */ |
| 1135 | |
| 1136 | const void * DNSSD_API TXTRecordGetBytesPtr |
| 1137 | ( |
| 1138 | const TXTRecordRef *txtRecord |
| 1139 | ); |
| 1140 | |
| 1141 | |
| 1142 | /********************************************************************************************* |
| 1143 | * |
| 1144 | * TXT Record Parsing Functions |
| 1145 | * |
| 1146 | *********************************************************************************************/ |
| 1147 | |
| 1148 | /* |
| 1149 | * A typical calling sequence for TXT record parsing is something like: |
| 1150 | * |
| 1151 | * Receive TXT record data in DNSServiceResolve() callback |
| 1152 | * if (TXTRecordContainsKey(txtLen, txtRecord, "key")) then do something |
| 1153 | * val1ptr = TXTRecordGetValuePtr(txtLen, txtRecord, "key1", &len1); |
| 1154 | * val2ptr = TXTRecordGetValuePtr(txtLen, txtRecord, "key2", &len2); |
| 1155 | * ... |
| 1156 | * memcpy(myval1, val1ptr, len1); |
| 1157 | * memcpy(myval2, val2ptr, len2); |
| 1158 | * ... |
| 1159 | * return; |
| 1160 | * |
| 1161 | * If you wish to retain the values after return from the DNSServiceResolve() |
| 1162 | * callback, then you need to copy the data to your own storage using memcpy() |
| 1163 | * or similar, as shown in the example above. |
| 1164 | * |
| 1165 | * If for some reason you need to parse a TXT record you built yourself |
| 1166 | * using the TXT record construction functions above, then you can do |
| 1167 | * that using TXTRecordGetLength and TXTRecordGetBytesPtr calls: |
| 1168 | * TXTRecordGetValue(TXTRecordGetLength(x), TXTRecordGetBytesPtr(x), key, &len); |
| 1169 | * |
| 1170 | * Most applications only fetch keys they know about from a TXT record and |
| 1171 | * ignore the rest. |
| 1172 | * However, some debugging tools wish to fetch and display all keys. |
| 1173 | * To do that, use the TXTRecordGetCount() and TXTRecordGetItemAtIndex() calls. |
| 1174 | */ |
| 1175 | |
| 1176 | /* TXTRecordContainsKey() |
| 1177 | * |
| 1178 | * Allows you to determine if a given TXT Record contains a specified key. |
| 1179 | * |
| 1180 | * txtLen: The size of the received TXT Record. |
| 1181 | * |
| 1182 | * txtRecord: Pointer to the received TXT Record bytes. |
| 1183 | * |
| 1184 | * key: A null-terminated ASCII string containing the key name. |
| 1185 | * |
| 1186 | * return value: Returns 1 if the TXT Record contains the specified key. |
| 1187 | * Otherwise, it returns 0. |
| 1188 | */ |
| 1189 | |
| 1190 | int DNSSD_API TXTRecordContainsKey |
| 1191 | ( |
| 1192 | uint16_t txtLen, |
| 1193 | const void *txtRecord, |
| 1194 | const char *key |
| 1195 | ); |
| 1196 | |
| 1197 | |
| 1198 | /* TXTRecordGetValuePtr() |
| 1199 | * |
| 1200 | * Allows you to retrieve the value for a given key from a TXT Record. |
| 1201 | * |
| 1202 | * txtLen: The size of the received TXT Record |
| 1203 | * |
| 1204 | * txtRecord: Pointer to the received TXT Record bytes. |
| 1205 | * |
| 1206 | * key: A null-terminated ASCII string containing the key name. |
| 1207 | * |
| 1208 | * valueLen: On output, will be set to the size of the "value" data. |
| 1209 | * |
| 1210 | * return value: Returns NULL if the key does not exist in this TXT record, |
| 1211 | * or exists with no value (to differentiate between |
| 1212 | * these two cases use TXTRecordContainsKey()). |
| 1213 | * Returns pointer to location within TXT Record bytes |
| 1214 | * if the key exists with empty or non-empty value. |
| 1215 | * For empty value, valueLen will be zero. |
| 1216 | * For non-empty value, valueLen will be length of value data. |
| 1217 | */ |
| 1218 | |
| 1219 | const void * DNSSD_API TXTRecordGetValuePtr |
| 1220 | ( |
| 1221 | uint16_t txtLen, |
| 1222 | const void *txtRecord, |
| 1223 | const char *key, |
| 1224 | uint8_t *valueLen |
| 1225 | ); |
| 1226 | |
| 1227 | |
| 1228 | /* TXTRecordGetCount() |
| 1229 | * |
| 1230 | * Returns the number of keys stored in the TXT Record. The count |
| 1231 | * can be used with TXTRecordGetItemAtIndex() to iterate through the keys. |
| 1232 | * |
| 1233 | * txtLen: The size of the received TXT Record. |
| 1234 | * |
| 1235 | * txtRecord: Pointer to the received TXT Record bytes. |
| 1236 | * |
| 1237 | * return value: Returns the total number of keys in the TXT Record. |
| 1238 | * |
| 1239 | */ |
| 1240 | |
| 1241 | uint16_t DNSSD_API TXTRecordGetCount |
| 1242 | ( |
| 1243 | uint16_t txtLen, |
| 1244 | const void *txtRecord |
| 1245 | ); |
| 1246 | |
| 1247 | |
| 1248 | /* TXTRecordGetItemAtIndex() |
| 1249 | * |
| 1250 | * Allows you to retrieve a key name and value pointer, given an index into |
| 1251 | * a TXT Record. Legal index values range from zero to TXTRecordGetCount()-1. |
| 1252 | * It's also possible to iterate through keys in a TXT record by simply |
| 1253 | * calling TXTRecordGetItemAtIndex() repeatedly, beginning with index zero |
| 1254 | * and increasing until TXTRecordGetItemAtIndex() returns kDNSServiceErr_Invalid. |
| 1255 | * |
| 1256 | * On return: |
| 1257 | * For keys with no value, *value is set to NULL and *valueLen is zero. |
| 1258 | * For keys with empty value, *value is non-NULL and *valueLen is zero. |
| 1259 | * For keys with non-empty value, *value is non-NULL and *valueLen is non-zero. |
| 1260 | * |
| 1261 | * txtLen: The size of the received TXT Record. |
| 1262 | * |
| 1263 | * txtRecord: Pointer to the received TXT Record bytes. |
| 1264 | * |
| 1265 | * itemIndex: An index into the TXT Record. |
| 1266 | * |
| 1267 | * keyBufLen: The size of the string buffer being supplied. |
| 1268 | * |
| 1269 | * key: A string buffer used to store the key name. |
| 1270 | * On return, the buffer contains a null-terminated C string |
| 1271 | * giving the key name. DNS-SD TXT keys are usually |
| 1272 | * 9 characters or fewer. To hold the maximum possible |
| 1273 | * key name, the buffer should be 256 bytes long. |
| 1274 | * |
| 1275 | * valueLen: On output, will be set to the size of the "value" data. |
| 1276 | * |
| 1277 | * value: On output, *value is set to point to location within TXT |
| 1278 | * Record bytes that holds the value data. |
| 1279 | * |
| 1280 | * return value: Returns kDNSServiceErr_NoError on success. |
| 1281 | * Returns kDNSServiceErr_NoMemory if keyBufLen is too short. |
| 1282 | * Returns kDNSServiceErr_Invalid if index is greater than |
| 1283 | * TXTRecordGetCount()-1. |
| 1284 | */ |
| 1285 | |
| 1286 | DNSServiceErrorType DNSSD_API TXTRecordGetItemAtIndex |
| 1287 | ( |
| 1288 | uint16_t txtLen, |
| 1289 | const void *txtRecord, |
| 1290 | uint16_t itemIndex, |
| 1291 | uint16_t keyBufLen, |
| 1292 | char *key, |
| 1293 | uint8_t *valueLen, |
| 1294 | const void **value |
| 1295 | ); |
| 1296 | |
| 1297 | #if _DNS_SD_LIBDISPATCH |
| 1298 | /* |
| 1299 | * DNSServiceSetDispatchQueue |
| 1300 | * |
| 1301 | * Allows you to schedule a DNSServiceRef on a serial dispatch queue for receiving asynchronous |
| 1302 | * callbacks. It's the clients responsibility to ensure that the provided dispatch queue is running. |
| 1303 | * |
| 1304 | * A typical application that uses CFRunLoopRun or dispatch_main on its main thread will |
| 1305 | * usually schedule DNSServiceRefs on its main queue (which is always a serial queue) |
| 1306 | * using "DNSServiceSetDispatchQueue(sdref, dispatch_get_main_queue());" |
| 1307 | * |
| 1308 | * If there is any error during the processing of events, the application callback will |
| 1309 | * be called with an error code. For shared connections, each subordinate DNSServiceRef |
| 1310 | * will get its own error callback. Currently these error callbacks only happen |
| 1311 | * if the mDNSResponder daemon is manually terminated or crashes, and the error |
| 1312 | * code in this case is kDNSServiceErr_ServiceNotRunning. The application must call |
| 1313 | * DNSServiceRefDeallocate to free the DNSServiceRef when it gets such an error code. |
| 1314 | * These error callbacks are rare and should not normally happen on customer machines, |
| 1315 | * but application code should be written defensively to handle such error callbacks |
| 1316 | * gracefully if they occur. |
| 1317 | * |
| 1318 | * After using DNSServiceSetDispatchQueue on a DNSServiceRef, calling DNSServiceProcessResult |
| 1319 | * on the same DNSServiceRef will result in undefined behavior and should be avoided. |
| 1320 | * |
| 1321 | * Once the application successfully schedules a DNSServiceRef on a serial dispatch queue using |
| 1322 | * DNSServiceSetDispatchQueue, it cannot remove the DNSServiceRef from the dispatch queue, or use |
| 1323 | * DNSServiceSetDispatchQueue a second time to schedule the DNSServiceRef onto a different serial dispatch |
| 1324 | * queue. Once scheduled onto a dispatch queue a DNSServiceRef will deliver events to that queue until |
| 1325 | * the application no longer requires that operation and terminates it using DNSServiceRefDeallocate. |
| 1326 | * |
| 1327 | * service: DNSServiceRef that was allocated and returned to the application, when the |
| 1328 | * application calls one of the DNSService API. |
| 1329 | * |
| 1330 | * queue: dispatch queue where the application callback will be scheduled |
| 1331 | * |
| 1332 | * return value: Returns kDNSServiceErr_NoError on success. |
| 1333 | * Returns kDNSServiceErr_NoMemory if it cannot create a dispatch source |
| 1334 | * Returns kDNSServiceErr_BadParam if the service param is invalid or the |
| 1335 | * queue param is invalid |
| 1336 | */ |
| 1337 | |
| 1338 | DNSServiceErrorType DNSSD_API DNSServiceSetDispatchQueue |
| 1339 | ( |
| 1340 | DNSServiceRef service, |
| 1341 | dispatch_queue_t queue |
| 1342 | ); |
| 1343 | #endif //_DNS_SD_LIBDISPATCH |
| 1344 | |
| 1345 | #ifdef __APPLE_API_PRIVATE |
| 1346 | |
| 1347 | #define kDNSServiceCompPrivateDNS "PrivateDNS" |
| 1348 | #define kDNSServiceCompMulticastDNS "MulticastDNS" |
| 1349 | |
| 1350 | #endif //__APPLE_API_PRIVATE |
| 1351 | |
| 1352 | /* Some C compiler cleverness. We can make the compiler check certain things for us, |
| 1353 | * and report errors at compile-time if anything is wrong. The usual way to do this would |
| 1354 | * be to use a run-time "if" statement or the conventional run-time "assert" mechanism, but |
| 1355 | * then you don't find out what's wrong until you run the software. This way, if the assertion |
| 1356 | * condition is false, the array size is negative, and the complier complains immediately. |
| 1357 | */ |
| 1358 | |
| 1359 | struct CompileTimeAssertionChecks_DNS_SD |
| 1360 | { |
| 1361 | char assert0[(sizeof(union _TXTRecordRef_t) == 16) ? 1 : -1]; |
| 1362 | }; |
| 1363 | |
| 1364 | #endif /* _DNS_SD_H */ |