summaryrefslogtreecommitdiff
path: root/source4/lib/socket_wrapper/socket_wrapper.c
diff options
context:
space:
mode:
authorStefan Metzmacher <metze@samba.org>2006-09-12 06:19:11 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 14:18:26 -0500
commitb5ea572f450a9161b96c9c08789791054d24df37 (patch)
treed8d558db84668b5ba41e5fdd16dbc03967c98705 /source4/lib/socket_wrapper/socket_wrapper.c
parent4de4af09426847d5f16361645dfa43dc75895189 (diff)
downloadsamba-b5ea572f450a9161b96c9c08789791054d24df37.tar.gz
samba-b5ea572f450a9161b96c9c08789791054d24df37.tar.bz2
samba-b5ea572f450a9161b96c9c08789791054d24df37.zip
r18417: overload send() and recv() by socket wrapper
and add a dummy swrap_dump_packet() function which can later dump the packet content, so that a script can then generate a capture file for wireshark metze (This used to be commit d05cab5c626b5960448f206e8c17b89edbf78733)
Diffstat (limited to 'source4/lib/socket_wrapper/socket_wrapper.c')
-rw-r--r--source4/lib/socket_wrapper/socket_wrapper.c64
1 files changed, 62 insertions, 2 deletions
diff --git a/source4/lib/socket_wrapper/socket_wrapper.c b/source4/lib/socket_wrapper/socket_wrapper.c
index 702b192aff..5ba1624af6 100644
--- a/source4/lib/socket_wrapper/socket_wrapper.c
+++ b/source4/lib/socket_wrapper/socket_wrapper.c
@@ -53,6 +53,8 @@
#define real_setsockopt setsockopt
#define real_recvfrom recvfrom
#define real_sendto sendto
+#define real_recv recv
+#define real_send send
#define real_socket socket
#define real_close close
#endif
@@ -398,6 +400,20 @@ static int sockaddr_convert_from_un(const struct socket_info *si,
return -1;
}
+enum swrap_packet_type {
+ SWRAP_RECVFROM,
+ SWRAP_SENDTO,
+ SWRAP_RECV,
+ SWRAP_SEND
+};
+
+static void swrap_dump_packet(struct socket_info *si, const struct sockaddr *addr,
+ enum swrap_packet_type type,
+ const void *buf, size_t len, ssize_t ret)
+{
+
+}
+
_PUBLIC_ int swrap_socket(int domain, int type, int protocol)
{
struct socket_info *si;
@@ -700,12 +716,14 @@ _PUBLIC_ ssize_t swrap_recvfrom(int s, void *buf, size_t len, int flags, struct
si->domain, from, fromlen) == -1) {
return -1;
}
-
+
+ swrap_dump_packet(si, from, SWRAP_RECVFROM, buf, len, ret);
+
return ret;
}
-_PUBLIC_ ssize_t swrap_sendto(int s, const void *buf, size_t len, int flags, const struct sockaddr *to, socklen_t tolen)
+_PUBLIC_ ssize_t swrap_sendto(int s, const void *buf, size_t len, int flags, const struct sockaddr *to, socklen_t tolen)
{
struct sockaddr_un un_addr;
int ret;
@@ -740,6 +758,9 @@ _PUBLIC_ ssize_t swrap_sendto(int s, const void *buf, size_t len, int flags,
/* ignore the any errors in broadcast sends */
real_sendto(s, buf, len, flags, (struct sockaddr *)&un_addr, sizeof(un_addr));
}
+
+ swrap_dump_packet(si, to, SWRAP_SENDTO, buf, len, len);
+
return len;
}
@@ -752,6 +773,45 @@ _PUBLIC_ ssize_t swrap_sendto(int s, const void *buf, size_t len, int flags,
}
}
+ swrap_dump_packet(si, to, SWRAP_SENDTO, buf, len, ret);
+
+ return ret;
+}
+
+_PUBLIC_ ssize_t swrap_recv(int s, void *buf, size_t len, int flags)
+{
+ int ret;
+ struct socket_info *si = find_socket_info(s);
+
+ if (!si) {
+ return real_recv(s, buf, len, flags);
+ }
+
+ ret = real_recv(s, buf, len, flags);
+ if (ret == -1)
+ return ret;
+
+ swrap_dump_packet(si, NULL, SWRAP_RECV, buf, len, ret);
+
+ return ret;
+}
+
+
+_PUBLIC_ ssize_t swrap_send(int s, const void *buf, size_t len, int flags)
+{
+ int ret;
+ struct socket_info *si = find_socket_info(s);
+
+ if (!si) {
+ return real_send(s, buf, len, flags);
+ }
+
+ ret = real_send(s, buf, len, flags);
+ if (ret == -1)
+ return ret;
+
+ swrap_dump_packet(si, NULL, SWRAP_SEND, buf, len, ret);
+
return ret;
}