2 * Copyright (c) 2004 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__
29 #include <sys/types.h>
30 #include <sys/socket.h>
31 #include <netinet/in.h>
32 #include <mach/mach.h>
38 * What's all of this stuff about???
40 * In order to minimize the amount of data conversions associated with
41 * storing, retrieving, and accessing the systems DNS configuration I
42 * have opted to create a memory image filled with the actual data
43 * types / structures that would be used by those applications which
44 * make use of these APIS. The implication here is that we use
45 * sockaddr's for addresses, char *'s for strings, etc.
47 * To achieve this goal the APIs which are used to store and access the
48 * configuration data build and use a single buffer of the relevant
49 * bits. When multiple instances of a given type / structure are needed
50 * we maintain a count, the actual data, and when the configuration has
51 * been unpacked, arrays of pointers to the data.
53 * In memory, the data looks as follows:
55 * +-------------------------------------------------------------------+
56 * | struct _dns_config_buf_t |
57 * +-+-------------+---------------------------------------------------+
58 * | | config | struct dns_config_t |
59 * | | +-+--------------+----------------------------------+
60 * | | | | n_resolver | int32_t | <- # of name resolvers
61 * | | | +--------------+----------------------------------+
62 * | | | | resolver | dns_resolver_t ** | <- not used during creation, filled
63 * | | | | | | in with pointer to a list of
64 * | | | | | | resolver configurations which be
65 * | | | | | | established in the "padding"
66 * | | | +--------------+----------------------------------+
68 * | +-------------+-+--------------+----------------------------------+
69 * | | n_attribute | uint32_t | <- how many bytes of "attribute"
70 * | | | | data is associated with the
71 * | | | | configuration
72 * |-+-------------+---------------------------------------------------+
73 * | | n_padding | uint32_t | <- how many additional bytes
74 * | | | | for arrays (of pointers), ...
75 * +-+-------------+---------------------------------------------------+
76 * | struct dns_attribute_t |
77 * |-+-------------+---------------------------------------------------+
78 * | | type | uint32_t | <- type of attribute (e.g. CONFIG_ATTRIBUTE_RESOLVER)
79 * | +-------------+---------------------------------------------------+
80 * | | length | uint32_t | <- length of the attribute
81 * | +-------------+---------------------------------------------------+
82 * | | attribute | struct _dns_resolver_buf_t | <- the attribute data (resolver configuration #1)
83 * | | +-+-------------+-----------------------------------+
84 * | | | | resolver | struct dns_resolver_t |
85 * | | | | +--------------+--------------------+
86 * | | | | | domain | char * | <- not used during creation,
87 * | | | | | | | filled in with pointer to
88 * | | | | | | | domain name in the "padding"
89 * | | | | +--------------+--------------------+
90 * | | | | | n_nameserver | int32_t | <- # of name server addresses
91 * | | | | +--------------+--------------------+
92 * | | | | | nameserver | struct sockaddr ** | <- not used during creation,
93 * | | | | | | | filled in with pointer to
94 * | | | | | | | a list of addresses which
95 * | | | | | | | will be established in the
96 * | | | | | | | "padding"
97 * | | | | +--------------+--------------------+
99 * | | +-+-------------+--------------+--------------------+
100 * | | | | n_attribute | uint32_t |
101 * | | +-+-------------+-----------------------------------+
102 * | | | | attribute | struct dns_attribute_t |
103 * | | | | +-+-----------+---------------------+
104 * | | | | | | type | uint32_t | <- type of attribute (e.g. RESOLVER_ATTRIBUTE_DOMAIN)
105 * | | | | | +-----------+---------------------+
106 * | | | | | | length | uint32_t | <- length of the attribute
107 * | | | | | +-----------+---------------------+
108 * | | | | | | attribute | | <- the attribute data ("apple.com")
109 * | | +-+-------------+-------------+---------------------+
110 * | | | | attribute | struct dns_attribute_t |
111 * | | | | +-+-----------+---------------------+
112 * | | | | | | type | uint32_t | <- type of attribute (e.g. RESOLVER_ATTRIBUTE_ADDRESS)
113 * | | | | | +-----------+---------------------+
114 * | | | | | | length | uint32_t | <- length of the attribute
115 * | | | | | +-----------+---------------------+
116 * | | | | | | attribute | | <- the attribute data ("struct sockaddr_in" #1)
117 * | | +---------------+-----------------------------------+
118 * | | | | attribute | struct dns_attribute_t |
119 * | | | | +-+-----------+---------------------+
120 * | | | | | | type | uint32_t | <- type of attribute (e.g. RESOLVER_ATTRIBUTE_ADDRESS)
121 * | | | | | +-----------+---------------------+
122 * | | | | | | length | uint32_t | <- length of the attribute
123 * | | | | | +-----------+---------------------+
124 * | | | | | | attribute | | <- the attribute data ("struct sockaddr_in" #2)
125 * | | +---------------+-----------------------------------+
127 * +-+-------------+---------------------------------------------------+
128 * | | attribute | struct _dns_resolver_buf_t | <- the attribute data (resolver configuration #2)
129 * | | +---------------+-----------------------------------+
131 * +---------------+---------------------------------------------------+
133 * +---------------+---------------------------------------------------+
135 * When the data is unpacked the "n_padding" additional bytes
136 * specified in configuration buffer will be allocated at the
137 * end of this buffer. Arrays of pointers will be allocated
138 * within the extra space array element (an "attribute") is
139 * encountered the pointer reference will be filled in.
143 // configuration buffer attributes
145 CONFIG_ATTRIBUTE_RESOLVER
= 1
149 // resolver buffer attributes
151 RESOLVER_ATTRIBUTE_DOMAIN
= 10,
152 RESOLVER_ATTRIBUTE_ADDRESS
,
153 RESOLVER_ATTRIBUTE_SEARCH
,
154 RESOLVER_ATTRIBUTE_SORTADDR
,
155 RESOLVER_ATTRIBUTE_OPTIONS
162 uint8_t attribute
[0];
168 uint32_t n_attribute
;
170 uint8_t attribute
[0];
175 dns_resolver_t resolver
;
176 uint32_t n_attribute
;
177 uint8_t attribute
[0];
178 } _dns_resolver_buf_t
;
181 const char * _dns_configuration_notify_key();
182 mach_port_t
_dns_configuration_server_port();
184 #endif __DNSINFO_PRIVATE_H__