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

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..7d2031ff92e9f533bd22e508653c8e9fcb886af5 100644
--- a/net/dns/dns_response.cc
+++ b/net/dns/dns_response.cc
@@ -4,6 +4,8 @@
#include "net/dns/dns_response.h"
+#include <climits>
gene 2013/04/17 02:05:38 you probably don't need this any more
Noam Samuel 2013/04/17 20:39:08 Done.
+
#include "base/string_util.h"
#include "base/sys_byteorder.h"
#include "net/base/address_list.h"
@@ -175,6 +177,17 @@ bool DnsResponse::InitParse(int nbytes, const DnsQuery& query) {
return true;
}
+bool DnsResponse::InitParse(int nbytes) {
+ if (nbytes >= io_buffer_->size())
+ return false;
+
+ // Construct the parser.
+ parser_ = DnsRecordParser(io_buffer_->data(),
gene 2013/04/17 02:04:02 nit: you can fit this in one line now
Noam Samuel 2013/04/17 20:39:08 Done.
+ nbytes,
+ GetResponseOffset());
gene 2013/04/17 02:04:02 do you want to fail InitParse if GetResponseOffset
Noam Samuel 2013/04/17 20:39:08 Yes.
+ return true;
+}
+
bool DnsResponse::IsValid() const {
return parser_.IsValid();
}
@@ -217,6 +230,39 @@ std::string DnsResponse::GetDottedName() const {
return DNSDomainToString(qname());
}
+size_t DnsResponse::GetResponseOffset() const {
+ uint16 qdcount = base::NetToHost16(header()->qdcount);
+ const char* data = io_buffer_->data();
+ size_t data_size = io_buffer_->size();
+ size_t pos = sizeof(dns_protocol::Header);
+
+ for (uint16 i = 0; i < qdcount; i++) {
+ while (pos < data_size && data[pos] != 0) {
+ unsigned txt_len = static_cast<unsigned>(data[pos]);
+ // Traversal and checks adapted from DNSDomainToString.
+
+ // Handling pointers, which have both high bits set and an extra
+ // byte trailing them to indicate a location in the buffer.
+ if (txt_len >= 192) {
+ pos += 2;
+ continue;
+ }
+
+ if (txt_len > 63) {
+ return 0;
+ }
+
+ pos += txt_len + 1;
+ }
+
+ pos += 5; // 1 for 0-length text, 2 for qtype, 2 for qclass
+ }
+
+ if (pos > data_size) return 0;
+
+ return pos;
+}
+
DnsRecordParser DnsResponse::Parser() const {
DCHECK(parser_.IsValid());
// Return a copy of the parser.
« 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