diff options
author | Laurent Bercot <ska-skaware@skarnet.org> | 2017-04-23 00:00:10 +0000 |
---|---|---|
committer | Laurent Bercot <ska-skaware@skarnet.org> | 2017-04-23 00:00:10 +0000 |
commit | b2eac2dedd62224df07148a9e42eae0197902c00 (patch) | |
tree | 7f78a7260c9b26f386da7cf177cc8a9034bade36 /src/sysdeps | |
parent | e48c16f37bac55820c605f82c07f04436a55f415 (diff) | |
download | skalibs-b2eac2dedd62224df07148a9e42eae0197902c00.tar.xz |
Align ancillary buffers on struct cmsghdr and int boundaries
Diffstat (limited to 'src/sysdeps')
-rw-r--r-- | src/sysdeps/output-types.c | 2 | ||||
-rw-r--r-- | src/sysdeps/tryancilautoclose.c | 14 |
2 files changed, 12 insertions, 4 deletions
diff --git a/src/sysdeps/output-types.c b/src/sysdeps/output-types.c index 09995d2..22e6093 100644 --- a/src/sysdeps/output-types.c +++ b/src/sysdeps/output-types.c @@ -1,3 +1,5 @@ +/* ISC license. */ + #include <sys/types.h> #include <stdio.h> diff --git a/src/sysdeps/tryancilautoclose.c b/src/sysdeps/tryancilautoclose.c index c7f461f..1da87bc 100644 --- a/src/sysdeps/tryancilautoclose.c +++ b/src/sysdeps/tryancilautoclose.c @@ -17,9 +17,15 @@ #include <sys/socket.h> #include <sys/uio.h> +union aligner_u +{ + struct cmsghdr cmsghdr ; + int i ; +} ; + static int ancil_send_fd (int sock, int fd) { - char ancilbuf[CMSG_SPACE(sizeof(int))] ; + union aligner_u ancilbuf[1 + CMSG_SPACE(sizeof(int)) / sizeof(union aligner_u)] ; char s[8] = "blahblah" ; struct iovec v = { .iov_base = s, .iov_len = 8 } ; struct msghdr msghdr = @@ -30,7 +36,7 @@ static int ancil_send_fd (int sock, int fd) .msg_iovlen = 1, .msg_flags = 0, .msg_control = ancilbuf, - .msg_controllen = sizeof(ancilbuf) + .msg_controllen = CMSG_SPACE(sizeof(int)) } ; struct cmsghdr *cmsg = CMSG_FIRSTHDR(&msghdr) ; cmsg->cmsg_len = CMSG_LEN(sizeof(int)) ; @@ -43,7 +49,7 @@ static int ancil_send_fd (int sock, int fd) static int ancil_recv_fd (int sock) { - char ancilbuf[CMSG_SPACE(sizeof(int))] ; + union aligner_u ancilbuf[1 + CMSG_SPACE(sizeof(int)) / sizeof(union aligner_u)] ; char s[8] ; struct iovec v = { .iov_base = s, .iov_len = 8 } ; struct msghdr msghdr = @@ -54,7 +60,7 @@ static int ancil_recv_fd (int sock) .msg_iovlen = 1, .msg_flags = 0, .msg_control = ancilbuf, - .msg_controllen = sizeof(ancilbuf) + .msg_controllen = CMSG_SPACE(sizeof(int)) } ; struct cmsghdr *cmsg = CMSG_FIRSTHDR(&msghdr) ; cmsg->cmsg_len = msghdr.msg_controllen ; |