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


The following commit(s) were added to refs/heads/master by this push:
     new 2eaeeaaa015 net/sixlowpan: Bind an unbound UDP socket before sending.
2eaeeaaa015 is described below

commit 2eaeeaaa0155f26f1425f33ce0f000ed8fe2ac15
Author: Max Kriegleder <[email protected]>
AuthorDate: Mon Oct 26 21:36:53 2026 +0100

    net/sixlowpan: Bind an unbound UDP socket before sending.
    
    psock_6lowpan_udp_sendto() sent from conn->lport without giving an
    unbound socket a local port, as psock_udp_sendto() does through
    udp_connect().  udp_poll() serves only connections with a local port,
    so sixlowpan_send() waited for a poll that never came and sendto()
    never returned.
    
    Select a free port there, as udp_connect() does.
    
    Assisted-by: Claude:claude-opus-5-5
    Signed-off-by: Max Kriegleder <[email protected]>
---
 net/sixlowpan/sixlowpan_udpsend.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/net/sixlowpan/sixlowpan_udpsend.c 
b/net/sixlowpan/sixlowpan_udpsend.c
index 80de3071973..389b5b574c5 100644
--- a/net/sixlowpan/sixlowpan_udpsend.c
+++ b/net/sixlowpan/sixlowpan_udpsend.c
@@ -191,6 +191,21 @@ ssize_t psock_6lowpan_udp_sendto(FAR struct socket *psock,
   conn = psock->s_conn;
   DEBUGASSERT(conn != NULL);
 
+  /* Bind an unbound socket to a local port, as psock_udp_sendto() does.
+   * udp_poll() serves only connections with a local port, so without one
+   * sixlowpan_send() would wait for a poll that never comes.
+   */
+
+  if (conn->lport == 0)
+    {
+      conn->lport = HTONS(udp_select_port(conn->domain, &conn->u));
+      if (conn->lport == 0)
+        {
+          nerr("ERROR: Failed to get a local port\n");
+          return (ssize_t)-EADDRINUSE;
+        }
+    }
+
   /* Route outgoing message to the correct device */
 
   dev = netdev_findby_ripv6addr(conn->u.ipv6.laddr,

Reply via email to