--- Makefile.target.orig	2009-09-02 16:09:39.000000000 -0400
+++ Makefile.target	2009-09-02 16:09:39.000000000 -0400
@@ -687,6 +687,9 @@
 COCOA_LIBS+=-framework CoreAudio
 endif
 endif
+ifdef CONFIG_PCAP
+LIBS+=$(PCAP_LIBS)
+endif
 ifdef CONFIG_SLIRP
 CPPFLAGS+=-I$(SRC_PATH)/slirp
 endif
--- configure.orig	2009-09-02 16:09:39.000000000 -0400
+++ configure	2009-09-02 16:09:39.000000000 -0400
@@ -188,6 +188,9 @@
 blobs="yes"
 fdt="yes"
 sdl_x11="no"
+pcap="no"
+pcap_create="no"
+bpf="no"
 
 # OS specific
 if check_define __linux__ ; then
@@ -388,6 +391,8 @@
   ;;
   --disable-vnc-tls) vnc_tls="no"
   ;;
+  --enable-pcap) pcap="yes"
+  ;;
   --disable-slirp) slirp="no"
   ;;
   --disable-vde) vde="no"
@@ -822,6 +827,47 @@
 fi
 
 ##########################################
+# pcap probe
+if test "$pcap" = "yes" ; then
+  if test "$mingw32" = "no" ; then
+    libpcap=-lpcap
+  else
+    libpcap=-lwpcap
+  fi
+  cat > $TMPC << EOF
+#include <pcap.h>
+int main(void) { return (pcap_lib_version() == (char *)0 ? 1 : 0); }
+EOF
+  if ! $cc $ARCH_CFLAGS -o $TMPE $libpcap $TMPC 2> /dev/null ; then
+    echo
+    echo "Error: Could not find pcap"
+    echo "Make sure to have the pcap libs and headers installed."
+    echo
+    exit 1
+  fi
+  cat > $TMPC << EOF
+#include <pcap.h>
+int main(void)
+{
+  char errbuf[PCAP_ERRBUF_SIZE];
+  return (pcap_create("foo", errbuf) == (pcap_t *)0 ? 1 : 0);
+}
+EOF
+  if $cc $ARCH_CFLAGS -o $TMPE $libpcap $TMPC 2> /dev/null ; then
+    pcap_create="yes"
+  fi
+  cat > $TMPC << EOF
+#define PCAP_DONT_INCLUDE_PCAP_BPF_H
+#include <pcap.h>
+#include <net/bpf.h>
+int main(void) { return (BPF_MAJOR_VERSION); }
+EOF
+  if $cc $ARCH_CFLAGS -o $TMPE $TMPC 2> /dev/null ; then
+    bpf="yes"
+  fi
+fi # test "$pcap"
+
+##########################################
 # VNC TLS detection
 if test "$vnc_tls" = "yes" ; then
 cat > $TMPC <<EOF
@@ -1365,6 +1411,17 @@
 if test $profiler = "yes" ; then
   echo "#define CONFIG_PROFILER 1" >> $config_h
 fi
+if test "$pcap" = "yes" ; then
+  echo "CONFIG_PCAP=yes" >> $config_mak
+  echo "#define CONFIG_PCAP 1" >> $config_h
+  if test "$pcap_create" = "yes" ; then
+    echo "#define CONFIG_PCAP_CREATE 1" >> $config_h
+  fi
+  if test "$bpf" = "yes" ; then
+    echo "#define CONFIG_BPF 1" >> $config_h
+  fi
+  echo "PCAP_LIBS=$libpcap" >> $config_mak
+fi
 if test "$slirp" = "yes" ; then
   echo "CONFIG_SLIRP=yes" >> $config_mak
   echo "#define CONFIG_SLIRP 1" >> $config_h
--- net.c.orig	2009-09-02 16:09:39.000000000 -0400
+++ net.c	2009-09-02 16:11:38.000000000 -0400
@@ -481,6 +481,166 @@
     return max_len;
 }
 
+#if defined(CONFIG_PCAP)
+#if defined(CONFIG_BPF)
+#define PCAP_DONT_INCLUDE_PCAP_BPF_H
+#include <net/bpf.h>
+#endif
+#include <pcap.h>
+
+typedef struct PCAPState {
+    VLANClientState *vc;
+    pcap_t *handle;
+} PCAPState;
+
+static void pcap_receive(void *opaque, const uint8_t *buf, int size)
+{
+    PCAPState *s = (PCAPState *)opaque;
+
+    pcap_sendpacket(s->handle, (u_char*)buf, size);
+}
+
+static void pcap_callback(u_char *user, struct pcap_pkthdr *phdr, u_char *pdata)
+{
+    VLANClientState *vc = (VLANClientState *)user;
+
+    qemu_send_packet(vc, pdata, phdr->len);
+}
+
+static void pcap_send(void *opaque)
+{
+    PCAPState *s = (PCAPState *)opaque;
+
+    pcap_dispatch(s->handle, 1, (pcap_handler)&pcap_callback, (u_char *)s->vc);
+}
+
+static void pcap_cleanup(VLANClientState *vc)
+{
+    PCAPState *s = vc->opaque;
+
+    pcap_close(s->handle);
+    qemu_free(s);
+}
+
+static int net_pcap_init(VLANState *vlan, const char *model, const char *name, char *ifname)
+{
+    PCAPState *s = NULL;
+    char errbuf[PCAP_ERRBUF_SIZE];
+#if defined(_WIN32)
+    HANDLE h;
+#endif
+    int i;
+
+    s = qemu_mallocz(sizeof(PCAPState));
+    if (!s)
+	return -1;
+
+    if (ifname == NULL && (ifname = pcap_lookupdev(errbuf)) == NULL) {
+	fprintf(stderr, "qemu: pcap_create: %s\n", errbuf);
+	goto fail;
+    }
+
+#if defined(CONFIG_PCAP_CREATE) || defined(_WIN32)
+    /*
+     * Create pcap handle for the device, set promiscuous mode and activate.
+     */
+    s->handle = (void *)pcap_create(ifname, errbuf);
+    if (!s->handle) {
+	fprintf(stderr, "qemu: pcap_create: %s\n", errbuf);
+	goto fail;
+    }
+    if (pcap_set_promisc(s->handle, 1) != 0) {
+	pcap_perror(s->handle, "qemu: pcap_set_promisc:");
+	goto fail;
+    }
+    if (pcap_activate(s->handle) != 0) {
+	pcap_perror(s->handle, "qemu: pcap_activate:");
+	goto fail;
+    }
+#else
+    /* Attempt to connect device. */
+    s->handle = (void *)pcap_open_live(ifname, 65535, 1, 0, errbuf);
+    if (!s->handle) {
+	fprintf(stderr, "qemu: pcap_open_live: %s\n", errbuf);
+	goto fail;
+    }
+#endif
+
+    /* Set non-blocking mode. */
+    if (pcap_setnonblock(s->handle, 1, errbuf) < 0) {
+	fprintf(stderr, "qemu: pcap_setnonblock: %s\n", errbuf);
+	goto fail;
+    }
+
+#if defined(_WIN32)
+    /*
+     * Tell the kernel that the packet has to be seen immediately.
+     */
+    if (pcap_setmintocopy(s->handle, 0) < 0) {
+	fprintf(stderr, "qemu: pcap failed to set immediate mode\n");
+	goto fail;
+    }
+#else /* !_WIN32 */
+#if defined(CONFIG_BPF)
+#if defined(BIOCIMMEDIATE)
+    /*
+     * Tell the kernel that the packet has to be seen immediately.
+     */
+    {
+	unsigned int one = 1;
+	if (ioctl(pcap_fileno(s->handle), BIOCIMMEDIATE, &one) < 0) {
+	    fprintf(stderr, "qemu: pcap failed to set immediate mode\n");
+	    goto fail;
+	}
+    }
+#endif /* BIOCIMMEDIATE */
+
+#if defined(BIOCFEEDBACK)
+    /*
+     * Tell the kernel that the sent packet has to be fed back.
+     * This is necessary to connect host and guest.
+     */
+    {
+	unsigned int one = 1;
+	if (ioctl(pcap_fileno(s->handle), BIOCFEEDBACK, &one) < 0) {
+	    fprintf(stderr, "qemu: pcap failed to set feedback mode\n");
+	    goto fail;
+	}
+    }
+#endif /* BIOCFEEDBACK */
+#endif /* CONFIG_BPF */
+#endif /* _WIN32 */
+
+    s->vc = qemu_new_vlan_client(vlan, model, name, pcap_receive, NULL, pcap_cleanup, s);
+    snprintf(s->vc->info_str, sizeof(s->vc->info_str), "pcap redirector");
+
+#if defined(_WIN32)
+    if ((h = pcap_getevent(s->handle)) == NULL) {
+	fprintf(stderr, "qemu: pcap_getevent failed\n");
+	goto fail;
+    }
+    qemu_add_wait_object(h, pcap_send, s);
+#else /* !_WIN32 */
+    if ((i = pcap_get_selectable_fd(s->handle)) < 0) {
+	fprintf(stderr, "qemu: pcap_get_selectable_fd failed\n");
+	goto fail;
+    }
+    qemu_set_fd_handler(i, pcap_send, NULL, s);
+#endif /* _WIN32 */
+
+    return 0;
+
+fail:
+    if (s) {
+	if (s->handle)
+	    pcap_close(s->handle);
+	qemu_free(s);
+    }
+
+    return -1;
+}
+#endif /* CONFIG_PCAP */
+
 #if defined(CONFIG_SLIRP)
 
 /* slirp network adapter */
@@ -1755,6 +1915,16 @@
            are wanted */
         ret = 0;
     } else
+#ifdef CONFIG_PCAP
+    if (!strcmp(device, "pcap")) {
+	char ifname[64];
+	vlan->nb_host_devs++;
+	if (get_param_value(ifname, sizeof(ifname), "ifname", p) <= 0)
+	    ret = net_pcap_init(vlan, device, name, NULL);
+	else
+	    ret = net_pcap_init(vlan, device, name, ifname);
+    } else
+#endif
 #ifdef CONFIG_SLIRP
     if (!strcmp(device, "user")) {
         if (get_param_value(buf, sizeof(buf), "hostname", p)) {
--- vl.c.orig	2009-09-02 16:09:39.000000000 -0400
+++ vl.c	2009-09-02 16:09:39.000000000 -0400
@@ -3990,6 +3990,10 @@
            "Network options:\n"
            "-net nic[,vlan=n][,macaddr=addr][,model=type][,name=str]\n"
            "                create a new Network Interface Card and connect it to VLAN 'n'\n"
+#ifdef CONFIG_PCAP
+           "-net pcap[,vlan=n][,name=str][,ifname=name]\n"
+           "                connect the host network interface using PCAP to VLAN 'n'\n"
+#endif
 #ifdef CONFIG_SLIRP
            "-net user[,vlan=n][,name=str][,hostname=host]\n"
            "                connect the user mode network stack to VLAN 'n' and send\n"
