From d2c9ac02cb1a3a59508dcf50cb8764e58d569832 Mon Sep 17 00:00:00 2001 From: Guy Bedford Date: Tue, 10 Nov 2026 21:13:27 -0700 Subject: [PATCH] net: expose peer name of pipe connections getpeername(2) on a Unix domain socket returns the path the peer is bound to, but the pipe handle had no getpeername method, so socket.remoteAddress was always undefined for pipe connections. Add getpeername to the pipe handle, backed by uv_pipe_getpeername(), so that socket.remoteAddress reports the listening path on the connecting side and the path of a bound client on the accepting side. It remains undefined for an unbound peer, and on Windows, where a named pipe has a single name rather than one per end. Signed-off-by: Guy Bedford Assisted-by: Claude Fable 5.2 PR-URL: https://github.com/nodejs/node/pull/67402 Reviewed-By: Ethan Arrowood Reviewed-By: James M Snell --- doc/api/net.md | 14 +++ lib/internal/http2/core.js | 6 +- lib/net.js | 6 +- src/pipe_wrap.cc | 46 ++++++++- src/pipe_wrap.h | 4 +- test/parallel/test-http2-pipe-origin-set.js | 47 +++++++++ test/parallel/test-net-pipe-remote-address.js | 99 +++++++++++++++++++ 7 files changed, 215 insertions(+), 7 deletions(-) create mode 100644 test/parallel/test-http2-pipe-origin-set.js create mode 100644 test/parallel/test-net-pipe-remote-address.js diff --git a/doc/api/net.md b/doc/api/net.md index 0a3800f3b90..3bf4f5659af 100644 --- a/doc/api/net.md +++ b/doc/api/net.md @@ -1602,6 +1602,10 @@ If the socket is `ref`ed calling `ref` again will have no effect. * Type: {string} @@ -1610,6 +1614,14 @@ The string representation of the remote IP address. For example, `'74.125.127.100'` or `'2001:4860:a005::68'`. Value may be `undefined` if the socket is destroyed (for example, if the client disconnected). +For a [Unix domain socket][IPC], this is the path the peer is bound to: the +listening path on the connecting side, and on the accepting side the path of a +client that was bound before connecting (see [`BoundSocket`][]). It is +`undefined` if the peer is not bound to a path, which is the case for most +clients. [`socket.remoteFamily`][] and [`socket.remotePort`][] are always +`undefined` for these connections, as is `socket.remoteAddress` for a Windows +named pipe. + ### `socket.remoteFamily`