From f8cf8aef77e6f3f093178269dd8f145603eeee40 Mon Sep 17 00:00:00 2001 From: tigerbot Date: Mon, 22 May 2017 18:22:54 -0600 Subject: [PATCH] added shortening of unpacked string IPv6 addresses --- parser/type.aaaa.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/parser/type.aaaa.js b/parser/type.aaaa.js index 9a05653..e05f20b 100644 --- a/parser/type.aaaa.js +++ b/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; };