1*94d3b452SApple OSS Distributions /*
2*94d3b452SApple OSS Distributions * Copyright (c) 2020-2022 Apple Inc. All rights reserved.
3*94d3b452SApple OSS Distributions *
4*94d3b452SApple OSS Distributions * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5*94d3b452SApple OSS Distributions *
6*94d3b452SApple OSS Distributions * This file contains Original Code and/or Modifications of Original Code
7*94d3b452SApple OSS Distributions * as defined in and that are subject to the Apple Public Source License
8*94d3b452SApple OSS Distributions * Version 2.0 (the 'License'). You may not use this file except in
9*94d3b452SApple OSS Distributions * compliance with the License. The rights granted to you under the License
10*94d3b452SApple OSS Distributions * may not be used to create, or enable the creation or redistribution of,
11*94d3b452SApple OSS Distributions * unlawful or unlicensed copies of an Apple operating system, or to
12*94d3b452SApple OSS Distributions * circumvent, violate, or enable the circumvention or violation of, any
13*94d3b452SApple OSS Distributions * terms of an Apple operating system software license agreement.
14*94d3b452SApple OSS Distributions *
15*94d3b452SApple OSS Distributions * Please obtain a copy of the License at
16*94d3b452SApple OSS Distributions * http://www.opensource.apple.com/apsl/ and read it before using this file.
17*94d3b452SApple OSS Distributions *
18*94d3b452SApple OSS Distributions * The Original Code and all software distributed under the License are
19*94d3b452SApple OSS Distributions * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20*94d3b452SApple OSS Distributions * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21*94d3b452SApple OSS Distributions * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22*94d3b452SApple OSS Distributions * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23*94d3b452SApple OSS Distributions * Please see the License for the specific language governing rights and
24*94d3b452SApple OSS Distributions * limitations under the License.
25*94d3b452SApple OSS Distributions *
26*94d3b452SApple OSS Distributions * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27*94d3b452SApple OSS Distributions */
28*94d3b452SApple OSS Distributions
29*94d3b452SApple OSS Distributions /* -*- compile-command: "xcrun --sdk macosx.internal make -C tests recvmsg_x_test" -*- */
30*94d3b452SApple OSS Distributions
31*94d3b452SApple OSS Distributions
32*94d3b452SApple OSS Distributions #define __APPLE_USE_RFC_3542 1
33*94d3b452SApple OSS Distributions
34*94d3b452SApple OSS Distributions #include <sys/errno.h>
35*94d3b452SApple OSS Distributions #include <sys/fcntl.h>
36*94d3b452SApple OSS Distributions #include <sys/socket.h>
37*94d3b452SApple OSS Distributions #include <netinet/in.h>
38*94d3b452SApple OSS Distributions #include <stdbool.h>
39*94d3b452SApple OSS Distributions #include <err.h>
40*94d3b452SApple OSS Distributions #include <stdio.h>
41*94d3b452SApple OSS Distributions #include <stdlib.h>
42*94d3b452SApple OSS Distributions #include <string.h>
43*94d3b452SApple OSS Distributions #include <sysexits.h>
44*94d3b452SApple OSS Distributions #include <unistd.h>
45*94d3b452SApple OSS Distributions
46*94d3b452SApple OSS Distributions #include <arpa/inet.h>
47*94d3b452SApple OSS Distributions
48*94d3b452SApple OSS Distributions #include <darwintest.h>
49*94d3b452SApple OSS Distributions #include <darwintest_utils.h>
50*94d3b452SApple OSS Distributions
51*94d3b452SApple OSS Distributions #define NMSGS 10
52*94d3b452SApple OSS Distributions #define BUFFERLEN 1000
53*94d3b452SApple OSS Distributions
54*94d3b452SApple OSS Distributions T_GLOBAL_META(T_META_NAMESPACE("xnu.net"));
55*94d3b452SApple OSS Distributions
56*94d3b452SApple OSS Distributions static void
send_packets(int sendSocket,u_int packetCount,struct sockaddr * to,int proto)57*94d3b452SApple OSS Distributions send_packets(int sendSocket, u_int packetCount, struct sockaddr *to, int proto)
58*94d3b452SApple OSS Distributions {
59*94d3b452SApple OSS Distributions u_int nmsgs = NMSGS;
60*94d3b452SApple OSS Distributions ssize_t sentMsgsCount = 0;
61*94d3b452SApple OSS Distributions struct msghdr_x msgList[NMSGS];
62*94d3b452SApple OSS Distributions
63*94d3b452SApple OSS Distributions struct msghdr_x *msg;
64*94d3b452SApple OSS Distributions struct iovec iovarray[NMSGS];
65*94d3b452SApple OSS Distributions char bytes[nmsgs][100];
66*94d3b452SApple OSS Distributions const socklen_t cmsg_size = (socklen_t)CMSG_SPACE(sizeof(int));
67*94d3b452SApple OSS Distributions char cmsgbuf[NMSGS][cmsg_size];
68*94d3b452SApple OSS Distributions
69*94d3b452SApple OSS Distributions bzero(msgList, sizeof(msgList));
70*94d3b452SApple OSS Distributions bzero(cmsgbuf, sizeof(cmsgbuf));
71*94d3b452SApple OSS Distributions
72*94d3b452SApple OSS Distributions for (int i = 0; i < NMSGS; i++) {
73*94d3b452SApple OSS Distributions msg = &msgList[i];
74*94d3b452SApple OSS Distributions
75*94d3b452SApple OSS Distributions int dscp = (i % 64) << 2;
76*94d3b452SApple OSS Distributions struct cmsghdr *cm;
77*94d3b452SApple OSS Distributions
78*94d3b452SApple OSS Distributions cm = (struct cmsghdr *)(void *)&cmsgbuf[i][0];
79*94d3b452SApple OSS Distributions if (proto == IPPROTO_IP) {
80*94d3b452SApple OSS Distributions cm->cmsg_len = CMSG_LEN(sizeof(int));
81*94d3b452SApple OSS Distributions cm->cmsg_level = IPPROTO_IP;
82*94d3b452SApple OSS Distributions cm->cmsg_type = IP_TOS;
83*94d3b452SApple OSS Distributions *(int *)(void *)CMSG_DATA(cm) = dscp;
84*94d3b452SApple OSS Distributions msg->msg_control = cmsgbuf[i];
85*94d3b452SApple OSS Distributions msg->msg_controllen = CMSG_SPACE(sizeof(int));
86*94d3b452SApple OSS Distributions } else if (proto == IPPROTO_IPV6) {
87*94d3b452SApple OSS Distributions cm->cmsg_len = CMSG_LEN(sizeof(sizeof(int)));
88*94d3b452SApple OSS Distributions cm->cmsg_level = IPPROTO_IPV6;
89*94d3b452SApple OSS Distributions cm->cmsg_type = IPV6_TCLASS;
90*94d3b452SApple OSS Distributions *(int *)(void *)CMSG_DATA(cm) = dscp;
91*94d3b452SApple OSS Distributions msg->msg_control = cmsgbuf[i];
92*94d3b452SApple OSS Distributions msg->msg_controllen = CMSG_SPACE(sizeof(int));
93*94d3b452SApple OSS Distributions }
94*94d3b452SApple OSS Distributions
95*94d3b452SApple OSS Distributions msg->msg_name = (void *)to;
96*94d3b452SApple OSS Distributions msg->msg_namelen = to->sa_len;
97*94d3b452SApple OSS Distributions msg->msg_iov = &iovarray[i];
98*94d3b452SApple OSS Distributions msg->msg_iovlen = 1;
99*94d3b452SApple OSS Distributions iovarray[i].iov_base = &bytes[i];
100*94d3b452SApple OSS Distributions iovarray[i].iov_len = 100;
101*94d3b452SApple OSS Distributions msg->msg_flags = 0;
102*94d3b452SApple OSS Distributions }
103*94d3b452SApple OSS Distributions
104*94d3b452SApple OSS Distributions while (1) {
105*94d3b452SApple OSS Distributions if (packetCount < nmsgs) {
106*94d3b452SApple OSS Distributions nmsgs = packetCount;
107*94d3b452SApple OSS Distributions }
108*94d3b452SApple OSS Distributions T_EXPECT_POSIX_SUCCESS(sentMsgsCount = sendmsg_x(sendSocket, msgList, nmsgs, 0), "sendmsg_x()");
109*94d3b452SApple OSS Distributions if (sentMsgsCount < 0) {
110*94d3b452SApple OSS Distributions break;
111*94d3b452SApple OSS Distributions } else {
112*94d3b452SApple OSS Distributions packetCount -= sentMsgsCount;
113*94d3b452SApple OSS Distributions }
114*94d3b452SApple OSS Distributions if (packetCount == 0) {
115*94d3b452SApple OSS Distributions break;
116*94d3b452SApple OSS Distributions }
117*94d3b452SApple OSS Distributions }
118*94d3b452SApple OSS Distributions }
119*94d3b452SApple OSS Distributions
120*94d3b452SApple OSS Distributions static bool
receive_packets(int recvSocket)121*94d3b452SApple OSS Distributions receive_packets(int recvSocket)
122*94d3b452SApple OSS Distributions {
123*94d3b452SApple OSS Distributions uint8_t maxPacketsToRead = NMSGS;
124*94d3b452SApple OSS Distributions int i;
125*94d3b452SApple OSS Distributions struct msghdr_x msglist[NMSGS];
126*94d3b452SApple OSS Distributions char bytes[NMSGS][100];
127*94d3b452SApple OSS Distributions struct iovec vec[NMSGS];
128*94d3b452SApple OSS Distributions const socklen_t cmsg_size = (socklen_t)MAX(CMSG_SPACE(sizeof(struct in_pktinfo)), CMSG_SPACE(sizeof(struct in6_pktinfo))) + CMSG_SPACE(sizeof(int));
129*94d3b452SApple OSS Distributions char cmsgbuf[NMSGS][cmsg_size];
130*94d3b452SApple OSS Distributions struct sockaddr_storage remoteAddress[NMSGS];
131*94d3b452SApple OSS Distributions bool success = true;
132*94d3b452SApple OSS Distributions
133*94d3b452SApple OSS Distributions bzero(msglist, sizeof(msglist));
134*94d3b452SApple OSS Distributions bzero(vec, sizeof(vec));
135*94d3b452SApple OSS Distributions bzero(cmsgbuf, sizeof(cmsgbuf));
136*94d3b452SApple OSS Distributions
137*94d3b452SApple OSS Distributions
138*94d3b452SApple OSS Distributions ssize_t total_received = 0;
139*94d3b452SApple OSS Distributions while (1) {
140*94d3b452SApple OSS Distributions ssize_t npkts;
141*94d3b452SApple OSS Distributions
142*94d3b452SApple OSS Distributions for (i = 0; i < maxPacketsToRead; i++) {
143*94d3b452SApple OSS Distributions struct msghdr_x *msg = &msglist[i];
144*94d3b452SApple OSS Distributions vec[i].iov_base = &bytes[i];
145*94d3b452SApple OSS Distributions vec[i].iov_len = 100;
146*94d3b452SApple OSS Distributions
147*94d3b452SApple OSS Distributions msg->msg_name = &remoteAddress[i];
148*94d3b452SApple OSS Distributions msg->msg_namelen = sizeof(struct sockaddr_storage);
149*94d3b452SApple OSS Distributions msg->msg_iov = &vec[i];
150*94d3b452SApple OSS Distributions msg->msg_iovlen = 1;
151*94d3b452SApple OSS Distributions msg->msg_control = cmsgbuf[i];
152*94d3b452SApple OSS Distributions msg->msg_controllen = cmsg_size;
153*94d3b452SApple OSS Distributions }
154*94d3b452SApple OSS Distributions
155*94d3b452SApple OSS Distributions npkts = recvmsg_x(recvSocket, msglist, maxPacketsToRead, 0);
156*94d3b452SApple OSS Distributions if (npkts < 0) {
157*94d3b452SApple OSS Distributions if (errno == EINTR || errno == EWOULDBLOCK) {
158*94d3b452SApple OSS Distributions continue;
159*94d3b452SApple OSS Distributions }
160*94d3b452SApple OSS Distributions T_EXPECT_POSIX_SUCCESS(npkts, "recvmsg_x() npkts %ld total_received %ld", npkts, total_received);
161*94d3b452SApple OSS Distributions break;
162*94d3b452SApple OSS Distributions }
163*94d3b452SApple OSS Distributions total_received += npkts;
164*94d3b452SApple OSS Distributions
165*94d3b452SApple OSS Distributions for (i = 0; i < npkts; i++) {
166*94d3b452SApple OSS Distributions struct msghdr_x *msg = &msglist[i];
167*94d3b452SApple OSS Distributions
168*94d3b452SApple OSS Distributions if ((msg->msg_controllen < (socklen_t)sizeof(struct cmsghdr)) || (msg->msg_flags & MSG_CTRUNC)) {
169*94d3b452SApple OSS Distributions success = false;
170*94d3b452SApple OSS Distributions T_LOG("msg[%d] bad control message len=%d (< %u?) msg_flags 0x%x socket %d",
171*94d3b452SApple OSS Distributions i, msg->msg_controllen, cmsg_size, msg->msg_flags, recvSocket);
172*94d3b452SApple OSS Distributions } else {
173*94d3b452SApple OSS Distributions T_LOG("msg[%d] good control message len=%d (< %u?) msg_flags 0x%x socket %d",
174*94d3b452SApple OSS Distributions i, msg->msg_controllen, cmsg_size, msg->msg_flags, recvSocket);
175*94d3b452SApple OSS Distributions }
176*94d3b452SApple OSS Distributions for (struct cmsghdr *cm = (struct cmsghdr *)CMSG_FIRSTHDR(msg);
177*94d3b452SApple OSS Distributions cm != NULL;
178*94d3b452SApple OSS Distributions cm = (struct cmsghdr *)CMSG_NXTHDR(msg, cm)) {
179*94d3b452SApple OSS Distributions T_LOG(" cmsg_level %u cmsg_type %u cmsg_len %u",
180*94d3b452SApple OSS Distributions cm->cmsg_level, cm->cmsg_type, cm->cmsg_len);
181*94d3b452SApple OSS Distributions
182*94d3b452SApple OSS Distributions if (cm->cmsg_level == IPPROTO_IP &&
183*94d3b452SApple OSS Distributions cm->cmsg_type == IP_RECVTOS &&
184*94d3b452SApple OSS Distributions cm->cmsg_len == CMSG_LEN(sizeof(u_char))) {
185*94d3b452SApple OSS Distributions u_char ip_tos = *(u_char *)(void *)CMSG_DATA(cm);
186*94d3b452SApple OSS Distributions
187*94d3b452SApple OSS Distributions T_LOG(" ip_tos 0x%x", ip_tos);
188*94d3b452SApple OSS Distributions } else if (cm->cmsg_level == IPPROTO_IPV6 &&
189*94d3b452SApple OSS Distributions cm->cmsg_type == IPV6_TCLASS &&
190*94d3b452SApple OSS Distributions cm->cmsg_len == CMSG_LEN(sizeof(int))) {
191*94d3b452SApple OSS Distributions int ipv6_tclass = *(int *)(void *)CMSG_DATA(cm);
192*94d3b452SApple OSS Distributions
193*94d3b452SApple OSS Distributions T_LOG(" ipv6_tclass 0x%x", ipv6_tclass);
194*94d3b452SApple OSS Distributions } else if (cm->cmsg_level == IPPROTO_IPV6 &&
195*94d3b452SApple OSS Distributions cm->cmsg_type == IPV6_PKTINFO &&
196*94d3b452SApple OSS Distributions cm->cmsg_len == CMSG_LEN(sizeof(struct in6_pktinfo))) {
197*94d3b452SApple OSS Distributions struct in6_pktinfo *pktinfo = (struct in6_pktinfo *)(void *)CMSG_DATA(cm);
198*94d3b452SApple OSS Distributions char addr[40];
199*94d3b452SApple OSS Distributions
200*94d3b452SApple OSS Distributions T_LOG(" pktinfo addr %s ifindex %u",
201*94d3b452SApple OSS Distributions inet_ntop(AF_INET6, &pktinfo->ipi6_addr, addr, sizeof(addr)), pktinfo->ipi6_ifindex);
202*94d3b452SApple OSS Distributions } else if (cm->cmsg_level == IPPROTO_IP &&
203*94d3b452SApple OSS Distributions cm->cmsg_type == IP_PKTINFO &&
204*94d3b452SApple OSS Distributions cm->cmsg_len == CMSG_LEN(sizeof(struct in_pktinfo))) {
205*94d3b452SApple OSS Distributions struct in_pktinfo *pktinfo = (struct in_pktinfo *)(void *)CMSG_DATA(cm);
206*94d3b452SApple OSS Distributions char spec_dst[20];
207*94d3b452SApple OSS Distributions char addr[20];
208*94d3b452SApple OSS Distributions
209*94d3b452SApple OSS Distributions inet_ntop(AF_INET, &pktinfo->ipi_spec_dst, spec_dst, sizeof(spec_dst));
210*94d3b452SApple OSS Distributions inet_ntop(AF_INET, &pktinfo->ipi_addr, addr, sizeof(addr));
211*94d3b452SApple OSS Distributions
212*94d3b452SApple OSS Distributions T_LOG(" pktinfo ifindex %u spec_dest %s addr %s",
213*94d3b452SApple OSS Distributions pktinfo->ipi_ifindex, spec_dst, addr);
214*94d3b452SApple OSS Distributions }
215*94d3b452SApple OSS Distributions }
216*94d3b452SApple OSS Distributions }
217*94d3b452SApple OSS Distributions
218*94d3b452SApple OSS Distributions if (total_received >= maxPacketsToRead) {
219*94d3b452SApple OSS Distributions // Since we received max number of packets in the last loop, it is not clear if there
220*94d3b452SApple OSS Distributions // are any more left in the socket buffer. So we need to try again
221*94d3b452SApple OSS Distributions break;
222*94d3b452SApple OSS Distributions }
223*94d3b452SApple OSS Distributions }
224*94d3b452SApple OSS Distributions return success;
225*94d3b452SApple OSS Distributions }
226*94d3b452SApple OSS Distributions
227*94d3b452SApple OSS Distributions T_DECL(recvmsg_x_ipv4_udp, "revcmsg_x() ipv4")
228*94d3b452SApple OSS Distributions {
229*94d3b452SApple OSS Distributions struct sockaddr_in addr = {
230*94d3b452SApple OSS Distributions .sin_len = sizeof(addr),
231*94d3b452SApple OSS Distributions .sin_family = AF_INET,
232*94d3b452SApple OSS Distributions .sin_addr.s_addr = htonl(0x7f000001),
233*94d3b452SApple OSS Distributions .sin_port = 0
234*94d3b452SApple OSS Distributions };
235*94d3b452SApple OSS Distributions
236*94d3b452SApple OSS Distributions int recvSocket;
237*94d3b452SApple OSS Distributions T_QUIET; T_EXPECT_POSIX_SUCCESS(recvSocket = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP), "socket()");
238*94d3b452SApple OSS Distributions T_QUIET; T_EXPECT_POSIX_SUCCESS(bind(recvSocket, (const struct sockaddr *)&addr, sizeof(addr)), "bind()");
239*94d3b452SApple OSS Distributions
240*94d3b452SApple OSS Distributions socklen_t addrLen = sizeof(addr);
241*94d3b452SApple OSS Distributions T_QUIET; T_EXPECT_POSIX_SUCCESS(getsockname(recvSocket, (struct sockaddr *)&addr, &addrLen), "getsockname()");
242*94d3b452SApple OSS Distributions
243*94d3b452SApple OSS Distributions int one = 1;
244*94d3b452SApple OSS Distributions T_QUIET; T_EXPECT_POSIX_SUCCESS(setsockopt(recvSocket, IPPROTO_IP, IP_RECVPKTINFO, (void *)&one, sizeof(one)), "setsockopt(IP_RECVPKTINFO)");
245*94d3b452SApple OSS Distributions
246*94d3b452SApple OSS Distributions T_QUIET; T_EXPECT_POSIX_SUCCESS(setsockopt(recvSocket, IPPROTO_IP, IP_RECVTOS, (void *)&one, sizeof(one)), "setsockopt(IP_RECVTOS)");
247*94d3b452SApple OSS Distributions
248*94d3b452SApple OSS Distributions int flags = fcntl(recvSocket, F_GETFL, 0);
249*94d3b452SApple OSS Distributions T_QUIET; T_EXPECT_POSIX_SUCCESS(fcntl(recvSocket, F_SETFL, flags | O_NONBLOCK), "fcntl()");
250*94d3b452SApple OSS Distributions
251*94d3b452SApple OSS Distributions int sendSocket;
252*94d3b452SApple OSS Distributions T_QUIET; T_EXPECT_POSIX_SUCCESS(sendSocket = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP), "sendSocket socket()");
253*94d3b452SApple OSS Distributions
254*94d3b452SApple OSS Distributions send_packets(sendSocket, 10, (struct sockaddr *)&addr, IPPROTO_IP);
255*94d3b452SApple OSS Distributions
256*94d3b452SApple OSS Distributions bool result;
257*94d3b452SApple OSS Distributions T_EXPECT_EQ(result = receive_packets(recvSocket), true, "receive_packets");
258*94d3b452SApple OSS Distributions
259*94d3b452SApple OSS Distributions close(sendSocket);
260*94d3b452SApple OSS Distributions close(recvSocket);
261*94d3b452SApple OSS Distributions }
262*94d3b452SApple OSS Distributions
263*94d3b452SApple OSS Distributions T_DECL(recvmsg_x_ipv6_udp, "exercise revcmsg_x() ")
264*94d3b452SApple OSS Distributions {
265*94d3b452SApple OSS Distributions struct sockaddr_in6 addr = {
266*94d3b452SApple OSS Distributions .sin6_len = sizeof(addr),
267*94d3b452SApple OSS Distributions .sin6_family = AF_INET6,
268*94d3b452SApple OSS Distributions .sin6_addr = IN6ADDR_LOOPBACK_INIT,
269*94d3b452SApple OSS Distributions .sin6_flowinfo = 0,
270*94d3b452SApple OSS Distributions .sin6_scope_id = 0,
271*94d3b452SApple OSS Distributions .sin6_port = 0
272*94d3b452SApple OSS Distributions };
273*94d3b452SApple OSS Distributions
274*94d3b452SApple OSS Distributions int recvSocket;
275*94d3b452SApple OSS Distributions T_QUIET; T_EXPECT_POSIX_SUCCESS(recvSocket = socket(AF_INET6, SOCK_DGRAM, IPPROTO_UDP), "socket()");
276*94d3b452SApple OSS Distributions T_QUIET; T_EXPECT_POSIX_SUCCESS(bind(recvSocket, (const struct sockaddr *)&addr, sizeof(addr)), "bind()");
277*94d3b452SApple OSS Distributions
278*94d3b452SApple OSS Distributions socklen_t addrLen = sizeof(addr);
279*94d3b452SApple OSS Distributions T_QUIET; T_EXPECT_POSIX_SUCCESS(getsockname(recvSocket, (struct sockaddr *)&addr, &addrLen), "getsockname()");
280*94d3b452SApple OSS Distributions
281*94d3b452SApple OSS Distributions int one = 1;
282*94d3b452SApple OSS Distributions T_QUIET; T_EXPECT_POSIX_SUCCESS(setsockopt(recvSocket, IPPROTO_IPV6, IPV6_RECVPKTINFO, (void *)&one, sizeof(one)), "setsockopt(IPV6_RECVPKTINFO)");
283*94d3b452SApple OSS Distributions
284*94d3b452SApple OSS Distributions T_QUIET; T_EXPECT_POSIX_SUCCESS(setsockopt(recvSocket, IPPROTO_IPV6, IPV6_RECVTCLASS, (void *)&one, sizeof(one)), "setsockopt(IPV6_RECVTCLASS)");
285*94d3b452SApple OSS Distributions
286*94d3b452SApple OSS Distributions int flags = fcntl(recvSocket, F_GETFL, 0);
287*94d3b452SApple OSS Distributions T_QUIET; T_EXPECT_POSIX_SUCCESS(fcntl(recvSocket, F_SETFL, flags | O_NONBLOCK), "fcntl()");
288*94d3b452SApple OSS Distributions
289*94d3b452SApple OSS Distributions int sendSocket;
290*94d3b452SApple OSS Distributions T_QUIET; T_EXPECT_POSIX_SUCCESS(sendSocket = socket(AF_INET6, SOCK_DGRAM, IPPROTO_UDP), "sendSocket socket()");
291*94d3b452SApple OSS Distributions
292*94d3b452SApple OSS Distributions send_packets(sendSocket, 10, (struct sockaddr *)&addr, IPPROTO_IPV6);
293*94d3b452SApple OSS Distributions
294*94d3b452SApple OSS Distributions bool result;
295*94d3b452SApple OSS Distributions T_EXPECT_EQ(result = receive_packets(recvSocket), true, "receive_packets");
296*94d3b452SApple OSS Distributions
297*94d3b452SApple OSS Distributions close(sendSocket);
298*94d3b452SApple OSS Distributions close(recvSocket);
299*94d3b452SApple OSS Distributions }
300