dns2 2.0.4 → 2.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/packet.js +7 -5
- package/test/index.js +7 -0
package/package.json
CHANGED
package/packet.js
CHANGED
|
@@ -4,6 +4,11 @@ const BufferWriter = require('./lib/writer');
|
|
|
4
4
|
|
|
5
5
|
const debug = debuglog('dns2');
|
|
6
6
|
|
|
7
|
+
const toIPv6 = buffer => buffer
|
|
8
|
+
.map(part => (part > 0 ? part.toString(16) : '0'))
|
|
9
|
+
.join(':')
|
|
10
|
+
.replace(/\b(?:0+:){1,}/, ':');
|
|
11
|
+
|
|
7
12
|
/**
|
|
8
13
|
* [Packet description]
|
|
9
14
|
* @param {[type]} data [description]
|
|
@@ -514,11 +519,7 @@ Packet.Resource.AAAA = {
|
|
|
514
519
|
length -= 2;
|
|
515
520
|
parts.push(reader.read(16));
|
|
516
521
|
}
|
|
517
|
-
this.address = parts
|
|
518
|
-
.map(part => part > 0 ? part.toString(16) : '')
|
|
519
|
-
.join(':')
|
|
520
|
-
.replace('::::', '::')
|
|
521
|
-
.replace(':::', '::');
|
|
522
|
+
this.address = toIPv6(parts);
|
|
522
523
|
return this;
|
|
523
524
|
},
|
|
524
525
|
encode: function(record, writer) {
|
|
@@ -872,3 +873,4 @@ Packet.prototype.toBase64URL = function() {
|
|
|
872
873
|
};
|
|
873
874
|
|
|
874
875
|
module.exports = Packet;
|
|
876
|
+
module.exports.toIPv6 = toIPv6;
|
package/test/index.js
CHANGED
|
@@ -85,6 +85,13 @@ test('Question#decode', function() {
|
|
|
85
85
|
});
|
|
86
86
|
|
|
87
87
|
//
|
|
88
|
+
test('Package#toIPv6', function() {
|
|
89
|
+
assert.equal(Packet.toIPv6([ 10756, 20034, 512, 0, 0, 0, 0, 803 ]), '2a04:4e42:200::323');
|
|
90
|
+
assert.equal(Packet.toIPv6([ 10755, 45248, 3, 208, 0, 0, 5057, 61441 ]), '2a03:b0c0:3:d0::13c1:f001');
|
|
91
|
+
assert.equal(Packet.toIPv6([ 10752, 5200, 16387, 2055, 0, 0, 0, 8206 ]), '2a00:1450:4003:807::200e');
|
|
92
|
+
assert.equal(Packet.toIPv6([ 9734, 18176, 12552, 0, 0, 0, 44098, 10984 ]), '2606:4700:3108::ac42:2ae8');
|
|
93
|
+
});
|
|
94
|
+
|
|
88
95
|
test('Packet#parse', function() {
|
|
89
96
|
const packet = Packet.parse(response);
|
|
90
97
|
assert.equal(packet.questions[0].name, 'www.z.cn');
|