Author: metze
Date: 2006-09-12 06:19:11 +0000 (Tue, 12 Sep 2006)
New Revision: 18417

WebSVN: 
http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=18417

Log:
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
Modified:
   branches/SAMBA_4_0/source/lib/socket_wrapper/socket_wrapper.c
   branches/SAMBA_4_0/source/lib/socket_wrapper/socket_wrapper.h


Changeset:
Modified: branches/SAMBA_4_0/source/lib/socket_wrapper/socket_wrapper.c
===================================================================
--- branches/SAMBA_4_0/source/lib/socket_wrapper/socket_wrapper.c       
2006-09-12 04:03:43 UTC (rev 18416)
+++ branches/SAMBA_4_0/source/lib/socket_wrapper/socket_wrapper.c       
2006-09-12 06:19:11 UTC (rev 18417)
@@ -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 @@
        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 @@
                                     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 @@
                        /* 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,9 +773,48 @@
                }
        }
 
+       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;
+}
+
 _PUBLIC_ int swrap_close(int fd)
 {
        struct socket_info *si = find_socket_info(fd);

Modified: branches/SAMBA_4_0/source/lib/socket_wrapper/socket_wrapper.h
===================================================================
--- branches/SAMBA_4_0/source/lib/socket_wrapper/socket_wrapper.h       
2006-09-12 04:03:43 UTC (rev 18416)
+++ branches/SAMBA_4_0/source/lib/socket_wrapper/socket_wrapper.h       
2006-09-12 06:19:11 UTC (rev 18417)
@@ -28,7 +28,9 @@
 int swrap_getsockopt(int s, int level, int optname, void *optval, socklen_t 
*optlen);
 int swrap_setsockopt(int s, int  level,  int  optname,  const  void  *optval, 
socklen_t optlen);
 ssize_t swrap_recvfrom(int s, void *buf, size_t len, int flags, struct 
sockaddr *from, socklen_t *fromlen);
-ssize_t swrap_sendto(int  s,  const  void *buf, size_t len, int flags, const 
struct sockaddr *to, socklen_t tolen);
+ssize_t swrap_sendto(int s, const void *buf, size_t len, int flags, const 
struct sockaddr *to, socklen_t tolen);
+ssize_t swrap_recv(int s, void *buf, size_t len, int flags);
+ssize_t swrap_send(int s, const void *buf, size_t len, int flags);
 int swrap_close(int);
 
 #ifdef SOCKET_WRAPPER_REPLACE
@@ -78,6 +80,16 @@
 #endif
 #define sendto(s,buf,len,flags,to,tolen)          
swrap_sendto(s,buf,len,flags,to,tolen)
 
+#ifdef recv
+#undef recv
+#endif
+#define recv(s,buf,len,flags)          swrap_recv(s,buf,len,flags)
+
+#ifdef send
+#undef send
+#endif
+#define send(s,buf,len,flags)          swrap_send(s,buf,len,flags)
+
 #ifdef socket
 #undef socket
 #endif

Reply via email to