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

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

Issue 1769783002: Migrate net::IPAddressList to net::IPAddress. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 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
« net/base/ip_address.h ('K') | « net/base/ip_address_number.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <limits> 7 #include <limits>
8 8
9 #include "base/big_endian.h" 9 #include "base/big_endian.h"
10 #include "base/strings/string_util.h" 10 #include "base/strings/string_util.h"
11 #include "base/sys_byteorder.h" 11 #include "base/sys_byteorder.h"
12 #include "net/base/address_list.h" 12 #include "net/base/address_list.h"
13 #include "net/base/io_buffer.h" 13 #include "net/base/io_buffer.h"
14 #include "net/base/ip_address.h"
14 #include "net/base/net_errors.h" 15 #include "net/base/net_errors.h"
15 #include "net/dns/dns_protocol.h" 16 #include "net/dns/dns_protocol.h"
16 #include "net/dns/dns_query.h" 17 #include "net/dns/dns_query.h"
17 #include "net/dns/dns_util.h" 18 #include "net/dns/dns_util.h"
18 19
19 namespace net { 20 namespace net {
20 21
21 DnsResourceRecord::DnsResourceRecord() { 22 DnsResourceRecord::DnsResourceRecord() {
22 } 23 }
23 24
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after
283 // we can always fall back to the system getaddrinfo. 284 // we can always fall back to the system getaddrinfo.
284 285
285 // Expected owner of record. No trailing dot. 286 // Expected owner of record. No trailing dot.
286 std::string expected_name = GetDottedName(); 287 std::string expected_name = GetDottedName();
287 288
288 uint16_t expected_type = qtype(); 289 uint16_t expected_type = qtype();
289 DCHECK(expected_type == dns_protocol::kTypeA || 290 DCHECK(expected_type == dns_protocol::kTypeA ||
290 expected_type == dns_protocol::kTypeAAAA); 291 expected_type == dns_protocol::kTypeAAAA);
291 292
292 size_t expected_size = (expected_type == dns_protocol::kTypeAAAA) 293 size_t expected_size = (expected_type == dns_protocol::kTypeAAAA)
293 ? kIPv6AddressSize : kIPv4AddressSize; 294 ? IPAddress::kIPv6AddressSize
295 : IPAddress::kIPv4AddressSize;
294 296
295 uint32_t ttl_sec = std::numeric_limits<uint32_t>::max(); 297 uint32_t ttl_sec = std::numeric_limits<uint32_t>::max();
296 IPAddressList ip_addresses; 298 IPAddressList ip_addresses;
297 DnsRecordParser parser = Parser(); 299 DnsRecordParser parser = Parser();
298 DnsResourceRecord record; 300 DnsResourceRecord record;
299 unsigned ancount = answer_count(); 301 unsigned ancount = answer_count();
300 for (unsigned i = 0; i < ancount; ++i) { 302 for (unsigned i = 0; i < ancount; ++i) {
301 if (!parser.ReadRecord(&record)) 303 if (!parser.ReadRecord(&record))
302 return DNS_MALFORMED_RESPONSE; 304 return DNS_MALFORMED_RESPONSE;
303 305
(...skipping 11 matching lines...) Expand all
315 317
316 ttl_sec = std::min(ttl_sec, record.ttl); 318 ttl_sec = std::min(ttl_sec, record.ttl);
317 } else if (record.type == expected_type) { 319 } else if (record.type == expected_type) {
318 if (record.rdata.size() != expected_size) 320 if (record.rdata.size() != expected_size)
319 return DNS_SIZE_MISMATCH; 321 return DNS_SIZE_MISMATCH;
320 322
321 if (!base::EqualsCaseInsensitiveASCII(record.name, expected_name)) 323 if (!base::EqualsCaseInsensitiveASCII(record.name, expected_name))
322 return DNS_NAME_MISMATCH; 324 return DNS_NAME_MISMATCH;
323 325
324 ttl_sec = std::min(ttl_sec, record.ttl); 326 ttl_sec = std::min(ttl_sec, record.ttl);
325 ip_addresses.push_back(IPAddressNumber(record.rdata.begin(), 327 ip_addresses.push_back(
326 record.rdata.end())); 328 IPAddress(reinterpret_cast<const uint8_t*>(record.rdata.data()),
329 record.rdata.length()));
327 } 330 }
328 } 331 }
329 332
330 // TODO(szym): Extract TTL for NODATA results. http://crbug.com/115051 333 // TODO(szym): Extract TTL for NODATA results. http://crbug.com/115051
331 334
332 // getcanonname in eglibc returns the first owner name of an A or AAAA RR. 335 // getcanonname in eglibc returns the first owner name of an A or AAAA RR.
333 // If the response passed all the checks so far, then |expected_name| is it. 336 // If the response passed all the checks so far, then |expected_name| is it.
334 *addr_list = AddressList::CreateFromIPAddressList(ip_addresses, 337 *addr_list = AddressList::CreateFromIPAddressList(ip_addresses,
335 expected_name); 338 expected_name);
336 *ttl = base::TimeDelta::FromSeconds(ttl_sec); 339 *ttl = base::TimeDelta::FromSeconds(ttl_sec);
337 return DNS_PARSE_OK; 340 return DNS_PARSE_OK;
338 } 341 }
339 342
340 } // namespace net 343 } // namespace net
OLDNEW
« net/base/ip_address.h ('K') | « net/base/ip_address_number.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698