diff --git a/net/socket/net_dup2.c b/net/socket/net_dup2.c index 05598bb6a7e..ff765b481ed 100644 --- a/net/socket/net_dup2.c +++ b/net/socket/net_dup2.c @@ -31,6 +31,7 @@ #include #include +#include #include "inet/inet.h" #include "tcp/tcp.h" @@ -59,6 +60,9 @@ int psock_dup2(FAR struct socket *psock1, FAR struct socket *psock2) { +#ifdef NET_TCP_HAVE_STACK + FAR struct tcp_conn_s *conn; +#endif int ret = OK; /* Parts of this operation need to be atomic */ @@ -97,7 +101,11 @@ int psock_dup2(FAR struct socket *psock1, FAR struct socket *psock2) * the network connection is lost. */ - if (psock2->s_type == SOCK_STREAM) + conn = (FAR struct tcp_conn_s *)psock2->s_conn; + + if (psock2->s_type == SOCK_STREAM && conn && + (conn->tcpstateflags == TCP_ESTABLISHED || + conn->tcpstateflags == TCP_SYN_RCVD)) { ret = tcp_start_monitor(psock2);