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