summaryrefslogtreecommitdiffstats
path: root/lib
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
parentac77482e871ee752ade1c56bff94915f6c0a219b (diff)
downloadsamba-5ce12a05658ce03bf6414c15f20c28e125897dc2.tar.gz
samba-5ce12a05658ce03bf6414c15f20c28e125897dc2.tar.xz
samba-5ce12a05658ce03bf6414c15f20c28e125897dc2.zip
Add read() to socketwrapper. Metze please check.
Jeremy.
Diffstat (limited to 'lib')
-rw-r--r--lib/socket_wrapper/socket_wrapper.c33
-rw-r--r--lib/socket_wrapper/socket_wrapper.h6
2 files changed, 38 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)
{
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