1 | /*
|
2 | Copyright 2011 Timothy J Fontaine <tjfontaine@gmail.com>
|
3 |
|
4 | Permission is hereby granted, free of charge, to any person obtaining a copy
|
5 | of this software and associated documentation files (the "Software"), to deal
|
6 | in the Software without restriction, including without limitation the rights
|
7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
8 | copies of the Software, and to permit persons to whom the Software is
|
9 | furnished to do so, subject to the following conditions:
|
10 |
|
11 | The above copyright notice and this permission notice shall be included in
|
12 | all copies or substantial portions of the Software.
|
13 |
|
14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
20 |
|
21 | */
|
22 |
|
23 | ;
|
24 |
|
25 | var util = require('util'),
|
26 | fields = require('./fields'),
|
27 | Message = require('./message');
|
28 |
|
29 | var headerFields = [
|
30 | fields.Struct('id', 'H'),
|
31 | fields.Struct('bitfields', 'H'),
|
32 | fields.Struct('qdcount', 'H'),
|
33 | fields.Struct('ancount', 'H'),
|
34 | fields.Struct('nscount', 'H'),
|
35 | fields.Struct('arcount', 'H'),
|
36 | ];
|
37 |
|
38 | var bitFields = [
|
39 | fields.SubField('qr', 'bitfields', 15, 0x8000),
|
40 | fields.SubField('opcode', 'bitfields', 11, 0x7800),
|
41 | fields.SubField('aa', 'bitfields', 10, 0x400),
|
42 | fields.SubField('tc', 'bitfields', 9, 0x200),
|
43 | fields.SubField('rd', 'bitfields', 8, 0x100),
|
44 | fields.SubField('ra', 'bitfields', 7, 0x80),
|
45 | fields.SubField('res1', 'bitfields', 6, 0x40),
|
46 | fields.SubField('res2', 'bitfields', 5, 0x20),
|
47 | fields.SubField('res3', 'bitfields', 4, 0x10),
|
48 | fields.SubField('rcode', 'bitfields', 0, 0xf),
|
49 | ];
|
50 |
|
51 | var Header = function () {
|
52 | this._fields = headerFields;
|
53 | this._sub_fields = bitFields;
|
54 | Message.call(this);
|
55 | };
|
56 | util.inherits(Header, Message);
|
57 |
|
58 | module.exports = Header;
|