Index: net/dns/dns_response.cc |
diff --git a/net/dns/dns_response.cc b/net/dns/dns_response.cc |
index 625e7c041dc0ddfc0eb5c02dc650b22d58fba7d2..006077886a7cd4af10a0249b48eb25989a673941 100644 |
--- a/net/dns/dns_response.cc |
+++ b/net/dns/dns_response.cc |
@@ -127,6 +127,20 @@ bool DnsRecordParser::ReadRecord(DnsResourceRecord* out) { |
return false; |
} |
+bool DnsRecordParser::SkipQuestion() { |
+ size_t consumed = ReadName(cur_, NULL); |
+ if (!consumed) |
+ return false; |
+ |
+ const char* next = cur_ + consumed + 2 * sizeof(uint16); // QTYPE + QCLASS |
szym
2013/04/23 19:36:41
nit: two spaces before //
Noam Samuel
2013/04/23 20:24:40
Done.
|
+ if (next > packet_ + length_) |
+ return false; |
+ |
+ cur_ = next; |
+ |
+ return true; |
+} |
+ |
DnsResponse::DnsResponse() |
: io_buffer_(new IOBufferWithSize(dns_protocol::kMaxUDPSize + 1)) { |
} |
@@ -175,6 +189,25 @@ bool DnsResponse::InitParse(int nbytes, const DnsQuery& query) { |
return true; |
} |
+bool DnsResponse::InitParseWithoutQuery(int nbytes) { |
+ if (nbytes >= io_buffer_->size()) |
+ return false; |
+ |
+ size_t hdr_size = sizeof(dns_protocol::Header); |
+ parser_ = DnsRecordParser( |
+ io_buffer_->data(), nbytes, hdr_size); |
+ |
+ unsigned qdcount = base::NetToHost16(header()->qdcount); |
+ for (unsigned i = 0; i < qdcount; ++i) { |
+ if (!parser_.SkipQuestion()) { |
+ parser_ = DnsRecordParser(); // Make parser invalid again. |
+ return false; |
+ } |
+ } |
+ |
+ return true; |
+} |
+ |
bool DnsResponse::IsValid() const { |
return parser_.IsValid(); |
} |