OLD | NEW |
---|---|
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 Loading... | |
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 bool DnsResponse::is_valid() const { |
170 return header()->flags[0]; | 171 return parser_.is_valid(); |
171 } | 172 } |
172 | 173 |
173 uint8 DnsResponse::flags1() const { | 174 uint16 DnsResponse::flags() const { |
174 return header()->flags[1] & ~(dns_protocol::kRcodeMask); | 175 DCHECK(parser_.is_valid()); |
176 return ntohs(header()->flags) & ~(dns_protocol::kRcodeMask); | |
175 } | 177 } |
176 | 178 |
177 uint8 DnsResponse::rcode() const { | 179 uint8 DnsResponse::rcode() const { |
178 return header()->flags[1] & dns_protocol::kRcodeMask; | 180 DCHECK(parser_.is_valid()); |
181 return ntohs(header()->flags) & dns_protocol::kRcodeMask; | |
179 } | 182 } |
180 | 183 |
181 int DnsResponse::answer_count() const { | 184 int DnsResponse::answer_count() const { |
185 DCHECK(parser_.is_valid()); | |
182 return ntohs(header()->ancount); | 186 return ntohs(header()->ancount); |
183 } | 187 } |
184 | 188 |
189 base::StringPiece DnsResponse::qname() const { | |
190 DCHECK(parser_.is_valid()); | |
191 const size_t hdr_size = sizeof(dns_protocol::Header); | |
192 const size_t qname_size = parser_.offset() - 2 * sizeof(uint16) - hdr_size; | |
cbentzel
2012/01/13 22:17:25
This would benefit from an explanation - particula
| |
193 return base::StringPiece(io_buffer_->data() + hdr_size, | |
194 qname_size); | |
195 } | |
196 | |
197 uint16 DnsResponse::qtype() const { | |
198 DCHECK(parser_.is_valid()); | |
199 const size_t type_offset = parser_.offset() - 2 * sizeof(uint16); | |
200 uint16 type; | |
201 ReadBigEndian<uint16>(io_buffer_->data() + type_offset, | |
202 &type); | |
203 return type; | |
204 } | |
205 | |
206 std::string DnsResponse::GetDottedName() const { | |
207 return DNSDomainToString(qname()); | |
cbentzel
2012/01/13 22:17:25
[Note to self: Looks like the expansion is done by
szym
2012/01/17 15:38:25
The whole question section must be exactly as in t
| |
208 } | |
209 | |
185 DnsRecordParser DnsResponse::Parser() const { | 210 DnsRecordParser DnsResponse::Parser() const { |
186 DCHECK(parser_.IsValid()); | 211 DCHECK(parser_.is_valid()); |
212 // Return a copy of the parser. | |
187 return parser_; | 213 return parser_; |
188 } | 214 } |
189 | 215 |
190 const dns_protocol::Header* DnsResponse::header() const { | 216 const dns_protocol::Header* DnsResponse::header() const { |
191 return reinterpret_cast<const dns_protocol::Header*>(io_buffer_->data()); | 217 return reinterpret_cast<const dns_protocol::Header*>(io_buffer_->data()); |
192 } | 218 } |
193 | 219 |
194 } // namespace net | 220 } // namespace net |
OLD | NEW |