Skip to content

Commit

Permalink
lib: add net.Socket#localFamily property
Browse files Browse the repository at this point in the history
Complements the existing net.Socket#remoteFamily property.

PR-URL: #956
Reviewed-By: Sam Roberts <vieuxtech@gmail.com>
Reviewed-By: Trevor Norris <trev.norris@gmail.com>
  • Loading branch information
bnoordhuis committed Aug 27, 2015
1 parent f337595 commit 7a999a1
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 0 deletions.
5 changes: 5 additions & 0 deletions doc/api/net.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,11 @@ client connects on `'192.168.1.1'`, the value would be `'192.168.1.1'`.
For UNIX sockets and Windows pipes, the file path the socket is listening
on. The local address for client sockets is always `''`, the empty string.

### socket.localFamily

The string representation of the local IP family. `'IPv4'` or `'IPv6'`
for TCP sockets, `'pipe'` for UNIX sockets and Windows pipes.

### socket.localPort

The numeric representation of the local port. For example, `80` or `21`.
Expand Down
3 changes: 3 additions & 0 deletions lib/net.js
Original file line number Diff line number Diff line change
Expand Up @@ -606,6 +606,9 @@ Socket.prototype.__defineGetter__('localAddress', function() {
return this._getsockname().address;
});

Socket.prototype.__defineGetter__('localFamily', function() {
return this._getsockname().family;
});

Socket.prototype.__defineGetter__('localPort', function() {
return this._getsockname().port;
Expand Down
1 change: 1 addition & 0 deletions test/parallel/test-cluster-http-pipe.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ http.createServer(function(req, res) {
assert.equal(req.connection.remoteFamily, 'pipe');
assert.equal(req.connection.remotePort, undefined);
assert.equal(req.connection.localAddress, common.PIPE);
assert.equal(req.connection.localFamily, 'pipe');
assert.equal(req.connection.localPort, undefined);
res.writeHead(200);
res.end('OK');
Expand Down

0 comments on commit 7a999a1

Please sign in to comment.