os-dns-native
Advanced tools
Comparing version 1.1.1 to 1.1.2
72
index.js
@@ -6,32 +6,50 @@ 'use strict'; | ||
const nodeDns = require('dns'); | ||
const debug = require('debug')('os-dns-native'); | ||
const rrtypes = ['A', 'AAAA', 'CNAME', 'TXT', 'SRV']; | ||
const rrtypeEnumToString = Object.fromEntries(rrtypes.map(t => [constants[t], t])); | ||
function resolve(hostname, rrtype, callback) { | ||
switch (rrtype) { | ||
case 'A': | ||
case 'AAAA': | ||
case 'CNAME': | ||
case 'TXT': | ||
case 'SRV': | ||
lookup(hostname, constants.INTERNET, constants[rrtype], function(err, results) { | ||
if (err) return callback(err); | ||
switch (rrtype) { | ||
case 'A': | ||
case 'CNAME': | ||
return callback(null, results); | ||
case 'AAAA': | ||
return callback(null, results.map(addr => ipv6normalize(addr))); | ||
case 'TXT': | ||
return callback(null, results.map(val => val.split('\0'))); | ||
case 'SRV': | ||
return callback(null, results.map(res => { | ||
const { name, port, priority, weight } = res.match( | ||
/^(?<name>.+):(?<port>\d+),prio=(?<priority>\d+),weight=(?<weight>\d+)$/).groups; | ||
return { name, port: +port, priority: +priority, weight: +weight }; | ||
})); | ||
} | ||
}); | ||
if (!rrtypes.includes(rrtype)) { | ||
throw new Error(`Unknown rrtype: ${rrtype}`); | ||
} | ||
lookup(hostname, constants.INTERNET, constants[rrtype], function(err, rawResults) { | ||
if (err) { | ||
debug(`failed ${rrtype} DNS resolution`, { hostname, err }); | ||
return callback(err); | ||
} | ||
debug(`received ${rrtype} DNS resolution`, { hostname, rawResults }); | ||
const results = []; | ||
for (const { type, value } of rawResults) { | ||
if (type !== constants[rrtype]) { | ||
debug(`skipping mismatched DNS answer: wanted ${rrtype} but got ${rrtypeEnumToString[type]}`, { hostname }); | ||
} else { | ||
results.push(value); | ||
} | ||
} | ||
if (results.length === 0 && rawResults.length !== 0) { | ||
// We encounter this situation when we only saw mismatching results. | ||
callback(new Error(`DNS server did not provide matching result for ${rrtype}: ${hostname}`)); | ||
return; | ||
default: | ||
throw new Error(`Unknown rrtype: ${rrtype}`); | ||
} | ||
} | ||
switch (rrtype) { | ||
case 'A': | ||
case 'CNAME': | ||
return callback(null, results); | ||
case 'AAAA': | ||
return callback(null, results.map(addr => ipv6normalize(addr))); | ||
case 'TXT': | ||
return callback(null, results.map(val => val.split('\0'))); | ||
case 'SRV': | ||
return callback(null, results.map(res => { | ||
const { name, port, priority, weight } = res.match( | ||
/^(?<name>.+):(?<port>\d+),prio=(?<priority>\d+),weight=(?<weight>\d+)$/).groups; | ||
return { name, port: +port, priority: +priority, weight: +weight }; | ||
})); | ||
} | ||
}); | ||
} | ||
@@ -38,0 +56,0 @@ |
{ | ||
"name": "os-dns-native", | ||
"version": "1.1.1", | ||
"version": "1.1.2", | ||
"description": "Perform DNS queries using OS APIs", | ||
@@ -17,2 +17,3 @@ "main": "index.js", | ||
"bindings": "^1.5.0", | ||
"debug": "^4.3.3", | ||
"ipv6-normalize": "^1.0.1", | ||
@@ -19,0 +20,0 @@ "node-addon-api": "^3.1.0" |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
21989
122
4
+ Addeddebug@^4.3.3
+ Addeddebug@4.3.7(transitive)
+ Addedms@2.1.3(transitive)