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

Unified Diff: net/dns/dns_query.cc

Issue 1546623002: net: add a convenience getter accessor for dns Header to DnsQuery (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: replace memset Created 5 years 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_query.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/dns/dns_query.cc
diff --git a/net/dns/dns_query.cc b/net/dns/dns_query.cc
index 0966def976d8b0c3189fc116561f1df034e871b7..1c78295ad1ac3a080e0b842bc5c3c44442386ca0 100644
--- a/net/dns/dns_query.cc
+++ b/net/dns/dns_query.cc
@@ -4,8 +4,6 @@
#include "net/dns/dns_query.h"
-#include <limits>
-
#include "base/big_endian.h"
#include "base/sys_byteorder.h"
#include "net/base/io_buffer.h"
@@ -25,15 +23,13 @@ DnsQuery::DnsQuery(uint16_t id, const base::StringPiece& qname, uint16_t qtype)
size_t question_size = qname_size_ + sizeof(uint16_t) + sizeof(uint16_t);
io_buffer_ = new IOBufferWithSize(sizeof(dns_protocol::Header) +
question_size);
- dns_protocol::Header* header =
- reinterpret_cast<dns_protocol::Header*>(io_buffer_->data());
- memset(header, 0, sizeof(dns_protocol::Header));
- header->id = base::HostToNet16(id);
- header->flags = base::HostToNet16(dns_protocol::kFlagRD);
- header->qdcount = base::HostToNet16(1);
+ *header() = {};
+ header()->id = base::HostToNet16(id);
+ header()->flags = base::HostToNet16(dns_protocol::kFlagRD);
+ header()->qdcount = base::HostToNet16(1);
// Write question section after the header.
- base::BigEndianWriter writer(reinterpret_cast<char*>(header + 1),
+ base::BigEndianWriter writer(reinterpret_cast<char*>(header() + 1),
question_size);
writer.WriteBytes(qname.data(), qname.size());
writer.WriteU16(qtype);
@@ -70,20 +66,20 @@ base::StringPiece DnsQuery::question() const {
qname_size_ + sizeof(uint16_t) + sizeof(uint16_t));
}
+void DnsQuery::set_flags(uint16_t flags) {
+ header()->flags = flags;
+}
+
DnsQuery::DnsQuery(const DnsQuery& orig, uint16_t id) {
qname_size_ = orig.qname_size_;
io_buffer_ = new IOBufferWithSize(orig.io_buffer()->size());
memcpy(io_buffer_.get()->data(), orig.io_buffer()->data(),
io_buffer_.get()->size());
- dns_protocol::Header* header =
- reinterpret_cast<dns_protocol::Header*>(io_buffer_->data());
- header->id = base::HostToNet16(id);
+ header()->id = base::HostToNet16(id);
}
-void DnsQuery::set_flags(uint16_t flags) {
- dns_protocol::Header* header =
- reinterpret_cast<dns_protocol::Header*>(io_buffer_->data());
- header->flags = flags;
+dns_protocol::Header* DnsQuery::header() {
+ return reinterpret_cast<dns_protocol::Header*>(io_buffer_->data());
}
} // namespace net
« no previous file with comments | « net/dns/dns_query.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698