(Niels Möller) writes:

[ I think the message I reply to got stuck in moderation, and has not
  yet appeared on the list. ]

> I'm setting up a test network with qemu and vde. I would like to be able
> to sniff traffic by running tcpdump on the host machine, by attaching
> tcpdump to one of the ports of an emulated vde_switch. (I'll configure
> vde_switch it to act as hub rather thna a switch if that's needed; not
> sure if there are other ways, like a second attach to port I'm really
> interested in, or some port-replication feature as found in some other
> switches).
> I'd prefer to not have to route packets via some real network interfaces
> on the host computer, just to be able to sniff it.
> I've been searching for tools to do this, but I couldn't find anything.
> Ideally, I'd like to use something like vde_plug the-hub | tcpdump -r -,
> but vde_plug and tcpdump don't use the same format.
> I have looked briefly at the vde_pcapplug source code, but it appears it
> doesn't support pcap savefiles. I imagine it wouldn't be very hard to
> extend vde_pcapplug to be able to read and/or write pcap files, instead
> of working with a real network interface. But before I try that, I'd
> like to know if there's any other tool I should be using instead?

I've now hacked vde_pcapplug to be able to do this. The patch below
seems to work.

If no interface is specified, packets are dumped in
pcap format to stdout. Reading a save file from stdin is not

Example usage:

  ./vde_pcapplug -s .vde-hubs/hub02 | tcpdump -r -


Line offsets in this patch may be a bit off, since I had to do a few
unrelated edits to get the file to compile outside of the vde tree, and
those changes are not included here. Also indentation changes are
excluded to reduce clutter, so one should reindent after applying the

diff --git a/vde_pcapplug.c b/vde_pcapplug.c
index 8045146..aef8f1c 100644
--- a/vde_pcapplug.c
+++ b/vde_pcapplug.c
@@ -68,6 +68,7 @@
 static VDECONN *conn = NULL;
 static pcap_t *pcap = NULL;
+static pcap_dumper_t *dumper = NULL;
 char *prog;
 int logok;
@@ -96,6 +97,8 @@ static void cleanup(void)
                printlog(LOG_WARNING,"Couldn't remove pidfile '%s': %s", 
pidfile, strerror(errno));
+       if (dumper)
+               pcap_dump_close(dumper);
        if (pcap)
        if (conn)
@@ -155,7 +158,7 @@ static void setsighandlers()
 struct pollfd 
 static void usage(void) {
-       fprintf(stderr, "Usage: %s [OPTION]... interface\n\n", prog);
+       fprintf(stderr, "Usage: %s [OPTION]... [interface]\n\n", prog);
        fprintf(stderr, "  -p, --port=portnum          Port number in the VDE 
                                "  -g, --group=group           Group for the 
                                        "  -m, --mode=mode             Octal 
mode for the socket\n"
@@ -359,12 +362,11 @@ int main(int argc, char **argv)
        if (optind < argc)
-       else
-               usage(); // implies exit
+       if (ifname) {
                pcap = pcap_open_live(ifname, BUFSIZE, 1, 0, errbuf);
                if (pcap == NULL) {
                        printlog(LOG_ERR, "Open %s: %s\n", ifname, errbuf);
@@ -380,8 +382,13 @@ int main(int argc, char **argv)
+       }
+       else {
+               pcap = pcap_open_dead (DLT_EN10MB, BUFSIZE);
+               dumper = pcap_dump_open (pcap, "-");
+               pollv[0].fd=-1;
+       }
@@ -399,10 +406,18 @@ int main(int argc, char **argv)
                        if (nx<=0)
+                       if (dumper) {
+                               struct pcap_pkthdr hdr;
+                               gettimeofday (&hdr.ts, NULL);
+                               hdr.len = hdr.caplen = nx;
+                               pcap_dump ((void *) dumper, &hdr, bufin);
+                       }
+                       else if (ifname) {
                                nx = pcap_inject(pcap, bufin, nx);
                                if (nx<=0)
+       }

Niels Möller. PGP-encrypted email is preferred. Keyid C0B98E26.
Internet email is subject to wholesale government surveillance.

Learn Graph Databases - Download FREE O'Reilly Book
"Graph Databases" is the definitive new guide to graph databases and their
applications. Written by three acclaimed leaders in the field,
this first edition is now available. Download your free book today!
vde-users mailing list

Reply via email to