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_test_util.h" | 5 #include "net/dns/dns_test_util.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
| 9 #include "base/big_endian.h" |
9 #include "base/bind.h" | 10 #include "base/bind.h" |
10 #include "base/memory/weak_ptr.h" | 11 #include "base/memory/weak_ptr.h" |
11 #include "base/message_loop/message_loop.h" | 12 #include "base/message_loop/message_loop.h" |
12 #include "base/sys_byteorder.h" | 13 #include "base/sys_byteorder.h" |
13 #include "net/base/big_endian.h" | |
14 #include "net/base/dns_util.h" | 14 #include "net/base/dns_util.h" |
15 #include "net/base/io_buffer.h" | 15 #include "net/base/io_buffer.h" |
16 #include "net/base/net_errors.h" | 16 #include "net/base/net_errors.h" |
17 #include "net/dns/address_sorter.h" | 17 #include "net/dns/address_sorter.h" |
18 #include "net/dns/dns_query.h" | 18 #include "net/dns/dns_query.h" |
19 #include "net/dns/dns_response.h" | 19 #include "net/dns/dns_response.h" |
20 #include "net/dns/dns_transaction.h" | 20 #include "net/dns/dns_transaction.h" |
21 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
22 | 22 |
23 namespace net { | 23 namespace net { |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 // Size of RDATA which is a IPv4 or IPv6 address. | 112 // Size of RDATA which is a IPv4 or IPv6 address. |
113 size_t rdata_size = qtype_ == net::dns_protocol::kTypeA ? | 113 size_t rdata_size = qtype_ == net::dns_protocol::kTypeA ? |
114 net::kIPv4AddressSize : net::kIPv6AddressSize; | 114 net::kIPv4AddressSize : net::kIPv6AddressSize; |
115 | 115 |
116 // 12 is the sum of sizes of the compressed name reference, TYPE, | 116 // 12 is the sum of sizes of the compressed name reference, TYPE, |
117 // CLASS, TTL and RDLENGTH. | 117 // CLASS, TTL and RDLENGTH. |
118 size_t answer_size = 12 + rdata_size; | 118 size_t answer_size = 12 + rdata_size; |
119 | 119 |
120 // Write answer with loopback IP address. | 120 // Write answer with loopback IP address. |
121 header->ancount = base::HostToNet16(1); | 121 header->ancount = base::HostToNet16(1); |
122 BigEndianWriter writer(buffer + nbytes, answer_size); | 122 base::BigEndianWriter writer(buffer + nbytes, answer_size); |
123 writer.WriteU16(kPointerToQueryName); | 123 writer.WriteU16(kPointerToQueryName); |
124 writer.WriteU16(qtype_); | 124 writer.WriteU16(qtype_); |
125 writer.WriteU16(net::dns_protocol::kClassIN); | 125 writer.WriteU16(net::dns_protocol::kClassIN); |
126 writer.WriteU32(kTTL); | 126 writer.WriteU32(kTTL); |
127 writer.WriteU16(rdata_size); | 127 writer.WriteU16(rdata_size); |
128 if (qtype_ == net::dns_protocol::kTypeA) { | 128 if (qtype_ == net::dns_protocol::kTypeA) { |
129 char kIPv4Loopback[] = { 0x7f, 0, 0, 1 }; | 129 char kIPv4Loopback[] = { 0x7f, 0, 0, 1 }; |
130 writer.WriteBytes(kIPv4Loopback, sizeof(kIPv4Loopback)); | 130 writer.WriteBytes(kIPv4Loopback, sizeof(kIPv4Loopback)); |
131 } else { | 131 } else { |
132 char kIPv6Loopback[] = { 0, 0, 0, 0, 0, 0, 0, 0, | 132 char kIPv6Loopback[] = { 0, 0, 0, 0, 0, 0, 0, 0, |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
220 | 220 |
221 AddressSorter* MockDnsClient::GetAddressSorter() { | 221 AddressSorter* MockDnsClient::GetAddressSorter() { |
222 return address_sorter_.get(); | 222 return address_sorter_.get(); |
223 } | 223 } |
224 | 224 |
225 void MockDnsClient::CompleteDelayedTransactions() { | 225 void MockDnsClient::CompleteDelayedTransactions() { |
226 factory_->CompleteDelayedTransactions(); | 226 factory_->CompleteDelayedTransactions(); |
227 } | 227 } |
228 | 228 |
229 } // namespace net | 229 } // namespace net |
OLD | NEW |