Commit 0c5a43a8 authored by Andreas Schneider's avatar Andreas Schneider

tests: Add test_connect_sendto_null_ipv4() test

Signed-off-by: default avatarAndreas Schneider <asn@samba.org>
Reviewed-by: default avatarRalph Boehme <slow@samba.org>
parent e443d679
......@@ -241,6 +241,55 @@ static void test_connect_sendto_ipv4(void **state)
close(s);
}
static void test_connect_sendto_null_ipv4(void **state)
{
struct torture_address addr = {
.sa_socklen = sizeof(struct sockaddr_in),
};
char send_buf[] = "packet.0";
char recv_buf[64] = {0};
ssize_t ret;
int rc;
int s;
(void) state; /* unused */
addr.sa.in.sin_family = AF_INET;
addr.sa.in.sin_port = htons(torture_server_port());
rc = inet_pton(AF_INET,
torture_server_address(AF_INET),
&addr.sa.in.sin_addr);
assert_int_equal(rc, 1);
s = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
assert_int_not_equal(s, -1);
/* Now, connect */
rc = connect(s, &addr.sa.s, addr.sa_socklen);
assert_return_code(rc, errno);
ret = sendto(s,
send_buf,
sizeof(send_buf),
0,
NULL,
0);
assert_return_code(ret, errno);
ret = recvfrom(s,
recv_buf,
sizeof(recv_buf),
0,
NULL,
0);
assert_return_code(ret, errno);
assert_memory_equal(send_buf, recv_buf, sizeof(send_buf));
close(s);
}
int main(void) {
int rc;
......@@ -256,6 +305,9 @@ int main(void) {
cmocka_unit_test_setup_teardown(test_connect_sendto_ipv4,
setup_echo_srv_udp_ipv4,
teardown),
cmocka_unit_test_setup_teardown(test_connect_sendto_null_ipv4,
setup_echo_srv_udp_ipv4,
teardown),
};
rc = cmocka_run_group_tests(sendto_tests, NULL, NULL);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment