xref: /xnu-12377.81.4/tests/v4mappedv6_join_group.c (revision 043036a2b3718f7f0be807e2870f8f47d3fa0796)
1*043036a2SApple OSS Distributions /*
2*043036a2SApple OSS Distributions  * Copyright (c) 2024 Apple Inc. All rights reserved.
3*043036a2SApple OSS Distributions  *
4*043036a2SApple OSS Distributions  * Chris Jarrett-Davies <[email protected]>
5*043036a2SApple OSS Distributions  * SEAR Red Team / 2024-Mar-20
6*043036a2SApple OSS Distributions  */
7*043036a2SApple OSS Distributions 
8*043036a2SApple OSS Distributions #include <darwintest.h>
9*043036a2SApple OSS Distributions #include <stdio.h>
10*043036a2SApple OSS Distributions 
11*043036a2SApple OSS Distributions #include <darwintest.h>
12*043036a2SApple OSS Distributions 
13*043036a2SApple OSS Distributions #include <string.h>
14*043036a2SApple OSS Distributions #include <strings.h>
15*043036a2SApple OSS Distributions 
16*043036a2SApple OSS Distributions #include <arpa/inet.h>
17*043036a2SApple OSS Distributions #include <netinet/in.h>
18*043036a2SApple OSS Distributions #include <sys/socket.h>
19*043036a2SApple OSS Distributions #include <unistd.h>
20*043036a2SApple OSS Distributions 
21*043036a2SApple OSS Distributions T_GLOBAL_META(
22*043036a2SApple OSS Distributions 	T_META_NAMESPACE("xnu.net"),
23*043036a2SApple OSS Distributions 	T_META_ASROOT(true),
24*043036a2SApple OSS Distributions 	T_META_RADAR_COMPONENT_NAME("xnu"),
25*043036a2SApple OSS Distributions 	T_META_RADAR_COMPONENT_VERSION("networking"),
26*043036a2SApple OSS Distributions 	T_META_ENABLED(!TARGET_OS_BRIDGE),
27*043036a2SApple OSS Distributions 	T_META_CHECK_LEAKS(false));
28*043036a2SApple OSS Distributions 
29*043036a2SApple OSS Distributions T_DECL(v4mappedv6_join_group, "Tests setting IPV6_JOIN_GROUP on an IPv4-mapped IPv6 address")
30*043036a2SApple OSS Distributions {
31*043036a2SApple OSS Distributions 	int s;
32*043036a2SApple OSS Distributions 	struct sockaddr_in6 sin6 = {
33*043036a2SApple OSS Distributions 		.sin6_family = AF_INET6,
34*043036a2SApple OSS Distributions 		.sin6_len = sizeof(struct sockaddr_in6),
35*043036a2SApple OSS Distributions 		.sin6_port = 1337
36*043036a2SApple OSS Distributions 	};
37*043036a2SApple OSS Distributions 	struct ipv6_mreq mreq = {};
38*043036a2SApple OSS Distributions 
39*043036a2SApple OSS Distributions 	T_ASSERT_POSIX_SUCCESS(s = socket(AF_INET6, SOCK_DGRAM, IPPROTO_UDP), "create socket");
40*043036a2SApple OSS Distributions 
41*043036a2SApple OSS Distributions 	T_ASSERT_POSIX_SUCCESS(inet_pton(AF_INET6, "::ffff:127.0.0.1", &sin6.sin6_addr), "inet_pton");
42*043036a2SApple OSS Distributions 	T_ASSERT_POSIX_SUCCESS(connect(s, (const struct sockaddr *)&sin6, sizeof(sin6)), "connect");
43*043036a2SApple OSS Distributions 
44*043036a2SApple OSS Distributions 	memset((unsigned char *)&mreq.ipv6mr_multiaddr, 0xff, 16);
45*043036a2SApple OSS Distributions 
46*043036a2SApple OSS Distributions 	// This should now fail (but not panic)
47*043036a2SApple OSS Distributions 	T_ASSERT_POSIX_FAILURE(setsockopt(s, IPPROTO_IPV6, IPV6_JOIN_GROUP, &mreq, sizeof(mreq)), EADDRNOTAVAIL, "setsockopt IPV6_JOIN_GROUP");
48*043036a2SApple OSS Distributions }
49