This is an automated email from the ASF dual-hosted git repository.
GUIDINGLI pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git
The following commit(s) were added to refs/heads/master by this push:
new f2cf719359b net/local: Give the ends of a socket pair an unnamed
address.
f2cf719359b is described below
commit f2cf719359b3b85777547f878d66a366b72d9c85
Author: Marco Casaroli <[email protected]>
AuthorDate: Thu Nov 26 15:37:55 2026 +0100
net/local: Give the ends of a socket pair an unnamed address.
socketpair() gives each end an internal name: "socketpair" and a
number. The name only names the FIFOs of the pair, but getsockname()
and getpeername() of an end gave it to the program, and recvfrom() of a
stream pair gave it as the source address. A program that prints or
compares the address got a name that no bind() made, and a different
one for each pair.
Linux gives an unnamed address for the ends of a socket pair: only
sun_family, and an address length of sizeof(sa_family_t). An unbound
local socket already gets this address. Now getsockname(),
getpeername() and the source address of recvfrom() give it for a socket
pair too. A datagram pair already sends an empty source name.
The behavior is the same in all build modes.
Assisted-by: Claude Code:claude-opus-5-5
Signed-off-by: Marco Casaroli <[email protected]>
---
net/local/local_recvutils.c | 17 +++++++++++++++++
net/local/local_sockif.c | 12 ++++++++----
2 files changed, 25 insertions(+), 4 deletions(-)
diff --git a/net/local/local_recvutils.c b/net/local/local_recvutils.c
index 4a208619a9c..bf7b5e9187e 100644
--- a/net/local/local_recvutils.c
+++ b/net/local/local_recvutils.c
@@ -153,6 +153,23 @@ int local_getaddr(FAR struct local_conn_s *conn, FAR
struct sockaddr *addr,
DEBUGASSERT(conn && addr && addrlen);
+ /* A socket pair has no name, as an unbound socket. Its internal name
+ * only names the FIFOs of the pair.
+ */
+
+ if (conn->lc_pair)
+ {
+ if (*addrlen < sizeof(sa_family_t))
+ {
+ *addrlen = 0;
+ return OK;
+ }
+
+ addr->sa_family = AF_LOCAL;
+ *addrlen = sizeof(sa_family_t);
+ return OK;
+ }
+
/* Get the length of the path (minus the NUL terminator) and the length
* of the whole Unix domain address.
*/
diff --git a/net/local/local_sockif.c b/net/local/local_sockif.c
index fab37936877..98d09b0c926 100644
--- a/net/local/local_sockif.c
+++ b/net/local/local_sockif.c
@@ -382,9 +382,11 @@ static int local_getsockname(FAR struct socket *psock,
{
/* Now copy the address description. */
- if (conn->lc_type == LOCAL_TYPE_UNNAMED)
+ if (conn->lc_type == LOCAL_TYPE_UNNAMED || conn->lc_pair)
{
- /* Zero-length sun_path... */
+ /* Zero-length sun_path. The name of a socket pair is internal:
+ * it only names the FIFOs of the pair.
+ */
*addrlen = sizeof(sa_family_t);
}
@@ -512,9 +514,11 @@ static int local_getpeername(FAR struct socket *psock,
{
/* Now copy the address description. */
- if (peer->lc_type == LOCAL_TYPE_UNNAMED)
+ if (peer->lc_type == LOCAL_TYPE_UNNAMED || peer->lc_pair)
{
- /* Zero-length sun_path... */
+ /* Zero-length sun_path. The name of a socket pair is internal:
+ * it only names the FIFOs of the pair.
+ */
*addrlen = sizeof(sa_family_t);
}