| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 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 | 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/record_rdata.h" | 5 #include "net/dns/record_rdata.h" |
| 6 | 6 |
| 7 #include "net/base/big_endian.h" | 7 #include "base/big_endian.h" |
| 8 #include "net/base/dns_util.h" | 8 #include "net/base/dns_util.h" |
| 9 #include "net/dns/dns_protocol.h" | 9 #include "net/dns/dns_protocol.h" |
| 10 #include "net/dns/dns_response.h" | 10 #include "net/dns/dns_response.h" |
| 11 | 11 |
| 12 namespace net { | 12 namespace net { |
| 13 | 13 |
| 14 static const size_t kSrvRecordMinimumSize = 6; | 14 static const size_t kSrvRecordMinimumSize = 6; |
| 15 | 15 |
| 16 RecordRdata::RecordRdata() { | 16 RecordRdata::RecordRdata() { |
| 17 } | 17 } |
| 18 | 18 |
| 19 SrvRecordRdata::SrvRecordRdata() : priority_(0), weight_(0), port_(0) { | 19 SrvRecordRdata::SrvRecordRdata() : priority_(0), weight_(0), port_(0) { |
| 20 } | 20 } |
| 21 | 21 |
| 22 SrvRecordRdata::~SrvRecordRdata() {} | 22 SrvRecordRdata::~SrvRecordRdata() {} |
| 23 | 23 |
| 24 // static | 24 // static |
| 25 scoped_ptr<SrvRecordRdata> SrvRecordRdata::Create( | 25 scoped_ptr<SrvRecordRdata> SrvRecordRdata::Create( |
| 26 const base::StringPiece& data, | 26 const base::StringPiece& data, |
| 27 const DnsRecordParser& parser) { | 27 const DnsRecordParser& parser) { |
| 28 if (data.size() < kSrvRecordMinimumSize) return scoped_ptr<SrvRecordRdata>(); | 28 if (data.size() < kSrvRecordMinimumSize) return scoped_ptr<SrvRecordRdata>(); |
| 29 | 29 |
| 30 scoped_ptr<SrvRecordRdata> rdata(new SrvRecordRdata); | 30 scoped_ptr<SrvRecordRdata> rdata(new SrvRecordRdata); |
| 31 | 31 |
| 32 BigEndianReader reader(data.data(), data.size()); | 32 base::BigEndianReader reader(data.data(), data.size()); |
| 33 // 2 bytes for priority, 2 bytes for weight, 2 bytes for port. | 33 // 2 bytes for priority, 2 bytes for weight, 2 bytes for port. |
| 34 reader.ReadU16(&rdata->priority_); | 34 reader.ReadU16(&rdata->priority_); |
| 35 reader.ReadU16(&rdata->weight_); | 35 reader.ReadU16(&rdata->weight_); |
| 36 reader.ReadU16(&rdata->port_); | 36 reader.ReadU16(&rdata->port_); |
| 37 | 37 |
| 38 if (!parser.ReadName(data.substr(kSrvRecordMinimumSize).begin(), | 38 if (!parser.ReadName(data.substr(kSrvRecordMinimumSize).begin(), |
| 39 &rdata->target_)) | 39 &rdata->target_)) |
| 40 return scoped_ptr<SrvRecordRdata>(); | 40 return scoped_ptr<SrvRecordRdata>(); |
| 41 | 41 |
| 42 return rdata.Pass(); | 42 return rdata.Pass(); |
| (...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 278 bool NsecRecordRdata::GetBit(unsigned i) const { | 278 bool NsecRecordRdata::GetBit(unsigned i) const { |
| 279 unsigned byte_num = i/8; | 279 unsigned byte_num = i/8; |
| 280 if (bitmap_.size() < byte_num + 1) | 280 if (bitmap_.size() < byte_num + 1) |
| 281 return false; | 281 return false; |
| 282 | 282 |
| 283 unsigned bit_num = 7 - i % 8; | 283 unsigned bit_num = 7 - i % 8; |
| 284 return (bitmap_[byte_num] & (1 << bit_num)) != 0; | 284 return (bitmap_[byte_num] & (1 << bit_num)) != 0; |
| 285 } | 285 } |
| 286 | 286 |
| 287 } // namespace net | 287 } // namespace net |
| OLD | NEW |