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 <resolv.h> | 5 #include <resolv.h> |
6 | 6 |
7 #include "base/sys_byteorder.h" | 7 #include "base/sys_byteorder.h" |
8 #include "net/dns/dns_config_service_posix.h" | 8 #include "net/dns/dns_config_service_posix.h" |
9 | 9 |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 | 66 |
67 const char* ip4addr[3] = { | 67 const char* ip4addr[3] = { |
68 "8.8.8.8", | 68 "8.8.8.8", |
69 "192.168.1.1", | 69 "192.168.1.1", |
70 "63.1.2.4", | 70 "63.1.2.4", |
71 }; | 71 }; |
72 | 72 |
73 for (int i = 0; i < 3; ++i) { | 73 for (int i = 0; i < 3; ++i) { |
74 struct sockaddr_in sa; | 74 struct sockaddr_in sa; |
75 sa.sin_family = AF_INET; | 75 sa.sin_family = AF_INET; |
76 sa.sin_port = htons(NS_DEFAULTPORT + i - generation); | 76 sa.sin_port = base::HostToNet16(NS_DEFAULTPORT + i - generation); |
77 inet_pton(AF_INET, ip4addr[i], &sa.sin_addr); | 77 inet_pton(AF_INET, ip4addr[i], &sa.sin_addr); |
78 res->nsaddr_list[i] = sa; | 78 res->nsaddr_list[i] = sa; |
79 } | 79 } |
80 res->nscount = 3; | 80 res->nscount = 3; |
81 | 81 |
82 #if defined(OS_LINUX) | 82 #if defined(OS_LINUX) |
83 const char* ip6addr[2] = { | 83 const char* ip6addr[2] = { |
84 "2001:db8:0::42", | 84 "2001:db8:0::42", |
85 "::FFFF:129.144.52.38", | 85 "::FFFF:129.144.52.38", |
86 }; | 86 }; |
87 | 87 |
88 for (int i = 0; i < 2; ++i) { | 88 for (int i = 0; i < 2; ++i) { |
89 // Must use malloc to mimick res_ninit. | 89 // Must use malloc to mimick res_ninit. |
90 struct sockaddr_in6 *sa6; | 90 struct sockaddr_in6 *sa6; |
91 sa6 = (struct sockaddr_in6 *)malloc(sizeof(*sa6)); | 91 sa6 = (struct sockaddr_in6 *)malloc(sizeof(*sa6)); |
92 sa6->sin6_family = AF_INET6; | 92 sa6->sin6_family = AF_INET6; |
93 sa6->sin6_port = htons(NS_DEFAULTPORT - i); | 93 sa6->sin6_port = base::HostToNet16(NS_DEFAULTPORT - i); |
94 inet_pton(AF_INET6, ip6addr[i], &sa6->sin6_addr); | 94 inet_pton(AF_INET6, ip6addr[i], &sa6->sin6_addr); |
95 res->_u._ext.nsaddrs[i] = sa6; | 95 res->_u._ext.nsaddrs[i] = sa6; |
96 } | 96 } |
97 res->_u._ext.nscount6 = 2; | 97 res->_u._ext.nscount6 = 2; |
98 #endif | 98 #endif |
99 } | 99 } |
100 | 100 |
101 void CloseResState(res_state res) { | 101 void CloseResState(res_state res) { |
102 #if defined(OS_LINUX) | 102 #if defined(OS_LINUX) |
103 for (int i = 0; i < res->_u._ext.nscount6; ++i) { | 103 for (int i = 0; i < res->_u._ext.nscount6; ++i) { |
(...skipping 16 matching lines...) Expand all Loading... |
120 CompareConfig(res[i], config[i]); | 120 CompareConfig(res[i], config[i]); |
121 CloseResState(&res[i]); | 121 CloseResState(&res[i]); |
122 } | 122 } |
123 EXPECT_TRUE(config[0].Equals(config[0])); | 123 EXPECT_TRUE(config[0].Equals(config[0])); |
124 EXPECT_FALSE(config[0].Equals(config[1])); | 124 EXPECT_FALSE(config[0].Equals(config[1])); |
125 EXPECT_FALSE(config[1].Equals(config[0])); | 125 EXPECT_FALSE(config[1].Equals(config[0])); |
126 } | 126 } |
127 | 127 |
128 } // namespace | 128 } // namespace |
129 } // namespace net | 129 } // namespace net |
130 | |
131 | |
OLD | NEW |