1*43a90889SApple OSS Distributions #include <darwintest.h>
2*43a90889SApple OSS Distributions #include <poll.h>
3*43a90889SApple OSS Distributions #include <sys/socket.h>
4*43a90889SApple OSS Distributions #include <unistd.h>
5*43a90889SApple OSS Distributions #include <netinet/in.h>
6*43a90889SApple OSS Distributions #include <arpa/inet.h>
7*43a90889SApple OSS Distributions #include <errno.h>
8*43a90889SApple OSS Distributions
9*43a90889SApple OSS Distributions static int
sockv6_open(void)10*43a90889SApple OSS Distributions sockv6_open(void)
11*43a90889SApple OSS Distributions {
12*43a90889SApple OSS Distributions int s;
13*43a90889SApple OSS Distributions
14*43a90889SApple OSS Distributions s = socket(AF_INET6, SOCK_DGRAM, 0);
15*43a90889SApple OSS Distributions T_QUIET;
16*43a90889SApple OSS Distributions T_ASSERT_POSIX_SUCCESS(s, "socket(AF_INET6, SOCK_DGRAM, 0)");
17*43a90889SApple OSS Distributions return s;
18*43a90889SApple OSS Distributions }
19*43a90889SApple OSS Distributions
20*43a90889SApple OSS Distributions T_DECL(v4_mapped_v6_ops,
21*43a90889SApple OSS Distributions "v4 mapped v6 sock operations around bind/connect",
22*43a90889SApple OSS Distributions T_META_ASROOT(false),
23*43a90889SApple OSS Distributions T_META_CHECK_LEAKS(false))
24*43a90889SApple OSS Distributions {
25*43a90889SApple OSS Distributions int s6 = -1;
26*43a90889SApple OSS Distributions int ret = 0;
27*43a90889SApple OSS Distributions uint16_t port = 12345;
28*43a90889SApple OSS Distributions struct sockaddr_in6 local = {};
29*43a90889SApple OSS Distributions struct sockaddr_in6 remote = {};
30*43a90889SApple OSS Distributions
31*43a90889SApple OSS Distributions s6 = sockv6_open();
32*43a90889SApple OSS Distributions
33*43a90889SApple OSS Distributions local.sin6_family = AF_INET;
34*43a90889SApple OSS Distributions local.sin6_len = sizeof(local);
35*43a90889SApple OSS Distributions local.sin6_port = htons(port);
36*43a90889SApple OSS Distributions
37*43a90889SApple OSS Distributions T_ASSERT_EQ(inet_pton(AF_INET6, "::ffff:c000:201", &local.sin6_addr), 1, NULL);
38*43a90889SApple OSS Distributions T_EXPECT_POSIX_FAILURE((ret = bind(s6, (const struct sockaddr *)&local, sizeof(local))), EADDRNOTAVAIL, NULL);
39*43a90889SApple OSS Distributions
40*43a90889SApple OSS Distributions remote.sin6_family = AF_INET6;
41*43a90889SApple OSS Distributions remote.sin6_len = sizeof(remote);
42*43a90889SApple OSS Distributions remote.sin6_port = htons(port);
43*43a90889SApple OSS Distributions
44*43a90889SApple OSS Distributions T_ASSERT_EQ(inet_pton(AF_INET6, "::", &remote.sin6_addr), 1, NULL);
45*43a90889SApple OSS Distributions T_EXPECT_POSIX_SUCCESS(connect(s6, (struct sockaddr *)&remote, sizeof(remote)), NULL);
46*43a90889SApple OSS Distributions T_PASS("System didn't panic!");
47*43a90889SApple OSS Distributions }
48