+ return ustcomm_recv_fd(sock, header, data, NULL);
+}
+
+
+int ustcomm_send_fd(int sock,
+ const struct ustcomm_header *header,
+ const char *data,
+ int *fd)
+{
+ struct iovec iov[2];
+ struct msghdr msg;
+ int result;
+ struct cmsghdr *cmsg;
+ char buf[CMSG_SPACE(sizeof(int))];
+
+ memset(&msg, 0, sizeof(msg));
+
+ iov[0].iov_base = (char *)header;
+ iov[0].iov_len = sizeof(struct ustcomm_header);
+
+ msg.msg_iov = iov;
+ msg.msg_iovlen = 1;
+
+ if (header->size && data) {
+ iov[1].iov_base = (char *)data;
+ iov[1].iov_len = header->size;
+
+ msg.msg_iovlen++;
+
+ }
+
+ if (fd && header->fd_included) {
+ msg.msg_control = buf;
+ msg.msg_controllen = sizeof(buf);
+ cmsg = CMSG_FIRSTHDR(&msg);
+ cmsg->cmsg_level = SOL_SOCKET;
+ cmsg->cmsg_type = SCM_RIGHTS;
+ cmsg->cmsg_len = CMSG_LEN(sizeof(int));
+ *(int *) CMSG_DATA(cmsg) = *fd;
+ msg.msg_controllen = cmsg->cmsg_len;
+ }
+
+ result = sendmsg(sock, &msg, MSG_NOSIGNAL);
+ if (result < 0 && errno != EPIPE) {
+ PERROR("sendmsg failed");
+ }
+ return result;