From f6263c8143eece101d8990f07e75c72c475bc802 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hubert=20Mi=C5=9B?= Date: Sat, 6 Feb 2021 19:07:10 +0100 Subject: [PATCH] net: socket: getsockopt SO_TYPE implementation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This patch adds implementation of socket option used to get type of given socket (e.g. SOCK_STREAM). Signed-off-by: Hubert Miś --- include/net/socket.h | 2 ++ subsys/net/lib/sockets/sockets.c | 13 +++++++++++++ 2 files changed, 15 insertions(+) diff --git a/include/net/socket.h b/include/net/socket.h index 44ed0775ad6..3a9e899591a 100644 --- a/include/net/socket.h +++ b/include/net/socket.h @@ -793,6 +793,8 @@ static inline char *inet_ntop(sa_family_t family, const void *src, char *dst, /* Socket options for SOL_SOCKET level */ /** sockopt: Enable server address reuse (ignored, for compatibility) */ #define SO_REUSEADDR 2 +/** sockopt: Type of the socket */ +#define SO_TYPE 3 /** sockopt: Async error (ignored, for compatibility) */ #define SO_ERROR 4 diff --git a/subsys/net/lib/sockets/sockets.c b/subsys/net/lib/sockets/sockets.c index c04fb24d1cb..8fdec9fd62c 100644 --- a/subsys/net/lib/sockets/sockets.c +++ b/subsys/net/lib/sockets/sockets.c @@ -1497,6 +1497,19 @@ int zsock_getsockopt_ctx(struct net_context *ctx, int level, int optname, switch (level) { case SOL_SOCKET: switch (optname) { + case SO_TYPE: { + int type = (int)net_context_get_type(ctx); + + if (*optlen != sizeof(type)) { + errno = EINVAL; + return -1; + } + + *(int *)optval = type; + + return 0; + } + case SO_TXTIME: if (IS_ENABLED(CONFIG_NET_CONTEXT_TXTIME)) { ret = net_context_get_option(ctx,