summaryrefslogtreecommitdiffstats
path: root/tests/test_echo_udp_sendto_recvfrom.c
diff options
context:
space:
mode:
authorRichard Sharpe <rsharpe@samba.org>2016-05-11 17:10:54 -0700
committerAndreas Schneider <asn@samba.org>2016-05-17 11:44:09 +0200
commite443d67914030e7f2e1126a82003e1bada5cbbac (patch)
tree6bd4502d4180306185e49e954c60d0e4bfe0fcbe /tests/test_echo_udp_sendto_recvfrom.c
parentec18c955e13ea2a294339e4c9ee977a769fbe903 (diff)
downloadsocket_wrapper-e443d67914030e7f2e1126a82003e1bada5cbbac.tar.gz
socket_wrapper-e443d67914030e7f2e1126a82003e1bada5cbbac.tar.xz
socket_wrapper-e443d67914030e7f2e1126a82003e1bada5cbbac.zip
tests: Add a udp test case for sendto() after a connect()
Here, we do the same as net ads dns gethostbyname. That is, we connect on a UDP socket and then send a sendto with a dest address (the same as the one we connected on.) and then a recvfrom etc. Signed-of-by: Richard Sharpe <rsharpe@samba.org> Reviewed-by: Andreas Schneider <asn@samba.org> Reviewed-by: Ralph Boehme <slow@samba.org>
Diffstat (limited to 'tests/test_echo_udp_sendto_recvfrom.c')
-rw-r--r--tests/test_echo_udp_sendto_recvfrom.c52
1 files changed, 52 insertions, 0 deletions
diff --git a/tests/test_echo_udp_sendto_recvfrom.c b/tests/test_echo_udp_sendto_recvfrom.c
index 79948ce..014eece 100644
--- a/tests/test_echo_udp_sendto_recvfrom.c
+++ b/tests/test_echo_udp_sendto_recvfrom.c
@@ -192,6 +192,55 @@ static void test_sendto_recvfrom_ipv6(void **state)
}
#endif
+static void test_connect_sendto_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,
+ &addr.sa.s,
+ addr.sa_socklen);
+ 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;
@@ -204,6 +253,9 @@ int main(void) {
setup_echo_srv_udp_ipv6,
teardown),
#endif
+ cmocka_unit_test_setup_teardown(test_connect_sendto_ipv4,
+ setup_echo_srv_udp_ipv4,
+ teardown),
};
rc = cmocka_run_group_tests(sendto_tests, NULL, NULL);