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 acd38f634b6fb7ef9dcfdfd4f5713811e1f5863d
Author: Marco Casaroli <[email protected]>
AuthorDate: Sat Nov 21 17:06:52 2026 +0100

    net/tcp: Refuse an IPv4-mapped address in connect() of an IPv6 socket.
    
    A TCP socket of AF_INET6 is IPv6-only (IPV6_V6ONLY is always set for
    TCP).  connect() to an IPv4-mapped address (::ffff:a.b.c.d) does not
    use IPv4: it sends IPv6 SYN segments with the mapped address as the
    destination, and the connection never completes.
    
    Return ENETUNREACH, as Linux does for an IPv6-only socket and as
    udp_connect() already does for a UDP socket with IPV6_V6ONLY.
    
    Assisted-by: Claude Code:claude-opus-5-5
    Signed-off-by: Marco Casaroli <[email protected]>
---
 net/tcp/tcp_conn.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/net/tcp/tcp_conn.c b/net/tcp/tcp_conn.c
index b576519f8e7..5211e1df21a 100644
--- a/net/tcp/tcp_conn.c
+++ b/net/tcp/tcp_conn.c
@@ -1547,6 +1547,15 @@ int tcp_connect(FAR struct tcp_conn_s *conn, FAR const 
struct sockaddr *addr)
       FAR const struct sockaddr_in6 *inaddr =
         (FAR const struct sockaddr_in6 *)addr;
 
+      /* A TCP socket is IPv6-only: an IPv4-mapped address is not
+       * reachable (as Linux with IPV6_V6ONLY).
+       */
+
+      if (ip6_is_ipv4addr(&inaddr->sin6_addr))
+        {
+          return -ENETUNREACH;
+        }
+
       conn->rport   = inaddr->sin6_port;
 
       /* The sockaddr address is 128-bits in network order.

Reply via email to