1'use strict'; 2const common = require('../common'); 3const assert = require('assert'); 4const net = require('net'); 5 6// EADDRINUSE is expected to occur on FreeBSD 7// Ref: https://github.com/nodejs/node/issues/13055 8const expectedErrorCodes = ['ECONNREFUSED', 'EADDRINUSE']; 9 10const optionsIPv4 = { 11 port: common.PORT, 12 localPort: common.PORT + 1, 13 localAddress: common.localhostIPv4 14}; 15 16const optionsIPv6 = { 17 host: '::1', 18 port: common.PORT + 2, 19 localPort: common.PORT + 3, 20 localAddress: '::1', 21}; 22 23function onError(err, options) { 24 assert.ok(expectedErrorCodes.includes(err.code)); 25 assert.strictEqual(err.syscall, 'connect'); 26 assert.strictEqual(err.localPort, options.localPort); 27 assert.strictEqual(err.localAddress, options.localAddress); 28 assert.strictEqual( 29 err.message, 30 `connect ${err.code} ${err.address}:${err.port} ` + 31 `- Local (${err.localAddress}:${err.localPort})` 32 ); 33} 34 35const clientIPv4 = net.connect(optionsIPv4); 36clientIPv4.on('error', common.mustCall((err) => onError(err, optionsIPv4))); 37 38if (!common.hasIPv6) { 39 common.printSkipMessage('ipv6 part of test, no IPv6 support'); 40 return; 41} 42 43const clientIPv6 = net.connect(optionsIPv6); 44clientIPv6.on('error', common.mustCall((err) => onError(err, optionsIPv6))); 45