From d5b08a7ef1797466ae79bd9845c5ba41c471e539 Mon Sep 17 00:00:00 2001 From: dongjiuzhu1 Date: Wed, 23 Nov 2022 18:11:11 +0800 Subject: [PATCH] net/usrsock: fix get/setsockopt issue about usrsock protocol Signed-off-by: dongjiuzhu1 --- net/socket/getsockopt.c | 13 ++++++++++++- net/socket/setsockopt.c | 16 ++++++++++++++-- net/usrsock/usrsock_getsockopt.c | 2 +- net/usrsock/usrsock_setsockopt.c | 4 ---- 4 files changed, 27 insertions(+), 8 deletions(-) diff --git a/net/socket/getsockopt.c b/net/socket/getsockopt.c index f2f45e73e2..e2f815b55c 100644 --- a/net/socket/getsockopt.c +++ b/net/socket/getsockopt.c @@ -33,6 +33,7 @@ #include #include "socket/socket.h" +#include "usrsock/usrsock.h" #include "utils/utils.h" /**************************************************************************** @@ -123,9 +124,19 @@ static int psock_socketlevel_option(FAR struct socket *psock, int option, net_dsec2timeval(timeo, (struct timeval *)value); *value_len = sizeof(struct timeval); + return OK; } - break; + } +#ifdef CONFIG_NET_USRSOCK + if (psock->s_type == SOCK_USRSOCK_TYPE) + { + return -ENOPROTOOPT; + } +#endif + + switch (option) + { case SO_ACCEPTCONN: /* Reports whether socket listening is enabled */ { if (*value_len < sizeof(int)) diff --git a/net/socket/setsockopt.c b/net/socket/setsockopt.c index a7ede25744..e2a13af450 100644 --- a/net/socket/setsockopt.c +++ b/net/socket/setsockopt.c @@ -38,6 +38,7 @@ #include #include "socket/socket.h" +#include "usrsock/usrsock.h" #include "utils/utils.h" /**************************************************************************** @@ -130,9 +131,20 @@ static int psock_socketlevel_option(FAR struct socket *psock, int option, { _SO_SETOPT(conn->s_options, option); } - } - break; + return OK; + } + } + +#ifdef CONFIG_NET_USRSOCK + if (psock->s_type == SOCK_USRSOCK_TYPE) + { + return -ENOPROTOOPT; + } +#endif + + switch (option) + { case SO_BROADCAST: /* Permits sending of broadcast messages */ case SO_DEBUG: /* Enables recording of debugging information */ case SO_DONTROUTE: /* Requests outgoing messages bypass standard routing */ diff --git a/net/usrsock/usrsock_getsockopt.c b/net/usrsock/usrsock_getsockopt.c index 07f57a26e8..393f79dd20 100644 --- a/net/usrsock/usrsock_getsockopt.c +++ b/net/usrsock/usrsock_getsockopt.c @@ -189,7 +189,7 @@ int usrsock_getsockopt(FAR struct socket *psock, int level, int option, *value_len = sizeof(int); return OK; } - else + else if (option == SO_RCVTIMEO || option == SO_SNDTIMEO) { return -ENOPROTOOPT; } diff --git a/net/usrsock/usrsock_setsockopt.c b/net/usrsock/usrsock_setsockopt.c index 922da98e27..3fc2c16c13 100644 --- a/net/usrsock/usrsock_setsockopt.c +++ b/net/usrsock/usrsock_setsockopt.c @@ -174,10 +174,6 @@ int usrsock_setsockopt(FAR struct socket *psock, int level, int option, { return -ENOPROTOOPT; } - else - { - return -EINVAL; - } } net_lock();