diff --git a/README.md b/README.md index faa9594..4f5ceaa 100644 --- a/README.md +++ b/README.md @@ -10,15 +10,15 @@ npm install dns-packet ## UDP Usage ``` js -var packet = require('dns-packet') +var dnsPacket = require('dns-packet') var dgram = require('dgram') var socket = dgram.createSocket('udp4') -var buf = packet.encode({ +var buf = dnsPacket.encode({ type: 'query', id: 1, - flags: packet.RECURSION_DESIRED, + flags: dnsPacket.RECURSION_DESIRED, questions: [{ type: 'A', class: 'IN', @@ -27,7 +27,7 @@ var buf = packet.encode({ }) socket.on('message', function (message) { - console.log(packet.decode(message)) // prints out a response from google dns + console.log(dnsPacket.decode(message)) // prints out a response from google dns }) socket.send(buf, 0, buf.length, 53, '8.8.8.8') diff --git a/examples/doh.js b/examples/doh.js index ea5bb83..3dfd507 100644 --- a/examples/doh.js +++ b/examples/doh.js @@ -8,17 +8,17 @@ * LICENSE: MIT */ -const packet = require('..') +const dnsPacket = require('..') const https = require('https') -function getRandomInt(min, max) { - return Math.floor(Math.random() * (max - min + 1)) + min; +function getRandomInt (min, max) { + return Math.floor(Math.random() * (max - min + 1)) + min } -const encodedPacket = packet.encode({ +const encodeddnsPacket = dnsPacket.encode({ type: 'query', id: getRandomInt(1, 65534), - flags: packet.RECURSION_DESIRED, + flags: dnsPacket.RECURSION_DESIRED, questions: [{ type: 'A', name: 'google.com' @@ -32,7 +32,7 @@ const options = { method: 'POST', headers: { 'Content-Type': 'application/dns-udpwireformat', - 'Content-Length': Buffer.byteLength(encodedPacket) + 'Content-Length': Buffer.byteLength(encodeddnsPacket) } } @@ -41,12 +41,12 @@ const request = https.request(options, (response) => { console.log('headers:', response.headers) response.on('data', (d) => { - console.log(packet.decode(d)) + console.log(dnsPacket.decode(d)) }) }) request.on('error', (e) => { console.error(e) }) -request.write(encodedPacket) +request.write(encodeddnsPacket) request.end() diff --git a/examples/tcp.js b/examples/tcp.js index 27d1fcc..6f2f707 100644 --- a/examples/tcp.js +++ b/examples/tcp.js @@ -1,19 +1,19 @@ 'use strict' -const packet = require('..') +const dnsPacket = require('..') const net = require('net') var response = null -var expected_length = 0 +var expectedLength = 0 -function getRandomInt(min, max) { - return Math.floor(Math.random() * (max - min + 1)) + min; +function getRandomInt (min, max) { + return Math.floor(Math.random() * (max - min + 1)) + min } -const encodedPacket = packet.streamEncode({ +const encodedPacket = dnsPacket.streamEncode({ type: 'query', id: getRandomInt(1, 65534), - flags: packet.RECURSION_DESIRED, + flags: dnsPacket.RECURSION_DESIRED, questions: [{ type: 'A', name: 'google.com' @@ -31,7 +31,7 @@ client.on('data', function (data) { if (response == null) { if (data.byteLength > 1) { const plen = data.readUInt16BE(0) - expected_length = plen + expectedLength = plen if (plen < 12) { throw new Error('below DNS minimum packet length') } @@ -41,8 +41,8 @@ client.on('data', function (data) { response = Buffer.concat([response, data]) } - if (response.byteLength >= expected_length) { - console.log(packet.streamDecode(response)) + if (response.byteLength >= expectedLength) { + console.log(dnsPacket.streamDecode(response)) client.destroy() } }) diff --git a/examples/tls.js b/examples/tls.js index 58fc9d3..514d34c 100644 --- a/examples/tls.js +++ b/examples/tls.js @@ -1,19 +1,19 @@ 'use strict' const tls = require('tls') -const packet = require('..') +const dnsPacket = require('..') var response = null -var expected_length = 0 +var expectedLength = 0 -function getRandomInt(min, max) { - return Math.floor(Math.random() * (max - min + 1)) + min; +function getRandomInt (min, max) { + return Math.floor(Math.random() * (max - min + 1)) + min } -const encodedPacket = packet.streamEncode({ +const encodedPacket = dnsPacket.streamEncode({ type: 'query', id: getRandomInt(1, 65534), - flags: packet.RECURSION_DESIRED, + flags: dnsPacket.RECURSION_DESIRED, questions: [{ type: 'A', name: 'google.com' @@ -40,7 +40,7 @@ client.on('data', function (data) { if (response == null) { if (data.byteLength > 1) { const plen = data.readUInt16BE(0) - expected_length = plen + expectedLength = plen if (plen < 12) { throw new Error('below DNS minimum packet length') } @@ -50,8 +50,8 @@ client.on('data', function (data) { response = Buffer.concat([response, data]) } - if (response.byteLength >= expected_length) { - console.log(packet.streamDecode(response)) + if (response.byteLength >= expectedLength) { + console.log(dnsPacket.streamDecode(response)) client.destroy() } }) diff --git a/examples/udp.js b/examples/udp.js index dcf50f9..0f9df9d 100644 --- a/examples/udp.js +++ b/examples/udp.js @@ -1,18 +1,18 @@ 'use strict' -const packet = require('..') +const dnsPacket = require('..') const dgram = require('dgram') const socket = dgram.createSocket('udp4') -function getRandomInt(min, max) { - return Math.floor(Math.random() * (max - min + 1)) + min; +function getRandomInt (min, max) { + return Math.floor(Math.random() * (max - min + 1)) + min } -const buf = packet.encode({ +const buf = dnsPacket.encode({ type: 'query', id: getRandomInt(1, 65534), - flags: packet.RECURSION_DESIRED, + flags: dnsPacket.RECURSION_DESIRED, questions: [{ type: 'A', name: 'google.com' @@ -21,7 +21,7 @@ const buf = packet.encode({ socket.on('message', function (message, rinfo) { console.log(rinfo) - console.log(packet.decode(message)) // prints out a response from google dns + console.log(dnsPacket.decode(message)) // prints out a response from google dns socket.close() }) diff --git a/package.json b/package.json index 7ef7819..30f34ac 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ "node": ">=6" }, "scripts": { - "test": "eslint --color *.js && tape test.js" + "test": "eslint --color *.js examples/*.js && tape test.js" }, "dependencies": { "ip": "^1.1.5"