1 | /* -*- Mode: C; tab-width: 4 -*- |
---|
2 | * |
---|
3 | * Copyright (c) 2003-2013 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 5440000 |
---|
81 | |
---|
82 | #ifdef __cplusplus |
---|
83 | extern "C" { |
---|
84 | #endif |
---|
85 | |
---|
86 | /* Set to 1 if libdispatch is supported |
---|
87 | * Note: May also be set by project and/or Makefile |
---|
88 | */ |
---|
89 | #ifndef _DNS_SD_LIBDISPATCH |
---|
90 | #define _DNS_SD_LIBDISPATCH 0 |
---|
91 | #endif /* ndef _DNS_SD_LIBDISPATCH */ |
---|
92 | |
---|
93 | /* standard calling convention under Win32 is __stdcall */ |
---|
94 | /* Note: When compiling Intel EFI (Extensible Firmware Interface) under MS Visual Studio, the */ |
---|
95 | /* _WIN32 symbol is defined by the compiler even though it's NOT compiling code for Windows32 */ |
---|
96 | #if defined(_WIN32) && !defined(EFI32) && !defined(EFI64) |
---|
97 | #define DNSSD_API __stdcall |
---|
98 | #else |
---|
99 | #define DNSSD_API |
---|
100 | #endif |
---|
101 | |
---|
102 | /* stdint.h does not exist on FreeBSD 4.x; its types are defined in sys/types.h instead */ |
---|
103 | #if defined(__FreeBSD__) && (__FreeBSD__ < 5) |
---|
104 | #include <sys/types.h> |
---|
105 | |
---|
106 | /* Likewise, on Sun, standard integer types are in sys/types.h */ |
---|
107 | #elif defined(__sun__) |
---|
108 | #include <sys/types.h> |
---|
109 | |
---|
110 | /* EFI does not have stdint.h, or anything else equivalent */ |
---|
111 | #elif defined(EFI32) || defined(EFI64) || defined(EFIX64) |
---|
112 | #include "Tiano.h" |
---|
113 | #if !defined(_STDINT_H_) |
---|
114 | typedef UINT8 uint8_t; |
---|
115 | typedef INT8 int8_t; |
---|
116 | typedef UINT16 uint16_t; |
---|
117 | typedef INT16 int16_t; |
---|
118 | typedef UINT32 uint32_t; |
---|
119 | typedef INT32 int32_t; |
---|
120 | #endif |
---|
121 | /* Windows has its own differences */ |
---|
122 | #elif defined(_WIN32) |
---|
123 | #include <windows.h> |
---|
124 | #define _UNUSED |
---|
125 | #ifndef _MSL_STDINT_H |
---|
126 | typedef UINT8 uint8_t; |
---|
127 | typedef INT8 int8_t; |
---|
128 | typedef UINT16 uint16_t; |
---|
129 | typedef INT16 int16_t; |
---|
130 | typedef UINT32 uint32_t; |
---|
131 | typedef INT32 int32_t; |
---|
132 | #endif |
---|
133 | |
---|
134 | /* All other Posix platforms use stdint.h */ |
---|
135 | #else |
---|
136 | #include <stdint.h> |
---|
137 | #endif |
---|
138 | |
---|
139 | #if _DNS_SD_LIBDISPATCH |
---|
140 | #include <dispatch/dispatch.h> |
---|
141 | #endif |
---|
142 | |
---|
143 | /* DNSServiceRef, DNSRecordRef |
---|
144 | * |
---|
145 | * Opaque internal data types. |
---|
146 | * Note: client is responsible for serializing access to these structures if |
---|
147 | * they are shared between concurrent threads. |
---|
148 | */ |
---|
149 | |
---|
150 | typedef struct _DNSServiceRef_t *DNSServiceRef; |
---|
151 | typedef struct _DNSRecordRef_t *DNSRecordRef; |
---|
152 | |
---|
153 | struct sockaddr; |
---|
154 | |
---|
155 | /*! @enum General flags |
---|
156 | * Most DNS-SD API functions and callbacks include a DNSServiceFlags parameter. |
---|
157 | * As a general rule, any given bit in the 32-bit flags field has a specific fixed meaning, |
---|
158 | * regardless of the function or callback being used. For any given function or callback, |
---|
159 | * typically only a subset of the possible flags are meaningful, and all others should be zero. |
---|
160 | * The discussion section for each API call describes which flags are valid for that call |
---|
161 | * and callback. In some cases, for a particular call, it may be that no flags are currently |
---|
162 | * defined, in which case the DNSServiceFlags parameter exists purely to allow future expansion. |
---|
163 | * In all cases, developers should expect that in future releases, it is possible that new flag |
---|
164 | * values will be defined, and write code with this in mind. For example, code that tests |
---|
165 | * if (flags == kDNSServiceFlagsAdd) ... |
---|
166 | * will fail if, in a future release, another bit in the 32-bit flags field is also set. |
---|
167 | * The reliable way to test whether a particular bit is set is not with an equality test, |
---|
168 | * but with a bitwise mask: |
---|
169 | * if (flags & kDNSServiceFlagsAdd) ... |
---|
170 | * With the exception of kDNSServiceFlagsValidate, each flag can be valid(be set) |
---|
171 | * EITHER only as an input to one of the DNSService*() APIs OR only as an output |
---|
172 | * (provide status) through any of the callbacks used. For example, kDNSServiceFlagsAdd |
---|
173 | * can be set only as an output in the callback, whereas the kDNSServiceFlagsIncludeP2P |
---|
174 | * can be set only as an input to the DNSService*() APIs. See comments on kDNSServiceFlagsValidate |
---|
175 | * defined in enum below. |
---|
176 | */ |
---|
177 | enum |
---|
178 | { |
---|
179 | kDNSServiceFlagsMoreComing = 0x1, |
---|
180 | /* MoreComing indicates to a callback that at least one more result is |
---|
181 | * queued and will be delivered following immediately after this one. |
---|
182 | * When the MoreComing flag is set, applications should not immediately |
---|
183 | * update their UI, because this can result in a great deal of ugly flickering |
---|
184 | * on the screen, and can waste a great deal of CPU time repeatedly updating |
---|
185 | * the screen with content that is then immediately erased, over and over. |
---|
186 | * Applications should wait until MoreComing is not set, and then |
---|
187 | * update their UI when no more changes are imminent. |
---|
188 | * When MoreComing is not set, that doesn't mean there will be no more |
---|
189 | * answers EVER, just that there are no more answers immediately |
---|
190 | * available right now at this instant. If more answers become available |
---|
191 | * in the future they will be delivered as usual. |
---|
192 | */ |
---|
193 | |
---|
194 | kDNSServiceFlagsAdd = 0x2, |
---|
195 | kDNSServiceFlagsDefault = 0x4, |
---|
196 | /* Flags for domain enumeration and browse/query reply callbacks. |
---|
197 | * "Default" applies only to enumeration and is only valid in |
---|
198 | * conjunction with "Add". An enumeration callback with the "Add" |
---|
199 | * flag NOT set indicates a "Remove", i.e. the domain is no longer |
---|
200 | * valid. |
---|
201 | */ |
---|
202 | |
---|
203 | kDNSServiceFlagsNoAutoRename = 0x8, |
---|
204 | /* Flag for specifying renaming behavior on name conflict when registering |
---|
205 | * non-shared records. By default, name conflicts are automatically handled |
---|
206 | * by renaming the service. NoAutoRename overrides this behavior - with this |
---|
207 | * flag set, name conflicts will result in a callback. The NoAutorename flag |
---|
208 | * is only valid if a name is explicitly specified when registering a service |
---|
209 | * (i.e. the default name is not used.) |
---|
210 | */ |
---|
211 | |
---|
212 | kDNSServiceFlagsShared = 0x10, |
---|
213 | kDNSServiceFlagsUnique = 0x20, |
---|
214 | /* Flag for registering individual records on a connected |
---|
215 | * DNSServiceRef. Shared indicates that there may be multiple records |
---|
216 | * with this name on the network (e.g. PTR records). Unique indicates that the |
---|
217 | * record's name is to be unique on the network (e.g. SRV records). |
---|
218 | */ |
---|
219 | |
---|
220 | kDNSServiceFlagsBrowseDomains = 0x40, |
---|
221 | kDNSServiceFlagsRegistrationDomains = 0x80, |
---|
222 | /* Flags for specifying domain enumeration type in DNSServiceEnumerateDomains. |
---|
223 | * BrowseDomains enumerates domains recommended for browsing, RegistrationDomains |
---|
224 | * enumerates domains recommended for registration. |
---|
225 | */ |
---|
226 | |
---|
227 | kDNSServiceFlagsLongLivedQuery = 0x100, |
---|
228 | /* Flag for creating a long-lived unicast query for the DNSServiceQueryRecord call. */ |
---|
229 | |
---|
230 | kDNSServiceFlagsAllowRemoteQuery = 0x200, |
---|
231 | /* Flag for creating a record for which we will answer remote queries |
---|
232 | * (queries from hosts more than one hop away; hosts not directly connected to the local link). |
---|
233 | */ |
---|
234 | |
---|
235 | kDNSServiceFlagsForceMulticast = 0x400, |
---|
236 | /* Flag for signifying that a query or registration should be performed exclusively via multicast |
---|
237 | * DNS, even for a name in a domain (e.g. foo.apple.com.) that would normally imply unicast DNS. |
---|
238 | */ |
---|
239 | |
---|
240 | kDNSServiceFlagsForce = 0x800, // This flag is deprecated. |
---|
241 | |
---|
242 | kDNSServiceFlagsKnownUnique = 0x800, |
---|
243 | /* |
---|
244 | * Client guarantees that record names are unique, so we can skip sending out initial |
---|
245 | * probe messages. Standard name conflict resolution is still done if a conflict is discovered. |
---|
246 | * Currently only valid for a DNSServiceRegister call. |
---|
247 | */ |
---|
248 | |
---|
249 | kDNSServiceFlagsReturnIntermediates = 0x1000, |
---|
250 | /* Flag for returning intermediate results. |
---|
251 | * For example, if a query results in an authoritative NXDomain (name does not exist) |
---|
252 | * then that result is returned to the client. However the query is not implicitly |
---|
253 | * cancelled -- it remains active and if the answer subsequently changes |
---|
254 | * (e.g. because a VPN tunnel is subsequently established) then that positive |
---|
255 | * result will still be returned to the client. |
---|
256 | * Similarly, if a query results in a CNAME record, then in addition to following |
---|
257 | * the CNAME referral, the intermediate CNAME result is also returned to the client. |
---|
258 | * When this flag is not set, NXDomain errors are not returned, and CNAME records |
---|
259 | * are followed silently without informing the client of the intermediate steps. |
---|
260 | * (In earlier builds this flag was briefly calledkDNSServiceFlagsReturnCNAME) |
---|
261 | */ |
---|
262 | |
---|
263 | kDNSServiceFlagsNonBrowsable = 0x2000, |
---|
264 | /* A service registered with the NonBrowsable flag set can be resolved using |
---|
265 | * DNSServiceResolve(), but will not be discoverable using DNSServiceBrowse(). |
---|
266 | * This is for cases where the name is actually a GUID; it is found by other means; |
---|
267 | * there is no end-user benefit to browsing to find a long list of opaque GUIDs. |
---|
268 | * Using the NonBrowsable flag creates SRV+TXT without the cost of also advertising |
---|
269 | * an associated PTR record. |
---|
270 | */ |
---|
271 | |
---|
272 | kDNSServiceFlagsShareConnection = 0x4000, |
---|
273 | /* For efficiency, clients that perform many concurrent operations may want to use a |
---|
274 | * single Unix Domain Socket connection with the background daemon, instead of having a |
---|
275 | * separate connection for each independent operation. To use this mode, clients first |
---|
276 | * call DNSServiceCreateConnection(&MainRef) to initialize the main DNSServiceRef. |
---|
277 | * For each subsequent operation that is to share that same connection, the client copies |
---|
278 | * the MainRef, and then passes the address of that copy, setting the ShareConnection flag |
---|
279 | * to tell the library that this DNSServiceRef is not a typical uninitialized DNSServiceRef; |
---|
280 | * it's a copy of an existing DNSServiceRef whose connection information should be reused. |
---|
281 | * |
---|
282 | * For example: |
---|
283 | * |
---|
284 | * DNSServiceErrorType error; |
---|
285 | * DNSServiceRef MainRef; |
---|
286 | * error = DNSServiceCreateConnection(&MainRef); |
---|
287 | * if (error) ... |
---|
288 | * DNSServiceRef BrowseRef = MainRef; // Important: COPY the primary DNSServiceRef first... |
---|
289 | * error = DNSServiceBrowse(&BrowseRef, kDNSServiceFlagsShareConnection, ...); // then use the copy |
---|
290 | * if (error) ... |
---|
291 | * ... |
---|
292 | * DNSServiceRefDeallocate(BrowseRef); // Terminate the browse operation |
---|
293 | * DNSServiceRefDeallocate(MainRef); // Terminate the shared connection |
---|
294 | * |
---|
295 | * Notes: |
---|
296 | * |
---|
297 | * 1. Collective kDNSServiceFlagsMoreComing flag |
---|
298 | * When callbacks are invoked using a shared DNSServiceRef, the |
---|
299 | * kDNSServiceFlagsMoreComing flag applies collectively to *all* active |
---|
300 | * operations sharing the same parent DNSServiceRef. If the MoreComing flag is |
---|
301 | * set it means that there are more results queued on this parent DNSServiceRef, |
---|
302 | * but not necessarily more results for this particular callback function. |
---|
303 | * The implication of this for client programmers is that when a callback |
---|
304 | * is invoked with the MoreComing flag set, the code should update its |
---|
305 | * internal data structures with the new result, and set a variable indicating |
---|
306 | * that its UI needs to be updated. Then, later when a callback is eventually |
---|
307 | * invoked with the MoreComing flag not set, the code should update *all* |
---|
308 | * stale UI elements related to that shared parent DNSServiceRef that need |
---|
309 | * updating, not just the UI elements related to the particular callback |
---|
310 | * that happened to be the last one to be invoked. |
---|
311 | * |
---|
312 | * 2. Canceling operations and kDNSServiceFlagsMoreComing |
---|
313 | * Whenever you cancel any operation for which you had deferred UI updates |
---|
314 | * waiting because of a kDNSServiceFlagsMoreComing flag, you should perform |
---|
315 | * those deferred UI updates. This is because, after cancelling the operation, |
---|
316 | * you can no longer wait for a callback *without* MoreComing set, to tell |
---|
317 | * you do perform your deferred UI updates (the operation has been canceled, |
---|
318 | * so there will be no more callbacks). An implication of the collective |
---|
319 | * kDNSServiceFlagsMoreComing flag for shared connections is that this |
---|
320 | * guideline applies more broadly -- any time you cancel an operation on |
---|
321 | * a shared connection, you should perform all deferred UI updates for all |
---|
322 | * operations sharing that connection. This is because the MoreComing flag |
---|
323 | * might have been referring to events coming for the operation you canceled, |
---|
324 | * which will now not be coming because the operation has been canceled. |
---|
325 | * |
---|
326 | * 3. Only share DNSServiceRef's created with DNSServiceCreateConnection |
---|
327 | * Calling DNSServiceCreateConnection(&ref) creates a special shareable DNSServiceRef. |
---|
328 | * DNSServiceRef's created by other calls like DNSServiceBrowse() or DNSServiceResolve() |
---|
329 | * cannot be shared by copying them and using kDNSServiceFlagsShareConnection. |
---|
330 | * |
---|
331 | * 4. Don't Double-Deallocate |
---|
332 | * Calling DNSServiceRefDeallocate(ref) for a particular operation's DNSServiceRef terminates |
---|
333 | * just that operation. Calling DNSServiceRefDeallocate(ref) for the main shared DNSServiceRef |
---|
334 | * (the parent DNSServiceRef, originally created by DNSServiceCreateConnection(&ref)) |
---|
335 | * automatically terminates the shared connection and all operations that were still using it. |
---|
336 | * After doing this, DO NOT then attempt to deallocate any remaining subordinate DNSServiceRef's. |
---|
337 | * The memory used by those subordinate DNSServiceRef's has already been freed, so any attempt |
---|
338 | * to do a DNSServiceRefDeallocate (or any other operation) on them will result in accesses |
---|
339 | * to freed memory, leading to crashes or other equally undesirable results. |
---|
340 | * |
---|
341 | * 5. Thread Safety |
---|
342 | * The dns_sd.h API does not presuppose any particular threading model, and consequently |
---|
343 | * does no locking of its own (which would require linking some specific threading library). |
---|
344 | * If client code calls API routines on the same DNSServiceRef concurrently |
---|
345 | * from multiple threads, it is the client's responsibility to use a mutext |
---|
346 | * lock or take similar appropriate precautions to serialize those calls. |
---|
347 | */ |
---|
348 | |
---|
349 | kDNSServiceFlagsSuppressUnusable = 0x8000, |
---|
350 | /* |
---|
351 | * This flag is meaningful only in DNSServiceQueryRecord which suppresses unusable queries on the |
---|
352 | * wire. If "hostname" is a wide-area unicast DNS hostname (i.e. not a ".local." name) |
---|
353 | * but this host has no routable IPv6 address, then the call will not try to look up IPv6 addresses |
---|
354 | * for "hostname", since any addresses it found would be unlikely to be of any use anyway. Similarly, |
---|
355 | * if this host has no routable IPv4 address, the call will not try to look up IPv4 addresses for |
---|
356 | * "hostname". |
---|
357 | */ |
---|
358 | |
---|
359 | kDNSServiceFlagsTimeout = 0x10000, |
---|
360 | /* |
---|
361 | * When kDNServiceFlagsTimeout is passed to DNSServiceQueryRecord or DNSServiceGetAddrInfo, the query is |
---|
362 | * stopped after a certain number of seconds have elapsed. The time at which the query will be stopped |
---|
363 | * is determined by the system and cannot be configured by the user. The query will be stopped irrespective |
---|
364 | * of whether a response was given earlier or not. When the query is stopped, the callback will be called |
---|
365 | * with an error code of kDNSServiceErr_Timeout and a NULL sockaddr will be returned for DNSServiceGetAddrInfo |
---|
366 | * and zero length rdata will be returned for DNSServiceQueryRecord. |
---|
367 | */ |
---|
368 | |
---|
369 | kDNSServiceFlagsIncludeP2P = 0x20000, |
---|
370 | /* |
---|
371 | * Include P2P interfaces when kDNSServiceInterfaceIndexAny is specified. |
---|
372 | * By default, specifying kDNSServiceInterfaceIndexAny does not include P2P interfaces. |
---|
373 | */ |
---|
374 | |
---|
375 | kDNSServiceFlagsWakeOnResolve = 0x40000, |
---|
376 | /* |
---|
377 | * This flag is meaningful only in DNSServiceResolve. When set, it tries to send a magic packet |
---|
378 | * to wake up the client. |
---|
379 | */ |
---|
380 | |
---|
381 | kDNSServiceFlagsBackgroundTrafficClass = 0x80000, |
---|
382 | /* |
---|
383 | * This flag is meaningful in DNSServiceBrowse, DNSServiceGetAddrInfo, DNSServiceQueryRecord, |
---|
384 | * and DNSServiceResolve. When set, it uses the background traffic |
---|
385 | * class for packets that service the request. |
---|
386 | */ |
---|
387 | |
---|
388 | kDNSServiceFlagsIncludeAWDL = 0x100000, |
---|
389 | /* |
---|
390 | * Include AWDL interface when kDNSServiceInterfaceIndexAny is specified. |
---|
391 | */ |
---|
392 | |
---|
393 | kDNSServiceFlagsValidate = 0x200000, |
---|
394 | /* |
---|
395 | * This flag is meaningful in DNSServiceGetAddrInfo and DNSServiceQueryRecord. This is the ONLY flag to be valid |
---|
396 | * as an input to the APIs and also an output through the callbacks in the APIs. |
---|
397 | * |
---|
398 | * When this flag is passed to DNSServiceQueryRecord and DNSServiceGetAddrInfo to resolve unicast names, |
---|
399 | * the response will be validated using DNSSEC. The validation results are delivered using the flags field in |
---|
400 | * the callback and kDNSServiceFlagsValidate is marked in the flags to indicate that DNSSEC status is also available. |
---|
401 | * When the callback is called to deliver the query results, the validation results may or may not be available. |
---|
402 | * If it is not delivered along with the results, the validation status is delivered when the validation completes. |
---|
403 | * |
---|
404 | * When the validation results are delivered in the callback, it is indicated by marking the flags with |
---|
405 | * kDNSServiceFlagsValidate and kDNSServiceFlagsAdd along with the DNSSEC status flags (described below) and a NULL |
---|
406 | * sockaddr will be returned for DNSServiceGetAddrInfo and zero length rdata will be returned for DNSServiceQueryRecord. |
---|
407 | * DNSSEC validation results are for the whole RRSet and not just individual records delivered in the callback. When |
---|
408 | * kDNSServiceFlagsAdd is not set in the flags, applications should implicitly assume that the DNSSEC status of the |
---|
409 | * RRSet that has been delivered up until that point is not valid anymore, till another callback is called with |
---|
410 | * kDNSServiceFlagsAdd and kDNSServiceFlagsValidate. |
---|
411 | * |
---|
412 | * The following four flags indicate the status of the DNSSEC validation and marked in the flags field of the callback. |
---|
413 | * When any of the four flags is set, kDNSServiceFlagsValidate will also be set. To check the validation status, the |
---|
414 | * other applicable output flags should be masked. See kDNSServiceOutputFlags below. |
---|
415 | */ |
---|
416 | |
---|
417 | kDNSServiceFlagsSecure = 0x200010, |
---|
418 | /* |
---|
419 | * The response has been validated by verifying all the signaures in the response and was able to |
---|
420 | * build a successful authentication chain starting from a known trust anchor. |
---|
421 | */ |
---|
422 | |
---|
423 | kDNSServiceFlagsInsecure = 0x200020, |
---|
424 | /* |
---|
425 | * A chain of trust cannot be built starting from a known trust anchor to the response. |
---|
426 | */ |
---|
427 | |
---|
428 | kDNSServiceFlagsBogus = 0x200040, |
---|
429 | /* |
---|
430 | * If the response cannot be verified to be secure due to expired signatures, missing signatures etc., |
---|
431 | * then the results are considered to be bogus. |
---|
432 | */ |
---|
433 | |
---|
434 | kDNSServiceFlagsIndeterminate = 0x200080, |
---|
435 | /* |
---|
436 | * There is no valid trust anchor that can be used to determine whether a response is secure or not. |
---|
437 | */ |
---|
438 | |
---|
439 | kDNSServiceFlagsUnicastResponse = 0x400000, |
---|
440 | /* |
---|
441 | * Request unicast response to query. |
---|
442 | */ |
---|
443 | kDNSServiceFlagsValidateOptional = 0x800000, |
---|
444 | |
---|
445 | /* |
---|
446 | * This flag is identical to kDNSServiceFlagsValidate except for the case where the response |
---|
447 | * cannot be validated. If this flag is set in DNSServiceQueryRecord or DNSServiceGetAddrInfo, |
---|
448 | * the DNSSEC records will be requested for validation. If they cannot be received for some reason |
---|
449 | * during the validation (e.g., zone is not signed, zone is signed but cannot be traced back to |
---|
450 | * root, recursive server does not understand DNSSEC etc.), then this will fallback to the default |
---|
451 | * behavior where the validation will not be performed and no DNSSEC results will be provided. |
---|
452 | * |
---|
453 | * If the zone is signed and there is a valid path to a known trust anchor configured in the system |
---|
454 | * and the application requires DNSSEC validation irrespective of the DNSSEC awareness in the current |
---|
455 | * network, then this option MUST not be used. This is only intended to be used during the transition |
---|
456 | * period where the different nodes participating in the DNS resolution may not understand DNSSEC or |
---|
457 | * managed properly (e.g. missing DS record) but still want to be able to resolve DNS successfully. |
---|
458 | */ |
---|
459 | |
---|
460 | kDNSServiceFlagsWakeOnlyService = 0x1000000, |
---|
461 | /* |
---|
462 | * This flag is meaningful only in DNSServiceRegister. When set, the service will not be registered |
---|
463 | * with sleep proxy server during sleep. |
---|
464 | */ |
---|
465 | |
---|
466 | kDNSServiceFlagsThresholdOne = 0x2000000, |
---|
467 | kDNSServiceFlagsThresholdFinder = 0x4000000, |
---|
468 | kDNSServiceFlagsThresholdReached = kDNSServiceFlagsThresholdOne, |
---|
469 | /* |
---|
470 | * kDNSServiceFlagsThresholdOne is meaningful only in DNSServiceBrowse. When set, |
---|
471 | * the system will stop issuing browse queries on the network once the number |
---|
472 | * of answers returned is one or more. It will issue queries on the network |
---|
473 | * again if the number of answers drops to zero. |
---|
474 | * This flag is for Apple internal use only. Third party developers |
---|
475 | * should not rely on this behavior being supported in any given software release. |
---|
476 | * |
---|
477 | * kDNSServiceFlagsThresholdFinder is meaningful only in DNSServiceBrowse. When set, |
---|
478 | * the system will stop issuing browse queries on the network once the number |
---|
479 | * of answers has reached the threshold set for Finder. |
---|
480 | * It will issue queries on the network again if the number of answers drops below |
---|
481 | * this threshold. |
---|
482 | * This flag is for Apple internal use only. Third party developers |
---|
483 | * should not rely on this behavior being supported in any given software release. |
---|
484 | * |
---|
485 | * When kDNSServiceFlagsThresholdReached is set in the client callback add or remove event, |
---|
486 | * it indicates that the browse answer threshold has been reached and no |
---|
487 | * browse requests will be generated on the network until the number of answers falls |
---|
488 | * below the threshold value. Add and remove events can still occur based |
---|
489 | * on incoming Bonjour traffic observed by the system. |
---|
490 | * The set of services return to the client is not guaranteed to represent the |
---|
491 | * entire set of services present on the network once the threshold has been reached. |
---|
492 | * |
---|
493 | * Note, while kDNSServiceFlagsThresholdReached and kDNSServiceFlagsThresholdOne |
---|
494 | * have the same value, there isn't a conflict because kDNSServiceFlagsThresholdReached |
---|
495 | * is only set in the callbacks and kDNSServiceFlagsThresholdOne is only set on |
---|
496 | * input to a DNSServiceBrowse call. |
---|
497 | */ |
---|
498 | }; |
---|
499 | |
---|
500 | #define kDNSServiceOutputFlags (kDNSServiceFlagsValidate | kDNSServiceFlagsValidateOptional | kDNSServiceFlagsMoreComing | kDNSServiceFlagsAdd | kDNSServiceFlagsDefault) |
---|
501 | /* All the output flags excluding the DNSSEC Status flags. Typically used to check DNSSEC Status */ |
---|
502 | |
---|
503 | /* Possible protocol values */ |
---|
504 | enum |
---|
505 | { |
---|
506 | /* for DNSServiceGetAddrInfo() */ |
---|
507 | kDNSServiceProtocol_IPv4 = 0x01, |
---|
508 | kDNSServiceProtocol_IPv6 = 0x02, |
---|
509 | /* 0x04 and 0x08 reserved for future internetwork protocols */ |
---|
510 | |
---|
511 | /* for DNSServiceNATPortMappingCreate() */ |
---|
512 | kDNSServiceProtocol_UDP = 0x10, |
---|
513 | kDNSServiceProtocol_TCP = 0x20 |
---|
514 | /* 0x40 and 0x80 reserved for future transport protocols, e.g. SCTP [RFC 2960] |
---|
515 | * or DCCP [RFC 4340]. If future NAT gateways are created that support port |
---|
516 | * mappings for these protocols, new constants will be defined here. |
---|
517 | */ |
---|
518 | }; |
---|
519 | |
---|
520 | /* |
---|
521 | * The values for DNS Classes and Types are listed in RFC 1035, and are available |
---|
522 | * on every OS in its DNS header file. Unfortunately every OS does not have the |
---|
523 | * same header file containing DNS Class and Type constants, and the names of |
---|
524 | * the constants are not consistent. For example, BIND 8 uses "T_A", |
---|
525 | * BIND 9 uses "ns_t_a", Windows uses "DNS_TYPE_A", etc. |
---|
526 | * For this reason, these constants are also listed here, so that code using |
---|
527 | * the DNS-SD programming APIs can use these constants, so that the same code |
---|
528 | * can compile on all our supported platforms. |
---|
529 | */ |
---|
530 | |
---|
531 | enum |
---|
532 | { |
---|
533 | kDNSServiceClass_IN = 1 /* Internet */ |
---|
534 | }; |
---|
535 | |
---|
536 | enum |
---|
537 | { |
---|
538 | kDNSServiceType_A = 1, /* Host address. */ |
---|
539 | kDNSServiceType_NS = 2, /* Authoritative server. */ |
---|
540 | kDNSServiceType_MD = 3, /* Mail destination. */ |
---|
541 | kDNSServiceType_MF = 4, /* Mail forwarder. */ |
---|
542 | kDNSServiceType_CNAME = 5, /* Canonical name. */ |
---|
543 | kDNSServiceType_SOA = 6, /* Start of authority zone. */ |
---|
544 | kDNSServiceType_MB = 7, /* Mailbox domain name. */ |
---|
545 | kDNSServiceType_MG = 8, /* Mail group member. */ |
---|
546 | kDNSServiceType_MR = 9, /* Mail rename name. */ |
---|
547 | kDNSServiceType_NULL = 10, /* Null resource record. */ |
---|
548 | kDNSServiceType_WKS = 11, /* Well known service. */ |
---|
549 | kDNSServiceType_PTR = 12, /* Domain name pointer. */ |
---|
550 | kDNSServiceType_HINFO = 13, /* Host information. */ |
---|
551 | kDNSServiceType_MINFO = 14, /* Mailbox information. */ |
---|
552 | kDNSServiceType_MX = 15, /* Mail routing information. */ |
---|
553 | kDNSServiceType_TXT = 16, /* One or more text strings (NOT "zero or more..."). */ |
---|
554 | kDNSServiceType_RP = 17, /* Responsible person. */ |
---|
555 | kDNSServiceType_AFSDB = 18, /* AFS cell database. */ |
---|
556 | kDNSServiceType_X25 = 19, /* X_25 calling address. */ |
---|
557 | kDNSServiceType_ISDN = 20, /* ISDN calling address. */ |
---|
558 | kDNSServiceType_RT = 21, /* Router. */ |
---|
559 | kDNSServiceType_NSAP = 22, /* NSAP address. */ |
---|
560 | kDNSServiceType_NSAP_PTR = 23, /* Reverse NSAP lookup (deprecated). */ |
---|
561 | kDNSServiceType_SIG = 24, /* Security signature. */ |
---|
562 | kDNSServiceType_KEY = 25, /* Security key. */ |
---|
563 | kDNSServiceType_PX = 26, /* X.400 mail mapping. */ |
---|
564 | kDNSServiceType_GPOS = 27, /* Geographical position (withdrawn). */ |
---|
565 | kDNSServiceType_AAAA = 28, /* IPv6 Address. */ |
---|
566 | kDNSServiceType_LOC = 29, /* Location Information. */ |
---|
567 | kDNSServiceType_NXT = 30, /* Next domain (security). */ |
---|
568 | kDNSServiceType_EID = 31, /* Endpoint identifier. */ |
---|
569 | kDNSServiceType_NIMLOC = 32, /* Nimrod Locator. */ |
---|
570 | kDNSServiceType_SRV = 33, /* Server Selection. */ |
---|
571 | kDNSServiceType_ATMA = 34, /* ATM Address */ |
---|
572 | kDNSServiceType_NAPTR = 35, /* Naming Authority PoinTeR */ |
---|
573 | kDNSServiceType_KX = 36, /* Key Exchange */ |
---|
574 | kDNSServiceType_CERT = 37, /* Certification record */ |
---|
575 | kDNSServiceType_A6 = 38, /* IPv6 Address (deprecated) */ |
---|
576 | kDNSServiceType_DNAME = 39, /* Non-terminal DNAME (for IPv6) */ |
---|
577 | kDNSServiceType_SINK = 40, /* Kitchen sink (experimental) */ |
---|
578 | kDNSServiceType_OPT = 41, /* EDNS0 option (meta-RR) */ |
---|
579 | kDNSServiceType_APL = 42, /* Address Prefix List */ |
---|
580 | kDNSServiceType_DS = 43, /* Delegation Signer */ |
---|
581 | kDNSServiceType_SSHFP = 44, /* SSH Key Fingerprint */ |
---|
582 | kDNSServiceType_IPSECKEY = 45, /* IPSECKEY */ |
---|
583 | kDNSServiceType_RRSIG = 46, /* RRSIG */ |
---|
584 | kDNSServiceType_NSEC = 47, /* Denial of Existence */ |
---|
585 | kDNSServiceType_DNSKEY = 48, /* DNSKEY */ |
---|
586 | kDNSServiceType_DHCID = 49, /* DHCP Client Identifier */ |
---|
587 | kDNSServiceType_NSEC3 = 50, /* Hashed Authenticated Denial of Existence */ |
---|
588 | kDNSServiceType_NSEC3PARAM = 51, /* Hashed Authenticated Denial of Existence */ |
---|
589 | |
---|
590 | kDNSServiceType_HIP = 55, /* Host Identity Protocol */ |
---|
591 | |
---|
592 | kDNSServiceType_SPF = 99, /* Sender Policy Framework for E-Mail */ |
---|
593 | kDNSServiceType_UINFO = 100, /* IANA-Reserved */ |
---|
594 | kDNSServiceType_UID = 101, /* IANA-Reserved */ |
---|
595 | kDNSServiceType_GID = 102, /* IANA-Reserved */ |
---|
596 | kDNSServiceType_UNSPEC = 103, /* IANA-Reserved */ |
---|
597 | |
---|
598 | kDNSServiceType_TKEY = 249, /* Transaction key */ |
---|
599 | kDNSServiceType_TSIG = 250, /* Transaction signature. */ |
---|
600 | kDNSServiceType_IXFR = 251, /* Incremental zone transfer. */ |
---|
601 | kDNSServiceType_AXFR = 252, /* Transfer zone of authority. */ |
---|
602 | kDNSServiceType_MAILB = 253, /* Transfer mailbox records. */ |
---|
603 | kDNSServiceType_MAILA = 254, /* Transfer mail agent records. */ |
---|
604 | kDNSServiceType_ANY = 255 /* Wildcard match. */ |
---|
605 | }; |
---|
606 | |
---|
607 | /* possible error code values */ |
---|
608 | enum |
---|
609 | { |
---|
610 | kDNSServiceErr_NoError = 0, |
---|
611 | kDNSServiceErr_Unknown = -65537, /* 0xFFFE FFFF */ |
---|
612 | kDNSServiceErr_NoSuchName = -65538, |
---|
613 | kDNSServiceErr_NoMemory = -65539, |
---|
614 | kDNSServiceErr_BadParam = -65540, |
---|
615 | kDNSServiceErr_BadReference = -65541, |
---|
616 | kDNSServiceErr_BadState = -65542, |
---|
617 | kDNSServiceErr_BadFlags = -65543, |
---|
618 | kDNSServiceErr_Unsupported = -65544, |
---|
619 | kDNSServiceErr_NotInitialized = -65545, |
---|
620 | kDNSServiceErr_AlreadyRegistered = -65547, |
---|
621 | kDNSServiceErr_NameConflict = -65548, |
---|
622 | kDNSServiceErr_Invalid = -65549, |
---|
623 | kDNSServiceErr_Firewall = -65550, |
---|
624 | kDNSServiceErr_Incompatible = -65551, /* client library incompatible with daemon */ |
---|
625 | kDNSServiceErr_BadInterfaceIndex = -65552, |
---|
626 | kDNSServiceErr_Refused = -65553, |
---|
627 | kDNSServiceErr_NoSuchRecord = -65554, |
---|
628 | kDNSServiceErr_NoAuth = -65555, |
---|
629 | kDNSServiceErr_NoSuchKey = -65556, |
---|
630 | kDNSServiceErr_NATTraversal = -65557, |
---|
631 | kDNSServiceErr_DoubleNAT = -65558, |
---|
632 | kDNSServiceErr_BadTime = -65559, /* Codes up to here existed in Tiger */ |
---|
633 | kDNSServiceErr_BadSig = -65560, |
---|
634 | kDNSServiceErr_BadKey = -65561, |
---|
635 | kDNSServiceErr_Transient = -65562, |
---|
636 | kDNSServiceErr_ServiceNotRunning = -65563, /* Background daemon not running */ |
---|
637 | kDNSServiceErr_NATPortMappingUnsupported = -65564, /* NAT doesn't support PCP, NAT-PMP or UPnP */ |
---|
638 | kDNSServiceErr_NATPortMappingDisabled = -65565, /* NAT supports PCP, NAT-PMP or UPnP, but it's disabled by the administrator */ |
---|
639 | kDNSServiceErr_NoRouter = -65566, /* No router currently configured (probably no network connectivity) */ |
---|
640 | kDNSServiceErr_PollingMode = -65567, |
---|
641 | kDNSServiceErr_Timeout = -65568 |
---|
642 | |
---|
643 | /* mDNS Error codes are in the range |
---|
644 | * FFFE FF00 (-65792) to FFFE FFFF (-65537) */ |
---|
645 | }; |
---|
646 | |
---|
647 | /* Maximum length, in bytes, of a service name represented as a */ |
---|
648 | /* literal C-String, including the terminating NULL at the end. */ |
---|
649 | |
---|
650 | #define kDNSServiceMaxServiceName 64 |
---|
651 | |
---|
652 | /* Maximum length, in bytes, of a domain name represented as an *escaped* C-String */ |
---|
653 | /* including the final trailing dot, and the C-String terminating NULL at the end. */ |
---|
654 | |
---|
655 | #define kDNSServiceMaxDomainName 1009 |
---|
656 | |
---|
657 | /* |
---|
658 | * Notes on DNS Name Escaping |
---|
659 | * -- or -- |
---|
660 | * "Why is kDNSServiceMaxDomainName 1009, when the maximum legal domain name is 256 bytes?" |
---|
661 | * |
---|
662 | * All strings used in the DNS-SD APIs are UTF-8 strings. Apart from the exceptions noted below, |
---|
663 | * the APIs expect the strings to be properly escaped, using the conventional DNS escaping rules: |
---|
664 | * |
---|
665 | * '\\' represents a single literal '\' in the name |
---|
666 | * '\.' represents a single literal '.' in the name |
---|
667 | * '\ddd', where ddd is a three-digit decimal value from 000 to 255, |
---|
668 | * represents a single literal byte with that value. |
---|
669 | * A bare unescaped '.' is a label separator, marking a boundary between domain and subdomain. |
---|
670 | * |
---|
671 | * The exceptions, that do not use escaping, are the routines where the full |
---|
672 | * DNS name of a resource is broken, for convenience, into servicename/regtype/domain. |
---|
673 | * In these routines, the "servicename" is NOT escaped. It does not need to be, since |
---|
674 | * it is, by definition, just a single literal string. Any characters in that string |
---|
675 | * represent exactly what they are. The "regtype" portion is, technically speaking, |
---|
676 | * escaped, but since legal regtypes are only allowed to contain letters, digits, |
---|
677 | * and hyphens, there is nothing to escape, so the issue is moot. The "domain" |
---|
678 | * portion is also escaped, though most domains in use on the public Internet |
---|
679 | * today, like regtypes, don't contain any characters that need to be escaped. |
---|
680 | * As DNS-SD becomes more popular, rich-text domains for service discovery will |
---|
681 | * become common, so software should be written to cope with domains with escaping. |
---|
682 | * |
---|
683 | * The servicename may be up to 63 bytes of UTF-8 text (not counting the C-String |
---|
684 | * terminating NULL at the end). The regtype is of the form _service._tcp or |
---|
685 | * _service._udp, where the "service" part is 1-15 characters, which may be |
---|
686 | * letters, digits, or hyphens. The domain part of the three-part name may be |
---|
687 | * any legal domain, providing that the resulting servicename+regtype+domain |
---|
688 | * name does not exceed 256 bytes. |
---|
689 | * |
---|
690 | * For most software, these issues are transparent. When browsing, the discovered |
---|
691 | * servicenames should simply be displayed as-is. When resolving, the discovered |
---|
692 | * servicename/regtype/domain are simply passed unchanged to DNSServiceResolve(). |
---|
693 | * When a DNSServiceResolve() succeeds, the returned fullname is already in |
---|
694 | * the correct format to pass to standard system DNS APIs such as res_query(). |
---|
695 | * For converting from servicename/regtype/domain to a single properly-escaped |
---|
696 | * full DNS name, the helper function DNSServiceConstructFullName() is provided. |
---|
697 | * |
---|
698 | * The following (highly contrived) example illustrates the escaping process. |
---|
699 | * Suppose you have an service called "Dr. Smith\Dr. Johnson", of type "_ftp._tcp" |
---|
700 | * in subdomain "4th. Floor" of subdomain "Building 2" of domain "apple.com." |
---|
701 | * The full (escaped) DNS name of this service's SRV record would be: |
---|
702 | * Dr\.\032Smith\\Dr\.\032Johnson._ftp._tcp.4th\.\032Floor.Building\0322.apple.com. |
---|
703 | */ |
---|
704 | |
---|
705 | |
---|
706 | /* |
---|
707 | * Constants for specifying an interface index |
---|
708 | * |
---|
709 | * Specific interface indexes are identified via a 32-bit unsigned integer returned |
---|
710 | * by the if_nametoindex() family of calls. |
---|
711 | * |
---|
712 | * If the client passes 0 for interface index, that means "do the right thing", |
---|
713 | * which (at present) means, "if the name is in an mDNS local multicast domain |
---|
714 | * (e.g. 'local.', '254.169.in-addr.arpa.', '{8,9,A,B}.E.F.ip6.arpa.') then multicast |
---|
715 | * on all applicable interfaces, otherwise send via unicast to the appropriate |
---|
716 | * DNS server." Normally, most clients will use 0 for interface index to |
---|
717 | * automatically get the default sensible behaviour. |
---|
718 | * |
---|
719 | * If the client passes a positive interface index, then for multicast names that |
---|
720 | * indicates to do the operation only on that one interface. For unicast names the |
---|
721 | * interface index is ignored unless kDNSServiceFlagsForceMulticast is also set. |
---|
722 | * |
---|
723 | * If the client passes kDNSServiceInterfaceIndexLocalOnly when registering |
---|
724 | * a service, then that service will be found *only* by other local clients |
---|
725 | * on the same machine that are browsing using kDNSServiceInterfaceIndexLocalOnly |
---|
726 | * or kDNSServiceInterfaceIndexAny. |
---|
727 | * If a client has a 'private' service, accessible only to other processes |
---|
728 | * running on the same machine, this allows the client to advertise that service |
---|
729 | * in a way such that it does not inadvertently appear in service lists on |
---|
730 | * all the other machines on the network. |
---|
731 | * |
---|
732 | * If the client passes kDNSServiceInterfaceIndexLocalOnly when browsing |
---|
733 | * then it will find *all* records registered on that same local machine. |
---|
734 | * Clients explicitly wishing to discover *only* LocalOnly services can |
---|
735 | * accomplish this by inspecting the interfaceIndex of each service reported |
---|
736 | * to their DNSServiceBrowseReply() callback function, and discarding those |
---|
737 | * where the interface index is not kDNSServiceInterfaceIndexLocalOnly. |
---|
738 | * |
---|
739 | * kDNSServiceInterfaceIndexP2P is meaningful only in Browse, QueryRecord, Register, |
---|
740 | * and Resolve operations. It should not be used in other DNSService APIs. |
---|
741 | * |
---|
742 | * - If kDNSServiceInterfaceIndexP2P is passed to DNSServiceBrowse or |
---|
743 | * DNSServiceQueryRecord, it restricts the operation to P2P. |
---|
744 | * |
---|
745 | * - If kDNSServiceInterfaceIndexP2P is passed to DNSServiceRegister, it is |
---|
746 | * mapped internally to kDNSServiceInterfaceIndexAny with the kDNSServiceFlagsIncludeP2P |
---|
747 | * set. |
---|
748 | * |
---|
749 | * - If kDNSServiceInterfaceIndexP2P is passed to DNSServiceResolve, it is |
---|
750 | * mapped internally to kDNSServiceInterfaceIndexAny with the kDNSServiceFlagsIncludeP2P |
---|
751 | * set, because resolving a P2P service may create and/or enable an interface whose |
---|
752 | * index is not known a priori. The resolve callback will indicate the index of the |
---|
753 | * interface via which the service can be accessed. |
---|
754 | * |
---|
755 | * If applications pass kDNSServiceInterfaceIndexAny to DNSServiceBrowse |
---|
756 | * or DNSServiceQueryRecord, they must set the kDNSServiceFlagsIncludeP2P flag |
---|
757 | * to include P2P. In this case, if a service instance or the record being queried |
---|
758 | * is found over P2P, the resulting ADD event will indicate kDNSServiceInterfaceIndexP2P |
---|
759 | * as the interface index. |
---|
760 | */ |
---|
761 | |
---|
762 | #define kDNSServiceInterfaceIndexAny 0 |
---|
763 | #define kDNSServiceInterfaceIndexLocalOnly ((uint32_t)-1) |
---|
764 | #define kDNSServiceInterfaceIndexUnicast ((uint32_t)-2) |
---|
765 | #define kDNSServiceInterfaceIndexP2P ((uint32_t)-3) |
---|
766 | |
---|
767 | typedef uint32_t DNSServiceFlags; |
---|
768 | typedef uint32_t DNSServiceProtocol; |
---|
769 | typedef int32_t DNSServiceErrorType; |
---|
770 | |
---|
771 | |
---|
772 | /********************************************************************************************* |
---|
773 | * |
---|
774 | * Version checking |
---|
775 | * |
---|
776 | *********************************************************************************************/ |
---|
777 | |
---|
778 | /* DNSServiceGetProperty() Parameters: |
---|
779 | * |
---|
780 | * property: The requested property. |
---|
781 | * Currently the only property defined is kDNSServiceProperty_DaemonVersion. |
---|
782 | * |
---|
783 | * result: Place to store result. |
---|
784 | * For retrieving DaemonVersion, this should be the address of a uint32_t. |
---|
785 | * |
---|
786 | * size: Pointer to uint32_t containing size of the result location. |
---|
787 | * For retrieving DaemonVersion, this should be sizeof(uint32_t). |
---|
788 | * On return the uint32_t is updated to the size of the data returned. |
---|
789 | * For DaemonVersion, the returned size is always sizeof(uint32_t), but |
---|
790 | * future properties could be defined which return variable-sized results. |
---|
791 | * |
---|
792 | * return value: Returns kDNSServiceErr_NoError on success, or kDNSServiceErr_ServiceNotRunning |
---|
793 | * if the daemon (or "system service" on Windows) is not running. |
---|
794 | */ |
---|
795 | |
---|
796 | DNSServiceErrorType DNSSD_API DNSServiceGetProperty |
---|
797 | ( |
---|
798 | const char *property, /* Requested property (i.e. kDNSServiceProperty_DaemonVersion) */ |
---|
799 | void *result, /* Pointer to place to store result */ |
---|
800 | uint32_t *size /* size of result location */ |
---|
801 | ); |
---|
802 | |
---|
803 | /* |
---|
804 | * When requesting kDNSServiceProperty_DaemonVersion, the result pointer must point |
---|
805 | * to a 32-bit unsigned integer, and the size parameter must be set to sizeof(uint32_t). |
---|
806 | * |
---|
807 | * On return, the 32-bit unsigned integer contains the version number, formatted as follows: |
---|
808 | * Major part of the build number * 10000 + |
---|
809 | * minor part of the build number * 100 |
---|
810 | * |
---|
811 | * For example, Mac OS X 10.4.9 has mDNSResponder-108.4, which would be represented as |
---|
812 | * version 1080400. This allows applications to do simple greater-than and less-than comparisons: |
---|
813 | * e.g. an application that requires at least mDNSResponder-108.4 can check: |
---|
814 | * |
---|
815 | * if (version >= 1080400) ... |
---|
816 | * |
---|
817 | * Example usage: |
---|
818 | * |
---|
819 | * uint32_t version; |
---|
820 | * uint32_t size = sizeof(version); |
---|
821 | * DNSServiceErrorType err = DNSServiceGetProperty(kDNSServiceProperty_DaemonVersion, &version, &size); |
---|
822 | * if (!err) printf("Bonjour version is %d.%d\n", version / 10000, version / 100 % 100); |
---|
823 | */ |
---|
824 | |
---|
825 | #define kDNSServiceProperty_DaemonVersion "DaemonVersion" |
---|
826 | |
---|
827 | |
---|
828 | // Map the source port of the local UDP socket that was opened for sending the DNS query |
---|
829 | // to the process ID of the application that triggered the DNS resolution. |
---|
830 | // |
---|
831 | /* DNSServiceGetPID() Parameters: |
---|
832 | * |
---|
833 | * srcport: Source port (in network byte order) of the UDP socket that was created by |
---|
834 | * mDNSResponder to send the DNS query on the wire. |
---|
835 | * |
---|
836 | * pid: Process ID of the application that started the name resolution which triggered |
---|
837 | * mDNSResponder to send the query on the wire. The value can be -1 if the srcport |
---|
838 | * cannot be mapped. |
---|
839 | * |
---|
840 | * return value: Returns kDNSServiceErr_NoError on success, or kDNSServiceErr_ServiceNotRunning |
---|
841 | * if the daemon is not running. The value of the pid is undefined if the return |
---|
842 | * value has error. |
---|
843 | */ |
---|
844 | DNSServiceErrorType DNSSD_API DNSServiceGetPID |
---|
845 | ( |
---|
846 | uint16_t srcport, |
---|
847 | int32_t *pid |
---|
848 | ); |
---|
849 | |
---|
850 | /********************************************************************************************* |
---|
851 | * |
---|
852 | * Unix Domain Socket access, DNSServiceRef deallocation, and data processing functions |
---|
853 | * |
---|
854 | *********************************************************************************************/ |
---|
855 | |
---|
856 | /* DNSServiceRefSockFD() |
---|
857 | * |
---|
858 | * Access underlying Unix domain socket for an initialized DNSServiceRef. |
---|
859 | * The DNS Service Discovery implementation uses this socket to communicate between the client and |
---|
860 | * the mDNSResponder daemon. The application MUST NOT directly read from or write to this socket. |
---|
861 | * Access to the socket is provided so that it can be used as a kqueue event source, a CFRunLoop |
---|
862 | * event source, in a select() loop, etc. When the underlying event management subsystem (kqueue/ |
---|
863 | * select/CFRunLoop etc.) indicates to the client that data is available for reading on the |
---|
864 | * socket, the client should call DNSServiceProcessResult(), which will extract the daemon's |
---|
865 | * reply from the socket, and pass it to the appropriate application callback. By using a run |
---|
866 | * loop or select(), results from the daemon can be processed asynchronously. Alternatively, |
---|
867 | * a client can choose to fork a thread and have it loop calling "DNSServiceProcessResult(ref);" |
---|
868 | * If DNSServiceProcessResult() is called when no data is available for reading on the socket, it |
---|
869 | * will block until data does become available, and then process the data and return to the caller. |
---|
870 | * When data arrives on the socket, the client is responsible for calling DNSServiceProcessResult(ref) |
---|
871 | * in a timely fashion -- if the client allows a large backlog of data to build up the daemon |
---|
872 | * may terminate the connection. |
---|
873 | * |
---|
874 | * sdRef: A DNSServiceRef initialized by any of the DNSService calls. |
---|
875 | * |
---|
876 | * return value: The DNSServiceRef's underlying socket descriptor, or -1 on |
---|
877 | * error. |
---|
878 | */ |
---|
879 | |
---|
880 | int DNSSD_API DNSServiceRefSockFD(DNSServiceRef sdRef); |
---|
881 | |
---|
882 | |
---|
883 | /* DNSServiceProcessResult() |
---|
884 | * |
---|
885 | * Read a reply from the daemon, calling the appropriate application callback. This call will |
---|
886 | * block until the daemon's response is received. Use DNSServiceRefSockFD() in |
---|
887 | * conjunction with a run loop or select() to determine the presence of a response from the |
---|
888 | * server before calling this function to process the reply without blocking. Call this function |
---|
889 | * at any point if it is acceptable to block until the daemon's response arrives. Note that the |
---|
890 | * client is responsible for ensuring that DNSServiceProcessResult() is called whenever there is |
---|
891 | * a reply from the daemon - the daemon may terminate its connection with a client that does not |
---|
892 | * process the daemon's responses. |
---|
893 | * |
---|
894 | * sdRef: A DNSServiceRef initialized by any of the DNSService calls |
---|
895 | * that take a callback parameter. |
---|
896 | * |
---|
897 | * return value: Returns kDNSServiceErr_NoError on success, otherwise returns |
---|
898 | * an error code indicating the specific failure that occurred. |
---|
899 | */ |
---|
900 | |
---|
901 | DNSServiceErrorType DNSSD_API DNSServiceProcessResult(DNSServiceRef sdRef); |
---|
902 | |
---|
903 | |
---|
904 | /* DNSServiceRefDeallocate() |
---|
905 | * |
---|
906 | * Terminate a connection with the daemon and free memory associated with the DNSServiceRef. |
---|
907 | * Any services or records registered with this DNSServiceRef will be deregistered. Any |
---|
908 | * Browse, Resolve, or Query operations called with this reference will be terminated. |
---|
909 | * |
---|
910 | * Note: If the reference's underlying socket is used in a run loop or select() call, it should |
---|
911 | * be removed BEFORE DNSServiceRefDeallocate() is called, as this function closes the reference's |
---|
912 | * socket. |
---|
913 | * |
---|
914 | * Note: If the reference was initialized with DNSServiceCreateConnection(), any DNSRecordRefs |
---|
915 | * created via this reference will be invalidated by this call - the resource records are |
---|
916 | * deregistered, and their DNSRecordRefs may not be used in subsequent functions. Similarly, |
---|
917 | * if the reference was initialized with DNSServiceRegister, and an extra resource record was |
---|
918 | * added to the service via DNSServiceAddRecord(), the DNSRecordRef created by the Add() call |
---|
919 | * is invalidated when this function is called - the DNSRecordRef may not be used in subsequent |
---|
920 | * functions. |
---|
921 | * |
---|
922 | * Note: This call is to be used only with the DNSServiceRef defined by this API. |
---|
923 | * |
---|
924 | * sdRef: A DNSServiceRef initialized by any of the DNSService calls. |
---|
925 | * |
---|
926 | */ |
---|
927 | |
---|
928 | void DNSSD_API DNSServiceRefDeallocate(DNSServiceRef sdRef); |
---|
929 | |
---|
930 | |
---|
931 | /********************************************************************************************* |
---|
932 | * |
---|
933 | * Domain Enumeration |
---|
934 | * |
---|
935 | *********************************************************************************************/ |
---|
936 | |
---|
937 | /* DNSServiceEnumerateDomains() |
---|
938 | * |
---|
939 | * Asynchronously enumerate domains available for browsing and registration. |
---|
940 | * |
---|
941 | * The enumeration MUST be cancelled via DNSServiceRefDeallocate() when no more domains |
---|
942 | * are to be found. |
---|
943 | * |
---|
944 | * Note that the names returned are (like all of DNS-SD) UTF-8 strings, |
---|
945 | * and are escaped using standard DNS escaping rules. |
---|
946 | * (See "Notes on DNS Name Escaping" earlier in this file for more details.) |
---|
947 | * A graphical browser displaying a hierarchical tree-structured view should cut |
---|
948 | * the names at the bare dots to yield individual labels, then de-escape each |
---|
949 | * label according to the escaping rules, and then display the resulting UTF-8 text. |
---|
950 | * |
---|
951 | * DNSServiceDomainEnumReply Callback Parameters: |
---|
952 | * |
---|
953 | * sdRef: The DNSServiceRef initialized by DNSServiceEnumerateDomains(). |
---|
954 | * |
---|
955 | * flags: Possible values are: |
---|
956 | * kDNSServiceFlagsMoreComing |
---|
957 | * kDNSServiceFlagsAdd |
---|
958 | * kDNSServiceFlagsDefault |
---|
959 | * |
---|
960 | * interfaceIndex: Specifies the interface on which the domain exists. (The index for a given |
---|
961 | * interface is determined via the if_nametoindex() family of calls.) |
---|
962 | * |
---|
963 | * errorCode: Will be kDNSServiceErr_NoError (0) on success, otherwise indicates |
---|
964 | * the failure that occurred (other parameters are undefined if errorCode is nonzero). |
---|
965 | * |
---|
966 | * replyDomain: The name of the domain. |
---|
967 | * |
---|
968 | * context: The context pointer passed to DNSServiceEnumerateDomains. |
---|
969 | * |
---|
970 | */ |
---|
971 | |
---|
972 | typedef void (DNSSD_API *DNSServiceDomainEnumReply) |
---|
973 | ( |
---|
974 | DNSServiceRef sdRef, |
---|
975 | DNSServiceFlags flags, |
---|
976 | uint32_t interfaceIndex, |
---|
977 | DNSServiceErrorType errorCode, |
---|
978 | const char *replyDomain, |
---|
979 | void *context |
---|
980 | ); |
---|
981 | |
---|
982 | |
---|
983 | /* DNSServiceEnumerateDomains() Parameters: |
---|
984 | * |
---|
985 | * sdRef: A pointer to an uninitialized DNSServiceRef. If the call succeeds |
---|
986 | * then it initializes the DNSServiceRef, returns kDNSServiceErr_NoError, |
---|
987 | * and the enumeration operation will run indefinitely until the client |
---|
988 | * terminates it by passing this DNSServiceRef to DNSServiceRefDeallocate(). |
---|
989 | * |
---|
990 | * flags: Possible values are: |
---|
991 | * kDNSServiceFlagsBrowseDomains to enumerate domains recommended for browsing. |
---|
992 | * kDNSServiceFlagsRegistrationDomains to enumerate domains recommended |
---|
993 | * for registration. |
---|
994 | * |
---|
995 | * interfaceIndex: If non-zero, specifies the interface on which to look for domains. |
---|
996 | * (the index for a given interface is determined via the if_nametoindex() |
---|
997 | * family of calls.) Most applications will pass 0 to enumerate domains on |
---|
998 | * all interfaces. See "Constants for specifying an interface index" for more details. |
---|
999 | * |
---|
1000 | * callBack: The function to be called when a domain is found or the call asynchronously |
---|
1001 | * fails. |
---|
1002 | * |
---|
1003 | * context: An application context pointer which is passed to the callback function |
---|
1004 | * (may be NULL). |
---|
1005 | * |
---|
1006 | * return value: Returns kDNSServiceErr_NoError on success (any subsequent, asynchronous |
---|
1007 | * errors are delivered to the callback), otherwise returns an error code indicating |
---|
1008 | * the error that occurred (the callback is not invoked and the DNSServiceRef |
---|
1009 | * is not initialized). |
---|
1010 | */ |
---|
1011 | |
---|
1012 | DNSServiceErrorType DNSSD_API DNSServiceEnumerateDomains |
---|
1013 | ( |
---|
1014 | DNSServiceRef *sdRef, |
---|
1015 | DNSServiceFlags flags, |
---|
1016 | uint32_t interfaceIndex, |
---|
1017 | DNSServiceDomainEnumReply callBack, |
---|
1018 | void *context /* may be NULL */ |
---|
1019 | ); |
---|
1020 | |
---|
1021 | |
---|
1022 | /********************************************************************************************* |
---|
1023 | * |
---|
1024 | * Service Registration |
---|
1025 | * |
---|
1026 | *********************************************************************************************/ |
---|
1027 | |
---|
1028 | /* Register a service that is discovered via Browse() and Resolve() calls. |
---|
1029 | * |
---|
1030 | * DNSServiceRegisterReply() Callback Parameters: |
---|
1031 | * |
---|
1032 | * sdRef: The DNSServiceRef initialized by DNSServiceRegister(). |
---|
1033 | * |
---|
1034 | * flags: When a name is successfully registered, the callback will be |
---|
1035 | * invoked with the kDNSServiceFlagsAdd flag set. When Wide-Area |
---|
1036 | * DNS-SD is in use, it is possible for a single service to get |
---|
1037 | * more than one success callback (e.g. one in the "local" multicast |
---|
1038 | * DNS domain, and another in a wide-area unicast DNS domain). |
---|
1039 | * If a successfully-registered name later suffers a name conflict |
---|
1040 | * or similar problem and has to be deregistered, the callback will |
---|
1041 | * be invoked with the kDNSServiceFlagsAdd flag not set. The callback |
---|
1042 | * is *not* invoked in the case where the caller explicitly terminates |
---|
1043 | * the service registration by calling DNSServiceRefDeallocate(ref); |
---|
1044 | * |
---|
1045 | * errorCode: Will be kDNSServiceErr_NoError on success, otherwise will |
---|
1046 | * indicate the failure that occurred (including name conflicts, |
---|
1047 | * if the kDNSServiceFlagsNoAutoRename flag was used when registering.) |
---|
1048 | * Other parameters are undefined if errorCode is nonzero. |
---|
1049 | * |
---|
1050 | * name: The service name registered (if the application did not specify a name in |
---|
1051 | * DNSServiceRegister(), this indicates what name was automatically chosen). |
---|
1052 | * |
---|
1053 | * regtype: The type of service registered, as it was passed to the callout. |
---|
1054 | * |
---|
1055 | * domain: The domain on which the service was registered (if the application did not |
---|
1056 | * specify a domain in DNSServiceRegister(), this indicates the default domain |
---|
1057 | * on which the service was registered). |
---|
1058 | * |
---|
1059 | * context: The context pointer that was passed to the callout. |
---|
1060 | * |
---|
1061 | */ |
---|
1062 | |
---|
1063 | typedef void (DNSSD_API *DNSServiceRegisterReply) |
---|
1064 | ( |
---|
1065 | DNSServiceRef sdRef, |
---|
1066 | DNSServiceFlags flags, |
---|
1067 | DNSServiceErrorType errorCode, |
---|
1068 | const char *name, |
---|
1069 | const char *regtype, |
---|
1070 | const char *domain, |
---|
1071 | void *context |
---|
1072 | ); |
---|
1073 | |
---|
1074 | |
---|
1075 | /* DNSServiceRegister() Parameters: |
---|
1076 | * |
---|
1077 | * sdRef: A pointer to an uninitialized DNSServiceRef. If the call succeeds |
---|
1078 | * then it initializes the DNSServiceRef, returns kDNSServiceErr_NoError, |
---|
1079 | * and the registration will remain active indefinitely until the client |
---|
1080 | * terminates it by passing this DNSServiceRef to DNSServiceRefDeallocate(). |
---|
1081 | * |
---|
1082 | * interfaceIndex: If non-zero, specifies the interface on which to register the service |
---|
1083 | * (the index for a given interface is determined via the if_nametoindex() |
---|
1084 | * family of calls.) Most applications will pass 0 to register on all |
---|
1085 | * available interfaces. See "Constants for specifying an interface index" for more details. |
---|
1086 | * |
---|
1087 | * flags: Indicates the renaming behavior on name conflict (most applications |
---|
1088 | * will pass 0). See flag definitions above for details. |
---|
1089 | * |
---|
1090 | * name: If non-NULL, specifies the service name to be registered. |
---|
1091 | * Most applications will not specify a name, in which case the computer |
---|
1092 | * name is used (this name is communicated to the client via the callback). |
---|
1093 | * If a name is specified, it must be 1-63 bytes of UTF-8 text. |
---|
1094 | * If the name is longer than 63 bytes it will be automatically truncated |
---|
1095 | * to a legal length, unless the NoAutoRename flag is set, |
---|
1096 | * in which case kDNSServiceErr_BadParam will be returned. |
---|
1097 | * |
---|
1098 | * regtype: The service type followed by the protocol, separated by a dot |
---|
1099 | * (e.g. "_ftp._tcp"). The service type must be an underscore, followed |
---|
1100 | * by 1-15 characters, which may be letters, digits, or hyphens. |
---|
1101 | * The transport protocol must be "_tcp" or "_udp". New service types |
---|
1102 | * should be registered at <http://www.dns-sd.org/ServiceTypes.html>. |
---|
1103 | * |
---|
1104 | * Additional subtypes of the primary service type (where a service |
---|
1105 | * type has defined subtypes) follow the primary service type in a |
---|
1106 | * comma-separated list, with no additional spaces, e.g. |
---|
1107 | * "_primarytype._tcp,_subtype1,_subtype2,_subtype3" |
---|
1108 | * Subtypes provide a mechanism for filtered browsing: A client browsing |
---|
1109 | * for "_primarytype._tcp" will discover all instances of this type; |
---|
1110 | * a client browsing for "_primarytype._tcp,_subtype2" will discover only |
---|
1111 | * those instances that were registered with "_subtype2" in their list of |
---|
1112 | * registered subtypes. |
---|
1113 | * |
---|
1114 | * The subtype mechanism can be illustrated with some examples using the |
---|
1115 | * dns-sd command-line tool: |
---|
1116 | * |
---|
1117 | * % dns-sd -R Simple _test._tcp "" 1001 & |
---|
1118 | * % dns-sd -R Better _test._tcp,HasFeatureA "" 1002 & |
---|
1119 | * % dns-sd -R Best _test._tcp,HasFeatureA,HasFeatureB "" 1003 & |
---|
1120 | * |
---|
1121 | * Now: |
---|
1122 | * % dns-sd -B _test._tcp # will find all three services |
---|
1123 | * % dns-sd -B _test._tcp,HasFeatureA # finds "Better" and "Best" |
---|
1124 | * % dns-sd -B _test._tcp,HasFeatureB # finds only "Best" |
---|
1125 | * |
---|
1126 | * Subtype labels may be up to 63 bytes long, and may contain any eight- |
---|
1127 | * bit byte values, including zero bytes. However, due to the nature of |
---|
1128 | * using a C-string-based API, conventional DNS escaping must be used for |
---|
1129 | * dots ('.'), commas (','), backslashes ('\') and zero bytes, as shown below: |
---|
1130 | * |
---|
1131 | * % dns-sd -R Test '_test._tcp,s\.one,s\,two,s\\three,s\000four' local 123 |
---|
1132 | * |
---|
1133 | * When a service is registered, all the clients browsing for the registered |
---|
1134 | * type ("regtype") will discover it. If the discovery should be |
---|
1135 | * restricted to a smaller set of well known peers, the service can be |
---|
1136 | * registered with additional data (group identifier) that is known |
---|
1137 | * only to a smaller set of peers. The group identifier should follow primary |
---|
1138 | * service type using a colon (":") as a delimeter. If subtypes are also present, |
---|
1139 | * it should be given before the subtype as shown below. |
---|
1140 | * |
---|
1141 | * % dns-sd -R _test1 _http._tcp:mygroup1 local 1001 |
---|
1142 | * % dns-sd -R _test2 _http._tcp:mygroup2 local 1001 |
---|
1143 | * % dns-sd -R _test3 _http._tcp:mygroup3,HasFeatureA local 1001 |
---|
1144 | * |
---|
1145 | * Now: |
---|
1146 | * % dns-sd -B _http._tcp:"mygroup1" # will discover only test1 |
---|
1147 | * % dns-sd -B _http._tcp:"mygroup2" # will discover only test2 |
---|
1148 | * % dns-sd -B _http._tcp:"mygroup3",HasFeatureA # will discover only test3 |
---|
1149 | * |
---|
1150 | * By specifying the group information, only the members of that group are |
---|
1151 | * discovered. |
---|
1152 | * |
---|
1153 | * The group identifier itself is not sent in clear. Only a hash of the group |
---|
1154 | * identifier is sent and the clients discover them anonymously. The group identifier |
---|
1155 | * may be up to 256 bytes long and may contain any eight bit values except comma which |
---|
1156 | * should be escaped. |
---|
1157 | * |
---|
1158 | * domain: If non-NULL, specifies the domain on which to advertise the service. |
---|
1159 | * Most applications will not specify a domain, instead automatically |
---|
1160 | * registering in the default domain(s). |
---|
1161 | * |
---|
1162 | * host: If non-NULL, specifies the SRV target host name. Most applications |
---|
1163 | * will not specify a host, instead automatically using the machine's |
---|
1164 | * default host name(s). Note that specifying a non-NULL host does NOT |
---|
1165 | * create an address record for that host - the application is responsible |
---|
1166 | * for ensuring that the appropriate address record exists, or creating it |
---|
1167 | * via DNSServiceRegisterRecord(). |
---|
1168 | * |
---|
1169 | * port: The port, in network byte order, on which the service accepts connections. |
---|
1170 | * Pass 0 for a "placeholder" service (i.e. a service that will not be discovered |
---|
1171 | * by browsing, but will cause a name conflict if another client tries to |
---|
1172 | * register that same name). Most clients will not use placeholder services. |
---|
1173 | * |
---|
1174 | * txtLen: The length of the txtRecord, in bytes. Must be zero if the txtRecord is NULL. |
---|
1175 | * |
---|
1176 | * txtRecord: The TXT record rdata. A non-NULL txtRecord MUST be a properly formatted DNS |
---|
1177 | * TXT record, i.e. <length byte> <data> <length byte> <data> ... |
---|
1178 | * Passing NULL for the txtRecord is allowed as a synonym for txtLen=1, txtRecord="", |
---|
1179 | * i.e. it creates a TXT record of length one containing a single empty string. |
---|
1180 | * RFC 1035 doesn't allow a TXT record to contain *zero* strings, so a single empty |
---|
1181 | * string is the smallest legal DNS TXT record. |
---|
1182 | * As with the other parameters, the DNSServiceRegister call copies the txtRecord |
---|
1183 | * data; e.g. if you allocated the storage for the txtRecord parameter with malloc() |
---|
1184 | * then you can safely free that memory right after the DNSServiceRegister call returns. |
---|
1185 | * |
---|
1186 | * callBack: The function to be called when the registration completes or asynchronously |
---|
1187 | * fails. The client MAY pass NULL for the callback - The client will NOT be notified |
---|
1188 | * of the default values picked on its behalf, and the client will NOT be notified of any |
---|
1189 | * asynchronous errors (e.g. out of memory errors, etc.) that may prevent the registration |
---|
1190 | * of the service. The client may NOT pass the NoAutoRename flag if the callback is NULL. |
---|
1191 | * The client may still deregister the service at any time via DNSServiceRefDeallocate(). |
---|
1192 | * |
---|
1193 | * context: An application context pointer which is passed to the callback function |
---|
1194 | * (may be NULL). |
---|
1195 | * |
---|
1196 | * return value: Returns kDNSServiceErr_NoError on success (any subsequent, asynchronous |
---|
1197 | * errors are delivered to the callback), otherwise returns an error code indicating |
---|
1198 | * the error that occurred (the callback is never invoked and the DNSServiceRef |
---|
1199 | * is not initialized). |
---|
1200 | */ |
---|
1201 | |
---|
1202 | DNSServiceErrorType DNSSD_API DNSServiceRegister |
---|
1203 | ( |
---|
1204 | DNSServiceRef *sdRef, |
---|
1205 | DNSServiceFlags flags, |
---|
1206 | uint32_t interfaceIndex, |
---|
1207 | const char *name, /* may be NULL */ |
---|
1208 | const char *regtype, |
---|
1209 | const char *domain, /* may be NULL */ |
---|
1210 | const char *host, /* may be NULL */ |
---|
1211 | uint16_t port, /* In network byte order */ |
---|
1212 | uint16_t txtLen, |
---|
1213 | const void *txtRecord, /* may be NULL */ |
---|
1214 | DNSServiceRegisterReply callBack, /* may be NULL */ |
---|
1215 | void *context /* may be NULL */ |
---|
1216 | ); |
---|
1217 | |
---|
1218 | |
---|
1219 | /* DNSServiceAddRecord() |
---|
1220 | * |
---|
1221 | * Add a record to a registered service. The name of the record will be the same as the |
---|
1222 | * registered service's name. |
---|
1223 | * The record can later be updated or deregistered by passing the RecordRef initialized |
---|
1224 | * by this function to DNSServiceUpdateRecord() or DNSServiceRemoveRecord(). |
---|
1225 | * |
---|
1226 | * Note that the DNSServiceAddRecord/UpdateRecord/RemoveRecord are *NOT* thread-safe |
---|
1227 | * with respect to a single DNSServiceRef. If you plan to have multiple threads |
---|
1228 | * in your program simultaneously add, update, or remove records from the same |
---|
1229 | * DNSServiceRef, then it's the caller's responsibility to use a mutext lock |
---|
1230 | * or take similar appropriate precautions to serialize those calls. |
---|
1231 | * |
---|
1232 | * Parameters; |
---|
1233 | * |
---|
1234 | * sdRef: A DNSServiceRef initialized by DNSServiceRegister(). |
---|
1235 | * |
---|
1236 | * RecordRef: A pointer to an uninitialized DNSRecordRef. Upon succesfull completion of this |
---|
1237 | * call, this ref may be passed to DNSServiceUpdateRecord() or DNSServiceRemoveRecord(). |
---|
1238 | * If the above DNSServiceRef is passed to DNSServiceRefDeallocate(), RecordRef is also |
---|
1239 | * invalidated and may not be used further. |
---|
1240 | * |
---|
1241 | * flags: Currently ignored, reserved for future use. |
---|
1242 | * |
---|
1243 | * rrtype: The type of the record (e.g. kDNSServiceType_TXT, kDNSServiceType_SRV, etc) |
---|
1244 | * |
---|
1245 | * rdlen: The length, in bytes, of the rdata. |
---|
1246 | * |
---|
1247 | * rdata: The raw rdata to be contained in the added resource record. |
---|
1248 | * |
---|
1249 | * ttl: The time to live of the resource record, in seconds. |
---|
1250 | * Most clients should pass 0 to indicate that the system should |
---|
1251 | * select a sensible default value. |
---|
1252 | * |
---|
1253 | * return value: Returns kDNSServiceErr_NoError on success, otherwise returns an |
---|
1254 | * error code indicating the error that occurred (the RecordRef is not initialized). |
---|
1255 | */ |
---|
1256 | |
---|
1257 | DNSServiceErrorType DNSSD_API DNSServiceAddRecord |
---|
1258 | ( |
---|
1259 | DNSServiceRef sdRef, |
---|
1260 | DNSRecordRef *RecordRef, |
---|
1261 | DNSServiceFlags flags, |
---|
1262 | uint16_t rrtype, |
---|
1263 | uint16_t rdlen, |
---|
1264 | const void *rdata, |
---|
1265 | uint32_t ttl |
---|
1266 | ); |
---|
1267 | |
---|
1268 | |
---|
1269 | /* DNSServiceUpdateRecord |
---|
1270 | * |
---|
1271 | * Update a registered resource record. The record must either be: |
---|
1272 | * - The primary txt record of a service registered via DNSServiceRegister() |
---|
1273 | * - A record added to a registered service via DNSServiceAddRecord() |
---|
1274 | * - An individual record registered by DNSServiceRegisterRecord() |
---|
1275 | * |
---|
1276 | * Parameters: |
---|
1277 | * |
---|
1278 | * sdRef: A DNSServiceRef that was initialized by DNSServiceRegister() |
---|
1279 | * or DNSServiceCreateConnection(). |
---|
1280 | * |
---|
1281 | * RecordRef: A DNSRecordRef initialized by DNSServiceAddRecord, or NULL to update the |
---|
1282 | * service's primary txt record. |
---|
1283 | * |
---|
1284 | * flags: Currently ignored, reserved for future use. |
---|
1285 | * |
---|
1286 | * rdlen: The length, in bytes, of the new rdata. |
---|
1287 | * |
---|
1288 | * rdata: The new rdata to be contained in the updated resource record. |
---|
1289 | * |
---|
1290 | * ttl: The time to live of the updated resource record, in seconds. |
---|
1291 | * Most clients should pass 0 to indicate that the system should |
---|
1292 | * select a sensible default value. |
---|
1293 | * |
---|
1294 | * return value: Returns kDNSServiceErr_NoError on success, otherwise returns an |
---|
1295 | * error code indicating the error that occurred. |
---|
1296 | */ |
---|
1297 | |
---|
1298 | DNSServiceErrorType DNSSD_API DNSServiceUpdateRecord |
---|
1299 | ( |
---|
1300 | DNSServiceRef sdRef, |
---|
1301 | DNSRecordRef RecordRef, /* may be NULL */ |
---|
1302 | DNSServiceFlags flags, |
---|
1303 | uint16_t rdlen, |
---|
1304 | const void *rdata, |
---|
1305 | uint32_t ttl |
---|
1306 | ); |
---|
1307 | |
---|
1308 | |
---|
1309 | /* DNSServiceRemoveRecord |
---|
1310 | * |
---|
1311 | * Remove a record previously added to a service record set via DNSServiceAddRecord(), or deregister |
---|
1312 | * an record registered individually via DNSServiceRegisterRecord(). |
---|
1313 | * |
---|
1314 | * Parameters: |
---|
1315 | * |
---|
1316 | * sdRef: A DNSServiceRef initialized by DNSServiceRegister() (if the |
---|
1317 | * record being removed was registered via DNSServiceAddRecord()) or by |
---|
1318 | * DNSServiceCreateConnection() (if the record being removed was registered via |
---|
1319 | * DNSServiceRegisterRecord()). |
---|
1320 | * |
---|
1321 | * recordRef: A DNSRecordRef initialized by a successful call to DNSServiceAddRecord() |
---|
1322 | * or DNSServiceRegisterRecord(). |
---|
1323 | * |
---|
1324 | * flags: Currently ignored, reserved for future use. |
---|
1325 | * |
---|
1326 | * return value: Returns kDNSServiceErr_NoError on success, otherwise returns an |
---|
1327 | * error code indicating the error that occurred. |
---|
1328 | */ |
---|
1329 | |
---|
1330 | DNSServiceErrorType DNSSD_API DNSServiceRemoveRecord |
---|
1331 | ( |
---|
1332 | DNSServiceRef sdRef, |
---|
1333 | DNSRecordRef RecordRef, |
---|
1334 | DNSServiceFlags flags |
---|
1335 | ); |
---|
1336 | |
---|
1337 | |
---|
1338 | /********************************************************************************************* |
---|
1339 | * |
---|
1340 | * Service Discovery |
---|
1341 | * |
---|
1342 | *********************************************************************************************/ |
---|
1343 | |
---|
1344 | /* Browse for instances of a service. |
---|
1345 | * |
---|
1346 | * DNSServiceBrowseReply() Parameters: |
---|
1347 | * |
---|
1348 | * sdRef: The DNSServiceRef initialized by DNSServiceBrowse(). |
---|
1349 | * |
---|
1350 | * flags: Possible values are kDNSServiceFlagsMoreComing and kDNSServiceFlagsAdd. |
---|
1351 | * See flag definitions for details. |
---|
1352 | * |
---|
1353 | * interfaceIndex: The interface on which the service is advertised. This index should |
---|
1354 | * be passed to DNSServiceResolve() when resolving the service. |
---|
1355 | * |
---|
1356 | * errorCode: Will be kDNSServiceErr_NoError (0) on success, otherwise will |
---|
1357 | * indicate the failure that occurred. Other parameters are undefined if |
---|
1358 | * the errorCode is nonzero. |
---|
1359 | * |
---|
1360 | * serviceName: The discovered service name. This name should be displayed to the user, |
---|
1361 | * and stored for subsequent use in the DNSServiceResolve() call. |
---|
1362 | * |
---|
1363 | * regtype: The service type, which is usually (but not always) the same as was passed |
---|
1364 | * to DNSServiceBrowse(). One case where the discovered service type may |
---|
1365 | * not be the same as the requested service type is when using subtypes: |
---|
1366 | * The client may want to browse for only those ftp servers that allow |
---|
1367 | * anonymous connections. The client will pass the string "_ftp._tcp,_anon" |
---|
1368 | * to DNSServiceBrowse(), but the type of the service that's discovered |
---|
1369 | * is simply "_ftp._tcp". The regtype for each discovered service instance |
---|
1370 | * should be stored along with the name, so that it can be passed to |
---|
1371 | * DNSServiceResolve() when the service is later resolved. |
---|
1372 | * |
---|
1373 | * domain: The domain of the discovered service instance. This may or may not be the |
---|
1374 | * same as the domain that was passed to DNSServiceBrowse(). The domain for each |
---|
1375 | * discovered service instance should be stored along with the name, so that |
---|
1376 | * it can be passed to DNSServiceResolve() when the service is later resolved. |
---|
1377 | * |
---|
1378 | * context: The context pointer that was passed to the callout. |
---|
1379 | * |
---|
1380 | */ |
---|
1381 | |
---|
1382 | typedef void (DNSSD_API *DNSServiceBrowseReply) |
---|
1383 | ( |
---|
1384 | DNSServiceRef sdRef, |
---|
1385 | DNSServiceFlags flags, |
---|
1386 | uint32_t interfaceIndex, |
---|
1387 | DNSServiceErrorType errorCode, |
---|
1388 | const char *serviceName, |
---|
1389 | const char *regtype, |
---|
1390 | const char *replyDomain, |
---|
1391 | void *context |
---|
1392 | ); |
---|
1393 | |
---|
1394 | |
---|
1395 | /* DNSServiceBrowse() Parameters: |
---|
1396 | * |
---|
1397 | * sdRef: A pointer to an uninitialized DNSServiceRef. If the call succeeds |
---|
1398 | * then it initializes the DNSServiceRef, returns kDNSServiceErr_NoError, |
---|
1399 | * and the browse operation will run indefinitely until the client |
---|
1400 | * terminates it by passing this DNSServiceRef to DNSServiceRefDeallocate(). |
---|
1401 | * |
---|
1402 | * flags: Currently ignored, reserved for future use. |
---|
1403 | * |
---|
1404 | * interfaceIndex: If non-zero, specifies the interface on which to browse for services |
---|
1405 | * (the index for a given interface is determined via the if_nametoindex() |
---|
1406 | * family of calls.) Most applications will pass 0 to browse on all available |
---|
1407 | * interfaces. See "Constants for specifying an interface index" for more details. |
---|
1408 | * |
---|
1409 | * regtype: The service type being browsed for followed by the protocol, separated by a |
---|
1410 | * dot (e.g. "_ftp._tcp"). The transport protocol must be "_tcp" or "_udp". |
---|
1411 | * A client may optionally specify a single subtype to perform filtered browsing: |
---|
1412 | * e.g. browsing for "_primarytype._tcp,_subtype" will discover only those |
---|
1413 | * instances of "_primarytype._tcp" that were registered specifying "_subtype" |
---|
1414 | * in their list of registered subtypes. Additionally, a group identifier may |
---|
1415 | * also be specified before the subtype e.g., _primarytype._tcp:GroupID, which |
---|
1416 | * will discover only the members that register the service with GroupID. See |
---|
1417 | * DNSServiceRegister for more details. |
---|
1418 | * |
---|
1419 | * domain: If non-NULL, specifies the domain on which to browse for services. |
---|
1420 | * Most applications will not specify a domain, instead browsing on the |
---|
1421 | * default domain(s). |
---|
1422 | * |
---|
1423 | * callBack: The function to be called when an instance of the service being browsed for |
---|
1424 | * is found, or if the call asynchronously fails. |
---|
1425 | * |
---|
1426 | * context: An application context pointer which is passed to the callback function |
---|
1427 | * (may be NULL). |
---|
1428 | * |
---|
1429 | * return value: Returns kDNSServiceErr_NoError on success (any subsequent, asynchronous |
---|
1430 | * errors are delivered to the callback), otherwise returns an error code indicating |
---|
1431 | * the error that occurred (the callback is not invoked and the DNSServiceRef |
---|
1432 | * is not initialized). |
---|
1433 | */ |
---|
1434 | |
---|
1435 | DNSServiceErrorType DNSSD_API DNSServiceBrowse |
---|
1436 | ( |
---|
1437 | DNSServiceRef *sdRef, |
---|
1438 | DNSServiceFlags flags, |
---|
1439 | uint32_t interfaceIndex, |
---|
1440 | const char *regtype, |
---|
1441 | const char *domain, /* may be NULL */ |
---|
1442 | DNSServiceBrowseReply callBack, |
---|
1443 | void *context /* may be NULL */ |
---|
1444 | ); |
---|
1445 | |
---|
1446 | |
---|
1447 | /* DNSServiceResolve() |
---|
1448 | * |
---|
1449 | * Resolve a service name discovered via DNSServiceBrowse() to a target host name, port number, and |
---|
1450 | * txt record. |
---|
1451 | * |
---|
1452 | * Note: Applications should NOT use DNSServiceResolve() solely for txt record monitoring - use |
---|
1453 | * DNSServiceQueryRecord() instead, as it is more efficient for this task. |
---|
1454 | * |
---|
1455 | * Note: When the desired results have been returned, the client MUST terminate the resolve by calling |
---|
1456 | * DNSServiceRefDeallocate(). |
---|
1457 | * |
---|
1458 | * Note: DNSServiceResolve() behaves correctly for typical services that have a single SRV record |
---|
1459 | * and a single TXT record. To resolve non-standard services with multiple SRV or TXT records, |
---|
1460 | * DNSServiceQueryRecord() should be used. |
---|
1461 | * |
---|
1462 | * DNSServiceResolveReply Callback Parameters: |
---|
1463 | * |
---|
1464 | * sdRef: The DNSServiceRef initialized by DNSServiceResolve(). |
---|
1465 | * |
---|
1466 | * flags: Possible values: kDNSServiceFlagsMoreComing |
---|
1467 | * |
---|
1468 | * interfaceIndex: The interface on which the service was resolved. |
---|
1469 | * |
---|
1470 | * errorCode: Will be kDNSServiceErr_NoError (0) on success, otherwise will |
---|
1471 | * indicate the failure that occurred. Other parameters are undefined if |
---|
1472 | * the errorCode is nonzero. |
---|
1473 | * |
---|
1474 | * fullname: The full service domain name, in the form <servicename>.<protocol>.<domain>. |
---|
1475 | * (This name is escaped following standard DNS rules, making it suitable for |
---|
1476 | * passing to standard system DNS APIs such as res_query(), or to the |
---|
1477 | * special-purpose functions included in this API that take fullname parameters. |
---|
1478 | * See "Notes on DNS Name Escaping" earlier in this file for more details.) |
---|
1479 | * |
---|
1480 | * hosttarget: The target hostname of the machine providing the service. This name can |
---|
1481 | * be passed to functions like gethostbyname() to identify the host's IP address. |
---|
1482 | * |
---|
1483 | * port: The port, in network byte order, on which connections are accepted for this service. |
---|
1484 | * |
---|
1485 | * txtLen: The length of the txt record, in bytes. |
---|
1486 | * |
---|
1487 | * txtRecord: The service's primary txt record, in standard txt record format. |
---|
1488 | * |
---|
1489 | * context: The context pointer that was passed to the callout. |
---|
1490 | * |
---|
1491 | * NOTE: In earlier versions of this header file, the txtRecord parameter was declared "const char *" |
---|
1492 | * This is incorrect, since it contains length bytes which are values in the range 0 to 255, not -128 to +127. |
---|
1493 | * Depending on your compiler settings, this change may cause signed/unsigned mismatch warnings. |
---|
1494 | * These should be fixed by updating your own callback function definition to match the corrected |
---|
1495 | * function signature using "const unsigned char *txtRecord". Making this change may also fix inadvertent |
---|
1496 | * bugs in your callback function, where it could have incorrectly interpreted a length byte with value 250 |
---|
1497 | * as being -6 instead, with various bad consequences ranging from incorrect operation to software crashes. |
---|
1498 | * If you need to maintain portable code that will compile cleanly with both the old and new versions of |
---|
1499 | * this header file, you should update your callback function definition to use the correct unsigned value, |
---|
1500 | * and then in the place where you pass your callback function to DNSServiceResolve(), use a cast to eliminate |
---|
1501 | * the compiler warning, e.g.: |
---|
1502 | * DNSServiceResolve(sd, flags, index, name, regtype, domain, (DNSServiceResolveReply)MyCallback, context); |
---|
1503 | * This will ensure that your code compiles cleanly without warnings (and more importantly, works correctly) |
---|
1504 | * with both the old header and with the new corrected version. |
---|
1505 | * |
---|
1506 | */ |
---|
1507 | |
---|
1508 | typedef void (DNSSD_API *DNSServiceResolveReply) |
---|
1509 | ( |
---|
1510 | DNSServiceRef sdRef, |
---|
1511 | DNSServiceFlags flags, |
---|
1512 | uint32_t interfaceIndex, |
---|
1513 | DNSServiceErrorType errorCode, |
---|
1514 | const char *fullname, |
---|
1515 | const char *hosttarget, |
---|
1516 | uint16_t port, /* In network byte order */ |
---|
1517 | uint16_t txtLen, |
---|
1518 | const unsigned char *txtRecord, |
---|
1519 | void *context |
---|
1520 | ); |
---|
1521 | |
---|
1522 | |
---|
1523 | /* DNSServiceResolve() Parameters |
---|
1524 | * |
---|
1525 | * sdRef: A pointer to an uninitialized DNSServiceRef. If the call succeeds |
---|
1526 | * then it initializes the DNSServiceRef, returns kDNSServiceErr_NoError, |
---|
1527 | * and the resolve operation will run indefinitely until the client |
---|
1528 | * terminates it by passing this DNSServiceRef to DNSServiceRefDeallocate(). |
---|
1529 | * |
---|
1530 | * flags: Specifying kDNSServiceFlagsForceMulticast will cause query to be |
---|
1531 | * performed with a link-local mDNS query, even if the name is an |
---|
1532 | * apparently non-local name (i.e. a name not ending in ".local.") |
---|
1533 | * |
---|
1534 | * interfaceIndex: The interface on which to resolve the service. If this resolve call is |
---|
1535 | * as a result of a currently active DNSServiceBrowse() operation, then the |
---|
1536 | * interfaceIndex should be the index reported in the DNSServiceBrowseReply |
---|
1537 | * callback. If this resolve call is using information previously saved |
---|
1538 | * (e.g. in a preference file) for later use, then use interfaceIndex 0, because |
---|
1539 | * the desired service may now be reachable via a different physical interface. |
---|
1540 | * See "Constants for specifying an interface index" for more details. |
---|
1541 | * |
---|
1542 | * name: The name of the service instance to be resolved, as reported to the |
---|
1543 | * DNSServiceBrowseReply() callback. |
---|
1544 | * |
---|
1545 | * regtype: The type of the service instance to be resolved, as reported to the |
---|
1546 | * DNSServiceBrowseReply() callback. |
---|
1547 | * |
---|
1548 | * domain: The domain of the service instance to be resolved, as reported to the |
---|
1549 | * DNSServiceBrowseReply() callback. |
---|
1550 | * |
---|
1551 | * callBack: The function to be called when a result is found, or if the call |
---|
1552 | * asynchronously fails. |
---|
1553 | * |
---|
1554 | * context: An application context pointer which is passed to the callback function |
---|
1555 | * (may be NULL). |
---|
1556 | * |
---|
1557 | * return value: Returns kDNSServiceErr_NoError on success (any subsequent, asynchronous |
---|
1558 | * errors are delivered to the callback), otherwise returns an error code indicating |
---|
1559 | * the error that occurred (the callback is never invoked and the DNSServiceRef |
---|
1560 | * is not initialized). |
---|
1561 | */ |
---|
1562 | |
---|
1563 | DNSServiceErrorType DNSSD_API DNSServiceResolve |
---|
1564 | ( |
---|
1565 | DNSServiceRef *sdRef, |
---|
1566 | DNSServiceFlags flags, |
---|
1567 | uint32_t interfaceIndex, |
---|
1568 | const char *name, |
---|
1569 | const char *regtype, |
---|
1570 | const char *domain, |
---|
1571 | DNSServiceResolveReply callBack, |
---|
1572 | void *context /* may be NULL */ |
---|
1573 | ); |
---|
1574 | |
---|
1575 | |
---|
1576 | /********************************************************************************************* |
---|
1577 | * |
---|
1578 | * Querying Individual Specific Records |
---|
1579 | * |
---|
1580 | *********************************************************************************************/ |
---|
1581 | |
---|
1582 | /* DNSServiceQueryRecord |
---|
1583 | * |
---|
1584 | * Query for an arbitrary DNS record. |
---|
1585 | * |
---|
1586 | * DNSServiceQueryRecordReply() Callback Parameters: |
---|
1587 | * |
---|
1588 | * sdRef: The DNSServiceRef initialized by DNSServiceQueryRecord(). |
---|
1589 | * |
---|
1590 | * flags: Possible values are kDNSServiceFlagsMoreComing and |
---|
1591 | * kDNSServiceFlagsAdd. The Add flag is NOT set for PTR records |
---|
1592 | * with a ttl of 0, i.e. "Remove" events. |
---|
1593 | * |
---|
1594 | * interfaceIndex: The interface on which the query was resolved (the index for a given |
---|
1595 | * interface is determined via the if_nametoindex() family of calls). |
---|
1596 | * See "Constants for specifying an interface index" for more details. |
---|
1597 | * |
---|
1598 | * errorCode: Will be kDNSServiceErr_NoError on success, otherwise will |
---|
1599 | * indicate the failure that occurred. Other parameters are undefined if |
---|
1600 | * errorCode is nonzero. |
---|
1601 | * |
---|
1602 | * fullname: The resource record's full domain name. |
---|
1603 | * |
---|
1604 | * rrtype: The resource record's type (e.g. kDNSServiceType_PTR, kDNSServiceType_SRV, etc) |
---|
1605 | * |
---|
1606 | * rrclass: The class of the resource record (usually kDNSServiceClass_IN). |
---|
1607 | * |
---|
1608 | * rdlen: The length, in bytes, of the resource record rdata. |
---|
1609 | * |
---|
1610 | * rdata: The raw rdata of the resource record. |
---|
1611 | * |
---|
1612 | * ttl: If the client wishes to cache the result for performance reasons, |
---|
1613 | * the TTL indicates how long the client may legitimately hold onto |
---|
1614 | * this result, in seconds. After the TTL expires, the client should |
---|
1615 | * consider the result no longer valid, and if it requires this data |
---|
1616 | * again, it should be re-fetched with a new query. Of course, this |
---|
1617 | * only applies to clients that cancel the asynchronous operation when |
---|
1618 | * they get a result. Clients that leave the asynchronous operation |
---|
1619 | * running can safely assume that the data remains valid until they |
---|
1620 | * get another callback telling them otherwise. |
---|
1621 | * |
---|
1622 | * context: The context pointer that was passed to the callout. |
---|
1623 | * |
---|
1624 | */ |
---|
1625 | |
---|
1626 | typedef void (DNSSD_API *DNSServiceQueryRecordReply) |
---|
1627 | ( |
---|
1628 | DNSServiceRef sdRef, |
---|
1629 | DNSServiceFlags flags, |
---|
1630 | uint32_t interfaceIndex, |
---|
1631 | DNSServiceErrorType errorCode, |
---|
1632 | const char *fullname, |
---|
1633 | uint16_t rrtype, |
---|
1634 | uint16_t rrclass, |
---|
1635 | uint16_t rdlen, |
---|
1636 | const void *rdata, |
---|
1637 | uint32_t ttl, |
---|
1638 | void *context |
---|
1639 | ); |
---|
1640 | |
---|
1641 | |
---|
1642 | /* DNSServiceQueryRecord() Parameters: |
---|
1643 | * |
---|
1644 | * sdRef: A pointer to an uninitialized DNSServiceRef. If the call succeeds |
---|
1645 | * then it initializes the DNSServiceRef, returns kDNSServiceErr_NoError, |
---|
1646 | * and the query operation will run indefinitely until the client |
---|
1647 | * terminates it by passing this DNSServiceRef to DNSServiceRefDeallocate(). |
---|
1648 | * |
---|
1649 | * flags: kDNSServiceFlagsForceMulticast or kDNSServiceFlagsLongLivedQuery. |
---|
1650 | * Pass kDNSServiceFlagsLongLivedQuery to create a "long-lived" unicast |
---|
1651 | * query to a unicast DNS server that implements the protocol. This flag |
---|
1652 | * has no effect on link-local multicast queries. |
---|
1653 | * |
---|
1654 | * interfaceIndex: If non-zero, specifies the interface on which to issue the query |
---|
1655 | * (the index for a given interface is determined via the if_nametoindex() |
---|
1656 | * family of calls.) Passing 0 causes the name to be queried for on all |
---|
1657 | * interfaces. See "Constants for specifying an interface index" for more details. |
---|
1658 | * |
---|
1659 | * fullname: The full domain name of the resource record to be queried for. |
---|
1660 | * |
---|
1661 | * rrtype: The numerical type of the resource record to be queried for |
---|
1662 | * (e.g. kDNSServiceType_PTR, kDNSServiceType_SRV, etc) |
---|
1663 | * |
---|
1664 | * rrclass: The class of the resource record (usually kDNSServiceClass_IN). |
---|
1665 | * |
---|
1666 | * callBack: The function to be called when a result is found, or if the call |
---|
1667 | * asynchronously fails. |
---|
1668 | * |
---|
1669 | * context: An application context pointer which is passed to the callback function |
---|
1670 | * (may be NULL). |
---|
1671 | * |
---|
1672 | * return value: Returns kDNSServiceErr_NoError on success (any subsequent, asynchronous |
---|
1673 | * errors are delivered to the callback), otherwise returns an error code indicating |
---|
1674 | * the error that occurred (the callback is never invoked and the DNSServiceRef |
---|
1675 | * is not initialized). |
---|
1676 | */ |
---|
1677 | |
---|
1678 | DNSServiceErrorType DNSSD_API DNSServiceQueryRecord |
---|
1679 | ( |
---|
1680 | DNSServiceRef *sdRef, |
---|
1681 | DNSServiceFlags flags, |
---|
1682 | uint32_t interfaceIndex, |
---|
1683 | const char *fullname, |
---|
1684 | uint16_t rrtype, |
---|
1685 | uint16_t rrclass, |
---|
1686 | DNSServiceQueryRecordReply callBack, |
---|
1687 | void *context /* may be NULL */ |
---|
1688 | ); |
---|
1689 | |
---|
1690 | |
---|
1691 | /********************************************************************************************* |
---|
1692 | * |
---|
1693 | * Unified lookup of both IPv4 and IPv6 addresses for a fully qualified hostname |
---|
1694 | * |
---|
1695 | *********************************************************************************************/ |
---|
1696 | |
---|
1697 | /* DNSServiceGetAddrInfo |
---|
1698 | * |
---|
1699 | * Queries for the IP address of a hostname by using either Multicast or Unicast DNS. |
---|
1700 | * |
---|
1701 | * DNSServiceGetAddrInfoReply() parameters: |
---|
1702 | * |
---|
1703 | * sdRef: The DNSServiceRef initialized by DNSServiceGetAddrInfo(). |
---|
1704 | * |
---|
1705 | * flags: Possible values are kDNSServiceFlagsMoreComing and |
---|
1706 | * kDNSServiceFlagsAdd. |
---|
1707 | * |
---|
1708 | * interfaceIndex: The interface to which the answers pertain. |
---|
1709 | * |
---|
1710 | * errorCode: Will be kDNSServiceErr_NoError on success, otherwise will |
---|
1711 | * indicate the failure that occurred. Other parameters are |
---|
1712 | * undefined if errorCode is nonzero. |
---|
1713 | * |
---|
1714 | * hostname: The fully qualified domain name of the host to be queried for. |
---|
1715 | * |
---|
1716 | * address: IPv4 or IPv6 address. |
---|
1717 | * |
---|
1718 | * ttl: If the client wishes to cache the result for performance reasons, |
---|
1719 | * the TTL indicates how long the client may legitimately hold onto |
---|
1720 | * this result, in seconds. After the TTL expires, the client should |
---|
1721 | * consider the result no longer valid, and if it requires this data |
---|
1722 | * again, it should be re-fetched with a new query. Of course, this |
---|
1723 | * only applies to clients that cancel the asynchronous operation when |
---|
1724 | * they get a result. Clients that leave the asynchronous operation |
---|
1725 | * running can safely assume that the data remains valid until they |
---|
1726 | * get another callback telling them otherwise. |
---|
1727 | * |
---|
1728 | * context: The context pointer that was passed to the callout. |
---|
1729 | * |
---|
1730 | */ |
---|
1731 | |
---|
1732 | typedef void (DNSSD_API *DNSServiceGetAddrInfoReply) |
---|
1733 | ( |
---|
1734 | DNSServiceRef sdRef, |
---|
1735 | DNSServiceFlags flags, |
---|
1736 | uint32_t interfaceIndex, |
---|
1737 | DNSServiceErrorType errorCode, |
---|
1738 | const char *hostname, |
---|
1739 | const struct sockaddr *address, |
---|
1740 | uint32_t ttl, |
---|
1741 | void *context |
---|
1742 | ); |
---|
1743 | |
---|
1744 | |
---|
1745 | /* DNSServiceGetAddrInfo() Parameters: |
---|
1746 | * |
---|
1747 | * sdRef: A pointer to an uninitialized DNSServiceRef. If the call succeeds then it |
---|
1748 | * initializes the DNSServiceRef, returns kDNSServiceErr_NoError, and the query |
---|
1749 | * begins and will last indefinitely until the client terminates the query |
---|
1750 | * by passing this DNSServiceRef to DNSServiceRefDeallocate(). |
---|
1751 | * |
---|
1752 | * flags: kDNSServiceFlagsForceMulticast or kDNSServiceFlagsLongLivedQuery. |
---|
1753 | * Pass kDNSServiceFlagsLongLivedQuery to create a "long-lived" unicast |
---|
1754 | * query to a unicast DNS server that implements the protocol. This flag |
---|
1755 | * has no effect on link-local multicast queries. |
---|
1756 | * |
---|
1757 | * interfaceIndex: The interface on which to issue the query. Passing 0 causes the query to be |
---|
1758 | * sent on all active interfaces via Multicast or the primary interface via Unicast. |
---|
1759 | * |
---|
1760 | * protocol: Pass in kDNSServiceProtocol_IPv4 to look up IPv4 addresses, or kDNSServiceProtocol_IPv6 |
---|
1761 | * to look up IPv6 addresses, or both to look up both kinds. If neither flag is |
---|
1762 | * set, the system will apply an intelligent heuristic, which is (currently) |
---|
1763 | * that it will attempt to look up both, except: |
---|
1764 | * |
---|
1765 | * * If "hostname" is a wide-area unicast DNS hostname (i.e. not a ".local." name) |
---|
1766 | * but this host has no routable IPv6 address, then the call will not try to |
---|
1767 | * look up IPv6 addresses for "hostname", since any addresses it found would be |
---|
1768 | * unlikely to be of any use anyway. Similarly, if this host has no routable |
---|
1769 | * IPv4 address, the call will not try to look up IPv4 addresses for "hostname". |
---|
1770 | * |
---|
1771 | * hostname: The fully qualified domain name of the host to be queried for. |
---|
1772 | * |
---|
1773 | * callBack: The function to be called when the query succeeds or fails asynchronously. |
---|
1774 | * |
---|
1775 | * context: An application context pointer which is passed to the callback function |
---|
1776 | * (may be NULL). |
---|
1777 | * |
---|
1778 | * return value: Returns kDNSServiceErr_NoError on success (any subsequent, asynchronous |
---|
1779 | * errors are delivered to the callback), otherwise returns an error code indicating |
---|
1780 | * the error that occurred. |
---|
1781 | */ |
---|
1782 | |
---|
1783 | DNSServiceErrorType DNSSD_API DNSServiceGetAddrInfo |
---|
1784 | ( |
---|
1785 | DNSServiceRef *sdRef, |
---|
1786 | DNSServiceFlags flags, |
---|
1787 | uint32_t interfaceIndex, |
---|
1788 | DNSServiceProtocol protocol, |
---|
1789 | const char *hostname, |
---|
1790 | DNSServiceGetAddrInfoReply callBack, |
---|
1791 | void *context /* may be NULL */ |
---|
1792 | ); |
---|
1793 | |
---|
1794 | |
---|
1795 | /********************************************************************************************* |
---|
1796 | * |
---|
1797 | * Special Purpose Calls: |
---|
1798 | * DNSServiceCreateConnection(), DNSServiceRegisterRecord(), DNSServiceReconfirmRecord() |
---|
1799 | * (most applications will not use these) |
---|
1800 | * |
---|
1801 | *********************************************************************************************/ |
---|
1802 | |
---|
1803 | /* DNSServiceCreateConnection() |
---|
1804 | * |
---|
1805 | * Create a connection to the daemon allowing efficient registration of |
---|
1806 | * multiple individual records. |
---|
1807 | * |
---|
1808 | * Parameters: |
---|
1809 | * |
---|
1810 | * sdRef: A pointer to an uninitialized DNSServiceRef. Deallocating |
---|
1811 | * the reference (via DNSServiceRefDeallocate()) severs the |
---|
1812 | * connection and deregisters all records registered on this connection. |
---|
1813 | * |
---|
1814 | * return value: Returns kDNSServiceErr_NoError on success, otherwise returns |
---|
1815 | * an error code indicating the specific failure that occurred (in which |
---|
1816 | * case the DNSServiceRef is not initialized). |
---|
1817 | */ |
---|
1818 | |
---|
1819 | DNSServiceErrorType DNSSD_API DNSServiceCreateConnection(DNSServiceRef *sdRef); |
---|
1820 | |
---|
1821 | /* DNSServiceRegisterRecord |
---|
1822 | * |
---|
1823 | * Register an individual resource record on a connected DNSServiceRef. |
---|
1824 | * |
---|
1825 | * Note that name conflicts occurring for records registered via this call must be handled |
---|
1826 | * by the client in the callback. |
---|
1827 | * |
---|
1828 | * DNSServiceRegisterRecordReply() parameters: |
---|
1829 | * |
---|
1830 | * sdRef: The connected DNSServiceRef initialized by |
---|
1831 | * DNSServiceCreateConnection(). |
---|
1832 | * |
---|
1833 | * RecordRef: The DNSRecordRef initialized by DNSServiceRegisterRecord(). If the above |
---|
1834 | * DNSServiceRef is passed to DNSServiceRefDeallocate(), this DNSRecordRef is |
---|
1835 | * invalidated, and may not be used further. |
---|
1836 | * |
---|
1837 | * flags: Currently unused, reserved for future use. |
---|
1838 | * |
---|
1839 | * errorCode: Will be kDNSServiceErr_NoError on success, otherwise will |
---|
1840 | * indicate the failure that occurred (including name conflicts.) |
---|
1841 | * Other parameters are undefined if errorCode is nonzero. |
---|
1842 | * |
---|
1843 | * context: The context pointer that was passed to the callout. |
---|
1844 | * |
---|
1845 | */ |
---|
1846 | |
---|
1847 | typedef void (DNSSD_API *DNSServiceRegisterRecordReply) |
---|
1848 | ( |
---|
1849 | DNSServiceRef sdRef, |
---|
1850 | DNSRecordRef RecordRef, |
---|
1851 | DNSServiceFlags flags, |
---|
1852 | DNSServiceErrorType errorCode, |
---|
1853 | void *context |
---|
1854 | ); |
---|
1855 | |
---|
1856 | |
---|
1857 | /* DNSServiceRegisterRecord() Parameters: |
---|
1858 | * |
---|
1859 | * sdRef: A DNSServiceRef initialized by DNSServiceCreateConnection(). |
---|
1860 | * |
---|
1861 | * RecordRef: A pointer to an uninitialized DNSRecordRef. Upon succesfull completion of this |
---|
1862 | * call, this ref may be passed to DNSServiceUpdateRecord() or DNSServiceRemoveRecord(). |
---|
1863 | * (To deregister ALL records registered on a single connected DNSServiceRef |
---|
1864 | * and deallocate each of their corresponding DNSServiceRecordRefs, call |
---|
1865 | * DNSServiceRefDeallocate()). |
---|
1866 | * |
---|
1867 | * flags: Possible values are kDNSServiceFlagsShared or kDNSServiceFlagsUnique |
---|
1868 | * (see flag type definitions for details). |
---|
1869 | * |
---|
1870 | * interfaceIndex: If non-zero, specifies the interface on which to register the record |
---|
1871 | * (the index for a given interface is determined via the if_nametoindex() |
---|
1872 | * family of calls.) Passing 0 causes the record to be registered on all interfaces. |
---|
1873 | * See "Constants for specifying an interface index" for more details. |
---|
1874 | * |
---|
1875 | * fullname: The full domain name of the resource record. |
---|
1876 | * |
---|
1877 | * rrtype: The numerical type of the resource record (e.g. kDNSServiceType_PTR, kDNSServiceType_SRV, etc) |
---|
1878 | * |
---|
1879 | * rrclass: The class of the resource record (usually kDNSServiceClass_IN) |
---|
1880 | * |
---|
1881 | * rdlen: Length, in bytes, of the rdata. |
---|
1882 | * |
---|
1883 | * rdata: A pointer to the raw rdata, as it is to appear in the DNS record. |
---|
1884 | * |
---|
1885 | * ttl: The time to live of the resource record, in seconds. |
---|
1886 | * Most clients should pass 0 to indicate that the system should |
---|
1887 | * select a sensible default value. |
---|
1888 | * |
---|
1889 | * callBack: The function to be called when a result is found, or if the call |
---|
1890 | * asynchronously fails (e.g. because of a name conflict.) |
---|
1891 | * |
---|
1892 | * context: An application context pointer which is passed to the callback function |
---|
1893 | * (may be NULL). |
---|
1894 | * |
---|
1895 | * return value: Returns kDNSServiceErr_NoError on success (any subsequent, asynchronous |
---|
1896 | * errors are delivered to the callback), otherwise returns an error code indicating |
---|
1897 | * the error that occurred (the callback is never invoked and the DNSRecordRef is |
---|
1898 | * not initialized). |
---|
1899 | */ |
---|
1900 | |
---|
1901 | DNSServiceErrorType DNSSD_API DNSServiceRegisterRecord |
---|
1902 | ( |
---|
1903 | DNSServiceRef sdRef, |
---|
1904 | DNSRecordRef *RecordRef, |
---|
1905 | DNSServiceFlags flags, |
---|
1906 | uint32_t interfaceIndex, |
---|
1907 | const char *fullname, |
---|
1908 | uint16_t rrtype, |
---|
1909 | uint16_t rrclass, |
---|
1910 | uint16_t rdlen, |
---|
1911 | const void *rdata, |
---|
1912 | uint32_t ttl, |
---|
1913 | DNSServiceRegisterRecordReply callBack, |
---|
1914 | void *context /* may be NULL */ |
---|
1915 | ); |
---|
1916 | |
---|
1917 | |
---|
1918 | /* DNSServiceReconfirmRecord |
---|
1919 | * |
---|
1920 | * Instruct the daemon to verify the validity of a resource record that appears |
---|
1921 | * to be out of date (e.g. because TCP connection to a service's target failed.) |
---|
1922 | * Causes the record to be flushed from the daemon's cache (as well as all other |
---|
1923 | * daemons' caches on the network) if the record is determined to be invalid. |
---|
1924 | * Use this routine conservatively. Reconfirming a record necessarily consumes |
---|
1925 | * network bandwidth, so this should not be done indiscriminately. |
---|
1926 | * |
---|
1927 | * Parameters: |
---|
1928 | * |
---|
1929 | * flags: Not currently used. |
---|
1930 | * |
---|
1931 | * interfaceIndex: Specifies the interface of the record in question. |
---|
1932 | * The caller must specify the interface. |
---|
1933 | * This API (by design) causes increased network traffic, so it requires |
---|
1934 | * the caller to be precise about which record should be reconfirmed. |
---|
1935 | * It is not possible to pass zero for the interface index to perform |
---|
1936 | * a "wildcard" reconfirmation, where *all* matching records are reconfirmed. |
---|
1937 | * |
---|
1938 | * fullname: The resource record's full domain name. |
---|
1939 | * |
---|
1940 | * rrtype: The resource record's type (e.g. kDNSServiceType_PTR, kDNSServiceType_SRV, etc) |
---|
1941 | * |
---|
1942 | * rrclass: The class of the resource record (usually kDNSServiceClass_IN). |
---|
1943 | * |
---|
1944 | * rdlen: The length, in bytes, of the resource record rdata. |
---|
1945 | * |
---|
1946 | * rdata: The raw rdata of the resource record. |
---|
1947 | * |
---|
1948 | */ |
---|
1949 | |
---|
1950 | DNSServiceErrorType DNSSD_API DNSServiceReconfirmRecord |
---|
1951 | ( |
---|
1952 | DNSServiceFlags flags, |
---|
1953 | uint32_t interfaceIndex, |
---|
1954 | const char *fullname, |
---|
1955 | uint16_t rrtype, |
---|
1956 | uint16_t rrclass, |
---|
1957 | uint16_t rdlen, |
---|
1958 | const void *rdata |
---|
1959 | ); |
---|
1960 | |
---|
1961 | |
---|
1962 | /********************************************************************************************* |
---|
1963 | * |
---|
1964 | * NAT Port Mapping |
---|
1965 | * |
---|
1966 | *********************************************************************************************/ |
---|
1967 | |
---|
1968 | /* DNSServiceNATPortMappingCreate |
---|
1969 | * |
---|
1970 | * Request a port mapping in the NAT gateway, which maps a port on the local machine |
---|
1971 | * to an external port on the NAT. The NAT should support either PCP, NAT-PMP or the |
---|
1972 | * UPnP/IGD protocol for this API to create a successful mapping. Note that this API |
---|
1973 | * currently supports IPv4 addresses/mappings only. If the NAT gateway supports PCP and |
---|
1974 | * returns an IPv6 address (incorrectly, since this API specifically requests IPv4 |
---|
1975 | * addresses), the DNSServiceNATPortMappingReply callback will be invoked with errorCode |
---|
1976 | * kDNSServiceErr_NATPortMappingUnsupported. |
---|
1977 | * |
---|
1978 | * The port mapping will be renewed indefinitely until the client process exits, or |
---|
1979 | * explicitly terminates the port mapping request by calling DNSServiceRefDeallocate(). |
---|
1980 | * The client callback will be invoked, informing the client of the NAT gateway's |
---|
1981 | * external IP address and the external port that has been allocated for this client. |
---|
1982 | * The client should then record this external IP address and port using whatever |
---|
1983 | * directory service mechanism it is using to enable peers to connect to it. |
---|
1984 | * (Clients advertising services using Wide-Area DNS-SD DO NOT need to use this API |
---|
1985 | * -- when a client calls DNSServiceRegister() NAT mappings are automatically created |
---|
1986 | * and the external IP address and port for the service are recorded in the global DNS. |
---|
1987 | * Only clients using some directory mechanism other than Wide-Area DNS-SD need to use |
---|
1988 | * this API to explicitly map their own ports.) |
---|
1989 | * |
---|
1990 | * It's possible that the client callback could be called multiple times, for example |
---|
1991 | * if the NAT gateway's IP address changes, or if a configuration change results in a |
---|
1992 | * different external port being mapped for this client. Over the lifetime of any long-lived |
---|
1993 | * port mapping, the client should be prepared to handle these notifications of changes |
---|
1994 | * in the environment, and should update its recorded address and/or port as appropriate. |
---|
1995 | * |
---|
1996 | * NOTE: There are two unusual aspects of how the DNSServiceNATPortMappingCreate API works, |
---|
1997 | * which were intentionally designed to help simplify client code: |
---|
1998 | * |
---|
1999 | * 1. It's not an error to request a NAT mapping when the machine is not behind a NAT gateway. |
---|
2000 | * In other NAT mapping APIs, if you request a NAT mapping and the machine is not behind a NAT |
---|
2001 | * gateway, then the API returns an error code -- it can't get you a NAT mapping if there's no |
---|
2002 | * NAT gateway. The DNSServiceNATPortMappingCreate API takes a different view. Working out |
---|
2003 | * whether or not you need a NAT mapping can be tricky and non-obvious, particularly on |
---|
2004 | * a machine with multiple active network interfaces. Rather than make every client recreate |
---|
2005 | * this logic for deciding whether a NAT mapping is required, the PortMapping API does that |
---|
2006 | * work for you. If the client calls the PortMapping API when the machine already has a |
---|
2007 | * routable public IP address, then instead of complaining about it and giving an error, |
---|
2008 | * the PortMapping API just invokes your callback, giving the machine's public address |
---|
2009 | * and your own port number. This means you don't need to write code to work out whether |
---|
2010 | * your client needs to call the PortMapping API -- just call it anyway, and if it wasn't |
---|
2011 | * necessary, no harm is done: |
---|
2012 | * |
---|
2013 | * - If the machine already has a routable public IP address, then your callback |
---|
2014 | * will just be invoked giving your own address and port. |
---|
2015 | * - If a NAT mapping is required and obtained, then your callback will be invoked |
---|
2016 | * giving you the external address and port. |
---|
2017 | * - If a NAT mapping is required but not obtained from the local NAT gateway, |
---|
2018 | * or the machine has no network connectivity, then your callback will be |
---|
2019 | * invoked giving zero address and port. |
---|
2020 | * |
---|
2021 | * 2. In other NAT mapping APIs, if a laptop computer is put to sleep and woken up on a new |
---|
2022 | * network, it's the client's job to notice this, and work out whether a NAT mapping |
---|
2023 | * is required on the new network, and make a new NAT mapping request if necessary. |
---|
2024 | * The DNSServiceNATPortMappingCreate API does this for you, automatically. |
---|
2025 | * The client just needs to make one call to the PortMapping API, and its callback will |
---|
2026 | * be invoked any time the mapping state changes. This property complements point (1) above. |
---|
2027 | * If the client didn't make a NAT mapping request just because it determined that one was |
---|
2028 | * not required at that particular moment in time, the client would then have to monitor |
---|
2029 | * for network state changes to determine if a NAT port mapping later became necessary. |
---|
2030 | * By unconditionally making a NAT mapping request, even when a NAT mapping not to be |
---|
2031 | * necessary, the PortMapping API will then begin monitoring network state changes on behalf of |
---|
2032 | * the client, and if a NAT mapping later becomes necessary, it will automatically create a NAT |
---|
2033 | * mapping and inform the client with a new callback giving the new address and port information. |
---|
2034 | * |
---|
2035 | * DNSServiceNATPortMappingReply() parameters: |
---|
2036 | * |
---|
2037 | * sdRef: The DNSServiceRef initialized by DNSServiceNATPortMappingCreate(). |
---|
2038 | * |
---|
2039 | * flags: Currently unused, reserved for future use. |
---|
2040 | * |
---|
2041 | * interfaceIndex: The interface through which the NAT gateway is reached. |
---|
2042 | * |
---|
2043 | * errorCode: Will be kDNSServiceErr_NoError on success. |
---|
2044 | * Will be kDNSServiceErr_DoubleNAT when the NAT gateway is itself behind one or |
---|
2045 | * more layers of NAT, in which case the other parameters have the defined values. |
---|
2046 | * For other failures, will indicate the failure that occurred, and the other |
---|
2047 | * parameters are undefined. |
---|
2048 | * |
---|
2049 | * externalAddress: Four byte IPv4 address in network byte order. |
---|
2050 | * |
---|
2051 | * protocol: Will be kDNSServiceProtocol_UDP or kDNSServiceProtocol_TCP or both. |
---|
2052 | * |
---|
2053 | * internalPort: The port on the local machine that was mapped. |
---|
2054 | * |
---|
2055 | * externalPort: The actual external port in the NAT gateway that was mapped. |
---|
2056 | * This is likely to be different than the requested external port. |
---|
2057 | * |
---|
2058 | * ttl: The lifetime of the NAT port mapping created on the gateway. |
---|
2059 | * This controls how quickly stale mappings will be garbage-collected |
---|
2060 | * if the client machine crashes, suffers a power failure, is disconnected |
---|
2061 | * from the network, or suffers some other unfortunate demise which |
---|
2062 | * causes it to vanish without explicitly removing its NAT port mapping. |
---|
2063 | * It's possible that the ttl value will differ from the requested ttl value. |
---|
2064 | * |
---|
2065 | * context: The context pointer that was passed to the callout. |
---|
2066 | * |
---|
2067 | */ |
---|
2068 | |
---|
2069 | typedef void (DNSSD_API *DNSServiceNATPortMappingReply) |
---|
2070 | ( |
---|
2071 | DNSServiceRef sdRef, |
---|
2072 | DNSServiceFlags flags, |
---|
2073 | uint32_t interfaceIndex, |
---|
2074 | DNSServiceErrorType errorCode, |
---|
2075 | uint32_t externalAddress, /* four byte IPv4 address in network byte order */ |
---|
2076 | DNSServiceProtocol protocol, |
---|
2077 | uint16_t internalPort, /* In network byte order */ |
---|
2078 | uint16_t externalPort, /* In network byte order and may be different than the requested port */ |
---|
2079 | uint32_t ttl, /* may be different than the requested ttl */ |
---|
2080 | void *context |
---|
2081 | ); |
---|
2082 | |
---|
2083 | |
---|
2084 | /* DNSServiceNATPortMappingCreate() Parameters: |
---|
2085 | * |
---|
2086 | * sdRef: A pointer to an uninitialized DNSServiceRef. If the call succeeds then it |
---|
2087 | * initializes the DNSServiceRef, returns kDNSServiceErr_NoError, and the nat |
---|
2088 | * port mapping will last indefinitely until the client terminates the port |
---|
2089 | * mapping request by passing this DNSServiceRef to DNSServiceRefDeallocate(). |
---|
2090 | * |
---|
2091 | * flags: Currently ignored, reserved for future use. |
---|
2092 | * |
---|
2093 | * interfaceIndex: The interface on which to create port mappings in a NAT gateway. Passing 0 causes |
---|
2094 | * the port mapping request to be sent on the primary interface. |
---|
2095 | * |
---|
2096 | * protocol: To request a port mapping, pass in kDNSServiceProtocol_UDP, or kDNSServiceProtocol_TCP, |
---|
2097 | * or (kDNSServiceProtocol_UDP | kDNSServiceProtocol_TCP) to map both. |
---|
2098 | * The local listening port number must also be specified in the internalPort parameter. |
---|
2099 | * To just discover the NAT gateway's external IP address, pass zero for protocol, |
---|
2100 | * internalPort, externalPort and ttl. |
---|
2101 | * |
---|
2102 | * internalPort: The port number in network byte order on the local machine which is listening for packets. |
---|
2103 | * |
---|
2104 | * externalPort: The requested external port in network byte order in the NAT gateway that you would |
---|
2105 | * like to map to the internal port. Pass 0 if you don't care which external port is chosen for you. |
---|
2106 | * |
---|
2107 | * ttl: The requested renewal period of the NAT port mapping, in seconds. |
---|
2108 | * If the client machine crashes, suffers a power failure, is disconnected from |
---|
2109 | * the network, or suffers some other unfortunate demise which causes it to vanish |
---|
2110 | * unexpectedly without explicitly removing its NAT port mappings, then the NAT gateway |
---|
2111 | * will garbage-collect old stale NAT port mappings when their lifetime expires. |
---|
2112 | * Requesting a short TTL causes such orphaned mappings to be garbage-collected |
---|
2113 | * more promptly, but consumes system resources and network bandwidth with |
---|
2114 | * frequent renewal packets to keep the mapping from expiring. |
---|
2115 | * Requesting a long TTL is more efficient on the network, but in the event of the |
---|
2116 | * client vanishing, stale NAT port mappings will not be garbage-collected as quickly. |
---|
2117 | * Most clients should pass 0 to use a system-wide default value. |
---|
2118 | * |
---|
2119 | * callBack: The function to be called when the port mapping request succeeds or fails asynchronously. |
---|
2120 | * |
---|
2121 | * context: An application context pointer which is passed to the callback function |
---|
2122 | * (may be NULL). |
---|
2123 | * |
---|
2124 | * return value: Returns kDNSServiceErr_NoError on success (any subsequent, asynchronous |
---|
2125 | * errors are delivered to the callback), otherwise returns an error code indicating |
---|
2126 | * the error that occurred. |
---|
2127 | * |
---|
2128 | * If you don't actually want a port mapped, and are just calling the API |
---|
2129 | * because you want to find out the NAT's external IP address (e.g. for UI |
---|
2130 | * display) then pass zero for protocol, internalPort, externalPort and ttl. |
---|
2131 | */ |
---|
2132 | |
---|
2133 | DNSServiceErrorType DNSSD_API DNSServiceNATPortMappingCreate |
---|
2134 | ( |
---|
2135 | DNSServiceRef *sdRef, |
---|
2136 | DNSServiceFlags flags, |
---|
2137 | uint32_t interfaceIndex, |
---|
2138 | DNSServiceProtocol protocol, /* TCP and/or UDP */ |
---|
2139 | uint16_t internalPort, /* network byte order */ |
---|
2140 | uint16_t externalPort, /* network byte order */ |
---|
2141 | uint32_t ttl, /* time to live in seconds */ |
---|
2142 | DNSServiceNATPortMappingReply callBack, |
---|
2143 | void *context /* may be NULL */ |
---|
2144 | ); |
---|
2145 | |
---|
2146 | |
---|
2147 | /********************************************************************************************* |
---|
2148 | * |
---|
2149 | * General Utility Functions |
---|
2150 | * |
---|
2151 | *********************************************************************************************/ |
---|
2152 | |
---|
2153 | /* DNSServiceConstructFullName() |
---|
2154 | * |
---|
2155 | * Concatenate a three-part domain name (as returned by the above callbacks) into a |
---|
2156 | * properly-escaped full domain name. Note that callbacks in the above functions ALREADY ESCAPE |
---|
2157 | * strings where necessary. |
---|
2158 | * |
---|
2159 | * Parameters: |
---|
2160 | * |
---|
2161 | * fullName: A pointer to a buffer that where the resulting full domain name is to be written. |
---|
2162 | * The buffer must be kDNSServiceMaxDomainName (1009) bytes in length to |
---|
2163 | * accommodate the longest legal domain name without buffer overrun. |
---|
2164 | * |
---|
2165 | * service: The service name - any dots or backslashes must NOT be escaped. |
---|
2166 | * May be NULL (to construct a PTR record name, e.g. |
---|
2167 | * "_ftp._tcp.apple.com."). |
---|
2168 | * |
---|
2169 | * regtype: The service type followed by the protocol, separated by a dot |
---|
2170 | * (e.g. "_ftp._tcp"). |
---|
2171 | * |
---|
2172 | * domain: The domain name, e.g. "apple.com.". Literal dots or backslashes, |
---|
2173 | * if any, must be escaped, e.g. "1st\. Floor.apple.com." |
---|
2174 | * |
---|
2175 | * return value: Returns kDNSServiceErr_NoError (0) on success, kDNSServiceErr_BadParam on error. |
---|
2176 | * |
---|
2177 | */ |
---|
2178 | |
---|
2179 | DNSServiceErrorType DNSSD_API DNSServiceConstructFullName |
---|
2180 | ( |
---|
2181 | char * const fullName, |
---|
2182 | const char * const service, /* may be NULL */ |
---|
2183 | const char * const regtype, |
---|
2184 | const char * const domain |
---|
2185 | ); |
---|
2186 | |
---|
2187 | |
---|
2188 | /********************************************************************************************* |
---|
2189 | * |
---|
2190 | * TXT Record Construction Functions |
---|
2191 | * |
---|
2192 | *********************************************************************************************/ |
---|
2193 | |
---|
2194 | /* |
---|
2195 | * A typical calling sequence for TXT record construction is something like: |
---|
2196 | * |
---|
2197 | * Client allocates storage for TXTRecord data (e.g. declare buffer on the stack) |
---|
2198 | * TXTRecordCreate(); |
---|
2199 | * TXTRecordSetValue(); |
---|
2200 | * TXTRecordSetValue(); |
---|
2201 | * TXTRecordSetValue(); |
---|
2202 | * ... |
---|
2203 | * DNSServiceRegister( ... TXTRecordGetLength(), TXTRecordGetBytesPtr() ... ); |
---|
2204 | * TXTRecordDeallocate(); |
---|
2205 | * Explicitly deallocate storage for TXTRecord data (if not allocated on the stack) |
---|
2206 | */ |
---|
2207 | |
---|
2208 | |
---|
2209 | /* TXTRecordRef |
---|
2210 | * |
---|
2211 | * Opaque internal data type. |
---|
2212 | * Note: Represents a DNS-SD TXT record. |
---|
2213 | */ |
---|
2214 | |
---|
2215 | typedef union _TXTRecordRef_t { char PrivateData[16]; char *ForceNaturalAlignment; } TXTRecordRef; |
---|
2216 | |
---|
2217 | |
---|
2218 | /* TXTRecordCreate() |
---|
2219 | * |
---|
2220 | * Creates a new empty TXTRecordRef referencing the specified storage. |
---|
2221 | * |
---|
2222 | * If the buffer parameter is NULL, or the specified storage size is not |
---|
2223 | * large enough to hold a key subsequently added using TXTRecordSetValue(), |
---|
2224 | * then additional memory will be added as needed using malloc(). |
---|
2225 | * |
---|
2226 | * On some platforms, when memory is low, malloc() may fail. In this |
---|
2227 | * case, TXTRecordSetValue() will return kDNSServiceErr_NoMemory, and this |
---|
2228 | * error condition will need to be handled as appropriate by the caller. |
---|
2229 | * |
---|
2230 | * You can avoid the need to handle this error condition if you ensure |
---|
2231 | * that the storage you initially provide is large enough to hold all |
---|
2232 | * the key/value pairs that are to be added to the record. |
---|
2233 | * The caller can precompute the exact length required for all of the |
---|
2234 | * key/value pairs to be added, or simply provide a fixed-sized buffer |
---|
2235 | * known in advance to be large enough. |
---|
2236 | * A no-value (key-only) key requires (1 + key length) bytes. |
---|
2237 | * A key with empty value requires (1 + key length + 1) bytes. |
---|
2238 | * A key with non-empty value requires (1 + key length + 1 + value length). |
---|
2239 | * For most applications, DNS-SD TXT records are generally |
---|
2240 | * less than 100 bytes, so in most cases a simple fixed-sized |
---|
2241 | * 256-byte buffer will be more than sufficient. |
---|
2242 | * Recommended size limits for DNS-SD TXT Records are discussed in |
---|
2243 | * <http://files.dns-sd.org/draft-cheshire-dnsext-dns-sd.txt> |
---|
2244 | * |
---|
2245 | * Note: When passing parameters to and from these TXT record APIs, |
---|
2246 | * the key name does not include the '=' character. The '=' character |
---|
2247 | * is the separator between the key and value in the on-the-wire |
---|
2248 | * packet format; it is not part of either the key or the value. |
---|
2249 | * |
---|
2250 | * txtRecord: A pointer to an uninitialized TXTRecordRef. |
---|
2251 | * |
---|
2252 | * bufferLen: The size of the storage provided in the "buffer" parameter. |
---|
2253 | * |
---|
2254 | * buffer: Optional caller-supplied storage used to hold the TXTRecord data. |
---|
2255 | * This storage must remain valid for as long as |
---|
2256 | * the TXTRecordRef. |
---|
2257 | */ |
---|
2258 | |
---|
2259 | void DNSSD_API TXTRecordCreate |
---|
2260 | ( |
---|
2261 | TXTRecordRef *txtRecord, |
---|
2262 | uint16_t bufferLen, |
---|
2263 | void *buffer |
---|
2264 | ); |
---|
2265 | |
---|
2266 | |
---|
2267 | /* TXTRecordDeallocate() |
---|
2268 | * |
---|
2269 | * Releases any resources allocated in the course of preparing a TXT Record |
---|
2270 | * using TXTRecordCreate()/TXTRecordSetValue()/TXTRecordRemoveValue(). |
---|
2271 | * Ownership of the buffer provided in TXTRecordCreate() returns to the client. |
---|
2272 | * |
---|
2273 | * txtRecord: A TXTRecordRef initialized by calling TXTRecordCreate(). |
---|
2274 | * |
---|
2275 | */ |
---|
2276 | |
---|
2277 | void DNSSD_API TXTRecordDeallocate |
---|
2278 | ( |
---|
2279 | TXTRecordRef *txtRecord |
---|
2280 | ); |
---|
2281 | |
---|
2282 | |
---|
2283 | /* TXTRecordSetValue() |
---|
2284 | * |
---|
2285 | * Adds a key (optionally with value) to a TXTRecordRef. If the "key" already |
---|
2286 | * exists in the TXTRecordRef, then the current value will be replaced with |
---|
2287 | * the new value. |
---|
2288 | * Keys may exist in four states with respect to a given TXT record: |
---|
2289 | * - Absent (key does not appear at all) |
---|
2290 | * - Present with no value ("key" appears alone) |
---|
2291 | * - Present with empty value ("key=" appears in TXT record) |
---|
2292 | * - Present with non-empty value ("key=value" appears in TXT record) |
---|
2293 | * For more details refer to "Data Syntax for DNS-SD TXT Records" in |
---|
2294 | * <http://files.dns-sd.org/draft-cheshire-dnsext-dns-sd.txt> |
---|
2295 | * |
---|
2296 | * txtRecord: A TXTRecordRef initialized by calling TXTRecordCreate(). |
---|
2297 | * |
---|
2298 | * key: A null-terminated string which only contains printable ASCII |
---|
2299 | * values (0x20-0x7E), excluding '=' (0x3D). Keys should be |
---|
2300 | * 9 characters or fewer (not counting the terminating null). |
---|
2301 | * |
---|
2302 | * valueSize: The size of the value. |
---|
2303 | * |
---|
2304 | * value: Any binary value. For values that represent |
---|
2305 | * textual data, UTF-8 is STRONGLY recommended. |
---|
2306 | * For values that represent textual data, valueSize |
---|
2307 | * should NOT include the terminating null (if any) |
---|
2308 | * at the end of the string. |
---|
2309 | * If NULL, then "key" will be added with no value. |
---|
2310 | * If non-NULL but valueSize is zero, then "key=" will be |
---|
2311 | * added with empty value. |
---|
2312 | * |
---|
2313 | * return value: Returns kDNSServiceErr_NoError on success. |
---|
2314 | * Returns kDNSServiceErr_Invalid if the "key" string contains |
---|
2315 | * illegal characters. |
---|
2316 | * Returns kDNSServiceErr_NoMemory if adding this key would |
---|
2317 | * exceed the available storage. |
---|
2318 | */ |
---|
2319 | |
---|
2320 | DNSServiceErrorType DNSSD_API TXTRecordSetValue |
---|
2321 | ( |
---|
2322 | TXTRecordRef *txtRecord, |
---|
2323 | const char *key, |
---|
2324 | uint8_t valueSize, /* may be zero */ |
---|
2325 | const void *value /* may be NULL */ |
---|
2326 | ); |
---|
2327 | |
---|
2328 | |
---|
2329 | /* TXTRecordRemoveValue() |
---|
2330 | * |
---|
2331 | * Removes a key from a TXTRecordRef. The "key" must be an |
---|
2332 | * ASCII string which exists in the TXTRecordRef. |
---|
2333 | * |
---|
2334 | * txtRecord: A TXTRecordRef initialized by calling TXTRecordCreate(). |
---|
2335 | * |
---|
2336 | * key: A key name which exists in the TXTRecordRef. |
---|
2337 | * |
---|
2338 | * return value: Returns kDNSServiceErr_NoError on success. |
---|
2339 | * Returns kDNSServiceErr_NoSuchKey if the "key" does not |
---|
2340 | * exist in the TXTRecordRef. |
---|
2341 | */ |
---|
2342 | |
---|
2343 | DNSServiceErrorType DNSSD_API TXTRecordRemoveValue |
---|
2344 | ( |
---|
2345 | TXTRecordRef *txtRecord, |
---|
2346 | const char *key |
---|
2347 | ); |
---|
2348 | |
---|
2349 | |
---|
2350 | /* TXTRecordGetLength() |
---|
2351 | * |
---|
2352 | * Allows you to determine the length of the raw bytes within a TXTRecordRef. |
---|
2353 | * |
---|
2354 | * txtRecord: A TXTRecordRef initialized by calling TXTRecordCreate(). |
---|
2355 | * |
---|
2356 | * return value: Returns the size of the raw bytes inside a TXTRecordRef |
---|
2357 | * which you can pass directly to DNSServiceRegister() or |
---|
2358 | * to DNSServiceUpdateRecord(). |
---|
2359 | * Returns 0 if the TXTRecordRef is empty. |
---|
2360 | */ |
---|
2361 | |
---|
2362 | uint16_t DNSSD_API TXTRecordGetLength |
---|
2363 | ( |
---|
2364 | const TXTRecordRef *txtRecord |
---|
2365 | ); |
---|
2366 | |
---|
2367 | |
---|
2368 | /* TXTRecordGetBytesPtr() |
---|
2369 | * |
---|
2370 | * Allows you to retrieve a pointer to the raw bytes within a TXTRecordRef. |
---|
2371 | * |
---|
2372 | * txtRecord: A TXTRecordRef initialized by calling TXTRecordCreate(). |
---|
2373 | * |
---|
2374 | * return value: Returns a pointer to the raw bytes inside the TXTRecordRef |
---|
2375 | * which you can pass directly to DNSServiceRegister() or |
---|
2376 | * to DNSServiceUpdateRecord(). |
---|
2377 | */ |
---|
2378 | |
---|
2379 | const void * DNSSD_API TXTRecordGetBytesPtr |
---|
2380 | ( |
---|
2381 | const TXTRecordRef *txtRecord |
---|
2382 | ); |
---|
2383 | |
---|
2384 | |
---|
2385 | /********************************************************************************************* |
---|
2386 | * |
---|
2387 | * TXT Record Parsing Functions |
---|
2388 | * |
---|
2389 | *********************************************************************************************/ |
---|
2390 | |
---|
2391 | /* |
---|
2392 | * A typical calling sequence for TXT record parsing is something like: |
---|
2393 | * |
---|
2394 | * Receive TXT record data in DNSServiceResolve() callback |
---|
2395 | * if (TXTRecordContainsKey(txtLen, txtRecord, "key")) then do something |
---|
2396 | * val1ptr = TXTRecordGetValuePtr(txtLen, txtRecord, "key1", &len1); |
---|
2397 | * val2ptr = TXTRecordGetValuePtr(txtLen, txtRecord, "key2", &len2); |
---|
2398 | * ... |
---|
2399 | * memcpy(myval1, val1ptr, len1); |
---|
2400 | * memcpy(myval2, val2ptr, len2); |
---|
2401 | * ... |
---|
2402 | * return; |
---|
2403 | * |
---|
2404 | * If you wish to retain the values after return from the DNSServiceResolve() |
---|
2405 | * callback, then you need to copy the data to your own storage using memcpy() |
---|
2406 | * or similar, as shown in the example above. |
---|
2407 | * |
---|
2408 | * If for some reason you need to parse a TXT record you built yourself |
---|
2409 | * using the TXT record construction functions above, then you can do |
---|
2410 | * that using TXTRecordGetLength and TXTRecordGetBytesPtr calls: |
---|
2411 | * TXTRecordGetValue(TXTRecordGetLength(x), TXTRecordGetBytesPtr(x), key, &len); |
---|
2412 | * |
---|
2413 | * Most applications only fetch keys they know about from a TXT record and |
---|
2414 | * ignore the rest. |
---|
2415 | * However, some debugging tools wish to fetch and display all keys. |
---|
2416 | * To do that, use the TXTRecordGetCount() and TXTRecordGetItemAtIndex() calls. |
---|
2417 | */ |
---|
2418 | |
---|
2419 | /* TXTRecordContainsKey() |
---|
2420 | * |
---|
2421 | * Allows you to determine if a given TXT Record contains a specified key. |
---|
2422 | * |
---|
2423 | * txtLen: The size of the received TXT Record. |
---|
2424 | * |
---|
2425 | * txtRecord: Pointer to the received TXT Record bytes. |
---|
2426 | * |
---|
2427 | * key: A null-terminated ASCII string containing the key name. |
---|
2428 | * |
---|
2429 | * return value: Returns 1 if the TXT Record contains the specified key. |
---|
2430 | * Otherwise, it returns 0. |
---|
2431 | */ |
---|
2432 | |
---|
2433 | int DNSSD_API TXTRecordContainsKey |
---|
2434 | ( |
---|
2435 | uint16_t txtLen, |
---|
2436 | const void *txtRecord, |
---|
2437 | const char *key |
---|
2438 | ); |
---|
2439 | |
---|
2440 | |
---|
2441 | /* TXTRecordGetValuePtr() |
---|
2442 | * |
---|
2443 | * Allows you to retrieve the value for a given key from a TXT Record. |
---|
2444 | * |
---|
2445 | * txtLen: The size of the received TXT Record |
---|
2446 | * |
---|
2447 | * txtRecord: Pointer to the received TXT Record bytes. |
---|
2448 | * |
---|
2449 | * key: A null-terminated ASCII string containing the key name. |
---|
2450 | * |
---|
2451 | * valueLen: On output, will be set to the size of the "value" data. |
---|
2452 | * |
---|
2453 | * return value: Returns NULL if the key does not exist in this TXT record, |
---|
2454 | * or exists with no value (to differentiate between |
---|
2455 | * these two cases use TXTRecordContainsKey()). |
---|
2456 | * Returns pointer to location within TXT Record bytes |
---|
2457 | * if the key exists with empty or non-empty value. |
---|
2458 | * For empty value, valueLen will be zero. |
---|
2459 | * For non-empty value, valueLen will be length of value data. |
---|
2460 | */ |
---|
2461 | |
---|
2462 | const void * DNSSD_API TXTRecordGetValuePtr |
---|
2463 | ( |
---|
2464 | uint16_t txtLen, |
---|
2465 | const void *txtRecord, |
---|
2466 | const char *key, |
---|
2467 | uint8_t *valueLen |
---|
2468 | ); |
---|
2469 | |
---|
2470 | |
---|
2471 | /* TXTRecordGetCount() |
---|
2472 | * |
---|
2473 | * Returns the number of keys stored in the TXT Record. The count |
---|
2474 | * can be used with TXTRecordGetItemAtIndex() to iterate through the keys. |
---|
2475 | * |
---|
2476 | * txtLen: The size of the received TXT Record. |
---|
2477 | * |
---|
2478 | * txtRecord: Pointer to the received TXT Record bytes. |
---|
2479 | * |
---|
2480 | * return value: Returns the total number of keys in the TXT Record. |
---|
2481 | * |
---|
2482 | */ |
---|
2483 | |
---|
2484 | uint16_t DNSSD_API TXTRecordGetCount |
---|
2485 | ( |
---|
2486 | uint16_t txtLen, |
---|
2487 | const void *txtRecord |
---|
2488 | ); |
---|
2489 | |
---|
2490 | |
---|
2491 | /* TXTRecordGetItemAtIndex() |
---|
2492 | * |
---|
2493 | * Allows you to retrieve a key name and value pointer, given an index into |
---|
2494 | * a TXT Record. Legal index values range from zero to TXTRecordGetCount()-1. |
---|
2495 | * It's also possible to iterate through keys in a TXT record by simply |
---|
2496 | * calling TXTRecordGetItemAtIndex() repeatedly, beginning with index zero |
---|
2497 | * and increasing until TXTRecordGetItemAtIndex() returns kDNSServiceErr_Invalid. |
---|
2498 | * |
---|
2499 | * On return: |
---|
2500 | * For keys with no value, *value is set to NULL and *valueLen is zero. |
---|
2501 | * For keys with empty value, *value is non-NULL and *valueLen is zero. |
---|
2502 | * For keys with non-empty value, *value is non-NULL and *valueLen is non-zero. |
---|
2503 | * |
---|
2504 | * txtLen: The size of the received TXT Record. |
---|
2505 | * |
---|
2506 | * txtRecord: Pointer to the received TXT Record bytes. |
---|
2507 | * |
---|
2508 | * itemIndex: An index into the TXT Record. |
---|
2509 | * |
---|
2510 | * keyBufLen: The size of the string buffer being supplied. |
---|
2511 | * |
---|
2512 | * key: A string buffer used to store the key name. |
---|
2513 | * On return, the buffer contains a null-terminated C string |
---|
2514 | * giving the key name. DNS-SD TXT keys are usually |
---|
2515 | * 9 characters or fewer. To hold the maximum possible |
---|
2516 | * key name, the buffer should be 256 bytes long. |
---|
2517 | * |
---|
2518 | * valueLen: On output, will be set to the size of the "value" data. |
---|
2519 | * |
---|
2520 | * value: On output, *value is set to point to location within TXT |
---|
2521 | * Record bytes that holds the value data. |
---|
2522 | * |
---|
2523 | * return value: Returns kDNSServiceErr_NoError on success. |
---|
2524 | * Returns kDNSServiceErr_NoMemory if keyBufLen is too short. |
---|
2525 | * Returns kDNSServiceErr_Invalid if index is greater than |
---|
2526 | * TXTRecordGetCount()-1. |
---|
2527 | */ |
---|
2528 | |
---|
2529 | DNSServiceErrorType DNSSD_API TXTRecordGetItemAtIndex |
---|
2530 | ( |
---|
2531 | uint16_t txtLen, |
---|
2532 | const void *txtRecord, |
---|
2533 | uint16_t itemIndex, |
---|
2534 | uint16_t keyBufLen, |
---|
2535 | char *key, |
---|
2536 | uint8_t *valueLen, |
---|
2537 | const void **value |
---|
2538 | ); |
---|
2539 | |
---|
2540 | #if _DNS_SD_LIBDISPATCH |
---|
2541 | /* |
---|
2542 | * DNSServiceSetDispatchQueue |
---|
2543 | * |
---|
2544 | * Allows you to schedule a DNSServiceRef on a serial dispatch queue for receiving asynchronous |
---|
2545 | * callbacks. It's the clients responsibility to ensure that the provided dispatch queue is running. |
---|
2546 | * |
---|
2547 | * A typical application that uses CFRunLoopRun or dispatch_main on its main thread will |
---|
2548 | * usually schedule DNSServiceRefs on its main queue (which is always a serial queue) |
---|
2549 | * using "DNSServiceSetDispatchQueue(sdref, dispatch_get_main_queue());" |
---|
2550 | * |
---|
2551 | * If there is any error during the processing of events, the application callback will |
---|
2552 | * be called with an error code. For shared connections, each subordinate DNSServiceRef |
---|
2553 | * will get its own error callback. Currently these error callbacks only happen |
---|
2554 | * if the mDNSResponder daemon is manually terminated or crashes, and the error |
---|
2555 | * code in this case is kDNSServiceErr_ServiceNotRunning. The application must call |
---|
2556 | * DNSServiceRefDeallocate to free the DNSServiceRef when it gets such an error code. |
---|
2557 | * These error callbacks are rare and should not normally happen on customer machines, |
---|
2558 | * but application code should be written defensively to handle such error callbacks |
---|
2559 | * gracefully if they occur. |
---|
2560 | * |
---|
2561 | * After using DNSServiceSetDispatchQueue on a DNSServiceRef, calling DNSServiceProcessResult |
---|
2562 | * on the same DNSServiceRef will result in undefined behavior and should be avoided. |
---|
2563 | * |
---|
2564 | * Once the application successfully schedules a DNSServiceRef on a serial dispatch queue using |
---|
2565 | * DNSServiceSetDispatchQueue, it cannot remove the DNSServiceRef from the dispatch queue, or use |
---|
2566 | * DNSServiceSetDispatchQueue a second time to schedule the DNSServiceRef onto a different serial dispatch |
---|
2567 | * queue. Once scheduled onto a dispatch queue a DNSServiceRef will deliver events to that queue until |
---|
2568 | * the application no longer requires that operation and terminates it using DNSServiceRefDeallocate. |
---|
2569 | * |
---|
2570 | * service: DNSServiceRef that was allocated and returned to the application, when the |
---|
2571 | * application calls one of the DNSService API. |
---|
2572 | * |
---|
2573 | * queue: dispatch queue where the application callback will be scheduled |
---|
2574 | * |
---|
2575 | * return value: Returns kDNSServiceErr_NoError on success. |
---|
2576 | * Returns kDNSServiceErr_NoMemory if it cannot create a dispatch source |
---|
2577 | * Returns kDNSServiceErr_BadParam if the service param is invalid or the |
---|
2578 | * queue param is invalid |
---|
2579 | */ |
---|
2580 | |
---|
2581 | DNSServiceErrorType DNSSD_API DNSServiceSetDispatchQueue |
---|
2582 | ( |
---|
2583 | DNSServiceRef service, |
---|
2584 | dispatch_queue_t queue |
---|
2585 | ); |
---|
2586 | #endif //_DNS_SD_LIBDISPATCH |
---|
2587 | |
---|
2588 | #if !defined(_WIN32) |
---|
2589 | typedef void (DNSSD_API *DNSServiceSleepKeepaliveReply) |
---|
2590 | ( |
---|
2591 | DNSServiceRef sdRef, |
---|
2592 | DNSServiceErrorType errorCode, |
---|
2593 | void *context |
---|
2594 | ); |
---|
2595 | DNSServiceErrorType DNSSD_API DNSServiceSleepKeepalive |
---|
2596 | ( |
---|
2597 | DNSServiceRef *sdRef, |
---|
2598 | DNSServiceFlags flags, |
---|
2599 | int fd, |
---|
2600 | unsigned int timeout, |
---|
2601 | DNSServiceSleepKeepaliveReply callBack, |
---|
2602 | void *context |
---|
2603 | ); |
---|
2604 | #endif |
---|
2605 | |
---|
2606 | #ifdef APPLE_OSX_mDNSResponder |
---|
2607 | /* DNSServiceCreateDelegateConnection() |
---|
2608 | * |
---|
2609 | * Create a delegate connection to the daemon allowing efficient registration of |
---|
2610 | * multiple individual records. |
---|
2611 | * |
---|
2612 | * Parameters: |
---|
2613 | * |
---|
2614 | * sdRef: A pointer to an uninitialized DNSServiceRef. Deallocating |
---|
2615 | * the reference (via DNSServiceRefDeallocate()) severs the |
---|
2616 | * connection and deregisters all records registered on this connection. |
---|
2617 | * |
---|
2618 | * pid : Process ID of the delegate |
---|
2619 | * |
---|
2620 | * uuid: UUID of the delegate |
---|
2621 | * |
---|
2622 | * Note that only one of the two arguments (pid or uuid) can be specified. If pid |
---|
2623 | * is zero, uuid will be assumed to be a valid value; otherwise pid will be used. |
---|
2624 | * |
---|
2625 | * return value: Returns kDNSServiceErr_NoError on success, otherwise returns |
---|
2626 | * an error code indicating the specific failure that occurred (in which |
---|
2627 | * case the DNSServiceRef is not initialized). kDNSServiceErr_NotAuth is |
---|
2628 | * returned to indicate that the calling process does not have entitlements |
---|
2629 | * to use this API. |
---|
2630 | */ |
---|
2631 | DNSServiceErrorType DNSSD_API DNSServiceCreateDelegateConnection(DNSServiceRef *sdRef, int32_t pid, uuid_t uuid); |
---|
2632 | #endif |
---|
2633 | |
---|
2634 | #ifdef __APPLE_API_PRIVATE |
---|
2635 | |
---|
2636 | #define kDNSServiceCompPrivateDNS "PrivateDNS" |
---|
2637 | #define kDNSServiceCompMulticastDNS "MulticastDNS" |
---|
2638 | |
---|
2639 | #endif //__APPLE_API_PRIVATE |
---|
2640 | |
---|
2641 | /* Some C compiler cleverness. We can make the compiler check certain things for us, |
---|
2642 | * and report errors at compile-time if anything is wrong. The usual way to do this would |
---|
2643 | * be to use a run-time "if" statement or the conventional run-time "assert" mechanism, but |
---|
2644 | * then you don't find out what's wrong until you run the software. This way, if the assertion |
---|
2645 | * condition is false, the array size is negative, and the complier complains immediately. |
---|
2646 | */ |
---|
2647 | |
---|
2648 | struct CompileTimeAssertionChecks_DNS_SD |
---|
2649 | { |
---|
2650 | char assert0[(sizeof(union _TXTRecordRef_t) == 16) ? 1 : -1]; |
---|
2651 | }; |
---|
2652 | |
---|
2653 | #ifdef __cplusplus |
---|
2654 | } |
---|
2655 | #endif |
---|
2656 | |
---|
2657 | #endif /* _DNS_SD_H */ |
---|