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