From e2683605b0c00a0911d59a9123210fe55400a732 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sun, 2 Mar 2014 19:33:08 +0100 Subject: [PATCH] lib: Add iov_buf Signed-off-by: Volker Lendecke Reviewed-by: Jeremy Allison --- source3/include/proto.h | 1 + source3/lib/util_sock.c | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/source3/include/proto.h b/source3/include/proto.h index 983a4d00948..0a4db861a82 100644 --- a/source3/include/proto.h +++ b/source3/include/proto.h @@ -584,6 +584,7 @@ NTSTATUS read_fd_with_timeout(int fd, char *buf, NTSTATUS read_data(int fd, char *buffer, size_t N); ssize_t write_data(int fd, const char *buffer, size_t N); ssize_t iov_buflen(const struct iovec *iov, int iovlen); +uint8_t *iov_buf(TALLOC_CTX *mem_ctx, const struct iovec *iov, int iovcnt); ssize_t write_data_iov(int fd, const struct iovec *orig_iov, int iovcnt); bool send_keepalive(int client); NTSTATUS read_smb_length_return_keepalive(int fd, char *inbuf, diff --git a/source3/lib/util_sock.c b/source3/lib/util_sock.c index b8149cad838..c5de61a094b 100644 --- a/source3/lib/util_sock.c +++ b/source3/lib/util_sock.c @@ -219,6 +219,31 @@ ssize_t iov_buflen(const struct iovec *iov, int iovcnt) return buflen; } +uint8_t *iov_buf(TALLOC_CTX *mem_ctx, const struct iovec *iov, int iovcnt) +{ + int i; + ssize_t buflen; + uint8_t *buf, *p; + + buflen = iov_buflen(iov, iovcnt); + if (buflen == -1) { + return NULL; + } + buf = talloc_array(mem_ctx, uint8_t, buflen); + if (buf == NULL) { + return NULL; + } + + p = buf; + for (i=0; i