Chromium Code Reviews| Index: net/dns/dns_response.cc |
| diff --git a/net/dns/dns_response.cc b/net/dns/dns_response.cc |
| index dabfc6ab89cd287cef90be3abc5cb8eeae0524d0..3bec0d8e2cf563f00c6930f8ba1eb159c45b9d80 100644 |
| --- a/net/dns/dns_response.cc |
| +++ b/net/dns/dns_response.cc |
| @@ -6,6 +6,7 @@ |
| #include "base/sys_byteorder.h" |
| #include "net/base/big_endian.h" |
| +#include "net/base/dns_util.h" |
| #include "net/base/io_buffer.h" |
| #include "net/base/net_errors.h" |
| #include "net/dns/dns_protocol.h" |
| @@ -166,24 +167,49 @@ bool DnsResponse::InitParse(int nbytes, const DnsQuery& query) { |
| return true; |
| } |
| -uint8 DnsResponse::flags0() const { |
| - return header()->flags[0]; |
| +bool DnsResponse::is_valid() const { |
| + return parser_.is_valid(); |
| } |
| -uint8 DnsResponse::flags1() const { |
| - return header()->flags[1] & ~(dns_protocol::kRcodeMask); |
| +uint16 DnsResponse::flags() const { |
| + DCHECK(parser_.is_valid()); |
| + return ntohs(header()->flags) & ~(dns_protocol::kRcodeMask); |
| } |
| uint8 DnsResponse::rcode() const { |
| - return header()->flags[1] & dns_protocol::kRcodeMask; |
| + DCHECK(parser_.is_valid()); |
| + return ntohs(header()->flags) & dns_protocol::kRcodeMask; |
| } |
| int DnsResponse::answer_count() const { |
| + DCHECK(parser_.is_valid()); |
| return ntohs(header()->ancount); |
| } |
| +base::StringPiece DnsResponse::qname() const { |
| + DCHECK(parser_.is_valid()); |
| + const size_t hdr_size = sizeof(dns_protocol::Header); |
| + const size_t qname_size = parser_.offset() - 2 * sizeof(uint16) - hdr_size; |
|
cbentzel
2012/01/13 22:17:25
This would benefit from an explanation - particula
|
| + return base::StringPiece(io_buffer_->data() + hdr_size, |
| + qname_size); |
| +} |
| + |
| +uint16 DnsResponse::qtype() const { |
| + DCHECK(parser_.is_valid()); |
| + const size_t type_offset = parser_.offset() - 2 * sizeof(uint16); |
| + uint16 type; |
| + ReadBigEndian<uint16>(io_buffer_->data() + type_offset, |
| + &type); |
| + return type; |
| +} |
| + |
| +std::string DnsResponse::GetDottedName() const { |
| + return DNSDomainToString(qname()); |
|
cbentzel
2012/01/13 22:17:25
[Note to self: Looks like the expansion is done by
szym
2012/01/17 15:38:25
The whole question section must be exactly as in t
|
| +} |
| + |
| DnsRecordParser DnsResponse::Parser() const { |
| - DCHECK(parser_.IsValid()); |
| + DCHECK(parser_.is_valid()); |
| + // Return a copy of the parser. |
| return parser_; |
| } |