forked from LittleChest/dns-packet
Implement QU bit support in question encoder/decoder
This commit fix current QU bit implementation that may be used in mDNS
protocol. Indeed, until now, if a packet with QU bit set is received,
it is decoded as:
{
...
questions: [
{
name: '...',
type: 'PTR',
class: 'UNKNOWN_32769'
},
{
name: '...',
type: 'PTR',
class: 'UNKNOWN_32769'
}
],
...
}
Instead of :
{
...
questions: [
{
name: '...',
type: 'PTR',
class: 'IN'
},
{
name: '...',
type: 'PTR',
class: 'IN'
}
],
...
}
This commit adds a proper QU bit support via the qu_bit field.
It enables:
- The encoder to parse properly both the class and the QU bit
- THe decoder to encode a DNS packet with the QU bit set
This commit is contained in:
parent
5b155e76d9
commit
dfe5e3f86b
8
index.js
8
index.js
@ -1600,7 +1600,7 @@ question.encode = function (q, buf, offset) {
|
||||
buf.writeUInt16BE(types.toType(q.type), offset)
|
||||
offset += 2
|
||||
|
||||
buf.writeUInt16BE(classes.toClass(q.class === undefined ? 'IN' : q.class), offset)
|
||||
buf.writeUInt16BE(((q.qu_bit === undefined || !q.qu_bit) ? 0 : QU_MASK) | classes.toClass(q.class === undefined ? 'IN' : q.class), offset)
|
||||
offset += 2
|
||||
|
||||
question.encode.bytes = offset - oldOffset
|
||||
@ -1621,12 +1621,10 @@ question.decode = function (buf, offset) {
|
||||
q.type = types.toString(buf.readUInt16BE(offset))
|
||||
offset += 2
|
||||
|
||||
q.class = classes.toString(buf.readUInt16BE(offset))
|
||||
q.qu_bit = (buf.readUInt16BE(offset) & QU_MASK) != 0;
|
||||
q.class = q.qu_bit ? classes.toString(buf.readUInt16BE(offset) - QU_MASK) : classes.toString(buf.readUInt16BE(offset));
|
||||
offset += 2
|
||||
|
||||
const qu = !!(q.class & QU_MASK)
|
||||
if (qu) q.class &= NOT_QU_MASK
|
||||
|
||||
question.decode.bytes = offset - oldOffset
|
||||
return q
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user