From bfa5009d3a8c694c94d5fa97b8dff7f070b74253 Mon Sep 17 00:00:00 2001 From: otto Date: Mon, 3 Apr 2017 19:40:43 +0000 Subject: [PATCH] Send and receive 1 byte of data in addition to the control message. This is needed to make the code work in more cases. Sending actually is not really needed, but do it anyway, to avoid confusing mismatch between producer and consumer. Problem noted by Luke Small; ok deraadt@ --- share/man/man3/CMSG_DATA.3 | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/share/man/man3/CMSG_DATA.3 b/share/man/man3/CMSG_DATA.3 index 1beb705b425..309be7ff810 100644 --- a/share/man/man3/CMSG_DATA.3 +++ b/share/man/man3/CMSG_DATA.3 @@ -1,7 +1,7 @@ -.\" $OpenBSD: CMSG_DATA.3,v 1.5 2008/03/24 16:11:07 deraadt Exp $ +.\" $OpenBSD: CMSG_DATA.3,v 1.6 2017/04/03 19:40:43 otto Exp $ .\" Written by Jared Yanovich .\" Public domain, July 3, 2005 -.Dd $Mdocdate: March 24 2008 $ +.Dd $Mdocdate: April 3 2017 $ .Dt CMSG_DATA 3 .Os .Sh NAME @@ -95,10 +95,16 @@ union { struct cmsghdr hdr; unsigned char buf[CMSG_SPACE(sizeof(int))]; } cmsgbuf; +struct iovec io_vector[1]; + +io_vector[0].iov_base = &ch; +io_vector[0].iov_len = 1; memset(&msg, 0, sizeof(msg)); msg.msg_control = &cmsgbuf.buf; msg.msg_controllen = sizeof(cmsgbuf.buf); +msg.msg_iov = io_vector; +msg.msg_iovlen = 1; cmsg = CMSG_FIRSTHDR(&msg); cmsg->cmsg_len = CMSG_LEN(sizeof(int)); @@ -118,10 +124,16 @@ union { struct cmsghdr hdr; unsigned char buf[CMSG_SPACE(sizeof(int))]; } cmsgbuf; +struct iovec io_vector[1]; + +io_vector[0].iov_base = &ch; +io_vector[0].iov_len = 1; memset(&msg, 0, sizeof(msg)); msg.msg_control = &cmsgbuf.buf; msg.msg_controllen = sizeof(cmsgbuf.buf); +msg.msg_iov = io_vector; +msg.msg_iovlen = 1; if (recvmsg(s, &msg, 0) == -1) err(1, "recvmsg"); -- 2.20.1