lib: add net.Socket#localFamily property
authorBen Noordhuis <info@bnoordhuis.nl>
Thu, 5 Mar 2015 13:24:53 +0000 (14:24 +0100)
committerBen Noordhuis <info@bnoordhuis.nl>
Thu, 27 Aug 2015 15:45:29 +0000 (17:45 +0200)
Complements the existing net.Socket#remoteFamily property.

PR-URL: https://github.com/nodejs/node/pull/956
Reviewed-By: Sam Roberts <vieuxtech@gmail.com>
Reviewed-By: Trevor Norris <trev.norris@gmail.com>
doc/api/net.markdown
lib/net.js
test/parallel/test-cluster-http-pipe.js

index ee7e487..08f27a5 100644 (file)
@@ -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`.
index c3ccebb..bd64b49 100644 (file)
@@ -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;
index f4ee5c2..0aae9b6 100644 (file)
@@ -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');