| 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/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/win/windows_version.h" | 8 #include "base/win/windows_version.h" |
| 9 #include "net/dns/dns_protocol.h" | 9 #include "net/dns/dns_protocol.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 EXPECT_EQ(expected_output, actual_output); | 45 EXPECT_EQ(expected_output, actual_output); |
| 46 } else { | 46 } else { |
| 47 EXPECT_FALSE(result) << "Unexpected parse success on " << t.input; | 47 EXPECT_FALSE(result) << "Unexpected parse success on " << t.input; |
| 48 } | 48 } |
| 49 } | 49 } |
| 50 } | 50 } |
| 51 | 51 |
| 52 struct AdapterInfo { | 52 struct AdapterInfo { |
| 53 IFTYPE if_type; | 53 IFTYPE if_type; |
| 54 IF_OPER_STATUS oper_status; | 54 IF_OPER_STATUS oper_status; |
| 55 PWCHAR dns_suffix; | 55 const WCHAR* dns_suffix; |
| 56 std::string dns_server_addresses[4]; // Empty string indicates end. | 56 std::string dns_server_addresses[4]; // Empty string indicates end. |
| 57 int ports[4]; | 57 int ports[4]; |
| 58 }; | 58 }; |
| 59 | 59 |
| 60 scoped_ptr_malloc<IP_ADAPTER_ADDRESSES> CreateAdapterAddresses( | 60 scoped_ptr_malloc<IP_ADAPTER_ADDRESSES> CreateAdapterAddresses( |
| 61 const AdapterInfo* infos) { | 61 const AdapterInfo* infos) { |
| 62 size_t num_adapters = 0; | 62 size_t num_adapters = 0; |
| 63 size_t num_addresses = 0; | 63 size_t num_addresses = 0; |
| 64 for (size_t i = 0; infos[i].if_type; ++i) { | 64 for (size_t i = 0; infos[i].if_type; ++i) { |
| 65 ++num_adapters; | 65 ++num_adapters; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 82 struct sockaddr_storage* storage = | 82 struct sockaddr_storage* storage = |
| 83 reinterpret_cast<struct sockaddr_storage*>(addresses + num_addresses); | 83 reinterpret_cast<struct sockaddr_storage*>(addresses + num_addresses); |
| 84 | 84 |
| 85 for (size_t i = 0; i < num_adapters; ++i) { | 85 for (size_t i = 0; i < num_adapters; ++i) { |
| 86 const AdapterInfo& info = infos[i]; | 86 const AdapterInfo& info = infos[i]; |
| 87 IP_ADAPTER_ADDRESSES* adapter = adapters + i; | 87 IP_ADAPTER_ADDRESSES* adapter = adapters + i; |
| 88 if (i + 1 < num_adapters) | 88 if (i + 1 < num_adapters) |
| 89 adapter->Next = adapter + 1; | 89 adapter->Next = adapter + 1; |
| 90 adapter->IfType = info.if_type; | 90 adapter->IfType = info.if_type; |
| 91 adapter->OperStatus = info.oper_status; | 91 adapter->OperStatus = info.oper_status; |
| 92 adapter->DnsSuffix = info.dns_suffix; | 92 adapter->DnsSuffix = const_cast<PWCHAR>(info.dns_suffix); |
| 93 IP_ADAPTER_DNS_SERVER_ADDRESS* address = NULL; | 93 IP_ADAPTER_DNS_SERVER_ADDRESS* address = NULL; |
| 94 for (size_t j = 0; !info.dns_server_addresses[j].empty(); ++j) { | 94 for (size_t j = 0; !info.dns_server_addresses[j].empty(); ++j) { |
| 95 --num_addresses; | 95 --num_addresses; |
| 96 if (j == 0) { | 96 if (j == 0) { |
| 97 address = adapter->FirstDnsServerAddress = addresses + num_addresses; | 97 address = adapter->FirstDnsServerAddress = addresses + num_addresses; |
| 98 } else { | 98 } else { |
| 99 // Note that |address| is moving backwards. | 99 // Note that |address| is moving backwards. |
| 100 address = address->Next = address - 1; | 100 address = address->Next = address - 1; |
| 101 } | 101 } |
| 102 IPAddressNumber ip; | 102 IPAddressNumber ip; |
| (...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 421 EXPECT_EQ(internal::CONFIG_PARSE_WIN_OK, | 421 EXPECT_EQ(internal::CONFIG_PARSE_WIN_OK, |
| 422 internal::ConvertSettingsToDnsConfig(settings, &config)); | 422 internal::ConvertSettingsToDnsConfig(settings, &config)); |
| 423 EXPECT_EQ(config.append_to_multi_label_name, t.expected_output); | 423 EXPECT_EQ(config.append_to_multi_label_name, t.expected_output); |
| 424 } | 424 } |
| 425 } | 425 } |
| 426 | 426 |
| 427 } // namespace | 427 } // namespace |
| 428 | 428 |
| 429 } // namespace net | 429 } // namespace net |
| 430 | 430 |
| OLD | NEW |