Skip to content

Commit

Permalink
Implement QU bit support in question encoder/decoder
Browse files Browse the repository at this point in the history
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
  • Loading branch information
vulcainman committed Oct 9, 2023
1 parent 7b66620 commit a7a0b78
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1609,7 +1609,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
Expand All @@ -1630,12 +1630,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
}
Expand Down

0 comments on commit a7a0b78

Please sign in to comment.