From 7a999a13766ac68049812fedbdfd15a0250f0f07 Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Thu, 5 Mar 2015 14:24:53 +0100 Subject: [PATCH] lib: add net.Socket#localFamily property Complements the existing net.Socket#remoteFamily property. PR-URL: https://github.com/nodejs/node/pull/956 Reviewed-By: Sam Roberts Reviewed-By: Trevor Norris --- doc/api/net.markdown | 5 +++++ lib/net.js | 3 +++ test/parallel/test-cluster-http-pipe.js | 1 + 3 files changed, 9 insertions(+) diff --git a/doc/api/net.markdown b/doc/api/net.markdown index ee7e487ca91770..08f27a57a5649d 100644 --- a/doc/api/net.markdown +++ b/doc/api/net.markdown @@ -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`. diff --git a/lib/net.js b/lib/net.js index c3ccebb6423f66..bd64b49ee75773 100644 --- a/lib/net.js +++ b/lib/net.js @@ -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; diff --git a/test/parallel/test-cluster-http-pipe.js b/test/parallel/test-cluster-http-pipe.js index f4ee5c240e6854..0aae9b6b4409bb 100644 --- a/test/parallel/test-cluster-http-pipe.js +++ b/test/parallel/test-cluster-http-pipe.js @@ -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');