summaryrefslogtreecommitdiff
path: root/test/parallel/test-net-listen-ipv6only.js
blob: a329011bcc8a2398d34e1f1e4ac951cbadbca9e2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
'use strict';

const common = require('../common');
if (!common.hasIPv6)
  common.skip('no IPv6 support');

// This test ensures that dual-stack support is disabled when
// we specify the `ipv6Only` option in `net.Server.listen()`.
const assert = require('assert');
const net = require('net');

const host = '::';
const server = net.createServer();
server.listen({
  host,
  port: 0,
  ipv6Only: true,
}, common.mustCall(() => {
  const { port } = server.address();
  const socket = net.connect({
    host: '0.0.0.0',
    port,
  });

  socket.on('connect', common.mustNotCall());
  socket.on('error', common.mustCall((err) => {
    assert.strictEqual(err.code, 'ECONNREFUSED');
    server.close();
  }));
}));