| 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_response.h" | 5 #include "net/dns/dns_response.h" |
| 6 | 6 |
| 7 #include "base/big_endian.h" | 7 #include "base/big_endian.h" |
| 8 #include "base/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
| 9 #include "base/sys_byteorder.h" | 9 #include "base/sys_byteorder.h" |
| 10 #include "net/base/address_list.h" | 10 #include "net/base/address_list.h" |
| (...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 296 unsigned ancount = answer_count(); | 296 unsigned ancount = answer_count(); |
| 297 for (unsigned i = 0; i < ancount; ++i) { | 297 for (unsigned i = 0; i < ancount; ++i) { |
| 298 if (!parser.ReadRecord(&record)) | 298 if (!parser.ReadRecord(&record)) |
| 299 return DNS_MALFORMED_RESPONSE; | 299 return DNS_MALFORMED_RESPONSE; |
| 300 | 300 |
| 301 if (record.type == dns_protocol::kTypeCNAME) { | 301 if (record.type == dns_protocol::kTypeCNAME) { |
| 302 // Following the CNAME chain, only if no addresses seen. | 302 // Following the CNAME chain, only if no addresses seen. |
| 303 if (!ip_addresses.empty()) | 303 if (!ip_addresses.empty()) |
| 304 return DNS_CNAME_AFTER_ADDRESS; | 304 return DNS_CNAME_AFTER_ADDRESS; |
| 305 | 305 |
| 306 if (base::strcasecmp(record.name.c_str(), expected_name.c_str()) != 0) | 306 if (!base::EqualsCaseInsensitiveASCII(record.name, expected_name)) |
| 307 return DNS_NAME_MISMATCH; | 307 return DNS_NAME_MISMATCH; |
| 308 | 308 |
| 309 if (record.rdata.size() != | 309 if (record.rdata.size() != |
| 310 parser.ReadName(record.rdata.begin(), &expected_name)) | 310 parser.ReadName(record.rdata.begin(), &expected_name)) |
| 311 return DNS_MALFORMED_CNAME; | 311 return DNS_MALFORMED_CNAME; |
| 312 | 312 |
| 313 ttl_sec = std::min(ttl_sec, record.ttl); | 313 ttl_sec = std::min(ttl_sec, record.ttl); |
| 314 } else if (record.type == expected_type) { | 314 } else if (record.type == expected_type) { |
| 315 if (record.rdata.size() != expected_size) | 315 if (record.rdata.size() != expected_size) |
| 316 return DNS_SIZE_MISMATCH; | 316 return DNS_SIZE_MISMATCH; |
| 317 | 317 |
| 318 if (base::strcasecmp(record.name.c_str(), expected_name.c_str()) != 0) | 318 if (!base::EqualsCaseInsensitiveASCII(record.name, expected_name)) |
| 319 return DNS_NAME_MISMATCH; | 319 return DNS_NAME_MISMATCH; |
| 320 | 320 |
| 321 ttl_sec = std::min(ttl_sec, record.ttl); | 321 ttl_sec = std::min(ttl_sec, record.ttl); |
| 322 ip_addresses.push_back(IPAddressNumber(record.rdata.begin(), | 322 ip_addresses.push_back(IPAddressNumber(record.rdata.begin(), |
| 323 record.rdata.end())); | 323 record.rdata.end())); |
| 324 } | 324 } |
| 325 } | 325 } |
| 326 | 326 |
| 327 // TODO(szym): Extract TTL for NODATA results. http://crbug.com/115051 | 327 // TODO(szym): Extract TTL for NODATA results. http://crbug.com/115051 |
| 328 | 328 |
| 329 // getcanonname in eglibc returns the first owner name of an A or AAAA RR. | 329 // getcanonname in eglibc returns the first owner name of an A or AAAA RR. |
| 330 // If the response passed all the checks so far, then |expected_name| is it. | 330 // If the response passed all the checks so far, then |expected_name| is it. |
| 331 *addr_list = AddressList::CreateFromIPAddressList(ip_addresses, | 331 *addr_list = AddressList::CreateFromIPAddressList(ip_addresses, |
| 332 expected_name); | 332 expected_name); |
| 333 *ttl = base::TimeDelta::FromSeconds(ttl_sec); | 333 *ttl = base::TimeDelta::FromSeconds(ttl_sec); |
| 334 return DNS_PARSE_OK; | 334 return DNS_PARSE_OK; |
| 335 } | 335 } |
| 336 | 336 |
| 337 } // namespace net | 337 } // namespace net |
| OLD | NEW |