added shortening of unpacked string IPv6 addresses

Cette révision appartient à :
tigerbot 2017-05-22 18:22:54 -06:00
Parent 8960b9ae2a
révision f8cf8aef77
1 fichiers modifiés avec 14 ajouts et 0 suppressions

Voir le fichier

@ -27,6 +27,20 @@ exports.DNS_PARSER_TYPE_AAAA = function (ab, packet, record) {
s += dv.getUint16(i, false).toString(16); 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; record.address = s;
return record; return record;
}; };