OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "net/dns/dns_config_watcher_mac.h" | 5 #include "net/dns/dns_config_watcher_mac.h" |
6 | 6 |
7 #include <dlfcn.h> | 7 #include <dlfcn.h> |
8 | 8 |
9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
10 #include "third_party/apple_apsl/dnsinfo.h" | 10 #include "third_party/apple_apsl/dnsinfo.h" |
11 | 11 |
12 namespace { | 12 namespace { |
13 | 13 |
14 // dnsinfo symbols are available via libSystem.dylib, but can also be present in | 14 // dnsinfo symbols are available via libSystem.dylib, but can also be present in |
15 // SystemConfiguration.framework. To avoid confusion, load them explicitly from | 15 // SystemConfiguration.framework. To avoid confusion, load them explicitly from |
16 // libSystem.dylib. | 16 // libSystem.dylib. |
17 class DnsInfoApi { | 17 class DnsInfoApi { |
18 public: | 18 public: |
19 typedef const char* (*dns_configuration_notify_key_t)(); | 19 typedef const char* (*dns_configuration_notify_key_t)(); |
20 typedef dns_config_t* (*dns_configuration_copy_t)(); | 20 typedef dns_config_t* (*dns_configuration_copy_t)(); |
21 typedef void (*dns_configuration_free_t)(dns_config_t*); | 21 typedef void (*dns_configuration_free_t)(dns_config_t*); |
22 | 22 |
23 DnsInfoApi() | 23 DnsInfoApi() |
24 : dns_configuration_notify_key(NULL), | 24 : dns_configuration_notify_key(NULL), |
25 dns_configuration_copy(NULL), | 25 dns_configuration_copy(NULL), |
26 dns_configuration_free(NULL) { | 26 dns_configuration_free(NULL) { |
27 handle_ = dlopen("/usr/lib/libSystem.dylib", | 27 handle_ = dlopen("/usr/lib/libSystem.dylib", RTLD_LAZY | RTLD_NOLOAD); |
28 RTLD_LAZY | RTLD_NOLOAD); | |
29 if (!handle_) | 28 if (!handle_) |
30 return; | 29 return; |
31 dns_configuration_notify_key = | 30 dns_configuration_notify_key = |
32 reinterpret_cast<dns_configuration_notify_key_t>( | 31 reinterpret_cast<dns_configuration_notify_key_t>( |
33 dlsym(handle_, "dns_configuration_notify_key")); | 32 dlsym(handle_, "dns_configuration_notify_key")); |
34 dns_configuration_copy = | 33 dns_configuration_copy = reinterpret_cast<dns_configuration_copy_t>( |
35 reinterpret_cast<dns_configuration_copy_t>( | 34 dlsym(handle_, "dns_configuration_copy")); |
36 dlsym(handle_, "dns_configuration_copy")); | 35 dns_configuration_free = reinterpret_cast<dns_configuration_free_t>( |
37 dns_configuration_free = | 36 dlsym(handle_, "dns_configuration_free")); |
38 reinterpret_cast<dns_configuration_free_t>( | |
39 dlsym(handle_, "dns_configuration_free")); | |
40 } | 37 } |
41 | 38 |
42 ~DnsInfoApi() { | 39 ~DnsInfoApi() { |
43 if (handle_) | 40 if (handle_) |
44 dlclose(handle_); | 41 dlclose(handle_); |
45 } | 42 } |
46 | 43 |
47 dns_configuration_notify_key_t dns_configuration_notify_key; | 44 dns_configuration_notify_key_t dns_configuration_notify_key; |
48 dns_configuration_copy_t dns_configuration_copy; | 45 dns_configuration_copy_t dns_configuration_copy; |
49 dns_configuration_free_t dns_configuration_free; | 46 dns_configuration_free_t dns_configuration_free; |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 continue; | 94 continue; |
98 ++num_resolvers; | 95 ++num_resolvers; |
99 } | 96 } |
100 if (num_resolvers > 1) | 97 if (num_resolvers > 1) |
101 return CONFIG_PARSE_POSIX_UNHANDLED_OPTIONS; | 98 return CONFIG_PARSE_POSIX_UNHANDLED_OPTIONS; |
102 return CONFIG_PARSE_POSIX_OK; | 99 return CONFIG_PARSE_POSIX_OK; |
103 } | 100 } |
104 | 101 |
105 } // namespace internal | 102 } // namespace internal |
106 } // namespace net | 103 } // namespace net |
OLD | NEW |