-----BEGIN PGP SIGNED MESSAGE-----
The following patch adds tcpdump functionality to uml_router.
(uml_router is a really a switch emulator. It can be used to connect
multiple User-Mode-Linux's together)
There are other ways to get this functionality, including booting a UML
on an mcast network connection and using plain tcpdump, but for various
reasons I want to use uml_router instead. (In particular, I will be
corrupting packets under program control to test network stacks)
To use this you'll need to checkout the "mcr_dissect" branch of tcpdump
from cvs.tcpdump.org.
Sorry, the Makefile patches will need local editing.
Jeff, once tcpdump.org figures out when the code will be more mainstream,
I'll redo the patch with #ifdef, etc. so that you can just apply it.
=== cd /c2/user-mode-linux/sf/tools/uml_router/
=== cvs diff -rHEAD -u Makefile
Index: Makefile
===================================================================
RCS file: /cvsroot/user-mode-linux/tools/uml_router/Makefile,v
retrieving revision 1.4
diff -u -r1.4 Makefile
- --- Makefile 2001/09/02 16:59:51 1.4
+++ Makefile 2001/10/01 04:27:47
@@ -1,10 +1,11 @@
OBJS = uml_router.o
- -CFLAGS = -g -Wall
+CFLAGS = -g -Wall -lnetdissect -I/home/mcr/src/tcpdump -I/home/mcr/src/libpcap
+LIBS = -L/home/mcr/src/tcpdump -lnetdissect -L/home/mcr/src/libpcap -lpcap
all : uml_router
uml_router : $(OBJS)
- - $(CC) $(CFLAGS) -o uml_router $(OBJS)
+ $(CC) $(CFLAGS) -o uml_router $(OBJS) $(LIBS)
clean :
rm -f uml_router $(OBJS) *~
=== Exit status: 1
=== cd /c2/user-mode-linux/sf/tools/uml_router/
=== cvs diff -rHEAD -u uml_router.c
Index: uml_router.c
===================================================================
RCS file: /cvsroot/user-mode-linux/tools/uml_router/uml_router.c,v
retrieving revision 1.5
diff -u -r1.5 uml_router.c
- --- uml_router.c 2001/07/16 01:05:00 1.5
+++ uml_router.c 2001/10/01 04:28:06
@@ -8,8 +8,13 @@
#include <sys/socket.h>
#include <sys/un.h>
+#include "netdissect.h"
+
#define ETH_ALEN 6
+struct netdissect_options gndo;
+int tcpdump_print = 1;
+
struct connection {
struct connection *next;
struct connection *prev;
@@ -136,6 +141,17 @@
sendto(fd, &p, len, 0, (struct sockaddr *) &c->name, sizeof(c->name));
}
}
+
+ /* now dump it to tcpdump dissector if one was configured */
+ if(tcpdump_print) {
+ struct pcap_pkthdr ph;
+
+ memset(&ph, 0, sizeof(ph));
+
+ ph.caplen = len;
+ ph.len = len;
+ ether_if_print((u_char *)&gndo, &ph, (u_char *)&p);
+ }
}
static void new_connection(int fd)
@@ -327,6 +343,43 @@
exit(1);
}
+/* Like default_print() but data need not be aligned */
+void
+default_print_unaligned(struct netdissect_options *ipdo,
+ register const u_char *cp, register u_int length)
+{
+ register u_int i, s;
+ register int nshorts;
+
+ if (ipdo->ndo_Xflag) {
+ ascii_print(ipdo, cp, length);
+ return;
+ }
+ nshorts = (u_int) length / sizeof(u_short);
+ i = 0;
+ while (--nshorts >= 0) {
+ if ((i++ % 8) == 0)
+ (void)printf("\n\t\t\t");
+ s = *cp++;
+ (void)printf(" %02x%02x", s, *cp++);
+ }
+ if (length & 1) {
+ if ((i % 8) == 0)
+ (void)printf("\n\t\t\t");
+ (void)printf(" %02x", *cp);
+ }
+}
+
+/*
+ * By default, print the packet out in hex.
+ */
+void
+default_print(struct netdissect_options *ndo,
+ register const u_char *bp, register u_int length)
+{
+ default_print_unaligned(ndo, bp, length);
+}
+
int main(int argc, char **argv)
{
int connect_fd, data_fd, n, one = 1;
@@ -339,7 +392,10 @@
data_socket = argv[3];
}
}
- -
+
+ memset(&gndo, 0, sizeof(gndo));
+ gndo.ndo_default_print = default_print;
+
if((connect_fd = socket(PF_UNIX, SOCK_STREAM, 0)) < 0){
perror("socket");
exit(1);
=== Exit status: 1
-----BEGIN PGP SIGNATURE-----
Version: 2.6.3ia
Charset: latin1
Comment: Finger me for keys
iQCVAwUBO7fxzYqHRg3pndX9AQHPNAP/Q7JYu5NWopCKY8+Y0tDvWgT4Csvi5z0j
CJCV2VWtXYZcIGGam3FyS+9BKxa1e8tn1kqFAfJ1O0XjXBbQAPkGnes69cTSnzgv
cU5t4WKerddDRdo9aKFm1XR8FWaJYp/7vNJZHRTv/KgzoOI/vqf0Vm5BgkD60oO7
p4h7KmDxVD0=
=W4+a
-----END PGP SIGNATURE-----
-
This is the TCPDUMP workers list. It is archived at
http://www.tcpdump.org/lists/workers/index.html
To unsubscribe use mailto:[EMAIL PROTECTED]?body=unsubscribe