summaryrefslogtreecommitdiffstats
path: root/lib/socket_wrapper
diff options
context:
space:
mode:
authorAndreas Schneider <asn@samba.org>2014-06-03 15:03:41 +0200
committerMichael Adam <obnox@samba.org>2014-06-05 23:57:10 +0200
commit2fe96124369fa51e18d83f7b90a8735047fa7012 (patch)
treed8611be234e391fa3c0a1e6ad6e1f9b6d2af51dd /lib/socket_wrapper
parentc704966f7980a9de333045fec8f5418abda57a5b (diff)
downloadsamba-2fe96124369fa51e18d83f7b90a8735047fa7012.tar.gz
samba-2fe96124369fa51e18d83f7b90a8735047fa7012.tar.xz
samba-2fe96124369fa51e18d83f7b90a8735047fa7012.zip
swrap: Add swrap_sendmsg_copy_cmsg().
Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Michael Adam <obnox@samba.org>
Diffstat (limited to 'lib/socket_wrapper')
-rw-r--r--lib/socket_wrapper/socket_wrapper.c42
1 files changed, 41 insertions, 1 deletions
diff --git a/lib/socket_wrapper/socket_wrapper.c b/lib/socket_wrapper/socket_wrapper.c
index 26750b0c082..5212cadd356 100644
--- a/lib/socket_wrapper/socket_wrapper.c
+++ b/lib/socket_wrapper/socket_wrapper.c
@@ -2995,6 +2995,15 @@ int ioctl(int s, unsigned long int r, ...)
*****************/
#ifdef HAVE_STRUCT_MSGHDR_MSG_CONTROL
+
+#ifndef CMSG_ALIGN
+# ifdef _ALIGN /* BSD */
+#define CMSG_ALIGN _ALIGN
+# else
+#error NO_CMSG_ALIGN
+# endif /* _ALIGN */
+#endif /* CMSG_ALIGN */
+
/**
* @brief Add a cmsghdr to a msghdr.
*
@@ -3145,6 +3154,10 @@ static int swrap_msghdr_add_socket_info(struct socket_info *si,
return rc;
}
+static int swrap_sendmsg_copy_cmsg(struct cmsghdr *cmsg,
+ uint8_t *cm_data,
+ size_t *cm_data_space);
+
static int swrap_sendmsg_filter_cmsghdr(struct msghdr *msg,
uint8_t *cm_data,
size_t *cm_data_space) {
@@ -3164,13 +3177,40 @@ static int swrap_sendmsg_filter_cmsghdr(struct msghdr *msg,
/* TODO swrap_sendmsg_filter_cmsg_socket */
break;
default:
- /* TODO swrap_sendmsg_copy_cmsg */
+ rc = swrap_sendmsg_copy_cmsg(cmsg,
+ cm_data,
+ cm_data_space);
break;
}
}
return rc;
}
+
+static int swrap_sendmsg_copy_cmsg(struct cmsghdr *cmsg,
+ uint8_t *cm_data,
+ size_t *cm_data_space)
+{
+ size_t cmspace;
+ uint8_t *p;
+
+ cmspace =
+ (*cm_data_space) +
+ CMSG_SPACE(cmsg->cmsg_len - CMSG_ALIGN(sizeof(struct cmsghdr)));
+
+ p = realloc(cm_data, cmspace);
+ if (p == NULL) {
+ return -1;
+ }
+ cm_data = p;
+
+ p = cm_data + (*cm_data_space);
+ *cm_data_space = cmspace;
+
+ memcpy(p, cmsg, cmsg->cmsg_len);
+
+ return 0;
+}
#endif /* HAVE_STRUCT_MSGHDR_MSG_CONTROL */
static ssize_t swrap_sendmsg_before(int fd,