• Home
  • History
  • Annotate
  • Raw
  • Download
  • only in /netgear-R7000-V1.0.7.12_1.2.5/ap/gpl/iserver/avahi-0.6.25/avahi-compat-libdns_sd/

Lines Matching defs:*

0 /* -*- Mode: C; tab-width: 4 -*-
3 * Copyright (c) 2003-2004, Apple Computer, Inc. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
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.
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.
29 #ifndef _DNS_SD_H
30 #define _DNS_SD_H
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
36 /* standard calling convention under Win32 is __stdcall */
37 /* Note: When compiling Intel EFI (Extensible Firmware Interface) under MS Visual Studio, the */
38 /* _WIN32 symbol is defined by the compiler even though it's NOT compiling code for Windows32 */
39 #if defined(_WIN32) && !defined(EFI32) && !defined(EFI64)
40 #define DNSSD_API __stdcall
41 #else
42 #define DNSSD_API
43 #endif
45 /* stdint.h does not exist on FreeBSD 4.x; its types are defined in sys/types.h instead */
46 #if defined(__FreeBSD__) && (__FreeBSD__ < 5)
47 #include <sys/types.h>
49 /* Likewise, on Sun, standard integer types are in sys/types.h */
50 #elif defined(__sun__)
51 #include <sys/types.h>
53 /* EFI does not have stdint.h, or anything else equivalent */
54 #elif defined(EFI32) || defined(EFI64)
55 typedef UINT8 uint8_t;
56 typedef INT8 int8_t;
57 typedef UINT16 uint16_t;
58 typedef INT16 int16_t;
59 typedef UINT32 uint32_t;
60 typedef INT32 int32_t;
62 /* Windows has its own differences */
63 #elif defined(_WIN32)
64 #include <windows.h>
65 #define _UNUSED
66 #define bzero(a, b) memset(a, 0, b)
67 #ifndef _MSL_STDINT_H
68 typedef UINT8 uint8_t;
69 typedef INT8 int8_t;
70 typedef UINT16 uint16_t;
71 typedef INT16 int16_t;
72 typedef UINT32 uint32_t;
73 typedef INT32 int32_t;
74 #endif
76 /* All other Posix platforms use stdint.h */
77 #else
78 #include <stdint.h>
79 #endif
81 /* DNSServiceRef, DNSRecordRef
83 * Opaque internal data types.
84 * Note: client is responsible for serializing access to these structures if
85 * they are shared between concurrent threads.
88 typedef struct _DNSServiceRef_t *DNSServiceRef;
89 typedef struct _DNSRecordRef_t *DNSRecordRef;
91 /* General flags used in functions defined below */
92 enum
94 kDNSServiceFlagsMoreComing = 0x1,
95 /* MoreComing indicates to a callback that at least one more result is
96 * queued and will be delivered following immediately after this one.
97 * Applications should not update their UI to display browse
98 * results when the MoreComing flag is set, because this would
99 * result in a great deal of ugly flickering on the screen.
100 * Applications should instead wait until until MoreComing is not set,
101 * and then update their UI.
102 * When MoreComing is not set, that doesn't mean there will be no more
103 * answers EVER, just that there are no more answers immediately
104 * available right now at this instant. If more answers become available
105 * in the future they will be delivered as usual.
108 kDNSServiceFlagsAdd = 0x2,
109 kDNSServiceFlagsDefault = 0x4,
110 /* Flags for domain enumeration and browse/query reply callbacks.
111 * "Default" applies only to enumeration and is only valid in
112 * conjuction with "Add". An enumeration callback with the "Add"
113 * flag NOT set indicates a "Remove", i.e. the domain is no longer
114 * valid.
117 kDNSServiceFlagsNoAutoRename = 0x8,
118 /* Flag for specifying renaming behavior on name conflict when registering
119 * non-shared records. By default, name conflicts are automatically handled
120 * by renaming the service. NoAutoRename overrides this behavior - with this
121 * flag set, name conflicts will result in a callback. The NoAutorename flag
122 * is only valid if a name is explicitly specified when registering a service
123 * (i.e. the default name is not used.)
126 kDNSServiceFlagsShared = 0x10,
127 kDNSServiceFlagsUnique = 0x20,
128 /* Flag for registering individual records on a connected
129 * DNSServiceRef. Shared indicates that there may be multiple records
130 * with this name on the network (e.g. PTR records). Unique indicates that the
131 * record's name is to be unique on the network (e.g. SRV records).
134 kDNSServiceFlagsBrowseDomains = 0x40,
135 kDNSServiceFlagsRegistrationDomains = 0x80,
136 /* Flags for specifying domain enumeration type in DNSServiceEnumerateDomains.
137 * BrowseDomains enumerates domains recommended for browsing, RegistrationDomains
138 * enumerates domains recommended for registration.
141 kDNSServiceFlagsLongLivedQuery = 0x100,
142 /* Flag for creating a long-lived unicast query for the DNSServiceQueryRecord call. */
144 kDNSServiceFlagsAllowRemoteQuery = 0x200,
145 /* Flag for creating a record for which we will answer remote queries
146 * (queries from hosts more than one hop away; hosts not directly connected to the local link).
149 kDNSServiceFlagsForceMulticast = 0x400,
150 /* Flag for signifying that a query or registration should be performed exclusively via multicast DNS,
151 * even for a name in a domain (e.g. foo.apple.com.) that would normally imply unicast DNS.
154 kDNSServiceFlagsReturnCNAME = 0x800
155 /* Flag for returning CNAME records in the DNSServiceQueryRecord call. CNAME records are
156 * normally followed without indicating to the client that there was a CNAME record.
161 * The values for DNS Classes and Types are listed in RFC 1035, and are available
162 * on every OS in its DNS header file. Unfortunately every OS does not have the
163 * same header file containing DNS Class and Type constants, and the names of
164 * the constants are not consistent. For example, BIND 8 uses "T_A",
165 * BIND 9 uses "ns_t_a", Windows uses "DNS_TYPE_A", etc.
166 * For this reason, these constants are also listed here, so that code using
167 * the DNS-SD programming APIs can use these constants, so that the same code
168 * can compile on all our supported platforms.
171 enum
173 kDNSServiceClass_IN = 1 /* Internet */
176 enum
178 kDNSServiceType_A = 1, /* Host address. */
179 kDNSServiceType_NS = 2, /* Authoritative server. */
180 kDNSServiceType_MD = 3, /* Mail destination. */
181 kDNSServiceType_MF = 4, /* Mail forwarder. */
182 kDNSServiceType_CNAME = 5, /* Canonical name. */
183 kDNSServiceType_SOA = 6, /* Start of authority zone. */
184 kDNSServiceType_MB = 7, /* Mailbox domain name. */
185 kDNSServiceType_MG = 8, /* Mail group member. */
186 kDNSServiceType_MR = 9, /* Mail rename name. */
187 kDNSServiceType_NULL = 10, /* Null resource record. */
188 kDNSServiceType_WKS = 11, /* Well known service. */
189 kDNSServiceType_PTR = 12, /* Domain name pointer. */
190 kDNSServiceType_HINFO = 13, /* Host information. */
191 kDNSServiceType_MINFO = 14, /* Mailbox information. */
192 kDNSServiceType_MX = 15, /* Mail routing information. */
193 kDNSServiceType_TXT = 16, /* One or more text strings. */
194 kDNSServiceType_RP = 17, /* Responsible person. */
195 kDNSServiceType_AFSDB = 18, /* AFS cell database. */
196 kDNSServiceType_X25 = 19, /* X_25 calling address. */
197 kDNSServiceType_ISDN = 20, /* ISDN calling address. */
198 kDNSServiceType_RT = 21, /* Router. */
199 kDNSServiceType_NSAP = 22, /* NSAP address. */
200 kDNSServiceType_NSAP_PTR = 23, /* Reverse NSAP lookup (deprecated). */
201 kDNSServiceType_SIG = 24, /* Security signature. */
202 kDNSServiceType_KEY = 25, /* Security key. */
203 kDNSServiceType_PX = 26, /* X.400 mail mapping. */
204 kDNSServiceType_GPOS = 27, /* Geographical position (withdrawn). */
205 kDNSServiceType_AAAA = 28, /* IPv6 Address. */
206 kDNSServiceType_LOC = 29, /* Location Information. */
207 kDNSServiceType_NXT = 30, /* Next domain (security). */
208 kDNSServiceType_EID = 31, /* Endpoint identifier. */
209 kDNSServiceType_NIMLOC = 32, /* Nimrod Locator. */
210 kDNSServiceType_SRV = 33, /* Server Selection. */
211 kDNSServiceType_ATMA = 34, /* ATM Address */
212 kDNSServiceType_NAPTR = 35, /* Naming Authority PoinTeR */
213 kDNSServiceType_KX = 36, /* Key Exchange */
214 kDNSServiceType_CERT = 37, /* Certification record */
215 kDNSServiceType_A6 = 38, /* IPv6 Address (deprecated) */
216 kDNSServiceType_DNAME = 39, /* Non-terminal DNAME (for IPv6) */
217 kDNSServiceType_SINK = 40, /* Kitchen sink (experimentatl) */
218 kDNSServiceType_OPT = 41, /* EDNS0 option (meta-RR) */
219 kDNSServiceType_TKEY = 249, /* Transaction key */
220 kDNSServiceType_TSIG = 250, /* Transaction signature. */
221 kDNSServiceType_IXFR = 251, /* Incremental zone transfer. */
222 kDNSServiceType_AXFR = 252, /* Transfer zone of authority. */
223 kDNSServiceType_MAILB = 253, /* Transfer mailbox records. */
224 kDNSServiceType_MAILA = 254, /* Transfer mail agent records. */
225 kDNSServiceType_ANY = 255 /* Wildcard match. */
229 /* possible error code values */
230 enum
232 kDNSServiceErr_NoError = 0,
233 kDNSServiceErr_Unknown = -65537, /* 0xFFFE FFFF */
234 kDNSServiceErr_NoSuchName = -65538,
235 kDNSServiceErr_NoMemory = -65539,
236 kDNSServiceErr_BadParam = -65540,
237 kDNSServiceErr_BadReference = -65541,
238 kDNSServiceErr_BadState = -65542,
239 kDNSServiceErr_BadFlags = -65543,
240 kDNSServiceErr_Unsupported = -65544,
241 kDNSServiceErr_NotInitialized = -65545,
242 kDNSServiceErr_AlreadyRegistered = -65547,
243 kDNSServiceErr_NameConflict = -65548,
244 kDNSServiceErr_Invalid = -65549,
245 kDNSServiceErr_Firewall = -65550,
246 kDNSServiceErr_Incompatible = -65551, /* client library incompatible with daemon */
247 kDNSServiceErr_BadInterfaceIndex = -65552,
248 kDNSServiceErr_Refused = -65553,
249 kDNSServiceErr_NoSuchRecord = -65554,
250 kDNSServiceErr_NoAuth = -65555,
251 kDNSServiceErr_NoSuchKey = -65556,
252 kDNSServiceErr_NATTraversal = -65557,
253 kDNSServiceErr_DoubleNAT = -65558,
254 kDNSServiceErr_BadTime = -65559
255 /* mDNS Error codes are in the range
256 * FFFE FF00 (-65792) to FFFE FFFF (-65537) */
260 /* Maximum length, in bytes, of a service name represented as a */
261 /* literal C-String, including the terminating NULL at the end. */
263 #define kDNSServiceMaxServiceName 64
265 /* Maximum length, in bytes, of a domain name represented as an *escaped* C-String */
266 /* including the final trailing dot, and the C-String terminating NULL at the end. */
268 #define kDNSServiceMaxDomainName 1005
271 * Notes on DNS Name Escaping
272 * -- or --
273 * "Why is kDNSServiceMaxDomainName 1005, when the maximum legal domain name is 255 bytes?"
275 * All strings used in DNS-SD are UTF-8 strings.
276 * With few exceptions, most are also escaped using standard DNS escaping rules:
278 * '\\' represents a single literal '\' in the name
279 * '\.' represents a single literal '.' in the name
280 * '\ddd', where ddd is a three-digit decimal value from 000 to 255,
281 * represents a single literal byte with that value.
282 * A bare unescaped '.' is a label separator, marking a boundary between domain and subdomain.
284 * The exceptions, that do not use escaping, are the routines where the full
285 * DNS name of a resource is broken, for convenience, into servicename/regtype/domain.
286 * In these routines, the "servicename" is NOT escaped. It does not need to be, since
287 * it is, by definition, just a single literal string. Any characters in that string
288 * represent exactly what they are. The "regtype" portion is, technically speaking,
289 * escaped, but since legal regtypes are only allowed to contain letters, digits,
290 * and hyphens, there is nothing to escape, so the issue is moot. The "domain"
291 * portion is also escaped, though most domains in use on the public Internet
292 * today, like regtypes, don't contain any characters that need to be escaped.
293 * As DNS-SD becomes more popular, rich-text domains for service discovery will
294 * become common, so software should be written to cope with domains with escaping.
296 * The servicename may be up to 63 bytes of UTF-8 text (not counting the C-String
297 * terminating NULL at the end). The regtype is of the form _service._tcp or
298 * _service._udp, where the "service" part is 1-14 characters, which may be
299 * letters, digits, or hyphens. The domain part of the three-part name may be
300 * any legal domain, providing that the resulting servicename+regtype+domain
301 * name does not exceed 255 bytes.
303 * For most software, these issues are transparent. When browsing, the discovered
304 * servicenames should simply be displayed as-is. When resolving, the discovered
305 * servicename/regtype/domain are simply passed unchanged to DNSServiceResolve().
306 * When a DNSServiceResolve() succeeds, the returned fullname is already in
307 * the correct format to pass to standard system DNS APIs such as res_query().
308 * For converting from servicename/regtype/domain to a single properly-escaped
309 * full DNS name, the helper function DNSServiceConstructFullName() is provided.
311 * The following (highly contrived) example illustrates the escaping process.
312 * Suppose you have an service called "Dr. Smith\Dr. Johnson", of type "_ftp._tcp"
313 * in subdomain "4th. Floor" of subdomain "Building 2" of domain "apple.com."
314 * The full (escaped) DNS name of this service's SRV record would be:
315 * Dr\.\032Smith\\Dr\.\032Johnson._ftp._tcp.4th\.\032Floor.Building\0322.apple.com.
320 * Constants for specifying an interface index
322 * Specific interface indexes are identified via a 32-bit unsigned integer returned
323 * by the if_nametoindex() family of calls.
325 * If the client passes 0 for interface index, that means "do the right thing",
326 * which (at present) means, "if the name is in an mDNS local multicast domain
327 * (e.g. 'local.', '254.169.in-addr.arpa.', '{8,9,A,B}.E.F.ip6.arpa.') then multicast
328 * on all applicable interfaces, otherwise send via unicast to the appropriate
329 * DNS server." Normally, most clients will use 0 for interface index to
330 * automatically get the default sensible behaviour.
332 * If the client passes a positive interface index, then for multicast names that
333 * indicates to do the operation only on that one interface. For unicast names the
334 * interface index is ignored unless kDNSServiceFlagsForceMulticast is also set.
336 * If the client passes kDNSServiceInterfaceIndexLocalOnly when registering
337 * a service, then that service will be found *only* by other local clients
338 * on the same machine that are browsing using kDNSServiceInterfaceIndexLocalOnly
339 * or kDNSServiceInterfaceIndexAny.
340 * If a client has a 'private' service, accessible only to other processes
341 * running on the same machine, this allows the client to advertise that service
342 * in a way such that it does not inadvertently appear in service lists on
343 * all the other machines on the network.
345 * If the client passes kDNSServiceInterfaceIndexLocalOnly when browsing
346 * then it will find *all* records registered on that same local machine.
347 * Clients explicitly wishing to discover *only* LocalOnly services can
348 * accomplish this by inspecting the interfaceIndex of each service reported
349 * to their DNSServiceBrowseReply() callback function, and discarding those
350 * where the interface index is not kDNSServiceInterfaceIndexLocalOnly.
353 #define kDNSServiceInterfaceIndexAny 0
354 #define kDNSServiceInterfaceIndexLocalOnly ( (uint32_t) -1 )
357 typedef uint32_t DNSServiceFlags;
358 typedef int32_t DNSServiceErrorType;
363 * Unix Domain Socket access, DNSServiceRef deallocation, and data processing functions
368 /* DNSServiceRefSockFD()
370 * Access underlying Unix domain socket for an initialized DNSServiceRef.
371 * The DNS Service Discovery implmementation uses this socket to communicate between
372 * the client and the mDNSResponder daemon. The application MUST NOT directly read from
373 * or write to this socket. Access to the socket is provided so that it can be used as a
374 * run loop source, or in a select() loop: when data is available for reading on the socket,
375 * DNSServiceProcessResult() should be called, which will extract the daemon's reply from
376 * the socket, and pass it to the appropriate application callback. By using a run loop or
377 * select(), results from the daemon can be processed asynchronously. Without using these
378 * constructs, DNSServiceProcessResult() will block until the response from the daemon arrives.
379 * The client is responsible for ensuring that the data on the socket is processed in a timely
380 * fashion - the daemon may terminate its connection with a client that does not clear its
381 * socket buffer.
383 * sdRef: A DNSServiceRef initialized by any of the DNSService calls.
385 * return value: The DNSServiceRef's underlying socket descriptor, or -1 on
386 * error.
389 int DNSSD_API DNSServiceRefSockFD(DNSServiceRef sdRef);
392 /* DNSServiceProcessResult()
394 * Read a reply from the daemon, calling the appropriate application callback. This call will
395 * block until the daemon's response is received. Use DNSServiceRefSockFD() in
396 * conjunction with a run loop or select() to determine the presence of a response from the
397 * server before calling this function to process the reply without blocking. Call this function
398 * at any point if it is acceptable to block until the daemon's response arrives. Note that the
399 * client is responsible for ensuring that DNSServiceProcessResult() is called whenever there is
400 * a reply from the daemon - the daemon may terminate its connection with a client that does not
401 * process the daemon's responses.
403 * sdRef: A DNSServiceRef initialized by any of the DNSService calls
404 * that take a callback parameter.
406 * return value: Returns kDNSServiceErr_NoError on success, otherwise returns
407 * an error code indicating the specific failure that occurred.
410 DNSServiceErrorType DNSSD_API DNSServiceProcessResult(DNSServiceRef sdRef);
413 /* DNSServiceRefDeallocate()
415 * Terminate a connection with the daemon and free memory associated with the DNSServiceRef.
416 * Any services or records registered with this DNSServiceRef will be deregistered. Any
417 * Browse, Resolve, or Query operations called with this reference will be terminated.
419 * Note: If the reference's underlying socket is used in a run loop or select() call, it should
420 * be removed BEFORE DNSServiceRefDeallocate() is called, as this function closes the reference's
421 * socket.
423 * Note: If the reference was initialized with DNSServiceCreateConnection(), any DNSRecordRefs
424 * created via this reference will be invalidated by this call - the resource records are
425 * deregistered, and their DNSRecordRefs may not be used in subsequent functions. Similarly,
426 * if the reference was initialized with DNSServiceRegister, and an extra resource record was
427 * added to the service via DNSServiceAddRecord(), the DNSRecordRef created by the Add() call
428 * is invalidated when this function is called - the DNSRecordRef may not be used in subsequent
429 * functions.
431 * Note: This call is to be used only with the DNSServiceRef defined by this API. It is
432 * not compatible with dns_service_discovery_ref objects defined in the legacy Mach-based
433 * DNSServiceDiscovery.h API.
435 * sdRef: A DNSServiceRef initialized by any of the DNSService calls.
439 void DNSSD_API DNSServiceRefDeallocate(DNSServiceRef sdRef);
444 * Domain Enumeration
448 /* DNSServiceEnumerateDomains()
450 * Asynchronously enumerate domains available for browsing and registration.
452 * The enumeration MUST be cancelled via DNSServiceRefDeallocate() when no more domains
453 * are to be found.
455 * Note that the names returned are (like all of DNS-SD) UTF-8 strings,
456 * and are escaped using standard DNS escaping rules.
457 * (See "Notes on DNS Name Escaping" earlier in this file for more details.)
458 * A graphical browser displaying a hierarchical tree-structured view should cut
459 * the names at the bare dots to yield individual labels, then de-escape each
460 * label according to the escaping rules, and then display the resulting UTF-8 text.
462 * DNSServiceDomainEnumReply Callback Parameters:
464 * sdRef: The DNSServiceRef initialized by DNSServiceEnumerateDomains().
466 * flags: Possible values are:
467 * kDNSServiceFlagsMoreComing
468 * kDNSServiceFlagsAdd
469 * kDNSServiceFlagsDefault
471 * interfaceIndex: Specifies the interface on which the domain exists. (The index for a given
472 * interface is determined via the if_nametoindex() family of calls.)
474 * errorCode: Will be kDNSServiceErr_NoError (0) on success, otherwise indicates
475 * the failure that occurred (other parameters are undefined if errorCode is nonzero).
477 * replyDomain: The name of the domain.
479 * context: The context pointer passed to DNSServiceEnumerateDomains.
483 typedef void (DNSSD_API *DNSServiceDomainEnumReply)
485 DNSServiceRef sdRef,
486 DNSServiceFlags flags,
487 uint32_t interfaceIndex,
488 DNSServiceErrorType errorCode,
489 const char *replyDomain,
490 void *context
494 /* DNSServiceEnumerateDomains() Parameters:
497 * sdRef: A pointer to an uninitialized DNSServiceRef. If the call succeeds
498 * then it initializes the DNSServiceRef, returns kDNSServiceErr_NoError,
499 * and the enumeration operation will run indefinitely until the client
500 * terminates it by passing this DNSServiceRef to DNSServiceRefDeallocate().
502 * flags: Possible values are:
503 * kDNSServiceFlagsBrowseDomains to enumerate domains recommended for browsing.
504 * kDNSServiceFlagsRegistrationDomains to enumerate domains recommended
505 * for registration.
507 * interfaceIndex: If non-zero, specifies the interface on which to look for domains.
508 * (the index for a given interface is determined via the if_nametoindex()
509 * family of calls.) Most applications will pass 0 to enumerate domains on
510 * all interfaces. See "Constants for specifying an interface index" for more details.
512 * callBack: The function to be called when a domain is found or the call asynchronously
513 * fails.
515 * context: An application context pointer which is passed to the callback function
516 * (may be NULL).
518 * return value: Returns kDNSServiceErr_NoError on succeses (any subsequent, asynchronous
519 * errors are delivered to the callback), otherwise returns an error code indicating
520 * the error that occurred (the callback is not invoked and the DNSServiceRef
521 * is not initialized.)
524 DNSServiceErrorType DNSSD_API DNSServiceEnumerateDomains
526 DNSServiceRef *sdRef,
527 DNSServiceFlags flags,
528 uint32_t interfaceIndex,
529 DNSServiceDomainEnumReply callBack,
530 void *context /* may be NULL */
536 * Service Registration
540 /* Register a service that is discovered via Browse() and Resolve() calls.
543 * DNSServiceRegisterReply() Callback Parameters:
545 * sdRef: The DNSServiceRef initialized by DNSServiceRegister().
547 * flags: Currently unused, reserved for future use.
549 * errorCode: Will be kDNSServiceErr_NoError on success, otherwise will
550 * indicate the failure that occurred (including name conflicts,
551 * if the kDNSServiceFlagsNoAutoRename flag was used when registering.)
552 * Other parameters are undefined if errorCode is nonzero.
554 * name: The service name registered (if the application did not specify a name in
555 * DNSServiceRegister(), this indicates what name was automatically chosen).
557 * regtype: The type of service registered, as it was passed to the callout.
559 * domain: The domain on which the service was registered (if the application did not
560 * specify a domain in DNSServiceRegister(), this indicates the default domain
561 * on which the service was registered).
563 * context: The context pointer that was passed to the callout.
567 typedef void (DNSSD_API *DNSServiceRegisterReply)
569 DNSServiceRef sdRef,
570 DNSServiceFlags flags,
571 DNSServiceErrorType errorCode,
572 const char *name,
573 const char *regtype,
574 const char *domain,
575 void *context
579 /* DNSServiceRegister() Parameters:
581 * sdRef: A pointer to an uninitialized DNSServiceRef. If the call succeeds
582 * then it initializes the DNSServiceRef, returns kDNSServiceErr_NoError,
583 * and the registration will remain active indefinitely until the client
584 * terminates it by passing this DNSServiceRef to DNSServiceRefDeallocate().
586 * interfaceIndex: If non-zero, specifies the interface on which to register the service
587 * (the index for a given interface is determined via the if_nametoindex()
588 * family of calls.) Most applications will pass 0 to register on all
589 * available interfaces. See "Constants for specifying an interface index" for more details.
591 * flags: Indicates the renaming behavior on name conflict (most applications
592 * will pass 0). See flag definitions above for details.
594 * name: If non-NULL, specifies the service name to be registered.
595 * Most applications will not specify a name, in which case the computer
596 * name is used (this name is communicated to the client via the callback).
597 * If a name is specified, it must be 1-63 bytes of UTF-8 text.
598 * If the name is longer than 63 bytes it will be automatically truncated
599 * to a legal length, unless the NoAutoRename flag is set,
600 * in which case kDNSServiceErr_BadParam will be returned.
602 * regtype: The service type followed by the protocol, separated by a dot
603 * (e.g. "_ftp._tcp"). The service type must be an underscore, followed
604 * by 1-14 characters, which may be letters, digits, or hyphens.
605 * The transport protocol must be "_tcp" or "_udp". New service types
606 * should be registered at <http://www.dns-sd.org/ServiceTypes.html>.
608 * domain: If non-NULL, specifies the domain on which to advertise the service.
609 * Most applications will not specify a domain, instead automatically
610 * registering in the default domain(s).
612 * host: If non-NULL, specifies the SRV target host name. Most applications
613 * will not specify a host, instead automatically using the machine's
614 * default host name(s). Note that specifying a non-NULL host does NOT
615 * create an address record for that host - the application is responsible
616 * for ensuring that the appropriate address record exists, or creating it
617 * via DNSServiceRegisterRecord().
619 * port: The port, in network byte order, on which the service accepts connections.
620 * Pass 0 for a "placeholder" service (i.e. a service that will not be discovered
621 * by browsing, but will cause a name conflict if another client tries to
622 * register that same name). Most clients will not use placeholder services.
624 * txtLen: The length of the txtRecord, in bytes. Must be zero if the txtRecord is NULL.
626 * txtRecord: The TXT record rdata. A non-NULL txtRecord MUST be a properly formatted DNS
627 * TXT record, i.e. <length byte> <data> <length byte> <data> ...
628 * Passing NULL for the txtRecord is allowed as a synonym for txtLen=1, txtRecord="",
629 * i.e. it creates a TXT record of length one containing a single empty string.
630 * RFC 1035 doesn't allow a TXT record to contain *zero* strings, so a single empty
631 * string is the smallest legal DNS TXT record.
632 * As with the other parameters, the DNSServiceRegister call copies the txtRecord
633 * data; e.g. if you allocated the storage for the txtRecord parameter with malloc()
634 * then you can safely free that memory right after the DNSServiceRegister call returns.
636 * callBack: The function to be called when the registration completes or asynchronously
637 * fails. The client MAY pass NULL for the callback - The client will NOT be notified
638 * of the default values picked on its behalf, and the client will NOT be notified of any
639 * asynchronous errors (e.g. out of memory errors, etc.) that may prevent the registration
640 * of the service. The client may NOT pass the NoAutoRename flag if the callback is NULL.
641 * The client may still deregister the service at any time via DNSServiceRefDeallocate().
643 * context: An application context pointer which is passed to the callback function
644 * (may be NULL).
646 * return value: Returns kDNSServiceErr_NoError on succeses (any subsequent, asynchronous
647 * errors are delivered to the callback), otherwise returns an error code indicating
648 * the error that occurred (the callback is never invoked and the DNSServiceRef
649 * is not initialized.)
652 DNSServiceErrorType DNSSD_API DNSServiceRegister
654 DNSServiceRef *sdRef,
655 DNSServiceFlags flags,
656 uint32_t interfaceIndex,
657 const char *name, /* may be NULL */
658 const char *regtype,
659 const char *domain, /* may be NULL */
660 const char *host, /* may be NULL */
661 uint16_t port,
662 uint16_t txtLen,
663 const void *txtRecord, /* may be NULL */
664 DNSServiceRegisterReply callBack, /* may be NULL */
665 void *context /* may be NULL */
669 /* DNSServiceAddRecord()
671 * Add a record to a registered service. The name of the record will be the same as the
672 * registered service's name.
673 * The record can later be updated or deregistered by passing the RecordRef initialized
674 * by this function to DNSServiceUpdateRecord() or DNSServiceRemoveRecord().
676 * Note that the DNSServiceAddRecord/UpdateRecord/RemoveRecord are *NOT* thread-safe
677 * with respect to a single DNSServiceRef. If you plan to have multiple threads
678 * in your program simultaneously add, update, or remove records from the same
679 * DNSServiceRef, then it's the caller's responsibility to use a mutext lock
680 * or take similar appropriate precautions to serialize those calls.
683 * Parameters;
685 * sdRef: A DNSServiceRef initialized by DNSServiceRegister().
687 * RecordRef: A pointer to an uninitialized DNSRecordRef. Upon succesfull completion of this
688 * call, this ref may be passed to DNSServiceUpdateRecord() or DNSServiceRemoveRecord().
689 * If the above DNSServiceRef is passed to DNSServiceRefDeallocate(), RecordRef is also
690 * invalidated and may not be used further.
692 * flags: Currently ignored, reserved for future use.
694 * rrtype: The type of the record (e.g. kDNSServiceType_TXT, kDNSServiceType_SRV, etc)
696 * rdlen: The length, in bytes, of the rdata.
698 * rdata: The raw rdata to be contained in the added resource record.
700 * ttl: The time to live of the resource record, in seconds. Pass 0 to use a default value.
702 * return value: Returns kDNSServiceErr_NoError on success, otherwise returns an
703 * error code indicating the error that occurred (the RecordRef is not initialized).
706 DNSServiceErrorType DNSSD_API DNSServiceAddRecord
708 DNSServiceRef sdRef,
709 DNSRecordRef *RecordRef,
710 DNSServiceFlags flags,
711 uint16_t rrtype,
712 uint16_t rdlen,
713 const void *rdata,
714 uint32_t ttl
718 /* DNSServiceUpdateRecord
720 * Update a registered resource record. The record must either be:
721 * - The primary txt record of a service registered via DNSServiceRegister()
722 * - A record added to a registered service via DNSServiceAddRecord()
723 * - An individual record registered by DNSServiceRegisterRecord()
726 * Parameters:
728 * sdRef: A DNSServiceRef that was initialized by DNSServiceRegister()
729 * or DNSServiceCreateConnection().
731 * RecordRef: A DNSRecordRef initialized by DNSServiceAddRecord, or NULL to update the
732 * service's primary txt record.
734 * flags: Currently ignored, reserved for future use.
736 * rdlen: The length, in bytes, of the new rdata.
738 * rdata: The new rdata to be contained in the updated resource record.
740 * ttl: The time to live of the updated resource record, in seconds.
742 * return value: Returns kDNSServiceErr_NoError on success, otherwise returns an
743 * error code indicating the error that occurred.
746 DNSServiceErrorType DNSSD_API DNSServiceUpdateRecord
748 DNSServiceRef sdRef,
749 DNSRecordRef RecordRef, /* may be NULL */
750 DNSServiceFlags flags,
751 uint16_t rdlen,
752 const void *rdata,
753 uint32_t ttl
757 /* DNSServiceRemoveRecord
759 * Remove a record previously added to a service record set via DNSServiceAddRecord(), or deregister
760 * an record registered individually via DNSServiceRegisterRecord().
762 * Parameters:
764 * sdRef: A DNSServiceRef initialized by DNSServiceRegister() (if the
765 * record being removed was registered via DNSServiceAddRecord()) or by
766 * DNSServiceCreateConnection() (if the record being removed was registered via
767 * DNSServiceRegisterRecord()).
769 * recordRef: A DNSRecordRef initialized by a successful call to DNSServiceAddRecord()
770 * or DNSServiceRegisterRecord().
772 * flags: Currently ignored, reserved for future use.
774 * return value: Returns kDNSServiceErr_NoError on success, otherwise returns an
775 * error code indicating the error that occurred.
778 DNSServiceErrorType DNSSD_API DNSServiceRemoveRecord
780 DNSServiceRef sdRef,
781 DNSRecordRef RecordRef,
782 DNSServiceFlags flags
788 * Service Discovery
792 /* Browse for instances of a service.
795 * DNSServiceBrowseReply() Parameters:
797 * sdRef: The DNSServiceRef initialized by DNSServiceBrowse().
799 * flags: Possible values are kDNSServiceFlagsMoreComing and kDNSServiceFlagsAdd.
800 * See flag definitions for details.
802 * interfaceIndex: The interface on which the service is advertised. This index should
803 * be passed to DNSServiceResolve() when resolving the service.
805 * errorCode: Will be kDNSServiceErr_NoError (0) on success, otherwise will
806 * indicate the failure that occurred. Other parameters are undefined if
807 * the errorCode is nonzero.
809 * serviceName: The discovered service name. This name should be displayed to the user,
810 * and stored for subsequent use in the DNSServiceResolve() call.
812 * regtype: The service type, which is usually (but not always) the same as was passed
813 * to DNSServiceBrowse(). One case where the discovered service type may
814 * not be the same as the requested service type is when using subtypes:
815 * The client may want to browse for only those ftp servers that allow
816 * anonymous connections. The client will pass the string "_ftp._tcp,_anon"
817 * to DNSServiceBrowse(), but the type of the service that's discovered
818 * is simply "_ftp._tcp". The regtype for each discovered service instance
819 * should be stored along with the name, so that it can be passed to
820 * DNSServiceResolve() when the service is later resolved.
822 * domain: The domain of the discovered service instance. This may or may not be the
823 * same as the domain that was passed to DNSServiceBrowse(). The domain for each
824 * discovered service instance should be stored along with the name, so that
825 * it can be passed to DNSServiceResolve() when the service is later resolved.
827 * context: The context pointer that was passed to the callout.
831 typedef void (DNSSD_API *DNSServiceBrowseReply)
833 DNSServiceRef sdRef,
834 DNSServiceFlags flags,
835 uint32_t interfaceIndex,
836 DNSServiceErrorType errorCode,
837 const char *serviceName,
838 const char *regtype,
839 const char *replyDomain,
840 void *context
844 /* DNSServiceBrowse() Parameters:
846 * sdRef: A pointer to an uninitialized DNSServiceRef. If the call succeeds
847 * then it initializes the DNSServiceRef, returns kDNSServiceErr_NoError,
848 * and the browse operation will run indefinitely until the client
849 * terminates it by passing this DNSServiceRef to DNSServiceRefDeallocate().
851 * flags: Currently ignored, reserved for future use.
853 * interfaceIndex: If non-zero, specifies the interface on which to browse for services
854 * (the index for a given interface is determined via the if_nametoindex()
855 * family of calls.) Most applications will pass 0 to browse on all available
856 * interfaces. See "Constants for specifying an interface index" for more details.
858 * regtype: The service type being browsed for followed by the protocol, separated by a
859 * dot (e.g. "_ftp._tcp"). The transport protocol must be "_tcp" or "_udp".
861 * domain: If non-NULL, specifies the domain on which to browse for services.
862 * Most applications will not specify a domain, instead browsing on the
863 * default domain(s).
865 * callBack: The function to be called when an instance of the service being browsed for
866 * is found, or if the call asynchronously fails.
868 * context: An application context pointer which is passed to the callback function
869 * (may be NULL).
871 * return value: Returns kDNSServiceErr_NoError on succeses (any subsequent, asynchronous
872 * errors are delivered to the callback), otherwise returns an error code indicating
873 * the error that occurred (the callback is not invoked and the DNSServiceRef
874 * is not initialized.)
877 DNSServiceErrorType DNSSD_API DNSServiceBrowse
879 DNSServiceRef *sdRef,
880 DNSServiceFlags flags,
881 uint32_t interfaceIndex,
882 const char *regtype,
883 const char *domain, /* may be NULL */
884 DNSServiceBrowseReply callBack,
885 void *context /* may be NULL */
889 /* DNSServiceResolve()
891 * Resolve a service name discovered via DNSServiceBrowse() to a target host name, port number, and
892 * txt record.
894 * Note: Applications should NOT use DNSServiceResolve() solely for txt record monitoring - use
895 * DNSServiceQueryRecord() instead, as it is more efficient for this task.
897 * Note: When the desired results have been returned, the client MUST terminate the resolve by calling
898 * DNSServiceRefDeallocate().
900 * Note: DNSServiceResolve() behaves correctly for typical services that have a single SRV record
901 * and a single TXT record. To resolve non-standard services with multiple SRV or TXT records,
902 * DNSServiceQueryRecord() should be used.
904 * DNSServiceResolveReply Callback Parameters:
906 * sdRef: The DNSServiceRef initialized by DNSServiceResolve().
908 * flags: Currently unused, reserved for future use.
910 * interfaceIndex: The interface on which the service was resolved.
912 * errorCode: Will be kDNSServiceErr_NoError (0) on success, otherwise will
913 * indicate the failure that occurred. Other parameters are undefined if
914 * the errorCode is nonzero.
916 * fullname: The full service domain name, in the form <servicename>.<protocol>.<domain>.
917 * (This name is escaped following standard DNS rules, making it suitable for
918 * passing to standard system DNS APIs such as res_query(), or to the
919 * special-purpose functions included in this API that take fullname parameters.
920 * See "Notes on DNS Name Escaping" earlier in this file for more details.)
922 * hosttarget: The target hostname of the machine providing the service. This name can
923 * be passed to functions like gethostbyname() to identify the host's IP address.
925 * port: The port, in network byte order, on which connections are accepted for this service.
927 * txtLen: The length of the txt record, in bytes.
929 * txtRecord: The service's primary txt record, in standard txt record format.
931 * context: The context pointer that was passed to the callout.
933 * NOTE: In earlier versions of this header file, the txtRecord parameter was declared "const char *"
934 * This is incorrect, since it contains length bytes which are values in the range 0 to 255, not -128 to +127.
935 * Depending on your compiler settings, this change may cause signed/unsigned mismatch warnings.
936 * These should be fixed by updating your own callback function definition to match the corrected
937 * function signature using "const unsigned char *txtRecord". Making this change may also fix inadvertent
938 * bugs in your callback function, where it could have incorrectly interpreted a length byte with value 250
939 * as being -6 instead, with various bad consequences ranging from incorrect operation to software crashes.
940 * If you need to maintain portable code that will compile cleanly with both the old and new versions of
941 * this header file, you should update your callback function definition to use the correct unsigned value,
942 * and then in the place where you pass your callback function to DNSServiceResolve(), use a cast to eliminate
943 * the compiler warning, e.g.:
944 * DNSServiceResolve(sd, flags, index, name, regtype, domain, (DNSServiceResolveReply)MyCallback, context);
945 * This will ensure that your code compiles cleanly without warnings (and more importantly, works correctly)
946 * with both the old header and with the new corrected version.
950 typedef void (DNSSD_API *DNSServiceResolveReply)
952 DNSServiceRef sdRef,
953 DNSServiceFlags flags,
954 uint32_t interfaceIndex,
955 DNSServiceErrorType errorCode,
956 const char *fullname,
957 const char *hosttarget,
958 uint16_t port,
959 uint16_t txtLen,
960 const unsigned char *txtRecord,
961 void *context
965 /* DNSServiceResolve() Parameters
967 * sdRef: A pointer to an uninitialized DNSServiceRef. If the call succeeds
968 * then it initializes the DNSServiceRef, returns kDNSServiceErr_NoError,
969 * and the resolve operation will run indefinitely until the client
970 * terminates it by passing this DNSServiceRef to DNSServiceRefDeallocate().
972 * flags: Currently ignored, reserved for future use.
974 * interfaceIndex: The interface on which to resolve the service. If this resolve call is
975 * as a result of a currently active DNSServiceBrowse() operation, then the
976 * interfaceIndex should be the index reported in the DNSServiceBrowseReply
977 * callback. If this resolve call is using information previously saved
978 * (e.g. in a preference file) for later use, then use interfaceIndex 0, because
979 * the desired service may now be reachable via a different physical interface.
980 * See "Constants for specifying an interface index" for more details.
982 * name: The name of the service instance to be resolved, as reported to the
983 * DNSServiceBrowseReply() callback.
985 * regtype: The type of the service instance to be resolved, as reported to the
986 * DNSServiceBrowseReply() callback.
988 * domain: The domain of the service instance to be resolved, as reported to the
989 * DNSServiceBrowseReply() callback.
991 * callBack: The function to be called when a result is found, or if the call
992 * asynchronously fails.
994 * context: An application context pointer which is passed to the callback function
995 * (may be NULL).
997 * return value: Returns kDNSServiceErr_NoError on succeses (any subsequent, asynchronous
998 * errors are delivered to the callback), otherwise returns an error code indicating
999 * the error that occurred (the callback is never invoked and the DNSServiceRef
1000 * is not initialized.)
1003 DNSServiceErrorType DNSSD_API DNSServiceResolve
1005 DNSServiceRef *sdRef,
1006 DNSServiceFlags flags,
1007 uint32_t interfaceIndex,
1008 const char *name,
1009 const char *regtype,
1010 const char *domain,
1011 DNSServiceResolveReply callBack,
1012 void *context /* may be NULL */
1018 * Special Purpose Calls (most applications will not use these)
1022 /* DNSServiceCreateConnection()
1024 * Create a connection to the daemon allowing efficient registration of
1025 * multiple individual records.
1028 * Parameters:
1030 * sdRef: A pointer to an uninitialized DNSServiceRef. Deallocating
1031 * the reference (via DNSServiceRefDeallocate()) severs the
1032 * connection and deregisters all records registered on this connection.
1034 * return value: Returns kDNSServiceErr_NoError on success, otherwise returns
1035 * an error code indicating the specific failure that occurred (in which
1036 * case the DNSServiceRef is not initialized).
1039 DNSServiceErrorType DNSSD_API DNSServiceCreateConnection(DNSServiceRef *sdRef);
1042 /* DNSServiceRegisterRecord
1044 * Register an individual resource record on a connected DNSServiceRef.
1046 * Note that name conflicts occurring for records registered via this call must be handled
1047 * by the client in the callback.
1050 * DNSServiceRegisterRecordReply() parameters:
1052 * sdRef: The connected DNSServiceRef initialized by
1053 * DNSServiceCreateConnection().
1055 * RecordRef: The DNSRecordRef initialized by DNSServiceRegisterRecord(). If the above
1056 * DNSServiceRef is passed to DNSServiceRefDeallocate(), this DNSRecordRef is
1057 * invalidated, and may not be used further.
1059 * flags: Currently unused, reserved for future use.
1061 * errorCode: Will be kDNSServiceErr_NoError on success, otherwise will
1062 * indicate the failure that occurred (including name conflicts.)
1063 * Other parameters are undefined if errorCode is nonzero.
1065 * context: The context pointer that was passed to the callout.
1069 typedef void (DNSSD_API *DNSServiceRegisterRecordReply)
1071 DNSServiceRef sdRef,
1072 DNSRecordRef RecordRef,
1073 DNSServiceFlags flags,
1074 DNSServiceErrorType errorCode,
1075 void *context
1079 /* DNSServiceRegisterRecord() Parameters:
1081 * sdRef: A DNSServiceRef initialized by DNSServiceCreateConnection().
1083 * RecordRef: A pointer to an uninitialized DNSRecordRef. Upon succesfull completion of this
1084 * call, this ref may be passed to DNSServiceUpdateRecord() or DNSServiceRemoveRecord().
1085 * (To deregister ALL records registered on a single connected DNSServiceRef
1086 * and deallocate each of their corresponding DNSServiceRecordRefs, call
1087 * DNSServiceRefDealloocate()).
1089 * flags: Possible values are kDNSServiceFlagsShared or kDNSServiceFlagsUnique
1090 * (see flag type definitions for details).
1092 * interfaceIndex: If non-zero, specifies the interface on which to register the record
1093 * (the index for a given interface is determined via the if_nametoindex()
1094 * family of calls.) Passing 0 causes the record to be registered on all interfaces.
1095 * See "Constants for specifying an interface index" for more details.
1097 * fullname: The full domain name of the resource record.
1099 * rrtype: The numerical type of the resource record (e.g. kDNSServiceType_PTR, kDNSServiceType_SRV, etc)
1101 * rrclass: The class of the resource record (usually kDNSServiceClass_IN)
1103 * rdlen: Length, in bytes, of the rdata.
1105 * rdata: A pointer to the raw rdata, as it is to appear in the DNS record.
1107 * ttl: The time to live of the resource record, in seconds. Pass 0 to use a default value.
1109 * callBack: The function to be called when a result is found, or if the call
1110 * asynchronously fails (e.g. because of a name conflict.)
1112 * context: An application context pointer which is passed to the callback function
1113 * (may be NULL).
1115 * return value: Returns kDNSServiceErr_NoError on succeses (any subsequent, asynchronous
1116 * errors are delivered to the callback), otherwise returns an error code indicating
1117 * the error that occurred (the callback is never invoked and the DNSRecordRef is
1118 * not initialized.)
1121 DNSServiceErrorType DNSSD_API DNSServiceRegisterRecord
1123 DNSServiceRef sdRef,
1124 DNSRecordRef *RecordRef,
1125 DNSServiceFlags flags,
1126 uint32_t interfaceIndex,
1127 const char *fullname,
1128 uint16_t rrtype,
1129 uint16_t rrclass,
1130 uint16_t rdlen,
1131 const void *rdata,
1132 uint32_t ttl,
1133 DNSServiceRegisterRecordReply callBack,
1134 void *context /* may be NULL */
1138 /* DNSServiceQueryRecord
1140 * Query for an arbitrary DNS record.
1143 * DNSServiceQueryRecordReply() Callback Parameters:
1145 * sdRef: The DNSServiceRef initialized by DNSServiceQueryRecord().
1147 * flags: Possible values are kDNSServiceFlagsMoreComing and
1148 * kDNSServiceFlagsAdd. The Add flag is NOT set for PTR records
1149 * with a ttl of 0, i.e. "Remove" events.
1151 * interfaceIndex: The interface on which the query was resolved (the index for a given
1152 * interface is determined via the if_nametoindex() family of calls).
1153 * See "Constants for specifying an interface index" for more details.
1155 * errorCode: Will be kDNSServiceErr_NoError on success, otherwise will
1156 * indicate the failure that occurred. Other parameters are undefined if
1157 * errorCode is nonzero.
1159 * fullname: The resource record's full domain name.
1161 * rrtype: The resource record's type (e.g. kDNSServiceType_PTR, kDNSServiceType_SRV, etc)
1163 * rrclass: The class of the resource record (usually kDNSServiceClass_IN).
1165 * rdlen: The length, in bytes, of the resource record rdata.
1167 * rdata: The raw rdata of the resource record.
1169 * ttl: The resource record's time to live, in seconds.
1171 * context: The context pointer that was passed to the callout.
1175 typedef void (DNSSD_API *DNSServiceQueryRecordReply)
1177 DNSServiceRef DNSServiceRef,
1178 DNSServiceFlags flags,
1179 uint32_t interfaceIndex,
1180 DNSServiceErrorType errorCode,
1181 const char *fullname,
1182 uint16_t rrtype,
1183 uint16_t rrclass,
1184 uint16_t rdlen,
1185 const void *rdata,
1186 uint32_t ttl,
1187 void *context
1191 /* DNSServiceQueryRecord() Parameters:
1193 * sdRef: A pointer to an uninitialized DNSServiceRef. If the call succeeds
1194 * then it initializes the DNSServiceRef, returns kDNSServiceErr_NoError,
1195 * and the query operation will run indefinitely until the client
1196 * terminates it by passing this DNSServiceRef to DNSServiceRefDeallocate().
1198 * flags: Pass kDNSServiceFlagsLongLivedQuery to create a "long-lived" unicast
1199 * query in a non-local domain. Without setting this flag, unicast queries
1200 * will be one-shot - that is, only answers available at the time of the call
1201 * will be returned. By setting this flag, answers (including Add and Remove
1202 * events) that become available after the initial call is made will generate
1203 * callbacks. This flag has no effect on link-local multicast queries.
1205 * interfaceIndex: If non-zero, specifies the interface on which to issue the query
1206 * (the index for a given interface is determined via the if_nametoindex()
1207 * family of calls.) Passing 0 causes the name to be queried for on all
1208 * interfaces. See "Constants for specifying an interface index" for more details.
1210 * fullname: The full domain name of the resource record to be queried for.
1212 * rrtype: The numerical type of the resource record to be queried for
1213 * (e.g. kDNSServiceType_PTR, kDNSServiceType_SRV, etc)
1215 * rrclass: The class of the resource record (usually kDNSServiceClass_IN).
1217 * callBack: The function to be called when a result is found, or if the call
1218 * asynchronously fails.
1220 * context: An application context pointer which is passed to the callback function
1221 * (may be NULL).
1223 * return value: Returns kDNSServiceErr_NoError on succeses (any subsequent, asynchronous
1224 * errors are delivered to the callback), otherwise returns an error code indicating
1225 * the error that occurred (the callback is never invoked and the DNSServiceRef
1226 * is not initialized.)
1229 DNSServiceErrorType DNSSD_API DNSServiceQueryRecord
1231 DNSServiceRef *sdRef,
1232 DNSServiceFlags flags,
1233 uint32_t interfaceIndex,
1234 const char *fullname,
1235 uint16_t rrtype,
1236 uint16_t rrclass,
1237 DNSServiceQueryRecordReply callBack,
1238 void *context /* may be NULL */
1242 /* DNSServiceReconfirmRecord
1244 * Instruct the daemon to verify the validity of a resource record that appears to
1245 * be out of date (e.g. because tcp connection to a service's target failed.)
1246 * Causes the record to be flushed from the daemon's cache (as well as all other
1247 * daemons' caches on the network) if the record is determined to be invalid.
1249 * Parameters:
1251 * flags: Currently unused, reserved for future use.
1253 * interfaceIndex: If non-zero, specifies the interface of the record in question.
1254 * Passing 0 causes all instances of this record to be reconfirmed.
1256 * fullname: The resource record's full domain name.
1258 * rrtype: The resource record's type (e.g. kDNSServiceType_PTR, kDNSServiceType_SRV, etc)
1260 * rrclass: The class of the resource record (usually kDNSServiceClass_IN).
1262 * rdlen: The length, in bytes, of the resource record rdata.
1264 * rdata: The raw rdata of the resource record.
1268 DNSServiceErrorType DNSSD_API DNSServiceReconfirmRecord
1270 DNSServiceFlags flags,
1271 uint32_t interfaceIndex,
1272 const char *fullname,
1273 uint16_t rrtype,
1274 uint16_t rrclass,
1275 uint16_t rdlen,
1276 const void *rdata
1282 * General Utility Functions
1286 /* DNSServiceConstructFullName()
1288 * Concatenate a three-part domain name (as returned by the above callbacks) into a
1289 * properly-escaped full domain name. Note that callbacks in the above functions ALREADY ESCAPE
1290 * strings where necessary.
1292 * Parameters:
1294 * fullName: A pointer to a buffer that where the resulting full domain name is to be written.
1295 * The buffer must be kDNSServiceMaxDomainName (1005) bytes in length to
1296 * accommodate the longest legal domain name without buffer overrun.
1298 * service: The service name - any dots or backslashes must NOT be escaped.
1299 * May be NULL (to construct a PTR record name, e.g.
1300 * "_ftp._tcp.apple.com.").
1302 * regtype: The service type followed by the protocol, separated by a dot
1303 * (e.g. "_ftp._tcp").
1305 * domain: The domain name, e.g. "apple.com.". Literal dots or backslashes,
1306 * if any, must be escaped, e.g. "1st\. Floor.apple.com."
1308 * return value: Returns 0 on success, -1 on error.
1312 int DNSSD_API DNSServiceConstructFullName
1314 char *fullName,
1315 const char *service, /* may be NULL */
1316 const char *regtype,
1317 const char *domain
1323 * TXT Record Construction Functions
1328 * A typical calling sequence for TXT record construction is something like:
1330 * Client allocates storage for TXTRecord data (e.g. declare buffer on the stack)
1331 * TXTRecordCreate();
1332 * TXTRecordSetValue();
1333 * TXTRecordSetValue();
1334 * TXTRecordSetValue();
1335 * ...
1336 * DNSServiceRegister( ... TXTRecordGetLength(), TXTRecordGetBytesPtr() ... );
1337 * TXTRecordDeallocate();
1338 * Explicitly deallocate storage for TXTRecord data (if not allocated on the stack)
1342 /* TXTRecordRef
1344 * Opaque internal data type.
1345 * Note: Represents a DNS-SD TXT record.
1348 typedef union _TXTRecordRef_t { char PrivateData[16]; char *ForceNaturalAlignment; } TXTRecordRef;
1351 /* TXTRecordCreate()
1353 * Creates a new empty TXTRecordRef referencing the specified storage.
1355 * If the buffer parameter is NULL, or the specified storage size is not
1356 * large enough to hold a key subsequently added using TXTRecordSetValue(),
1357 * then additional memory will be added as needed using malloc().
1359 * On some platforms, when memory is low, malloc() may fail. In this
1360 * case, TXTRecordSetValue() will return kDNSServiceErr_NoMemory, and this
1361 * error condition will need to be handled as appropriate by the caller.
1363 * You can avoid the need to handle this error condition if you ensure
1364 * that the storage you initially provide is large enough to hold all
1365 * the key/value pairs that are to be added to the record.
1366 * The caller can precompute the exact length required for all of the
1367 * key/value pairs to be added, or simply provide a fixed-sized buffer
1368 * known in advance to be large enough.
1369 * A no-value (key-only) key requires (1 + key length) bytes.
1370 * A key with empty value requires (1 + key length + 1) bytes.
1371 * A key with non-empty value requires (1 + key length + 1 + value length).
1372 * For most applications, DNS-SD TXT records are generally
1373 * less than 100 bytes, so in most cases a simple fixed-sized
1374 * 256-byte buffer will be more than sufficient.
1375 * Recommended size limits for DNS-SD TXT Records are discussed in
1376 * <http://files.dns-sd.org/draft-cheshire-dnsext-dns-sd.txt>
1378 * Note: When passing parameters to and from these TXT record APIs,
1379 * the key name does not include the '=' character. The '=' character
1380 * is the separator between the key and value in the on-the-wire
1381 * packet format; it is not part of either the key or the value.
1383 * txtRecord: A pointer to an uninitialized TXTRecordRef.
1385 * bufferLen: The size of the storage provided in the "buffer" parameter.
1387 * buffer: Optional caller-supplied storage used to hold the TXTRecord data.
1388 * This storage must remain valid for as long as
1389 * the TXTRecordRef.
1392 void DNSSD_API TXTRecordCreate
1394 TXTRecordRef *txtRecord,
1395 uint16_t bufferLen,
1396 void *buffer
1400 /* TXTRecordDeallocate()
1402 * Releases any resources allocated in the course of preparing a TXT Record
1403 * using TXTRecordCreate()/TXTRecordSetValue()/TXTRecordRemoveValue().
1404 * Ownership of the buffer provided in TXTRecordCreate() returns to the client.
1406 * txtRecord: A TXTRecordRef initialized by calling TXTRecordCreate().
1410 void DNSSD_API TXTRecordDeallocate
1412 TXTRecordRef *txtRecord
1416 /* TXTRecordSetValue()
1418 * Adds a key (optionally with value) to a TXTRecordRef. If the "key" already
1419 * exists in the TXTRecordRef, then the current value will be replaced with
1420 * the new value.
1421 * Keys may exist in four states with respect to a given TXT record:
1422 * - Absent (key does not appear at all)
1423 * - Present with no value ("key" appears alone)
1424 * - Present with empty value ("key=" appears in TXT record)
1425 * - Present with non-empty value ("key=value" appears in TXT record)
1426 * For more details refer to "Data Syntax for DNS-SD TXT Records" in
1427 * <http://files.dns-sd.org/draft-cheshire-dnsext-dns-sd.txt>
1429 * txtRecord: A TXTRecordRef initialized by calling TXTRecordCreate().
1431 * key: A null-terminated string which only contains printable ASCII
1432 * values (0x20-0x7E), excluding '=' (0x3D). Keys should be
1433 * 8 characters or less (not counting the terminating null).
1435 * valueSize: The size of the value.
1437 * value: Any binary value. For values that represent
1438 * textual data, UTF-8 is STRONGLY recommended.
1439 * For values that represent textual data, valueSize
1440 * should NOT include the terminating null (if any)
1441 * at the end of the string.
1442 * If NULL, then "key" will be added with no value.
1443 * If non-NULL but valueSize is zero, then "key=" will be
1444 * added with empty value.
1446 * return value: Returns kDNSServiceErr_NoError on success.
1447 * Returns kDNSServiceErr_Invalid if the "key" string contains
1448 * illegal characters.
1449 * Returns kDNSServiceErr_NoMemory if adding this key would
1450 * exceed the available storage.
1453 DNSServiceErrorType DNSSD_API TXTRecordSetValue
1455 TXTRecordRef *txtRecord,
1456 const char *key,
1457 uint8_t valueSize, /* may be zero */
1458 const void *value /* may be NULL */
1462 /* TXTRecordRemoveValue()
1464 * Removes a key from a TXTRecordRef. The "key" must be an
1465 * ASCII string which exists in the TXTRecordRef.
1467 * txtRecord: A TXTRecordRef initialized by calling TXTRecordCreate().
1469 * key: A key name which exists in the TXTRecordRef.
1471 * return value: Returns kDNSServiceErr_NoError on success.
1472 * Returns kDNSServiceErr_NoSuchKey if the "key" does not
1473 * exist in the TXTRecordRef.
1476 DNSServiceErrorType DNSSD_API TXTRecordRemoveValue
1478 TXTRecordRef *txtRecord,
1479 const char *key
1483 /* TXTRecordGetLength()
1485 * Allows you to determine the length of the raw bytes within a TXTRecordRef.
1487 * txtRecord: A TXTRecordRef initialized by calling TXTRecordCreate().
1489 * return value: Returns the size of the raw bytes inside a TXTRecordRef
1490 * which you can pass directly to DNSServiceRegister() or
1491 * to DNSServiceUpdateRecord().
1492 * Returns 0 if the TXTRecordRef is empty.
1495 uint16_t DNSSD_API TXTRecordGetLength
1497 const TXTRecordRef *txtRecord
1501 /* TXTRecordGetBytesPtr()
1503 * Allows you to retrieve a pointer to the raw bytes within a TXTRecordRef.
1505 * txtRecord: A TXTRecordRef initialized by calling TXTRecordCreate().
1507 * return value: Returns a pointer to the raw bytes inside the TXTRecordRef
1508 * which you can pass directly to DNSServiceRegister() or
1509 * to DNSServiceUpdateRecord().
1512 const void * DNSSD_API TXTRecordGetBytesPtr
1514 const TXTRecordRef *txtRecord
1520 * TXT Record Parsing Functions
1525 * A typical calling sequence for TXT record parsing is something like:
1527 * Receive TXT record data in DNSServiceResolve() callback
1528 * if (TXTRecordContainsKey(txtLen, txtRecord, "key")) then do something
1529 * val1ptr = TXTRecordGetValuePtr(txtLen, txtRecord, "key1", &len1);
1530 * val2ptr = TXTRecordGetValuePtr(txtLen, txtRecord, "key2", &len2);
1531 * ...
1532 * bcopy(val1ptr, myval1, len1);
1533 * bcopy(val2ptr, myval2, len2);
1534 * ...
1535 * return;
1537 * If you wish to retain the values after return from the DNSServiceResolve()
1538 * callback, then you need to copy the data to your own storage using bcopy()
1539 * or similar, as shown in the example above.
1541 * If for some reason you need to parse a TXT record you built yourself
1542 * using the TXT record construction functions above, then you can do
1543 * that using TXTRecordGetLength and TXTRecordGetBytesPtr calls:
1544 * TXTRecordGetValue(TXTRecordGetLength(x), TXTRecordGetBytesPtr(x), key, &len);
1546 * Most applications only fetch keys they know about from a TXT record and
1547 * ignore the rest.
1548 * However, some debugging tools wish to fetch and display all keys.
1549 * To do that, use the TXTRecordGetCount() and TXTRecordGetItemAtIndex() calls.
1552 /* TXTRecordContainsKey()
1554 * Allows you to determine if a given TXT Record contains a specified key.
1556 * txtLen: The size of the received TXT Record.
1558 * txtRecord: Pointer to the received TXT Record bytes.
1560 * key: A null-terminated ASCII string containing the key name.
1562 * return value: Returns 1 if the TXT Record contains the specified key.
1563 * Otherwise, it returns 0.
1566 int DNSSD_API TXTRecordContainsKey
1568 uint16_t txtLen,
1569 const void *txtRecord,
1570 const char *key
1574 /* TXTRecordGetValuePtr()
1576 * Allows you to retrieve the value for a given key from a TXT Record.
1578 * txtLen: The size of the received TXT Record
1580 * txtRecord: Pointer to the received TXT Record bytes.
1582 * key: A null-terminated ASCII string containing the key name.
1584 * valueLen: On output, will be set to the size of the "value" data.
1586 * return value: Returns NULL if the key does not exist in this TXT record,
1587 * or exists with no value (to differentiate between
1588 * these two cases use TXTRecordContainsKey()).
1589 * Returns pointer to location within TXT Record bytes
1590 * if the key exists with empty or non-empty value.
1591 * For empty value, valueLen will be zero.
1592 * For non-empty value, valueLen will be length of value data.
1595 const void * DNSSD_API TXTRecordGetValuePtr
1597 uint16_t txtLen,
1598 const void *txtRecord,
1599 const char *key,
1600 uint8_t *valueLen
1604 /* TXTRecordGetCount()
1606 * Returns the number of keys stored in the TXT Record. The count
1607 * can be used with TXTRecordGetItemAtIndex() to iterate through the keys.
1609 * txtLen: The size of the received TXT Record.
1611 * txtRecord: Pointer to the received TXT Record bytes.
1613 * return value: Returns the total number of keys in the TXT Record.
1617 uint16_t DNSSD_API TXTRecordGetCount
1619 uint16_t txtLen,
1620 const void *txtRecord
1624 /* TXTRecordGetItemAtIndex()
1626 * Allows you to retrieve a key name and value pointer, given an index into
1627 * a TXT Record. Legal index values range from zero to TXTRecordGetCount()-1.
1628 * It's also possible to iterate through keys in a TXT record by simply
1629 * calling TXTRecordGetItemAtIndex() repeatedly, beginning with index zero
1630 * and increasing until TXTRecordGetItemAtIndex() returns kDNSServiceErr_Invalid.
1632 * On return:
1633 * For keys with no value, *value is set to NULL and *valueLen is zero.
1634 * For keys with empty value, *value is non-NULL and *valueLen is zero.
1635 * For keys with non-empty value, *value is non-NULL and *valueLen is non-zero.
1637 * txtLen: The size of the received TXT Record.
1639 * txtRecord: Pointer to the received TXT Record bytes.
1641 * index: An index into the TXT Record.
1643 * keyBufLen: The size of the string buffer being supplied.
1645 * key: A string buffer used to store the key name.
1646 * On return, the buffer contains a null-terminated C string
1647 * giving the key name. DNS-SD TXT keys are usually
1648 * 8 characters or less. To hold the maximum possible
1649 * key name, the buffer should be 256 bytes long.
1651 * valueLen: On output, will be set to the size of the "value" data.
1653 * value: On output, *value is set to point to location within TXT
1654 * Record bytes that holds the value data.
1656 * return value: Returns kDNSServiceErr_NoError on success.
1657 * Returns kDNSServiceErr_NoMemory if keyBufLen is too short.
1658 * Returns kDNSServiceErr_Invalid if index is greater than
1659 * TXTRecordGetCount()-1.
1662 DNSServiceErrorType DNSSD_API TXTRecordGetItemAtIndex
1664 uint16_t txtLen,
1665 const void *txtRecord,
1666 uint16_t index,
1667 uint16_t keyBufLen,
1668 char *key,
1669 uint8_t *valueLen,
1670 const void **value
1673 #ifdef __APPLE_API_PRIVATE
1676 * Mac OS X specific functionality
1677 * 3rd party clients of this API should not depend on future support or availability of this routine
1680 /* DNSServiceSetDefaultDomainForUser()
1682 * Set the default domain for the caller's UID. Future browse and registration
1683 * calls by this user that do not specify an explicit domain will browse and
1684 * register in this wide-area domain in addition to .local. In addition, this
1685 * domain will be returned as a Browse domain via domain enumeration calls.
1688 * Parameters:
1690 * flags: Pass kDNSServiceFlagsAdd to add a domain for a user. Call without
1691 * this flag set to clear a previously added domain.
1693 * domain: The domain to be used for the caller's UID.
1695 * return value: Returns kDNSServiceErr_NoError on succeses, otherwise returns
1696 * an error code indicating the error that occurred
1699 DNSServiceErrorType DNSSD_API DNSServiceSetDefaultDomainForUser
1701 DNSServiceFlags flags,
1702 const char *domain
1705 #endif //__APPLE_API_PRIVATE
1707 // Some C compiler cleverness. We can make the compiler check certain things for us,
1708 // and report errors at compile-time if anything is wrong. The usual way to do this would
1709 // be to use a run-time "if" statement or the conventional run-time "assert" mechanism, but
1710 // then you don't find out what's wrong until you run the software. This way, if the assertion
1711 // condition is false, the array size is negative, and the complier complains immediately.
1713 struct DNS_SD_CompileTimeAssertionChecks
1715 char assert0[(sizeof(union _TXTRecordRef_t) == 16) ? 1 : -1];
1718 #ifdef __cplusplus
1720 #endif
1722 #endif /* _DNS_SD_H */