OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "net/dns/mdns_query.h" |
| 6 |
| 7 #include "base/sys_byteorder.h" |
| 8 #include "net/base/big_endian.h" |
| 9 #include "net/base/dns_util.h" |
| 10 #include "net/dns/dns_protocol.h" |
| 11 |
| 12 namespace net { |
| 13 |
| 14 MDnsQuery::MDnsQuery(const base::StringPiece& qname, uint16 qtype) { |
| 15 DCHECK(!DNSDomainToString(qname).empty()); |
| 16 |
| 17 // QNAME + QTYPE + QCLASS |
| 18 size_t question_size = qname.size() + sizeof(uint16) + sizeof(uint16); |
| 19 io_buffer_ = new IOBufferWithSize(sizeof(dns_protocol::Header) + |
| 20 question_size); |
| 21 dns_protocol::Header* header = |
| 22 reinterpret_cast<dns_protocol::Header*>(io_buffer_->data()); |
| 23 memset(header, 0, sizeof(dns_protocol::Header)); |
| 24 // Do not set ID or flags. |
| 25 header->qdcount = base::HostToNet16(1); |
| 26 |
| 27 // Write question section after the header. |
| 28 BigEndianWriter writer(reinterpret_cast<char*>(header + 1), question_size); |
| 29 writer.WriteBytes(qname.data(), qname.size()); |
| 30 writer.WriteU16(qtype); |
| 31 writer.WriteU16(dns_protocol::kClassIN); |
| 32 } |
| 33 |
| 34 MDnsQuery::~MDnsQuery() { |
| 35 } |
| 36 } |
OLD | NEW |