diff options
author | Andreas Schneider <asn@samba.org> | 2014-05-28 09:46:40 +0200 |
---|---|---|
committer | Michael Adam <obnox@samba.org> | 2014-05-31 12:32:35 +0200 |
commit | 00258577e86f4b6c15d504954ee6233086638a3e (patch) | |
tree | bdfddcea507cf7fbad5fea407b4eb35599d1606b /tests/test_echo_tcp_bind.c | |
parent | ccf4e64fe7bf788c17ca1a41e456e3b9ecdcb85b (diff) | |
download | socket_wrapper-00258577e86f4b6c15d504954ee6233086638a3e.tar.gz socket_wrapper-00258577e86f4b6c15d504954ee6233086638a3e.tar.xz socket_wrapper-00258577e86f4b6c15d504954ee6233086638a3e.zip |
tests: Add tests for bindresvport().
Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
Diffstat (limited to 'tests/test_echo_tcp_bind.c')
-rw-r--r-- | tests/test_echo_tcp_bind.c | 113 |
1 files changed, 113 insertions, 0 deletions
diff --git a/tests/test_echo_tcp_bind.c b/tests/test_echo_tcp_bind.c index 6f811dc..b3f2656 100644 --- a/tests/test_echo_tcp_bind.c +++ b/tests/test_echo_tcp_bind.c @@ -63,6 +63,66 @@ static void test_bind_ipv4(void **state) close(s); } +static void test_bindresvport_ipv4(void **state) +{ + struct sockaddr_in sin; + socklen_t slen = sizeof(struct sockaddr_in); + int rc; + int s; + + (void) state; /* unused */ + + s = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); + assert_return_code(s, errno); + + ZERO_STRUCT(sin); + sin.sin_family = AF_INET; + + rc = inet_pton(AF_INET, "127.0.0.20", &sin.sin_addr); + assert_int_equal(rc, 1); + + rc = bindresvport(s, &sin); + assert_return_code(rc, errno); + + ZERO_STRUCT(sin); + sin.sin_family = AF_INET; + sin.sin_port = htons(torture_server_port()); + rc = inet_pton(AF_INET, torture_server_address(AF_INET), &sin.sin_addr); + assert_int_equal(rc, 1); + + rc = connect(s, (struct sockaddr *)&sin, slen); + assert_return_code(rc, errno); + + close(s); +} + +static void test_bindresvport_ipv4_null(void **state) +{ + struct sockaddr_in sin; + socklen_t slen = sizeof(struct sockaddr_in); + int rc; + int s; + + (void) state; /* unused */ + + s = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); + assert_return_code(s, errno); + + rc = bindresvport(s, NULL); + assert_return_code(rc, errno); + + ZERO_STRUCT(sin); + sin.sin_family = AF_INET; + sin.sin_port = htons(torture_server_port()); + rc = inet_pton(AF_INET, torture_server_address(AF_INET), &sin.sin_addr); + assert_int_equal(rc, 1); + + rc = connect(s, (struct sockaddr *)&sin, slen); + assert_return_code(rc, errno); + + close(s); +} + #ifdef HAVE_IPV6 static void test_bind_on_ipv6_sock(void **state) { @@ -88,6 +148,47 @@ static void test_bind_on_ipv6_sock(void **state) close(s); } + +static void test_bindresvport_on_ipv6_sock(void **state) +{ + struct sockaddr_in sin; + int rc; + int s; + + (void) state; /* unused */ + + s = socket(AF_INET6, SOCK_STREAM, IPPROTO_TCP); + assert_return_code(s, errno); + + ZERO_STRUCT(sin); + sin.sin_family = AF_INET; + + rc = inet_pton(AF_INET, "127.0.0.20", &sin.sin_addr); + assert_int_equal(rc, 1); + + rc = bindresvport(s, &sin); + assert_int_equal(rc, -1); + assert_int_equal(errno, EINVAL); + + close(s); +} + +static void test_bindresvport_on_ipv6_sock_null(void **state) +{ + int rc; + int s; + + (void) state; /* unused */ + + s = socket(AF_INET6, SOCK_STREAM, IPPROTO_TCP); + assert_return_code(s, errno); + + rc = bindresvport(s, NULL); + assert_return_code(rc, errno); + + close(s); +} + #endif /* HAVE_IPV6 */ int main(void) { @@ -97,10 +198,22 @@ int main(void) { unit_test_setup_teardown(test_bind_ipv4, setup_echo_srv_tcp_ipv4, teardown), + unit_test_setup_teardown(test_bindresvport_ipv4, + setup_echo_srv_tcp_ipv4, + teardown), + unit_test_setup_teardown(test_bindresvport_ipv4_null, + setup_echo_srv_tcp_ipv4, + teardown), #ifdef HAVE_IPV6 unit_test_setup_teardown(test_bind_on_ipv6_sock, setup_echo_srv_tcp_ipv6, teardown), + unit_test_setup_teardown(test_bindresvport_on_ipv6_sock, + setup_echo_srv_tcp_ipv6, + teardown), + unit_test_setup_teardown(test_bindresvport_on_ipv6_sock_null, + setup_echo_srv_tcp_ipv6, + teardown), #endif /* HAVE_IPV6 */ }; |