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

Unified Diff: net/dns/dns_response.cc

Issue 14049018: Add simple non-response-based question parsing for mDNS passive listening (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years, 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « net/dns/dns_response.h ('k') | net/dns/dns_response_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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();
}
« no previous file with comments | « net/dns/dns_response.h ('k') | net/dns/dns_response_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698