WIP output byte indexes while parsing
This commit is contained in:
parent
633e60d643
commit
b5af1bfe24
35
bin/debug.js
35
bin/debug.js
|
@ -45,8 +45,6 @@ console.log('ancount', ancount);
|
||||||
console.log('nscount', nscount);
|
console.log('nscount', nscount);
|
||||||
console.log('arcount', arcount);
|
console.log('arcount', arcount);
|
||||||
|
|
||||||
var total = 12;
|
|
||||||
|
|
||||||
function unpackQuestion(dv, total, len) {
|
function unpackQuestion(dv, total, len) {
|
||||||
var qnames = [];
|
var qnames = [];
|
||||||
var labelLen;
|
var labelLen;
|
||||||
|
@ -77,10 +75,11 @@ function unpackQuestion(dv, total, len) {
|
||||||
console.log('label:', label);
|
console.log('label:', label);
|
||||||
qnames.push(label);
|
qnames.push(label);
|
||||||
}
|
}
|
||||||
console.log('QNAME:', qnames.join('.'));
|
// leading length and (potentially) trailing null
|
||||||
console.log('QTYPE:', dv.getUint16(total), false);
|
console.log('QNAME (len ' + (qnames.join('.').length + 1 + (labelLen ? 0 : 1)) + '):', qnames.join('.'));
|
||||||
|
console.log('QTYPE (len 2):', dv.getUint16(total, false));
|
||||||
total += 2;
|
total += 2;
|
||||||
console.log('QCLASS:', dv.getUint16(total), false);
|
console.log('QCLASS (len 2):', dv.getUint16(total, false));
|
||||||
total += 2;
|
total += 2;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
@ -89,8 +88,9 @@ function unpackQuestion(dv, total, len) {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
var q = { total: total };
|
var q = { total: 12 };
|
||||||
function mapChar(ch) { return String.fromCharCode(ch) + '(' + ch + ')'; }
|
function mapChar(ch) { return JSON.stringify(String.fromCharCode(ch)) + '(' + ch + ')'; }
|
||||||
|
|
||||||
|
|
||||||
console.log('');
|
console.log('');
|
||||||
console.log('//////////////////');
|
console.log('//////////////////');
|
||||||
|
@ -98,7 +98,8 @@ console.log('// QUESTION //');
|
||||||
console.log('//////////////////');
|
console.log('//////////////////');
|
||||||
console.log('');
|
console.log('');
|
||||||
for (count = 0; count < qdcount; count += 1) {
|
for (count = 0; count < qdcount; count += 1) {
|
||||||
console.log('Question', count + 1, 'of', qdcount);
|
console.log('');
|
||||||
|
console.log('Question ' + (count + 1) + ' of ' + qdcount + ' (byte index: ' + q.total + ')');
|
||||||
q = unpackQuestion(dv, q.total, ab.byteLength);
|
q = unpackQuestion(dv, q.total, ab.byteLength);
|
||||||
console.log('');
|
console.log('');
|
||||||
}
|
}
|
||||||
|
@ -109,7 +110,8 @@ console.log('// ANSWER //');
|
||||||
console.log('//////////////////');
|
console.log('//////////////////');
|
||||||
console.log('');
|
console.log('');
|
||||||
for (count = 0; count < ancount; count += 1) {
|
for (count = 0; count < ancount; count += 1) {
|
||||||
console.log('Answer', count + 1, 'of', ancount);
|
console.log('');
|
||||||
|
console.log('Answer', count + 1, 'of', ancount + ' (byte index: ' + q.total + ')');
|
||||||
q = unpackQuestion(dv, q.total, ab.byteLength);
|
q = unpackQuestion(dv, q.total, ab.byteLength);
|
||||||
console.log('');
|
console.log('');
|
||||||
}
|
}
|
||||||
|
@ -121,16 +123,18 @@ console.log('// AUTHORITY //');
|
||||||
console.log('//////////////////');
|
console.log('//////////////////');
|
||||||
console.log('');
|
console.log('');
|
||||||
for (count = 0; count < nscount; count += 1) {
|
for (count = 0; count < nscount; count += 1) {
|
||||||
console.log('Authority', count + 1, 'of', nscount);
|
console.log('');
|
||||||
|
console.log('Authority', count + 1, 'of', nscount + ' (byte index: ' + q.total + ')');
|
||||||
q = unpackQuestion(dv, q.total, ab.byteLength);
|
q = unpackQuestion(dv, q.total, ab.byteLength);
|
||||||
console.log('ttl:', dv.getUint32(q.total, false));
|
console.log('ttl (len 4):', dv.getUint32(q.total, false));
|
||||||
q.total += 4;
|
q.total += 4;
|
||||||
q.rdlength = dv.getUint16(q.total, false);
|
q.rdlength = dv.getUint16(q.total, false);
|
||||||
console.log('rdlen:', q.rdlength);
|
console.log('rdlen (len 2):', q.rdlength);
|
||||||
q.total += 2;
|
q.total += 2;
|
||||||
console.log('rrdata:');
|
console.log('rrdata (len ' + q.rdlength + '):');
|
||||||
console.log([].slice.call(new Uint8Array(ab), q.total, q.total + q.rdlength).map(mapChar));
|
console.log([].slice.call(new Uint8Array(ab), q.total, q.total + q.rdlength).map(mapChar).join(' '));
|
||||||
q.total += q.rdlength;
|
q.total += q.rdlength;
|
||||||
|
console.log('');
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log('');
|
console.log('');
|
||||||
|
@ -139,7 +143,8 @@ console.log('// ADDITIONAL //');
|
||||||
console.log('//////////////////');
|
console.log('//////////////////');
|
||||||
console.log('');
|
console.log('');
|
||||||
for (count = 0; count < arcount; count += 1) {
|
for (count = 0; count < arcount; count += 1) {
|
||||||
console.log('Additional', count + 1, 'of', arcount);
|
console.log('');
|
||||||
|
console.log('Additional', count + 1, 'of', arcount + ' (byte index: ' + q.total + ')');
|
||||||
q = unpackQuestion(dv, q.total, ab.byteLength);
|
q = unpackQuestion(dv, q.total, ab.byteLength);
|
||||||
console.log('');
|
console.log('');
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue