Skip to content

Commit 3348dde

Browse files
theanarkhdanielleadams
authored andcommitted
net: add local family
PR-URL: #43975 Reviewed-By: Paolo Insogna <paolo@cowtech.it> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
1 parent ad1a823 commit 3348dde

3 files changed

Lines changed: 16 additions & 0 deletions

File tree

‎doc/api/net.md‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,7 @@ TCP server, the argument is as follows, otherwise the argument is `undefined`.
294294
*`data` {Object} The argument passed to event listener.
295295
*`localAddress` {string} Local address.
296296
*`localPort` {number} Local port.
297+
*`localFamily` {string} Local family.
297298
*`remoteAddress` {string} Remote address.
298299
*`remotePort` {number} Remote port.
299300
*`remoteFamily` {string} Remote IP family. `'IPv4'` or `'IPv6'`.
@@ -1045,6 +1046,16 @@ added: v0.9.6
10451046

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

1049+
### `socket.localFamily`
1050+
1051+
<!-- YAML
1052+
added: REPLACEME
1053+
-->
1054+
1055+
* {string}
1056+
1057+
The string representation of the local IP family. `'IPv4'` or `'IPv6'`.
1058+
10481059
### `socket.pause()`
10491060

10501061
* Returns: {net.Socket} The socket itself.

‎lib/net.js‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -840,6 +840,9 @@ protoGetter('localPort', function localPort() {
840840
returnthis._getsockname().port;
841841
});
842842

843+
protoGetter('localFamily',functionlocalFamily(){
844+
returnthis._getsockname().family;
845+
});
843846

844847
Socket.prototype[kAfterAsyncWrite]=function(){
845848
this[kLastWriteQueueSize]=0;
@@ -1674,6 +1677,7 @@ function onconnection(err, clientHandle) {
16741677
clientHandle.getsockname(localInfo);
16751678
data.localAddress=localInfo.address;
16761679
data.localPort=localInfo.port;
1680+
data.localFamily=localInfo.family;
16771681
}
16781682
if(clientHandle.getpeername){
16791683
constremoteInfo=ObjectCreate(null);

‎test/parallel/test-net-local-address-port.js‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ const net = require('net');
2727
constserver=net.createServer(common.mustCall(function(socket){
2828
assert.strictEqual(socket.localAddress,common.localhostIPv4);
2929
assert.strictEqual(socket.localPort,this.address().port);
30+
assert.strictEqual(socket.localFamily,this.address().family);
3031
socket.on('end',function(){
3132
server.close();
3233
});

0 commit comments

Comments
 (0)