more linting

This commit is contained in:
AJ ONeal 2017-02-17 18:32:45 -07:00
parent b6f0cff7b8
commit b4f0cdee78
1 changed files with 22 additions and 10 deletions

View File

@ -16,6 +16,10 @@ var dnspack = exports.DNS_PACKER = {
var header = dnspack.packHeader(packet.header); // 2 bytes var header = dnspack.packHeader(packet.header); // 2 bytes
total = 12; // 2+2+2+2 bytes ({qd,an,ns,ar}count) total = 12; // 2+2+2+2 bytes ({qd,an,ns,ar}count)
if (!id) {
throw new Error("'id' should be set to a crypto random id");
}
dv.setUint16(0, id, false); dv.setUint16(0, id, false);
dv.setUint16(2, header, false); dv.setUint16(2, header, false);
dv.setUint16(4, packet.question.length, false); dv.setUint16(4, packet.question.length, false);
@ -135,17 +139,25 @@ var dnspack = exports.DNS_PACKER = {
, packHeader: function(h) { , packHeader: function(h) {
var val = 0; var val = 0;
var req = h.opcode;
var res = h.qr || h.aa || h.ra || h.rcode;
val += (h.qr << 15) & 0x8000; if (req && res) {
val += (h.opcode << 11) & 0x7800; throw new Error("Both request-only and response-only headers are set: " + JSON.stringify(h));
val += (h.aa << 10) & 0x400; }
val += (h.tc << 9) & 0x200;
val += (h.rd << 8) & 0x100; // TODO check if is request or response
val += (h.ra << 7) & 0x80;
val += (h.res1 << 6) & 0x40; val += ((h.qr || 0) << 15) & 0x8000;
val += (h.res2 << 5) & 0x20; val += ((h.opcode || 0) << 11) & 0x7800;
val += (h.res3 << 4) & 0x10; val += ((h.aa || 0) << 10) & 0x400;
val += h.rcode & 0xF; val += ((h.tc || 0) << 9) & 0x200;
val += ((h.rd || 0) << 8) & 0x100;
val += ((h.ra || 0) << 7) & 0x80;
val += ((h.res1 || 0) << 6) & 0x40;
val += ((h.res2 || 0) << 5) & 0x20;
val += ((h.res3 || 0) << 4) & 0x10;
val += (h.rcode || 0) & 0xF;
return val; return val;
} }