diff --git a/net/tcp/tcp_conn.c b/net/tcp/tcp_conn.c index e95f2a4ab7..b421d9d453 100644 --- a/net/tcp/tcp_conn.c +++ b/net/tcp/tcp_conn.c @@ -1199,6 +1199,15 @@ FAR struct tcp_conn_s *tcp_alloc_accept(FAR struct net_driver_s *dev, int tcp_bind(FAR struct tcp_conn_s *conn, FAR const struct sockaddr *addr) { +#if defined(CONFIG_NET_IPv4) && defined(CONFIG_NET_IPv6) + if (conn->domain != addr->sa_family) + { + nerr("ERROR: Invalid address type: %d != %d\n", conn->domain, + addr->sa_family); + return -EINVAL; + } +#endif + #ifdef CONFIG_NET_IPv4 #ifdef CONFIG_NET_IPv6 if (conn->domain == PF_INET) diff --git a/net/udp/udp_conn.c b/net/udp/udp_conn.c index 5b18064927..7c2a631896 100644 --- a/net/udp/udp_conn.c +++ b/net/udp/udp_conn.c @@ -807,6 +807,15 @@ int udp_bind(FAR struct udp_conn_s *conn, FAR const struct sockaddr *addr) uint16_t portno; int ret; +#if defined(CONFIG_NET_IPv4) && defined(CONFIG_NET_IPv6) + if (conn->domain != addr->sa_family) + { + nerr("ERROR: Invalid address type: %d != %d\n", conn->domain, + addr->sa_family); + return -EINVAL; + } +#endif + #ifdef CONFIG_NET_IPv4 #ifdef CONFIG_NET_IPv6 if (conn->domain == PF_INET)