Skip to content

Commit

Permalink
Packet.Resource.EDNS.ECS.decode now supports IPv6 subnets
Browse files Browse the repository at this point in the history
  • Loading branch information
herenickname authored and lsongdev committed Aug 23, 2024
1 parent 6ffa410 commit 0fed203
Showing 1 changed file with 21 additions and 12 deletions.
33 changes: 21 additions & 12 deletions packet.js
Original file line number Diff line number Diff line change
Expand Up @@ -794,21 +794,30 @@ Packet.Resource.EDNS.ECS.decode = function(reader, length) {
rdata.scopePrefixLength = reader.read(8);
length -= 4;

if (rdata.family !== 1) {
debug('node-dns > unimplemented address family');
reader.read(length * 8); // Ignore data that doesn't understand
return rdata;
if (rdata.family === 1) {
const ipv4Octets = [];
while (length--) {
const octet = reader.read(8);
ipv4Octets.push(octet);
}
while (ipv4Octets.length < 4) {
ipv4Octets.push(0);
}
rdata.ip = ipv4Octets.join('.');
}

const ipv4Octets = [];
while (length--) {
const octet = reader.read(8);
ipv4Octets.push(octet);
}
while (ipv4Octets.length < 4) {
ipv4Octets.push(0);
if (rdata.family === 2) {
const ipv6Segments = [];
for (; length; length -= 2) {
const segment = reader.read(16).toString(16);
ipv6Segments.push(segment);
}
while (ipv6Segments.length < 8) {
ipv6Segments.push('0');
}
rdata.ip = ipv6Segments.join(':');
}
rdata.ip = ipv4Octets.join('.');

return rdata;
};

Expand Down

0 comments on commit 0fed203

Please sign in to comment.