Fix alignment of the cmsg buffer by placing it in a union with a struct
cmsghdr. Derived from upstream patch. Submitted by: cognet MFC after: 2 weeks
This commit is contained in:
parent
979b646f30
commit
882ff9f579
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=180989
@ -49,7 +49,10 @@ mm_send_fd(int sock, int fd)
|
|||||||
char ch = '\0';
|
char ch = '\0';
|
||||||
ssize_t n;
|
ssize_t n;
|
||||||
#ifndef HAVE_ACCRIGHTS_IN_MSGHDR
|
#ifndef HAVE_ACCRIGHTS_IN_MSGHDR
|
||||||
char tmp[CMSG_SPACE(sizeof(int))];
|
union {
|
||||||
|
struct cmsghdr hdr;
|
||||||
|
char buf[CMSG_SPACE(sizeof(int))];
|
||||||
|
} cmsgbuf;
|
||||||
struct cmsghdr *cmsg;
|
struct cmsghdr *cmsg;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -58,8 +61,8 @@ mm_send_fd(int sock, int fd)
|
|||||||
msg.msg_accrights = (caddr_t)&fd;
|
msg.msg_accrights = (caddr_t)&fd;
|
||||||
msg.msg_accrightslen = sizeof(fd);
|
msg.msg_accrightslen = sizeof(fd);
|
||||||
#else
|
#else
|
||||||
msg.msg_control = (caddr_t)tmp;
|
msg.msg_control = (caddr_t)&cmsgbuf.buf;
|
||||||
msg.msg_controllen = CMSG_LEN(sizeof(int));
|
msg.msg_controllen = sizeof(cmsgbuf.buf);
|
||||||
cmsg = CMSG_FIRSTHDR(&msg);
|
cmsg = CMSG_FIRSTHDR(&msg);
|
||||||
cmsg->cmsg_len = CMSG_LEN(sizeof(int));
|
cmsg->cmsg_len = CMSG_LEN(sizeof(int));
|
||||||
cmsg->cmsg_level = SOL_SOCKET;
|
cmsg->cmsg_level = SOL_SOCKET;
|
||||||
@ -94,7 +97,10 @@ mm_receive_fd(int sock)
|
|||||||
char ch;
|
char ch;
|
||||||
int fd;
|
int fd;
|
||||||
#ifndef HAVE_ACCRIGHTS_IN_MSGHDR
|
#ifndef HAVE_ACCRIGHTS_IN_MSGHDR
|
||||||
char tmp[CMSG_SPACE(sizeof(int))];
|
union {
|
||||||
|
struct cmsghdr hdr;
|
||||||
|
char buf[CMSG_SPACE(sizeof(int))];
|
||||||
|
} cmsgbuf;
|
||||||
struct cmsghdr *cmsg;
|
struct cmsghdr *cmsg;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -107,8 +113,8 @@ mm_receive_fd(int sock)
|
|||||||
msg.msg_accrights = (caddr_t)&fd;
|
msg.msg_accrights = (caddr_t)&fd;
|
||||||
msg.msg_accrightslen = sizeof(fd);
|
msg.msg_accrightslen = sizeof(fd);
|
||||||
#else
|
#else
|
||||||
msg.msg_control = tmp;
|
msg.msg_control = &cmsgbuf.buf;
|
||||||
msg.msg_controllen = sizeof(tmp);
|
msg.msg_controllen = sizeof(cmsgbuf.buf);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if ((n = recvmsg(sock, &msg, 0)) == -1)
|
if ((n = recvmsg(sock, &msg, 0)) == -1)
|
||||||
|
Loading…
Reference in New Issue
Block a user