This is an automated email from the ASF dual-hosted git repository. xiaoxiang781216 pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit 82920e7ede8cd7c7d40a6def8cd5252f19aeddd5 Author: Marco Casaroli <[email protected]> AuthorDate: Wed Nov 11 04:44:30 2026 +0100 net/tcp: Fail listen() on a connected socket with EINVAL. listen() on a connected TCP socket, or on one that connects, succeeded and put the connection in the listener table. On an accepted socket it failed with EADDRINUSE. POSIX and Linux return EINVAL: only a socket that is not connected can listen. inet_listen() now checks the TCP state first. Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Marco Casaroli <[email protected]> --- net/inet/inet_sockif.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/net/inet/inet_sockif.c b/net/inet/inet_sockif.c index 64cdc247e14..29af73ab596 100644 --- a/net/inet/inet_sockif.c +++ b/net/inet/inet_sockif.c @@ -1127,6 +1127,13 @@ static int inet_listen(FAR struct socket *psock, int backlog) #ifdef NET_TCP_HAVE_STACK conn = psock->s_conn; + /* A connected socket, or one that connects, cannot listen (as Linux) */ + + if (conn->tcpstateflags != TCP_ALLOCATED) + { + return -EINVAL; + } + if (conn->lport == 0) { #ifdef CONFIG_NET_IPv4
