summaryrefslogtreecommitdiffstats
path: root/tests/echo_srv.c
diff options
context:
space:
mode:
authorStefan Metzmacher <metze@samba.org>2020-06-19 20:52:23 +0200
committerStefan Metzmacher <metze@samba.org>2020-06-22 16:45:36 +0200
commit309103f464af19d6190f89de959c6dc41ba58c85 (patch)
treeef95618d4643c68e4d28cf38c35f67f3b5472414 /tests/echo_srv.c
parentc73d8a43c07ffbd9f4a7010b99363ffa53b4723c (diff)
test_echo_tcp_socket_options.c: add tests for TCP_INFO
Signed-off-by: Stefan Metzmacher <metze@samba.org> Reviewed-by: Andreas Schneider <asn@samba.org> (cherry picked from commit a37c0175492fb1b35257b785c71dea4e4f6d4750)
Diffstat (limited to 'tests/echo_srv.c')
-rw-r--r--tests/echo_srv.c32
1 files changed, 32 insertions, 0 deletions
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 <arpa/inet.h>
#include <netinet/in.h>
+#include <netinet/tcp.h>
+#ifdef HAVE_NETINET_TCP_FSM_H
+#include <netinet/tcp_fsm.h>
+#endif
#include <netdb.h>
#include <resolv.h>
@@ -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;