Add read() to socketwrapper. Metze please check.
authorJeremy Allison <jra@samba.org>
Tue, 8 Sep 2009 03:31:01 +0000 (20:31 -0700)
committerJeremy Allison <jra@samba.org>
Tue, 8 Sep 2009 03:31:01 +0000 (20:31 -0700)
Jeremy.

lib/socket_wrapper/socket_wrapper.c
lib/socket_wrapper/socket_wrapper.h
source3/Makefile.in

index 933b1260e43270d92060acb97ea3e9e4c3d4e0a4..eb53c9c6eaf4db493d79e147455050d8c33d5ad0 100644 (file)
 #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)
 {
index 56282e23b979c94fa4358211d80bc02db5aa9b02..472aa19ced09b60e196dd2d2ccf1f89f9ffa3308 100644 (file)
@@ -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
index 3528d6ce391e1ed17efdc7c24a7ef00db2a8e9f9..76ab280a1a597f47acb3f99c0f007add3688f0c6 100644 (file)
@@ -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