Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

os-dns-native

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

os-dns-native - npm Package Compare versions

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc