2015-05-19 13:00:06 +02:00
|
|
|
'use strict';
|
2016-09-09 15:28:15 -07:00
|
|
|
const common = require('../common');
|
|
|
|
const assert = require('assert');
|
2011-04-13 12:19:15 -04:00
|
|
|
|
2016-09-09 15:28:15 -07:00
|
|
|
const net = require('net');
|
2011-04-13 12:19:15 -04:00
|
|
|
|
2017-01-08 13:19:00 +00:00
|
|
|
let conns_closed = 0;
|
2011-04-13 12:19:15 -04:00
|
|
|
|
2017-01-08 13:19:00 +00:00
|
|
|
const remoteAddrCandidates = [ common.localhostIPv4 ];
|
2014-08-11 13:29:00 -07:00
|
|
|
if (common.hasIPv6) remoteAddrCandidates.push('::ffff:127.0.0.1');
|
|
|
|
|
2017-01-08 13:19:00 +00:00
|
|
|
const remoteFamilyCandidates = ['IPv4'];
|
2014-08-11 13:29:00 -07:00
|
|
|
if (common.hasIPv6) remoteFamilyCandidates.push('IPv6');
|
|
|
|
|
2017-01-08 13:19:00 +00:00
|
|
|
const server = net.createServer(common.mustCall(function(socket) {
|
2016-12-30 10:09:13 -05:00
|
|
|
assert.ok(remoteAddrCandidates.includes(socket.remoteAddress));
|
|
|
|
assert.ok(remoteFamilyCandidates.includes(socket.remoteFamily));
|
2011-09-05 02:09:24 +02:00
|
|
|
assert.ok(socket.remotePort);
|
2016-12-30 10:09:13 -05:00
|
|
|
assert.notStrictEqual(socket.remotePort, this.address().port);
|
2011-04-13 12:19:15 -04:00
|
|
|
socket.on('end', function() {
|
2016-09-09 15:28:15 -07:00
|
|
|
if (++conns_closed === 2) server.close();
|
2011-04-13 12:19:15 -04:00
|
|
|
});
|
2015-03-10 16:48:19 -04:00
|
|
|
socket.on('close', function() {
|
2016-12-30 10:09:13 -05:00
|
|
|
assert.ok(remoteAddrCandidates.includes(socket.remoteAddress));
|
|
|
|
assert.ok(remoteFamilyCandidates.includes(socket.remoteFamily));
|
2015-03-10 16:48:19 -04:00
|
|
|
});
|
2012-12-13 09:51:31 -08:00
|
|
|
socket.resume();
|
2016-07-15 15:43:24 -04:00
|
|
|
}, 2));
|
2011-04-13 12:19:15 -04:00
|
|
|
|
2016-05-29 03:06:56 -04:00
|
|
|
server.listen(0, 'localhost', function() {
|
2017-01-08 13:19:00 +00:00
|
|
|
const client = net.createConnection(this.address().port, 'localhost');
|
|
|
|
const client2 = net.createConnection(this.address().port);
|
2011-04-13 12:19:15 -04:00
|
|
|
client.on('connect', function() {
|
2016-12-30 10:09:13 -05:00
|
|
|
assert.ok(remoteAddrCandidates.includes(client.remoteAddress));
|
|
|
|
assert.ok(remoteFamilyCandidates.includes(client.remoteFamily));
|
2016-09-09 15:28:15 -07:00
|
|
|
assert.strictEqual(client.remotePort, server.address().port);
|
2011-04-13 12:19:15 -04:00
|
|
|
client.end();
|
|
|
|
});
|
2015-03-10 16:48:19 -04:00
|
|
|
client.on('close', function() {
|
2016-12-30 10:09:13 -05:00
|
|
|
assert.ok(remoteAddrCandidates.includes(client.remoteAddress));
|
|
|
|
assert.ok(remoteFamilyCandidates.includes(client.remoteFamily));
|
2015-03-10 16:48:19 -04:00
|
|
|
});
|
2011-04-13 12:19:15 -04:00
|
|
|
client2.on('connect', function() {
|
2016-12-30 10:09:13 -05:00
|
|
|
assert.ok(remoteAddrCandidates.includes(client2.remoteAddress));
|
|
|
|
assert.ok(remoteFamilyCandidates.includes(client2.remoteFamily));
|
2016-09-09 15:28:15 -07:00
|
|
|
assert.strictEqual(client2.remotePort, server.address().port);
|
2011-04-13 12:19:15 -04:00
|
|
|
client2.end();
|
|
|
|
});
|
2015-03-10 16:48:19 -04:00
|
|
|
client2.on('close', function() {
|
2016-12-30 10:09:13 -05:00
|
|
|
assert.ok(remoteAddrCandidates.includes(client2.remoteAddress));
|
|
|
|
assert.ok(remoteFamilyCandidates.includes(client2.remoteFamily));
|
2015-03-10 16:48:19 -04:00
|
|
|
});
|
2011-04-13 12:19:15 -04:00
|
|
|
});
|