| 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/base/address_list.h" | 5 #include "net/base/address_list.h" |
| 6 | 6 |
| 7 #include "base/strings/string_util.h" | 7 #include "base/strings/string_util.h" |
| 8 #include "base/sys_byteorder.h" | 8 #include "base/sys_byteorder.h" |
| 9 #include "net/base/net_util.h" | 9 #include "net/base/net_util.h" |
| 10 #include "net/base/sys_addrinfo.h" | 10 #include "net/base/sys_addrinfo.h" |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 SockaddrStorage storage[kNumElements]; | 47 SockaddrStorage storage[kNumElements]; |
| 48 struct addrinfo ai[kNumElements]; | 48 struct addrinfo ai[kNumElements]; |
| 49 for (unsigned i = 0; i < kNumElements; ++i) { | 49 for (unsigned i = 0; i < kNumElements; ++i) { |
| 50 struct sockaddr_in* addr = | 50 struct sockaddr_in* addr = |
| 51 reinterpret_cast<struct sockaddr_in*>(storage[i].addr); | 51 reinterpret_cast<struct sockaddr_in*>(storage[i].addr); |
| 52 storage[i].addr_len = sizeof(struct sockaddr_in); | 52 storage[i].addr_len = sizeof(struct sockaddr_in); |
| 53 // Populating the address with { i, i, i, i }. | 53 // Populating the address with { i, i, i, i }. |
| 54 memset(&addr->sin_addr, i, kIPv4AddressSize); | 54 memset(&addr->sin_addr, i, kIPv4AddressSize); |
| 55 addr->sin_family = AF_INET; | 55 addr->sin_family = AF_INET; |
| 56 // Set port to i << 2; | 56 // Set port to i << 2; |
| 57 addr->sin_port = base::HostToNet16(static_cast<uint16>(i << 2)); | 57 addr->sin_port = base::HostToNet16(static_cast<uint16_t>(i << 2)); |
| 58 memset(&ai[i], 0x0, sizeof(ai[i])); | 58 memset(&ai[i], 0x0, sizeof(ai[i])); |
| 59 ai[i].ai_family = addr->sin_family; | 59 ai[i].ai_family = addr->sin_family; |
| 60 ai[i].ai_socktype = SOCK_STREAM; | 60 ai[i].ai_socktype = SOCK_STREAM; |
| 61 ai[i].ai_addrlen = storage[i].addr_len; | 61 ai[i].ai_addrlen = storage[i].addr_len; |
| 62 ai[i].ai_addr = storage[i].addr; | 62 ai[i].ai_addr = storage[i].addr; |
| 63 if (i + 1 < kNumElements) | 63 if (i + 1 < kNumElements) |
| 64 ai[i].ai_next = &ai[i + 1]; | 64 ai[i].ai_next = &ai[i + 1]; |
| 65 } | 65 } |
| 66 | 66 |
| 67 AddressList list = AddressList::CreateFromAddrinfo(&ai[0]); | 67 AddressList list = AddressList::CreateFromAddrinfo(&ai[0]); |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 | 129 |
| 130 AddressList test_list = AddressList::CreateFromIPAddressList(ip_list, | 130 AddressList test_list = AddressList::CreateFromIPAddressList(ip_list, |
| 131 kCanonicalName); | 131 kCanonicalName); |
| 132 std::string canonical_name; | 132 std::string canonical_name; |
| 133 EXPECT_EQ(kCanonicalName, test_list.canonical_name()); | 133 EXPECT_EQ(kCanonicalName, test_list.canonical_name()); |
| 134 EXPECT_EQ(arraysize(tests), test_list.size()); | 134 EXPECT_EQ(arraysize(tests), test_list.size()); |
| 135 } | 135 } |
| 136 | 136 |
| 137 } // namespace | 137 } // namespace |
| 138 } // namespace net | 138 } // namespace net |
| OLD | NEW |