summaryrefslogtreecommitdiff
path: root/lib/socket_wrapper/socket_wrapper.c
diff options
context:
space:
mode:
authorJeremy Allison <jra@samba.org>2009-09-07 20:31:01 -0700
committerJeremy Allison <jra@samba.org>2009-09-07 20:31:01 -0700
commit5ce12a05658ce03bf6414c15f20c28e125897dc2 (patch)
tree1104ab4d557b06d06c9532f2aa7dd37a5cd0d6cd /lib/socket_wrapper/socket_wrapper.c
parentac77482e871ee752ade1c56bff94915f6c0a219b (diff)
downloadsamba-5ce12a05658ce03bf6414c15f20c28e125897dc2.tar.gz
samba-5ce12a05658ce03bf6414c15f20c28e125897dc2.tar.bz2
samba-5ce12a05658ce03bf6414c15f20c28e125897dc2.zip
Add read() to socketwrapper. Metze please check.
Jeremy.
Diffstat (limited to 'lib/socket_wrapper/socket_wrapper.c')
-rw-r--r--lib/socket_wrapper/socket_wrapper.c33
1 files changed, 32 insertions, 1 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)
{