Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 3348dde

Browse filesBrowse 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
Copy full SHA for 3348dde

File tree

Expand file treeCollapse file tree

3 files changed

+16
-0
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

3 files changed

+16
-0
lines changed
Open diff view settings
Collapse file

‎doc/api/net.md‎

Copy file name to clipboardExpand all lines: doc/api/net.md
+11Lines changed: 11 additions & 0 deletions
  • Display the source diff
  • Display the rich diff
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.
Collapse file

‎lib/net.js‎

Copy file name to clipboardExpand all lines: lib/net.js
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -840,6 +840,9 @@ protoGetter('localPort', function localPort() {
840840
return this._getsockname().port;
841841
});
842842

843+
protoGetter('localFamily', function localFamily() {
844+
return this._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
const remoteInfo = ObjectCreate(null);
Collapse file

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

Copy file name to clipboardExpand all lines: test/parallel/test-net-local-address-port.js
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ const net = require('net');
2727
const server = 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.