Decode RCODE and other header flags. Fixes #11.
This commit is contained in:
parent
5aaf0790d9
commit
eabaaa5156
10
index.js
10
index.js
@ -1,4 +1,5 @@
|
||||
var types = require('./types')
|
||||
var rcodes = require('./rcodes')
|
||||
var ip = require('ip')
|
||||
var Buffer = require('safe-buffer').Buffer
|
||||
|
||||
@ -126,6 +127,15 @@ header.decode = function (buf, offset) {
|
||||
id: buf.readUInt16BE(offset),
|
||||
type: flags & RESPONSE_FLAG ? 'response' : 'query',
|
||||
flags: flags & 32767,
|
||||
opcode: (flags >> 11) & 0xf,
|
||||
flag_auth: (flags >> 10) & 0x1,
|
||||
flag_trunc: (flags >> 9) & 0x1,
|
||||
flag_rd: (flags >> 8) & 0x1,
|
||||
flag_ra: (flags >> 7) & 0x1,
|
||||
flag_z: (flags >> 6) & 0x1,
|
||||
flag_ad: (flags >> 5) & 0x1,
|
||||
flag_cd: (flags >> 4) & 0x1,
|
||||
rcode: rcodes.toString(flags & 0xf),
|
||||
questions: new Array(buf.readUInt16BE(offset + 4)),
|
||||
answers: new Array(buf.readUInt16BE(offset + 6)),
|
||||
authorities: new Array(buf.readUInt16BE(offset + 8)),
|
||||
|
||||
@ -32,7 +32,8 @@
|
||||
],
|
||||
"files": [
|
||||
"index.js",
|
||||
"types.js"
|
||||
"types.js",
|
||||
"rcodes.js"
|
||||
],
|
||||
"author": "Mathias Buus",
|
||||
"license": "MIT"
|
||||
|
||||
48
rcodes.js
Normal file
48
rcodes.js
Normal file
@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Traditional DNS header RCODEs (4-bits) defined by IANA in
|
||||
* https://www.iana.org/assignments/dns-parameters/dns-parameters.xhtml
|
||||
*/
|
||||
|
||||
exports.toString = function (rcode) {
|
||||
switch (rcode) {
|
||||
case 0: return 'NOERROR'
|
||||
case 1: return 'FORMERR'
|
||||
case 2: return 'SERVFAIL'
|
||||
case 3: return 'NXDOMAIN'
|
||||
case 4: return 'NOTIMP'
|
||||
case 5: return 'REFUSED'
|
||||
case 6: return 'YXDOMAIN'
|
||||
case 7: return 'YXRRSET'
|
||||
case 8: return 'NXRRSET'
|
||||
case 9: return 'NOTAUTH'
|
||||
case 10: return 'NOTZONE'
|
||||
case 11: return 'RCODE_11'
|
||||
case 12: return 'RCODE_12'
|
||||
case 13: return 'RCODE_13'
|
||||
case 14: return 'RCODE_14'
|
||||
case 15: return 'RCODE_15'
|
||||
}
|
||||
return 'RCODE_' + type
|
||||
}
|
||||
|
||||
exports.toRcode = function (code) {
|
||||
switch (code.toUpperCase()) {
|
||||
case 'NOERROR': return 0
|
||||
case 'FORMERR': return 1
|
||||
case 'SERVFAIL': return 2
|
||||
case 'NXDOMAIN': return 3
|
||||
case 'NOTIMP': return 4
|
||||
case 'REFUSED': return 5
|
||||
case 'YXDOMAIN': return 6
|
||||
case 'YXRRSET': return 7
|
||||
case 'NXRRSET': return 8
|
||||
case 'NOTAUTH': return 9
|
||||
case 'NOTZONE': return 10
|
||||
case 'RCODE_11': return 11
|
||||
case 'RCODE_12': return 12
|
||||
case 'RCODE_13': return 13
|
||||
case 'RCODE_14': return 14
|
||||
case 'RCODE_15': return 15
|
||||
}
|
||||
return 0
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user