2 * Copyright (c) 2004-2006 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
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
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.
21 * @APPLE_LICENSE_HEADER_END@
24 #ifndef __DNSINFO_PRIVATE_H__
25 #define __DNSINFO_PRIVATE_H__
28 #include <AvailabilityMacros.h>
29 #include <sys/cdefs.h>
31 #include <sys/types.h>
32 #include <sys/socket.h>
33 #include <netinet/in.h>
34 #include <mach/mach.h>
38 #if MAC_OS_X_VERSION_MAX_ALLOWED >= 1040
41 * What's all of this stuff about???
43 * In order to minimize the amount of data conversions associated with
44 * storing, retrieving, and accessing the systems DNS configuration I
45 * have opted to create a memory image filled with the actual data
46 * types / structures that would be used by those applications which
47 * make use of these APIS. The implication here is that we use
48 * sockaddr's for addresses, char *'s for strings, etc.
50 * To achieve this goal the APIs which are used to store and access the
51 * configuration data build and use a single buffer of the relevant
52 * bits. When multiple instances of a given type / structure are needed
53 * we maintain a count, the actual data, and when the configuration has
54 * been unpacked, arrays of pointers to the data.
56 * In memory, the data looks as follows:
58 * +-------------------------------------------------------------------+
59 * | struct _dns_config_buf_t |
60 * +-+-------------+---------------------------------------------------+
61 * | | config | struct dns_config_t |
62 * | | +-+--------------+----------------------------------+
63 * | | | | n_resolver | int32_t | <- # of name resolvers
64 * | | | +--------------+----------------------------------+
65 * | | | | resolver | dns_resolver_t ** | <- not used during creation, filled
66 * | | | | | | in with pointer to a list of
67 * | | | | | | resolver configurations which be
68 * | | | | | | established in the "padding"
69 * | | | +--------------+----------------------------------+
71 * | +-------------+-+--------------+----------------------------------+
72 * | | n_attribute | uint32_t | <- how many bytes of "attribute"
73 * | | | | data is associated with the
74 * | | | | configuration
75 * |-+-------------+---------------------------------------------------+
76 * | | n_padding | uint32_t | <- how many additional bytes
77 * | | | | for arrays (of pointers), ...
78 * +-+-------------+---------------------------------------------------+
79 * | struct dns_attribute_t |
80 * |-+-------------+---------------------------------------------------+
81 * | | type | uint32_t | <- type of attribute (e.g. CONFIG_ATTRIBUTE_RESOLVER)
82 * | +-------------+---------------------------------------------------+
83 * | | length | uint32_t | <- length of the attribute
84 * | +-------------+---------------------------------------------------+
85 * | | attribute | struct _dns_resolver_buf_t | <- the attribute data (resolver configuration #1)
86 * | | +-+-------------+-----------------------------------+
87 * | | | | resolver | struct dns_resolver_t |
88 * | | | | +--------------+--------------------+
89 * | | | | | domain | char * | <- not used during creation,
90 * | | | | | | | filled in with pointer to
91 * | | | | | | | domain name in the "padding"
92 * | | | | +--------------+--------------------+
93 * | | | | | n_nameserver | int32_t | <- # of name server addresses
94 * | | | | +--------------+--------------------+
95 * | | | | | nameserver | struct sockaddr ** | <- not used during creation,
96 * | | | | | | | filled in with pointer to
97 * | | | | | | | a list of addresses which
98 * | | | | | | | will be established in the
99 * | | | | | | | "padding"
100 * | | | | +--------------+--------------------+
102 * | | +-+-------------+--------------+--------------------+
103 * | | | | n_attribute | uint32_t |
104 * | | +-+-------------+-----------------------------------+
105 * | | | | attribute | struct dns_attribute_t |
106 * | | | | +-+-----------+---------------------+
107 * | | | | | | type | uint32_t | <- type of attribute (e.g. RESOLVER_ATTRIBUTE_DOMAIN)
108 * | | | | | +-----------+---------------------+
109 * | | | | | | length | uint32_t | <- length of the attribute
110 * | | | | | +-----------+---------------------+
111 * | | | | | | attribute | | <- the attribute data ("apple.com")
112 * | | +-+-------------+-------------+---------------------+
113 * | | | | attribute | struct dns_attribute_t |
114 * | | | | +-+-----------+---------------------+
115 * | | | | | | type | uint32_t | <- type of attribute (e.g. RESOLVER_ATTRIBUTE_ADDRESS)
116 * | | | | | +-----------+---------------------+
117 * | | | | | | length | uint32_t | <- length of the attribute
118 * | | | | | +-----------+---------------------+
119 * | | | | | | attribute | | <- the attribute data ("struct sockaddr_in" #1)
120 * | | +---------------+-----------------------------------+
121 * | | | | attribute | struct dns_attribute_t |
122 * | | | | +-+-----------+---------------------+
123 * | | | | | | type | uint32_t | <- type of attribute (e.g. RESOLVER_ATTRIBUTE_ADDRESS)
124 * | | | | | +-----------+---------------------+
125 * | | | | | | length | uint32_t | <- length of the attribute
126 * | | | | | +-----------+---------------------+
127 * | | | | | | attribute | | <- the attribute data ("struct sockaddr_in" #2)
128 * | | +---------------+-----------------------------------+
130 * +-+-------------+---------------------------------------------------+
131 * | | attribute | struct _dns_resolver_buf_t | <- the attribute data (resolver configuration #2)
132 * | | +---------------+-----------------------------------+
134 * +---------------+---------------------------------------------------+
136 * +---------------+---------------------------------------------------+
138 * When the data is unpacked the "n_padding" additional bytes
139 * specified in configuration buffer will be allocated at the
140 * end of this buffer. Arrays of pointers will be allocated
141 * within the extra space array element (an "attribute") is
142 * encountered the pointer reference will be filled in.
146 // configuration buffer attributes
148 CONFIG_ATTRIBUTE_RESOLVER
= 1
152 // resolver buffer attributes
154 RESOLVER_ATTRIBUTE_DOMAIN
= 10,
155 RESOLVER_ATTRIBUTE_ADDRESS
,
156 RESOLVER_ATTRIBUTE_SEARCH
,
157 RESOLVER_ATTRIBUTE_SORTADDR
,
158 RESOLVER_ATTRIBUTE_OPTIONS
166 uint8_t attribute
[0];
174 uint32_t n_attribute
;
176 uint8_t attribute
[0];
183 dns_resolver_t resolver
;
184 uint32_t n_attribute
;
185 uint8_t attribute
[0];
186 } _dns_resolver_buf_t
;
192 const char * _dns_configuration_notify_key (void) AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER
;
193 mach_port_t
_dns_configuration_server_port (void) AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER
;
197 #endif /* MAC_OS_X_VERSION_MAX_ALLOWED >= 1040 */
199 #endif /* __DNSINFO_PRIVATE_H__ */