diff --git a/include/net/net_context.h b/include/net/net_context.h index 39c46e8a445..9d90fddc599 100644 --- a/include/net/net_context.h +++ b/include/net/net_context.h @@ -257,6 +257,9 @@ struct net_context { #endif /* CONFIG_NET_CONTEXT_SYNC_RECV */ #if defined(CONFIG_NET_SOCKETS) + /** BSD socket private data */ + void *socket_data; + /** Per-socket packet or connection queues */ union { struct k_fifo recv_q; diff --git a/subsys/net/lib/sockets/sockets.c b/subsys/net/lib/sockets/sockets.c index b57f19c0900..b808cbc1cab 100644 --- a/subsys/net/lib/sockets/sockets.c +++ b/subsys/net/lib/sockets/sockets.c @@ -111,6 +111,9 @@ int zsock_socket_internal(int family, int type, int proto) /* Initialize user_data, all other calls will preserve it */ ctx->user_data = NULL; + /* The socket flags are stored here */ + ctx->socket_data = NULL; + /* recv_q and accept_q are in union */ k_fifo_init(&ctx->recv_q); diff --git a/subsys/net/lib/sockets/sockets_internal.h b/subsys/net/lib/sockets/sockets_internal.h index 356ab7c4827..22c525732de 100644 --- a/subsys/net/lib/sockets/sockets_internal.h +++ b/subsys/net/lib/sockets/sockets_internal.h @@ -15,15 +15,15 @@ static inline void sock_set_flag(struct net_context *ctx, uintptr_t mask, uintptr_t flag) { - uintptr_t val = POINTER_TO_UINT(ctx->user_data); + uintptr_t val = POINTER_TO_UINT(ctx->socket_data); val = (val & ~mask) | flag; - (ctx)->user_data = UINT_TO_POINTER(val); + (ctx)->socket_data = UINT_TO_POINTER(val); } static inline uintptr_t sock_get_flag(struct net_context *ctx, uintptr_t mask) { - return POINTER_TO_UINT(ctx->user_data) & mask; + return POINTER_TO_UINT(ctx->socket_data) & mask; } #define sock_is_eof(ctx) sock_get_flag(ctx, SOCK_EOF)