| 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/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/memory/weak_ptr.h" | 10 #include "base/memory/weak_ptr.h" |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 | 79 |
| 80 // Size of RDATA which is a IPv4 or IPv6 address. | 80 // Size of RDATA which is a IPv4 or IPv6 address. |
| 81 size_t rdata_size = qtype_ == net::dns_protocol::kTypeA ? | 81 size_t rdata_size = qtype_ == net::dns_protocol::kTypeA ? |
| 82 net::kIPv4AddressSize : net::kIPv6AddressSize; | 82 net::kIPv4AddressSize : net::kIPv6AddressSize; |
| 83 | 83 |
| 84 // 12 is the sum of sizes of the compressed name reference, TYPE, | 84 // 12 is the sum of sizes of the compressed name reference, TYPE, |
| 85 // CLASS, TTL and RDLENGTH. | 85 // CLASS, TTL and RDLENGTH. |
| 86 size_t answer_size = 12 + rdata_size; | 86 size_t answer_size = 12 + rdata_size; |
| 87 | 87 |
| 88 // Write answer with loopback IP address. | 88 // Write answer with loopback IP address. |
| 89 reinterpret_cast<dns_protocol::Header*>(buffer)->ancount = htons(1); | 89 reinterpret_cast<dns_protocol::Header*>(buffer)->ancount = |
| 90 base::HostToNet16(1); |
| 90 BigEndianWriter writer(buffer + nbytes, answer_size); | 91 BigEndianWriter writer(buffer + nbytes, answer_size); |
| 91 writer.WriteU16(kPointerToQueryName); | 92 writer.WriteU16(kPointerToQueryName); |
| 92 writer.WriteU16(qtype_); | 93 writer.WriteU16(qtype_); |
| 93 writer.WriteU16(net::dns_protocol::kClassIN); | 94 writer.WriteU16(net::dns_protocol::kClassIN); |
| 94 writer.WriteU32(kTTL); | 95 writer.WriteU32(kTTL); |
| 95 writer.WriteU16(rdata_size); | 96 writer.WriteU16(rdata_size); |
| 96 if (qtype_ == net::dns_protocol::kTypeA) { | 97 if (qtype_ == net::dns_protocol::kTypeA) { |
| 97 char kIPv4Loopback[] = { 0x7f, 0, 0, 1 }; | 98 char kIPv4Loopback[] = { 0x7f, 0, 0, 1 }; |
| 98 writer.WriteBytes(kIPv4Loopback, sizeof(kIPv4Loopback)); | 99 writer.WriteBytes(kIPv4Loopback, sizeof(kIPv4Loopback)); |
| 99 } else { | 100 } else { |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 // static | 161 // static |
| 161 scoped_ptr<DnsClient> CreateMockDnsClient(const DnsConfig& config) { | 162 scoped_ptr<DnsClient> CreateMockDnsClient(const DnsConfig& config) { |
| 162 return scoped_ptr<DnsClient>(new MockDnsClient(config)); | 163 return scoped_ptr<DnsClient>(new MockDnsClient(config)); |
| 163 } | 164 } |
| 164 | 165 |
| 165 void MockDnsConfigService::Watch(const CallbackType& callback) { | 166 void MockDnsConfigService::Watch(const CallbackType& callback) { |
| 166 set_callback(callback); | 167 set_callback(callback); |
| 167 } | 168 } |
| 168 | 169 |
| 169 } // namespace net | 170 } // namespace net |
| 170 | |
| OLD | NEW |