Index: net/dns/mdns_query.cc |
diff --git a/net/dns/mdns_query.cc b/net/dns/mdns_query.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..80a6c23fe7b44116878bd7da2fd3adac1110b58f |
--- /dev/null |
+++ b/net/dns/mdns_query.cc |
@@ -0,0 +1,36 @@ |
+// Copyright (c) 2013 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "net/dns/mdns_query.h" |
+ |
+#include "base/sys_byteorder.h" |
+#include "net/base/big_endian.h" |
+#include "net/base/dns_util.h" |
+#include "net/dns/dns_protocol.h" |
+ |
+namespace net { |
+ |
+MDnsQuery::MDnsQuery(const base::StringPiece& qname, uint16 qtype) { |
+ DCHECK(!DNSDomainToString(qname).empty()); |
+ |
+ // QNAME + QTYPE + QCLASS |
+ size_t question_size = qname.size() + sizeof(uint16) + sizeof(uint16); |
+ 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)); |
+ // Do not set ID or flags. |
+ header->qdcount = base::HostToNet16(1); |
+ |
+ // Write question section after the header. |
+ BigEndianWriter writer(reinterpret_cast<char*>(header + 1), question_size); |
+ writer.WriteBytes(qname.data(), qname.size()); |
+ writer.WriteU16(qtype); |
+ writer.WriteU16(dns_protocol::kClassIN); |
+} |
+ |
+MDnsQuery::~MDnsQuery() { |
+} |
+} |