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..050b35e8352358ba9cb8a5a8a3e1c51021dc615d 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,22 +167,41 @@ bool DnsResponse::InitParse(int nbytes, const DnsQuery& query) { |
| return true; |
| } |
| -uint8 DnsResponse::flags0() const { |
| - return header()->flags[0]; |
| -} |
| - |
| -uint8 DnsResponse::flags1() const { |
| - return header()->flags[1] & ~(dns_protocol::kRcodeMask); |
| +uint16 DnsResponse::flags() const { |
| + return ntohs(header()->flags) & ~(dns_protocol::kRcodeMask); |
| } |
| uint8 DnsResponse::rcode() const { |
| - return header()->flags[1] & dns_protocol::kRcodeMask; |
| + return ntohs(header()->flags) & dns_protocol::kRcodeMask; |
| } |
| int DnsResponse::answer_count() const { |
| return ntohs(header()->ancount); |
| } |
| +base::StringPiece DnsResponse::qname() const { |
| + DCHECK(parser_.IsValid()); |
| + const size_t hdr_size = sizeof(dns_protocol::Header); |
| + const size_t qname_size = parser_.offset() - 2 * sizeof(uint16) - hdr_size; |
|
mmenke
2012/01/13 16:44:37
Could you add a comment that this always works bec
|
| + return base::StringPiece(io_buffer_->data() + hdr_size, |
| + qname_size); |
| +} |
| + |
| +uint16 DnsResponse::qtype() const { |
| + DCHECK(parser_.IsValid()); |
| + 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 { |
| + DCHECK(parser_.IsValid()); |
| + return DNSDomainToString(qname()); |
| +} |
| + |
| + |
|
mmenke
2012/01/13 16:44:37
nit: Remove extra linebreak.
|
| DnsRecordParser DnsResponse::Parser() const { |
| DCHECK(parser_.IsValid()); |
| return parser_; |