blob: 939a4a71e3ee2f67a5f99bb51e1ce64c9d9518b8 [file] [log] [blame]
[email protected]13677b82011-05-18 18:29:361// Copyright (c) 2011 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]32b76ef2010-07-26 23:08:247#pragma once
[email protected]c36f0642009-09-09 01:10:508
9#include <string>
10
[email protected]b3ccac82010-08-04 15:54:4011#include "base/basictypes.h"
[email protected]d10740b2011-05-24 19:26:3112#include "base/string_piece.h"
[email protected]13677b82011-05-18 18:29:3613#include "net/base/net_api.h"
[email protected]b3ccac82010-08-04 15:54:4014
[email protected]c36f0642009-09-09 01:10:5015namespace net {
16
17// DNSDomainFromDot - convert a domain string to DNS format. From DJB's
18// public domain DNS library.
19//
20// dotted: a string in dotted form: "www.google.com"
21// out: a result in DNS form: "\x03www\x06google\x03com\x00"
[email protected]13677b82011-05-18 18:29:3622NET_TEST bool DNSDomainFromDot(const std::string& dotted, std::string* out);
[email protected]c36f0642009-09-09 01:10:5023
[email protected]f060be32011-02-17 17:20:2824// DNSDomainToString coverts a domain in DNS format to a dotted string.
[email protected]13677b82011-05-18 18:29:3625NET_TEST std::string DNSDomainToString(const std::string& domain);
[email protected]f060be32011-02-17 17:20:2826
[email protected]c36f0642009-09-09 01:10:5027// Returns true iff the given character is in the set of valid DNS label
28// characters as given in RFC 3490, 4.1, 3(a)
[email protected]13677b82011-05-18 18:29:3629NET_TEST bool IsSTD3ASCIIValidCharacter(char c);
[email protected]c36f0642009-09-09 01:10:5030
[email protected]13c340e12010-03-08 19:29:4131// Returns the hostname by trimming the ending dot, if one exists.
[email protected]d01c6bd2011-05-31 23:20:5932NET_API std::string TrimEndingDot(const std::string& host);
[email protected]13c340e12010-03-08 19:29:4133
[email protected]b5810642011-06-03 21:26:4934// DNS class types.
35static const uint16 kClassIN = 1;
36
[email protected]b3ccac82010-08-04 15:54:4037// DNS resource record types. See
38// http://www.iana.org/assignments/dns-parameters
[email protected]b1d8c252011-01-13 20:27:5039// WARNING: if you're adding any new values here you may need to add them to
40// dnsrr_resolver.cc:DnsRRIsParsedByWindows.
[email protected]b5810642011-06-03 21:26:4941static const uint16 kDNS_A = 1;
[email protected]b40f05a2010-09-09 20:13:2342static const uint16 kDNS_CNAME = 5;
[email protected]b3ccac82010-08-04 15:54:4043static const uint16 kDNS_TXT = 16;
[email protected]b5810642011-06-03 21:26:4944static const uint16 kDNS_AAAA = 28;
[email protected]b3ccac82010-08-04 15:54:4045static const uint16 kDNS_CERT = 37;
[email protected]b24713592010-08-11 19:50:0246static const uint16 kDNS_DS = 43;
47static const uint16 kDNS_RRSIG = 46;
48static const uint16 kDNS_DNSKEY = 48;
[email protected]b3ccac82010-08-04 15:54:4049static const uint16 kDNS_ANY = 0xff;
[email protected]bad796d2011-06-02 21:06:5450static const uint16 kDNS_CAA = 257;
[email protected]9cf1e9da72010-09-30 16:13:1551static const uint16 kDNS_TESTING = 0xfffe; // in private use area.
[email protected]b3ccac82010-08-04 15:54:4052
[email protected]b24713592010-08-11 19:50:0253// http://www.iana.org/assignments/dns-sec-alg-numbers/dns-sec-alg-numbers.xhtml
54static const uint8 kDNSSEC_RSA_SHA1 = 5;
55static const uint8 kDNSSEC_RSA_SHA1_NSEC3 = 7;
56static const uint8 kDNSSEC_RSA_SHA256 = 8;
57
58// RFC 4509
59static const uint8 kDNSSEC_SHA1 = 1;
60static const uint8 kDNSSEC_SHA256 = 2;
61
[email protected]d10740b2011-05-24 19:26:3162// A Buffer is used for walking over a DNS response packet.
63class DnsResponseBuffer {
64 public:
65 DnsResponseBuffer(const uint8* p, unsigned len)
66 : p_(p),
67 packet_(p),
68 len_(len),
69 packet_len_(len) {
70 }
71
72 bool U8(uint8* v);
73 bool U16(uint16* v);
74 bool U32(uint32* v);
75 bool Skip(unsigned n);
76
77 bool Block(base::StringPiece* out, unsigned len);
78
79 // DNSName parses a (possibly compressed) DNS name from the packet. If |name|
80 // is not NULL, then the name is written into it. See RFC 1035 section 4.1.4.
81 bool DNSName(std::string* name);
82
83 private:
84 const uint8* p_;
85 const uint8* const packet_;
86 unsigned len_;
87 const unsigned packet_len_;
88
89 DISALLOW_COPY_AND_ASSIGN(DnsResponseBuffer);
90};
91
92
[email protected]c36f0642009-09-09 01:10:5093} // namespace net
94
95#endif // NET_BASE_DNS_UTIL_H_