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

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
Index: net/dns/dns_response.cc
diff --git a/net/dns/dns_response.cc b/net/dns/dns_response.cc
index 625e7c041dc0ddfc0eb5c02dc650b22d58fba7d2..f14e2a81ef0938f492d48ea7749d34fc9dd70b0f 100644
--- a/net/dns/dns_response.cc
+++ b/net/dns/dns_response.cc
@@ -175,6 +175,20 @@ 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.
+ size_t response_offset = GetResponseOffset();
+ if (response_offset == 0)
+ return false;
+
+ parser_ = DnsRecordParser(
+ io_buffer_->data(), nbytes, response_offset);
+ return true;
+}
+
bool DnsResponse::IsValid() const {
return parser_.IsValid();
}
@@ -217,6 +231,39 @@ std::string DnsResponse::GetDottedName() const {
return DNSDomainToString(qname());
}
+size_t DnsResponse::GetResponseOffset() const {
szym 2013/04/17 22:11:12 Use DnsRecordParser instead. ReadName with |out| s
Noam Samuel 2013/04/18 19:03:17 Done.
+ 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;
szym 2013/04/17 22:11:12 This is an error. At this point you should be done
Noam Samuel 2013/04/18 19:03:17 Made irrelevant. On 2013/04/17 22:11:12, szym wro
+ }
+
+ 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.

Powered by Google App Engine
This is Rietveld 408576698