changed examples to use `dns-suite` instead of `dns-js`
This commit is contained in:
parent
8fc78f35f0
commit
53cae83af4
|
@ -37,6 +37,11 @@ var dnspack = exports.DNS_PACKER = {
|
|||
if (!r.className) {
|
||||
throw new Error("no className");
|
||||
}
|
||||
if (!classes[r.className]) {
|
||||
console.warn("ignoring invalid class '" + r.className + "' for '" + r.name);
|
||||
} else {
|
||||
r.class = classes[r.className];
|
||||
}
|
||||
}
|
||||
|
||||
if (!r.type) {
|
||||
|
@ -44,7 +49,9 @@ var dnspack = exports.DNS_PACKER = {
|
|||
throw new Error("no typeName");
|
||||
}
|
||||
if (!types[r.typeName]) {
|
||||
console.warn("ignoring invalid type '" + r.type + "' for '" + r.name + "', ignoring");
|
||||
console.warn("ignoring invalid type '" + r.typeName + "' for '" + r.name);
|
||||
} else {
|
||||
r.type = types[r.typeName];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,20 +1,44 @@
|
|||
'use strict';
|
||||
|
||||
module.exports.respond = function (socket, packets, rinfo) {
|
||||
var dns = require('dns-js');
|
||||
var dns = require('../');
|
||||
var os = require('os');
|
||||
var queryname = '_cloud._tcp.local';
|
||||
|
||||
console.log(packets);
|
||||
|
||||
packets.forEach(function (packet) {
|
||||
// Only respond to queries, otherwise we'll end up responding to ourselves forever.
|
||||
if (packet.header.qr !== 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
packet.question.forEach(function (q) {
|
||||
if (queryname !== q.name) {
|
||||
return;
|
||||
}
|
||||
|
||||
console.log('question', q.name, q.typeName, q.className, q.flag, q);
|
||||
var rpacket = new dns.DNSPacket();
|
||||
var rpacket = {
|
||||
header: {
|
||||
id: packet.header.id
|
||||
, qr: 1
|
||||
, opcode: 0
|
||||
, aa: 1
|
||||
, tc: 0
|
||||
, rd: 0
|
||||
, ra: 0
|
||||
, res1: 0
|
||||
, res2: 0
|
||||
, res3: 0
|
||||
, rcode: 0
|
||||
, }
|
||||
, question: [q]
|
||||
, answer: []
|
||||
, authority: []
|
||||
, additional: []
|
||||
, edns_options: []
|
||||
};
|
||||
var ifaces = os.networkInterfaces();
|
||||
//var llRe = /^(fe80|169)/i; // link-local
|
||||
|
||||
|
@ -29,9 +53,9 @@ module.exports.respond = function (socket, packets, rinfo) {
|
|||
iface.forEach(function (pface) {
|
||||
rpacket.additional.push({
|
||||
name: q.name
|
||||
, type: ('IPv4' === pface.family ? dns.DNSRecord.Type.A : dns.DNSRecord.Type.AAAA)
|
||||
, typeName: ('IPv4' === pface.family ? 'A' : 'AAAA')
|
||||
, ttl: 10
|
||||
, class: dns.DNSRecord.Class.IN
|
||||
, className: 'IN'
|
||||
, address: pface.address // '_workstation._tcp.local'
|
||||
});
|
||||
});
|
||||
|
@ -40,43 +64,33 @@ module.exports.respond = function (socket, packets, rinfo) {
|
|||
var myRndId = 'be1af7a';
|
||||
rpacket.answer.push({
|
||||
name: q.name
|
||||
, type: dns.DNSRecord.Type.PTR
|
||||
, typeName: 'PTR'
|
||||
, ttl: 10
|
||||
, class: dns.DNSRecord.Class.IN
|
||||
, className: 'IN'
|
||||
, data: myRndId + '.' + queryname
|
||||
});
|
||||
rpacket.question.push(new dns.DNSRecord(
|
||||
queryname // Name
|
||||
, dns.DNSRecord.Type.PTR // Type
|
||||
, dns.DNSRecord.Class.IN // Class
|
||||
//, null // TTL
|
||||
));
|
||||
rpacket.additional.push({
|
||||
name: myRndId + '.' + queryname
|
||||
, type: dns.DNSRecord.Type.SRV
|
||||
, typeName: 'SRV'
|
||||
, ttl: 10
|
||||
, class: dns.DNSRecord.Class.IN
|
||||
, priority: 0
|
||||
, className: 'IN'
|
||||
, priority: 1
|
||||
, weight: 0
|
||||
, port: 443
|
||||
, target: myRndId + ".local"
|
||||
});
|
||||
rpacket.additional.push({
|
||||
name: myRndId + '.' + '_device-info._tcp.local'
|
||||
, type: dns.DNSRecord.Type.TXT
|
||||
, typeName: 'TXT'
|
||||
, ttl: 10
|
||||
, class: dns.DNSRecord.Class.IN
|
||||
, className: 'IN'
|
||||
, data: ["model=CloudHome1,1", "dappsvers=1"]
|
||||
});
|
||||
rpacket.header.id = packet.header.id;
|
||||
rpacket.header.aa = 1;
|
||||
rpacket.header.qr = 1;
|
||||
rpacket.header.rd = 0;
|
||||
|
||||
console.log('');
|
||||
console.log('START JSON PACKET');
|
||||
console.log(rpacket);
|
||||
var buf = dns.DNSPacket.toBuffer(rpacket);
|
||||
var buf = dns.DNSPacket.write(rpacket);
|
||||
console.log(buf.toString('hex'));
|
||||
console.log('END JSON PACKET');
|
||||
console.log('');
|
||||
|
@ -89,8 +103,7 @@ module.exports.respond = function (socket, packets, rinfo) {
|
|||
console.log('');
|
||||
socket.send(buf, rinfo.port, rinfo.address);
|
||||
});
|
||||
/*
|
||||
*/
|
||||
|
||||
packet.answer.forEach(function (a) {
|
||||
console.log('answer', a.name, a.typeName, a.className, a.flag, a);
|
||||
});
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
'use strict';
|
||||
|
||||
var dgram = require('dgram');
|
||||
var dnsjs = require('dns-js');
|
||||
|
||||
// SO_REUSEADDR and SO_REUSEPORT are set because
|
||||
// the system mDNS Responder may already be listening on this port
|
||||
|
|
|
@ -5,7 +5,7 @@ var socket = dgram.createSocket({
|
|||
type: 'udp4'
|
||||
, reuseAddr: true
|
||||
});
|
||||
var dns = require('dns-js');
|
||||
var dns = require('../');
|
||||
//var DNSPacket = dns.DNSPacket;
|
||||
|
||||
var broadcast = '224.0.0.251'; // mdns
|
||||
|
@ -31,14 +31,11 @@ return binString;
|
|||
}
|
||||
|
||||
socket.on('message', function (message, rinfo) {
|
||||
console.log('Received %d bytes from %s:%d\n',
|
||||
message.length, rinfo.address, rinfo.port);
|
||||
console.log('Received %d bytes from %s:%d', message.length, rinfo.address, rinfo.port);
|
||||
//console.log(msg.toString('utf8'));
|
||||
|
||||
message.forEach(function(byte){
|
||||
|
||||
console.log(pad(byte.toString(2), 8,'0'));
|
||||
|
||||
console.log(pad(byte.toString(2), 8, '0'));
|
||||
});
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue