-static clib_error_t *
-memif_msg_send (int fd, memif_msg_t * msg, int afd)
-{
- struct msghdr mh = { 0 };
- struct iovec iov[1];
- char ctl[CMSG_SPACE (sizeof (int))];
- int rv;
-
- iov[0].iov_base = (void *) msg;
- iov[0].iov_len = sizeof (memif_msg_t);
- mh.msg_iov = iov;
- mh.msg_iovlen = 1;
-
- if (afd > 0)
- {
- struct cmsghdr *cmsg;
- memset (&ctl, 0, sizeof (ctl));
- mh.msg_control = ctl;
- mh.msg_controllen = sizeof (ctl);
- cmsg = CMSG_FIRSTHDR (&mh);
- cmsg->cmsg_len = CMSG_LEN (sizeof (int));
- cmsg->cmsg_level = SOL_SOCKET;
- cmsg->cmsg_type = SCM_RIGHTS;
- memcpy (CMSG_DATA (cmsg), &afd, sizeof (int));
- }
- rv = sendmsg (fd, &mh, 0);
- if (rv < 0)
- return clib_error_return_unix (0, "sendmsg");
- DBG ("Message type %u sent (fd %d)", msg->type, afd);
- return 0;
-}
-