lib: Add msghdr_prep_recv_fds
authorVolker Lendecke <vl@samba.org>
Wed, 31 Dec 2014 13:18:59 +0000 (14:18 +0100)
committerJeremy Allison <jra@samba.org>
Mon, 5 Jan 2015 23:33:10 +0000 (00:33 +0100)
This will prepare a msghdr for receiving fd's. Same pattern as before: First
get the buffer size, then fill in msghdr.

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
source3/lib/msghdr.c
source3/lib/msghdr.h

index 3449579b4389243c66cc141e656a127baac055ea..9ed14449cfef8e1677e918337d622a798e3b6714 100644 (file)
@@ -126,6 +126,26 @@ struct msghdr *msghdr_buf_msghdr(struct msghdr_buf *msg)
        return &msg->msg;
 }
 
+size_t msghdr_prep_recv_fds(struct msghdr *msg, uint8_t *buf, size_t bufsize,
+                           size_t num_fds)
+{
+       size_t ret = CMSG_SPACE(sizeof(int) * num_fds);
+
+       if (bufsize < ret) {
+               return ret;
+       }
+       if (msg != NULL) {
+               if (num_fds != 0) {
+                       msg->msg_control = buf;
+                       msg->msg_controllen = ret;
+               } else {
+                       msg->msg_control = NULL;
+                       msg->msg_controllen = 0;
+               }
+       }
+       return ret;
+}
+
 size_t msghdr_extract_fds(struct msghdr *msg, int *fds, size_t fds_size)
 {
        struct cmsghdr *cmsg;
index 88829238a2bf2b6ab658c3fee35e103219369de0..c1676d2e4de8ad01ff9d1ae4965de44f260229f2 100644 (file)
@@ -35,6 +35,8 @@ ssize_t msghdr_copy(struct msghdr_buf *msg, size_t msgsize,
                    const int *fds, size_t num_fds);
 struct msghdr *msghdr_buf_msghdr(struct msghdr_buf *msg);
 
+size_t msghdr_prep_recv_fds(struct msghdr *msg, uint8_t *buf, size_t bufsize,
+                           size_t num_fds);
 size_t msghdr_extract_fds(struct msghdr *msg, int *fds, size_t num_fds);
 
 #endif