mirror of
https://github.com/samba-team/samba.git
synced 2024-12-24 21:34:56 +03:00
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 d05cab5c62
)
This commit is contained in:
parent
4de4af0942
commit
b5ea572f45
@ -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;
|
||||
}
|
||||
|
||||
|
@ -28,7 +28,9 @@ int swrap_getsockname(int s, struct sockaddr *name, socklen_t *addrlen);
|
||||
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 @@ int swrap_close(int);
|
||||
#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
|
||||
|
Loading…
Reference in New Issue
Block a user