From fb3655e9f04a7ad10249c50c57d8110a10e2ea8b Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Mon, 23 Oct 2017 09:58:11 -0600 Subject: [PATCH] net/inet: Add check for protocol before handing out TCP and UDP sockets. --- net/inet/inet_sockif.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/net/inet/inet_sockif.c b/net/inet/inet_sockif.c index 0aa96e70b2a..df9b4676974 100644 --- a/net/inet/inet_sockif.c +++ b/net/inet/inet_sockif.c @@ -1237,9 +1237,23 @@ FAR const struct sock_intf_s * } else #endif +#ifdef NET_UDP_HAVE_STACK + if (type == SOCK_DGRAM && (protocol == 0 || protocol == IPPROTO_UDP)) { return &g_inet_sockif; } + else +#endif +#ifdef NET_TCP_HAVE_STACK + if (type == SOCK_STREAM && (protocol == 0 || protocol == IPPROTO_TCP)) + { + return &g_inet_sockif; + } + else +#endif + { + return NULL; + } } #endif /* HAVE_INET_SOCKETS */