Browse Source

added shortening of unpacked string IPv6 addresses

v1.0
tigerbot 7 years ago
parent
commit
f8cf8aef77
  1. 14
      parser/type.aaaa.js

14
parser/type.aaaa.js

@ -27,6 +27,20 @@ exports.DNS_PARSER_TYPE_AAAA = function (ab, packet, record) {
s += dv.getUint16(i, false).toString(16);
}
// Represent the string address as recommended on the wikipedia page
// https://en.wikipedia.org/wiki/IPv6_address#Recommended_representation_as_text.
// (shorten the longest section of 0's as long as it's more than one section, replacing
// the left-most instance in the event of ties.)
var re = /:(0:)+/g;
var match;
var longest = '_BAD';
while (!!(match = re.exec(s))) {
if (match[0].length > longest.length) {
longest = match[0];
}
}
s = s.replace(longest, '::');
record.address = s;
return record;
};

Loading…
Cancel
Save