From 11732744fa4f67f020ff244e1eb93078dd5708a7 Mon Sep 17 00:00:00 2001 From: Ted Carnahan Date: Tue, 18 Sep 2018 09:01:29 -0500 Subject: [PATCH 1/4] Fix example code so that it works --- README.md | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 696f074..a33b498 100644 --- a/README.md +++ b/README.md @@ -37,23 +37,25 @@ server ```js const dns = require('dns2'); -var server = dns.createServer(function(request){ +var server = dns.createServer(function(request,send){ var response = new dns.Packet(request); - response.question.push({ - address: '8.8.8.8' + response.header.qr = 1; + response.answers.push({ + address: '8.8.8.8', + type: dns.Packet.TYPE.A, + class: dns.Packet.CLASS.IN }); - this.send(response); - + send(response); }).listen(5353); // dig @127.0.0.1 -p5353 lsong.org ``` -### API +### Api - dns2.Packet() - dns2.Client() @@ -98,4 +100,4 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ---- \ No newline at end of file +--- From 1038000f9bb360258330f3f222bf64a94fd77425 Mon Sep 17 00:00:00 2001 From: Ted Carnahan Date: Tue, 18 Sep 2018 09:18:10 -0500 Subject: [PATCH 2/4] Documentation cleanup --- README.md | 54 +++++++++++++++++++++++++++++++----------------------- 1 file changed, 31 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index a33b498..550cd46 100644 --- a/README.md +++ b/README.md @@ -1,29 +1,29 @@ -## dns2 +# dns2 ![NPM version](https://img.shields.io/npm/v/dns2.svg?style=flat) [![Build Status](https://travis-ci.org/song940/node-dns.svg?branch=master)](https://travis-ci.org/song940/node-dns) -> A dns server and client implementation +> A DNS server and client implementation ### Installation ```bash -$ npm i dns2 +$ npm install dns2 ``` -### Example +### Example Client -```js -const DNS = require('dns2'); +Lookup any records available for the domain `lsong.org`. -var dns = new DNS(); +```js +const dns = require('dns2'); -var packet = new DNS.Packet(); +var packet = new dns.Packet(); packet.questions.push({ name : 'lsong.org', - type : DNS.Packet.TYPE.ANY, - class: DNS.Packet.CLASS.IN + type : dns.Packet.TYPE.ANY, + class: dns.Packet.CLASS.IN }); dns.send(packet, function(err, res){ @@ -32,7 +32,9 @@ dns.send(packet, function(err, res){ ``` -server +### Example Server + +Respond to any DNS request on UDP port 5353 with `8.8.8.8`, a Google Public DNS server address. ```js const dns = require('dns2'); @@ -50,26 +52,33 @@ var server = dns.createServer(function(request,send){ send(response); }).listen(5353); +``` -// dig @127.0.0.1 -p5353 lsong.org +Then you can test your DNS server: +```bash +$ dig @127.0.0.1 -p5353 lsong.org ``` -### Api +Note that when implementing your own lookups, the contents of the query +will be found in `request.questions[0].name`. + +### API +- dns2.createServer() +- dns2.lookup() - dns2.Packet() - dns2.Client() - dns2.Server() -- dns2.createServer() -- dns2.lookup() -### SPEC +### Relevant Specifications -+ rfc1034 https://tools.ietf.org/html/rfc1034 -+ rfc1035 https://tools.ietf.org/html/rfc1035 -+ rfc2782 https://tools.ietf.org/html/rfc2782 ++ [RFC-1034 - Domain Names - Concepts and Facilities](https://tools.ietf.org/html/rfc1034) ++ [RFC-1035 - Domain Names - Implementation and Specification](https://tools.ietf.org/html/rfc1035) ++ [RFC-2782 - A DNS RR for specifying the location of services (DNS SRV)](https://tools.ietf.org/html/rfc2782) ### Contributing + - Fork this Repo first - Clone your Repo - Install dependencies by `$ npm install` @@ -80,10 +89,11 @@ var server = dns.createServer(function(request,send){ - Enjoy hacking <3 ### MIT license + Copyright (c) 2016 lsong Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal +of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is @@ -92,12 +102,10 @@ furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +THE SOFTWARE IS PROVIDED "AS IS," WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - ---- From 3ad44a3ee6d40a66738980e3761fb99aef541e40 Mon Sep 17 00:00:00 2001 From: Ted Carnahan Date: Tue, 18 Sep 2018 09:22:50 -0500 Subject: [PATCH 3/4] Remove unnecessary require('tcp') --- server.js | 1 - 1 file changed, 1 deletion(-) diff --git a/server.js b/server.js index 02afa6e..9481ca3 100644 --- a/server.js +++ b/server.js @@ -1,4 +1,3 @@ -const tcp = require('net'); const util = require('util'); const udp = require('dgram'); const EventEmitter = require('events'); From ed146a095dcff9f844b90bbab042f4e73da3a491 Mon Sep 17 00:00:00 2001 From: Ted Carnahan Date: Tue, 18 Sep 2018 09:23:36 -0500 Subject: [PATCH 4/4] Fix typos --- packet.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packet.js b/packet.js index 39ac5b0..2d3c482 100644 --- a/packet.js +++ b/packet.js @@ -324,7 +324,7 @@ Packet.Resource.encode = function(resource, writer){ if(encoder in Packet.Resource && Packet.Resource[ encoder ].encode){ return Packet.Resource[ encoder ].encode(resource, writer); }else{ - console.error('node-dns > unknow encoder %s(%j)', encoder, resource.type); + console.error('node-dns > unknown encoder %s(%j)', encoder, resource.type); } }; /** @@ -349,7 +349,7 @@ Packet.Resource.decode = function(reader){ if(parser in Packet.Resource){ resource = Packet.Resource[ parser ].decode.call(resource, reader, length); }else{ - console.error('node-dns > unknow parser type: %s(%j)', parser, resource.type); + console.error('node-dns > unknown parser type: %s(%j)', parser, resource.type); var arr = []; while(length--) arr.push(reader.read(8)); resource.data = new Buffer(arr);