factor out printing of header and query
This commit is contained in:
parent
57ced95c0d
commit
cdd490ec42
24
bin/dig.js
24
bin/dig.js
|
@ -157,9 +157,9 @@ cli.main(function (args, cli) {
|
|||
cli.onError = function (err) {
|
||||
console.error("error:", err.stack);
|
||||
};
|
||||
|
||||
cli.onMessage = function (nb) {
|
||||
var packet = dnsjs.DNSPacket.parse(nb.buffer.slice(nb.byteOffset, nb.byteOffset + nb.byteLength));
|
||||
var flags = "";
|
||||
|
||||
if (packet.id !== query.id) {
|
||||
console.log('ignoring packet for ', packet.question[0].name);
|
||||
|
@ -172,26 +172,8 @@ cli.main(function (args, cli) {
|
|||
}
|
||||
|
||||
console.log(';; Got answer:');
|
||||
// TODO opcode 0 QUERY rcode 0 NOERROR
|
||||
console.log(';; ->>HEADER<<- [opcode: ' + packet.header.opcode + ', status: ' + packet.header.rcode + '], id: ' + packet.header.id);
|
||||
if (packet.header.tc) { console.log("Truncated [tc] (we don't know the normal way to print a tc packet... you should record this with -o tc-packet.dig and send it to us)"); }
|
||||
flags += ";; flags:";
|
||||
if (packet.header.qr) { flags += " qr"; }
|
||||
if (packet.header.aa) { flags += " aa"; }
|
||||
if (packet.header.rd) { flags += " rd"; }
|
||||
if (packet.header.ra) { flags += " ra"; }
|
||||
flags += "; QUERY: " + packet.question.length + ", ANSWER: " + packet.answer.length + ", AUTHORITY: " + packet.authority.length + ", ADDITIONAL: " + packet.additional.length;
|
||||
console.log(flags);
|
||||
if (packet.header.res1) { console.log("[res1] (we don't know how to print a packet with res1 yet)"); }
|
||||
if (packet.header.res2) { console.log("[res2] (we don't know how to print a packet with res2 yet)"); }
|
||||
if (packet.header.res3) { console.log("[res3] (we don't know how to print a packet with res2 yet)"); }
|
||||
// {"id":32736,"qr":1,"opcode":0,"aa":0,"tc":0,"rd":1,"ra":0,"res1":0,"res2":0,"res3":0,"rcode":5}
|
||||
//console.log(JSON.stringify(packet.header));
|
||||
console.log('');
|
||||
console.log(';; QUESTION SECTION:');
|
||||
packet.question.forEach(function (q) {
|
||||
console.log(';' + q.name + '.', ' ', q.className, q.typeName);
|
||||
});
|
||||
dig.logQuestion(packet);
|
||||
|
||||
function print(q) {
|
||||
var printer = common.printers[q.typeName] || common.printers.ANY;
|
||||
printer(q);
|
||||
|
|
|
@ -4,7 +4,32 @@ var dnsjs = require('dns-suite');
|
|||
var crypto = require('crypto');
|
||||
var dgram = require('dgram');
|
||||
|
||||
function request(queryAb, opts) {
|
||||
function logQuestion(packet) {
|
||||
var flags = "";
|
||||
|
||||
// TODO opcode 0 QUERY rcode 0 NOERROR
|
||||
console.log(';; ->>HEADER<<- [opcode: ' + packet.header.opcode + ', status: ' + packet.header.rcode + '], id: ' + packet.header.id);
|
||||
if (packet.header.tc) { console.log("Truncated [tc] (we don't know the normal way to print a tc packet... you should record this with -o tc-packet.dig and send it to us)"); }
|
||||
flags += ";; flags:";
|
||||
if (packet.header.qr) { flags += " qr"; }
|
||||
if (packet.header.aa) { flags += " aa"; }
|
||||
if (packet.header.rd) { flags += " rd"; }
|
||||
if (packet.header.ra) { flags += " ra"; }
|
||||
flags += "; QUERY: " + packet.question.length + ", ANSWER: " + packet.answer.length + ", AUTHORITY: " + packet.authority.length + ", ADDITIONAL: " + packet.additional.length;
|
||||
console.log(flags);
|
||||
if (packet.header.res1) { console.log("[res1] (we don't know how to print a packet with res1 yet)"); }
|
||||
if (packet.header.res2) { console.log("[res2] (we don't know how to print a packet with res2 yet)"); }
|
||||
if (packet.header.res3) { console.log("[res3] (we don't know how to print a packet with res2 yet)"); }
|
||||
// {"id":32736,"qr":1,"opcode":0,"aa":0,"tc":0,"rd":1,"ra":0,"res1":0,"res2":0,"res3":0,"rcode":5}
|
||||
//console.log(JSON.stringify(packet.header));
|
||||
console.log('');
|
||||
console.log(';; QUESTION SECTION:');
|
||||
packet.question.forEach(function (q) {
|
||||
console.log(';' + q.name + '.', ' ', q.className, q.typeName);
|
||||
});
|
||||
}
|
||||
|
||||
function resolve(queryAb, opts) {
|
||||
var handlers = {};
|
||||
var nameservers;
|
||||
var nameserver = opts.nameserver;
|
||||
|
@ -76,7 +101,7 @@ function request(queryAb, opts) {
|
|||
}, ms);
|
||||
}
|
||||
|
||||
function requestJson(query, opts) {
|
||||
function resolveJson(query, opts) {
|
||||
var queryAb = dnsjs.DNSPacket.write(query);
|
||||
var options = {
|
||||
onError: opts.onError
|
||||
|
@ -87,15 +112,20 @@ function requestJson(query, opts) {
|
|||
}
|
||||
, onListening: opts.onListening
|
||||
, onSent: opts.onSent
|
||||
, onClose: opts.onClose
|
||||
, onTimeout: opts.onTimeout
|
||||
, mdns: opts.mdns
|
||||
, nameserver: opts.nameserver
|
||||
, port: opts.port
|
||||
, timeout: opts.timeout
|
||||
};
|
||||
|
||||
return request(queryAb, options);
|
||||
return resolve(queryAb, options);
|
||||
}
|
||||
|
||||
module.exports.resolve = request;
|
||||
module.exports.request = request;
|
||||
module.exports.requestJson = requestJson;
|
||||
module.exports.resolve = resolve;
|
||||
module.exports.resolveJson = resolveJson;
|
||||
module.exports.request = resolve;
|
||||
module.exports.requestJson = resolveJson;
|
||||
|
||||
module.exports.logQuestion = logQuestion;
|
||||
|
|
Loading…
Reference in New Issue