summaryrefslogtreecommitdiff
path: root/source3/lib/socket_wrapper
diff options
context:
space:
mode:
authorJelmer Vernooij <jelmer@samba.org>2008-02-19 23:53:04 +0100
committerStefan Metzmacher <metze@samba.org>2008-06-10 11:36:39 +0200
commite2fe170423c7ac1b11a1a601c5c383e99e9682a2 (patch)
tree2f2907ca72083a03add3f2378e78c8e22994c5ff /source3/lib/socket_wrapper
parenta7967bc84ce6e5177659060c8c2baf120d9686a2 (diff)
downloadsamba-e2fe170423c7ac1b11a1a601c5c383e99e9682a2.tar.gz
samba-e2fe170423c7ac1b11a1a601c5c383e99e9682a2.tar.bz2
samba-e2fe170423c7ac1b11a1a601c5c383e99e9682a2.zip
Factor out IP marshalling into separate function.
(cherry picked from commit 2548c2a1e7dab8abc00f8f49374a08cc0b427552) (This used to be commit e4e015caac88f6e31ca6d8fcda5a97a11aee226d)
Diffstat (limited to 'source3/lib/socket_wrapper')
-rw-r--r--source3/lib/socket_wrapper/socket_wrapper.c79
1 files changed, 43 insertions, 36 deletions
diff --git a/source3/lib/socket_wrapper/socket_wrapper.c b/source3/lib/socket_wrapper/socket_wrapper.c
index f433b0e41f..d0326be495 100644
--- a/source3/lib/socket_wrapper/socket_wrapper.c
+++ b/source3/lib/socket_wrapper/socket_wrapper.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) Jelmer Vernooij 2005 <jelmer@samba.org>
+ * Copyright (C) Jelmer Vernooij 2005,2008 <jelmer@samba.org>
* Copyright (C) Stefan Metzmacher 2006 <metze@samba.org>
*
* All rights reserved.
@@ -213,7 +213,6 @@ struct socket_info
static struct socket_info *sockets;
-
const char *socket_wrapper_dir(void)
{
const char *s = getenv("SOCKET_WRAPPER_DIR");
@@ -909,40 +908,31 @@ static int swrap_get_pcap_fd(const char *fname)
return fd;
}
-static void swrap_dump_packet(struct socket_info *si, const struct sockaddr *addr,
- enum swrap_packet_type type,
- const void *buf, size_t len)
+static struct swrap_packet *swrap_marshall_packet(struct socket_info *si,
+ const struct sockaddr *addr,
+ enum swrap_packet_type type,
+ const void *buf, size_t len,
+ size_t *packet_len)
{
const struct sockaddr_in *src_addr;
const struct sockaddr_in *dest_addr;
- const char *file_name;
unsigned long tcp_seq = 0;
unsigned long tcp_ack = 0;
unsigned char tcp_ctl = 0;
int unreachable = 0;
- struct timeval tv;
- struct swrap_packet *packet;
- size_t packet_len = 0;
- int fd;
- file_name = socket_wrapper_pcap_file();
- if (!file_name) {
- return;
- }
+ struct timeval tv;
switch (si->family) {
case AF_INET:
-#ifdef HAVE_IPV6
- case AF_INET6:
-#endif
break;
default:
- return;
+ return NULL;
}
switch (type) {
case SWRAP_CONNECT_SEND:
- if (si->type != SOCK_STREAM) return;
+ if (si->type != SOCK_STREAM) return NULL;
src_addr = (const struct sockaddr_in *)si->myname;
dest_addr = (const struct sockaddr_in *)addr;
@@ -956,7 +946,7 @@ static void swrap_dump_packet(struct socket_info *si, const struct sockaddr *add
break;
case SWRAP_CONNECT_RECV:
- if (si->type != SOCK_STREAM) return;
+ if (si->type != SOCK_STREAM) return NULL;
dest_addr = (const struct sockaddr_in *)si->myname;
src_addr = (const struct sockaddr_in *)addr;
@@ -970,7 +960,7 @@ static void swrap_dump_packet(struct socket_info *si, const struct sockaddr *add
break;
case SWRAP_CONNECT_UNREACH:
- if (si->type != SOCK_STREAM) return;
+ if (si->type != SOCK_STREAM) return NULL;
dest_addr = (const struct sockaddr_in *)si->myname;
src_addr = (const struct sockaddr_in *)addr;
@@ -984,7 +974,7 @@ static void swrap_dump_packet(struct socket_info *si, const struct sockaddr *add
break;
case SWRAP_CONNECT_ACK:
- if (si->type != SOCK_STREAM) return;
+ if (si->type != SOCK_STREAM) return NULL;
src_addr = (const struct sockaddr_in *)si->myname;
dest_addr = (const struct sockaddr_in *)addr;
@@ -996,7 +986,7 @@ static void swrap_dump_packet(struct socket_info *si, const struct sockaddr *add
break;
case SWRAP_ACCEPT_SEND:
- if (si->type != SOCK_STREAM) return;
+ if (si->type != SOCK_STREAM) return NULL;
dest_addr = (const struct sockaddr_in *)si->myname;
src_addr = (const struct sockaddr_in *)addr;
@@ -1010,7 +1000,7 @@ static void swrap_dump_packet(struct socket_info *si, const struct sockaddr *add
break;
case SWRAP_ACCEPT_RECV:
- if (si->type != SOCK_STREAM) return;
+ if (si->type != SOCK_STREAM) return NULL;
src_addr = (const struct sockaddr_in *)si->myname;
dest_addr = (const struct sockaddr_in *)addr;
@@ -1024,7 +1014,7 @@ static void swrap_dump_packet(struct socket_info *si, const struct sockaddr *add
break;
case SWRAP_ACCEPT_ACK:
- if (si->type != SOCK_STREAM) return;
+ if (si->type != SOCK_STREAM) return NULL;
dest_addr = (const struct sockaddr_in *)si->myname;
src_addr = (const struct sockaddr_in *)addr;
@@ -1052,10 +1042,9 @@ static void swrap_dump_packet(struct socket_info *si, const struct sockaddr *add
src_addr = (const struct sockaddr_in *)si->peername;
if (si->type == SOCK_DGRAM) {
- swrap_dump_packet(si, si->peername,
+ return swrap_marshall_packet(si, si->peername,
SWRAP_SENDTO_UNREACH,
- buf, len);
- return;
+ buf, len, packet_len);
}
tcp_seq = si->io.pck_rcv;
@@ -1069,7 +1058,7 @@ static void swrap_dump_packet(struct socket_info *si, const struct sockaddr *add
src_addr = (const struct sockaddr_in *)si->peername;
if (si->type == SOCK_DGRAM) {
- return;
+ return NULL;
}
tcp_seq = si->io.pck_rcv;
@@ -1095,7 +1084,7 @@ static void swrap_dump_packet(struct socket_info *si, const struct sockaddr *add
src_addr = (const struct sockaddr_in *)si->peername;
if (si->type == SOCK_DGRAM) {
- return;
+ return NULL;
}
tcp_seq = si->io.pck_rcv;
@@ -1129,7 +1118,7 @@ static void swrap_dump_packet(struct socket_info *si, const struct sockaddr *add
break;
case SWRAP_CLOSE_SEND:
- if (si->type != SOCK_STREAM) return;
+ if (si->type != SOCK_STREAM) return NULL;
src_addr = (const struct sockaddr_in *)si->myname;
dest_addr = (const struct sockaddr_in *)si->peername;
@@ -1143,7 +1132,7 @@ static void swrap_dump_packet(struct socket_info *si, const struct sockaddr *add
break;
case SWRAP_CLOSE_RECV:
- if (si->type != SOCK_STREAM) return;
+ if (si->type != SOCK_STREAM) return NULL;
dest_addr = (const struct sockaddr_in *)si->myname;
src_addr = (const struct sockaddr_in *)si->peername;
@@ -1157,7 +1146,7 @@ static void swrap_dump_packet(struct socket_info *si, const struct sockaddr *add
break;
case SWRAP_CLOSE_ACK:
- if (si->type != SOCK_STREAM) return;
+ if (si->type != SOCK_STREAM) return NULL;
src_addr = (const struct sockaddr_in *)si->myname;
dest_addr = (const struct sockaddr_in *)si->peername;
@@ -1168,15 +1157,33 @@ static void swrap_dump_packet(struct socket_info *si, const struct sockaddr *add
break;
default:
- return;
+ return NULL;
}
swrapGetTimeOfDay(&tv);
- packet = swrap_packet_init(&tv, src_addr, dest_addr, si->type,
+ return swrap_packet_init(&tv, src_addr, dest_addr, si->type,
(const unsigned char *)buf, len,
tcp_seq, tcp_ack, tcp_ctl, unreachable,
- &packet_len);
+ packet_len);
+}
+
+static void swrap_dump_packet(struct socket_info *si,
+ const struct sockaddr *addr,
+ enum swrap_packet_type type,
+ const void *buf, size_t len)
+{
+ const char *file_name;
+ struct swrap_packet *packet;
+ size_t packet_len = 0;
+ int fd;
+
+ file_name = socket_wrapper_pcap_file();
+ if (!file_name) {
+ return;
+ }
+
+ packet = swrap_marshall_packet(si, addr, type, buf, len, &packet_len);
if (!packet) {
return;
}