blob: db44158745b64842b3006e663835bea239cdfe1e [file] [log] [blame]
[email protected]d0d49dd82012-01-26 00:03:591// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]c36f0642009-09-09 01:10:502// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef NET_BASE_DNS_UTIL_H_
6#define NET_BASE_DNS_UTIL_H_
[email protected]c36f0642009-09-09 01:10:507
8#include <string>
9
[email protected]b3ccac82010-08-04 15:54:4010#include "base/basictypes.h"
[email protected]d10740b2011-05-24 19:26:3111#include "base/string_piece.h"
[email protected]172da1b2011-08-12 15:52:2612#include "net/base/net_export.h"
[email protected]b3ccac82010-08-04 15:54:4013
[email protected]c36f0642009-09-09 01:10:5014namespace net {
15
16// DNSDomainFromDot - convert a domain string to DNS format. From DJB's
17// public domain DNS library.
18//
19// dotted: a string in dotted form: "www.google.com"
20// out: a result in DNS form: "\x03www\x06google\x03com\x00"
[email protected]7556ea22011-12-08 19:29:1521NET_EXPORT_PRIVATE bool DNSDomainFromDot(const base::StringPiece& dotted,
[email protected]172da1b2011-08-12 15:52:2622 std::string* out);
[email protected]c36f0642009-09-09 01:10:5023
[email protected]d0d49dd82012-01-26 00:03:5924// DNSDomainToString converts a domain in DNS format to a dotted string.
25// Excludes the dot at the end.
[email protected]7556ea22011-12-08 19:29:1526NET_EXPORT_PRIVATE std::string DNSDomainToString(
27 const base::StringPiece& domain);
[email protected]f060be32011-02-17 17:20:2828
[email protected]c36f0642009-09-09 01:10:5029// Returns true iff the given character is in the set of valid DNS label
30// characters as given in RFC 3490, 4.1, 3(a)
[email protected]172da1b2011-08-12 15:52:2631NET_EXPORT_PRIVATE bool IsSTD3ASCIIValidCharacter(char c);
[email protected]c36f0642009-09-09 01:10:5032
[email protected]13c340e12010-03-08 19:29:4133// Returns the hostname by trimming the ending dot, if one exists.
[email protected]7556ea22011-12-08 19:29:1534NET_EXPORT std::string TrimEndingDot(const base::StringPiece& host);
35
36// TODO(szym): remove all definitions below once DnsRRResolver migrates to
37// DnsClient
[email protected]13c340e12010-03-08 19:29:4138
[email protected]b5810642011-06-03 21:26:4939// DNS class types.
40static const uint16 kClassIN = 1;
41
[email protected]b3ccac82010-08-04 15:54:4042// DNS resource record types. See
43// http://www.iana.org/assignments/dns-parameters
[email protected]c284be32012-02-23 15:51:3444// WARNING: if you're adding any new values here you may need to add them to
45// dnsrr_resolver.cc:DnsRRIsParsedByWindows.
46static const uint16 kDNS_A = 1;
[email protected]b40f05a2010-09-09 20:13:2347static const uint16 kDNS_CNAME = 5;
[email protected]b3ccac82010-08-04 15:54:4048static const uint16 kDNS_TXT = 16;
[email protected]c284be32012-02-23 15:51:3449static const uint16 kDNS_AAAA = 28;
[email protected]b3ccac82010-08-04 15:54:4050static const uint16 kDNS_CERT = 37;
[email protected]b24713592010-08-11 19:50:0251static const uint16 kDNS_DS = 43;
52static const uint16 kDNS_RRSIG = 46;
53static const uint16 kDNS_DNSKEY = 48;
[email protected]c284be32012-02-23 15:51:3454static const uint16 kDNS_ANY = 0xff;
[email protected]bad796d2011-06-02 21:06:5455static const uint16 kDNS_CAA = 257;
[email protected]c284be32012-02-23 15:51:3456static const uint16 kDNS_TESTING = 0xfffe; // in private use area.
[email protected]b3ccac82010-08-04 15:54:4057
[email protected]b24713592010-08-11 19:50:0258// http://www.iana.org/assignments/dns-sec-alg-numbers/dns-sec-alg-numbers.xhtml
59static const uint8 kDNSSEC_RSA_SHA1 = 5;
60static const uint8 kDNSSEC_RSA_SHA1_NSEC3 = 7;
61static const uint8 kDNSSEC_RSA_SHA256 = 8;
[email protected]659ba742012-04-17 19:05:1562static const uint8 kDNSSEC_RSA_SHA512 = 10;
[email protected]b24713592010-08-11 19:50:0263
64// RFC 4509
65static const uint8 kDNSSEC_SHA1 = 1;
66static const uint8 kDNSSEC_SHA256 = 2;
67
[email protected]c284be32012-02-23 15:51:3468// A Buffer is used for walking over a DNS response packet.
69class DnsResponseBuffer {
70 public:
71 DnsResponseBuffer(const uint8* p, unsigned len)
72 : p_(p),
73 packet_(p),
74 len_(len),
75 packet_len_(len) {
76 }
77
78 bool U8(uint8* v);
79 bool U16(uint16* v);
80 bool U32(uint32* v);
81 bool Skip(unsigned n);
82
83 bool Block(base::StringPiece* out, unsigned len);
84
85 // DNSName parses a (possibly compressed) DNS name from the packet. If |name|
86 // is not NULL, then the name is written into it. See RFC 1035 section 4.1.4.
87 bool DNSName(std::string* name);
88
89 private:
90 const uint8* p_;
91 const uint8* const packet_;
92 unsigned len_;
93 const unsigned packet_len_;
94
95 DISALLOW_COPY_AND_ASSIGN(DnsResponseBuffer);
96};
97
98
[email protected]c36f0642009-09-09 01:10:5099} // namespace net
100
101#endif // NET_BASE_DNS_UTIL_H_