mmsg.c revision a50ec349456c79467d58ced70787a44d4c3d309c
138a34c9349267c99ce1ddbd0b6e985147415d355Dmitry V. Levin/*
238a34c9349267c99ce1ddbd0b6e985147415d355Dmitry V. Levin * Copyright (c) 2014 Masatake YAMATO <yamato@redhat.com>
34e66672923bc480d9cb7c158e39e4a67322ab2cfDmitry V. Levin * Copyright (c) 2014-2016 Dmitry V. Levin <ldv@altlinux.org>
438a34c9349267c99ce1ddbd0b6e985147415d355Dmitry V. Levin * All rights reserved.
538a34c9349267c99ce1ddbd0b6e985147415d355Dmitry V. Levin *
638a34c9349267c99ce1ddbd0b6e985147415d355Dmitry V. Levin * Redistribution and use in source and binary forms, with or without
738a34c9349267c99ce1ddbd0b6e985147415d355Dmitry V. Levin * modification, are permitted provided that the following conditions
838a34c9349267c99ce1ddbd0b6e985147415d355Dmitry V. Levin * are met:
938a34c9349267c99ce1ddbd0b6e985147415d355Dmitry V. Levin * 1. Redistributions of source code must retain the above copyright
1038a34c9349267c99ce1ddbd0b6e985147415d355Dmitry V. Levin *    notice, this list of conditions and the following disclaimer.
1138a34c9349267c99ce1ddbd0b6e985147415d355Dmitry V. Levin * 2. Redistributions in binary form must reproduce the above copyright
1238a34c9349267c99ce1ddbd0b6e985147415d355Dmitry V. Levin *    notice, this list of conditions and the following disclaimer in the
1338a34c9349267c99ce1ddbd0b6e985147415d355Dmitry V. Levin *    documentation and/or other materials provided with the distribution.
1438a34c9349267c99ce1ddbd0b6e985147415d355Dmitry V. Levin * 3. The name of the author may not be used to endorse or promote products
1538a34c9349267c99ce1ddbd0b6e985147415d355Dmitry V. Levin *    derived from this software without specific prior written permission.
1638a34c9349267c99ce1ddbd0b6e985147415d355Dmitry V. Levin *
1738a34c9349267c99ce1ddbd0b6e985147415d355Dmitry V. Levin * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
1838a34c9349267c99ce1ddbd0b6e985147415d355Dmitry V. Levin * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
1938a34c9349267c99ce1ddbd0b6e985147415d355Dmitry V. Levin * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
2038a34c9349267c99ce1ddbd0b6e985147415d355Dmitry V. Levin * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
2138a34c9349267c99ce1ddbd0b6e985147415d355Dmitry V. Levin * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
2238a34c9349267c99ce1ddbd0b6e985147415d355Dmitry V. Levin * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2338a34c9349267c99ce1ddbd0b6e985147415d355Dmitry V. Levin * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2438a34c9349267c99ce1ddbd0b6e985147415d355Dmitry V. Levin * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2538a34c9349267c99ce1ddbd0b6e985147415d355Dmitry V. Levin * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
2638a34c9349267c99ce1ddbd0b6e985147415d355Dmitry V. Levin * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2738a34c9349267c99ce1ddbd0b6e985147415d355Dmitry V. Levin */
2838a34c9349267c99ce1ddbd0b6e985147415d355Dmitry V. Levin
290c8853c3c39fe11f1a80456e744d7db861c39df2Dmitry V. Levin#include "tests.h"
306e815ce640200462cd29a106197dfc2feee7cc6aDmitry V. Levin# include <sys/syscall.h>
314e66672923bc480d9cb7c158e39e4a67322ab2cfDmitry V. Levin
32eb4649a0dc0bfaa0df336de5dc95b41612e0b42dDmitry V. Levin#if (defined __NR_sendmmsg || defined HAVE_SENDMMSG) \
33eb4649a0dc0bfaa0df336de5dc95b41612e0b42dDmitry V. Levin && (defined __NR_recvmmsg || defined HAVE_RECVMMSG)
344e66672923bc480d9cb7c158e39e4a67322ab2cfDmitry V. Levin
354e66672923bc480d9cb7c158e39e4a67322ab2cfDmitry V. Levin# include <assert.h>
364e66672923bc480d9cb7c158e39e4a67322ab2cfDmitry V. Levin# include <errno.h>
3719d10f89650554eb68050b1247c3018b263e95cbDmitry V. Levin# include <stdio.h>
384e66672923bc480d9cb7c158e39e4a67322ab2cfDmitry V. Levin# include <unistd.h>
39993198deb3a0e3311e7a062451d141c5c410406cMasatake YAMATO
404b38ce956c270a28fd0aa018f448b082371a08b1Dmitry V. Levin# include "msghdr.h"
4119d10f89650554eb68050b1247c3018b263e95cbDmitry V. Levin
426e815ce640200462cd29a106197dfc2feee7cc6aDmitry V. Levinstatic int
436e815ce640200462cd29a106197dfc2feee7cc6aDmitry V. Levinsend_mmsg(int fd, struct mmsghdr *vec, unsigned int vlen, unsigned int flags)
446e815ce640200462cd29a106197dfc2feee7cc6aDmitry V. Levin{
456e815ce640200462cd29a106197dfc2feee7cc6aDmitry V. Levin	int rc;
466e815ce640200462cd29a106197dfc2feee7cc6aDmitry V. Levin#ifdef __NR_sendmmsg
476e815ce640200462cd29a106197dfc2feee7cc6aDmitry V. Levin	rc = syscall(__NR_sendmmsg, (long) fd, vec, (unsigned long) vlen,
486e815ce640200462cd29a106197dfc2feee7cc6aDmitry V. Levin		     (unsigned long) flags);
496e815ce640200462cd29a106197dfc2feee7cc6aDmitry V. Levin	if (rc >= 0 || ENOSYS != errno)
506e815ce640200462cd29a106197dfc2feee7cc6aDmitry V. Levin		return rc;
51536a0353ddf11a6edc78c10102c046bc58221ff0Dmitry V. Levin	tprintf("sendmmsg(%d, %p, %u, MSG_DONTROUTE|MSG_NOSIGNAL)"
5219d10f89650554eb68050b1247c3018b263e95cbDmitry V. Levin		" = -1 ENOSYS (%m)\n", fd, vec, vlen);
536e815ce640200462cd29a106197dfc2feee7cc6aDmitry V. Levin#endif
546e815ce640200462cd29a106197dfc2feee7cc6aDmitry V. Levin#ifdef HAVE_SENDMMSG
556e815ce640200462cd29a106197dfc2feee7cc6aDmitry V. Levin	rc = sendmmsg(fd, vec, vlen, flags);
566e815ce640200462cd29a106197dfc2feee7cc6aDmitry V. Levin#endif
576e815ce640200462cd29a106197dfc2feee7cc6aDmitry V. Levin	return rc;
586e815ce640200462cd29a106197dfc2feee7cc6aDmitry V. Levin}
596e815ce640200462cd29a106197dfc2feee7cc6aDmitry V. Levin
606e815ce640200462cd29a106197dfc2feee7cc6aDmitry V. Levinstatic int
616e815ce640200462cd29a106197dfc2feee7cc6aDmitry V. Levinrecv_mmsg(int fd, struct mmsghdr *vec, unsigned int vlen, unsigned int flags,
626e815ce640200462cd29a106197dfc2feee7cc6aDmitry V. Levin	  struct timespec *timeout)
636e815ce640200462cd29a106197dfc2feee7cc6aDmitry V. Levin{
646e815ce640200462cd29a106197dfc2feee7cc6aDmitry V. Levin	int rc;
65eb4649a0dc0bfaa0df336de5dc95b41612e0b42dDmitry V. Levin#ifdef __NR_recvmmsg
666e815ce640200462cd29a106197dfc2feee7cc6aDmitry V. Levin	rc = syscall(__NR_recvmmsg, (long) fd, vec, (unsigned long) vlen,
676e815ce640200462cd29a106197dfc2feee7cc6aDmitry V. Levin		     (unsigned long) flags, timeout);
686e815ce640200462cd29a106197dfc2feee7cc6aDmitry V. Levin	if (rc >= 0 || ENOSYS != errno)
696e815ce640200462cd29a106197dfc2feee7cc6aDmitry V. Levin		return rc;
70536a0353ddf11a6edc78c10102c046bc58221ff0Dmitry V. Levin	tprintf("recvmmsg(%d, %p, %u, MSG_DONTWAIT, NULL)"
7119d10f89650554eb68050b1247c3018b263e95cbDmitry V. Levin		" = -1 ENOSYS (%m)\n", fd, vec, vlen);
726e815ce640200462cd29a106197dfc2feee7cc6aDmitry V. Levin#endif
73eb4649a0dc0bfaa0df336de5dc95b41612e0b42dDmitry V. Levin#ifdef HAVE_RECVMMSG
746e815ce640200462cd29a106197dfc2feee7cc6aDmitry V. Levin	rc = recvmmsg(fd, vec, vlen, flags, timeout);
756e815ce640200462cd29a106197dfc2feee7cc6aDmitry V. Levin#endif
766e815ce640200462cd29a106197dfc2feee7cc6aDmitry V. Levin	return rc;
776e815ce640200462cd29a106197dfc2feee7cc6aDmitry V. Levin}
786e815ce640200462cd29a106197dfc2feee7cc6aDmitry V. Levin
79993198deb3a0e3311e7a062451d141c5c410406cMasatake YAMATOint
80993198deb3a0e3311e7a062451d141c5c410406cMasatake YAMATOmain(void)
81993198deb3a0e3311e7a062451d141c5c410406cMasatake YAMATO{
82536a0353ddf11a6edc78c10102c046bc58221ff0Dmitry V. Levin	tprintf("%s", "");
83536a0353ddf11a6edc78c10102c046bc58221ff0Dmitry V. Levin
84d44707d889a9a69e3aaebd2535968957cbcddedbDmitry V. Levin	int fds[2];
85d44707d889a9a69e3aaebd2535968957cbcddedbDmitry V. Levin	if (socketpair(AF_UNIX, SOCK_DGRAM, 0, fds))
8635eb03fdf74b67c558b2eef11a041e99a2ae5dd9Dmitry V. Levin		perror_msg_and_skip("socketpair");
87d44707d889a9a69e3aaebd2535968957cbcddedbDmitry V. Levin	assert(0 == fds[0]);
88d44707d889a9a69e3aaebd2535968957cbcddedbDmitry V. Levin	assert(1 == fds[1]);
8935eb03fdf74b67c558b2eef11a041e99a2ae5dd9Dmitry V. Levin
90d44707d889a9a69e3aaebd2535968957cbcddedbDmitry V. Levin	static const char w0_c[] = "012";
91d44707d889a9a69e3aaebd2535968957cbcddedbDmitry V. Levin	const char *w0_d = hexdump_strdup(w0_c);
92d44707d889a9a69e3aaebd2535968957cbcddedbDmitry V. Levin	void *w0 = tail_memdup(w0_c, LENGTH_OF(w0_c));
9319d10f89650554eb68050b1247c3018b263e95cbDmitry V. Levin
94d44707d889a9a69e3aaebd2535968957cbcddedbDmitry V. Levin	static const char w1_c[] = "34567";
95d44707d889a9a69e3aaebd2535968957cbcddedbDmitry V. Levin	const char *w1_d = hexdump_strdup(w1_c);
96d44707d889a9a69e3aaebd2535968957cbcddedbDmitry V. Levin	void *w1 = tail_memdup(w1_c, LENGTH_OF(w1_c));
97993198deb3a0e3311e7a062451d141c5c410406cMasatake YAMATO
98d44707d889a9a69e3aaebd2535968957cbcddedbDmitry V. Levin	static const char w2_c[] = "89abcde";
99d44707d889a9a69e3aaebd2535968957cbcddedbDmitry V. Levin	const char *w2_d = hexdump_strdup(w2_c);
100d44707d889a9a69e3aaebd2535968957cbcddedbDmitry V. Levin	void *w2 = tail_memdup(w2_c, LENGTH_OF(w2_c));
101d44707d889a9a69e3aaebd2535968957cbcddedbDmitry V. Levin
102d44707d889a9a69e3aaebd2535968957cbcddedbDmitry V. Levin	const struct iovec w0_iov_[] = {
103993198deb3a0e3311e7a062451d141c5c410406cMasatake YAMATO		{
104d44707d889a9a69e3aaebd2535968957cbcddedbDmitry V. Levin			.iov_base = w0,
105d44707d889a9a69e3aaebd2535968957cbcddedbDmitry V. Levin			.iov_len = LENGTH_OF(w0_c)
106993198deb3a0e3311e7a062451d141c5c410406cMasatake YAMATO		}, {
107d44707d889a9a69e3aaebd2535968957cbcddedbDmitry V. Levin			.iov_base = w1,
108d44707d889a9a69e3aaebd2535968957cbcddedbDmitry V. Levin			.iov_len = LENGTH_OF(w1_c)
109993198deb3a0e3311e7a062451d141c5c410406cMasatake YAMATO		}
110993198deb3a0e3311e7a062451d141c5c410406cMasatake YAMATO	};
111d44707d889a9a69e3aaebd2535968957cbcddedbDmitry V. Levin	struct iovec *w0_iov = tail_memdup(w0_iov_, sizeof(w0_iov_));
112993198deb3a0e3311e7a062451d141c5c410406cMasatake YAMATO
113d44707d889a9a69e3aaebd2535968957cbcddedbDmitry V. Levin	const struct iovec w1_iov_[] = {
114d44707d889a9a69e3aaebd2535968957cbcddedbDmitry V. Levin		{
115d44707d889a9a69e3aaebd2535968957cbcddedbDmitry V. Levin			.iov_base = w2,
116d44707d889a9a69e3aaebd2535968957cbcddedbDmitry V. Levin			.iov_len = LENGTH_OF(w2_c)
117d44707d889a9a69e3aaebd2535968957cbcddedbDmitry V. Levin		}
118d44707d889a9a69e3aaebd2535968957cbcddedbDmitry V. Levin	};
119d44707d889a9a69e3aaebd2535968957cbcddedbDmitry V. Levin	struct iovec *w1_iov = tail_memdup(w1_iov_, sizeof(w1_iov_));
120d44707d889a9a69e3aaebd2535968957cbcddedbDmitry V. Levin
121d44707d889a9a69e3aaebd2535968957cbcddedbDmitry V. Levin	const struct mmsghdr w_mmh_[] = {
122993198deb3a0e3311e7a062451d141c5c410406cMasatake YAMATO		{
123993198deb3a0e3311e7a062451d141c5c410406cMasatake YAMATO			.msg_hdr = {
124d44707d889a9a69e3aaebd2535968957cbcddedbDmitry V. Levin				.msg_iov = w0_iov,
125d44707d889a9a69e3aaebd2535968957cbcddedbDmitry V. Levin				.msg_iovlen = ARRAY_SIZE(w0_iov_),
126993198deb3a0e3311e7a062451d141c5c410406cMasatake YAMATO			}
127993198deb3a0e3311e7a062451d141c5c410406cMasatake YAMATO		}, {
128993198deb3a0e3311e7a062451d141c5c410406cMasatake YAMATO			.msg_hdr = {
129d44707d889a9a69e3aaebd2535968957cbcddedbDmitry V. Levin				.msg_iov = w1_iov,
130d44707d889a9a69e3aaebd2535968957cbcddedbDmitry V. Levin				.msg_iovlen = ARRAY_SIZE(w1_iov_),
131993198deb3a0e3311e7a062451d141c5c410406cMasatake YAMATO			}
132993198deb3a0e3311e7a062451d141c5c410406cMasatake YAMATO		}
133993198deb3a0e3311e7a062451d141c5c410406cMasatake YAMATO	};
134d44707d889a9a69e3aaebd2535968957cbcddedbDmitry V. Levin	void *w_mmh = tail_memdup(w_mmh_, sizeof(w_mmh_));
135d44707d889a9a69e3aaebd2535968957cbcddedbDmitry V. Levin	const unsigned int n_w_mmh = ARRAY_SIZE(w_mmh_);
136993198deb3a0e3311e7a062451d141c5c410406cMasatake YAMATO
137d44707d889a9a69e3aaebd2535968957cbcddedbDmitry V. Levin	int r = send_mmsg(1, w_mmh, n_w_mmh, MSG_DONTROUTE | MSG_NOSIGNAL);
13895cbf6ebfdbf4739fb9c65d46487cb0210b539a4Dmitry V. Levin	if (r < 0 && errno == ENOSYS)
1394e66672923bc480d9cb7c158e39e4a67322ab2cfDmitry V. Levin		perror_msg_and_skip("sendmmsg");
140d44707d889a9a69e3aaebd2535968957cbcddedbDmitry V. Levin	assert(r == (int) n_w_mmh);
141d44707d889a9a69e3aaebd2535968957cbcddedbDmitry V. Levin	assert(close(1) == 0);
142a50ec349456c79467d58ced70787a44d4c3d309cDmitry V. Levin	tprintf("sendmmsg(1, [{msg_hdr={msg_name=NULL, msg_namelen=0"
14326f90afc686afcf01807e75515541085081f670bDmitry V. Levin		", msg_iov=[{\"%s\", %u}, {\"%s\", %u}], msg_iovlen=%u"
144a50ec349456c79467d58ced70787a44d4c3d309cDmitry V. Levin		", msg_controllen=0, msg_flags=0}, msg_len=%u}"
145a50ec349456c79467d58ced70787a44d4c3d309cDmitry V. Levin		", {msg_hdr={msg_name=NULL, msg_namelen=0"
14626f90afc686afcf01807e75515541085081f670bDmitry V. Levin		", msg_iov=[{\"%s\", %u}], msg_iovlen=%u"
147a50ec349456c79467d58ced70787a44d4c3d309cDmitry V. Levin		", msg_controllen=0, msg_flags=0}, msg_len=%u}], %u"
14819d10f89650554eb68050b1247c3018b263e95cbDmitry V. Levin		", MSG_DONTROUTE|MSG_NOSIGNAL) = %d\n"
14919d10f89650554eb68050b1247c3018b263e95cbDmitry V. Levin		" = %u buffers in vector 0\n"
15019d10f89650554eb68050b1247c3018b263e95cbDmitry V. Levin		" * %u bytes in buffer 0\n"
151d44707d889a9a69e3aaebd2535968957cbcddedbDmitry V. Levin		" | 00000 %-49s  %-16s |\n"
15219d10f89650554eb68050b1247c3018b263e95cbDmitry V. Levin		" * %u bytes in buffer 1\n"
153d44707d889a9a69e3aaebd2535968957cbcddedbDmitry V. Levin		" | 00000 %-49s  %-16s |\n"
15419d10f89650554eb68050b1247c3018b263e95cbDmitry V. Levin		" = %u buffers in vector 1\n"
15519d10f89650554eb68050b1247c3018b263e95cbDmitry V. Levin		" * %u bytes in buffer 0\n"
156d44707d889a9a69e3aaebd2535968957cbcddedbDmitry V. Levin		" | 00000 %-49s  %-16s |\n",
15726f90afc686afcf01807e75515541085081f670bDmitry V. Levin		w0_c, LENGTH_OF(w0_c),
158d44707d889a9a69e3aaebd2535968957cbcddedbDmitry V. Levin		w1_c, LENGTH_OF(w1_c),
15926f90afc686afcf01807e75515541085081f670bDmitry V. Levin		ARRAY_SIZE(w0_iov_),
160d44707d889a9a69e3aaebd2535968957cbcddedbDmitry V. Levin		LENGTH_OF(w0_c) + LENGTH_OF(w1_c),
16126f90afc686afcf01807e75515541085081f670bDmitry V. Levin		w2_c, LENGTH_OF(w2_c), ARRAY_SIZE(w1_iov_),
16226f90afc686afcf01807e75515541085081f670bDmitry V. Levin		LENGTH_OF(w2_c),
163d44707d889a9a69e3aaebd2535968957cbcddedbDmitry V. Levin		n_w_mmh, r,
164d44707d889a9a69e3aaebd2535968957cbcddedbDmitry V. Levin		ARRAY_SIZE(w0_iov_), LENGTH_OF(w0_c), w0_d, w0_c,
165d44707d889a9a69e3aaebd2535968957cbcddedbDmitry V. Levin		LENGTH_OF(w1_c), w1_d, w1_c,
166d44707d889a9a69e3aaebd2535968957cbcddedbDmitry V. Levin		ARRAY_SIZE(w1_iov_), LENGTH_OF(w2_c), w2_d, w2_c);
167d44707d889a9a69e3aaebd2535968957cbcddedbDmitry V. Levin
168d44707d889a9a69e3aaebd2535968957cbcddedbDmitry V. Levin	const unsigned int w_len =
169d44707d889a9a69e3aaebd2535968957cbcddedbDmitry V. Levin		LENGTH_OF(w0_c) + LENGTH_OF(w1_c) + LENGTH_OF(w2_c);
170d44707d889a9a69e3aaebd2535968957cbcddedbDmitry V. Levin	const unsigned int r_len = (w_len + 1) / 2;
171d44707d889a9a69e3aaebd2535968957cbcddedbDmitry V. Levin	void *r0 = tail_alloc(r_len);
172d44707d889a9a69e3aaebd2535968957cbcddedbDmitry V. Levin	void *r1 = tail_alloc(r_len);
173d44707d889a9a69e3aaebd2535968957cbcddedbDmitry V. Levin	void *r2 = tail_alloc(r_len);
174d44707d889a9a69e3aaebd2535968957cbcddedbDmitry V. Levin	const struct iovec r0_iov_[] = {
175d44707d889a9a69e3aaebd2535968957cbcddedbDmitry V. Levin		{
176d44707d889a9a69e3aaebd2535968957cbcddedbDmitry V. Levin			.iov_base = r0,
177d44707d889a9a69e3aaebd2535968957cbcddedbDmitry V. Levin			.iov_len = r_len
178d44707d889a9a69e3aaebd2535968957cbcddedbDmitry V. Levin		}
179d44707d889a9a69e3aaebd2535968957cbcddedbDmitry V. Levin	};
180d44707d889a9a69e3aaebd2535968957cbcddedbDmitry V. Levin	struct iovec *r0_iov = tail_memdup(r0_iov_, sizeof(r0_iov_));
181d44707d889a9a69e3aaebd2535968957cbcddedbDmitry V. Levin	const struct iovec r1_iov_[] = {
182d44707d889a9a69e3aaebd2535968957cbcddedbDmitry V. Levin		{
183d44707d889a9a69e3aaebd2535968957cbcddedbDmitry V. Levin			.iov_base = r1,
184d44707d889a9a69e3aaebd2535968957cbcddedbDmitry V. Levin			.iov_len = r_len
185d44707d889a9a69e3aaebd2535968957cbcddedbDmitry V. Levin		},
186d44707d889a9a69e3aaebd2535968957cbcddedbDmitry V. Levin		{
187d44707d889a9a69e3aaebd2535968957cbcddedbDmitry V. Levin			.iov_base = r2,
188d44707d889a9a69e3aaebd2535968957cbcddedbDmitry V. Levin			.iov_len = r_len
189d44707d889a9a69e3aaebd2535968957cbcddedbDmitry V. Levin		}
190d44707d889a9a69e3aaebd2535968957cbcddedbDmitry V. Levin	};
191d44707d889a9a69e3aaebd2535968957cbcddedbDmitry V. Levin	struct iovec *r1_iov = tail_memdup(r1_iov_, sizeof(r1_iov_));
192d44707d889a9a69e3aaebd2535968957cbcddedbDmitry V. Levin
193d44707d889a9a69e3aaebd2535968957cbcddedbDmitry V. Levin	const struct mmsghdr r_mmh_[] = {
194d44707d889a9a69e3aaebd2535968957cbcddedbDmitry V. Levin		{
195d44707d889a9a69e3aaebd2535968957cbcddedbDmitry V. Levin			.msg_hdr = {
196d44707d889a9a69e3aaebd2535968957cbcddedbDmitry V. Levin				.msg_iov = r0_iov,
197d44707d889a9a69e3aaebd2535968957cbcddedbDmitry V. Levin				.msg_iovlen = ARRAY_SIZE(r0_iov_),
198d44707d889a9a69e3aaebd2535968957cbcddedbDmitry V. Levin			}
199d44707d889a9a69e3aaebd2535968957cbcddedbDmitry V. Levin		}, {
200d44707d889a9a69e3aaebd2535968957cbcddedbDmitry V. Levin			.msg_hdr = {
201d44707d889a9a69e3aaebd2535968957cbcddedbDmitry V. Levin				.msg_iov = r1_iov,
202d44707d889a9a69e3aaebd2535968957cbcddedbDmitry V. Levin				.msg_iovlen = ARRAY_SIZE(r1_iov_),
203d44707d889a9a69e3aaebd2535968957cbcddedbDmitry V. Levin			}
204d44707d889a9a69e3aaebd2535968957cbcddedbDmitry V. Levin		}
205d44707d889a9a69e3aaebd2535968957cbcddedbDmitry V. Levin	};
206d44707d889a9a69e3aaebd2535968957cbcddedbDmitry V. Levin	void *r_mmh = tail_memdup(r_mmh_, sizeof(r_mmh_));
207d44707d889a9a69e3aaebd2535968957cbcddedbDmitry V. Levin	const unsigned int n_r_mmh = ARRAY_SIZE(r_mmh_);
208d44707d889a9a69e3aaebd2535968957cbcddedbDmitry V. Levin
209d44707d889a9a69e3aaebd2535968957cbcddedbDmitry V. Levin	static const char r0_c[] = "01234567";
210d44707d889a9a69e3aaebd2535968957cbcddedbDmitry V. Levin	const char *r0_d = hexdump_strdup(r0_c);
211d44707d889a9a69e3aaebd2535968957cbcddedbDmitry V. Levin	static const char r1_c[] = "89abcde";
212d44707d889a9a69e3aaebd2535968957cbcddedbDmitry V. Levin	const char *r1_d = hexdump_strdup(r1_c);
213d44707d889a9a69e3aaebd2535968957cbcddedbDmitry V. Levin
214d44707d889a9a69e3aaebd2535968957cbcddedbDmitry V. Levin	assert(recv_mmsg(0, r_mmh, n_r_mmh, MSG_DONTWAIT, NULL) == (int) n_r_mmh);
215d44707d889a9a69e3aaebd2535968957cbcddedbDmitry V. Levin	assert(close(0) == 0);
216a50ec349456c79467d58ced70787a44d4c3d309cDmitry V. Levin	tprintf("recvmmsg(0, [{msg_hdr={msg_name=NULL, msg_namelen=0"
21726f90afc686afcf01807e75515541085081f670bDmitry V. Levin		", msg_iov=[{\"%s\", %u}], msg_iovlen=%u"
218a50ec349456c79467d58ced70787a44d4c3d309cDmitry V. Levin		", msg_controllen=0, msg_flags=0}, msg_len=%u}"
219a50ec349456c79467d58ced70787a44d4c3d309cDmitry V. Levin		", {msg_hdr={msg_name=NULL, msg_namelen=0"
22026f90afc686afcf01807e75515541085081f670bDmitry V. Levin		", msg_iov=[{\"%s\", %u}, {\"\", %u}], msg_iovlen=%u"
221a50ec349456c79467d58ced70787a44d4c3d309cDmitry V. Levin		", msg_controllen=0, msg_flags=0}, msg_len=%u}], %u"
22219d10f89650554eb68050b1247c3018b263e95cbDmitry V. Levin		", MSG_DONTWAIT, NULL) = %d (left NULL)\n"
22319d10f89650554eb68050b1247c3018b263e95cbDmitry V. Levin		" = %u buffers in vector 0\n"
22419d10f89650554eb68050b1247c3018b263e95cbDmitry V. Levin		" * %u bytes in buffer 0\n"
225d44707d889a9a69e3aaebd2535968957cbcddedbDmitry V. Levin		" | 00000 %-49s  %-16s |\n"
22619d10f89650554eb68050b1247c3018b263e95cbDmitry V. Levin		" = %u buffers in vector 1\n"
22719d10f89650554eb68050b1247c3018b263e95cbDmitry V. Levin		" * %u bytes in buffer 0\n"
228d44707d889a9a69e3aaebd2535968957cbcddedbDmitry V. Levin		" | 00000 %-49s  %-16s |\n",
22926f90afc686afcf01807e75515541085081f670bDmitry V. Levin		r0_c, r_len, ARRAY_SIZE(r0_iov_), LENGTH_OF(r0_c),
23026f90afc686afcf01807e75515541085081f670bDmitry V. Levin		r1_c, r_len, r_len, ARRAY_SIZE(r1_iov_), LENGTH_OF(r1_c),
231d44707d889a9a69e3aaebd2535968957cbcddedbDmitry V. Levin		n_r_mmh, r,
232d44707d889a9a69e3aaebd2535968957cbcddedbDmitry V. Levin		ARRAY_SIZE(r0_iov_), LENGTH_OF(r0_c), r0_d, r0_c,
233d44707d889a9a69e3aaebd2535968957cbcddedbDmitry V. Levin		ARRAY_SIZE(r1_iov_), LENGTH_OF(r1_c), r1_d, r1_c);
23419d10f89650554eb68050b1247c3018b263e95cbDmitry V. Levin
235536a0353ddf11a6edc78c10102c046bc58221ff0Dmitry V. Levin	tprintf("+++ exited with 0 +++\n");
236993198deb3a0e3311e7a062451d141c5c410406cMasatake YAMATO	return 0;
2374e66672923bc480d9cb7c158e39e4a67322ab2cfDmitry V. Levin}
2384e66672923bc480d9cb7c158e39e4a67322ab2cfDmitry V. Levin
239993198deb3a0e3311e7a062451d141c5c410406cMasatake YAMATO#else
2404e66672923bc480d9cb7c158e39e4a67322ab2cfDmitry V. Levin
241eb4649a0dc0bfaa0df336de5dc95b41612e0b42dDmitry V. LevinSKIP_MAIN_UNDEFINED("(__NR_sendmmsg || HAVE_SENDMMSG) && (__NR_recvmmsg || HAVE_RECVMMSG)")
2424e66672923bc480d9cb7c158e39e4a67322ab2cfDmitry V. Levin
243993198deb3a0e3311e7a062451d141c5c410406cMasatake YAMATO#endif
244