aboutsummaryrefslogtreecommitdiffstats
path: root/man3/cmsg.3
diff options
context:
space:
mode:
authorSukadev Bhattiprolu <sukadev@linux.vnet.ibm.com>2017-07-19 22:47:14 -0400
committerMichael Kerrisk <mtk.manpages@gmail.com>2017-08-16 02:29:29 +0200
commitcf699fb57e4c480f736a752b50d1e9fd40d809ef (patch)
tree17482908069f9df407a80802796ad49956128ece /man3/cmsg.3
parentd8026103cbe52ac8104a49ced041520c2bd42f27 (diff)
downloadman-pages-cf699fb57e4c480f736a752b50d1e9fd40d809ef.tar.gz
cmsg.3: Add a scatter/gather buffer to sample code
Add a simple scatter/gather buffer to the cmsg sample code. It appears that the scatter/gather buffer is required even though it may not be used. In my testing (on Fedora 24 4.8.7-200.fc24.x86_64 as well as a 4.11 based kernel) return value of sendmsg() was the number of bytes in the scatter/gather buffer (1 with the patch below). Without the iovec buffer, sendmsg() returns 0 which means no bytes were transferred and the corresponding recvmsg() blocks indefinitely. Signed-off-by: Sukadev Bhattiprolu <sukadev@linux.vnet.ibm.com> Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
Diffstat (limited to 'man3/cmsg.3')
-rw-r--r--man3/cmsg.37
1 files changed, 7 insertions, 0 deletions
diff --git a/man3/cmsg.3 b/man3/cmsg.3
index a537a0c69b..060b96fd8c 100644
--- a/man3/cmsg.3
+++ b/man3/cmsg.3
@@ -200,12 +200,19 @@ struct msghdr msg = { 0 };
struct cmsghdr *cmsg;
int myfds[NUM_FD]; /* Contains the file descriptors to pass */
int *fdptr;
+char iobuf[1];
+struct iovec io = {
+ .iov_base = iobuf,
+ .iov_len = sizeof(iobuf)
+};
union { /* Ancillary data buffer, wrapped in a union
in order to ensure it is suitably aligned */
char buf[CMSG_SPACE(sizeof(myfds))];
struct cmsghdr align;
} u;
+msg.msg_iov = &io;
+msg.msg_iovlen = 1;
msg.msg_control = u.buf;
msg.msg_controllen = sizeof(u.buf);
cmsg = CMSG_FIRSTHDR(&msg);