sendmmsg(2) System Calls Manual sendmmsg(2) sendmmsg - LIBRARY Standard C library (libc, -lc) #define _GNU_SOURCE /* feature_test_macros(7) */ #include int sendmmsg(int sockfd, struct mmsghdr *msgvec, unsigned int vlen, int flags); sendmmsg() sendmsg(2), , ( ). sockfd . msgvec mmsghdr. vlen. mmsghdr : struct mmsghdr { struct msghdr msg_hdr; /* */ unsigned int msg_len; /* - */ }; msg_hdr msghdr, sendmsg(2). msg_len , msg_hdr (. ., , sendmsg(2)). flags OR . , sendmsg(2). sendmmsg() , vlen . ( vlen) . sendmmsg(), msg_len msgvec , msg_hdr. msgvec, . sendmmsg() , msgvec; vlen, sendmmsg() . -1, errno . sendmsg(2). , . . Linux. Linux 3.0, glibc 2.14. , vlen, UIO_MAXIOV (1024). , . . , , , . sendmmsg() onetwo three UDP . . #define _GNU_SOURCE #include #include #include #include #include #include #include int main(void) { int retval; int sockfd; struct iovec msg1[2], msg2; struct mmsghdr msg[2]; struct sockaddr_in addr; sockfd = socket(AF_INET, SOCK_DGRAM, 0); if (sockfd == -1) { perror("socket()"); exit(EXIT_FAILURE); } addr.sin_family = AF_INET; addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK); addr.sin_port = htons(1234); if (connect(sockfd, (struct sockaddr *) &addr, sizeof(addr)) == -1) { perror("connect()"); exit(EXIT_FAILURE); } memset(msg1, 0, sizeof(msg1)); msg1[0].iov_base = "one"; msg1[0].iov_len = 3; msg1[1].iov_base = "two"; msg1[1].iov_len = 3; memset(&msg2, 0, sizeof(msg2)); msg2.iov_base = "three"; msg2.iov_len = 5; memset(msg, 0, sizeof(msg)); msg[0].msg_hdr.msg_iov = msg1; msg[0].msg_hdr.msg_iovlen = 2; msg[1].msg_hdr.msg_iov = &msg2; msg[1].msg_hdr.msg_iovlen = 1; retval = sendmmsg(sockfd, msg, 2, 0); if (retval == -1) perror("sendmmsg()"); else printf("%d messages sent\n", retval); exit(0); } recvmmsg(2), sendmsg(2), socket(2), socket(7) Alexander Golubev , Azamat Hackimov , Hotellook, Nikita , Spiros Georgaras , Vladislav , Yuri Kozlov ; GNU (GNU General Public License - GPL, 3 ) , - . - , , <>. Linux man-pages 6.8 2 2024 . sendmmsg(2)