don't modify original object, chimney
This commit is contained in:
parent
39de466876
commit
113187e68a
|
@ -23,10 +23,10 @@ var dnspack = exports.DNS_PACKER = {
|
||||||
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);
|
||||||
dv.setUint16(6, packet.answer.length, false);
|
dv.setUint16(6, (packet.answer||[]).length, false);
|
||||||
dv.setUint16(8, packet.authority.length, false);
|
dv.setUint16(8, (packet.authority||[]).length, false);
|
||||||
// EDNS is added as an additional with TYPE 41 (OPT, 0x29)
|
// EDNS is added as an additional with TYPE 41 (OPT, 0x29)
|
||||||
dv.setUint16(10, packet.additional.length + (packet.payload ? 1 : 0), false);
|
dv.setUint16(10, (packet.additional||[]).length + (packet.payload ? 1 : 0), false);
|
||||||
|
|
||||||
function lint(r) {
|
function lint(r) {
|
||||||
if (!r.name) {
|
if (!r.name) {
|
||||||
|
@ -37,24 +37,20 @@ var dnspack = exports.DNS_PACKER = {
|
||||||
if (!r.className) {
|
if (!r.className) {
|
||||||
throw new Error("no className");
|
throw new Error("no className");
|
||||||
}
|
}
|
||||||
r.class = classes[r.className];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!r.type) {
|
if (!r.type) {
|
||||||
if (!r.typeName) {
|
if (!r.typeName) {
|
||||||
throw new Error("no typeName");
|
throw new Error("no typeName");
|
||||||
}
|
}
|
||||||
r.type = types[r.typeName];
|
if (!types[r.typeName]) {
|
||||||
if (!r.type) {
|
|
||||||
console.warn("ignoring invalid type '" + r.type + "' for '" + r.name + "', ignoring");
|
console.warn("ignoring invalid type '" + r.type + "' for '" + r.name + "', ignoring");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function packLabelSequence(sequence, terminates) {
|
function packLabelSequence(sequence, terminates) {
|
||||||
console.log('sequence:', sequence);
|
|
||||||
if (labelsMap[sequence]) {
|
if (labelsMap[sequence]) {
|
||||||
console.log('cached sequence:', sequence);
|
|
||||||
// minimal compression pointer 0xc0 (192)
|
// minimal compression pointer 0xc0 (192)
|
||||||
dv.setUint8(total, 0xc0, false);
|
dv.setUint8(total, 0xc0, false);
|
||||||
total += 1;
|
total += 1;
|
||||||
|
@ -88,9 +84,9 @@ var dnspack = exports.DNS_PACKER = {
|
||||||
|
|
||||||
packLabelSequence(q.name, true);
|
packLabelSequence(q.name, true);
|
||||||
|
|
||||||
dv.setUint16(total, q.type, false);
|
dv.setUint16(total, q.type || types[q.typeName], false);
|
||||||
total += 2;
|
total += 2;
|
||||||
dv.setUint16(total, q.class, false);
|
dv.setUint16(total, q.class || classes[q.className], false);
|
||||||
total += 2;
|
total += 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -118,13 +114,10 @@ var dnspack = exports.DNS_PACKER = {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//console.log(packet);
|
|
||||||
// fixed size, other than labels
|
|
||||||
|
|
||||||
packet.question.forEach(packQuestion);
|
packet.question.forEach(packQuestion);
|
||||||
packet.answer.forEach(packAnswer);
|
(packet.answer||[]).forEach(packAnswer);
|
||||||
packet.authority.forEach(packAnswer);
|
(packet.authority||[]).forEach(packAnswer);
|
||||||
packet.additional.forEach(packAnswer);
|
(packet.additional||[]).forEach(packAnswer);
|
||||||
|
|
||||||
// TODO handle compression pointers
|
// TODO handle compression pointers
|
||||||
// TODO handle edns
|
// TODO handle edns
|
||||||
|
|
Loading…
Reference in New Issue