| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_service_win.h" | 5 #include "net/dns/dns_config_service_win.h" |
| 6 | 6 |
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/win/windows_version.h" | 9 #include "base/win/windows_version.h" |
| 10 #include "net/dns/dns_protocol.h" | 10 #include "net/dns/dns_protocol.h" |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 } | 51 } |
| 52 | 52 |
| 53 struct AdapterInfo { | 53 struct AdapterInfo { |
| 54 IFTYPE if_type; | 54 IFTYPE if_type; |
| 55 IF_OPER_STATUS oper_status; | 55 IF_OPER_STATUS oper_status; |
| 56 const WCHAR* dns_suffix; | 56 const WCHAR* dns_suffix; |
| 57 std::string dns_server_addresses[4]; // Empty string indicates end. | 57 std::string dns_server_addresses[4]; // Empty string indicates end. |
| 58 int ports[4]; | 58 int ports[4]; |
| 59 }; | 59 }; |
| 60 | 60 |
| 61 scoped_ptr_malloc<IP_ADAPTER_ADDRESSES> CreateAdapterAddresses( | 61 scoped_ptr<IP_ADAPTER_ADDRESSES, base::FreeDeleter> CreateAdapterAddresses( |
| 62 const AdapterInfo* infos) { | 62 const AdapterInfo* infos) { |
| 63 size_t num_adapters = 0; | 63 size_t num_adapters = 0; |
| 64 size_t num_addresses = 0; | 64 size_t num_addresses = 0; |
| 65 for (size_t i = 0; infos[i].if_type; ++i) { | 65 for (size_t i = 0; infos[i].if_type; ++i) { |
| 66 ++num_adapters; | 66 ++num_adapters; |
| 67 for (size_t j = 0; !infos[i].dns_server_addresses[j].empty(); ++j) { | 67 for (size_t j = 0; !infos[i].dns_server_addresses[j].empty(); ++j) { |
| 68 ++num_addresses; | 68 ++num_addresses; |
| 69 } | 69 } |
| 70 } | 70 } |
| 71 | 71 |
| 72 size_t heap_size = num_adapters * sizeof(IP_ADAPTER_ADDRESSES) + | 72 size_t heap_size = num_adapters * sizeof(IP_ADAPTER_ADDRESSES) + |
| 73 num_addresses * (sizeof(IP_ADAPTER_DNS_SERVER_ADDRESS) + | 73 num_addresses * (sizeof(IP_ADAPTER_DNS_SERVER_ADDRESS) + |
| 74 sizeof(struct sockaddr_storage)); | 74 sizeof(struct sockaddr_storage)); |
| 75 scoped_ptr_malloc<IP_ADAPTER_ADDRESSES> heap( | 75 scoped_ptr<IP_ADAPTER_ADDRESSES, base::FreeDeleter> heap( |
| 76 reinterpret_cast<IP_ADAPTER_ADDRESSES*>(malloc(heap_size))); | 76 static_cast<IP_ADAPTER_ADDRESSES*>(malloc(heap_size))); |
| 77 CHECK(heap.get()); | 77 CHECK(heap.get()); |
| 78 memset(heap.get(), 0, heap_size); | 78 memset(heap.get(), 0, heap_size); |
| 79 | 79 |
| 80 IP_ADAPTER_ADDRESSES* adapters = heap.get(); | 80 IP_ADAPTER_ADDRESSES* adapters = heap.get(); |
| 81 IP_ADAPTER_DNS_SERVER_ADDRESS* addresses = | 81 IP_ADAPTER_DNS_SERVER_ADDRESS* addresses = |
| 82 reinterpret_cast<IP_ADAPTER_DNS_SERVER_ADDRESS*>(adapters + num_adapters); | 82 reinterpret_cast<IP_ADAPTER_DNS_SERVER_ADDRESS*>(adapters + num_adapters); |
| 83 struct sockaddr_storage* storage = | 83 struct sockaddr_storage* storage = |
| 84 reinterpret_cast<struct sockaddr_storage*>(addresses + num_addresses); | 84 reinterpret_cast<struct sockaddr_storage*>(addresses + num_addresses); |
| 85 | 85 |
| 86 for (size_t i = 0; i < num_adapters; ++i) { | 86 for (size_t i = 0; i < num_adapters; ++i) { |
| (...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 458 EXPECT_EQ(t.unhandled_options, config.unhandled_options); | 458 EXPECT_EQ(t.unhandled_options, config.unhandled_options); |
| 459 EXPECT_EQ(t.have_nrpt, config.use_local_ipv6); | 459 EXPECT_EQ(t.have_nrpt, config.use_local_ipv6); |
| 460 } | 460 } |
| 461 } | 461 } |
| 462 | 462 |
| 463 | 463 |
| 464 } // namespace | 464 } // namespace |
| 465 | 465 |
| 466 } // namespace net | 466 } // namespace net |
| 467 | 467 |
| OLD | NEW |