Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(171)

Side by Side Diff: net/dns/dns_response.cc

Issue 9369045: [net] HostResolverImpl + DnsTransaction + DnsConfigService = Asynchronous DNS ready for experiments. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Ready for test-drive. Created 8 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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_response.h" 5 #include "net/dns/dns_response.h"
6 6
7 #include "base/sys_byteorder.h" 7 #include "base/sys_byteorder.h"
8 #include "net/base/address_list.h"
8 #include "net/base/big_endian.h" 9 #include "net/base/big_endian.h"
9 #include "net/base/dns_util.h" 10 #include "net/base/dns_util.h"
10 #include "net/base/io_buffer.h" 11 #include "net/base/io_buffer.h"
11 #include "net/base/net_errors.h" 12 #include "net/base/net_errors.h"
12 #include "net/dns/dns_protocol.h" 13 #include "net/dns/dns_protocol.h"
13 #include "net/dns/dns_query.h" 14 #include "net/dns/dns_query.h"
14 15
15 namespace net { 16 namespace net {
16 17
17 DnsResourceRecord::DnsResourceRecord() { 18 DnsResourceRecord::DnsResourceRecord() {
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 DnsRecordParser DnsResponse::Parser() const { 214 DnsRecordParser DnsResponse::Parser() const {
214 DCHECK(parser_.IsValid()); 215 DCHECK(parser_.IsValid());
215 // Return a copy of the parser. 216 // Return a copy of the parser.
216 return parser_; 217 return parser_;
217 } 218 }
218 219
219 const dns_protocol::Header* DnsResponse::header() const { 220 const dns_protocol::Header* DnsResponse::header() const {
220 return reinterpret_cast<const dns_protocol::Header*>(io_buffer_->data()); 221 return reinterpret_cast<const dns_protocol::Header*>(io_buffer_->data());
221 } 222 }
222 223
224 bool DnsResponseToAddressList(const DnsResponse* response,
225 AddressList* addr_list,
226 base::TimeDelta* ttl) {
227 DCHECK(response->IsValid());
228 // DnsTransaction already verified that |response| matches the issued query
229 // in terms of query header. We still need to determine if there is a valid
230 // chain of CNAMEs from the query name to the RR owner name.
231
232 // Expected owner of record.
233 std::string expected_name = response->GetDottedName();
234
235 // getcanonname in eglibc returns the first owner name of an A or AAAA RR.
236 std::string canon_name;
237
238 uint32 ttl_sec = kuint32max;
239 IPAddressList ip_addresses;
240 DnsRecordParser parser = response->Parser();
241 DnsResourceRecord record;
242 while (parser.ParseRecord(&record)) {
243 if (record.name != expected_name) {
244 // We ignore records owned by unexpected name.
245 continue;
246 }
247 if (record.type == dns_protocol::kTypeCNAME) {
248 // New |hostname|, following the CNAME chain.
249 if (!parser.ParseName(record.rdata.begin(), &expected_name)) {
250 return false;
251 }
252 } else if (record.type == response->qtype() &&
253 (record.rdata.size() == kIPv4AddressSize ||
254 record.rdata.size() == kIPv6AddressSize)) {
255 ip_addresses.push_back(IPAddressNumber(record.rdata.begin(),
256 record.rdata.end()));
257 ttl_sec = std::min(ttl_sec, record.ttl);
258 if (canon_name.empty())
259 canon_name = record.name;
260 }
261 }
262 if (ip_addresses.empty())
263 return false;
264
265 *addr_list = AddressList::CreateFromIPAddressList(ip_addresses,
266 canon_name);
267 *ttl = base::TimeDelta::FromSeconds(ttl_sec);
268 return true;
269 }
270
223 } // namespace net 271 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698