added shortening of unpacked string IPv6 addresses
This commit is contained in:
parent
8960b9ae2a
commit
f8cf8aef77
|
@ -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…
Reference in New Issue