Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return new Promise((resolve, reject) => {
const { host, servername, name, klass, type, port } = argsOrder(args);
let response = new Buffer(0);
let packetLength = 0;
const id = randomId();
const dnsQuery = getDnsQuery({ type, name, klass, id });
const dnsQueryBuf = dnsPacket.streamEncode(dnsQuery);
const socket = connect({ host, servername, port });
socket.on('secureConnect', () => socket.write(dnsQueryBuf));
socket.on('data', (data: Buffer) => {
if (response.length === 0) {
// https://tools.ietf.org/html/rfc7858#section-3.3
// https://tools.ietf.org/html/rfc1035#section-4.2.2
// The message is prefixed with a two byte length field which gives the
// message length, excluding the two byte length field.
packetLength = data.readUInt16BE(0);
if (packetLength < 12) {
reject('Below DNS minimum packet length (DNS Header is 12 bytes)');
}
response = Buffer.from(data);