mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 10:59:27 +00:00
1b2749ecbe
Switch the default from `ipv4first` to `verbatim` (return them exactly as the resolver sent them to us). PR-URL: https://github.com/nodejs/node/pull/39987 Fixes: https://github.com/nodejs/node/issues/31566 Refs: https://github.com/nodejs/node/issues/6307 Refs: https://github.com/nodejs/node/pull/20710 Refs: https://github.com/nodejs/node/pull/38099 Co-authored-by: treysis <treysis@gmx.net> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Michael Dawson <midawson@redhat.com>
47 lines
1.3 KiB
JavaScript
47 lines
1.3 KiB
JavaScript
'use strict';
|
|
const common = require('../common');
|
|
const assert = require('assert');
|
|
const net = require('net');
|
|
|
|
// EADDRINUSE is expected to occur on FreeBSD
|
|
// Ref: https://github.com/nodejs/node/issues/13055
|
|
const expectedErrorCodes = ['ECONNREFUSED', 'EADDRINUSE'];
|
|
|
|
const optionsIPv4 = {
|
|
port: common.PORT,
|
|
family: 4,
|
|
localPort: common.PORT + 1,
|
|
localAddress: common.localhostIPv4
|
|
};
|
|
|
|
const optionsIPv6 = {
|
|
host: '::1',
|
|
family: 6,
|
|
port: common.PORT + 2,
|
|
localPort: common.PORT + 3,
|
|
localAddress: '::1',
|
|
};
|
|
|
|
function onError(err, options) {
|
|
assert.ok(expectedErrorCodes.includes(err.code));
|
|
assert.strictEqual(err.syscall, 'connect');
|
|
assert.strictEqual(err.localPort, options.localPort);
|
|
assert.strictEqual(err.localAddress, options.localAddress);
|
|
assert.strictEqual(
|
|
err.message,
|
|
`connect ${err.code} ${err.address}:${err.port} ` +
|
|
`- Local (${err.localAddress}:${err.localPort})`
|
|
);
|
|
}
|
|
|
|
const clientIPv4 = net.connect(optionsIPv4);
|
|
clientIPv4.on('error', common.mustCall((err) => onError(err, optionsIPv4)));
|
|
|
|
if (!common.hasIPv6) {
|
|
common.printSkipMessage('ipv6 part of test, no IPv6 support');
|
|
return;
|
|
}
|
|
|
|
const clientIPv6 = net.connect(optionsIPv6);
|
|
clientIPv6.on('error', common.mustCall((err) => onError(err, optionsIPv6)));
|