From 51efe468b9ea77b85ad4b914e758101748334d09 Mon Sep 17 00:00:00 2001 From: "chao.an" Date: Tue, 1 Dec 2020 15:51:12 +0800 Subject: [PATCH] net/sockopt: fix invalid option set fix invalid option set if enable UDP without TCP Change-Id: I732893501a9b28749706d6f860c77ae9e14b358c Signed-off-by: chao.an --- net/socket/getsockopt.c | 11 ++++------- net/socket/setsockopt.c | 6 +++--- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/net/socket/getsockopt.c b/net/socket/getsockopt.c index b3a575ff3e..11932ba1b8 100644 --- a/net/socket/getsockopt.c +++ b/net/socket/getsockopt.c @@ -379,17 +379,17 @@ int psock_getsockopt(FAR struct socket *psock, int level, int option, ret = psock_socketlevel_option(psock, option, value, value_len); break; - case IPPROTO_TCP: /* TCP protocol socket options (see include/netinet/tcp.h) */ #ifdef CONFIG_NET_TCPPROTO_OPTIONS + case IPPROTO_TCP: /* TCP protocol socket options (see include/netinet/tcp.h) */ ret = tcp_getsockopt(psock, option, value, value_len); break; #endif - case SOL_CAN_RAW:/* CAN protocol socket options (see include/netpacket/can.h) */ #ifdef CONFIG_NET_CANPROTO_OPTIONS + case SOL_CAN_RAW:/* CAN protocol socket options (see include/netpacket/can.h) */ ret = can_getsockopt(psock, option, value, value_len); -#endif break; +#endif /* These levels are defined in sys/socket.h, but are not yet * implemented. @@ -398,11 +398,8 @@ int psock_getsockopt(FAR struct socket *psock, int level, int option, case IPPROTO_IP: /* TCP protocol socket options (see include/netinet/ip.h) */ case IPPROTO_IPV6: /* TCP protocol socket options (see include/netinet/ip6.h) */ case IPPROTO_UDP: /* TCP protocol socket options (see include/netinit/udp.h) */ - ret = -ENOSYS; - break; - default: /* The provided level is invalid */ - ret = -EINVAL; + ret = -ENOPROTOOPT; break; } diff --git a/net/socket/setsockopt.c b/net/socket/setsockopt.c index 9a9892b236..bddd9c6414 100644 --- a/net/socket/setsockopt.c +++ b/net/socket/setsockopt.c @@ -399,14 +399,14 @@ int psock_setsockopt(FAR struct socket *psock, int level, int option, ret = psock_socketlevel_option(psock, option, value, value_len); break; - case IPPROTO_TCP:/* TCP protocol socket options (see include/netinet/tcp.h) */ #ifdef CONFIG_NET_TCPPROTO_OPTIONS + case IPPROTO_TCP:/* TCP protocol socket options (see include/netinet/tcp.h) */ ret = tcp_setsockopt(psock, option, value, value_len); break; #endif - case IPPROTO_UDP:/* UDP protocol socket options (see include/netinet/udp.h) */ #ifdef CONFIG_NET_UDPPROTO_OPTIONS + case IPPROTO_UDP:/* UDP protocol socket options (see include/netinet/udp.h) */ ret = udp_setsockopt(psock, option, value, value_len); break; #endif @@ -430,7 +430,7 @@ int psock_setsockopt(FAR struct socket *psock, int level, int option, #endif default: /* The provided level is invalid */ - ret = -EINVAL; + ret = -ENOPROTOOPT; break; }