2 __RCSID("$NetBSD: t_udp.c,v 1.2 2013/01/06 02:22:50 christos Exp $");
4 #include <sys/socket.h>
5 #include <netinet/in.h>
14 static const char msg[] = "sendto test";
19 struct addrinfo hints;
24 /* lookup localhost addr, depending on argv[1] */
25 memset(&hints, 0, sizeof(hints));
26 hints.ai_family = family;
27 hints.ai_socktype = SOCK_DGRAM;
28 hints.ai_protocol = IPPROTO_UDP;
31 e = getaddrinfo("localhost", "9999", &hints, &res);
32 ATF_REQUIRE_MSG(e == 0, "getaddrinfo AF=%d: %s", family,
36 S = socket(res->ai_family, res->ai_socktype, res->ai_protocol);
37 ATF_REQUIRE_MSG(S >= 0, "server-socket AF=%d: %s", family,
40 e = bind(S, res->ai_addr, res->ai_addrlen);
41 ATF_REQUIRE_MSG(e == 0, "bind AF=%d: %s", family,
45 s = socket(res->ai_family, res->ai_socktype, res->ai_protocol);
46 ATF_REQUIRE_MSG(s >= 0, "client-socket AF=%d: %s", family,
50 e = sendto(s, msg, sizeof(msg), 0, res->ai_addr, res->ai_addrlen);
51 ATF_REQUIRE_MSG(e == sizeof(msg), "sendto(1) AF=%d: %s", family,
54 e = sendto(s, msg, sizeof(msg), 0, res->ai_addr, res->ai_addrlen);
55 ATF_REQUIRE_MSG(e == sizeof(msg), "sendto(2) AF=%d: %s", family,
59 e = connect(s, res->ai_addr, res->ai_addrlen);
60 ATF_REQUIRE_MSG(e == 0, "connect(1) AF=%d: %s", family,
63 e = send(s, msg, sizeof(msg), 0);
64 ATF_REQUIRE_MSG(e == sizeof(msg), "send(1) AF=%d: %s", family,
67 e = connect(s, res->ai_addr, res->ai_addrlen);
68 ATF_REQUIRE_MSG(e == 0, "connect(2) AF=%d: %s", family,
71 e = send(s, msg, sizeof(msg), 0);
72 ATF_REQUIRE_MSG(e == sizeof(msg), "send(2) AF=%d: %s", family,
79 ATF_TC_HEAD(udp4_send, tc)
82 atf_tc_set_md_var(tc, "descr", "Check that inet4 udp send works both"
83 " for connected and unconnected sockets");
86 ATF_TC_BODY(udp4_send, tc)
92 ATF_TC_HEAD(udp6_send, tc)
95 atf_tc_set_md_var(tc, "descr", "Check that inet6 udp send works both"
96 " for connected and unconnected sockets");
99 ATF_TC_BODY(udp6_send, tc)
107 ATF_TP_ADD_TC(tp, udp4_send);
108 ATF_TP_ADD_TC(tp, udp6_send);
109 return atf_no_error();