2 * Copyright (c) 2013 Apple 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 _S_DNSINFO_INTERNAL_H
25 #define _S_DNSINFO_INTERNAL_H
27 #include <Availability.h>
28 #include <TargetConditionals.h>
29 #include <sys/cdefs.h>
30 #include <SystemConfiguration/SystemConfiguration.h>
31 #include <SystemConfiguration/SCPrivate.h>
32 #include "SCNetworkReachabilityInternal.h"
33 #include <arpa/inet.h>
39 static __inline__
void
40 _dns_resolver_print(dns_resolver_t
*resolver
, int index
)
44 SCPrint(TRUE
, stdout
, CFSTR("\nresolver #%d\n"), index
);
46 if (resolver
->domain
!= NULL
) {
47 SCPrint(TRUE
, stdout
, CFSTR(" domain : %s\n"), resolver
->domain
);
50 for (i
= 0; i
< resolver
->n_search
; i
++) {
51 SCPrint(TRUE
, stdout
, CFSTR(" search domain[%d] : %s\n"), i
, resolver
->search
[i
]);
54 for (i
= 0; i
< resolver
->n_nameserver
; i
++) {
57 _SC_sockaddr_to_string(resolver
->nameserver
[i
], buf
, sizeof(buf
));
58 SCPrint(TRUE
, stdout
, CFSTR(" nameserver[%d] : %s\n"), i
, buf
);
61 for (i
= 0; i
< resolver
->n_sortaddr
; i
++) {
65 (void)inet_ntop(AF_INET
, &resolver
->sortaddr
[i
]->address
, abuf
, sizeof(abuf
));
66 (void)inet_ntop(AF_INET
, &resolver
->sortaddr
[i
]->mask
, mbuf
, sizeof(mbuf
));
67 SCPrint(TRUE
, stdout
, CFSTR(" sortaddr[%d] : %s/%s\n"), i
, abuf
, mbuf
);
70 if (resolver
->options
!= NULL
) {
71 SCPrint(TRUE
, stdout
, CFSTR(" options : %s\n"), resolver
->options
);
74 if (resolver
->port
!= 0) {
75 SCPrint(TRUE
, stdout
, CFSTR(" port : %hd\n"), resolver
->port
);
78 if (resolver
->timeout
!= 0) {
79 SCPrint(TRUE
, stdout
, CFSTR(" timeout : %d\n"), resolver
->timeout
);
82 if (resolver
->if_index
!= 0) {
86 if_name
= if_indextoname(resolver
->if_index
, buf
);
87 SCPrint(TRUE
, stdout
, CFSTR(" if_index : %d (%s)\n"),
89 (if_name
!= NULL
) ? if_name
: "?");
92 if (resolver
->service_identifier
!= 0) {
93 SCPrint(TRUE
, stdout
, CFSTR(" service_identifier : %d\n"),
94 resolver
->service_identifier
);
97 if (resolver
->flags
!= 0) {
98 uint32_t flags
= resolver
->flags
;
100 SCPrint(TRUE
, stdout
, CFSTR(" flags : "));
101 SCPrint(_sc_debug
, stdout
, CFSTR("0x%08x ("), flags
);
102 if (flags
& DNS_RESOLVER_FLAGS_SCOPED
) {
103 SCPrint(TRUE
, stdout
, CFSTR("Scoped"));
104 flags
&= ~DNS_RESOLVER_FLAGS_SCOPED
;
105 SCPrint(flags
!= 0, stdout
, CFSTR(", "));
107 if (flags
& DNS_RESOLVER_FLAGS_SERVICE_SPECIFIC
) {
108 SCPrint(TRUE
, stdout
, CFSTR("Service-specific"));
109 flags
&= ~DNS_RESOLVER_FLAGS_SERVICE_SPECIFIC
;
110 SCPrint(flags
!= 0, stdout
, CFSTR(", "));
112 if (flags
& DNS_RESOLVER_FLAGS_REQUEST_A_RECORDS
) {
113 SCPrint(TRUE
, stdout
, CFSTR("Request A records"));
114 flags
&= ~DNS_RESOLVER_FLAGS_REQUEST_A_RECORDS
;
115 SCPrint(flags
!= 0, stdout
, CFSTR(", "));
117 if (flags
& DNS_RESOLVER_FLAGS_REQUEST_AAAA_RECORDS
) {
118 SCPrint(TRUE
, stdout
, CFSTR("Request AAAA records"));
119 flags
&= ~DNS_RESOLVER_FLAGS_REQUEST_AAAA_RECORDS
;
120 SCPrint(flags
!= 0, stdout
, CFSTR(", "));
123 SCPrint(TRUE
, stdout
, CFSTR("0x%08x"), flags
);
125 SCPrint(_sc_debug
, stdout
, CFSTR(")"));
126 SCPrint(TRUE
, stdout
, CFSTR("\n"));
129 if (resolver
->reach_flags
!= 0) {
130 uint32_t flags
= resolver
->reach_flags
;
132 SCPrint(TRUE
, stdout
, CFSTR(" reach : "));
133 SCPrint(_sc_debug
, stdout
, CFSTR("0x%08x ("), flags
);
134 __SCNetworkReachabilityPrintFlags(flags
);
135 SCPrint(_sc_debug
, stdout
, CFSTR(")"));
136 SCPrint(TRUE
, stdout
, CFSTR("\n"));
139 if (resolver
->search_order
!= 0) {
140 SCPrint(TRUE
, stdout
, CFSTR(" order : %d\n"), resolver
->search_order
);
147 static __inline__
void
148 _dns_configuration_print(dns_config_t
*dns_config
)
152 SCPrint(TRUE
, stdout
, CFSTR("DNS configuration\n"));
154 for (i
= 0; i
< dns_config
->n_resolver
; i
++) {
155 dns_resolver_t
*resolver
= dns_config
->resolver
[i
];
157 _dns_resolver_print(resolver
, i
+ 1);
160 if ((dns_config
->n_scoped_resolver
> 0) && (dns_config
->scoped_resolver
!= NULL
)) {
161 SCPrint(TRUE
, stdout
, CFSTR("\nDNS configuration (for scoped queries)\n"));
163 for (i
= 0; i
< dns_config
->n_scoped_resolver
; i
++) {
164 dns_resolver_t
*resolver
= dns_config
->scoped_resolver
[i
];
166 _dns_resolver_print(resolver
, i
+ 1);
170 if ((dns_config
->n_service_specific_resolver
> 0) && (dns_config
->service_specific_resolver
!= NULL
)) {
171 SCPrint(TRUE
, stdout
, CFSTR("\nDNS configuration (for service-specific queries)\n"));
173 for (i
= 0; i
< dns_config
->n_service_specific_resolver
; i
++) {
174 dns_resolver_t
*resolver
= dns_config
->service_specific_resolver
[i
];
176 _dns_resolver_print(resolver
, i
+ 1);
185 #endif /* !_S_DNSINFO_INTERNAL_H */