Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Solve fix inconsistent (hostname vs host) in DNS. #20892
  • Loading branch information
UlisesGascon committed Jun 22, 2018
commit fab9b1567f244a57c2250400e5bd0f88e648741c
20 changes: 10 additions & 10 deletions lib/dns.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,21 +149,21 @@ Object.defineProperty(lookup, customPromisifyArgs,
{ value: ['address', 'family'], enumerable: false });


function onlookupservice(err, host, service) {
function onlookupservice(err, hostname, service) {
if (err)
return this.callback(dnsException(err, 'getnameinfo', this.host));
return this.callback(dnsException(err, 'getnameinfo', this.hostname));

this.callback(null, host, service);
this.callback(null, hostname, service);
}


// lookupService(address, port, callback)
function lookupService(host, port, callback) {
function lookupService(hostname, port, callback) {
if (arguments.length !== 3)
throw new ERR_MISSING_ARGS('host', 'port', 'callback');
throw new ERR_MISSING_ARGS('hostname', 'port', 'callback');

if (isIP(host) === 0)
throw new ERR_INVALID_OPT_VALUE('host', host);
if (isIP(hostname) === 0)
throw new ERR_INVALID_OPT_VALUE('hostname', hostname);

if (!isLegalPort(port))
throw new ERR_SOCKET_BAD_PORT(port);
Expand All @@ -175,12 +175,12 @@ function lookupService(host, port, callback) {

var req = new GetNameInfoReqWrap();
req.callback = callback;
req.host = host;
req.hostname = hostname;
req.port = port;
req.oncomplete = onlookupservice;

var err = cares.getnameinfo(req, host, port);
if (err) throw dnsException(err, 'getnameinfo', host);
var err = cares.getnameinfo(req, hostname, port);
if (err) throw dnsException(err, 'getnameinfo', hostname);
return req;
}

Expand Down
6 changes: 3 additions & 3 deletions test/common/dns.js
Original file line number Diff line number Diff line change
Expand Up @@ -291,12 +291,12 @@ const mockedErrorCode = 'ENOTFOUND';
const mockedSysCall = 'getaddrinfo';

function errorLookupMock(code = mockedErrorCode, syscall = mockedSysCall) {
return function lookupWithError(host, dnsopts, cb) {
const err = new Error(`${syscall} ${code} ${host}`);
return function lookupWithError(hostname, dnsopts, cb) {
const err = new Error(`${syscall} ${code} ${hostname}`);
err.code = code;
err.errno = code;
err.syscall = syscall;
err.hostname = host;
err.hostname = hostname;
cb(err);
};
}
Expand Down