Skip to content

Commit 7a999a1

Browse files
committed
lib: add net.Socket#localFamily property
Complements the existing net.Socket#remoteFamily property. PR-URL: #956 Reviewed-By: Sam Roberts <[email protected]> Reviewed-By: Trevor Norris <[email protected]>
1 parent f337595 commit 7a999a1

File tree

3 files changed

+9
-0
lines changed

3 files changed

+9
-0
lines changed

doc/api/net.markdown

+5
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,11 @@ client connects on `'192.168.1.1'`, the value would be `'192.168.1.1'`.
533533
For UNIX sockets and Windows pipes, the file path the socket is listening
534534
on. The local address for client sockets is always `''`, the empty string.
535535

536+
### socket.localFamily
537+
538+
The string representation of the local IP family. `'IPv4'` or `'IPv6'`
539+
for TCP sockets, `'pipe'` for UNIX sockets and Windows pipes.
540+
536541
### socket.localPort
537542

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

lib/net.js

+3
Original file line numberDiff line numberDiff line change
@@ -606,6 +606,9 @@ Socket.prototype.__defineGetter__('localAddress', function() {
606606
return this._getsockname().address;
607607
});
608608

609+
Socket.prototype.__defineGetter__('localFamily', function() {
610+
return this._getsockname().family;
611+
});
609612

610613
Socket.prototype.__defineGetter__('localPort', function() {
611614
return this._getsockname().port;

test/parallel/test-cluster-http-pipe.js

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ http.createServer(function(req, res) {
3333
assert.equal(req.connection.remoteFamily, 'pipe');
3434
assert.equal(req.connection.remotePort, undefined);
3535
assert.equal(req.connection.localAddress, common.PIPE);
36+
assert.equal(req.connection.localFamily, 'pipe');
3637
assert.equal(req.connection.localPort, undefined);
3738
res.writeHead(200);
3839
res.end('OK');

0 commit comments

Comments
 (0)