]> git.saurik.com Git - apple/mdnsresponder.git/blob - mDNSCore/mDNSClientAPI.h
a968c7f6c84bc81876446f7892430d43735e68b3
[apple/mdnsresponder.git] / mDNSCore / mDNSClientAPI.h
1 /*
2 * Copyright (c) 2002-2003 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
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
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
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 *
21 * @APPLE_LICENSE_HEADER_END@
22
23 Change History (most recent first):
24
25 $Log: mDNSClientAPI.h,v $
26 Revision 1.114.2.6 2004/03/02 02:55:25 cheshire
27 <rdar://problem/3549576> Properly support "_services._dns-sd._udp" meta-queries
28
29 Revision 1.114.2.5 2004/02/18 23:35:17 cheshire
30 <rdar://problem/3488559>: Hard code domain enumeration functions to return ".local" only
31 Also make mDNS_StopGetDomains() a no-op too, so that we don't get warning messages in syslog
32
33 Revision 1.114.2.4 2004/01/28 23:29:20 cheshire
34 Fix structure packing (only affects third-party Darwin developers)
35
36 Revision 1.114.2.3 2003/12/05 00:03:34 cheshire
37 <rdar://problem/3487869> Use buffer size MAX_ESCAPED_DOMAIN_NAME instead of 256
38
39 Revision 1.114.2.2 2003/12/04 23:30:00 cheshire
40 Add "#define MAX_ESCAPED_DOMAIN_NAME 1005", needed for Posix folder to build
41
42 Revision 1.114.2.1 2003/12/03 11:07:58 cheshire
43 <rdar://problem/3457718>: Stop and start of a service uses old ip address (with old port number)
44
45 Revision 1.114 2003/08/29 19:44:15 cheshire
46 <rdar://problem/3400967> Traffic reduction: Eliminate synchronized QUs when a new service appears
47 1. Use m->RandomQueryDelay to impose a random delay in the range 0-500ms on queries
48 that already have at least one unique answer in the cache
49 2. For these queries, go straight to QM, skipping QU
50
51 Revision 1.113 2003/08/21 19:31:58 cheshire
52 Cosmetic: Swap order of fields
53
54 Revision 1.112 2003/08/21 19:27:36 cheshire
55 <rdar://problem/3387878> Traffic reduction: No need to announce record for longer than TTL
56
57 Revision 1.111 2003/08/21 02:21:50 cheshire
58 <rdar://problem/3386473> Efficiency: Reduce repeated queries
59
60 Revision 1.110 2003/08/20 23:39:31 cheshire
61 <rdar://problem/3344098> Review syslog messages, and remove as appropriate
62
63 Revision 1.109 2003/08/19 22:24:10 cheshire
64 Comment change
65
66 Revision 1.108 2003/08/19 22:20:00 cheshire
67 <rdar://problem/3376721> Don't use IPv6 on interfaces that have a routable IPv4 address configured
68 More minor refinements
69
70 Revision 1.107 2003/08/19 06:48:25 cheshire
71 <rdar://problem/3376552> Guard against excessive record updates
72 Each record starts with 10 UpdateCredits.
73 Every update consumes one UpdateCredit.
74 UpdateCredits are replenished at a rate of one one per minute, up to a maximum of 10.
75 As the number of UpdateCredits declines, the number of announcements is similarly scaled back.
76 When fewer than 5 UpdateCredits remain, the first announcement is also delayed by an increasing amount.
77
78 Revision 1.106 2003/08/19 04:49:28 cheshire
79 <rdar://problem/3368159> Interaction between v4, v6 and dual-stack hosts not working quite right
80 1. A dual-stack host should only suppress its own query if it sees the same query from other hosts on BOTH IPv4 and IPv6.
81 2. When we see the first v4 (or first v6) member of a group, we re-trigger questions and probes on that interface.
82 3. When we see the last v4 (or v6) member of a group go away, we revalidate all the records received on that interface.
83
84 Revision 1.105 2003/08/19 02:33:37 cheshire
85 Update comments
86
87 Revision 1.104 2003/08/19 02:31:11 cheshire
88 <rdar://problem/3378386> mDNSResponder overenthusiastic with final expiration queries
89 Final expiration queries now only mark the question for sending on the particular interface
90 pertaining to the record that's expiring.
91
92 Revision 1.103 2003/08/18 19:05:44 cheshire
93 <rdar://problem/3382423> UpdateRecord not working right
94 Added "newrdlength" field to hold new length of updated rdata
95
96 Revision 1.102 2003/08/16 03:39:00 cheshire
97 <rdar://problem/3338440> InterfaceID -1 indicates "local only"
98
99 Revision 1.101 2003/08/15 20:16:02 cheshire
100 <rdar://problem/3366590> mDNSResponder takes too much RPRVT
101 We want to avoid touching the rdata pages, so we don't page them in.
102 1. RDLength was stored with the rdata, which meant touching the page just to find the length.
103 Moved this from the RData to the ResourceRecord object.
104 2. To avoid unnecessarily touching the rdata just to compare it,
105 compute a hash of the rdata and store the hash in the ResourceRecord object.
106
107 Revision 1.100 2003/08/14 19:29:04 cheshire
108 <rdar://problem/3378473> Include cache records in SIGINFO output
109 Moved declarations of DNSTypeName() and GetRRDisplayString to mDNSClientAPI.h so daemon.c can use them
110
111 Revision 1.99 2003/08/14 02:17:05 cheshire
112 <rdar://problem/3375491> Split generic ResourceRecord type into two separate types: AuthRecord and CacheRecord
113
114 Revision 1.98 2003/08/12 19:56:23 cheshire
115 Update to APSL 2.0
116
117 Revision 1.97 2003/08/12 14:59:27 cheshire
118 <rdar://problem/3374490> Rate-limiting blocks some legitimate responses
119 When setting LastMCTime also record LastMCInterface. When checking LastMCTime to determine
120 whether to suppress the response, also check LastMCInterface to see if it matches.
121
122 Revision 1.96 2003/08/12 13:57:04 cheshire
123 <rdar://problem/3323817> Improve cache performance
124 Changed the number of hash table slots from 37 to 499
125
126 Revision 1.95 2003/08/09 00:55:02 cheshire
127 <rdar://problem/3366553> mDNSResponder is taking 20-30% of the CPU
128 Don't scan the whole cache after every packet.
129
130 Revision 1.94 2003/08/09 00:35:29 cheshire
131
132 Revision 1.93 2003/08/08 18:55:48 cheshire
133 <rdar://problem/3370365> Guard against time going backwards
134
135 Revision 1.92 2003/08/08 18:36:04 cheshire
136 <rdar://problem/3344154> Only need to revalidate on interface removal on platforms that have the PhantomInterfaces bug
137
138 Revision 1.91 2003/08/06 21:33:39 cheshire
139 Fix compiler warnings on PocketPC 2003 (Windows CE)
140
141 Revision 1.90 2003/08/06 20:30:17 cheshire
142 Add structure definition for rdataMX (not currently used, but good to have it for completeness)
143
144 Revision 1.89 2003/08/06 18:58:19 cheshire
145 Update comments
146
147 Revision 1.88 2003/07/24 23:45:44 cheshire
148 To eliminate compiler warnings, changed definition of mDNSBool from
149 "unsigned char" to "int", since "int" is in fact truly the type that C uses
150 for the result of comparison operators (a<b) and logical operators (a||b)
151
152 Revision 1.87 2003/07/22 23:57:20 cheshire
153 Move platform-layer function prototypes from mDNSClientAPI.h to mDNSPlatformFunctions.h where they belong
154
155 Revision 1.86 2003/07/20 03:52:02 ksekar
156 Bug #: <rdar://problem/3320722>: Feature: New Rendezvous APIs (#7875) (mDNSResponder component)
157 Added error type for incompatibility between daemon and client versions
158
159 Revision 1.85 2003/07/19 03:23:13 cheshire
160 <rdar://problem/2986147> mDNSResponder needs to receive and cache larger records
161
162 Revision 1.84 2003/07/18 23:52:12 cheshire
163 To improve consistency of field naming, global search-and-replace:
164 NextProbeTime -> NextScheduledProbe
165 NextResponseTime -> NextScheduledResponse
166
167 Revision 1.83 2003/07/18 00:29:59 cheshire
168 <rdar://problem/3268878> Remove mDNSResponder version from packet header and use HINFO record instead
169
170 Revision 1.82 2003/07/17 17:35:04 cheshire
171 <rdar://problem/3325583> Rate-limit responses, to guard against packet flooding
172
173 Revision 1.81 2003/07/16 05:01:36 cheshire
174 Add fields 'LargeAnswers' and 'ExpectUnicastResponse' in preparation for
175 <rdar://problem/3315761> Need to implement "unicast response" request, using top bit of qclass
176
177 Revision 1.80 2003/07/15 01:55:12 cheshire
178 <rdar://problem/3315777> Need to implement service registration with subtypes
179
180 Revision 1.79 2003/07/13 02:28:00 cheshire
181 <rdar://problem/3325166> SendResponses didn't all its responses
182 Delete all references to RRInterfaceActive -- it's now superfluous
183
184 Revision 1.78 2003/07/13 01:47:53 cheshire
185 Fix one error and one warning in the Windows build
186
187 Revision 1.77 2003/07/11 01:32:38 cheshire
188 Syntactic cleanup (no change to funcationality): Now that we only have one host name,
189 rename field "hostname1" to "hostname", and field "RR_A1" to "RR_A".
190
191 Revision 1.76 2003/07/11 01:28:00 cheshire
192 <rdar://problem/3161289> No more local.arpa
193
194 Revision 1.75 2003/07/02 21:19:45 cheshire
195 <rdar://problem/3313413> Update copyright notices, etc., in source code comments
196
197 Revision 1.74 2003/07/02 02:41:23 cheshire
198 <rdar://problem/2986146> mDNSResponder needs to start with a smaller cache and then grow it as needed
199
200 Revision 1.73 2003/06/10 04:24:39 cheshire
201 <rdar://problem/3283637> React when we observe other people query unsuccessfully for a record that's in our cache
202 Some additional refinements:
203 Don't try to do this for unicast-response queries
204 better tracking of Qs and KAs in multi-packet KA lists
205
206 Revision 1.72 2003/06/10 01:46:27 cheshire
207 Add better comments explaining how these data structures are intended to be used from the client layer
208
209 Revision 1.71 2003/06/07 06:45:05 cheshire
210 <rdar://problem/3283666> No need for multiple machines to all be sending the same queries
211
212 Revision 1.70 2003/06/07 04:50:53 cheshire
213 <rdar://problem/3283637> React when we observe other people query unsuccessfully for a record that's in our cache
214
215 Revision 1.69 2003/06/07 04:22:17 cheshire
216 Add MsgBuffer for error log and debug messages
217
218 Revision 1.68 2003/06/07 01:46:38 cheshire
219 <rdar://problem/3283540> When query produces zero results, call mDNS_Reconfirm() on any antecedent records
220
221 Revision 1.67 2003/06/07 01:22:14 cheshire
222 <rdar://problem/3283516> mDNSResponder needs an mDNS_Reconfirm() function
223
224 Revision 1.66 2003/06/07 00:59:43 cheshire
225 <rdar://problem/3283454> Need some randomness to spread queries on the network
226
227 Revision 1.65 2003/06/06 21:41:11 cheshire
228 For consistency, mDNS_StopQuery() should return an mStatus result, just like all the other mDNSCore routines
229
230 Revision 1.64 2003/06/06 21:38:55 cheshire
231 Renamed 'NewData' as 'FreshData' (The data may not be new data, just a refresh of data that we
232 already had in our cache. This refreshes our TTL on the data, but the data itself stays the same.)
233
234 Revision 1.63 2003/06/06 17:20:14 cheshire
235 For clarity, rename question fields name/rrtype/rrclass as qname/qtype/qclass
236 (Global search-and-replace; no functional change to code execution.)
237
238 Revision 1.62 2003/06/04 01:25:33 cheshire
239 <rdar://problem/3274950> Cannot perform multi-packet known-answer suppression messages
240 Display time interval between first and subsequent queries
241
242 Revision 1.61 2003/06/03 05:02:16 cheshire
243 <rdar://problem/3277080> Duplicate registrations not handled as efficiently as they should be
244
245 Revision 1.60 2003/05/31 00:09:49 cheshire
246 <rdar://problem/3274862> Add ability to discover what services are on a network
247
248 Revision 1.59 2003/05/29 06:11:35 cheshire
249 <rdar://problem/3272214>: Report if there appear to be too many "Resolve" callbacks
250
251 Revision 1.58 2003/05/29 05:48:06 cheshire
252 Minor fix for when generating printf warnings: mDNS_snprintf arguments are now 3,4
253
254 Revision 1.57 2003/05/26 03:21:27 cheshire
255 Tidy up address structure naming:
256 mDNSIPAddr => mDNSv4Addr (for consistency with mDNSv6Addr)
257 mDNSAddr.addr.ipv4 => mDNSAddr.ip.v4
258 mDNSAddr.addr.ipv6 => mDNSAddr.ip.v6
259
260 Revision 1.56 2003/05/26 03:01:27 cheshire
261 <rdar://problem/3268904> sprintf/vsprintf-style functions are unsafe; use snprintf/vsnprintf instead
262
263 Revision 1.55 2003/05/26 00:47:30 cheshire
264 Comment clarification
265
266 Revision 1.54 2003/05/24 16:39:48 cheshire
267 <rdar://problem/3268631> SendResponses also needs to handle multihoming better
268
269 Revision 1.53 2003/05/23 02:15:37 cheshire
270 Fixed misleading use of the term "duplicate suppression" where it should have
271 said "known answer suppression". (Duplicate answer suppression is something
272 different, and duplicate question suppression is yet another thing, so the use
273 of the completely vague term "duplicate suppression" was particularly bad.)
274
275 Revision 1.52 2003/05/22 02:29:22 cheshire
276 <rdar://problem/2984918> SendQueries needs to handle multihoming better
277 Complete rewrite of SendQueries. Works much better now :-)
278
279 Revision 1.51 2003/05/21 20:14:55 cheshire
280 Fix comments and warnings
281
282 Revision 1.50 2003/05/14 07:08:36 cheshire
283 <rdar://problem/3159272> mDNSResponder should be smarter about reconfigurations
284 Previously, when there was any network configuration change, mDNSResponder
285 would tear down the entire list of active interfaces and start again.
286 That was very disruptive, and caused the entire cache to be flushed,
287 and caused lots of extra network traffic. Now it only removes interfaces
288 that have really gone, and only adds new ones that weren't there before.
289
290 Revision 1.49 2003/05/07 01:49:36 cheshire
291 Remove "const" in ConstructServiceName prototype
292
293 Revision 1.48 2003/05/07 00:18:44 cheshire
294 Fix typo: "kDNSQClass_Mask" should be "kDNSClass_Mask"
295
296 Revision 1.47 2003/05/06 00:00:46 cheshire
297 <rdar://problem/3248914> Rationalize naming of domainname manipulation functions
298
299 Revision 1.46 2003/04/30 20:39:09 cheshire
300 Add comment
301
302 Revision 1.45 2003/04/29 00:40:50 cheshire
303 Fix compiler warnings
304
305 Revision 1.44 2003/04/26 02:41:56 cheshire
306 <rdar://problem/3241281> Change timenow from a local variable to a structure member
307
308 Revision 1.43 2003/04/25 01:45:56 cheshire
309 <rdar://problem/3240002> mDNS_RegisterNoSuchService needs to include a host name
310
311 Revision 1.42 2003/04/15 20:58:31 jgraessl
312
313 Bug #: 3229014
314 Added a hash to lookup records in the cache.
315
316 Revision 1.41 2003/04/15 18:09:13 jgraessl
317
318 Bug #: 3228892
319 Reviewed by: Stuart Cheshire
320 Added code to keep track of when the next cache item will expire so we can
321 call TidyRRCache only when necessary.
322
323 Revision 1.40 2003/03/29 01:55:19 cheshire
324 <rdar://problem/3212360> mDNSResponder sometimes suffers false self-conflicts when it sees its own packets
325 Solution: Major cleanup of packet timing and conflict handling rules
326
327 Revision 1.39 2003/03/27 03:30:55 cheshire
328 <rdar://problem/3210018> Name conflicts not handled properly, resulting in memory corruption, and eventual crash
329 Problem was that HostNameCallback() was calling mDNS_DeregisterInterface(), which is not safe in a callback
330 Fixes:
331 1. Make mDNS_DeregisterInterface() safe to call from a callback
332 2. Make HostNameCallback() use mDNS_DeadvertiseInterface() instead
333 (it never really needed to deregister the interface at all)
334
335 Revision 1.38 2003/03/15 04:40:36 cheshire
336 Change type called "mDNSOpaqueID" to the more descriptive name "mDNSInterfaceID"
337
338 Revision 1.37 2003/03/14 21:34:11 cheshire
339 <rdar://problem/3176950> Can't setup and print to Lexmark PS printers via Airport Extreme
340 Increase size of cache rdata from 512 to 768
341
342 Revision 1.36 2003/03/05 03:38:35 cheshire
343 Bug #: 3185731 Bogus error message in console: died or deallocated, but no record of client can be found!
344 Fixed by leaving client in list after conflict, until client explicitly deallocates
345
346 Revision 1.35 2003/02/21 02:47:54 cheshire
347 Bug #: 3099194 mDNSResponder needs performance improvements
348 Several places in the code were calling CacheRRActive(), which searched the entire
349 question list every time, to see if this cache resource record answers any question.
350 Instead, we now have a field "CRActiveQuestion" in the resource record structure
351
352 Revision 1.34 2003/02/21 01:54:08 cheshire
353 Bug #: 3099194 mDNSResponder needs performance improvements
354 Switched to using new "mDNS_Execute" model (see "Implementer Notes.txt")
355
356 Revision 1.33 2003/02/20 06:48:32 cheshire
357 Bug #: 3169535 Xserve RAID needs to do interface-specific registrations
358 Reviewed by: Josh Graessley, Bob Bradley
359
360 Revision 1.32 2003/01/31 03:35:59 cheshire
361 Bug #: 3147097 mDNSResponder sometimes fails to find the correct results
362 When there were *two* active questions in the list, they were incorrectly
363 finding *each other* and *both* being marked as duplicates of another question
364
365 Revision 1.31 2003/01/29 02:46:37 cheshire
366 Fix for IPv6:
367 A physical interface is identified solely by its InterfaceID (not by IP and type).
368 On a given InterfaceID, mDNSCore may send both v4 and v6 multicasts.
369 In cases where the requested outbound protocol (v4 or v6) is not supported on
370 that InterfaceID, the platform support layer should simply discard that packet.
371
372 Revision 1.30 2003/01/29 01:47:08 cheshire
373 Rename 'Active' to 'CRActive' or 'InterfaceActive' for improved clarity
374
375 Revision 1.29 2003/01/28 05:23:43 cheshire
376 Bug #: 3147097 mDNSResponder sometimes fails to find the correct results
377 Add 'Active' flag for interfaces
378
379 Revision 1.28 2003/01/28 01:35:56 cheshire
380 Revise comment about ThisQInterval to reflect new semantics
381
382 Revision 1.27 2003/01/13 23:49:42 jgraessl
383 Merged changes for the following fixes in to top of tree:
384 3086540 computer name changes not handled properly
385 3124348 service name changes are not properly handled
386 3124352 announcements sent in pairs, failing chattiness test
387
388 Revision 1.26 2002/12/23 22:13:28 jgraessl
389
390 Reviewed by: Stuart Cheshire
391 Initial IPv6 support for mDNSResponder.
392
393 Revision 1.25 2002/09/21 20:44:49 zarzycki
394 Added APSL info
395
396 Revision 1.24 2002/09/19 23:47:35 cheshire
397 Added mDNS_RegisterNoSuchService() function for assertion of non-existance
398 of a particular named service
399
400 Revision 1.23 2002/09/19 21:25:34 cheshire
401 mDNS_snprintf() doesn't need to be in a separate file
402
403 Revision 1.22 2002/09/19 04:20:43 cheshire
404 Remove high-ascii characters that confuse some systems
405
406 Revision 1.21 2002/09/17 01:06:35 cheshire
407 Change mDNS_AdvertiseLocalAddresses to be a parameter to mDNS_Init()
408
409 Revision 1.20 2002/09/16 18:41:41 cheshire
410 Merge in license terms from Quinn's copy, in preparation for Darwin release
411
412 */
413
414 #ifndef __mDNSClientAPI_h
415 #define __mDNSClientAPI_h
416
417 #include <stdarg.h> // stdarg.h is required for for va_list support for the mDNS_vsnprintf declaration
418 #include "mDNSDebug.h"
419
420 #ifdef __cplusplus
421 extern "C" {
422 #endif
423
424 // ***************************************************************************
425 // Function scope indicators
426
427 // If you see "mDNSlocal" before a function name in a C file, it means the function is not callable outside this file
428 #ifndef mDNSlocal
429 #define mDNSlocal static
430 #endif
431 // If you see "mDNSexport" before a symbol in a C file, it means the symbol is exported for use by clients
432 // For every "mDNSexport" in a C file, there needs to be a corresponding "extern" declaration in some header file
433 // (When a C file #includes a header file, the "extern" declarations tell the compiler:
434 // "This symbol exists -- but not necessarily in this C file.")
435 #ifndef mDNSexport
436 #define mDNSexport
437 #endif
438
439 // ***************************************************************************
440 // Structure packing macro
441
442 // If we're not using GNUC, it's not fatal.
443 // Most compilers naturally pack the on-the-wire structures correctly anyway, so a plain "struct" is usually fine.
444 // In the event that structures are not packed correctly, mDNS_Init() will detect this and report an error, so the
445 // developer will know what's wrong, and can investigate what needs to be done on that compiler to provide proper packing.
446 #ifndef packed_struct
447 #ifdef __GNUC__
448 #define packedstruct struct __attribute__((__packed__))
449 #define packedunion union __attribute__((__packed__))
450 #else
451 #define packedstruct struct
452 #define packedunion union
453 #endif
454 #endif
455
456 // ***************************************************************************
457 #if 0
458 #pragma mark - DNS Resource Record class and type constants
459 #endif
460
461 typedef enum // From RFC 1035
462 {
463 kDNSClass_IN = 1, // Internet
464 kDNSClass_CS = 2, // CSNET
465 kDNSClass_CH = 3, // CHAOS
466 kDNSClass_HS = 4, // Hesiod
467 kDNSClass_NONE = 254, // Used in DNS UPDATE [RFC 2136]
468
469 kDNSClass_Mask = 0x7FFF,// Multicast DNS uses the bottom 15 bits to identify the record class...
470 kDNSClass_UniqueRRSet = 0x8000,// ... and the top bit indicates that all other cached records are now invalid
471
472 kDNSQClass_ANY = 255, // Not a DNS class, but a DNS query class, meaning "all classes"
473 kDNSQClass_UnicastResponse = 0x8000 // Top bit set in a question means "unicast response acceptable"
474 } DNS_ClassValues;
475
476 typedef enum // From RFC 1035
477 {
478 kDNSType_A = 1, // 1 Address
479 kDNSType_NS, // 2 Name Server
480 kDNSType_MD, // 3 Mail Destination
481 kDNSType_MF, // 4 Mail Forwarder
482 kDNSType_CNAME, // 5 Canonical Name
483 kDNSType_SOA, // 6 Start of Authority
484 kDNSType_MB, // 7 Mailbox
485 kDNSType_MG, // 8 Mail Group
486 kDNSType_MR, // 9 Mail Rename
487 kDNSType_NULL, // 10 NULL RR
488 kDNSType_WKS, // 11 Well-known-service
489 kDNSType_PTR, // 12 Domain name pointer
490 kDNSType_HINFO, // 13 Host information
491 kDNSType_MINFO, // 14 Mailbox information
492 kDNSType_MX, // 15 Mail Exchanger
493 kDNSType_TXT, // 16 Arbitrary text string
494
495 kDNSType_AAAA = 28, // 28 IPv6 address
496 kDNSType_SRV = 33, // 33 Service record
497
498 kDNSQType_ANY = 255 // Not a DNS type, but a DNS query type, meaning "all types"
499 } DNS_TypeValues;
500
501 // ***************************************************************************
502 #if 0
503 #pragma mark - Simple types
504 #endif
505
506 // mDNS defines its own names for these common types to simplify portability across
507 // multiple platforms that may each have their own (different) names for these types.
508 typedef int mDNSBool;
509 typedef signed char mDNSs8;
510 typedef unsigned char mDNSu8;
511 typedef signed short mDNSs16;
512 typedef unsigned short mDNSu16;
513 #if _LP64
514 typedef signed int mDNSs32;
515 typedef unsigned int mDNSu32;
516 #else
517 typedef signed long mDNSs32;
518 typedef unsigned long mDNSu32;
519 #endif
520
521 // To enforce useful type checking, we make mDNSInterfaceID be a pointer to a dummy struct
522 // This way, mDNSInterfaceIDs can be assigned, and compared with each other, but not with other types
523 // Declaring the type to be the typical generic "void *" would lack this type checking
524 typedef struct { void *dummy; } *mDNSInterfaceID;
525
526 // These types are for opaque two- and four-byte identifiers.
527 // The "NotAnInteger" fields of the unions allow the value to be conveniently passed around in a
528 // register for the sake of efficiency, and compared for equality or inequality, but don't forget --
529 // just because it is in a register doesn't mean it is an integer. Operations like greater than,
530 // less than, add, multiply, increment, decrement, etc., are undefined for opaque identifiers,
531 // and if you make the mistake of trying to do those using the NotAnInteger field, then you'll
532 // find you get code that doesn't work consistently on big-endian and little-endian machines.
533 typedef packedunion { mDNSu8 b[2]; mDNSu16 NotAnInteger; } mDNSOpaque16;
534 typedef packedunion { mDNSu8 b[4]; mDNSu32 NotAnInteger; } mDNSOpaque32;
535 typedef packedunion { mDNSu8 b[16]; mDNSu16 w[8]; mDNSu32 l[4]; } mDNSOpaque128;
536
537 typedef mDNSOpaque16 mDNSIPPort; // An IP port is a two-byte opaque identifier (not an integer)
538 typedef mDNSOpaque32 mDNSv4Addr; // An IP address is a four-byte opaque identifier (not an integer)
539 typedef mDNSOpaque128 mDNSv6Addr; // An IPv6 address is a 16-byte opaque identifier (not an integer)
540
541 enum
542 {
543 mDNSAddrType_None = 0,
544 mDNSAddrType_IPv4 = 4,
545 mDNSAddrType_IPv6 = 6,
546 mDNSAddrType_Unknown = ~0 // Special marker value used in known answer list recording
547 };
548
549 typedef struct
550 {
551 mDNSs32 type;
552 union { mDNSv6Addr v6; mDNSv4Addr v4; } ip;
553 } mDNSAddr;
554
555 enum { mDNSfalse = 0, mDNStrue = 1 };
556
557 #define mDNSNULL 0L
558
559 enum
560 {
561 mStatus_Waiting = 1,
562 mStatus_NoError = 0,
563
564 // mDNS return values are in the range FFFE FF00 (-65792) to FFFE FFFF (-65537)
565 // The top end of the range (FFFE FFFF) is used for error codes;
566 // the bottom end of the range (FFFE FF00) is used for non-error values;
567
568 // Error codes:
569 mStatus_UnknownErr = -65537, // 0xFFFE FFFF
570 mStatus_NoSuchNameErr = -65538,
571 mStatus_NoMemoryErr = -65539,
572 mStatus_BadParamErr = -65540,
573 mStatus_BadReferenceErr = -65541,
574 mStatus_BadStateErr = -65542,
575 mStatus_BadFlagsErr = -65543,
576 mStatus_UnsupportedErr = -65544,
577 mStatus_NotInitializedErr = -65545,
578 mStatus_NoCache = -65546,
579 mStatus_AlreadyRegistered = -65547,
580 mStatus_NameConflict = -65548,
581 mStatus_Invalid = -65549,
582 // = -65550,
583 mStatus_Incompatible = -65551,
584 mStatus_BadInterfaceErr = -65552,
585
586 // -65553 - -65789 currently unused
587
588 // Non-error values:
589 mStatus_GrowCache = -65790,
590 mStatus_ConfigChanged = -65791,
591 mStatus_MemFree = -65792 // 0xFFFE FF00
592 };
593
594 typedef mDNSs32 mStatus;
595
596 // RFC 1034/1035 specify that a domain label consists of a length byte plus up to 63 characters
597 #define MAX_DOMAIN_LABEL 63
598 typedef struct { mDNSu8 c[ 64]; } domainlabel; // One label: length byte and up to 63 characters
599
600 // RFC 1034/1035 specify that a domain name, including length bytes, data bytes, and terminating zero, may be up to 255 bytes long
601 #define MAX_DOMAIN_NAME 255
602 typedef struct { mDNSu8 c[256]; } domainname; // Up to 255 bytes of length-prefixed domainlabels
603
604 typedef struct { mDNSu8 c[256]; } UTF8str255; // Null-terminated C string
605
606 // The longest legal textual form of a DNS name is 1005 bytes, including the C-string terminating NULL at the end.
607 // Explanation:
608 // When a native domainname object is converted to printable textual form using ConvertDomainNameToCString(),
609 // non-printing characters are represented in the conventional DNS way, as '\ddd', where ddd is a three-digit decimal number.
610 // The longest legal domain name is 255 bytes, in the form of four labels as shown below:
611 // Length byte, 63 data bytes, length byte, 63 data bytes, length byte, 63 data bytes, length byte, 61 data bytes, zero byte.
612 // Each label is encoded textually as characters followed by a trailing dot.
613 // If every character has to be represented as a four-byte escape sequence, then this makes the maximum textual form four labels
614 // plus the C-string terminating NULL as shown below:
615 // 63*4+1 + 63*4+1 + 63*4+1 + 61*4+1 + 1 = 1005.
616 // Note that MAX_ESCAPED_DOMAIN_LABEL is not normally used: If you're only decoding a single label, escaping is usually not required.
617 // It is for domain names, where dots are used as label separators, that proper escaping is vital.
618 #define MAX_ESCAPED_DOMAIN_LABEL 254
619 #define MAX_ESCAPED_DOMAIN_NAME 1005
620
621 // ***************************************************************************
622 #if 0
623 #pragma mark - Resource Record structures
624 #endif
625
626 // Authoritative Resource Records:
627 // There are four basic types: Shared, Advisory, Unique, Known Unique
628
629 // * Shared Resource Records do not have to be unique
630 // -- Shared Resource Records are used for DNS-SD service PTRs
631 // -- It is okay for several hosts to have RRs with the same name but different RDATA
632 // -- We use a random delay on responses to reduce collisions when all the hosts respond to the same query
633 // -- These RRs typically have moderately high TTLs (e.g. one hour)
634 // -- These records are announced on startup and topology changes for the benefit of passive listeners
635 // -- These records send a goodbye packet when deregistering
636 //
637 // * Advisory Resource Records are like Shared Resource Records, except they don't send a goodbye packet
638 //
639 // * Unique Resource Records should be unique among hosts within any given mDNS scope
640 // -- The majority of Resource Records are of this type
641 // -- If two entities on the network have RRs with the same name but different RDATA, this is a conflict
642 // -- Responses may be sent immediately, because only one host should be responding to any particular query
643 // -- These RRs typically have low TTLs (e.g. ten seconds)
644 // -- On startup and after topology changes, a host issues queries to verify uniqueness
645
646 // * Known Unique Resource Records are treated like Unique Resource Records, except that mDNS does
647 // not have to verify their uniqueness because this is already known by other means (e.g. the RR name
648 // is derived from the host's IP or Ethernet address, which is already known to be a unique identifier).
649
650 // Summary of properties of different record types:
651 // Probe? Does this record type send probes before announcing?
652 // Conflict? Does this record type react if we observe an apparent conflict?
653 // Goodbye? Does this record type send a goodbye packet on departure?
654 //
655 // Probe? Conflict? Goodbye? Notes
656 // Unregistered Should not appear in any list (sanity check value)
657 // Shared No No Yes e.g. Service PTR record
658 // Deregistering No No Yes Shared record about to announce its departure and leave the list
659 // Advisory No No No
660 // Unique Yes Yes No Record intended to be unique -- will probe to verify
661 // Verified Yes Yes No Record has completed probing, and is verified unique
662 // KnownUnique No Yes No Record is assumed by other means to be unique
663
664 // Valid lifecycle of a record:
665 // Unregistered -> Shared -> Deregistering -(goodbye)-> Unregistered
666 // Unregistered -> Advisory -> Unregistered
667 // Unregistered -> Unique -(probe)-> Verified -> Unregistered
668 // Unregistered -> KnownUnique -> Unregistered
669
670 // Each Authoritative kDNSRecordType has only one bit set. This makes it easy to quickly see if a record
671 // is one of a particular set of types simply by performing the appropriate bitwise masking operation.
672
673 // Cache Resource Records (received from the network):
674 // There are four basic types: Answer, Unique Answer, Additional, Unique Additional
675 // Bit 7 (the top bit) of kDNSRecordType is always set for Cache Resource Records; always clear for Authoritative Resource Records
676 // Bit 6 (value 0x40) is set for answer records; clear for additional records
677 // Bit 5 (value 0x20) is set for records received with the kDNSClass_UniqueRRSet
678
679 enum
680 {
681 kDNSRecordTypeUnregistered = 0x00, // Not currently in any list
682 kDNSRecordTypeDeregistering = 0x01, // Shared record about to announce its departure and leave the list
683
684 kDNSRecordTypeUnique = 0x02, // Will become a kDNSRecordTypeVerified when probing is complete
685
686 kDNSRecordTypeAdvisory = 0x04, // Like Shared, but no goodbye packet
687 kDNSRecordTypeShared = 0x08, // Shared means record name does not have to be unique -- use random delay on responses
688 kDNSRecordTypeVerified = 0x10, // Unique means mDNS should check that name is unique (and then send immediate responses)
689 kDNSRecordTypeKnownUnique = 0x20, // Known Unique means mDNS can assume name is unique without checking
690
691 kDNSRecordTypeUniqueMask = (kDNSRecordTypeUnique | kDNSRecordTypeVerified | kDNSRecordTypeKnownUnique),
692 kDNSRecordTypeActiveMask = (kDNSRecordTypeAdvisory | kDNSRecordTypeShared | kDNSRecordTypeVerified | kDNSRecordTypeKnownUnique),
693
694 kDNSRecordTypePacketAdd = 0x80, // Received in the Additional Section of a DNS Response
695 kDNSRecordTypePacketAddUnique = 0xA0, // Received in the Additional Section of a DNS Response with kDNSClass_UniqueRRSet set
696 kDNSRecordTypePacketAns = 0xC0, // Received in the Answer Section of a DNS Response
697 kDNSRecordTypePacketAnsUnique = 0xE0, // Received in the Answer Section of a DNS Response with kDNSClass_UniqueRRSet set
698
699 kDNSRecordTypePacketAnsMask = 0x40, // True for PacketAns and PacketAnsUnique
700 kDNSRecordTypePacketUniqueMask = 0x20 // True for PacketAddUnique and PacketAnsUnique
701 };
702
703 typedef packedstruct { mDNSu16 priority; mDNSu16 weight; mDNSIPPort port; domainname target; } rdataSRV;
704 typedef packedstruct { mDNSu16 preference; domainname exchange; } rdataMX;
705
706 // StandardAuthRDSize is 264 (256+8), which is large enough to hold a maximum-sized SRV record
707 // MaximumRDSize is 8K the absolute maximum we support (at least for now)
708 #define StandardAuthRDSize 264
709 #define MaximumRDSize 8192
710
711 // InlineCacheRDSize is 64
712 // Records received from the network with rdata this size or less have their rdata stored right in the CacheRecord object
713 // Records received from the network with rdata larger than this have additional storage allocated for the rdata
714 // A quick unscientific sample from a busy network at Apple with lots of machines revealed this:
715 // 1461 records in cache
716 // 292 were one-byte TXT records
717 // 136 were four-byte A records
718 // 184 were sixteen-byte AAAA records
719 // 780 were various PTR, TXT and SRV records from 12-64 bytes
720 // Only 69 records had rdata bigger than 64 bytes
721 #define InlineCacheRDSize 64
722
723 typedef union
724 {
725 mDNSu8 data[StandardAuthRDSize];
726 mDNSv4Addr ip; // For 'A' record
727 mDNSv6Addr ipv6; // For 'AAAA' record
728 domainname name; // For PTR and CNAME records
729 UTF8str255 txt; // For TXT record
730 rdataSRV srv; // For SRV record
731 rdataMX mx; // For MX record
732 } RDataBody;
733
734 typedef struct
735 {
736 mDNSu16 MaxRDLength; // Amount of storage allocated for rdata (usually sizeof(RDataBody))
737 RDataBody u;
738 } RData;
739 #define sizeofRDataHeader (sizeof(RData) - sizeof(RDataBody))
740
741 typedef struct AuthRecord_struct AuthRecord;
742 typedef struct CacheRecord_struct CacheRecord;
743 typedef struct ResourceRecord_struct ResourceRecord;
744 typedef struct DNSQuestion_struct DNSQuestion;
745 typedef struct mDNS_struct mDNS;
746 typedef struct mDNS_PlatformSupport_struct mDNS_PlatformSupport;
747
748 // Note: Within an mDNSRecordCallback mDNS all API calls are legal except mDNS_Init(), mDNS_Close(), mDNS_Execute()
749 typedef void mDNSRecordCallback(mDNS *const m, AuthRecord *const rr, mStatus result);
750
751 // Note:
752 // Restrictions: An mDNSRecordUpdateCallback may not make any mDNS API calls.
753 // The intent of this callback is to allow the client to free memory, if necessary.
754 // The internal data structures of the mDNS code may not be in a state where mDNS API calls may be made safely.
755 typedef void mDNSRecordUpdateCallback(mDNS *const m, AuthRecord *const rr, RData *OldRData);
756
757 struct ResourceRecord_struct
758 {
759 mDNSu8 RecordType; // See enum above
760 mDNSInterfaceID InterfaceID; // Set if this RR is specific to one interface
761 // For records received off the wire, InterfaceID is *always* set to the receiving interface
762 // For our authoritative records, InterfaceID is usually zero, except for those few records
763 // that are interface-specific (e.g. address records, especially linklocal addresses)
764 domainname name;
765 mDNSu16 rrtype;
766 mDNSu16 rrclass;
767 mDNSu32 rroriginalttl; // In seconds
768 mDNSu16 rdlength; // Size of the raw rdata, in bytes
769 mDNSu16 rdestimate; // Upper bound on size of rdata after name compression
770 mDNSu32 namehash; // Name-based (i.e. case insensitive) hash of name
771 mDNSu32 rdatahash; // 32-bit hash of the raw rdata
772 mDNSu32 rdnamehash; // Set if this rdata contains a domain name (e.g. PTR, SRV, CNAME etc.)
773 RData *rdata; // Pointer to storage for this rdata
774 };
775
776 struct AuthRecord_struct
777 {
778 // For examples of how to set up this structure for use in mDNS_Register(),
779 // see mDNS_AdvertiseInterface() or mDNS_RegisterService().
780 // Basically, resrec and persistent metadata need to be set up before calling mDNS_Register().
781 // mDNS_SetupResourceRecord() is avaliable as a helper routine to set up most fields to sensible default values for you
782
783 AuthRecord *next; // Next in list; first element of structure for efficiency reasons
784 ResourceRecord resrec;
785
786 // Persistent metadata for Authoritative Records
787 AuthRecord *Additional1; // Recommended additional record to include in response
788 AuthRecord *Additional2; // Another additional
789 AuthRecord *DependentOn; // This record depends on another for its uniqueness checking
790 AuthRecord *RRSet; // This unique record is part of an RRSet
791 mDNSRecordCallback *RecordCallback; // Callback function to call for state changes
792 void *RecordContext; // Context parameter for the callback function
793 mDNSu8 HostTarget; // Set if the target of this record (PTR, CNAME, SRV, etc.) is our host name
794
795 // Transient state for Authoritative Records
796 mDNSu8 Acknowledged; // Set if we've given the success callback to the client
797 mDNSu8 ProbeCount; // Number of probes remaining before this record is valid (kDNSRecordTypeUnique)
798 mDNSu8 AnnounceCount; // Number of announcements remaining (kDNSRecordTypeShared)
799 mDNSu8 IncludeInProbe; // Set if this RR is being put into a probe right now
800 mDNSInterfaceID ImmedAnswer; // Someone on this interface issued a query we need to answer (all-ones for all interfaces)
801 mDNSInterfaceID ImmedAdditional; // Hint that we might want to also send this record, just to be helpful
802 mDNSInterfaceID SendRNow; // The interface this query is being sent on right now
803 mDNSv4Addr v4Requester; // Recent v4 query for this record, or all-ones if more than one recent query
804 mDNSv6Addr v6Requester; // Recent v6 query for this record, or all-ones if more than one recent query
805 AuthRecord *NextResponse; // Link to the next element in the chain of responses to generate
806 const mDNSu8 *NR_AnswerTo; // Set if this record was selected by virtue of being a direct answer to a question
807 AuthRecord *NR_AdditionalTo; // Set if this record was selected by virtue of being additional to another
808 mDNSs32 ThisAPInterval; // In platform time units: Current interval for announce/probe
809 mDNSs32 AnnounceUntil; // In platform time units: Creation time + TTL
810 mDNSs32 LastAPTime; // In platform time units: Last time we sent announcement/probe
811 mDNSs32 LastMCTime; // Last time we multicast this record (used to guard against packet-storm attacks)
812 mDNSInterfaceID LastMCInterface; // Interface this record was multicast on at the time LastMCTime was recorded
813 RData *NewRData; // Set if we are updating this record with new rdata
814 mDNSu16 newrdlength; // ... and the length of the new RData
815 mDNSRecordUpdateCallback *UpdateCallback;
816 mDNSu32 UpdateCredits; // Token-bucket rate limiting of excessive updates
817 mDNSs32 NextUpdateCredit; // Time next token is added to bucket
818 mDNSs32 UpdateBlocked; // Set if update delaying is in effect
819
820 RData rdatastorage; // Normally the storage is right here, except for oversized records
821 // rdatastorage MUST be the last thing in the structure -- when using oversized AuthRecords, extra bytes
822 // are appended after the end of the AuthRecord, logically augmenting the size of the rdatastorage
823 // DO NOT ADD ANY MORE FIELDS HERE
824 };
825
826 struct CacheRecord_struct
827 {
828 CacheRecord *next; // Next in list; first element of structure for efficiency reasons
829 ResourceRecord resrec;
830
831 // Transient state for Cache Records
832 CacheRecord *NextInKAList; // Link to the next element in the chain of known answers to send
833 mDNSs32 TimeRcvd; // In platform time units
834 mDNSs32 NextRequiredQuery; // In platform time units
835 mDNSs32 LastUsed; // In platform time units
836 mDNSu32 UseCount; // Number of times this RR has been used to answer a question
837 DNSQuestion *CRActiveQuestion; // Points to an active question referencing this answer
838 mDNSu32 UnansweredQueries; // Number of times we've issued a query for this record without getting an answer
839 mDNSs32 LastUnansweredTime; // In platform time units; last time we incremented UnansweredQueries
840 mDNSu32 MPUnansweredQ; // Multi-packet query handling: Number of times we've seen a query for this record
841 mDNSs32 MPLastUnansweredQT; // Multi-packet query handling: Last time we incremented MPUnansweredQ
842 mDNSu32 MPUnansweredKA; // Multi-packet query handling: Number of times we've seen this record in a KA list
843 mDNSBool MPExpectingKA; // Multi-packet query handling: Set when we increment MPUnansweredQ; allows one KA
844 CacheRecord *NextInCFList; // Set if this is in the list of records we just received with the cache flush bit set
845
846 struct { mDNSu16 MaxRDLength; mDNSu8 data[InlineCacheRDSize]; } rdatastorage; // Storage for small records is right here
847 };
848
849 typedef struct
850 {
851 CacheRecord r;
852 mDNSu8 _extradata[MaximumRDSize-InlineCacheRDSize]; // Glue on the necessary number of extra bytes
853 } LargeCacheRecord;
854
855 typedef struct NetworkInterfaceInfo_struct NetworkInterfaceInfo;
856
857 struct NetworkInterfaceInfo_struct
858 {
859 // Internal state fields. These are used internally by mDNSCore; the client layer needn't be concerned with them.
860 NetworkInterfaceInfo *next;
861
862 mDNSBool InterfaceActive; // InterfaceActive is set if interface is sending & receiving packets
863 // InterfaceActive is clear if interface is here to represent an address with A
864 // and/or AAAA records, but there is already an earlier representative for this
865 // physical interface which will be used for the actual sending & receiving
866 // packets (this status may change as interfaces are added and removed)
867 mDNSBool IPv4Available; // If InterfaceActive, set if v4 available on this InterfaceID
868 mDNSBool IPv6Available; // If InterfaceActive, set if v6 available on this InterfaceID
869
870 // Standard AuthRecords that every Responder host should have (one per active IP address)
871 AuthRecord RR_A; // 'A' or 'AAAA' (address) record for our ".local" name
872 AuthRecord RR_PTR; // PTR (reverse lookup) record
873 AuthRecord RR_HINFO;
874
875 // Client API fields: The client must set up these fields *before* calling mDNS_RegisterInterface()
876 mDNSInterfaceID InterfaceID;
877 mDNSAddr ip;
878 mDNSBool Advertise; // Set Advertise to false if you are only searching on this interface
879 mDNSBool TxAndRx; // Set to false if not sending and receiving packets on this interface
880 };
881
882 typedef struct ExtraResourceRecord_struct ExtraResourceRecord;
883 struct ExtraResourceRecord_struct
884 {
885 ExtraResourceRecord *next;
886 AuthRecord r;
887 // Note: Add any additional fields *before* the AuthRecord in this structure, not at the end.
888 // In some cases clients can allocate larger chunks of memory and set r->rdata->MaxRDLength to indicate
889 // that this extra memory is available, which would result in any fields after the AuthRecord getting smashed
890 };
891
892 // Note: Within an mDNSServiceCallback mDNS all API calls are legal except mDNS_Init(), mDNS_Close(), mDNS_Execute()
893 typedef struct ServiceRecordSet_struct ServiceRecordSet;
894 typedef void mDNSServiceCallback(mDNS *const m, ServiceRecordSet *const sr, mStatus result);
895 struct ServiceRecordSet_struct
896 {
897 // Internal state fields. These are used internally by mDNSCore; the client layer needn't be concerned with them.
898 // No fields need to be set up by the client prior to calling mDNS_RegisterService();
899 // all required data is passed as parameters to that function.
900 mDNSServiceCallback *ServiceCallback;
901 void *ServiceContext;
902 ExtraResourceRecord *Extras; // Optional list of extra AuthRecords attached to this service registration
903 mDNSu32 NumSubTypes;
904 AuthRecord *SubTypes;
905 mDNSBool Conflict; // Set if this record set was forcibly deregistered because of a conflict
906 domainname Host; // Set if this service record does not use the standard target host name
907 AuthRecord RR_ADV; // e.g. _services._dns-sd._udp.local. PTR _printer._tcp.local.
908 AuthRecord RR_PTR; // e.g. _printer._tcp.local. PTR Name._printer._tcp.local.
909 AuthRecord RR_SRV; // e.g. Name._printer._tcp.local. SRV 0 0 port target
910 AuthRecord RR_TXT; // e.g. Name._printer._tcp.local. TXT PrintQueueName
911 // Don't add any fields after AuthRecord RR_TXT.
912 // This is where the implicit extra space goes if we allocate a ServiceRecordSet containing an oversized RR_TXT record
913 };
914
915 // ***************************************************************************
916 #if 0
917 #pragma mark - Question structures
918 #endif
919
920 // We record the last eight instances of each duplicate query
921 // This gives us v4/v6 on each of Ethernet/AirPort and Firewire, and two free slots "for future expansion"
922 // If the host has more active interfaces that this it is not fatal -- duplicate question suppression will degrade gracefully.
923 // Since we will still remember the last eight, the busiest interfaces will still get the effective duplicate question suppression.
924 #define DupSuppressInfoSize 8
925
926 typedef struct
927 {
928 mDNSs32 Time;
929 mDNSInterfaceID InterfaceID;
930 mDNSs32 Type; // v4 or v6?
931 } DupSuppressInfo;
932
933 // Note: Within an mDNSQuestionCallback mDNS all API calls are legal except mDNS_Init(), mDNS_Close(), mDNS_Execute()
934 typedef void mDNSQuestionCallback(mDNS *const m, DNSQuestion *question, const ResourceRecord *const answer, mDNSBool AddRecord);
935 struct DNSQuestion_struct
936 {
937 // Internal state fields. These are used internally by mDNSCore; the client layer needn't be concerned with them.
938 DNSQuestion *next;
939 mDNSu32 qnamehash;
940 mDNSs32 LastQTime; // Last scheduled transmission of this Q on *all* applicable interfaces
941 mDNSs32 ThisQInterval; // LastQTime + ThisQInterval is the next scheduled transmission of this Q
942 // ThisQInterval > 0 for an active question;
943 // ThisQInterval = 0 for a suspended question that's still in the list
944 // ThisQInterval = -1 for a cancelled question that's been removed from the list
945 mDNSu32 RecentAnswers; // Number of answers since the last time we sent this query
946 mDNSu32 CurrentAnswers; // Number of records currently in the cache that answer this question
947 mDNSu32 LargeAnswers; // Number of answers with rdata > 1024 bytes
948 mDNSu32 UniqueAnswers; // Number of answers received with kDNSClass_UniqueRRSet bit set
949 DNSQuestion *DuplicateOf;
950 DNSQuestion *NextInDQList;
951 DupSuppressInfo DupSuppress[DupSuppressInfoSize];
952 mDNSInterfaceID SendQNow; // The interface this query is being sent on right now
953 mDNSBool SendOnAll; // Set if we're sending this question on all active interfaces
954 mDNSs32 LastQTxTime; // Last time this Q was sent on one (but not necessarily all) interfaces
955
956 // Client API fields: The client must set up these fields *before* calling mDNS_StartQuery()
957 mDNSInterfaceID InterfaceID; // Non-zero if you want to issue link-local queries only on a single specific IP interface
958 domainname qname;
959 mDNSu16 qtype;
960 mDNSu16 qclass;
961 mDNSQuestionCallback *QuestionCallback;
962 void *QuestionContext;
963 };
964
965 typedef struct
966 {
967 // Client API fields: The client must set up name and InterfaceID *before* calling mDNS_StartResolveService()
968 // When the callback is invoked, ip, port, TXTlen and TXTinfo will have been filled in with the results learned from the network.
969 domainname name;
970 mDNSInterfaceID InterfaceID; // ID of the interface the response was received on
971 mDNSAddr ip; // Remote (destination) IP address where this service can be accessed
972 mDNSIPPort port; // Port where this service can be accessed
973 mDNSu16 TXTlen;
974 mDNSu8 TXTinfo[2048]; // Additional demultiplexing information (e.g. LPR queue name)
975 } ServiceInfo;
976
977 // Note: Within an mDNSServiceInfoQueryCallback mDNS all API calls are legal except mDNS_Init(), mDNS_Close(), mDNS_Execute()
978 typedef struct ServiceInfoQuery_struct ServiceInfoQuery;
979 typedef void mDNSServiceInfoQueryCallback(mDNS *const m, ServiceInfoQuery *query);
980 struct ServiceInfoQuery_struct
981 {
982 // Internal state fields. These are used internally by mDNSCore; the client layer needn't be concerned with them.
983 // No fields need to be set up by the client prior to calling mDNS_StartResolveService();
984 // all required data is passed as parameters to that function.
985 // The ServiceInfoQuery structure memory is working storage for mDNSCore to discover the requested information
986 // and place it in the ServiceInfo structure. After the client has called mDNS_StopResolveService(), it may
987 // dispose of the ServiceInfoQuery structure while retaining the results in the ServiceInfo structure.
988 DNSQuestion qSRV;
989 DNSQuestion qTXT;
990 DNSQuestion qAv4;
991 DNSQuestion qAv6;
992 mDNSu8 GotSRV;
993 mDNSu8 GotTXT;
994 mDNSu8 GotADD;
995 mDNSu32 Answers;
996 ServiceInfo *info;
997 mDNSServiceInfoQueryCallback *ServiceInfoQueryCallback;
998 void *ServiceInfoQueryContext;
999 };
1000
1001 // ***************************************************************************
1002 #if 0
1003 #pragma mark - Main mDNS object, used to hold all the mDNS state
1004 #endif
1005
1006 typedef void mDNSCallback(mDNS *const m, mStatus result);
1007
1008 #define CACHE_HASH_SLOTS 499
1009
1010 enum
1011 {
1012 mDNS_KnownBug_PhantomInterfaces = 1
1013 };
1014
1015 struct mDNS_struct
1016 {
1017 // Internal state fields. These hold the main internal state of mDNSCore;
1018 // the client layer needn't be concerned with them.
1019 // No fields need to be set up by the client prior to calling mDNS_Init();
1020 // all required data is passed as parameters to that function.
1021
1022 mDNS_PlatformSupport *p; // Pointer to platform-specific data of indeterminite size
1023 mDNSu32 KnownBugs;
1024 mDNSBool AdvertiseLocalAddresses;
1025 mStatus mDNSPlatformStatus;
1026 mDNSCallback *MainCallback;
1027 void *MainContext;
1028
1029 // For debugging: To catch and report locking failures
1030 mDNSu32 mDNS_busy; // Incremented between mDNS_Lock/mDNS_Unlock section
1031 mDNSu32 mDNS_reentrancy; // Incremented when calling a client callback
1032 mDNSu8 mDNS_shutdown; // Set when we're shutting down, allows us to skip some unnecessary steps
1033 mDNSu8 lock_rrcache; // For debugging: Set at times when these lists may not be modified
1034 mDNSu8 lock_Questions;
1035 mDNSu8 lock_Records;
1036 char MsgBuffer[80]; // Temp storage used while building error log messages
1037
1038 // Task Scheduling variables
1039 mDNSs32 timenow; // The time that this particular activation of the mDNS code started
1040 mDNSs32 timenow_last; // The time the last time we ran
1041 mDNSs32 timenow_adjust; // Correction applied if we ever discover time went backwards
1042 mDNSs32 NextScheduledEvent; // Derived from values below
1043 mDNSs32 SuppressSending; // Don't send *any* packets during this time
1044 mDNSs32 NextCacheCheck; // Next time to refresh cache record before it expires
1045 mDNSs32 NextScheduledQuery; // Next time to send query in its exponential backoff sequence
1046 mDNSs32 NextScheduledProbe; // Next time to probe for new authoritative record
1047 mDNSs32 NextScheduledResponse; // Next time to send authoritative record(s) in responses
1048 mDNSs32 ExpectUnicastResponse; // Set when we send a query with the kDNSQClass_UnicastResponse bit set
1049 mDNSs32 RandomQueryDelay; // For de-synchronization of query packets on the wire
1050 mDNSBool SendDeregistrations; // Set if we need to send deregistrations (immediately)
1051 mDNSBool SendImmediateAnswers; // Set if we need to send answers (immediately -- or as soon as SuppressSending clears)
1052 mDNSBool SleepState; // Set if we're sleeping (send no more packets)
1053
1054 // These fields only required for mDNS Searcher...
1055 DNSQuestion *Questions; // List of all registered questions, active and inactive
1056 DNSQuestion *NewQuestions; // Fresh questions not yet answered from cache
1057 DNSQuestion *CurrentQuestion; // Next question about to be examined in AnswerLocalQuestions()
1058 DNSQuestion *LocalOnlyQuestions; // Questions with InterfaceID set to ~0 ("local only")
1059 DNSQuestion *NewLocalOnlyQuestions; // Fresh local-only questions not yet answered
1060 mDNSu32 rrcache_size; // Total number of available cache entries
1061 mDNSu32 rrcache_totalused; // Number of cache entries currently occupied
1062 mDNSu32 rrcache_active; // Number of cache entries currently occupied by records that answer active questions
1063 mDNSu32 rrcache_report;
1064 CacheRecord *rrcache_free;
1065 CacheRecord *rrcache_hash[CACHE_HASH_SLOTS];
1066 CacheRecord **rrcache_tail[CACHE_HASH_SLOTS];
1067 mDNSu32 rrcache_used[CACHE_HASH_SLOTS];
1068
1069 // Fields below only required for mDNS Responder...
1070 domainlabel nicelabel; // Rich text label encoded using canonically precomposed UTF-8
1071 domainlabel hostlabel; // Conforms to RFC 1034 "letter-digit-hyphen" ARPANET host name rules
1072 domainname hostname; // Host Name, e.g. "Foo.local."
1073 UTF8str255 HIHardware;
1074 UTF8str255 HISoftware;
1075 AuthRecord *ResourceRecords;
1076 AuthRecord *DuplicateRecords; // Records currently 'on hold' because they are duplicates of existing records
1077 AuthRecord *LocalOnlyRecords; // Local records registered with InterfaceID set to ~0 ("local only")
1078 AuthRecord *NewLocalOnlyRecords; // Fresh local-only records not yet delivered to local-only questions
1079 mDNSBool DiscardLocalOnlyRecords;// Set when we have "remove" events we need to deliver to local-only questions
1080 AuthRecord *CurrentRecord; // Next AuthRecord about to be examined
1081 NetworkInterfaceInfo *HostInterfaces;
1082 mDNSs32 ProbeFailTime;
1083 mDNSs32 NumFailedProbes;
1084 mDNSs32 SuppressProbes;
1085 };
1086
1087 // ***************************************************************************
1088 #if 0
1089 #pragma mark - Useful Static Constants
1090 #endif
1091
1092 extern const mDNSIPPort zeroIPPort;
1093 extern const mDNSv4Addr zeroIPAddr;
1094 extern const mDNSv6Addr zerov6Addr;
1095 extern const mDNSv4Addr onesIPv4Addr;
1096 extern const mDNSv6Addr onesIPv6Addr;
1097 extern const mDNSInterfaceID mDNSInterface_Any;
1098
1099 extern const mDNSIPPort UnicastDNSPort;
1100 extern const mDNSIPPort MulticastDNSPort;
1101 extern const mDNSv4Addr AllDNSAdminGroup;
1102 extern const mDNSv4Addr AllDNSLinkGroup;
1103 extern const mDNSv6Addr AllDNSLinkGroupv6;
1104 extern const mDNSAddr AllDNSLinkGroup_v4;
1105 extern const mDNSAddr AllDNSLinkGroup_v6;
1106
1107 // ***************************************************************************
1108 #if 0
1109 #pragma mark - Main Client Functions
1110 #endif
1111
1112 // Every client should call mDNS_Init, passing in storage for the mDNS object, mDNS_PlatformSupport object, and rrcache.
1113 // The rrcachesize parameter is the size of (i.e. number of entries in) the rrcache array passed in.
1114 // Most clients use mDNS_Init_AdvertiseLocalAddresses. This causes mDNSCore to automatically
1115 // create the correct address records for all the hosts interfaces. If you plan to advertise
1116 // services being offered by the local machine, this is almost always what you want.
1117 // There are two cases where you might use mDNS_Init_DontAdvertiseLocalAddresses:
1118 // 1. A client-only device, that browses for services but doesn't advertise any of its own.
1119 // 2. A proxy-registration service, that advertises services being offered by other machines, and takes
1120 // the appropriate steps to manually create the correct address records for those other machines.
1121 // In principle, a proxy-like registration service could manually create address records for its own machine too,
1122 // but this would be pointless extra effort when using mDNS_Init_AdvertiseLocalAddresses does that for you.
1123 //
1124 // When mDNS has finished setting up the client's callback is called
1125 // A client can also spin and poll the mDNSPlatformStatus field to see when it changes from mStatus_Waiting to mStatus_NoError
1126 //
1127 // Call mDNS_Close to tidy up before exiting
1128 //
1129 // Call mDNS_Register with a completed AuthRecord object to register a resource record
1130 // If the resource record type is kDNSRecordTypeUnique (or kDNSknownunique) then if a conflicting resource record is discovered,
1131 // the resource record's mDNSRecordCallback will be called with error code mStatus_NameConflict. The callback should deregister
1132 // the record, and may then try registering the record again after picking a new name (e.g. by automatically appending a number).
1133 //
1134 // Call mDNS_StartQuery to initiate a query. mDNS will proceed to issue Multicast DNS query packets, and any time a response
1135 // is received containing a record which matches the question, the DNSQuestion's mDNSAnswerCallback function will be called
1136 // Call mDNS_StopQuery when no more answers are required
1137 //
1138 // Care should be taken on multi-threaded or interrupt-driven environments.
1139 // The main mDNS routines call mDNSPlatformLock() on entry and mDNSPlatformUnlock() on exit;
1140 // each platform layer needs to implement these appropriately for its respective platform.
1141 // For example, if the support code on a particular platform implements timer callbacks at interrupt time, then
1142 // mDNSPlatformLock/Unlock need to disable interrupts or do similar concurrency control to ensure that the mDNS
1143 // code is not entered by an interrupt-time timer callback while in the middle of processing a client call.
1144
1145 extern mStatus mDNS_Init (mDNS *const m, mDNS_PlatformSupport *const p,
1146 CacheRecord *rrcachestorage, mDNSu32 rrcachesize,
1147 mDNSBool AdvertiseLocalAddresses,
1148 mDNSCallback *Callback, void *Context);
1149 // See notes above on use of NoCache/ZeroCacheSize
1150 #define mDNS_Init_NoCache mDNSNULL
1151 #define mDNS_Init_ZeroCacheSize 0
1152 // See notes above on use of Advertise/DontAdvertiseLocalAddresses
1153 #define mDNS_Init_AdvertiseLocalAddresses mDNStrue
1154 #define mDNS_Init_DontAdvertiseLocalAddresses mDNSfalse
1155 #define mDNS_Init_NoInitCallback mDNSNULL
1156 #define mDNS_Init_NoInitCallbackContext mDNSNULL
1157
1158 extern void mDNS_GrowCache (mDNS *const m, CacheRecord *storage, mDNSu32 numrecords);
1159 extern void mDNS_Close (mDNS *const m);
1160 extern mDNSs32 mDNS_Execute (mDNS *const m);
1161
1162 extern mStatus mDNS_Register (mDNS *const m, AuthRecord *const rr);
1163 extern mStatus mDNS_Update (mDNS *const m, AuthRecord *const rr, mDNSu32 newttl,
1164 const mDNSu16 newrdlength,
1165 RData *const newrdata, mDNSRecordUpdateCallback *Callback);
1166 extern mStatus mDNS_Deregister(mDNS *const m, AuthRecord *const rr);
1167
1168 extern mStatus mDNS_StartQuery(mDNS *const m, DNSQuestion *const question);
1169 extern mStatus mDNS_StopQuery (mDNS *const m, DNSQuestion *const question);
1170 extern mStatus mDNS_Reconfirm (mDNS *const m, CacheRecord *const cacherr);
1171 extern mStatus mDNS_ReconfirmByValue(mDNS *const m, ResourceRecord *const rr);
1172
1173 // ***************************************************************************
1174 #if 0
1175 #pragma mark - Platform support functions that are accessible to the client layer too
1176 #endif
1177
1178 extern mDNSs32 mDNSPlatformOneSecond;
1179 extern mDNSs32 mDNSPlatformTimeNow(void);
1180
1181 // ***************************************************************************
1182 #if 0
1183 #pragma mark - General utility and helper functions
1184 #endif
1185
1186 // mDNS_RegisterService is a single call to register the set of resource records associated with a given named service.
1187 //
1188 // mDNS_StartResolveService is single call which is equivalent to multiple calls to mDNS_StartQuery,
1189 // to find the IP address, port number, and demultiplexing information for a given named service.
1190 // As with mDNS_StartQuery, it executes asynchronously, and calls the ServiceInfoQueryCallback when the answer is
1191 // found. After the service is resolved, the client should call mDNS_StopResolveService to complete the transaction.
1192 // The client can also call mDNS_StopResolveService at any time to abort the transaction.
1193 //
1194 // mDNS_GetBrowseDomains is a special case of the mDNS_StartQuery call, where the resulting answers
1195 // are a list of PTR records indicating (in the rdata) domains that are recommended for browsing.
1196 // After getting the list of domains to browse, call mDNS_StopQuery to end the search.
1197 // mDNS_GetDefaultBrowseDomain returns the name of the domain that should be highlighted by default.
1198 //
1199 // mDNS_GetRegistrationDomains and mDNS_GetDefaultRegistrationDomain are the equivalent calls to get the list
1200 // of one or more domains that should be offered to the user as choices for where they may register their service,
1201 // and the default domain in which to register in the case where the user has made no selection.
1202
1203 extern void mDNS_SetupResourceRecord(AuthRecord *rr, RData *RDataStorage, mDNSInterfaceID InterfaceID,
1204 mDNSu16 rrtype, mDNSu32 ttl, mDNSu8 RecordType, mDNSRecordCallback Callback, void *Context);
1205
1206 extern mStatus mDNS_RegisterService (mDNS *const m, ServiceRecordSet *sr,
1207 const domainlabel *const name, const domainname *const type, const domainname *const domain,
1208 const domainname *const host, mDNSIPPort port, const mDNSu8 txtinfo[], mDNSu16 txtlen,
1209 AuthRecord *SubTypes, mDNSu32 NumSubTypes,
1210 const mDNSInterfaceID InterfaceID, mDNSServiceCallback Callback, void *Context);
1211 extern mStatus mDNS_AddRecordToService(mDNS *const m, ServiceRecordSet *sr, ExtraResourceRecord *extra, RData *rdata, mDNSu32 ttl);
1212 extern mStatus mDNS_RemoveRecordFromService(mDNS *const m, ServiceRecordSet *sr, ExtraResourceRecord *extra);
1213 extern mStatus mDNS_RenameAndReregisterService(mDNS *const m, ServiceRecordSet *const sr, const domainlabel *newname);
1214 extern mStatus mDNS_DeregisterService(mDNS *const m, ServiceRecordSet *sr);
1215
1216 extern mStatus mDNS_RegisterNoSuchService(mDNS *const m, AuthRecord *const rr,
1217 const domainlabel *const name, const domainname *const type, const domainname *const domain,
1218 const domainname *const host,
1219 const mDNSInterfaceID InterfaceID, mDNSRecordCallback Callback, void *Context);
1220 #define mDNS_DeregisterNoSuchService mDNS_Deregister
1221
1222 extern mStatus mDNS_StartBrowse(mDNS *const m, DNSQuestion *const question,
1223 const domainname *const srv, const domainname *const domain,
1224 const mDNSInterfaceID InterfaceID, mDNSQuestionCallback *Callback, void *Context);
1225 #define mDNS_StopBrowse mDNS_StopQuery
1226
1227 extern mStatus mDNS_StartResolveService(mDNS *const m, ServiceInfoQuery *query, ServiceInfo *info, mDNSServiceInfoQueryCallback *Callback, void *Context);
1228 extern void mDNS_StopResolveService (mDNS *const m, ServiceInfoQuery *query);
1229
1230 typedef enum
1231 {
1232 mDNS_DomainTypeBrowse = 0,
1233 mDNS_DomainTypeBrowseDefault = 1,
1234 mDNS_DomainTypeRegistration = 2,
1235 mDNS_DomainTypeRegistrationDefault = 3
1236 } mDNS_DomainType;
1237
1238 extern mStatus mDNS_GetDomains(mDNS *const m, DNSQuestion *const question, mDNS_DomainType DomainType, const mDNSInterfaceID InterfaceID, mDNSQuestionCallback *Callback, void *Context);
1239 // In the Panther mDNSResponder we don't do unicast queries yet, so there's no point trying to do domain enumeration
1240 // mDNS_GetDomains() and mDNS_StopGetDomains() are set to be no-ops so that clients don't try to do browse/register operations that will fail
1241 //#define mDNS_StopGetDomains mDNS_StopQuery
1242 #define mDNS_StopGetDomains(m,q) ((void)(m),(void)(q))
1243 extern mStatus mDNS_AdvertiseDomains(mDNS *const m, AuthRecord *rr, mDNS_DomainType DomainType, const mDNSInterfaceID InterfaceID, char *domname);
1244 #define mDNS_StopAdvertiseDomains mDNS_Deregister
1245
1246 // ***************************************************************************
1247 #if 0
1248 #pragma mark - DNS name utility functions
1249 #endif
1250
1251 // In order to expose the full capabilities of the DNS protocol (which allows any arbitrary eight-bit values
1252 // in domain name labels, including unlikely characters like ascii nulls and even dots) all the mDNS APIs
1253 // work with DNS's native length-prefixed strings. For convenience in C, the following utility functions
1254 // are provided for converting between C's null-terminated strings and DNS's length-prefixed strings.
1255
1256 // Assignment
1257 // A simple C structure assignment of a domainname can cause a protection fault by accessing unmapped memory,
1258 // because that object is defined to be 256 bytes long, but not all domainname objects are truly the full size.
1259 // This macro uses mDNSPlatformMemCopy() to make sure it only touches the actual bytes that are valid.
1260 #define AssignDomainName(DST, SRC) mDNSPlatformMemCopy((SRC).c, (DST).c, DomainNameLength(&(SRC)))
1261
1262 // Comparison functions
1263 extern mDNSBool SameDomainLabel(const mDNSu8 *a, const mDNSu8 *b);
1264 extern mDNSBool SameDomainName(const domainname *const d1, const domainname *const d2);
1265
1266 // Get total length of domain name, in native DNS format, including terminal root label
1267 // (e.g. length of "com." is 5 (length byte, three data bytes, final zero)
1268 extern mDNSu16 DomainNameLength(const domainname *const name);
1269
1270 // Append functions to append one or more labels to an existing native format domain name:
1271 // AppendLiteralLabelString adds a single label from a literal C string, with no escape character interpretation.
1272 // AppendDNSNameString adds zero or more labels from a C string using conventional DNS dots-and-escaping interpretation
1273 // AppendDomainLabel adds a single label from a native format domainlabel
1274 // AppendDomainName adds zero or more labels from a native format domainname
1275 extern mDNSu8 *AppendLiteralLabelString(domainname *const name, const char *cstr);
1276 extern mDNSu8 *AppendDNSNameString (domainname *const name, const char *cstr);
1277 extern mDNSu8 *AppendDomainLabel (domainname *const name, const domainlabel *const label);
1278 extern mDNSu8 *AppendDomainName (domainname *const name, const domainname *const append);
1279
1280 // Convert from null-terminated string to native DNS format:
1281 // The DomainLabel form makes a single label from a literal C string, with no escape character interpretation.
1282 // The DomainName form makes native format domain name from a C string using conventional DNS interpretation:
1283 // dots separate labels, and within each label, '\.' represents a literal dot, '\\' represents a literal
1284 // backslash and backslash with three decimal digits (e.g. \000) represents an arbitrary byte value.
1285 extern mDNSBool MakeDomainLabelFromLiteralString(domainlabel *const label, const char *cstr);
1286 extern mDNSu8 *MakeDomainNameFromDNSNameString (domainname *const name, const char *cstr);
1287
1288 // Convert native format domainlabel or domainname back to C string format
1289 // IMPORTANT:
1290 // When using ConvertDomainLabelToCString, the target buffer must be MAX_ESCAPED_DOMAIN_LABEL (254) bytes long
1291 // to guarantee there will be no buffer overrun. It is only safe to use a buffer shorter than this in rare cases
1292 // where the label is known to be constrained somehow (for example, if the label is known to be either "_tcp" or "_udp").
1293 // Similarly, when using ConvertDomainNameToCString, the target buffer must be MAX_ESCAPED_DOMAIN_NAME (1005) bytes long.
1294 // See definitions of MAX_ESCAPED_DOMAIN_LABEL and MAX_ESCAPED_DOMAIN_NAME for more detailed explanation.
1295 extern char *ConvertDomainLabelToCString_withescape(const domainlabel *const name, char *cstr, char esc);
1296 #define ConvertDomainLabelToCString_unescaped(D,C) ConvertDomainLabelToCString_withescape((D), (C), 0)
1297 #define ConvertDomainLabelToCString(D,C) ConvertDomainLabelToCString_withescape((D), (C), '\\')
1298 extern char *ConvertDomainNameToCString_withescape(const domainname *const name, char *cstr, char esc);
1299 #define ConvertDomainNameToCString_unescaped(D,C) ConvertDomainNameToCString_withescape((D), (C), 0)
1300 #define ConvertDomainNameToCString(D,C) ConvertDomainNameToCString_withescape((D), (C), '\\')
1301
1302 extern void ConvertUTF8PstringToRFC1034HostLabel(const mDNSu8 UTF8Name[], domainlabel *const hostlabel);
1303
1304 extern mDNSu8 *ConstructServiceName(domainname *const fqdn, const domainlabel *name, const domainname *type, const domainname *const domain);
1305 extern mDNSBool DeconstructServiceName(const domainname *const fqdn, domainlabel *const name, domainname *const type, domainname *const domain);
1306
1307 // Note: Some old functions have been replaced by more sensibly-named versions.
1308 // You can uncomment the hash-defines below if you don't want to have to change your source code right away.
1309 // When updating your code, note that (unlike the old versions) *all* the new routines take the target object
1310 // as their first parameter.
1311 //#define ConvertCStringToDomainName(SRC,DST) MakeDomainNameFromDNSNameString((DST),(SRC))
1312 //#define ConvertCStringToDomainLabel(SRC,DST) MakeDomainLabelFromLiteralString((DST),(SRC))
1313 //#define AppendStringLabelToName(DST,SRC) AppendLiteralLabelString((DST),(SRC))
1314 //#define AppendStringNameToName(DST,SRC) AppendDNSNameString((DST),(SRC))
1315 //#define AppendDomainLabelToName(DST,SRC) AppendDomainLabel((DST),(SRC))
1316 //#define AppendDomainNameToName(DST,SRC) AppendDomainName((DST),(SRC))
1317
1318 // ***************************************************************************
1319 #if 0
1320 #pragma mark - Other utility functions
1321 #endif
1322
1323 extern mDNSu32 mDNS_vsnprintf(char *sbuffer, mDNSu32 buflen, const char *fmt, va_list arg);
1324 extern mDNSu32 mDNS_snprintf(char *sbuffer, mDNSu32 buflen, const char *fmt, ...) IS_A_PRINTF_STYLE_FUNCTION(3,4);
1325 extern char *DNSTypeName(mDNSu16 rrtype);
1326 extern char *GetRRDisplayString_rdb(mDNS *const m, const ResourceRecord *rr, RDataBody *rd);
1327 #define GetRRDisplayString(m, rr) GetRRDisplayString_rdb((m), &(rr)->resrec, &(rr)->resrec.rdata->u)
1328 extern mDNSBool mDNSSameAddress(const mDNSAddr *ip1, const mDNSAddr *ip2);
1329 extern void IncrementLabelSuffix(domainlabel *name, mDNSBool RichText);
1330
1331 // ***************************************************************************
1332 #if 0
1333 #pragma mark - PlatformSupport interface
1334 #endif
1335
1336 // This section defines the interface to the Platform Support layer.
1337 // Normal client code should not use any of types defined here, or directly call any of the functions defined here.
1338 // The definitions are placed here because sometimes clients do use these calls indirectly, via other supported client operations.
1339 // For example, AssignDomainName is a macro defined using mDNSPlatformMemCopy()
1340
1341 typedef packedstruct
1342 {
1343 mDNSOpaque16 id;
1344 mDNSOpaque16 flags;
1345 mDNSu16 numQuestions;
1346 mDNSu16 numAnswers;
1347 mDNSu16 numAuthorities;
1348 mDNSu16 numAdditionals;
1349 } DNSMessageHeader;
1350
1351 // We can send and receive packets up to 9000 bytes (Ethernet Jumbo Frame size, if that ever becomes widely used)
1352 // However, in the normal case we try to limit packets to 1500 bytes so that we don't get IP fragmentation on standard Ethernet
1353 // 40 (IPv6 header) + 8 (UDP header) + 12 (DNS message header) + 1440 (DNS message body) = 1500 total
1354 #define AbsoluteMaxDNSMessageData 8940
1355 #define NormalMaxDNSMessageData 1440
1356 typedef packedstruct
1357 {
1358 DNSMessageHeader h; // Note: Size 12 bytes
1359 mDNSu8 data[AbsoluteMaxDNSMessageData]; // 40 (IPv6) + 8 (UDP) + 12 (DNS header) + 8940 (data) = 9000
1360 } DNSMessage;
1361
1362 // Every platform support module must provide the following functions.
1363 // mDNSPlatformInit() typically opens a communication endpoint, and starts listening for mDNS packets.
1364 // When Setup is complete, the platform support layer calls mDNSCoreInitComplete().
1365 // mDNSPlatformSendUDP() sends one UDP packet
1366 // When a packet is received, the PlatformSupport code calls mDNSCoreReceive()
1367 // mDNSPlatformClose() tidies up on exit
1368 // Note: mDNSPlatformMemAllocate/mDNSPlatformMemFree are only required for handling oversized resource records.
1369 // If your target platform has a well-defined specialized application, and you know that all the records it uses
1370 // are InlineCacheRDSize or less, then you can just make a simple mDNSPlatformMemAllocate() stub that always returns
1371 // NULL. InlineCacheRDSize is a compile-time constant, which is set by default to 64. If you need to handle records
1372 // a little larger than this and you don't want to have to implement run-time allocation and freeing, then you
1373 // can raise the value of this constant to a suitable value (at the expense of increased memory usage).
1374 extern mStatus mDNSPlatformInit (mDNS *const m);
1375 extern void mDNSPlatformClose (mDNS *const m);
1376 extern mStatus mDNSPlatformSendUDP(const mDNS *const m, const DNSMessage *const msg, const mDNSu8 *const end,
1377 mDNSInterfaceID InterfaceID, mDNSIPPort srcport, const mDNSAddr *dst, mDNSIPPort dstport);
1378
1379 extern void mDNSPlatformLock (const mDNS *const m);
1380 extern void mDNSPlatformUnlock (const mDNS *const m);
1381
1382 extern void mDNSPlatformStrCopy (const void *src, void *dst);
1383 extern mDNSu32 mDNSPlatformStrLen (const void *src);
1384 extern void mDNSPlatformMemCopy (const void *src, void *dst, mDNSu32 len);
1385 extern mDNSBool mDNSPlatformMemSame (const void *src, const void *dst, mDNSu32 len);
1386 extern void mDNSPlatformMemZero ( void *dst, mDNSu32 len);
1387 extern void * mDNSPlatformMemAllocate (mDNSu32 len);
1388 extern void mDNSPlatformMemFree (void *mem);
1389 extern mStatus mDNSPlatformTimeInit (mDNSs32 *timenow);
1390
1391 // The core mDNS code provides these functions, for the platform support code to call at appropriate times
1392 //
1393 // mDNS_GenerateFQDN() is called once on startup (typically from mDNSPlatformInit())
1394 // and then again on each subsequent change of the dot-local host name.
1395 //
1396 // mDNS_RegisterInterface() is used by the platform support layer to inform mDNSCore of what
1397 // physical and/or logical interfaces are available for sending and receiving packets.
1398 // Typically it is called on startup for each available interface, but register/deregister may be
1399 // called again later, on multiple occasions, to inform the core of interface configuration changes.
1400 // If set->Advertise is set non-zero, then mDNS_RegisterInterface() also registers the standard
1401 // resource records that should be associated with every publicised IP address/interface:
1402 // -- Name-to-address records (A/AAAA)
1403 // -- Address-to-name records (PTR)
1404 // -- Host information (HINFO)
1405 //
1406 // mDNSCoreInitComplete() is called when the platform support layer is finished.
1407 // Typically this is at the end of mDNSPlatformInit(), but may be later
1408 // (on platforms like OT that allow asynchronous initialization of the networking stack).
1409 //
1410 // mDNSCoreReceive() is called when a UDP packet is received
1411 //
1412 // mDNSCoreMachineSleep() is called when the machine sleeps or wakes
1413 // (This refers to heavyweight laptop-style sleep/wake that disables network access,
1414 // not lightweight second-by-second CPU power management modes.)
1415
1416 extern void mDNS_GenerateFQDN(mDNS *const m);
1417 extern mStatus mDNS_RegisterInterface (mDNS *const m, NetworkInterfaceInfo *set);
1418 extern void mDNS_DeregisterInterface(mDNS *const m, NetworkInterfaceInfo *set);
1419 extern void mDNSCoreInitComplete(mDNS *const m, mStatus result);
1420 extern void mDNSCoreReceive(mDNS *const m, DNSMessage *const msg, const mDNSu8 *const end,
1421 const mDNSAddr *const srcaddr, const mDNSIPPort srcport,
1422 const mDNSAddr *const dstaddr, const mDNSIPPort dstport, const mDNSInterfaceID InterfaceID, mDNSu8 ttl);
1423 extern void mDNSCoreMachineSleep(mDNS *const m, mDNSBool wake);
1424
1425 // ***************************************************************************
1426 #if 0
1427 #pragma mark - Compile-Time assertion checks
1428 #endif
1429
1430 // Some C compiler cleverness. We can make the compiler check certain things for
1431 // us, and report compile-time errors if anything is wrong. The usual way to do
1432 // this would be to use a run-time "if" statement, but then you don't find out
1433 // what's wrong until you run the software. This way, if the assertion condition
1434 // is false, the array size is negative, and the complier complains immediately.
1435
1436 struct mDNS_CompileTimeAssertionChecks
1437 {
1438 // Check that the compiler generated our on-the-wire packet format structure definitions
1439 // properly packed, without adding padding bytes to align fields on 32-bit or 64-bit boundaries.
1440 char assert0[(sizeof(rdataSRV) == 262 ) ? 1 : -1];
1441 char assert1[(sizeof(DNSMessageHeader) == 12 ) ? 1 : -1];
1442 char assert2[(sizeof(DNSMessage) == 12+AbsoluteMaxDNSMessageData) ? 1 : -1];
1443 char assert3[(sizeof(mDNSs8) == 1 ) ? 1 : -1];
1444 char assert4[(sizeof(mDNSu8) == 1 ) ? 1 : -1];
1445 char assert5[(sizeof(mDNSs16) == 2 ) ? 1 : -1];
1446 char assert6[(sizeof(mDNSu16) == 2 ) ? 1 : -1];
1447 char assert7[(sizeof(mDNSs32) == 4 ) ? 1 : -1];
1448 char assert8[(sizeof(mDNSu32) == 4 ) ? 1 : -1];
1449 char assert9[(sizeof(mDNSOpaque16) == 2 ) ? 1 : -1];
1450 char assertA[(sizeof(mDNSOpaque32) == 4 ) ? 1 : -1];
1451 char assertB[(sizeof(mDNSOpaque128) == 16 ) ? 1 : -1];
1452 };
1453
1454 // ***************************************************************************
1455
1456 #ifdef __cplusplus
1457 }
1458 #endif
1459
1460 #endif