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 2c199417d8dbd7aeedc7c62e994ee4dc815b040a
Author: raiden00pl <[email protected]>
AuthorDate: Thu Oct 22 18:18:02 2026 +0200

    net/can: Accept SO_RCVBUF and SO_SNDBUF at level SOL_SOCKET.
    
    can_setsockopt() and can_getsockopt() keep SO_RCVBUF and SO_SNDBUF but
    accepted them only at SOL_CAN_RAW, so the SOL_SOCKET form failed with
    ENOPROTOOPT.  POSIX XSH 2.10.16, socket-level options: "Unless otherwise
    noted, each may be examined with getsockopt() and set with setsockopt()
    on all types of socket."
    
https://pubs.opengroup.org/onlinepubs/9799919799/functions/V2_chap02.html#tag_16_10_16
    
    Assisted-by: Claude:claude-opus-5-5
    Signed-off-by: raiden00pl <[email protected]>
---
 net/can/can_getsockopt.c | 13 ++++++++++++-
 net/can/can_setsockopt.c | 13 ++++++++++++-
 2 files changed, 24 insertions(+), 2 deletions(-)

diff --git a/net/can/can_getsockopt.c b/net/can/can_getsockopt.c
index 266e3be00d7..50a67e4569e 100644
--- a/net/can/can_getsockopt.c
+++ b/net/can/can_getsockopt.c
@@ -83,7 +83,18 @@ int can_getsockopt(FAR struct socket *psock, int level, int 
option,
   DEBUGASSERT(value != NULL && value_len != NULL);
   conn = psock->s_conn;
 
-  if (level != SOL_CAN_RAW)
+  /* SO_RCVBUF and SO_SNDBUF are socket-level options that are kept in
+   * the CAN connection; psock_socketlevel_option() handles the others.
+   */
+
+  if (level == SOL_SOCKET)
+    {
+      if (option != SO_RCVBUF && option != SO_SNDBUF)
+        {
+          return -ENOPROTOOPT;
+        }
+    }
+  else if (level != SOL_CAN_RAW)
     {
       return -ENOPROTOOPT;
     }
diff --git a/net/can/can_setsockopt.c b/net/can/can_setsockopt.c
index 22d1c8bd0b3..175fd1fd85a 100644
--- a/net/can/can_setsockopt.c
+++ b/net/can/can_setsockopt.c
@@ -81,7 +81,18 @@ int can_setsockopt(FAR struct socket *psock, int level, int 
option,
 
   conn = psock->s_conn;
 
-  if (level != SOL_CAN_RAW)
+  /* SO_RCVBUF and SO_SNDBUF are socket-level options that are kept in
+   * the CAN connection; psock_socketlevel_option() handles the others.
+   */
+
+  if (level == SOL_SOCKET)
+    {
+      if (option != SO_RCVBUF && option != SO_SNDBUF)
+        {
+          return -ENOPROTOOPT;
+        }
+    }
+  else if (level != SOL_CAN_RAW)
     {
       return -ENOPROTOOPT;
     }

Reply via email to