Chromium Code Reviews| Index: net/dns/dns_query.cc |
| diff --git a/net/dns/dns_query.cc b/net/dns/dns_query.cc |
| index 0966def976d8b0c3189fc116561f1df034e871b7..c47aeafb8bc9c1fe8aba8f1ddc5a26b5b49cce45 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); |
| + memset(header(), 0, sizeof(dns_protocol::Header)); |
|
pauljensen
2015/12/29 12:38:02
I don't like how the sizeof() uses a length differ
tfarina
2015/12/29 13:57:43
I don't see how this matters much. I don't think c
pauljensen
2015/12/29 15:06:22
You're making this code more fragile and susceptib
tfarina
2015/12/29 18:48:01
Sorry, I'm not getting your point Paul. The code h
pauljensen
2015/12/29 19:42:37
I dislike memset() because it's very type-unsafe.
tfarina
2015/12/29 19:57:07
Sorry, someone changing one but not the other? How
|
| + 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), |
|
pauljensen
2015/12/29 12:38:02
I'd much rather all this was rewritten in a more t
tfarina
2015/12/29 13:57:43
Maybe? I don't think this belongs to this change.
pauljensen
2015/12/29 15:06:22
Acknowledged.
|
| 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 |