add MX record type
Fixes: https://github.com/mafintosh/dns-packet/issues/10
This commit is contained in:
parent
8000f406c8
commit
087d59bb63
@ -245,6 +245,15 @@ When encoding, scalar values are converted to an array and strings are converted
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
#### `MX`
|
||||||
|
|
||||||
|
``` js
|
||||||
|
{
|
||||||
|
preference: 10,
|
||||||
|
exchange: 'mail.example.net'
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
If you need another one, open an issue and we'll try to add it.
|
If you need another one, open an issue and we'll try to add it.
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|||||||
41
index.js
41
index.js
@ -564,6 +564,46 @@ rcaa.encodingLength = function (data) {
|
|||||||
return string.encodingLength(data.tag) + string.encodingLength(data.value) + 2
|
return string.encodingLength(data.tag) + string.encodingLength(data.value) + 2
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const rmx = exports.mx = {}
|
||||||
|
|
||||||
|
rmx.encode = function (data, buf, offset) {
|
||||||
|
if (!buf) buf = Buffer.allocUnsafe(rmx.encodingLength(data))
|
||||||
|
if (!offset) offset = 0
|
||||||
|
|
||||||
|
const oldOffset = offset
|
||||||
|
offset += 2
|
||||||
|
buf.writeUInt16BE(data.preference || 0, offset)
|
||||||
|
offset += 2
|
||||||
|
name.encode(data.exchange, buf, offset)
|
||||||
|
offset += name.encode.bytes
|
||||||
|
|
||||||
|
buf.writeUInt16BE(offset - oldOffset - 2, oldOffset)
|
||||||
|
rmx.encode.bytes = offset - oldOffset
|
||||||
|
return buf
|
||||||
|
}
|
||||||
|
|
||||||
|
rmx.encode.bytes = 0
|
||||||
|
|
||||||
|
rmx.decode = function (buf, offset) {
|
||||||
|
if (!offset) offset = 0
|
||||||
|
|
||||||
|
const oldOffset = offset
|
||||||
|
|
||||||
|
const data = {}
|
||||||
|
offset += 2
|
||||||
|
data.preference = buf.readUInt16BE(offset)
|
||||||
|
offset += 2
|
||||||
|
data.exchange = name.decode(buf, offset)
|
||||||
|
offset += name.decode.bytes
|
||||||
|
|
||||||
|
rmx.decode.bytes = offset - oldOffset
|
||||||
|
return data
|
||||||
|
}
|
||||||
|
|
||||||
|
rmx.encodingLength = function (data) {
|
||||||
|
return 4 + name.encodingLength(data.exchange)
|
||||||
|
}
|
||||||
|
|
||||||
const ra = exports.a = {}
|
const ra = exports.a = {}
|
||||||
|
|
||||||
ra.encode = function (host, buf, offset) {
|
ra.encode = function (host, buf, offset) {
|
||||||
@ -638,6 +678,7 @@ const renc = exports.record = function (type) {
|
|||||||
case 'CAA': return rcaa
|
case 'CAA': return rcaa
|
||||||
case 'NS': return rns
|
case 'NS': return rns
|
||||||
case 'SOA': return rsoa
|
case 'SOA': return rsoa
|
||||||
|
case 'MX': return rmx
|
||||||
}
|
}
|
||||||
return runknown
|
return runknown
|
||||||
}
|
}
|
||||||
|
|||||||
6
test.js
6
test.js
@ -83,6 +83,12 @@ tape('caa', function (t) {
|
|||||||
t.end()
|
t.end()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
tape('mx', function (t) {
|
||||||
|
testEncoder(t, packet.mx, {preference: 10, exchange: 'mx.hello.world.com'})
|
||||||
|
testEncoder(t, packet.mx, {exchange: 'mx.hello.world.com'})
|
||||||
|
t.end()
|
||||||
|
})
|
||||||
|
|
||||||
tape('ns', function (t) {
|
tape('ns', function (t) {
|
||||||
testEncoder(t, packet.ns, 'ns.world.com')
|
testEncoder(t, packet.ns, 'ns.world.com')
|
||||||
t.end()
|
t.end()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user