summaryrefslogtreecommitdiffstats
path: root/tests/test_echo_tcp_socket_options.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/test_echo_tcp_socket_options.c
parentc73d8a43c07ffbd9f4a7010b99363ffa53b4723c (diff)
downloadsocket_wrapper-309103f464af19d6190f89de959c6dc41ba58c85.tar.gz
socket_wrapper-309103f464af19d6190f89de959c6dc41ba58c85.tar.xz
socket_wrapper-309103f464af19d6190f89de959c6dc41ba58c85.zip
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/test_echo_tcp_socket_options.c')
-rw-r--r--tests/test_echo_tcp_socket_options.c50
1 files changed, 50 insertions, 0 deletions
diff --git a/tests/test_echo_tcp_socket_options.c b/tests/test_echo_tcp_socket_options.c
index dfa46fe..5e5661d 100644
--- a/tests/test_echo_tcp_socket_options.c
+++ b/tests/test_echo_tcp_socket_options.c
@@ -11,12 +11,25 @@
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
+#ifdef HAVE_NETINET_TCP_FSM_H
+#include <netinet/tcp_fsm.h>
+#endif
#include <arpa/inet.h>
#include <netdb.h>
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
+#ifdef HAVE_NETINET_TCP_FSM_H
+/* This is FreeBSD */
+# define __TCP_ESTABLISHED TCPS_ESTABLISHED
+# define __TCP_CLOSE TCPS_CLOSED
+#else
+/* This is Linux */
+# define __TCP_ESTABLISHED TCP_ESTABLISHED
+# define __TCP_CLOSE TCP_CLOSE
+#endif
+
#ifndef ZERO_STRUCT
#define ZERO_STRUCT(x) memset((char *)&(x), 0, sizeof(x))
#endif
@@ -300,6 +313,9 @@ static void test_sockopt_tcp(void **state)
.sa_socklen = sizeof(struct sockaddr_in),
};
int opt = -1;
+#ifdef TCP_INFO
+ struct tcp_info info;
+#endif
socklen_t optlen = sizeof(int);
int rc;
@@ -318,9 +334,27 @@ static void test_sockopt_tcp(void **state)
&addr.sa.in.sin_addr);
assert_int_equal(rc, 1);
+#ifdef TCP_INFO
+ ZERO_STRUCT(info);
+ optlen = sizeof(info);
+ rc = getsockopt(s, IPPROTO_TCP, TCP_INFO, &info, &optlen);
+ assert_return_code(rc, errno);
+ assert_int_equal(optlen, sizeof(info));
+ printf("info.tcpi_state=0x%x\n", info.tcpi_state);
+ printf("info.tcpi_rto=%u\n", info.tcpi_rto);
+ printf("info.tcpi_rtt=%u\n", info.tcpi_rtt);
+ printf("info.tcpi_rttvar=%u\n", info.tcpi_rttvar);
+ assert_int_equal(info.tcpi_state, __TCP_CLOSE);
+ assert_int_not_equal(info.tcpi_rto, 0);
+ assert_int_equal(info.tcpi_rtt, 0);
+ assert_int_not_equal(info.tcpi_rttvar, 0);
+#endif /* TCP_INFO */
+
rc = connect(s, &addr.sa.s, addr.sa_socklen);
assert_int_equal(rc, 0);
+ opt = -1;
+ optlen = sizeof(int);
rc = getsockopt(s, IPPROTO_TCP, TCP_NODELAY, &opt, &optlen);
assert_return_code(rc, errno);
assert_int_equal(opt, 0);
@@ -336,6 +370,22 @@ static void test_sockopt_tcp(void **state)
assert_return_code(rc, errno);
assert_int_equal(opt, 1);
+#ifdef TCP_INFO
+ ZERO_STRUCT(info);
+ optlen = sizeof(info);
+ rc = getsockopt(s, IPPROTO_TCP, TCP_INFO, &info, &optlen);
+ assert_return_code(rc, errno);
+ assert_int_equal(optlen, sizeof(info));
+ printf("info.tcpi_state=0x%x\n", info.tcpi_state);
+ printf("info.tcpi_rto=%u\n", info.tcpi_rto);
+ printf("info.tcpi_rtt=%u\n", info.tcpi_rtt);
+ printf("info.tcpi_rttvar=%u\n", info.tcpi_rttvar);
+ assert_int_equal(info.tcpi_state, __TCP_ESTABLISHED);
+ assert_int_not_equal(info.tcpi_rto, 0);
+ assert_int_not_equal(info.tcpi_rtt, 0);
+ assert_int_not_equal(info.tcpi_rttvar, 0);
+#endif /* TCP_INFO */
+
close(s);
}