-
Notifications
You must be signed in to change notification settings - Fork 57
/
mDNSEmbeddedAPI.h
executable file
·3712 lines (3243 loc) · 195 KB
/
mDNSEmbeddedAPI.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* -*- Mode: C; tab-width: 4 -*-
*
* Copyright (c) 2002-2018 Apple Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
NOTE:
If you're building an application that uses DNS Service Discovery
this is probably NOT the header file you're looking for.
In most cases you will want to use /usr/include/dns_sd.h instead.
This header file defines the lowest level raw interface to mDNSCore,
which is appropriate *only* on tiny embedded systems where everything
runs in a single address space and memory is extremely constrained.
All the APIs here are malloc-free, which means that the caller is
responsible for passing in a pointer to the relevant storage that
will be used in the execution of that call, and (when called with
correct parameters) all the calls are guaranteed to succeed. There
is never a case where a call can suffer intermittent failures because
the implementation calls malloc() and sometimes malloc() returns NULL
because memory is so limited that no more is available.
This is primarily for devices that need to have precisely known fixed
memory requirements, with absolutely no uncertainty or run-time variation,
but that certainty comes at a cost of more difficult programming.
For applications running on general-purpose desktop operating systems
(Mac OS, Linux, Solaris, Windows, etc.) the API you should use is
/usr/include/dns_sd.h, which defines the API by which multiple
independent client processes communicate their DNS Service Discovery
requests to a single "mdnsd" daemon running in the background.
Even on platforms that don't run multiple independent processes in
multiple independent address spaces, you can still use the preferred
dns_sd.h APIs by linking in "dnssd_clientshim.c", which implements
the standard "dns_sd.h" API calls, allocates any required storage
using malloc(), and then calls through to the low-level malloc-free
mDNSCore routines defined here. This has the benefit that even though
you're running on a small embedded system with a single address space,
you can still use the exact same client C code as you'd use on a
general-purpose desktop system.
*/
#ifndef __mDNSEmbeddedAPI_h
#define __mDNSEmbeddedAPI_h
#if defined(EFI32) || defined(EFI64) || defined(EFIX64)
// EFI doesn't have stdarg.h unless it's building with GCC.
#include "Tiano.h"
#if !defined(__GNUC__)
#define va_list VA_LIST
#define va_start(a, b) VA_START(a, b)
#define va_end(a) VA_END(a)
#define va_arg(a, b) VA_ARG(a, b)
#endif
#else
#include <stdarg.h> // stdarg.h is required for for va_list support for the mDNS_vsnprintf declaration
#endif
#include "mDNSDebug.h"
#if APPLE_OSX_mDNSResponder
#include <uuid/uuid.h>
#include <TargetConditionals.h>
#endif
#ifdef __cplusplus
extern "C" {
#endif
// ***************************************************************************
// Feature removal compile options & limited resource targets
// The following compile options are responsible for removing certain features from mDNSCore to reduce the
// memory footprint for use in embedded systems with limited resources.
// UNICAST_DISABLED - disables unicast DNS functionality, including Wide Area Bonjour
// ANONYMOUS_DISABLED - disables anonymous functionality
// DNSSEC_DISABLED - disables DNSSEC functionality
// SPC_DISABLED - disables Bonjour Sleep Proxy client
// IDLESLEEPCONTROL_DISABLED - disables sleep control for Bonjour Sleep Proxy clients
// In order to disable the above features pass the option to your compiler, e.g. -D UNICAST_DISABLED
// Additionally, the LIMITED_RESOURCES_TARGET compile option will reduce the maximum DNS message sizes.
#ifdef LIMITED_RESOURCES_TARGET
// Don't support jumbo frames
// 40 (IPv6 header) + 8 (UDP header) + 12 (DNS message header) + 1440 (DNS message body) = 1500 total
#define AbsoluteMaxDNSMessageData 1440
// StandardAuthRDSize is 264 (256+8), which is large enough to hold a maximum-sized SRV record (6 + 256 bytes)
#define MaximumRDSize 264
#endif
#if !defined(MDNSRESPONDER_BTMM_SUPPORT)
#define MDNSRESPONDER_BTMM_SUPPORT 0
#endif
// ***************************************************************************
// Function scope indicators
// If you see "mDNSlocal" before a function name in a C file, it means the function is not callable outside this file
#ifndef mDNSlocal
#define mDNSlocal static
#endif
// If you see "mDNSexport" before a symbol in a C file, it means the symbol is exported for use by clients
// For every "mDNSexport" in a C file, there needs to be a corresponding "extern" declaration in some header file
// (When a C file #includes a header file, the "extern" declarations tell the compiler:
// "This symbol exists -- but not necessarily in this C file.")
#ifndef mDNSexport
#define mDNSexport
#endif
// Explanation: These local/export markers are a little habit of mine for signaling the programmers' intentions.
// When "mDNSlocal" is just a synonym for "static", and "mDNSexport" is a complete no-op, you could be
// forgiven for asking what purpose they serve. The idea is that if you see "mDNSexport" in front of a
// function definition it means the programmer intended it to be exported and callable from other files
// in the project. If you see "mDNSlocal" in front of a function definition it means the programmer
// intended it to be private to that file. If you see neither in front of a function definition it
// means the programmer forgot (so you should work out which it is supposed to be, and fix it).
// Using "mDNSlocal" instead of "static" makes it easier to do a textual searches for one or the other.
// For example you can do a search for "static" to find if any functions declare any local variables as "static"
// (generally a bad idea unless it's also "const", because static storage usually risks being non-thread-safe)
// without the results being cluttered with hundreds of matches for functions declared static.
// - Stuart Cheshire
// ***************************************************************************
// Structure packing macro
// If we're not using GNUC, it's not fatal.
// Most compilers naturally pack the on-the-wire structures correctly anyway, so a plain "struct" is usually fine.
// In the event that structures are not packed correctly, mDNS_Init() will detect this and report an error, so the
// developer will know what's wrong, and can investigate what needs to be done on that compiler to provide proper packing.
#ifndef packedstruct
#if ((__GNUC__ > 2) || ((__GNUC__ == 2) && (__GNUC_MINOR__ >= 9)))
#define packedstruct struct __attribute__((__packed__))
#define packedunion union __attribute__((__packed__))
#else
#define packedstruct struct
#define packedunion union
#endif
#endif
// ***************************************************************************
#if 0
#pragma mark - DNS Resource Record class and type constants
#endif
typedef enum // From RFC 1035
{
kDNSClass_IN = 1, // Internet
kDNSClass_CS = 2, // CSNET
kDNSClass_CH = 3, // CHAOS
kDNSClass_HS = 4, // Hesiod
kDNSClass_NONE = 254, // Used in DNS UPDATE [RFC 2136]
kDNSClass_Mask = 0x7FFF, // Multicast DNS uses the bottom 15 bits to identify the record class...
kDNSClass_UniqueRRSet = 0x8000, // ... and the top bit indicates that all other cached records are now invalid
kDNSQClass_ANY = 255, // Not a DNS class, but a DNS query class, meaning "all classes"
kDNSQClass_UnicastResponse = 0x8000 // Top bit set in a question means "unicast response acceptable"
} DNS_ClassValues;
typedef enum // From RFC 1035
{
kDNSType_A = 1, // 1 Address
kDNSType_NS, // 2 Name Server
kDNSType_MD, // 3 Mail Destination
kDNSType_MF, // 4 Mail Forwarder
kDNSType_CNAME, // 5 Canonical Name
kDNSType_SOA, // 6 Start of Authority
kDNSType_MB, // 7 Mailbox
kDNSType_MG, // 8 Mail Group
kDNSType_MR, // 9 Mail Rename
kDNSType_NULL, // 10 NULL RR
kDNSType_WKS, // 11 Well-known-service
kDNSType_PTR, // 12 Domain name pointer
kDNSType_HINFO, // 13 Host information
kDNSType_MINFO, // 14 Mailbox information
kDNSType_MX, // 15 Mail Exchanger
kDNSType_TXT, // 16 Arbitrary text string
kDNSType_RP, // 17 Responsible person
kDNSType_AFSDB, // 18 AFS cell database
kDNSType_X25, // 19 X_25 calling address
kDNSType_ISDN, // 20 ISDN calling address
kDNSType_RT, // 21 Router
kDNSType_NSAP, // 22 NSAP address
kDNSType_NSAP_PTR, // 23 Reverse NSAP lookup (deprecated)
kDNSType_SIG, // 24 Security signature
kDNSType_KEY, // 25 Security key
kDNSType_PX, // 26 X.400 mail mapping
kDNSType_GPOS, // 27 Geographical position (withdrawn)
kDNSType_AAAA, // 28 IPv6 Address
kDNSType_LOC, // 29 Location Information
kDNSType_NXT, // 30 Next domain (security)
kDNSType_EID, // 31 Endpoint identifier
kDNSType_NIMLOC, // 32 Nimrod Locator
kDNSType_SRV, // 33 Service record
kDNSType_ATMA, // 34 ATM Address
kDNSType_NAPTR, // 35 Naming Authority PoinTeR
kDNSType_KX, // 36 Key Exchange
kDNSType_CERT, // 37 Certification record
kDNSType_A6, // 38 IPv6 Address (deprecated)
kDNSType_DNAME, // 39 Non-terminal DNAME (for IPv6)
kDNSType_SINK, // 40 Kitchen sink (experimental)
kDNSType_OPT, // 41 EDNS0 option (meta-RR)
kDNSType_APL, // 42 Address Prefix List
kDNSType_DS, // 43 Delegation Signer
kDNSType_SSHFP, // 44 SSH Key Fingerprint
kDNSType_IPSECKEY, // 45 IPSECKEY
kDNSType_RRSIG, // 46 RRSIG
kDNSType_NSEC, // 47 Denial of Existence
kDNSType_DNSKEY, // 48 DNSKEY
kDNSType_DHCID, // 49 DHCP Client Identifier
kDNSType_NSEC3, // 50 Hashed Authenticated Denial of Existence
kDNSType_NSEC3PARAM, // 51 Hashed Authenticated Denial of Existence
kDNSType_HIP = 55, // 55 Host Identity Protocol
kDNSType_SPF = 99, // 99 Sender Policy Framework for E-Mail
kDNSType_UINFO, // 100 IANA-Reserved
kDNSType_UID, // 101 IANA-Reserved
kDNSType_GID, // 102 IANA-Reserved
kDNSType_UNSPEC, // 103 IANA-Reserved
kDNSType_TKEY = 249, // 249 Transaction key
kDNSType_TSIG, // 250 Transaction signature
kDNSType_IXFR, // 251 Incremental zone transfer
kDNSType_AXFR, // 252 Transfer zone of authority
kDNSType_MAILB, // 253 Transfer mailbox records
kDNSType_MAILA, // 254 Transfer mail agent records
kDNSQType_ANY // Not a DNS type, but a DNS query type, meaning "all types"
} DNS_TypeValues;
// ***************************************************************************
#if 0
#pragma mark -
#pragma mark - Simple types
#endif
// mDNS defines its own names for these common types to simplify portability across
// multiple platforms that may each have their own (different) names for these types.
typedef unsigned char mDNSBool;
typedef signed char mDNSs8;
typedef unsigned char mDNSu8;
typedef signed short mDNSs16;
typedef unsigned short mDNSu16;
// Source: http://www.unix.org/version2/whatsnew/lp64_wp.html
// http://software.intel.com/sites/products/documentation/hpc/mkl/lin/MKL_UG_structure/Support_for_ILP64_Programming.htm
// It can be safely assumed that int is 32bits on the platform
#if defined(_ILP64) || defined(__ILP64__)
typedef signed int32 mDNSs32;
typedef unsigned int32 mDNSu32;
#else
typedef signed int mDNSs32;
typedef unsigned int mDNSu32;
#endif
// To enforce useful type checking, we make mDNSInterfaceID be a pointer to a dummy struct
// This way, mDNSInterfaceIDs can be assigned, and compared with each other, but not with other types
// Declaring the type to be the typical generic "void *" would lack this type checking
typedef struct mDNSInterfaceID_dummystruct { void *dummy; } *mDNSInterfaceID;
// These types are for opaque two- and four-byte identifiers.
// The "NotAnInteger" fields of the unions allow the value to be conveniently passed around in a
// register for the sake of efficiency, and compared for equality or inequality, but don't forget --
// just because it is in a register doesn't mean it is an integer. Operations like greater than,
// less than, add, multiply, increment, decrement, etc., are undefined for opaque identifiers,
// and if you make the mistake of trying to do those using the NotAnInteger field, then you'll
// find you get code that doesn't work consistently on big-endian and little-endian machines.
#if defined(_WIN32)
#pragma pack(push,2)
#endif
typedef union { mDNSu8 b[ 2]; mDNSu16 NotAnInteger; } mDNSOpaque16;
typedef union { mDNSu8 b[ 4]; mDNSu32 NotAnInteger; } mDNSOpaque32;
typedef packedunion { mDNSu8 b[ 6]; mDNSu16 w[3]; mDNSu32 l[1]; } mDNSOpaque48;
typedef union { mDNSu8 b[ 8]; mDNSu16 w[4]; mDNSu32 l[2]; } mDNSOpaque64;
typedef union { mDNSu8 b[16]; mDNSu16 w[8]; mDNSu32 l[4]; } mDNSOpaque128;
#if defined(_WIN32)
#pragma pack(pop)
#endif
typedef mDNSOpaque16 mDNSIPPort; // An IP port is a two-byte opaque identifier (not an integer)
typedef mDNSOpaque32 mDNSv4Addr; // An IP address is a four-byte opaque identifier (not an integer)
typedef mDNSOpaque128 mDNSv6Addr; // An IPv6 address is a 16-byte opaque identifier (not an integer)
typedef mDNSOpaque48 mDNSEthAddr; // An Ethernet address is a six-byte opaque identifier (not an integer)
// Bit operations for opaque 64 bit quantity. Uses the 32 bit quantity(l[2]) to set and clear bits
#define mDNSNBBY 8
#define bit_set_opaque64(op64, index) (op64.l[((index))/(sizeof(mDNSu32) * mDNSNBBY)] |= (1 << ((index) % (sizeof(mDNSu32) * mDNSNBBY))))
#define bit_clr_opaque64(op64, index) (op64.l[((index))/(sizeof(mDNSu32) * mDNSNBBY)] &= ~(1 << ((index) % (sizeof(mDNSu32) * mDNSNBBY))))
#define bit_get_opaque64(op64, index) (op64.l[((index))/(sizeof(mDNSu32) * mDNSNBBY)] & (1 << ((index) % (sizeof(mDNSu32) * mDNSNBBY))))
// Bit operations for opaque 128 bit quantity. Uses the 32 bit quantity(l[4]) to set and clear bits
#define bit_set_opaque128(op128, index) (op128.l[((index))/(sizeof(mDNSu32) * mDNSNBBY)] |= (1 << ((index) % (sizeof(mDNSu32) * mDNSNBBY))))
#define bit_clr_opaque128(op128, index) (op128.l[((index))/(sizeof(mDNSu32) * mDNSNBBY)] &= ~(1 << ((index) % (sizeof(mDNSu32) * mDNSNBBY))))
#define bit_get_opaque128(op128, index) (op128.l[((index))/(sizeof(mDNSu32) * mDNSNBBY)] & (1 << ((index) % (sizeof(mDNSu32) * mDNSNBBY))))
typedef enum
{
mDNSAddrType_None = 0,
mDNSAddrType_IPv4 = 4,
mDNSAddrType_IPv6 = 6,
mDNSAddrType_Unknown = ~0 // Special marker value used in known answer list recording
} mDNSAddr_Type;
typedef enum
{
mDNSTransport_None = 0,
mDNSTransport_UDP = 1,
mDNSTransport_TCP = 2
} mDNSTransport_Type;
typedef struct
{
mDNSs32 type;
union { mDNSv6Addr v6; mDNSv4Addr v4; } ip;
} mDNSAddr;
enum { mDNSfalse = 0, mDNStrue = 1 };
#define mDNSNULL 0L
enum
{
mStatus_Waiting = 1,
mStatus_NoError = 0,
// mDNS return values are in the range FFFE FF00 (-65792) to FFFE FFFF (-65537)
// The top end of the range (FFFE FFFF) is used for error codes;
// the bottom end of the range (FFFE FF00) is used for non-error values;
// Error codes:
mStatus_UnknownErr = -65537, // First value: 0xFFFE FFFF
mStatus_NoSuchNameErr = -65538,
mStatus_NoMemoryErr = -65539,
mStatus_BadParamErr = -65540,
mStatus_BadReferenceErr = -65541,
mStatus_BadStateErr = -65542,
mStatus_BadFlagsErr = -65543,
mStatus_UnsupportedErr = -65544,
mStatus_NotInitializedErr = -65545,
mStatus_NoCache = -65546,
mStatus_AlreadyRegistered = -65547,
mStatus_NameConflict = -65548,
mStatus_Invalid = -65549,
mStatus_Firewall = -65550,
mStatus_Incompatible = -65551,
mStatus_BadInterfaceErr = -65552,
mStatus_Refused = -65553,
mStatus_NoSuchRecord = -65554,
mStatus_NoAuth = -65555,
mStatus_NoSuchKey = -65556,
mStatus_NATTraversal = -65557,
mStatus_DoubleNAT = -65558,
mStatus_BadTime = -65559,
mStatus_BadSig = -65560, // while we define this per RFC 2845, BIND 9 returns Refused for bad/missing signatures
mStatus_BadKey = -65561,
mStatus_TransientErr = -65562, // transient failures, e.g. sending packets shortly after a network transition or wake from sleep
mStatus_ServiceNotRunning = -65563, // Background daemon not running
mStatus_NATPortMappingUnsupported = -65564, // NAT doesn't support PCP, NAT-PMP or UPnP
mStatus_NATPortMappingDisabled = -65565, // NAT supports PCP, NAT-PMP or UPnP, but it's disabled by the administrator
mStatus_NoRouter = -65566,
mStatus_PollingMode = -65567,
mStatus_Timeout = -65568,
mStatus_HostUnreachErr = -65569,
// -65570 to -65786 currently unused; available for allocation
// tcp connection status
mStatus_ConnPending = -65787,
mStatus_ConnFailed = -65788,
mStatus_ConnEstablished = -65789,
// Non-error values:
mStatus_GrowCache = -65790,
mStatus_ConfigChanged = -65791,
mStatus_MemFree = -65792 // Last value: 0xFFFE FF00
// mStatus_MemFree is the last legal mDNS error code, at the end of the range allocated for mDNS
};
typedef mDNSs32 mStatus;
#define MaxIp 5 // Needs to be consistent with MaxInputIf in dns_services.h
typedef enum { q_stop = 0, q_start } q_state;
typedef enum { reg_stop = 0, reg_start } reg_state;
// RFC 1034/1035 specify that a domain label consists of a length byte plus up to 63 characters
#define MAX_DOMAIN_LABEL 63
typedef struct { mDNSu8 c[ 64]; } domainlabel; // One label: length byte and up to 63 characters
// RFC 1034/1035/2181 specify that a domain name (length bytes and data bytes) may be up to 255 bytes long,
// plus the terminating zero at the end makes 256 bytes total in the on-the-wire format.
#define MAX_DOMAIN_NAME 256
typedef struct { mDNSu8 c[256]; } domainname; // Up to 256 bytes of length-prefixed domainlabels
typedef struct { mDNSu8 c[256]; } UTF8str255; // Null-terminated C string
// The longest legal textual form of a DNS name is 1009 bytes, including the C-string terminating NULL at the end.
// Explanation:
// When a native domainname object is converted to printable textual form using ConvertDomainNameToCString(),
// non-printing characters are represented in the conventional DNS way, as '\ddd', where ddd is a three-digit decimal number.
// The longest legal domain name is 256 bytes, in the form of four labels as shown below:
// Length byte, 63 data bytes, length byte, 63 data bytes, length byte, 63 data bytes, length byte, 62 data bytes, zero byte.
// Each label is encoded textually as characters followed by a trailing dot.
// If every character has to be represented as a four-byte escape sequence, then this makes the maximum textual form four labels
// plus the C-string terminating NULL as shown below:
// 63*4+1 + 63*4+1 + 63*4+1 + 62*4+1 + 1 = 1009.
// Note that MAX_ESCAPED_DOMAIN_LABEL is not normally used: If you're only decoding a single label, escaping is usually not required.
// It is for domain names, where dots are used as label separators, that proper escaping is vital.
#define MAX_ESCAPED_DOMAIN_LABEL 254
#define MAX_ESCAPED_DOMAIN_NAME 1009
// MAX_REVERSE_MAPPING_NAME
// For IPv4: "123.123.123.123.in-addr.arpa." 30 bytes including terminating NUL
// For IPv6: "x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.ip6.arpa." 74 bytes including terminating NUL
#define MAX_REVERSE_MAPPING_NAME_V4 30
#define MAX_REVERSE_MAPPING_NAME_V6 74
#define MAX_REVERSE_MAPPING_NAME 74
// Most records have a TTL of 75 minutes, so that their 80% cache-renewal query occurs once per hour.
// For records containing a hostname (in the name on the left, or in the rdata on the right),
// like A, AAAA, reverse-mapping PTR, and SRV, we use a two-minute TTL by default, because we don't want
// them to hang around for too long in the cache if the host in question crashes or otherwise goes away.
#define kStandardTTL (3600UL * 100 / 80)
#define kHostNameTTL 120UL
// Some applications want to register their SRV records with a lower ttl so that in case the server
// using a dynamic port number restarts, the clients will not have stale information for more than
// 10 seconds
#define kHostNameSmallTTL 10UL
// Multicast DNS uses announcements (gratuitous responses) to update peer caches.
// This means it is feasible to use relatively larger TTL values than we might otherwise
// use, because we have a cache coherency protocol to keep the peer caches up to date.
// With Unicast DNS, once an authoritative server gives a record with a certain TTL value to a client
// or caching server, that client or caching server is entitled to hold onto the record until its TTL
// expires, and has no obligation to contact the authoritative server again until that time arrives.
// This means that whereas Multicast DNS can use announcements to pre-emptively update stale data
// before it would otherwise have expired, standard Unicast DNS (not using LLQs) has no equivalent
// mechanism, and TTL expiry is the *only* mechanism by which stale data gets deleted. Because of this,
// we currently limit the TTL to ten seconds in such cases where no dynamic cache updating is possible.
#define kStaticCacheTTL 10
#define DefaultTTLforRRType(X) (((X) == kDNSType_A || (X) == kDNSType_AAAA || (X) == kDNSType_SRV) ? kHostNameTTL : kStandardTTL)
#define mDNS_KeepaliveRecord(rr) ((rr)->rrtype == kDNSType_NULL && SameDomainLabel(SecondLabel((rr)->name)->c, (mDNSu8 *)"\x0A_keepalive"))
// Number of times keepalives are sent if no ACK is received before waking up the system
// this is analogous to net.inet.tcp.keepcnt
#define kKeepaliveRetryCount 10
// The frequency at which keepalives are retried if no ACK is received
#define kKeepaliveRetryInterval 30
typedef struct AuthRecord_struct AuthRecord;
typedef struct ServiceRecordSet_struct ServiceRecordSet;
typedef struct CacheRecord_struct CacheRecord;
typedef struct CacheGroup_struct CacheGroup;
typedef struct AuthGroup_struct AuthGroup;
typedef struct DNSQuestion_struct DNSQuestion;
typedef struct ZoneData_struct ZoneData;
typedef struct mDNS_struct mDNS;
typedef struct mDNS_PlatformSupport_struct mDNS_PlatformSupport;
typedef struct NATTraversalInfo_struct NATTraversalInfo;
typedef struct ResourceRecord_struct ResourceRecord;
// Structure to abstract away the differences between TCP/SSL sockets, and one for UDP sockets
// The actual definition of these structures appear in the appropriate platform support code
typedef struct TCPSocket_struct TCPSocket;
typedef struct UDPSocket_struct UDPSocket;
// ***************************************************************************
#if 0
#pragma mark -
#pragma mark - DNS Message structures
#endif
#define mDNS_numZones numQuestions
#define mDNS_numPrereqs numAnswers
#define mDNS_numUpdates numAuthorities
typedef struct
{
mDNSOpaque16 id;
mDNSOpaque16 flags;
mDNSu16 numQuestions;
mDNSu16 numAnswers;
mDNSu16 numAuthorities;
mDNSu16 numAdditionals;
} DNSMessageHeader;
// We can send and receive packets up to 9000 bytes (Ethernet Jumbo Frame size, if that ever becomes widely used)
// However, in the normal case we try to limit packets to 1500 bytes so that we don't get IP fragmentation on standard Ethernet
// 40 (IPv6 header) + 8 (UDP header) + 12 (DNS message header) + 1440 (DNS message body) = 1500 total
#ifndef AbsoluteMaxDNSMessageData
#define AbsoluteMaxDNSMessageData 8940
#endif
#define NormalMaxDNSMessageData 1440
typedef struct
{
DNSMessageHeader h; // Note: Size 12 bytes
mDNSu8 data[AbsoluteMaxDNSMessageData]; // 40 (IPv6) + 8 (UDP) + 12 (DNS header) + 8940 (data) = 9000
} DNSMessage;
typedef struct tcpInfo_t
{
mDNS *m;
TCPSocket *sock;
DNSMessage request;
int requestLen;
DNSQuestion *question; // For queries
AuthRecord *rr; // For record updates
mDNSAddr Addr;
mDNSIPPort Port;
mDNSIPPort SrcPort;
DNSMessage *reply;
mDNSu16 replylen;
unsigned long nread;
int numReplies;
} tcpInfo_t;
// ***************************************************************************
#if 0
#pragma mark -
#pragma mark - Other Packet Format Structures
#endif
typedef packedstruct
{
mDNSEthAddr dst;
mDNSEthAddr src;
mDNSOpaque16 ethertype;
} EthernetHeader; // 14 bytes
typedef packedstruct
{
mDNSOpaque16 hrd;
mDNSOpaque16 pro;
mDNSu8 hln;
mDNSu8 pln;
mDNSOpaque16 op;
mDNSEthAddr sha;
mDNSv4Addr spa;
mDNSEthAddr tha;
mDNSv4Addr tpa;
} ARP_EthIP; // 28 bytes
typedef packedstruct
{
mDNSu8 vlen;
mDNSu8 tos;
mDNSOpaque16 totlen;
mDNSOpaque16 id;
mDNSOpaque16 flagsfrags;
mDNSu8 ttl;
mDNSu8 protocol; // Payload type: 0x06 = TCP, 0x11 = UDP
mDNSu16 checksum;
mDNSv4Addr src;
mDNSv4Addr dst;
} IPv4Header; // 20 bytes
typedef packedstruct
{
mDNSu32 vcf; // Version, Traffic Class, Flow Label
mDNSu16 len; // Payload Length
mDNSu8 pro; // Type of next header: 0x06 = TCP, 0x11 = UDP, 0x3A = ICMPv6
mDNSu8 ttl; // Hop Limit
mDNSv6Addr src;
mDNSv6Addr dst;
} IPv6Header; // 40 bytes
typedef packedstruct
{
mDNSv6Addr src;
mDNSv6Addr dst;
mDNSOpaque32 len;
mDNSOpaque32 pro;
} IPv6PseudoHeader; // 40 bytes
typedef union
{
mDNSu8 bytes[20];
ARP_EthIP arp;
IPv4Header v4;
IPv6Header v6;
} NetworkLayerPacket;
typedef packedstruct
{
mDNSIPPort src;
mDNSIPPort dst;
mDNSu32 seq;
mDNSu32 ack;
mDNSu8 offset;
mDNSu8 flags;
mDNSu16 window;
mDNSu16 checksum;
mDNSu16 urgent;
} TCPHeader; // 20 bytes; IP protocol type 0x06
typedef struct
{
mDNSInterfaceID IntfId;
mDNSu32 seq;
mDNSu32 ack;
mDNSu16 window;
} mDNSTCPInfo;
typedef packedstruct
{
mDNSIPPort src;
mDNSIPPort dst;
mDNSu16 len; // Length including UDP header (i.e. minimum value is 8 bytes)
mDNSu16 checksum;
} UDPHeader; // 8 bytes; IP protocol type 0x11
typedef struct
{
mDNSu8 type; // 0x87 == Neighbor Solicitation, 0x88 == Neighbor Advertisement
mDNSu8 code;
mDNSu16 checksum;
mDNSu32 flags_res; // R/S/O flags and reserved bits
mDNSv6Addr target;
// Typically 8 bytes of options are also present
} IPv6NDP; // 24 bytes or more; IP protocol type 0x3A
typedef struct
{
mDNSAddr ipaddr;
char ethaddr[18];
} IPAddressMACMapping;
#define NDP_Sol 0x87
#define NDP_Adv 0x88
#define NDP_Router 0x80
#define NDP_Solicited 0x40
#define NDP_Override 0x20
#define NDP_SrcLL 1
#define NDP_TgtLL 2
typedef union
{
mDNSu8 bytes[20];
TCPHeader tcp;
UDPHeader udp;
IPv6NDP ndp;
} TransportLayerPacket;
typedef packedstruct
{
mDNSOpaque64 InitiatorCookie;
mDNSOpaque64 ResponderCookie;
mDNSu8 NextPayload;
mDNSu8 Version;
mDNSu8 ExchangeType;
mDNSu8 Flags;
mDNSOpaque32 MessageID;
mDNSu32 Length;
} IKEHeader; // 28 bytes
// ***************************************************************************
#if 0
#pragma mark -
#pragma mark - Resource Record structures
#endif
// Authoritative Resource Records:
// There are four basic types: Shared, Advisory, Unique, Known Unique
// * Shared Resource Records do not have to be unique
// -- Shared Resource Records are used for DNS-SD service PTRs
// -- It is okay for several hosts to have RRs with the same name but different RDATA
// -- We use a random delay on responses to reduce collisions when all the hosts respond to the same query
// -- These RRs typically have moderately high TTLs (e.g. one hour)
// -- These records are announced on startup and topology changes for the benefit of passive listeners
// -- These records send a goodbye packet when deregistering
//
// * Advisory Resource Records are like Shared Resource Records, except they don't send a goodbye packet
//
// * Unique Resource Records should be unique among hosts within any given mDNS scope
// -- The majority of Resource Records are of this type
// -- If two entities on the network have RRs with the same name but different RDATA, this is a conflict
// -- Responses may be sent immediately, because only one host should be responding to any particular query
// -- These RRs typically have low TTLs (e.g. a few minutes)
// -- On startup and after topology changes, a host issues queries to verify uniqueness
// * Known Unique Resource Records are treated like Unique Resource Records, except that mDNS does
// not have to verify their uniqueness because this is already known by other means (e.g. the RR name
// is derived from the host's IP or Ethernet address, which is already known to be a unique identifier).
// Summary of properties of different record types:
// Probe? Does this record type send probes before announcing?
// Conflict? Does this record type react if we observe an apparent conflict?
// Goodbye? Does this record type send a goodbye packet on departure?
//
// Probe? Conflict? Goodbye? Notes
// Unregistered Should not appear in any list (sanity check value)
// Shared No No Yes e.g. Service PTR record
// Deregistering No No Yes Shared record about to announce its departure and leave the list
// Advisory No No No
// Unique Yes Yes No Record intended to be unique -- will probe to verify
// Verified Yes Yes No Record has completed probing, and is verified unique
// KnownUnique No Yes No Record is assumed by other means to be unique
// Valid lifecycle of a record:
// Unregistered -> Shared -> Deregistering -(goodbye)-> Unregistered
// Unregistered -> Advisory -> Unregistered
// Unregistered -> Unique -(probe)-> Verified -> Unregistered
// Unregistered -> KnownUnique -> Unregistered
// Each Authoritative kDNSRecordType has only one bit set. This makes it easy to quickly see if a record
// is one of a particular set of types simply by performing the appropriate bitwise masking operation.
// Cache Resource Records (received from the network):
// There are four basic types: Answer, Unique Answer, Additional, Unique Additional
// Bit 7 (the top bit) of kDNSRecordType is always set for Cache Resource Records; always clear for Authoritative Resource Records
// Bit 6 (value 0x40) is set for answer records; clear for authority/additional records
// Bit 5 (value 0x20) is set for records received with the kDNSClass_UniqueRRSet
typedef enum
{
kDNSRecordTypeUnregistered = 0x00, // Not currently in any list
kDNSRecordTypeDeregistering = 0x01, // Shared record about to announce its departure and leave the list
kDNSRecordTypeUnique = 0x02, // Will become a kDNSRecordTypeVerified when probing is complete
kDNSRecordTypeAdvisory = 0x04, // Like Shared, but no goodbye packet
kDNSRecordTypeShared = 0x08, // Shared means record name does not have to be unique -- use random delay on responses
kDNSRecordTypeVerified = 0x10, // Unique means mDNS should check that name is unique (and then send immediate responses)
kDNSRecordTypeKnownUnique = 0x20, // Known Unique means mDNS can assume name is unique without checking
// For Dynamic Update records, Known Unique means the record must already exist on the server.
kDNSRecordTypeUniqueMask = (kDNSRecordTypeUnique | kDNSRecordTypeVerified | kDNSRecordTypeKnownUnique),
kDNSRecordTypeActiveSharedMask = (kDNSRecordTypeAdvisory | kDNSRecordTypeShared),
kDNSRecordTypeActiveUniqueMask = (kDNSRecordTypeVerified | kDNSRecordTypeKnownUnique),
kDNSRecordTypeActiveMask = (kDNSRecordTypeActiveSharedMask | kDNSRecordTypeActiveUniqueMask),
kDNSRecordTypePacketAdd = 0x80, // Received in the Additional Section of a DNS Response
kDNSRecordTypePacketAddUnique = 0x90, // Received in the Additional Section of a DNS Response with kDNSClass_UniqueRRSet set
kDNSRecordTypePacketAuth = 0xA0, // Received in the Authorities Section of a DNS Response
kDNSRecordTypePacketAuthUnique = 0xB0, // Received in the Authorities Section of a DNS Response with kDNSClass_UniqueRRSet set
kDNSRecordTypePacketAns = 0xC0, // Received in the Answer Section of a DNS Response
kDNSRecordTypePacketAnsUnique = 0xD0, // Received in the Answer Section of a DNS Response with kDNSClass_UniqueRRSet set
kDNSRecordTypePacketNegative = 0xF0, // Pseudo-RR generated to cache non-existence results like NXDomain
kDNSRecordTypePacketUniqueMask = 0x10 // True for PacketAddUnique, PacketAnsUnique, PacketAuthUnique, kDNSRecordTypePacketNegative
} kDNSRecordTypes;
typedef packedstruct { mDNSu16 priority; mDNSu16 weight; mDNSIPPort port; domainname target; } rdataSRV;
typedef packedstruct { mDNSu16 preference; domainname exchange; } rdataMX;
typedef packedstruct { domainname mbox; domainname txt; } rdataRP;
typedef packedstruct { mDNSu16 preference; domainname map822; domainname mapx400; } rdataPX;
typedef packedstruct
{
domainname mname;
domainname rname;
mDNSs32 serial; // Modular counter; increases when zone changes
mDNSu32 refresh; // Time in seconds that a slave waits after successful replication of the database before it attempts replication again
mDNSu32 retry; // Time in seconds that a slave waits after an unsuccessful replication attempt before it attempts replication again
mDNSu32 expire; // Time in seconds that a slave holds on to old data while replication attempts remain unsuccessful
mDNSu32 min; // Nominally the minimum record TTL for this zone, in seconds; also used for negative caching.
} rdataSOA;
// http://www.iana.org/assignments/dns-sec-alg-numbers/dns-sec-alg-numbers.xhtml
// Algorithm used for RRSIG, DS and DNS KEY
#define CRYPTO_RSA_SHA1 0x05
#define CRYPTO_DSA_NSEC3_SHA1 0x06
#define CRYPTO_RSA_NSEC3_SHA1 0x07
#define CRYPTO_RSA_SHA256 0x08
#define CRYPTO_RSA_SHA512 0x0A
#define CRYPTO_ALG_MAX 0x0B
// alg - same as in RRSIG, DNS KEY or DS.
// RFC 4034 defines SHA1
// RFC 4509 defines SHA256
// Note: NSEC3 also uses 1 for SHA1 and hence we will reuse for now till a new
// value is assigned.
//
#define SHA1_DIGEST_TYPE 1
#define SHA256_DIGEST_TYPE 2
#define DIGEST_TYPE_MAX 3
// We need support for base64 and base32 encoding for displaying KEY, NSEC3
// To make this platform agnostic, we define two types which the platform
// needs to support
#define ENC_BASE32 1
#define ENC_BASE64 2
#define ENC_ALG_MAX 3
#define DS_FIXED_SIZE 4
typedef packedstruct
{
mDNSu16 keyTag;
mDNSu8 alg;
mDNSu8 digestType;
mDNSu8 *digest;
} rdataDS;
typedef struct TrustAnchor
{
struct TrustAnchor *next;
int digestLen;
mDNSu32 validFrom;
mDNSu32 validUntil;
domainname zone;
rdataDS rds;
} TrustAnchor;
//size of rdataRRSIG excluding signerName and signature (which are variable fields)
#define RRSIG_FIXED_SIZE 18
typedef struct
{
mDNSu16 typeCovered;
mDNSu8 alg;
mDNSu8 labels;
mDNSu32 origTTL;
mDNSu32 sigExpireTime;
mDNSu32 sigInceptTime;
mDNSu16 keyTag;
mDNSu8 signerName[1]; // signerName is a dynamically-sized array
// mDNSu8 *signature
} rdataRRSig;
// RFC 4034: For DNS Key RR
// flags - the valid value for DNSSEC is 256 (Zone signing key - ZSK) and 257 (Secure Entry Point) which also
// includes the ZSK bit
//
#define DNSKEY_ZONE_SIGN_KEY 0x100
#define DNSKEY_SECURE_ENTRY_POINT 0x101
// proto - the only valid value for protocol is 3 (See RFC 4034)
#define DNSKEY_VALID_PROTO_VALUE 0x003
// alg - The only mandatory algorithm that we support is RSA/SHA-1
// DNSSEC_RSA_SHA1_ALG
#define DNSKEY_FIXED_SIZE 4
typedef packedstruct
{
mDNSu16 flags;
mDNSu8 proto;
mDNSu8 alg;
mDNSu8 *data;
} rdataDNSKey;
#define NSEC3_FIXED_SIZE 5
#define NSEC3_FLAGS_OPTOUT 1
#define NSEC3_MAX_ITERATIONS 2500
typedef packedstruct
{
mDNSu8 alg;
mDNSu8 flags;
mDNSu16 iterations;
mDNSu8 saltLength;
mDNSu8 *salt;
// hashLength, nxt, bitmap
} rdataNSEC3;
// In the multicast usage of NSEC3, we know the actual size of RData
// 4 bytes : HashAlg, Flags,Iterations
// 5 bytes : Salt Length 1 byte, Salt 4 bytes
// 21 bytes : HashLength 1 byte, Hash 20 bytes
// 34 bytes : Window number, Bitmap length, Type bit map to include the first 256 types
#define MCAST_NSEC3_RDLENGTH (4 + 5 + 21 + 34)
#define SHA1_HASH_LENGTH 20
// Base32 encoding takes 5 bytes of the input and encodes as 8 bytes of output.
// For example, SHA-1 hash of 20 bytes will be encoded as 20/5 * 8 = 32 base32
// bytes. For a max domain name size of 255 bytes of base32 encoding : (255/8)*5
// is the max hash length possible.
#define NSEC3_MAX_HASH_LEN 155
// In NSEC3, the names are hashed and stored in the first label and hence cannot exceed label
// size.
#define NSEC3_MAX_B32_LEN MAX_DOMAIN_LABEL
// We define it here instead of dnssec.h so that these values can be used
// in files without bringing in all of dnssec.h unnecessarily.
typedef enum
{
DNSSEC_Secure = 1, // Securely validated and has a chain up to the trust anchor
DNSSEC_Insecure, // Cannot build a chain up to the trust anchor
DNSSEC_Indeterminate, // Not used currently
DNSSEC_Bogus, // failed to validate signatures
DNSSEC_NoResponse // No DNSSEC records to start with
} DNSSECStatus;
#define DNSSECRecordType(rrtype) (((rrtype) == kDNSType_RRSIG) || ((rrtype) == kDNSType_NSEC) || ((rrtype) == kDNSType_DNSKEY) || ((rrtype) == kDNSType_DS) || \
((rrtype) == kDNSType_NSEC3))
typedef enum
{
platform_OSX = 1, // OSX Platform
platform_iOS, // iOS Platform
platform_Atv, // Atv Platform
platform_NonApple // Non-Apple (Windows, POSIX) Platform
} Platform_t;
// EDNS Option Code registrations are recorded in the "DNS EDNS0 Options" section of
// <http://www.iana.org/assignments/dns-parameters>
#define kDNSOpt_LLQ 1
#define kDNSOpt_Lease 2
#define kDNSOpt_NSID 3
#define kDNSOpt_Owner 4
#define kDNSOpt_Trace 65001 // 65001-65534 Reserved for Local/Experimental Use
typedef struct
{
mDNSu16 vers;
mDNSu16 llqOp;
mDNSu16 err; // Or UDP reply port, in setup request
// Note: In the in-memory form, there's typically a two-byte space here, so that the following 64-bit id is word-aligned
mDNSOpaque64 id;
mDNSu32 llqlease;
} LLQOptData;
typedef struct
{
mDNSu8 vers; // Version number of this Owner OPT record
mDNSs8 seq; // Sleep/wake epoch
mDNSEthAddr HMAC; // Host's primary identifier (e.g. MAC of on-board Ethernet)
mDNSEthAddr IMAC; // Interface's MAC address (if different to primary MAC)
mDNSOpaque48 password; // Optional password
} OwnerOptData;
typedef struct
{
mDNSu8 platf; // Running platform (see enum Platform_t)
mDNSu32 mDNSv; // mDNSResponder Version (DNS_SD_H defined in dns_sd.h)
} TracerOptData;
// Note: rdataOPT format may be repeated an arbitrary number of times in a single resource record
typedef struct
{
mDNSu16 opt;
mDNSu16 optlen;
union { LLQOptData llq; mDNSu32 updatelease; OwnerOptData owner; TracerOptData tracer; } u;
} rdataOPT;
// Space needed to put OPT records into a packet:
// Header 11 bytes (name 1, type 2, class 2, TTL 4, length 2)
// LLQ rdata 18 bytes (opt 2, len 2, vers 2, op 2, err 2, id 8, lease 4)
// Lease rdata 8 bytes (opt 2, len 2, lease 4)
// Owner rdata 12-24 bytes (opt 2, len 2, owner 8-20)
// Trace rdata 9 bytes (opt 2, len 2, platf 1, mDNSv 4)
#define DNSOpt_Header_Space 11
#define DNSOpt_LLQData_Space (4 + 2 + 2 + 2 + 8 + 4)
#define DNSOpt_LeaseData_Space (4 + 4)
#define DNSOpt_OwnerData_ID_Space (4 + 2 + 6)
#define DNSOpt_OwnerData_ID_Wake_Space (4 + 2 + 6 + 6)
#define DNSOpt_OwnerData_ID_Wake_PW4_Space (4 + 2 + 6 + 6 + 4)
#define DNSOpt_OwnerData_ID_Wake_PW6_Space (4 + 2 + 6 + 6 + 6)
#define DNSOpt_TraceData_Space (4 + 1 + 4)
#define ValidOwnerLength(X) ( (X) == DNSOpt_OwnerData_ID_Space - 4 || \
(X) == DNSOpt_OwnerData_ID_Wake_Space - 4 || \
(X) == DNSOpt_OwnerData_ID_Wake_PW4_Space - 4 || \
(X) == DNSOpt_OwnerData_ID_Wake_PW6_Space - 4 )
#define DNSOpt_Owner_Space(A,B) (mDNSSameEthAddress((A),(B)) ? DNSOpt_OwnerData_ID_Space : DNSOpt_OwnerData_ID_Wake_Space)
#define DNSOpt_Data_Space(O) ( \
(O)->opt == kDNSOpt_LLQ ? DNSOpt_LLQData_Space : \
(O)->opt == kDNSOpt_Lease ? DNSOpt_LeaseData_Space : \
(O)->opt == kDNSOpt_Trace ? DNSOpt_TraceData_Space : \
(O)->opt == kDNSOpt_Owner ? DNSOpt_Owner_Space(&(O)->u.owner.HMAC, &(O)->u.owner.IMAC) : 0x10000)
// NSEC record is defined in RFC 4034.
// 16 bit RRTYPE space is split into 256 windows and each window has 256 bits (32 bytes).
// If we create a structure for NSEC, it's size would be:
//
// 256 bytes domainname 'nextname'
// + 256 * 34 = 8704 bytes of bitmap data
// = 8960 bytes total
//
// This would be a waste, as types about 256 are not very common. But it would be odd, if we receive
// a type above 256 (.US zone had TYPE65534 when this code was written) and not able to handle it.
// Hence, we handle any size by not fixing a strucure in place. The following is just a placeholder
// and never used anywhere.
//
#define NSEC_MCAST_WINDOW_SIZE 32