diff options
author | Michael Adam <obnox@samba.org> | 2014-09-29 12:54:00 +0200 |
---|---|---|
committer | Michael Adam <obnox@samba.org> | 2014-09-30 16:36:10 +0200 |
commit | 20cd934ec04e601a6bac6fc1dd61c75767c6213f (patch) | |
tree | 31da528e05efd1f146b3853aebeeffb7718c5c3d | |
parent | 67684dc69585559fae6718837bf6c5ba83af267f (diff) | |
download | samba-20cd934ec04e601a6bac6fc1dd61c75767c6213f.tar.gz |
s3:unix_msg: factor extract_fd_array_from_msghdr() out of unix_dgram_recv_handler()
For re-use.
Signed-off-by: Michael Adam <obnox@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Volker Lendecke <vl@samba.org>
-rw-r--r-- | source3/lib/unix_msg/unix_msg.c | 46 |
1 files changed, 27 insertions, 19 deletions
diff --git a/source3/lib/unix_msg/unix_msg.c b/source3/lib/unix_msg/unix_msg.c index 9fdb7c16e44..6d1f3adce40 100644 --- a/source3/lib/unix_msg/unix_msg.c +++ b/source3/lib/unix_msg/unix_msg.c @@ -137,6 +137,32 @@ static int prepare_socket(int sock) return prepare_socket_cloexec(sock); } +static void extract_fd_array_from_msghdr(struct msghdr *msg, int **fds, + size_t *num_fds) +{ +#ifdef HAVE_STRUCT_MSGHDR_MSG_CONTROL + struct cmsghdr *cmsg; + + for(cmsg = CMSG_FIRSTHDR(msg); + cmsg != NULL; + cmsg = CMSG_NXTHDR(msg, cmsg)) + { + void *data = CMSG_DATA(cmsg); + + if (cmsg->cmsg_type != SCM_RIGHTS) { + continue; + } + if (cmsg->cmsg_level != SOL_SOCKET) { + continue; + } + + *fds = (int *)data; + *num_fds = (cmsg->cmsg_len - CMSG_LEN(0)) / sizeof (int); + break; + } +#endif +} + static void close_fd_array(int *fds, size_t num_fds) { size_t i; @@ -248,7 +274,6 @@ static void unix_dgram_recv_handler(struct poll_watch *w, int fd, short events, struct iovec iov; #ifdef HAVE_STRUCT_MSGHDR_MSG_CONTROL char buf[CMSG_SPACE(sizeof(int)*INT8_MAX)] = { 0, }; - struct cmsghdr *cmsg; #endif /* HAVE_STRUCT_MSGHDR_MSG_CONTROL */ int *fds = NULL; size_t i, num_fds = 0; @@ -288,24 +313,7 @@ static void unix_dgram_recv_handler(struct poll_watch *w, int fd, short events, return; } -#ifdef HAVE_STRUCT_MSGHDR_MSG_CONTROL - for(cmsg = CMSG_FIRSTHDR(&msg); cmsg != NULL; - cmsg = CMSG_NXTHDR(&msg, cmsg)) - { - void *data = CMSG_DATA(cmsg); - - if (cmsg->cmsg_type != SCM_RIGHTS) { - continue; - } - if (cmsg->cmsg_level != SOL_SOCKET) { - continue; - } - - fds = (int *)data; - num_fds = (cmsg->cmsg_len - CMSG_LEN(0)) / sizeof (int); - break; - } -#endif + extract_fd_array_from_msghdr(&msg, &fds, &num_fds); for (i = 0; i < num_fds; i++) { int err; |