2017-01-21 21:33:51 +00:00
|
|
|
(function (exports) {
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
exports.DNS_RDATA_PARSE = function (ab, packet, record) {
|
|
|
|
// ab is needed if the rdata makes use of compression pointers
|
|
|
|
// packet is given for convenience
|
|
|
|
var parser;
|
|
|
|
|
2017-01-27 00:03:16 +00:00
|
|
|
|
2017-01-21 21:33:51 +00:00
|
|
|
if (!record.className) {
|
2017-02-11 16:56:17 +00:00
|
|
|
throw new Error("Support for DNS Class 0x" + record.class.toString(16) + " (" + record.class + ")"
|
2017-01-21 21:33:51 +00:00
|
|
|
+ " is not implemented yet. Open an issue if you actually need support"
|
|
|
|
+ " (i.e. you're not working with a malformed packet)"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!record.typeName) {
|
2017-02-11 16:56:17 +00:00
|
|
|
throw new Error("Support for DNS Type 0x" + record.type.toString(16) + " (" + record.type + ")"
|
2017-01-21 21:33:51 +00:00
|
|
|
+ " is not implemented yet. Open an issue if you actually need support"
|
|
|
|
+ " (i.e. you're not working with a malformed packet)"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
2017-02-18 02:38:47 +00:00
|
|
|
parser = exports['DNS_PARSER_TYPE_' + record.typeName]
|
2017-02-17 23:13:57 +00:00
|
|
|
|| require('./parser/type.' + record.typeName.toLowerCase())['DNS_PARSER_TYPE_' + record.typeName];
|
2017-01-21 21:33:51 +00:00
|
|
|
}
|
|
|
|
catch (e) { /*console.error(e)*/ }
|
|
|
|
|
|
|
|
if (!parser) {
|
2017-02-18 02:38:47 +00:00
|
|
|
if (require) {
|
|
|
|
require('./parser/type.' + record.typeName.toLowerCase());
|
|
|
|
}
|
2017-01-21 21:33:51 +00:00
|
|
|
throw new Error("Parser for DNS Type " + record.typeName + " could not be loaded."
|
2017-02-17 23:13:57 +00:00
|
|
|
+ " Did you include <script src=\"parser/type." + record.typeName.toLowerCase() + ".js\"></script> ?"
|
2017-01-21 21:33:51 +00:00
|
|
|
+ " (or perhaps we plan to implement it and haven't yet - in which case please open an issue)"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2017-02-03 01:39:32 +00:00
|
|
|
// NOTE: record will be modified
|
|
|
|
// Things that get added include:
|
2017-02-03 02:44:18 +00:00
|
|
|
// address, data, priority exchange, weight,
|
|
|
|
// NOTE: this slicing is a shim so that we don't have to pass rdend to unpackLabel
|
|
|
|
// (because `undefined` and 0x00 are functionally equivalent)
|
|
|
|
return parser(ab.slice(0, record.rdstart + record.rdlength), packet, record);
|
2017-01-21 21:33:51 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}('undefined' !== typeof window ? window : exports));
|