Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
11 changes: 11 additions & 0 deletions doc/api/net.md
Original file line numberDiff line numberDiff line change
Expand Up@@ -294,6 +294,7 @@ TCP server, the argument is as follows, otherwise the argument is `undefined`.
* `data` {Object} The argument passed to event listener.
* `localAddress` {string} Local address.
* `localPort` {number} Local port.
* `localFamily` {string} Local family.
* `remoteAddress` {string} Remote address.
* `remotePort` {number} Remote port.
* `remoteFamily` {string} Remote IP family. `'IPv4'` or `'IPv6'`.
Expand DownExpand Up@@ -1047,6 +1048,16 @@ added: v0.9.6

The numeric representation of the local port. For example, `80` or `21`.

### `socket.localFamily`

<!-- YAML
added: REPLACEME
-->

* {string}

The string representation of the local IP family. `'IPv4'` or `'IPv6'`.

### `socket.pause()`

* Returns: {net.Socket} The socket itself.
Expand Down
4 changes: 4 additions & 0 deletions lib/net.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -834,6 +834,9 @@ protoGetter('localPort', function localPort() {
return this._getsockname().port;
});

protoGetter('localFamily', function localFamily() {
return this._getsockname().family;
});

Socket.prototype[kAfterAsyncWrite] = function() {
this[kLastWriteQueueSize] = 0;
Expand DownExpand Up@@ -1668,6 +1671,7 @@ function onconnection(err, clientHandle) {
clientHandle.getsockname(localInfo);
data.localAddress = localInfo.address;
data.localPort = localInfo.port;
data.localFamily = localInfo.family;
}
if (clientHandle.getpeername) {
const remoteInfo = ObjectCreate(null);
Expand Down
1 change: 1 addition & 0 deletions test/parallel/test-net-local-address-port.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -27,6 +27,7 @@ const net = require('net');
const server = net.createServer(common.mustCall(function(socket) {
assert.strictEqual(socket.localAddress, common.localhostIPv4);
assert.strictEqual(socket.localPort, this.address().port);
assert.strictEqual(socket.localFamily, this.address().family);
socket.on('end', function() {
server.close();
});
Expand Down