dns2 2.0.2 → 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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dns2",
3
- "version": "2.0.2",
3
+ "version": "2.0.5",
4
4
  "description": "A DNS Server and Client Implementation in Pure JavaScript with no dependencies.",
5
5
  "main": "index.js",
6
6
  "scripts": {
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,9 +519,7 @@ Packet.Resource.AAAA = {
514
519
  length -= 2;
515
520
  parts.push(reader.read(16));
516
521
  }
517
- this.address = parts.map(function(part) {
518
- return part > 0 ? part.toString(16) : '';
519
- }).join(':');
522
+ this.address = toIPv6(parts);
520
523
  return this;
521
524
  },
522
525
  encode: function(record, writer) {
@@ -870,3 +873,4 @@ Packet.prototype.toBase64URL = function() {
870
873
  };
871
874
 
872
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');
@@ -112,7 +119,7 @@ test('Packet#encode', function() {
112
119
  type : Packet.TYPE.AAAA,
113
120
  class : Packet.CLASS.IN,
114
121
  ttl : 300,
115
- address : '2001:db8::::ff00:42:8329',
122
+ address : '2001:db8::ff00:42:8329',
116
123
  });
117
124
 
118
125
  response.answers.push({