Enabling tests which should be fixed by r173829.
[chromium-blink-merge.git] / net / dns / dns_protocol.h
blobbbd8fa24b822d54d6e5e7c4156873f9a31757218
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef NET_DNS_DNS_PROTOCOL_H_
6 #define NET_DNS_DNS_PROTOCOL_H_
8 #include "base/basictypes.h"
9 #include "net/base/net_export.h"
11 namespace net {
13 namespace dns_protocol {
15 static const uint16 kDefaultPort = 53;
17 // DNS packet consists of a header followed by questions and/or answers.
18 // For the meaning of specific fields, please see RFC 1035 and 2535
20 // Header format.
21 // 1 1 1 1 1 1
22 // 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
23 // +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
24 // | ID |
25 // +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
26 // |QR| Opcode |AA|TC|RD|RA| Z|AD|CD| RCODE |
27 // +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
28 // | QDCOUNT |
29 // +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
30 // | ANCOUNT |
31 // +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
32 // | NSCOUNT |
33 // +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
34 // | ARCOUNT |
35 // +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
37 // Question format.
38 // 1 1 1 1 1 1
39 // 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
40 // +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
41 // | |
42 // / QNAME /
43 // / /
44 // +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
45 // | QTYPE |
46 // +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
47 // | QCLASS |
48 // +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
50 // Answer format.
51 // 1 1 1 1 1 1
52 // 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
53 // +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
54 // | |
55 // / /
56 // / NAME /
57 // | |
58 // +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
59 // | TYPE |
60 // +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
61 // | CLASS |
62 // +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
63 // | TTL |
64 // | |
65 // +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
66 // | RDLENGTH |
67 // +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--|
68 // / RDATA /
69 // / /
70 // +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
72 #pragma pack(push)
73 #pragma pack(1)
75 // On-the-wire header. All uint16 are in network order.
76 // Used internally in DnsQuery and DnsResponseParser.
77 struct NET_EXPORT_PRIVATE Header {
78 uint16 id;
79 uint16 flags;
80 uint16 qdcount;
81 uint16 ancount;
82 uint16 nscount;
83 uint16 arcount;
86 #pragma pack(pop)
88 static const uint8 kLabelMask = 0xc0;
89 static const uint8 kLabelPointer = 0xc0;
90 static const uint8 kLabelDirect = 0x0;
91 static const uint16 kOffsetMask = 0x3fff;
93 static const int kMaxNameLength = 255;
95 // RFC 1035, section 4.2.1: Messages carried by UDP are restricted to 512
96 // bytes (not counting the IP nor UDP headers).
97 static const int kMaxUDPSize = 512;
99 // DNS class types.
100 static const uint16 kClassIN = 1;
102 // DNS resource record types. See
103 // http://www.iana.org/assignments/dns-parameters
104 static const uint16 kTypeA = 1;
105 static const uint16 kTypeCNAME = 5;
106 static const uint16 kTypeTXT = 16;
107 static const uint16 kTypeAAAA = 28;
109 // DNS rcode values.
110 static const uint8 kRcodeMask = 0xf;
111 static const uint8 kRcodeNOERROR = 0;
112 static const uint8 kRcodeFORMERR = 1;
113 static const uint8 kRcodeSERVFAIL = 2;
114 static const uint8 kRcodeNXDOMAIN = 3;
115 static const uint8 kRcodeNOTIMP = 4;
116 static const uint8 kRcodeREFUSED = 5;
118 // DNS flags.
119 static const uint16 kFlagResponse = 0x8000;
120 static const uint16 kFlagRA = 0x80;
121 static const uint16 kFlagRD = 0x100;
122 static const uint16 kFlagTC = 0x200;
123 static const uint16 kFlagAA = 0x400;
125 } // namespace dns_protocol
127 } // namespace net
129 #endif // NET_DNS_DNS_PROTOCOL_H_