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

Side by Side Diff: net/dns/dns_response.cc

Issue 9190031: DnsClient refactoring + features (timeout, suffix search, server rotation). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Added comments. Fixed tests. Created 8 years, 11 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "net/dns/dns_response.h" 5 #include "net/dns/dns_response.h"
6 6
7 #include "base/sys_byteorder.h" 7 #include "base/sys_byteorder.h"
8 #include "net/base/big_endian.h" 8 #include "net/base/big_endian.h"
9 #include "net/base/dns_util.h"
9 #include "net/base/io_buffer.h" 10 #include "net/base/io_buffer.h"
10 #include "net/base/net_errors.h" 11 #include "net/base/net_errors.h"
11 #include "net/dns/dns_protocol.h" 12 #include "net/dns/dns_protocol.h"
12 #include "net/dns/dns_query.h" 13 #include "net/dns/dns_query.h"
13 14
14 namespace net { 15 namespace net {
15 16
16 DnsResourceRecord::DnsResourceRecord() { 17 DnsResourceRecord::DnsResourceRecord() {
17 } 18 }
18 19
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 return false; 160 return false;
160 } 161 }
161 162
162 // Construct the parser. 163 // Construct the parser.
163 parser_ = DnsRecordParser(io_buffer_->data(), 164 parser_ = DnsRecordParser(io_buffer_->data(),
164 nbytes, 165 nbytes,
165 hdr_size + question.size()); 166 hdr_size + question.size());
166 return true; 167 return true;
167 } 168 }
168 169
169 uint8 DnsResponse::flags0() const { 170 uint16 DnsResponse::flags() const {
170 return header()->flags[0]; 171 return ntohs(header()->flags) & ~(dns_protocol::kRcodeMask);
171 }
172
173 uint8 DnsResponse::flags1() const {
174 return header()->flags[1] & ~(dns_protocol::kRcodeMask);
175 } 172 }
176 173
177 uint8 DnsResponse::rcode() const { 174 uint8 DnsResponse::rcode() const {
178 return header()->flags[1] & dns_protocol::kRcodeMask; 175 return ntohs(header()->flags) & dns_protocol::kRcodeMask;
179 } 176 }
180 177
181 int DnsResponse::answer_count() const { 178 int DnsResponse::answer_count() const {
182 return ntohs(header()->ancount); 179 return ntohs(header()->ancount);
183 } 180 }
184 181
182 base::StringPiece DnsResponse::qname() const {
183 DCHECK(parser_.IsValid());
184 const size_t hdr_size = sizeof(dns_protocol::Header);
185 const size_t qname_size = parser_.offset() - 2 * sizeof(uint16) - hdr_size;
mmenke 2012/01/13 16:44:37 Could you add a comment that this always works bec
186 return base::StringPiece(io_buffer_->data() + hdr_size,
187 qname_size);
188 }
189
190 uint16 DnsResponse::qtype() const {
191 DCHECK(parser_.IsValid());
192 const size_t type_offset = parser_.offset() - 2 * sizeof(uint16);
193 uint16 type;
194 ReadBigEndian<uint16>(io_buffer_->data() + type_offset,
195 &type);
196 return type;
197 }
198
199 std::string DnsResponse::GetDottedName() const {
200 DCHECK(parser_.IsValid());
201 return DNSDomainToString(qname());
202 }
203
204
mmenke 2012/01/13 16:44:37 nit: Remove extra linebreak.
185 DnsRecordParser DnsResponse::Parser() const { 205 DnsRecordParser DnsResponse::Parser() const {
186 DCHECK(parser_.IsValid()); 206 DCHECK(parser_.IsValid());
187 return parser_; 207 return parser_;
188 } 208 }
189 209
190 const dns_protocol::Header* DnsResponse::header() const { 210 const dns_protocol::Header* DnsResponse::header() const {
191 return reinterpret_cast<const dns_protocol::Header*>(io_buffer_->data()); 211 return reinterpret_cast<const dns_protocol::Header*>(io_buffer_->data());
192 } 212 }
193 213
194 } // namespace net 214 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698