summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/socket_wrapper/socket_wrapper.c33
-rw-r--r--lib/socket_wrapper/socket_wrapper.h6
-rw-r--r--source3/Makefile.in2
3 files changed, 39 insertions, 2 deletions
diff --git a/lib/socket_wrapper/socket_wrapper.c b/lib/socket_wrapper/socket_wrapper.c
index 933b1260e4..eb53c9c6ea 100644
--- a/lib/socket_wrapper/socket_wrapper.c
+++ b/lib/socket_wrapper/socket_wrapper.c
@@ -121,6 +121,7 @@
#define real_sendmsg sendmsg
#define real_ioctl ioctl
#define real_recv recv
+#define real_read read
#define real_send send
#define real_readv readv
#define real_writev writev
@@ -669,7 +670,9 @@ enum swrap_packet_type {
SWRAP_SEND_RST,
SWRAP_CLOSE_SEND,
SWRAP_CLOSE_RECV,
- SWRAP_CLOSE_ACK
+ SWRAP_CLOSE_ACK,
+ SWRAP_READ,
+ SWRAP_READ_RST
};
struct swrap_file_hdr {
@@ -2039,6 +2042,34 @@ _PUBLIC_ ssize_t swrap_recv(int s, void *buf, size_t len, int flags)
return ret;
}
+_PUBLIC_ ssize_t swrap_read(int s, void *buf, size_t len)
+{
+ int ret;
+ struct socket_info *si = find_socket_info(s);
+
+ if (!si) {
+ return real_read(s, buf, len);
+ }
+
+ if (si->type == SOCK_STREAM) {
+ /* cut down to 1500 byte packets for stream sockets,
+ * which makes it easier to format PCAP capture files
+ * (as the caller will simply continue from here) */
+ len = MIN(len, 1500);
+ }
+
+ ret = real_read(s, buf, len);
+ if (ret == -1 && errno != EAGAIN && errno != ENOBUFS) {
+ swrap_dump_packet(si, NULL, SWRAP_READ_RST, NULL, 0);
+ } else if (ret == 0) { /* END OF FILE */
+ swrap_dump_packet(si, NULL, SWRAP_READ_RST, NULL, 0);
+ } else if (ret > 0) {
+ swrap_dump_packet(si, NULL, SWRAP_READ, buf, ret);
+ }
+
+ return ret;
+}
+
_PUBLIC_ ssize_t swrap_send(int s, const void *buf, size_t len, int flags)
{
diff --git a/lib/socket_wrapper/socket_wrapper.h b/lib/socket_wrapper/socket_wrapper.h
index 56282e23b9..472aa19ced 100644
--- a/lib/socket_wrapper/socket_wrapper.h
+++ b/lib/socket_wrapper/socket_wrapper.h
@@ -52,6 +52,7 @@ ssize_t swrap_sendto(int s, const void *buf, size_t len, int flags, const struct
ssize_t swrap_sendmsg(int s, const struct msghdr *msg, int flags);
int swrap_ioctl(int s, int req, void *ptr);
ssize_t swrap_recv(int s, void *buf, size_t len, int flags);
+ssize_t swrap_read(int s, void *buf, size_t len);
ssize_t swrap_send(int s, const void *buf, size_t len, int flags);
int swrap_readv(int s, const struct iovec *vector, size_t count);
int swrap_writev(int s, const struct iovec *vector, size_t count);
@@ -124,6 +125,11 @@ int swrap_close(int);
#endif
#define recv(s,buf,len,flags) swrap_recv(s,buf,len,flags)
+#ifdef read
+#undef read
+#endif
+#define read(s,buf,len) swrap_read(s,buf,len)
+
#ifdef send
#undef send
#endif
diff --git a/source3/Makefile.in b/source3/Makefile.in
index 3528d6ce39..76ab280a1a 100644
--- a/source3/Makefile.in
+++ b/source3/Makefile.in
@@ -1100,7 +1100,7 @@ REPLACETORT_OBJ = @libreplacedir@/test/testsuite.o \
@libreplacedir@/test/os2_delete.o \
@libreplacedir@/test/strptime.o \
@libreplacedir@/test/main.o \
- $(LIBREPLACE_OBJ)
+ $(LIBREPLACE_OBJ) $(SOCKET_WRAPPER_OBJ)
DEBUG2HTML_OBJ = utils/debug2html.o utils/debugparse.o