bugfix: pack multiple TXT strings correctly
This commit is contained in:
parent
d743b8f3d0
commit
908fd5314c
|
@ -2,32 +2,44 @@
|
|||
'use strict';
|
||||
|
||||
// Record type is just any text.
|
||||
// RFC 1035 - 3.3. Standard RRs - <character-string>
|
||||
// RFC 1035 - 3.3.14. TXT RDATA format
|
||||
|
||||
exports.DNS_PACKER_TYPE_TXT = function (ab, dv, total, record) {
|
||||
if (!record.data){
|
||||
throw new Error("no data for TXT record");
|
||||
if ('string' === typeof record.data) {
|
||||
console.warn("[WARN] 'data' should be an array of strings, not a single string");
|
||||
record.data = [ record.data ];
|
||||
}
|
||||
if (!Array.isArray(record.data) || !record.data.length){
|
||||
throw new Error("bad data or no data for TXT record");
|
||||
}
|
||||
|
||||
var txtLen = 0;
|
||||
var rdLenIndex = total;
|
||||
total += 3;
|
||||
total += 2; // saving space for rdata length
|
||||
|
||||
// RDATA
|
||||
record.data.forEach(function(str){
|
||||
|
||||
if (str.length > 255) {
|
||||
throw new Error("bad TXT string length " + str.length + " (max 255)");
|
||||
}
|
||||
|
||||
// size of this string
|
||||
dv.setUint8(total, str.length, false);
|
||||
total += 1;
|
||||
txtLen += 1;
|
||||
|
||||
str.split('').forEach(function(ch) {
|
||||
|
||||
txtLen += 1;
|
||||
// console.log(chcim);
|
||||
dv.setUint8(total, ch.charCodeAt(0), false);
|
||||
total += 1;
|
||||
txtLen += 1;
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
dv.setUint16(rdLenIndex, txtLen+1, false);
|
||||
dv.setUint8(rdLenIndex+2, txtLen, false);
|
||||
// total +=1;
|
||||
dv.setUint16(rdLenIndex, txtLen, false);
|
||||
|
||||
return total;
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue