-
Notifications
You must be signed in to change notification settings - Fork 8
Open
Description
Have a look at the union here: http://man7.org/linux/man-pages/man3/cmsg.3.html
struct msghdr msg = {0};
struct cmsghdr *cmsg;
int myfds[NUM_FD]; /* Contains the file descriptors to pass. */
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;
int *fdptr;
msg.msg_control = u.buf;
msg.msg_controllen = sizeof u.buf;
cmsg = CMSG_FIRSTHDR(&msg);
cmsg->cmsg_level = SOL_SOCKET;
cmsg->cmsg_type = SCM_RIGHTS;
cmsg->cmsg_len = CMSG_LEN(sizeof(int) * NUM_FD);
/* Initialize the payload: */
fdptr = (int *) CMSG_DATA(cmsg);
memcpy(fdptr, myfds, NUM_FD * sizeof(int));
On clang, the current code fails with an alignment warning for me.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels