2017-01-03 13:16:48 -08:00
|
|
|
// Copyright Joyent, Inc. and other Node contributors.
|
|
|
|
//
|
|
|
|
// Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
// copy of this software and associated documentation files (the
|
|
|
|
// "Software"), to deal in the Software without restriction, including
|
|
|
|
// without limitation the rights to use, copy, modify, merge, publish,
|
|
|
|
// distribute, sublicense, and/or sell copies of the Software, and to permit
|
|
|
|
// persons to whom the Software is furnished to do so, subject to the
|
|
|
|
// following conditions:
|
|
|
|
//
|
|
|
|
// The above copyright notice and this permission notice shall be included
|
|
|
|
// in all copies or substantial portions of the Software.
|
|
|
|
//
|
|
|
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
|
|
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
|
|
|
|
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
|
|
|
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
|
|
|
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
|
|
|
|
// USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
|
2014-11-22 16:59:48 +01:00
|
|
|
'use strict';
|
|
|
|
|
2019-11-22 18:04:46 +01:00
|
|
|
const {
|
2020-11-20 10:26:23 +01:00
|
|
|
ArrayPrototypeMap,
|
2019-11-22 18:04:46 +01:00
|
|
|
ObjectCreate,
|
|
|
|
ObjectDefineProperties,
|
|
|
|
ObjectDefineProperty,
|
2020-11-20 10:26:23 +01:00
|
|
|
ReflectApply,
|
2022-03-29 23:43:28 +08:00
|
|
|
Symbol,
|
2019-11-22 18:04:46 +01:00
|
|
|
} = primordials;
|
2019-04-09 09:55:53 +02:00
|
|
|
|
2018-08-23 09:28:41 -04:00
|
|
|
const cares = internalBinding('cares_wrap');
|
2018-10-10 20:23:48 +02:00
|
|
|
const { toASCII } = require('internal/idna');
|
2020-02-18 09:14:50 -08:00
|
|
|
const { isIP } = require('internal/net');
|
2017-04-16 21:35:29 +02:00
|
|
|
const { customPromisifyArgs } = require('internal/util');
|
2017-07-13 07:58:59 +08:00
|
|
|
const errors = require('internal/errors');
|
2018-02-27 14:55:32 +01:00
|
|
|
const {
|
2018-06-11 14:56:33 -04:00
|
|
|
bindDefaultResolver,
|
|
|
|
getDefaultResolver,
|
|
|
|
setDefaultResolver,
|
|
|
|
Resolver,
|
2018-09-30 18:17:36 +08:00
|
|
|
validateHints,
|
|
|
|
emitInvalidHostnameWarning,
|
2021-04-06 16:09:11 +08:00
|
|
|
getDefaultVerbatim,
|
|
|
|
setDefaultResultOrder,
|
2022-06-18 20:54:31 +08:00
|
|
|
errorCodes: dnsErrorCodes,
|
2018-06-11 14:56:33 -04:00
|
|
|
} = require('internal/dns/utils');
|
2022-06-18 20:54:31 +08:00
|
|
|
const {
|
|
|
|
NODATA,
|
|
|
|
FORMERR,
|
|
|
|
SERVFAIL,
|
|
|
|
NOTFOUND,
|
|
|
|
NOTIMP,
|
|
|
|
REFUSED,
|
|
|
|
BADQUERY,
|
|
|
|
BADNAME,
|
|
|
|
BADFAMILY,
|
|
|
|
BADRESP,
|
|
|
|
CONNREFUSED,
|
|
|
|
TIMEOUT,
|
|
|
|
EOF,
|
|
|
|
FILE,
|
|
|
|
NOMEM,
|
|
|
|
DESTRUCTION,
|
|
|
|
BADSTR,
|
|
|
|
BADFLAGS,
|
|
|
|
NONAME,
|
|
|
|
BADHINTS,
|
|
|
|
NOTINITIALIZED,
|
|
|
|
LOADIPHLPAPI,
|
|
|
|
ADDRGETNETWORKPARAMS,
|
|
|
|
CANCELLED,
|
|
|
|
} = dnsErrorCodes;
|
2018-06-11 14:56:33 -04:00
|
|
|
const {
|
2018-02-27 14:55:32 +01:00
|
|
|
ERR_INVALID_ARG_TYPE,
|
2020-08-08 19:01:59 +03:00
|
|
|
ERR_INVALID_ARG_VALUE,
|
2018-02-27 14:55:32 +01:00
|
|
|
ERR_MISSING_ARGS,
|
|
|
|
} = errors.codes;
|
2020-02-18 09:14:50 -08:00
|
|
|
const {
|
2022-01-07 12:00:10 +01:00
|
|
|
validateBoolean,
|
2022-01-24 19:39:16 +03:30
|
|
|
validateFunction,
|
2022-01-07 12:00:10 +01:00
|
|
|
validateNumber,
|
|
|
|
validateOneOf,
|
2020-02-18 09:14:50 -08:00
|
|
|
validatePort,
|
|
|
|
validateString,
|
|
|
|
} = require('internal/validators');
|
2013-07-18 23:18:50 +02:00
|
|
|
|
2017-07-27 16:34:40 +02:00
|
|
|
const {
|
|
|
|
GetAddrInfoReqWrap,
|
|
|
|
GetNameInfoReqWrap,
|
|
|
|
QueryReqWrap,
|
|
|
|
} = cares;
|
|
|
|
|
2022-03-29 23:43:28 +08:00
|
|
|
const kPerfHooksDnsLookupContext = Symbol('kPerfHooksDnsLookupContext');
|
|
|
|
const kPerfHooksDnsLookupServiceContext = Symbol('kPerfHooksDnsLookupServiceContext');
|
|
|
|
const kPerfHooksDnsLookupResolveContext = Symbol('kPerfHooksDnsLookupResolveContext');
|
|
|
|
|
|
|
|
const {
|
2022-06-09 12:32:46 +08:00
|
|
|
hasObserver,
|
2022-03-29 23:43:28 +08:00
|
|
|
startPerf,
|
|
|
|
stopPerf,
|
|
|
|
} = require('internal/perf/observe');
|
|
|
|
|
2018-02-03 17:09:15 +08:00
|
|
|
const dnsException = errors.dnsException;
|
2013-07-18 23:18:50 +02:00
|
|
|
|
2018-12-02 12:25:39 -05:00
|
|
|
let promises = null; // Lazy loaded
|
2018-06-11 14:56:33 -04:00
|
|
|
|
2013-08-12 17:54:11 +02:00
|
|
|
function onlookup(err, addresses) {
|
|
|
|
if (err) {
|
2018-02-03 17:09:15 +08:00
|
|
|
return this.callback(dnsException(err, 'getaddrinfo', this.hostname));
|
2013-08-12 17:54:11 +02:00
|
|
|
}
|
2020-04-05 16:57:13 +08:00
|
|
|
this.callback(null, addresses[0], this.family || isIP(addresses[0]));
|
2022-06-09 12:32:46 +08:00
|
|
|
if (this[kPerfHooksDnsLookupContext] && hasObserver('dns')) {
|
2022-07-29 21:27:16 +08:00
|
|
|
stopPerf(this, kPerfHooksDnsLookupContext, { detail: { addresses } });
|
2022-06-09 12:32:46 +08:00
|
|
|
}
|
2013-08-12 17:54:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-02-06 21:43:50 +01:00
|
|
|
function onlookupall(err, addresses) {
|
|
|
|
if (err) {
|
2018-02-03 17:09:15 +08:00
|
|
|
return this.callback(dnsException(err, 'getaddrinfo', this.hostname));
|
2015-02-06 21:43:50 +01:00
|
|
|
}
|
|
|
|
|
2019-03-26 05:21:27 +01:00
|
|
|
const family = this.family;
|
2019-11-06 13:32:31 +03:00
|
|
|
for (let i = 0; i < addresses.length; i++) {
|
2017-05-27 21:44:03 -04:00
|
|
|
const addr = addresses[i];
|
|
|
|
addresses[i] = {
|
|
|
|
address: addr,
|
2019-04-16 11:07:17 -07:00
|
|
|
family: family || isIP(addr)
|
2017-05-27 21:44:03 -04:00
|
|
|
};
|
2015-02-06 21:43:50 +01:00
|
|
|
}
|
|
|
|
|
2017-05-27 21:44:03 -04:00
|
|
|
this.callback(null, addresses);
|
2022-06-09 12:32:46 +08:00
|
|
|
if (this[kPerfHooksDnsLookupContext] && hasObserver('dns')) {
|
2022-07-29 21:27:16 +08:00
|
|
|
stopPerf(this, kPerfHooksDnsLookupContext, { detail: { addresses } });
|
2022-06-09 12:32:46 +08:00
|
|
|
}
|
2015-02-06 21:43:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-07-05 00:17:20 +02:00
|
|
|
// Easy DNS A/AAAA look up
|
2014-05-21 22:13:09 -04:00
|
|
|
// lookup(hostname, [options,] callback)
|
2022-01-07 12:00:10 +01:00
|
|
|
const validFamilies = [0, 4, 6];
|
2017-02-27 17:54:16 -08:00
|
|
|
function lookup(hostname, options, callback) {
|
2019-11-06 13:32:31 +03:00
|
|
|
let hints = 0;
|
2022-01-07 12:00:10 +01:00
|
|
|
let family = 0;
|
2019-11-06 13:32:31 +03:00
|
|
|
let all = false;
|
2021-04-06 16:09:11 +08:00
|
|
|
let verbatim = getDefaultVerbatim();
|
2014-05-21 22:13:09 -04:00
|
|
|
|
|
|
|
// Parse arguments
|
2021-01-20 22:07:39 +08:00
|
|
|
if (hostname) {
|
|
|
|
validateString(hostname, 'hostname');
|
2020-12-23 19:22:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (typeof options === 'function') {
|
2014-05-21 22:13:09 -04:00
|
|
|
callback = options;
|
2011-07-05 00:17:20 +02:00
|
|
|
family = 0;
|
2022-01-07 12:00:10 +01:00
|
|
|
} else if (typeof options === 'number') {
|
|
|
|
validateFunction(callback, 'callback');
|
|
|
|
|
|
|
|
validateOneOf(options, 'family', validFamilies, true);
|
|
|
|
family = options;
|
|
|
|
} else if (options !== undefined && typeof options !== 'object') {
|
|
|
|
validateFunction(arguments.length === 2 ? options : callback, 'callback');
|
|
|
|
throw new ERR_INVALID_ARG_TYPE('options', ['integer', 'object'], options);
|
2014-08-07 22:36:56 -04:00
|
|
|
} else {
|
2022-01-24 19:39:16 +03:30
|
|
|
validateFunction(callback, 'callback');
|
2020-12-23 19:22:00 +08:00
|
|
|
|
2022-01-07 12:00:10 +01:00
|
|
|
if (options?.hints != null) {
|
|
|
|
validateNumber(options.hints, 'options.hints');
|
2020-12-23 19:22:00 +08:00
|
|
|
hints = options.hints >>> 0;
|
|
|
|
validateHints(hints);
|
2022-01-07 12:00:10 +01:00
|
|
|
}
|
|
|
|
if (options?.family != null) {
|
2022-05-10 11:10:03 +02:00
|
|
|
switch (options.family) {
|
|
|
|
case 'IPv4':
|
|
|
|
family = 4;
|
|
|
|
break;
|
|
|
|
case 'IPv6':
|
|
|
|
family = 6;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
validateOneOf(options.family, 'options.family', validFamilies, true);
|
|
|
|
family = options.family;
|
|
|
|
break;
|
|
|
|
}
|
2022-01-07 12:00:10 +01:00
|
|
|
}
|
|
|
|
if (options?.all != null) {
|
|
|
|
validateBoolean(options.all, 'options.all');
|
|
|
|
all = options.all;
|
|
|
|
}
|
|
|
|
if (options?.verbatim != null) {
|
|
|
|
validateBoolean(options.verbatim, 'options.verbatim');
|
|
|
|
verbatim = options.verbatim;
|
2020-12-23 19:22:00 +08:00
|
|
|
}
|
2011-07-05 00:17:20 +02:00
|
|
|
}
|
2014-05-21 22:13:09 -04:00
|
|
|
|
2013-10-15 12:51:12 +02:00
|
|
|
if (!hostname) {
|
2018-09-30 18:17:36 +08:00
|
|
|
emitInvalidHostnameWarning(hostname);
|
2015-02-06 21:43:50 +01:00
|
|
|
if (all) {
|
2017-05-27 20:35:13 -04:00
|
|
|
process.nextTick(callback, null, []);
|
2015-02-06 21:43:50 +01:00
|
|
|
} else {
|
2017-05-27 20:35:13 -04:00
|
|
|
process.nextTick(callback, null, null, family === 6 ? 6 : 4);
|
2015-02-06 21:43:50 +01:00
|
|
|
}
|
2011-07-05 00:17:20 +02:00
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
2019-03-26 05:21:27 +01:00
|
|
|
const matchedFamily = isIP(hostname);
|
2011-07-05 00:17:20 +02:00
|
|
|
if (matchedFamily) {
|
2015-02-06 21:43:50 +01:00
|
|
|
if (all) {
|
2017-05-27 20:35:13 -04:00
|
|
|
process.nextTick(
|
2017-07-10 20:55:21 -04:00
|
|
|
callback, null, [{ address: hostname, family: matchedFamily }]);
|
2015-02-06 21:43:50 +01:00
|
|
|
} else {
|
2017-05-27 20:35:13 -04:00
|
|
|
process.nextTick(callback, null, hostname, matchedFamily);
|
2015-02-06 21:43:50 +01:00
|
|
|
}
|
2011-07-05 00:17:20 +02:00
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
2019-03-26 05:21:27 +01:00
|
|
|
const req = new GetAddrInfoReqWrap();
|
2014-12-09 05:29:47 +01:00
|
|
|
req.callback = callback;
|
|
|
|
req.family = family;
|
|
|
|
req.hostname = hostname;
|
2015-02-06 21:43:50 +01:00
|
|
|
req.oncomplete = all ? onlookupall : onlookup;
|
2014-06-04 17:26:34 -07:00
|
|
|
|
2019-03-26 05:21:27 +01:00
|
|
|
const err = cares.getaddrinfo(
|
|
|
|
req, toASCII(hostname), family, hints, verbatim
|
|
|
|
);
|
2014-06-04 17:26:34 -07:00
|
|
|
if (err) {
|
2018-02-03 17:09:15 +08:00
|
|
|
process.nextTick(callback, dnsException(err, 'getaddrinfo', hostname));
|
2014-06-04 17:26:34 -07:00
|
|
|
return {};
|
|
|
|
}
|
2022-06-09 12:32:46 +08:00
|
|
|
if (hasObserver('dns')) {
|
|
|
|
const detail = {
|
|
|
|
hostname,
|
|
|
|
family,
|
|
|
|
hints,
|
|
|
|
verbatim,
|
|
|
|
};
|
|
|
|
startPerf(req, kPerfHooksDnsLookupContext, { type: 'dns', name: 'lookup', detail });
|
|
|
|
}
|
2013-07-18 23:18:50 +02:00
|
|
|
return req;
|
2017-02-27 17:54:16 -08:00
|
|
|
}
|
2011-07-05 00:17:20 +02:00
|
|
|
|
2019-11-22 18:04:46 +01:00
|
|
|
ObjectDefineProperty(lookup, customPromisifyArgs,
|
2022-06-03 10:23:58 +02:00
|
|
|
{ __proto__: null, value: ['address', 'family'], enumerable: false });
|
2017-04-16 21:35:29 +02:00
|
|
|
|
2011-07-05 00:17:20 +02:00
|
|
|
|
2018-06-22 17:41:42 +00:00
|
|
|
function onlookupservice(err, hostname, service) {
|
2014-06-21 00:43:00 +02:00
|
|
|
if (err)
|
2018-06-22 17:41:42 +00:00
|
|
|
return this.callback(dnsException(err, 'getnameinfo', this.hostname));
|
2014-06-21 00:43:00 +02:00
|
|
|
|
2018-06-22 17:41:42 +00:00
|
|
|
this.callback(null, hostname, service);
|
2022-06-09 12:32:46 +08:00
|
|
|
if (this[kPerfHooksDnsLookupServiceContext] && hasObserver('dns')) {
|
2022-07-29 21:27:16 +08:00
|
|
|
stopPerf(this, kPerfHooksDnsLookupServiceContext, { detail: { hostname, service } });
|
2022-06-09 12:32:46 +08:00
|
|
|
}
|
2014-06-21 00:43:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-08-07 21:59:51 -04:00
|
|
|
function lookupService(address, port, callback) {
|
2014-06-21 00:43:00 +02:00
|
|
|
if (arguments.length !== 3)
|
2019-08-07 21:59:51 -04:00
|
|
|
throw new ERR_MISSING_ARGS('address', 'port', 'callback');
|
2014-06-21 00:43:00 +02:00
|
|
|
|
2019-08-07 21:59:51 -04:00
|
|
|
if (isIP(address) === 0)
|
2020-08-08 19:01:59 +03:00
|
|
|
throw new ERR_INVALID_ARG_VALUE('address', address);
|
2014-06-21 00:43:00 +02:00
|
|
|
|
2020-02-18 09:14:50 -08:00
|
|
|
validatePort(port);
|
2016-01-24 08:58:56 -06:00
|
|
|
|
2022-01-24 19:39:16 +03:30
|
|
|
validateFunction(callback, 'callback');
|
2016-08-18 17:09:37 -04:00
|
|
|
|
2016-01-26 08:15:53 -06:00
|
|
|
port = +port;
|
2014-06-21 00:43:00 +02:00
|
|
|
|
2019-03-26 05:21:27 +01:00
|
|
|
const req = new GetNameInfoReqWrap();
|
2014-12-09 05:29:47 +01:00
|
|
|
req.callback = callback;
|
2019-08-07 21:59:51 -04:00
|
|
|
req.hostname = address;
|
2014-12-09 05:29:47 +01:00
|
|
|
req.port = port;
|
|
|
|
req.oncomplete = onlookupservice;
|
|
|
|
|
2019-08-07 21:59:51 -04:00
|
|
|
const err = cares.getnameinfo(req, address, port);
|
|
|
|
if (err) throw dnsException(err, 'getnameinfo', address);
|
2022-06-09 12:32:46 +08:00
|
|
|
if (hasObserver('dns')) {
|
|
|
|
startPerf(req, kPerfHooksDnsLookupServiceContext, {
|
|
|
|
type: 'dns',
|
|
|
|
name: 'lookupService',
|
|
|
|
detail: {
|
|
|
|
host: address,
|
|
|
|
port,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
2014-06-21 00:43:00 +02:00
|
|
|
return req;
|
2017-02-27 17:54:16 -08:00
|
|
|
}
|
2014-06-21 00:43:00 +02:00
|
|
|
|
2019-11-22 18:04:46 +01:00
|
|
|
ObjectDefineProperty(lookupService, customPromisifyArgs,
|
2022-06-03 10:23:58 +02:00
|
|
|
{ __proto__: null, value: ['hostname', 'service'], enumerable: false });
|
2017-04-16 21:35:29 +02:00
|
|
|
|
2014-06-21 00:43:00 +02:00
|
|
|
|
2016-10-26 07:51:34 +02:00
|
|
|
function onresolve(err, result, ttls) {
|
|
|
|
if (ttls && this.ttl)
|
2020-11-20 10:26:23 +01:00
|
|
|
result = ArrayPrototypeMap(
|
|
|
|
result, (address, index) => ({ address, ttl: ttls[index] }));
|
2016-10-26 07:51:34 +02:00
|
|
|
|
2013-08-12 17:54:11 +02:00
|
|
|
if (err)
|
2018-02-03 17:09:15 +08:00
|
|
|
this.callback(dnsException(err, this.bindingName, this.hostname));
|
2022-03-29 23:43:28 +08:00
|
|
|
else {
|
2013-08-12 17:54:11 +02:00
|
|
|
this.callback(null, result);
|
2022-06-09 12:32:46 +08:00
|
|
|
if (this[kPerfHooksDnsLookupResolveContext] && hasObserver('dns')) {
|
2022-07-29 21:27:16 +08:00
|
|
|
stopPerf(this, kPerfHooksDnsLookupResolveContext, { detail: { result } });
|
2022-06-09 12:32:46 +08:00
|
|
|
}
|
2022-03-29 23:43:28 +08:00
|
|
|
}
|
2013-08-12 17:54:11 +02:00
|
|
|
}
|
|
|
|
|
2011-07-05 00:17:20 +02:00
|
|
|
function resolver(bindingName) {
|
2017-07-31 22:06:47 +02:00
|
|
|
function query(name, /* options, */ callback) {
|
2019-11-06 13:32:31 +03:00
|
|
|
let options;
|
2016-10-26 07:51:34 +02:00
|
|
|
if (arguments.length > 2) {
|
|
|
|
options = callback;
|
|
|
|
callback = arguments[2];
|
|
|
|
}
|
|
|
|
|
2018-08-02 18:51:02 -04:00
|
|
|
validateString(name, 'name');
|
2022-01-24 19:39:16 +03:30
|
|
|
validateFunction(callback, 'callback');
|
2014-02-07 18:50:29 +01:00
|
|
|
|
2019-03-26 05:21:27 +01:00
|
|
|
const req = new QueryReqWrap();
|
2015-09-30 15:55:06 -06:00
|
|
|
req.bindingName = bindingName;
|
|
|
|
req.callback = callback;
|
|
|
|
req.hostname = name;
|
|
|
|
req.oncomplete = onresolve;
|
2016-10-26 07:51:34 +02:00
|
|
|
req.ttl = !!(options && options.ttl);
|
2019-03-26 05:21:27 +01:00
|
|
|
const err = this._handle[bindingName](req, toASCII(name));
|
2018-04-01 07:54:32 +02:00
|
|
|
if (err) throw dnsException(err, bindingName, name);
|
2022-06-09 12:32:46 +08:00
|
|
|
if (hasObserver('dns')) {
|
|
|
|
startPerf(req, kPerfHooksDnsLookupResolveContext, {
|
|
|
|
type: 'dns',
|
|
|
|
name: bindingName,
|
|
|
|
detail: {
|
|
|
|
host: name,
|
|
|
|
ttl: req.ttl,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
2013-07-18 23:18:50 +02:00
|
|
|
return req;
|
2017-07-31 22:06:47 +02:00
|
|
|
}
|
2022-06-03 10:23:58 +02:00
|
|
|
ObjectDefineProperty(query, 'name', { __proto__: null, value: bindingName });
|
2017-07-31 22:06:47 +02:00
|
|
|
return query;
|
2011-07-05 00:17:20 +02:00
|
|
|
}
|
|
|
|
|
2019-11-22 18:04:46 +01:00
|
|
|
const resolveMap = ObjectCreate(null);
|
2017-07-27 18:54:20 +02:00
|
|
|
Resolver.prototype.resolveAny = resolveMap.ANY = resolver('queryAny');
|
|
|
|
Resolver.prototype.resolve4 = resolveMap.A = resolver('queryA');
|
|
|
|
Resolver.prototype.resolve6 = resolveMap.AAAA = resolver('queryAaaa');
|
2020-10-02 17:52:47 +02:00
|
|
|
Resolver.prototype.resolveCaa = resolveMap.CAA = resolver('queryCaa');
|
2017-07-27 18:54:20 +02:00
|
|
|
Resolver.prototype.resolveCname = resolveMap.CNAME = resolver('queryCname');
|
|
|
|
Resolver.prototype.resolveMx = resolveMap.MX = resolver('queryMx');
|
|
|
|
Resolver.prototype.resolveNs = resolveMap.NS = resolver('queryNs');
|
|
|
|
Resolver.prototype.resolveTxt = resolveMap.TXT = resolver('queryTxt');
|
|
|
|
Resolver.prototype.resolveSrv = resolveMap.SRV = resolver('querySrv');
|
|
|
|
Resolver.prototype.resolvePtr = resolveMap.PTR = resolver('queryPtr');
|
|
|
|
Resolver.prototype.resolveNaptr = resolveMap.NAPTR = resolver('queryNaptr');
|
|
|
|
Resolver.prototype.resolveSoa = resolveMap.SOA = resolver('querySoa');
|
|
|
|
Resolver.prototype.reverse = resolver('getHostByAddr');
|
|
|
|
|
|
|
|
Resolver.prototype.resolve = resolve;
|
2017-02-27 17:54:16 -08:00
|
|
|
|
2017-05-17 13:37:30 -07:00
|
|
|
function resolve(hostname, rrtype, callback) {
|
2019-11-06 13:32:31 +03:00
|
|
|
let resolver;
|
2017-05-17 13:37:30 -07:00
|
|
|
if (typeof rrtype === 'string') {
|
|
|
|
resolver = resolveMap[rrtype];
|
|
|
|
} else if (typeof rrtype === 'function') {
|
2017-02-27 17:54:16 -08:00
|
|
|
resolver = resolveMap.A;
|
2017-05-17 13:37:30 -07:00
|
|
|
callback = rrtype;
|
2014-02-07 18:18:27 +01:00
|
|
|
} else {
|
2018-02-27 14:55:32 +01:00
|
|
|
throw new ERR_INVALID_ARG_TYPE('rrtype', 'string', rrtype);
|
2011-07-05 00:17:20 +02:00
|
|
|
}
|
|
|
|
|
2015-01-28 20:05:53 -05:00
|
|
|
if (typeof resolver === 'function') {
|
2020-11-20 10:26:23 +01:00
|
|
|
return ReflectApply(resolver, this, [hostname, callback]);
|
2011-07-05 00:17:20 +02:00
|
|
|
}
|
2020-08-08 19:01:59 +03:00
|
|
|
throw new ERR_INVALID_ARG_VALUE('rrtype', rrtype);
|
2017-02-27 17:54:16 -08:00
|
|
|
}
|
2011-07-05 00:17:20 +02:00
|
|
|
|
2017-11-15 15:09:33 +08:00
|
|
|
function defaultResolverSetServers(servers) {
|
|
|
|
const resolver = new Resolver();
|
2018-06-11 14:56:33 -04:00
|
|
|
|
2017-11-15 15:09:33 +08:00
|
|
|
resolver.setServers(servers);
|
2018-06-11 14:56:33 -04:00
|
|
|
setDefaultResolver(resolver);
|
|
|
|
bindDefaultResolver(module.exports, Resolver.prototype);
|
|
|
|
|
2018-12-02 12:25:39 -05:00
|
|
|
if (promises !== null)
|
2018-06-11 14:56:33 -04:00
|
|
|
bindDefaultResolver(promises, promises.Resolver.prototype);
|
2017-11-15 15:09:33 +08:00
|
|
|
}
|
2017-07-27 18:54:20 +02:00
|
|
|
|
2017-02-27 17:54:16 -08:00
|
|
|
module.exports = {
|
|
|
|
lookup,
|
|
|
|
lookupService,
|
2017-07-27 18:54:20 +02:00
|
|
|
|
|
|
|
Resolver,
|
2021-04-06 16:09:11 +08:00
|
|
|
setDefaultResultOrder,
|
2017-11-15 15:09:33 +08:00
|
|
|
setServers: defaultResolverSetServers,
|
2017-02-27 17:54:16 -08:00
|
|
|
|
|
|
|
// uv_getaddrinfo flags
|
|
|
|
ADDRCONFIG: cares.AI_ADDRCONFIG,
|
2020-03-09 15:44:47 -07:00
|
|
|
ALL: cares.AI_ALL,
|
2017-02-27 17:54:16 -08:00
|
|
|
V4MAPPED: cares.AI_V4MAPPED,
|
|
|
|
|
|
|
|
// ERROR CODES
|
2022-06-18 20:54:31 +08:00
|
|
|
NODATA,
|
|
|
|
FORMERR,
|
|
|
|
SERVFAIL,
|
|
|
|
NOTFOUND,
|
|
|
|
NOTIMP,
|
|
|
|
REFUSED,
|
|
|
|
BADQUERY,
|
|
|
|
BADNAME,
|
|
|
|
BADFAMILY,
|
|
|
|
BADRESP,
|
|
|
|
CONNREFUSED,
|
|
|
|
TIMEOUT,
|
|
|
|
EOF,
|
|
|
|
FILE,
|
|
|
|
NOMEM,
|
|
|
|
DESTRUCTION,
|
|
|
|
BADSTR,
|
|
|
|
BADFLAGS,
|
|
|
|
NONAME,
|
|
|
|
BADHINTS,
|
|
|
|
NOTINITIALIZED,
|
|
|
|
LOADIPHLPAPI,
|
|
|
|
ADDRGETNETWORKPARAMS,
|
|
|
|
CANCELLED,
|
2017-02-27 17:54:16 -08:00
|
|
|
};
|
2017-11-15 15:09:33 +08:00
|
|
|
|
2018-06-11 14:56:33 -04:00
|
|
|
bindDefaultResolver(module.exports, getDefaultResolver());
|
|
|
|
|
2019-11-22 18:04:46 +01:00
|
|
|
ObjectDefineProperties(module.exports, {
|
2018-06-11 14:56:33 -04:00
|
|
|
promises: {
|
2022-06-03 10:23:58 +02:00
|
|
|
__proto__: null,
|
2018-06-11 14:56:33 -04:00
|
|
|
configurable: true,
|
2019-03-27 13:21:25 -04:00
|
|
|
enumerable: true,
|
2018-06-11 14:56:33 -04:00
|
|
|
get() {
|
2018-12-02 12:25:39 -05:00
|
|
|
if (promises === null) {
|
2018-06-11 14:56:33 -04:00
|
|
|
promises = require('internal/dns/promises');
|
|
|
|
}
|
|
|
|
return promises;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|