From a37c0175492fb1b35257b785c71dea4e4f6d4750 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Fri, 19 Jun 2020 20:52:23 +0200 Subject: test_echo_tcp_socket_options.c: add tests for TCP_INFO Signed-off-by: Stefan Metzmacher --- tests/echo_srv.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'tests/echo_srv.c') diff --git a/tests/echo_srv.c b/tests/echo_srv.c index 93778f2..87c85f7 100644 --- a/tests/echo_srv.c +++ b/tests/echo_srv.c @@ -9,6 +9,10 @@ #include #include +#include +#ifdef HAVE_NETINET_TCP_FSM_H +#include +#endif #include #include @@ -315,6 +319,34 @@ static int setup_srv(struct echo_srv_opts *opts, int *_sock) perror("listen"); return ret; } +#ifdef TCP_INFO + { + struct tcp_info info; + socklen_t optlen = sizeof(info); + + ZERO_STRUCT(info); + ret = getsockopt(sock, IPPROTO_TCP, TCP_INFO, &info, &optlen); + if (ret == -1) { + ret = errno; + perror("TCP_INFO failed"); + close(sock); + return ret; + } +#ifdef HAVE_NETINET_TCP_FSM_H +/* This is FreeBSD */ +# define __TCP_LISTEN TCPS_LISTEN +#else +/* This is Linux */ +# define __TCP_LISTEN TCP_LISTEN +#endif + if (info.tcpi_state != __TCP_LISTEN) { + errno = ret = ERANGE; + perror("not __TCP_LISTEN => ERANGE..."); + close(sock); + return ret; + } + } +#endif /* TCP_INFO */ } *_sock = sock; -- cgit