aboutsummaryrefslogtreecommitdiff
path: root/net
diff options
context:
space:
mode:
authorSergey Matveychuk <sem@FreeBSD.org>2005-03-11 13:51:32 +0000
committerSergey Matveychuk <sem@FreeBSD.org>2005-03-11 13:51:32 +0000
commit032fc7a937a99728fd73f642950e45fb59ea55e5 (patch)
treef9cff82a48e3421e2b160246e1931048dfaf8a87 /net
parent2186979471b6c681d441ecf826d13c1cdacf9146 (diff)
downloadports-032fc7a937a99728fd73f642950e45fb59ea55e5.tar.gz
ports-032fc7a937a99728fd73f642950e45fb59ea55e5.zip
VDE is a user-mode ethernet simulation. It's quite useful for
hooking together multiple qemu instances into a single virtual network without needing root access. It can also be used for tunneling or other network simulation tasks. PR: ports/76874 Submitted by: Craig Boston <craig@yekse.gank.org>
Notes
Notes: svn path=/head/; revision=130884
Diffstat (limited to 'net')
-rw-r--r--net/Makefile1
-rw-r--r--net/vde/Makefile29
-rw-r--r--net/vde/distinfo2
-rw-r--r--net/vde/files/patch-Makefile40
-rw-r--r--net/vde/files/patch-hash.c23
-rw-r--r--net/vde/files/patch-port.c34
-rw-r--r--net/vde/files/patch-qemu::Makefile8
-rw-r--r--net/vde/files/patch-qemu::vdeq.c103
-rw-r--r--net/vde/files/patch-slirpvde::Makefile20
-rw-r--r--net/vde/files/patch-slirpvde::ip.h34
-rw-r--r--net/vde/files/patch-slirpvde::libslirp.h14
-rw-r--r--net/vde/files/patch-slirpvde::slirp_config.h33
-rw-r--r--net/vde/files/patch-slirpvde::slirpvde.c95
-rw-r--r--net/vde/files/patch-slirpvde::tcp.h34
-rw-r--r--net/vde/files/patch-tuntap.c45
-rw-r--r--net/vde/files/patch-vde.h15
-rw-r--r--net/vde/files/patch-vde_plug.c98
-rw-r--r--net/vde/files/patch-vde_switch.c80
-rw-r--r--net/vde/files/patch-vdetaplib::Makefile11
-rw-r--r--net/vde/files/patch-vdetaplib::libvdetap.c260
-rw-r--r--net/vde/files/patch-vdetaplib::test.c46
-rw-r--r--net/vde/files/patch-vdetaplib::vdetap.c107
-rw-r--r--net/vde/pkg-descr7
-rw-r--r--net/vde/pkg-plist8
-rw-r--r--net/vde2/Makefile29
-rw-r--r--net/vde2/distinfo2
-rw-r--r--net/vde2/files/patch-Makefile40
-rw-r--r--net/vde2/files/patch-hash.c23
-rw-r--r--net/vde2/files/patch-port.c34
-rw-r--r--net/vde2/files/patch-qemu::Makefile8
-rw-r--r--net/vde2/files/patch-qemu::vdeq.c103
-rw-r--r--net/vde2/files/patch-slirpvde::Makefile20
-rw-r--r--net/vde2/files/patch-slirpvde::ip.h34
-rw-r--r--net/vde2/files/patch-slirpvde::libslirp.h14
-rw-r--r--net/vde2/files/patch-slirpvde::slirp_config.h33
-rw-r--r--net/vde2/files/patch-slirpvde::slirpvde.c95
-rw-r--r--net/vde2/files/patch-slirpvde::tcp.h34
-rw-r--r--net/vde2/files/patch-tuntap.c45
-rw-r--r--net/vde2/files/patch-vde.h15
-rw-r--r--net/vde2/files/patch-vde_plug.c98
-rw-r--r--net/vde2/files/patch-vde_switch.c80
-rw-r--r--net/vde2/files/patch-vdetaplib::Makefile11
-rw-r--r--net/vde2/files/patch-vdetaplib::libvdetap.c260
-rw-r--r--net/vde2/files/patch-vdetaplib::test.c46
-rw-r--r--net/vde2/files/patch-vdetaplib::vdetap.c107
-rw-r--r--net/vde2/pkg-descr7
-rw-r--r--net/vde2/pkg-plist8
47 files changed, 2293 insertions, 0 deletions
diff --git a/net/Makefile b/net/Makefile
index d0e1d4cec6e0..4c11f04a8cd8 100644
--- a/net/Makefile
+++ b/net/Makefile
@@ -798,6 +798,7 @@
SUBDIR += v6eval
SUBDIR += valknut
SUBDIR += vchat
+ SUBDIR += vde
SUBDIR += verlihub
SUBDIR += verlihub-plugins
SUBDIR += vicq
diff --git a/net/vde/Makefile b/net/vde/Makefile
new file mode 100644
index 000000000000..f826688bf162
--- /dev/null
+++ b/net/vde/Makefile
@@ -0,0 +1,29 @@
+# New ports collection makefile for: vde
+# Date created: 30 Janurary 2005
+# Whom: Craig Boston <craig@yekse.gank.org>
+#
+# $FreeBSD$
+#
+
+PORTNAME= vde
+PORTVERSION= 1.5.7
+CATEGORIES= net
+MASTER_SITES= ${MASTER_SITE_SOURCEFORGE}
+MASTER_SITE_SUBDIR= vde
+EXTRACT_SUFX= .tgz
+
+MAINTAINER= craig@yekse.gank.org
+COMMENT= User-mode virtual ethernet infrastructure
+
+USE_GMAKE= yes
+USE_GETOPT_LONG=yes
+INSTALLS_SHLIB= yes
+
+.include <bsd.port.pre.mk>
+
+CFLAGS+= ${CPPFLAGS}
+MAKE_ENV+= LDFLAGS="${LDFLAGS}"
+
+MAN1= dpipe.1 slirpvde.1 vdetaplib.1 vdeq.1 vde_plug.1 vde_switch.1
+
+.include <bsd.port.post.mk>
diff --git a/net/vde/distinfo b/net/vde/distinfo
new file mode 100644
index 000000000000..9568b8f96dc9
--- /dev/null
+++ b/net/vde/distinfo
@@ -0,0 +1,2 @@
+MD5 (vde-1.5.7.tgz) = f89a958a6997114b46abd66c00e217c8
+SIZE (vde-1.5.7.tgz) = 139314
diff --git a/net/vde/files/patch-Makefile b/net/vde/files/patch-Makefile
new file mode 100644
index 000000000000..5d0cf76b3e4b
--- /dev/null
+++ b/net/vde/files/patch-Makefile
@@ -0,0 +1,40 @@
+--- Makefile Sat Jan 29 15:02:08 2005
++++ Makefile Sun Jan 30 13:46:59 2005
+@@ -1,14 +1,15 @@
+-TUNTAP = $(shell [ -e /usr/include/linux/if_tun.h ] && echo -DTUNTAP)
++TUNTAP = $(shell [ -e /usr/include/net/if_tun.h ] && echo -DTUNTAP)
+
+ OBJSSW = hash.o port.o vde_switch.o tuntap.o
+ BINSW = vde_switch
+ BIN = $(BINSW) dpipe vde_plug
+ #CFLAGS = -g -Wall $(TUNTAP) -DINFO -O3
+-CFLAGS = -Wall $(TUNTAP) -O3
++CFLAGS += -Wall $(TUNTAP) -O
+
+-BIN_DIR ?= /usr/local/bin
+-LIB_DIR ?= /usr/local/lib
+-MAN_DIR ?= /usr/local/man
++PREFIX ?= /usr/local
++BIN_DIR ?= $(PREFIX)/bin
++LIB_DIR ?= $(PREFIX)/lib
++MAN_DIR ?= $(PREFIX)/man
+
+ ifneq ($(TUNTAP),)
+ OBJS += tuntap.o
+@@ -30,13 +31,13 @@
+ vde_switch.o: vde_switch.c vde.h switch.h hash.h port.h tuntap.h
+
+ $(BINSW) : $(OBJSSW)
+- $(CC) $(CFLAGS) -o $(BINSW) $(OBJSSW)
++ $(CC) $(CFLAGS) $(LDFLAGS) -o $(BINSW) $(OBJSSW)
+
+ dpipe: dpipe.o
+- $(CC) $(CFLAGS) -o dpipe dpipe.o
++ $(CC) $(CFLAGS) $(LDFLAGS) -o dpipe dpipe.o
+
+ vde_plug: vde_plug.o
+- $(CC) $(CFLAGS) -o vde_plug vde_plug.o
++ $(CC) $(CFLAGS) $(LDFLAGS) -o vde_plug vde_plug.o
+
+ clean :
+ rm -f $(BIN) *.o *~
diff --git a/net/vde/files/patch-hash.c b/net/vde/files/patch-hash.c
new file mode 100644
index 000000000000..e4cdaef6e90b
--- /dev/null
+++ b/net/vde/files/patch-hash.c
@@ -0,0 +1,23 @@
+--- hash.c Sat Jan 29 15:02:08 2005
++++ hash.c Sat Jan 29 15:08:18 2005
+@@ -14,7 +14,11 @@
+ #include <syslog.h>
+ #include <sys/types.h>
+ #include <sys/time.h>
++#ifdef __FreeBSD__
++#include <signal.h>
++#else
+ #include <sys/signal.h>
++#endif
+ #include "switch.h"
+ #include "hash.h"
+
+@@ -129,7 +133,7 @@
+ printf("Hash: %d Addr: %02x:%02x:%02x:%02x:%02x:%02x to port: %s "
+ "age %ld secs\n", calc_hash(e->dst),
+ e->dst[0], e->dst[1], e->dst[2], e->dst[3], e->dst[4], e->dst[5],
+- (*p->port_id)(e->port), (int) p->now - e->last_seen);
++ (*p->port_id)(e->port), (long) p->now - e->last_seen);
+ }
+
+ void print_hash(char *(*port_id)(void *))
diff --git a/net/vde/files/patch-port.c b/net/vde/files/patch-port.c
new file mode 100644
index 000000000000..02d2359c0e15
--- /dev/null
+++ b/net/vde/files/patch-port.c
@@ -0,0 +1,34 @@
+--- port.c Sat Jan 29 15:02:08 2005
++++ port.c Sun Jan 30 11:36:03 2005
+@@ -10,6 +10,9 @@
+ #include <syslog.h>
+ #include <sys/socket.h>
+ #include <sys/un.h>
++#ifdef __FreeBSD__
++#include <string.h>
++#endif
+ #include "switch.h"
+ #include "hash.h"
+ #include "port.h"
+@@ -316,10 +319,19 @@
+ port=p->data;
+ //if(match_sock(p->control, fd, p->data, p->data_len, &data)) break;
+ if(p->data_len == sizeof(struct sock_data) &&
+- !(memcmp(&(port->sock), &mine->sock, sizeof(mine->sock)))) break;
++#ifdef __FreeBSD__
++ port->sock.sun_family == mine->sock.sun_family &&
++ !(strcmp(port->sock.sun_path, mine->sock.sun_path)))
++#else
++ !(memcmp(&(port->sock), &mine->sock, sizeof(mine->sock))))
++#endif
++ break;
+ }
+ }
+- handle_direct_data(p,hub,&packet,len);
++ if (i < g_nfds)
++ handle_direct_data(p,hub,&packet,len);
++ else
++ printlog(LOG_WARNING, "No port associated with descriptor %d", fd);
+ return 0;
+ }
+
diff --git a/net/vde/files/patch-qemu::Makefile b/net/vde/files/patch-qemu::Makefile
new file mode 100644
index 000000000000..1b460436f1d3
--- /dev/null
+++ b/net/vde/files/patch-qemu::Makefile
@@ -0,0 +1,8 @@
+--- qemu/Makefile Sat Jan 29 15:02:08 2005
++++ qemu/Makefile Sun Jan 30 12:59:52 2005
+@@ -1,4 +1,4 @@
+-ALL: vdeq
++all: vdeq
+
+ vdeq.o: vdeq.c ../vde.h
+
diff --git a/net/vde/files/patch-qemu::vdeq.c b/net/vde/files/patch-qemu::vdeq.c
new file mode 100644
index 000000000000..9c34761c145e
--- /dev/null
+++ b/net/vde/files/patch-qemu::vdeq.c
@@ -0,0 +1,103 @@
+--- qemu/vdeq.c Sat Jan 29 15:02:08 2005
++++ qemu/vdeq.c Sun Jan 30 13:31:46 2005
+@@ -7,14 +7,20 @@
+ #include <signal.h>
+ #include <errno.h>
+ #include <unistd.h>
++#ifndef __FreeBSD__
+ #include <stdint.h>
++#endif
+ #include <libgen.h>
+ #include <sys/ioctl.h>
+ #include <sys/socket.h>
+ #include <sys/un.h>
+ #include <sys/uio.h>
+ #include <sys/poll.h>
++#ifdef __FreeBSD__
++#include <string.h>
++#include <sys/time.h>
+ #include "../vde.h"
++#endif
+
+ #define SWITCH_MAGIC 0xfeedface
+ #define BUFSIZE 2048
+@@ -29,6 +35,15 @@
+ struct sockaddr_un sock;
+ };
+
++#ifdef __FreeBSD__
++static char *data_socket = NULL;
++
++static void cleanup()
++{
++ if(data_socket != NULL)
++ unlink(data_socket);
++}
++#endif
+
+ static int send_fd(char *name, int fddata, struct sockaddr_un *datasock, int intno, int group)
+ {
+@@ -37,6 +52,9 @@
+ int fdctl;
+
+ struct sockaddr_un sock;
++#ifdef __FreeBSD__
++ struct timeval tv;
++#endif
+
+ if((fdctl = socket(AF_UNIX, SOCK_STREAM, 0)) < 0){
+ perror("socket");
+@@ -56,7 +74,14 @@
+
+ req.sock.sun_family=AF_UNIX;
+ memset(req.sock.sun_path, 0, sizeof(req.sock.sun_path));
++#ifdef __FreeBSD__
++ gettimeofday(&tv, NULL);
++ snprintf(req.sock.sun_path, sizeof(req.sock.sun_path), "%s.%i.%li",
++ VDEDATSOCK, pid, tv.tv_usec);
++ data_socket = strdup(req.sock.sun_path);
++#else
+ sprintf(&req.sock.sun_path[1], "%5d-%2d", pid, intno);
++#endif
+
+ if(bind(fddata, (struct sockaddr *) &req.sock, sizeof(req.sock)) < 0){
+ perror("bind");
+@@ -111,20 +136,23 @@
+ static void leave()
+ {
+ fprintf(stderr,"qemu exited: %s quits\n", vdeqname);
++#ifdef __FreeBSD__
++ cleanup(0, NULL);
++#endif
+ exit(0);
+ }
+
+ int main(int argc, char **argv)
+ {
+ int *fddata;
+- char *argsock,**sockname;
++ char *argsock = NULL,**sockname;
+ struct sockaddr_un *dataout,datain;
+ int datainsize;
+ int result;
+ int group=0;
+ int *connected_fd;
+ register ssize_t nx;
+- int args;
++ int args = 0;
+ int newargc;
+ char **newargv;
+ typedef int pair[2];
+@@ -154,10 +182,10 @@
+ )) {
+ usage();
+ } else if (argc > args+1 &&
+- (strcmp(argv[args],"-vdesock")==0) ||
++ ((strcmp(argv[args],"-vdesock")==0) ||
+ (strcmp(argv[args],"-sock")==0) ||
+ (strcmp(argv[args],"-unix")==0) ||
+- (strcmp(argv[args],"-s")==0)
++ (strcmp(argv[args],"-s")==0))
+ ){
+ argsock=argv[args+1];
+ args+=2;
diff --git a/net/vde/files/patch-slirpvde::Makefile b/net/vde/files/patch-slirpvde::Makefile
new file mode 100644
index 000000000000..05f3bea2367d
--- /dev/null
+++ b/net/vde/files/patch-slirpvde::Makefile
@@ -0,0 +1,20 @@
+--- slirpvde/Makefile Sat Jan 29 15:02:08 2005
++++ slirpvde/Makefile Sun Jan 30 14:02:57 2005
+@@ -3,7 +3,7 @@
+ tcp_timer.o udp.o \
+ bootp.o
+
+-CFLAGS=-I. -DVDE
++CFLAGS+=-I. -DVDE
+
+ all: libslirp.a slirpvde
+
+@@ -34,7 +34,7 @@
+ udp.o: udp.c ip_icmp.h
+
+ slirpvde: slirpvde.o libslirp.a
+- $(CC) -o slirpvde slirpvde.o libslirp.a
++ $(CC) $(LDFLAGS) -o slirpvde slirpvde.o libslirp.a
+
+ clean:
+ rm -rf *.o slirpvde libslirp.a
diff --git a/net/vde/files/patch-slirpvde::ip.h b/net/vde/files/patch-slirpvde::ip.h
new file mode 100644
index 000000000000..7f19d53739d6
--- /dev/null
+++ b/net/vde/files/patch-slirpvde::ip.h
@@ -0,0 +1,34 @@
+--- slirpvde/ip.h Sat Jan 29 15:02:08 2005
++++ slirpvde/ip.h Sun Jan 30 14:00:32 2005
+@@ -37,6 +37,31 @@
+ #ifndef _IP_H_
+ #define _IP_H_
+
++#ifdef __FreeBSD__
++#include <sys/endian.h>
++
++#if !defined(__BYTE_ORDER)
++#if defined(_BYTE_ORDER)
++#define __BYTE_ORDER _BYTE_ORDER
++#elif defined(BYTE_ORDER)
++#define __BYTE_ORDER BYTE_ORDER
++#else
++#error BYTE_ORDER not defined
++#endif
++#endif /* !defined(__BYTE_ORDER) */
++
++#if !defined(__BIG_ENDIAN)
++#if defined(_BIG_ENDIAN)
++#define __BIG_ENDIAN _BIG_ENDIAN
++#elif defined(BIG_ENDIAN)
++#define __BIG_ENDIAN BIG_ENDIAN
++#else
++#error BIG_ENDIAN not defined
++#endif
++#endif /* !defined(__BIG_ENDIAN) */
++
++#endif /* __FreeBSD__ */
++
+ #if __BYTE_ORDER == __BIG_ENDIAN
+ # ifndef NTOHL
+ # define NTOHL(d)
diff --git a/net/vde/files/patch-slirpvde::libslirp.h b/net/vde/files/patch-slirpvde::libslirp.h
new file mode 100644
index 000000000000..b8a62739b93f
--- /dev/null
+++ b/net/vde/files/patch-slirpvde::libslirp.h
@@ -0,0 +1,14 @@
+--- slirpvde/libslirp.h Sat Jan 29 15:02:08 2005
++++ slirpvde/libslirp.h Sun Jan 30 13:55:31 2005
+@@ -2,7 +2,11 @@
+ #define _LIBSLIRP_H
+
+ #include <sys/select.h>
++#ifdef __FreeBSD__
++#include <sys/types.h>
++#else
+ #include <stdint.h>
++#endif
+
+ void slirp_init(char *network);
+
diff --git a/net/vde/files/patch-slirpvde::slirp_config.h b/net/vde/files/patch-slirpvde::slirp_config.h
new file mode 100644
index 000000000000..dfd1288b6c2e
--- /dev/null
+++ b/net/vde/files/patch-slirpvde::slirp_config.h
@@ -0,0 +1,33 @@
+--- slirpvde/slirp_config.h Sat Jan 29 15:02:08 2005
++++ slirpvde/slirp_config.h Sat Jan 29 15:15:18 2005
+@@ -61,10 +61,18 @@
+ #define HAVE_STDLIB_H
+
+ /* Define if you have sys/ioctl.h */
++#ifdef __FreeBSD__
++#define HAVE_SYS_IOCTL_H
++#else
+ #undef HAVE_SYS_IOCTL_H
++#endif
+
+ /* Define if you have sys/filio.h */
++#ifdef __FreeBSD__
++#define HAVE_SYS_FILIO_H
++#else
+ #undef HAVE_SYS_FILIO_H
++#endif
+
+ /* Define if you have strerror */
+ #define HAVE_STRERROR
+@@ -162,7 +170,11 @@
+ #define HAVE_MEMMOVE
+
+ /* Define if you have <termios.h> */
++#ifdef __FreeBSD__
++#define HAVE_TERMIOS_H
++#else
+ #undef HAVE_TERMIOS_H
++#endif
+
+ /* Define if you have gethostid */
+ #undef HAVE_GETHOSTID
diff --git a/net/vde/files/patch-slirpvde::slirpvde.c b/net/vde/files/patch-slirpvde::slirpvde.c
new file mode 100644
index 000000000000..f76790701b07
--- /dev/null
+++ b/net/vde/files/patch-slirpvde::slirpvde.c
@@ -0,0 +1,95 @@
+--- slirpvde/slirpvde.c Sat Jan 29 15:02:08 2005
++++ slirpvde/slirpvde.c Sun Jan 30 14:24:33 2005
+@@ -7,7 +7,9 @@
+ #include <signal.h>
+ #include <errno.h>
+ #include <unistd.h>
++#ifndef __FreeBSD__
+ #include <stdint.h>
++#endif
+ #include <libgen.h>
+ #include <sys/ioctl.h>
+ #include <sys/socket.h>
+@@ -16,6 +18,10 @@
+ #include <sys/poll.h>
+ #include <libslirp.h>
+ #include <getopt.h>
++#ifdef __FreeBSD__
++#include <string.h>
++#include <sys/time.h>
++#endif
+
+ #define SWITCH_MAGIC 0xfeedface
+ #define BUFSIZE 2048
+@@ -32,6 +38,25 @@
+ struct sockaddr_un sock;
+ };
+
++#ifdef __FreeBSD__
++#include "../vde.h"
++static char *data_socket = NULL;
++
++static void cleanup()
++{
++ if(data_socket != NULL)
++ unlink(data_socket);
++}
++
++static void sig_handler(int sig)
++{
++ fprintf(stderr, "Caught signal %d, cleaning up and exiting\n", sig);
++ cleanup(1,NULL);
++ signal(sig, SIG_DFL);
++ kill(getpid(), sig);
++}
++#endif
++
+ static int send_fd(char *name, int fddata, struct sockaddr_un *datasock, int group)
+ {
+ int pid = getpid();
+@@ -39,6 +64,9 @@
+ int fdctl;
+
+ struct sockaddr_un sock;
++#ifdef __FreeBSD__
++ struct timeval tv;
++#endif
+
+ if((fdctl = socket(AF_UNIX, SOCK_STREAM, 0)) < 0){
+ perror("socket");
+@@ -58,7 +86,14 @@
+
+ req.sock.sun_family=AF_UNIX;
+ memset(req.sock.sun_path, 0, sizeof(req.sock.sun_path));
++#ifdef __FreeBSD__
++ gettimeofday(&tv, NULL);
++ snprintf(req.sock.sun_path, sizeof(req.sock.sun_path), "%s.%i.%li",
++ VDEDATSOCK, pid, tv.tv_usec);
++ data_socket = strdup(req.sock.sun_path);
++#else
+ sprintf(&req.sock.sun_path[1], "%5d", pid);
++#endif
+
+ if(bind(fddata, (struct sockaddr *) &req.sock, sizeof(req.sock)) < 0){
+ perror("bind");
+@@ -149,7 +184,6 @@
+ int group=0;
+ int connected_fd;
+ register ssize_t nx;
+- register int i;
+ fd_set rs,ws,xs;
+ int opt,longindx;
+ char *netw=NULL;
+@@ -175,6 +209,12 @@
+ exit(1);
+ }
+ connected_fd=send_fd(sockname, fddata, &dataout, group);
++#ifdef __FreeBSD__
++ if(signal(SIGINT, sig_handler) < 0) {
++ perror("signal");
++ }
++ signal(SIGPIPE, SIG_IGN); /* FreeBSD 4.x sends SIGPIPE on reset sockets */
++#endif
+ slirp_init(netw);
+
+ for(;;) {
diff --git a/net/vde/files/patch-slirpvde::tcp.h b/net/vde/files/patch-slirpvde::tcp.h
new file mode 100644
index 000000000000..1dade2d0986c
--- /dev/null
+++ b/net/vde/files/patch-slirpvde::tcp.h
@@ -0,0 +1,34 @@
+--- slirpvde/tcp.h Sat Jan 29 15:02:08 2005
++++ slirpvde/tcp.h Sun Jan 30 14:00:50 2005
+@@ -37,6 +37,31 @@
+ #ifndef _TCP_H_
+ #define _TCP_H_
+
++#ifdef __FreeBSD__
++#include <sys/endian.h>
++
++#if !defined(__BYTE_ORDER)
++#if defined(_BYTE_ORDER)
++#define __BYTE_ORDER _BYTE_ORDER
++#elif defined(BYTE_ORDER)
++#define __BYTE_ORDER BYTE_ORDER
++#else
++#error BYTE_ORDER not defined
++#endif
++#endif /* !defined(__BYTE_ORDER) */
++
++#if !defined(__BIG_ENDIAN)
++#if defined(_BIG_ENDIAN)
++#define __BIG_ENDIAN _BIG_ENDIAN
++#elif defined(BIG_ENDIAN)
++#define __BIG_ENDIAN BIG_ENDIAN
++#else
++#error BIG_ENDIAN not defined
++#endif
++#endif /* !defined(__BIG_ENDIAN) */
++
++#endif /* __FreeBSD__ */
++
+ typedef u_int32_t tcp_seq;
+
+ #define PR_SLOWHZ 2 /* 2 slow timeouts per second (approx) */
diff --git a/net/vde/files/patch-tuntap.c b/net/vde/files/patch-tuntap.c
new file mode 100644
index 000000000000..43b31617ea17
--- /dev/null
+++ b/net/vde/files/patch-tuntap.c
@@ -0,0 +1,45 @@
+--- tuntap.c Sat Jan 29 15:02:08 2005
++++ tuntap.c Sun Jan 30 00:27:23 2005
+@@ -11,8 +11,16 @@
+ #include <unistd.h>
+ #include <syslog.h>
+ #include <sys/ioctl.h>
++#ifdef __FreeBSD__
++#include <sys/types.h>
++#include <sys/socket.h>
++#endif
+ #include <net/if.h>
++#ifdef __FreeBSD__
++#include <net/if_tun.h>
++#else
+ #include <linux/if_tun.h>
++#endif
+ #include "port.h"
+ #include "switch.h"
+
+@@ -28,13 +36,16 @@
+
+ int open_tap(char *dev)
+ {
++#ifndef __FreeBSD__
+ struct ifreq ifr;
++#endif
+ int fd;
+
+- if((fd = open("/dev/net/tun", O_RDWR)) < 0){
+- printlog(LOG_ERR,"Failed to open /dev/net/tun %s",strerror(errno));
++ if((fd = open(dev, O_RDWR)) < 0){
++ printlog(LOG_ERR,"Failed to open %s %s", dev, strerror(errno));
+ return(-1);
+ }
++#ifndef __FreeBSD__
+ memset(&ifr, 0, sizeof(ifr));
+ ifr.ifr_flags = IFF_TAP | IFF_NO_PI;
+ strncpy(ifr.ifr_name, dev, sizeof(ifr.ifr_name) - 1);
+@@ -43,5 +54,6 @@
+ close(fd);
+ return(-1);
+ }
++#endif
+ return(fd);
+ }
diff --git a/net/vde/files/patch-vde.h b/net/vde/files/patch-vde.h
new file mode 100644
index 000000000000..8097ca0bcce2
--- /dev/null
+++ b/net/vde/files/patch-vde.h
@@ -0,0 +1,15 @@
+--- vde.h Sat Jan 29 15:02:08 2005
++++ vde.h Sun Jan 30 11:39:43 2005
+@@ -2,6 +2,12 @@
+ #define VDESTDSOCK "/tmp/vde.ctl"
+ #endif
+
++#ifdef __FreeBSD__
++#ifndef VDEDATSOCK
++#define VDEDATSOCK "/tmp/.vde.data"
++#endif
++#endif
++
+ #define DO_SYSLOG
+ #define VDE_IP_LOG
+
diff --git a/net/vde/files/patch-vde_plug.c b/net/vde/files/patch-vde_plug.c
new file mode 100644
index 000000000000..416291e4337e
--- /dev/null
+++ b/net/vde/files/patch-vde_plug.c
@@ -0,0 +1,98 @@
+--- vde_plug.c Sat Jan 29 15:02:08 2005
++++ vde_plug.c Sun Jan 30 13:52:57 2005
+@@ -7,7 +7,9 @@
+ #include <signal.h>
+ #include <errno.h>
+ #include <unistd.h>
++#ifndef __FreeBSD__
+ #include <stdint.h>
++#endif
+ #include <getopt.h>
+ #include <sys/ioctl.h>
+ #include <sys/socket.h>
+@@ -15,6 +17,11 @@
+ #include <sys/uio.h>
+ #include <sys/poll.h>
+ #include <sys/utsname.h>
++#ifdef __FreeBSD__
++#include <sys/time.h>
++#include <netinet/in.h>
++#include <string.h>
++#endif
+ #include "vde.h"
+ #ifdef VDE_IP_LOG
+ #define DO_SYSLOG
+@@ -47,6 +54,24 @@
+ static struct passwd *callerpwd;
+ static char host[256];
+
++#ifdef __FreeBSD__
++static char *data_socket = NULL;
++
++static void cleanup()
++{
++ if(data_socket != NULL)
++ unlink(data_socket);
++}
++
++static void sig_handler(int sig)
++{
++ fprintf(stderr, "Caught signal %d, cleaning up and exiting\n", sig);
++ cleanup(1,NULL);
++ signal(sig, SIG_DFL);
++ kill(getpid(), sig);
++}
++#endif
++
+ void write_syslog_entry(char *message)
+ {
+ char *ssh_client;
+@@ -183,6 +208,9 @@
+ int fdctl;
+
+ struct sockaddr_un sock;
++#ifdef __FreeBSD__
++ struct timeval tv;
++#endif
+
+ if((fdctl = socket(AF_UNIX, SOCK_STREAM, 0)) < 0){
+ perror("socket");
+@@ -202,7 +230,14 @@
+
+ req.sock.sun_family=AF_UNIX;
+ memset(req.sock.sun_path, 0, sizeof(req.sock.sun_path));
++#ifdef __FreeBSD__
++ gettimeofday(&tv, NULL);
++ snprintf(req.sock.sun_path, sizeof(req.sock.sun_path), "%s.%i.%li",
++ VDEDATSOCK, pid, tv.tv_usec);
++ data_socket = strdup(req.sock.sun_path);
++#else
+ sprintf(&req.sock.sun_path[1], "%5d", pid);
++#endif
+
+ if(bind(fddata, (struct sockaddr *) &req.sock, sizeof(req.sock)) < 0){
+ perror("bind");
+@@ -309,6 +344,10 @@
+ int connected_fd;
+ register ssize_t nx;
+
++#ifdef __FreeBSD__
++ atexit(cleanup);
++#endif
++
+ uname(&me);
+ if (argv[0][0] == '-')
+ netusage(); //implies exit
+@@ -383,6 +422,12 @@
+ }
+ connected_fd=send_fd(sockname, fddata, &dataout, group);
+ pollv[1].fd=fddata;
++
++#ifdef __FreeBSD__
++ if(signal(SIGINT, sig_handler) < 0) {
++ perror("signal");
++ }
++#endif
+
+ for(;;) {
+ result=poll(pollv,2,-1);
diff --git a/net/vde/files/patch-vde_switch.c b/net/vde/files/patch-vde_switch.c
new file mode 100644
index 000000000000..c95f04789071
--- /dev/null
+++ b/net/vde/files/patch-vde_switch.c
@@ -0,0 +1,80 @@
+--- vde_switch.c Sat Jan 29 15:02:08 2005
++++ vde_switch.c Sun Jan 30 13:33:00 2005
+@@ -8,7 +8,9 @@
+ #include <stdlib.h>
+ #include <signal.h>
+ #include <fcntl.h>
++#ifndef __FreeBSD__
+ #include <stdint.h>
++#endif
+ #include <getopt.h>
+ #include <sys/socket.h>
+ #include <sys/un.h>
+@@ -17,7 +19,11 @@
+ #include <unistd.h>
+ #include <syslog.h>
+ #include <libgen.h>
++#ifdef __FreeBSD__
++#include <string.h>
++#else
+ #include <endian.h>
++#endif
+ #include "vde.h"
+ #include "switch.h"
+ #include "port.h"
+@@ -95,6 +101,13 @@
+ }
+ }
+
++#ifdef __FreeBSD__
++static void cleanupwrapper()
++{
++ cleanup(0, NULL);
++}
++#endif
++
+ void **g_fdsdata = NULL;
+ int g_nfds = 0;
+ int g_minfds = 0;
+@@ -276,19 +289,27 @@
+
+ void bind_data_socket(int fd, struct sockaddr_un *sun)
+ {
++ struct timeval tv;
++
++ sun->sun_family = AF_UNIX;
++#ifdef __FreeBSD__
++ gettimeofday(&tv, NULL);
++ snprintf(sun->sun_path, sizeof(sun->sun_path), "%s.%i.%li",
++ VDEDATSOCK, getpid(), tv.tv_usec);
++ data_socket = strdup(sun->sun_path);
++#else
+ struct {
+ char zero;
+ int pid;
+ int usecs;
+ } name;
+- struct timeval tv;
+
+ name.zero = 0;
+ name.pid = getpid();
+ gettimeofday(&tv, NULL);
+ name.usecs = tv.tv_usec;
+- sun->sun_family = AF_UNIX;
+ memcpy(sun->sun_path, &name, sizeof(name));
++#endif
+ if(bind(fd, (struct sockaddr *) sun, sizeof(*sun)) < 0){
+ printlog(LOG_ERR,"Binding to data socket %s",strerror(errno));
+ exit(1);
+@@ -338,7 +359,11 @@
+ int tap_fd = -1;
+ #endif
+
++#ifdef __FreeBSD__
++ atexit(cleanupwrapper);
++#else
+ on_exit(cleanup, NULL);
++#endif
+ prog = argv[0];
+ /* option parsing */
+ {
diff --git a/net/vde/files/patch-vdetaplib::Makefile b/net/vde/files/patch-vdetaplib::Makefile
new file mode 100644
index 000000000000..ff72703ce702
--- /dev/null
+++ b/net/vde/files/patch-vdetaplib::Makefile
@@ -0,0 +1,11 @@
+--- vdetaplib/Makefile Sat Jan 29 15:02:08 2005
++++ vdetaplib/Makefile Sun Jan 30 12:21:39 2005
+@@ -9,7 +9,7 @@
+ all: vdetap libvdetap.so
+
+ libvdetap.so: libvdetap.a
+- $(LD) -E -o $@ -L./ -ldl -shared -export-dynamic -Bdynamic \
++ $(LD) -E -o $@ -L./ -shared -export-dynamic -Bdynamic \
+ --whole-archive libvdetap.a
+
+ libvdetap.a: libvdetap.o
diff --git a/net/vde/files/patch-vdetaplib::libvdetap.c b/net/vde/files/patch-vdetaplib::libvdetap.c
new file mode 100644
index 000000000000..7c304913b035
--- /dev/null
+++ b/net/vde/files/patch-vdetaplib::libvdetap.c
@@ -0,0 +1,260 @@
+--- vdetaplib/libvdetap.c Sat Jan 29 15:02:08 2005
++++ vdetaplib/libvdetap.c Sun Jan 30 13:29:07 2005
+@@ -5,26 +5,39 @@
+ #include <sys/socket.h>
+ #include <sys/syscall.h>
+ #include <sys/stat.h>
++#include <limits.h>
++#include <dlfcn.h>
+ #include <stdarg.h>
+ #include <string.h>
+ #include <unistd.h>
+ #include <stdlib.h>
+-#define __USE_LARGEFILE64
+ #include <fcntl.h>
+ #include <errno.h>
+ #include <signal.h>
+-#include <linux/ioctl.h>
+-#include <linux/if.h>
+-#include <linux/if_tun.h>
++#include <stdio.h>
++#include <sys/ioctl.h>
++#include <net/if.h>
++#include <net/if_tun.h>
+
+-#define TUNTAPPATH "/dev/net/tun"
++#define TUNTAPPATH "/dev/tap"
+ #define VDETAPEXEC "vdetap"
+ #define VDEALLTAP "VDEALLTAP"
+ #define MAX 10
+
++#if defined(RTLD_NEXT)
++#define REAL_LIBC RTLD_NEXT
++#else
++#define REAL_LIBC ((void *) -1L)
++#endif
++
++#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__bsdi__)
++typedef unsigned long request_t;
++#else
++typedef int request_t;
++#endif
++
+ int tapfd[2] = {-1,-1};
+ static int tapcount=0;
+-static int tuncount=0;
+
+ static struct pidlist {
+ pid_t pid;
+@@ -39,11 +52,6 @@
+ return rv;
+ }
+
+-static void plfree (struct pidlist *el) {
+- el->next=flh;
+- flh=el;
+-}
+-
+ static int addpid(int pid) {
+ struct pidlist *plp;
+ if ((plp=plmalloc ()) != NULL) {
+@@ -74,105 +82,41 @@
+ }
+ }
+
+- int
+-native_open(const char *pathname, int flags, mode_t data)
+-{
+- return (syscall(SYS_open, pathname, flags, data));
+-}
+-
+- int
+-native_ioctl(int fd, unsigned long int command, char *data)
+-{
+- return (syscall(SYS_ioctl, fd, command, data));
+-}
+-
+-
+ int open(const char *path, int flags, ...)
+ {
+- static char buf[PATH_MAX];
++ static int (*func) (const char *, int, mode_t) = NULL;
++ char *vdesock;
++ int pid;
+ va_list ap;
+ mode_t data;
+
+- va_start(ap, flags);
+- data = va_arg(ap, mode_t);
+- va_end(ap);
+-
+- if (strcmp(path,TUNTAPPATH)==0 && tapfd[0] == -1) {
+- if (socketpair(PF_UNIX, SOCK_DGRAM, 0,tapfd) == 0) {
+- return tapfd[0];
+- }
+- else
+- return -1;
+-
+- } else
+- return native_open(path, flags, data);
+-}
+-
+-int open64(const char *path, int flags, ...)
+-{
+- static char buf[PATH_MAX];
+- va_list ap;
+- mode_t data;
++ if (!func)
++ func = (int (*) (const char *, int, mode_t))
++ dlsym (REAL_LIBC, "open");
+
+ va_start(ap, flags);
+- data = va_arg(ap, mode_t);
++ data = va_arg(ap, int);
+ va_end(ap);
+
+ if (strcmp(path,TUNTAPPATH)==0 && tapfd[0] == -1) {
+ if (socketpair(PF_UNIX, SOCK_DGRAM, 0,tapfd) == 0) {
+- return tapfd[0];
+- }
+- else
+- return -1;
+-
+- } else
+- return native_open(path, flags | O_LARGEFILE, data);
+-}
+-
+-int ioctl(int fd, unsigned long int command, ...)
+-{
+- va_list ap;
+- char *data;
+- char *vdesock;
+- int pid;
+-
+- va_start(ap, command);
+- data = va_arg(ap, char *);
+- va_end(ap);
+-
+- if (fd == tapfd[0]) {
+- if (command == TUNSETIFF) {
+- struct ifreq *ifr = (struct ifreq *) data;
+ char num[5];
+ char name[10];
+-
+- ifr->ifr_name[IFNAMSIZ-1] = '\0';
+- if (ifr->ifr_name[0] == 0) {
+- if (ifr->ifr_flags & IFF_TAP)
+- sprintf(name,"tap%d",tapcount++);
+- else
+- sprintf(name,"tun%d",tuncount++);
+- strncpy(ifr->ifr_name,name,IFNAMSIZ);
+- }
+- else if (strchr(ifr->ifr_name, '%') != NULL) {
+- sprintf(name,ifr->ifr_name,tapcount++);
+- strncpy(ifr->ifr_name,name,IFNAMSIZ);
+- }
+- if (ifr->ifr_flags & IFF_TAP &&
+- ((vdesock=getenv(ifr->ifr_name)) != NULL)
+- ||(vdesock=getenv(VDEALLTAP)) != NULL){
++ sprintf(name,"tap%d",tapcount++);
++ if (((vdesock=getenv(name)) != NULL)
++ ||(vdesock=getenv(VDEALLTAP)) != NULL){
+ if ((pid=fork()) < 0) {
+ close(tapfd[1]);
+ errno=EINVAL;
+ return -1;
+ } else if (pid > 0) { /*father*/
+- if(pid=addpid(pid) < 0) {
++ if((pid=addpid(pid)) < 0) {
+ close(tapfd[0]);
+ close(tapfd[1]);
+ return -1;
+ } else {
+ close(tapfd[1]);
+- return 0;
++ return tapfd[0];
+ }
+ } else { /*son*/
+ plh=NULL;
+@@ -181,34 +125,53 @@
+ execlp(VDETAPEXEC,"-",num,vdesock,(char *) 0);
+ }
+ }
+- else /*roll back to the native tuntap*/
+- {
+- int newfd;
+- int saverrno;
+- int resultioctl;
+- close(tapfd[1]);
+- if ((newfd=native_open(TUNTAPPATH, O_RDWR, 0)) < 0) {
+- saverrno=errno;
+- close(tapfd[0]);
+- errno=saverrno;
+- return -1;
+- } else
+- {
+- resultioctl=native_ioctl(fd, command, data);
+- if (resultioctl < 0) {
+- saverrno=errno;
+- close(tapfd[0]);
+- errno=saverrno;
+- return -1;
+- } else {
+- dup2(newfd,tapfd[0]);
+- return resultioctl;
+- }
+- }
+- }
+- } else
+- return 0;
++ return tapfd[0];
++ }
++ else
++ return -1;
++
+ } else
+- return (native_ioctl(fd, command, data));
++ return (*func)(path, flags, data);
++}
++
++int ioctl(int fd, unsigned long int command, ...)
++{
++ static int (*func) (int, request_t, void *) = NULL;
++ int dummy;
++ va_list ap;
++ char *data;
++ struct ifstat *ifs;
++
++ if (!func)
++ func = (int (*) (int, request_t, void *))
++ dlsym (REAL_LIBC, "ioctl");
++
++ va_start(ap, command);
++ data = va_arg(ap, char *);
++ va_end(ap);
++
++ if (fd == tapfd[0]) {
++ switch(command) {
++ case SIOCSIFFLAGS:
++ case SIOCADDMULTI:
++ case SIOCDELMULTI:
++ break;
++
++ case SIOCGIFSTATUS:
++ ifs = (struct ifstat *)data;
++ dummy = strlen(ifs->ascii);
++ if(plh && dummy < sizeof(ifs->ascii))
++ snprintf(ifs->ascii + dummy,
++ sizeof(ifs->ascii) - dummy,
++ "\tOpened by PID %d\n",
++ plh[0].pid);
++ break;
++
++ default:
++ return (*func) (fd, command, data);
++ }
++ }
++
++ return (*func) (fd, command, data);
+ }
+
diff --git a/net/vde/files/patch-vdetaplib::test.c b/net/vde/files/patch-vdetaplib::test.c
new file mode 100644
index 000000000000..d26ffa326253
--- /dev/null
+++ b/net/vde/files/patch-vdetaplib::test.c
@@ -0,0 +1,46 @@
+--- vdetaplib/test.c Sat Jan 29 15:02:08 2005
++++ vdetaplib/test.c Sun Jan 30 12:27:35 2005
+@@ -6,35 +6,28 @@
+ #include <errno.h>
+ #include <string.h>
+ #include <unistd.h>
++#include <sys/types.h>
+ #include <sys/ioctl.h>
++#include <sys/socket.h>
+ #include <net/if.h>
+-#include <linux/if_tun.h>
++#include <net/if_tun.h>
+
+ static int tun_alloc(char *dev)
+ {
+- struct ifreq ifr;
++ struct ifstat ifs;
+ int fd, err;
+
+- if( (fd = open("/dev/net/tun", O_RDWR)) < 0 )
++ if( (fd = open("/dev/tap", O_RDWR)) < 0 )
+ return (-1);
+
+- memset(&ifr, 0, sizeof(ifr));
++ memset(&ifs, 0, sizeof(ifs));
+
+- /* Flags: IFF_TUN - TUN device (no Ethernet headers)
+- * IFF_TAP - TAP device
+- *
+- * IFF_NO_PI - Do not provide packet information
+- */
+- ifr.ifr_flags = IFF_TAP;
+- if( *dev )
+- strncpy(ifr.ifr_name, dev, IFNAMSIZ);
+-
+- if( (err = ioctl(fd, TUNSETIFF, (void *) &ifr)) < 0 ){
++ if( (err = ioctl(fd, SIOCGIFSTATUS, (void *) &ifs)) < 0 ){
+ close(fd);
+ return err;
+ }
+ printf("ioctl returns\n");
+- strcpy(dev, ifr.ifr_name);
++ puts(ifs.ascii);
+ printf("ioctl idev\n");
+ return fd;
+ }
diff --git a/net/vde/files/patch-vdetaplib::vdetap.c b/net/vde/files/patch-vdetaplib::vdetap.c
new file mode 100644
index 000000000000..3e5ded1cc07b
--- /dev/null
+++ b/net/vde/files/patch-vdetaplib::vdetap.c
@@ -0,0 +1,107 @@
+--- vdetaplib/vdetap.c Sat Jan 29 15:02:08 2005
++++ vdetaplib/vdetap.c Sun Jan 30 14:05:26 2005
+@@ -2,11 +2,25 @@
+ * Reseased under the GPLv2 */
+
+ #include <stdio.h>
++#ifndef __FreeBSD__
+ #include <stdint.h>
++#endif
++#ifdef __FreeBSD__
++#include <sys/types.h>
++#include <sys/time.h>
++#include <unistd.h>
++#else
+ #include <sys/select.h>
++#endif
+ #include <sys/poll.h>
+ #include <sys/socket.h>
+ #include <sys/un.h>
++#ifdef __FreeBSD__
++#include "../vde.h"
++#include <signal.h>
++#include <stdlib.h>
++#include <string.h>
++#endif
+
+ #define SWITCH_MAGIC 0xfeedface
+ #define BUFSIZE 2048
+@@ -21,6 +35,23 @@
+
+ static unsigned char bufin[BUFSIZE];
+
++#ifdef __FreeBSD__
++static char *data_socket = NULL;
++
++static void cleanup()
++{
++ if(data_socket != NULL)
++ unlink(data_socket);
++}
++
++static void sig_handler(int sig)
++{
++ cleanup(1, NULL);
++ signal(sig, SIG_DFL);
++ kill(getpid(), sig);
++}
++#endif
++
+ static int send_fd(char *name, int fddata, struct sockaddr_un *datasock, int intno, int group)
+ {
+ int pid = getpid();
+@@ -28,6 +59,9 @@
+ int fdctl;
+
+ struct sockaddr_un sock;
++#ifdef __FreeBSD__
++ struct timeval tv;
++#endif
+
+ if((fdctl = socket(AF_UNIX, SOCK_STREAM, 0)) < 0){
+ perror("socket");
+@@ -47,7 +81,14 @@
+
+ req.sock.sun_family=AF_UNIX;
+ memset(req.sock.sun_path, 0, sizeof(req.sock.sun_path));
++#ifdef __FreeBSD__
++ gettimeofday(&tv, NULL);
++ snprintf(req.sock.sun_path, sizeof(req.sock.sun_path), "%s.%i.%li",
++ VDEDATSOCK, pid, tv.tv_usec);
++ data_socket = strdup(req.sock.sun_path);
++#else
+ sprintf(&req.sock.sun_path[1], "%5d-%2d", pid, intno);
++#endif
+
+ if(bind(fddata, (struct sockaddr *) &req.sock, sizeof(req.sock)) < 0){
+ perror("bind");
+@@ -69,7 +110,7 @@
+
+ static struct pollfd pollv[]={{0,POLLIN|POLLHUP,0},{0,POLLIN|POLLHUP,0}};
+
+-main(int argc,char *argv[])
++int main(int argc,char *argv[])
+ {
+ int fd,fddata;
+ struct sockaddr_un dataout,datain;
+@@ -96,6 +137,12 @@
+ send_fd(argv[2],fddata,&dataout,0,0);
+ pollv[0].fd=fd;
+ pollv[1].fd=fddata;
++
++#ifdef __FreeBSD__
++ if(signal(SIGINT, sig_handler) < 0) {
++ perror("signal");
++ }
++#endif
+ for(;;) {
+ result=poll(pollv,2,-1);
+ if (pollv[0].revents & POLLHUP || pollv[1].revents & POLLHUP)
+@@ -113,5 +160,7 @@
+ write(fd,bufin,nx);
+ }
+ }
++ cleanup(0, NULL);
++ return 0;
+ }
+
diff --git a/net/vde/pkg-descr b/net/vde/pkg-descr
new file mode 100644
index 000000000000..0787b5b905df
--- /dev/null
+++ b/net/vde/pkg-descr
@@ -0,0 +1,7 @@
+Virtual Distributed Ethernet is a user-mode virtual network (layer
+2) infrastructure. It can be used for network simulations, joining
+multiple qemu instances together in a shared virtual network, or
+tunneling over the Internet. Physical hosts can be joined to the
+virtual network by means of the tap(4) driver.
+
+WWW: http://vde.sourceforge.net/
diff --git a/net/vde/pkg-plist b/net/vde/pkg-plist
new file mode 100644
index 000000000000..5d6c79f75ade
--- /dev/null
+++ b/net/vde/pkg-plist
@@ -0,0 +1,8 @@
+bin/dpipe
+bin/slirpvde
+bin/vde_plug
+bin/vde_switch
+bin/vdeq
+bin/vdeqemu
+bin/vdetap
+lib/libvdetap.so
diff --git a/net/vde2/Makefile b/net/vde2/Makefile
new file mode 100644
index 000000000000..f826688bf162
--- /dev/null
+++ b/net/vde2/Makefile
@@ -0,0 +1,29 @@
+# New ports collection makefile for: vde
+# Date created: 30 Janurary 2005
+# Whom: Craig Boston <craig@yekse.gank.org>
+#
+# $FreeBSD$
+#
+
+PORTNAME= vde
+PORTVERSION= 1.5.7
+CATEGORIES= net
+MASTER_SITES= ${MASTER_SITE_SOURCEFORGE}
+MASTER_SITE_SUBDIR= vde
+EXTRACT_SUFX= .tgz
+
+MAINTAINER= craig@yekse.gank.org
+COMMENT= User-mode virtual ethernet infrastructure
+
+USE_GMAKE= yes
+USE_GETOPT_LONG=yes
+INSTALLS_SHLIB= yes
+
+.include <bsd.port.pre.mk>
+
+CFLAGS+= ${CPPFLAGS}
+MAKE_ENV+= LDFLAGS="${LDFLAGS}"
+
+MAN1= dpipe.1 slirpvde.1 vdetaplib.1 vdeq.1 vde_plug.1 vde_switch.1
+
+.include <bsd.port.post.mk>
diff --git a/net/vde2/distinfo b/net/vde2/distinfo
new file mode 100644
index 000000000000..9568b8f96dc9
--- /dev/null
+++ b/net/vde2/distinfo
@@ -0,0 +1,2 @@
+MD5 (vde-1.5.7.tgz) = f89a958a6997114b46abd66c00e217c8
+SIZE (vde-1.5.7.tgz) = 139314
diff --git a/net/vde2/files/patch-Makefile b/net/vde2/files/patch-Makefile
new file mode 100644
index 000000000000..5d0cf76b3e4b
--- /dev/null
+++ b/net/vde2/files/patch-Makefile
@@ -0,0 +1,40 @@
+--- Makefile Sat Jan 29 15:02:08 2005
++++ Makefile Sun Jan 30 13:46:59 2005
+@@ -1,14 +1,15 @@
+-TUNTAP = $(shell [ -e /usr/include/linux/if_tun.h ] && echo -DTUNTAP)
++TUNTAP = $(shell [ -e /usr/include/net/if_tun.h ] && echo -DTUNTAP)
+
+ OBJSSW = hash.o port.o vde_switch.o tuntap.o
+ BINSW = vde_switch
+ BIN = $(BINSW) dpipe vde_plug
+ #CFLAGS = -g -Wall $(TUNTAP) -DINFO -O3
+-CFLAGS = -Wall $(TUNTAP) -O3
++CFLAGS += -Wall $(TUNTAP) -O
+
+-BIN_DIR ?= /usr/local/bin
+-LIB_DIR ?= /usr/local/lib
+-MAN_DIR ?= /usr/local/man
++PREFIX ?= /usr/local
++BIN_DIR ?= $(PREFIX)/bin
++LIB_DIR ?= $(PREFIX)/lib
++MAN_DIR ?= $(PREFIX)/man
+
+ ifneq ($(TUNTAP),)
+ OBJS += tuntap.o
+@@ -30,13 +31,13 @@
+ vde_switch.o: vde_switch.c vde.h switch.h hash.h port.h tuntap.h
+
+ $(BINSW) : $(OBJSSW)
+- $(CC) $(CFLAGS) -o $(BINSW) $(OBJSSW)
++ $(CC) $(CFLAGS) $(LDFLAGS) -o $(BINSW) $(OBJSSW)
+
+ dpipe: dpipe.o
+- $(CC) $(CFLAGS) -o dpipe dpipe.o
++ $(CC) $(CFLAGS) $(LDFLAGS) -o dpipe dpipe.o
+
+ vde_plug: vde_plug.o
+- $(CC) $(CFLAGS) -o vde_plug vde_plug.o
++ $(CC) $(CFLAGS) $(LDFLAGS) -o vde_plug vde_plug.o
+
+ clean :
+ rm -f $(BIN) *.o *~
diff --git a/net/vde2/files/patch-hash.c b/net/vde2/files/patch-hash.c
new file mode 100644
index 000000000000..e4cdaef6e90b
--- /dev/null
+++ b/net/vde2/files/patch-hash.c
@@ -0,0 +1,23 @@
+--- hash.c Sat Jan 29 15:02:08 2005
++++ hash.c Sat Jan 29 15:08:18 2005
+@@ -14,7 +14,11 @@
+ #include <syslog.h>
+ #include <sys/types.h>
+ #include <sys/time.h>
++#ifdef __FreeBSD__
++#include <signal.h>
++#else
+ #include <sys/signal.h>
++#endif
+ #include "switch.h"
+ #include "hash.h"
+
+@@ -129,7 +133,7 @@
+ printf("Hash: %d Addr: %02x:%02x:%02x:%02x:%02x:%02x to port: %s "
+ "age %ld secs\n", calc_hash(e->dst),
+ e->dst[0], e->dst[1], e->dst[2], e->dst[3], e->dst[4], e->dst[5],
+- (*p->port_id)(e->port), (int) p->now - e->last_seen);
++ (*p->port_id)(e->port), (long) p->now - e->last_seen);
+ }
+
+ void print_hash(char *(*port_id)(void *))
diff --git a/net/vde2/files/patch-port.c b/net/vde2/files/patch-port.c
new file mode 100644
index 000000000000..02d2359c0e15
--- /dev/null
+++ b/net/vde2/files/patch-port.c
@@ -0,0 +1,34 @@
+--- port.c Sat Jan 29 15:02:08 2005
++++ port.c Sun Jan 30 11:36:03 2005
+@@ -10,6 +10,9 @@
+ #include <syslog.h>
+ #include <sys/socket.h>
+ #include <sys/un.h>
++#ifdef __FreeBSD__
++#include <string.h>
++#endif
+ #include "switch.h"
+ #include "hash.h"
+ #include "port.h"
+@@ -316,10 +319,19 @@
+ port=p->data;
+ //if(match_sock(p->control, fd, p->data, p->data_len, &data)) break;
+ if(p->data_len == sizeof(struct sock_data) &&
+- !(memcmp(&(port->sock), &mine->sock, sizeof(mine->sock)))) break;
++#ifdef __FreeBSD__
++ port->sock.sun_family == mine->sock.sun_family &&
++ !(strcmp(port->sock.sun_path, mine->sock.sun_path)))
++#else
++ !(memcmp(&(port->sock), &mine->sock, sizeof(mine->sock))))
++#endif
++ break;
+ }
+ }
+- handle_direct_data(p,hub,&packet,len);
++ if (i < g_nfds)
++ handle_direct_data(p,hub,&packet,len);
++ else
++ printlog(LOG_WARNING, "No port associated with descriptor %d", fd);
+ return 0;
+ }
+
diff --git a/net/vde2/files/patch-qemu::Makefile b/net/vde2/files/patch-qemu::Makefile
new file mode 100644
index 000000000000..1b460436f1d3
--- /dev/null
+++ b/net/vde2/files/patch-qemu::Makefile
@@ -0,0 +1,8 @@
+--- qemu/Makefile Sat Jan 29 15:02:08 2005
++++ qemu/Makefile Sun Jan 30 12:59:52 2005
+@@ -1,4 +1,4 @@
+-ALL: vdeq
++all: vdeq
+
+ vdeq.o: vdeq.c ../vde.h
+
diff --git a/net/vde2/files/patch-qemu::vdeq.c b/net/vde2/files/patch-qemu::vdeq.c
new file mode 100644
index 000000000000..9c34761c145e
--- /dev/null
+++ b/net/vde2/files/patch-qemu::vdeq.c
@@ -0,0 +1,103 @@
+--- qemu/vdeq.c Sat Jan 29 15:02:08 2005
++++ qemu/vdeq.c Sun Jan 30 13:31:46 2005
+@@ -7,14 +7,20 @@
+ #include <signal.h>
+ #include <errno.h>
+ #include <unistd.h>
++#ifndef __FreeBSD__
+ #include <stdint.h>
++#endif
+ #include <libgen.h>
+ #include <sys/ioctl.h>
+ #include <sys/socket.h>
+ #include <sys/un.h>
+ #include <sys/uio.h>
+ #include <sys/poll.h>
++#ifdef __FreeBSD__
++#include <string.h>
++#include <sys/time.h>
+ #include "../vde.h"
++#endif
+
+ #define SWITCH_MAGIC 0xfeedface
+ #define BUFSIZE 2048
+@@ -29,6 +35,15 @@
+ struct sockaddr_un sock;
+ };
+
++#ifdef __FreeBSD__
++static char *data_socket = NULL;
++
++static void cleanup()
++{
++ if(data_socket != NULL)
++ unlink(data_socket);
++}
++#endif
+
+ static int send_fd(char *name, int fddata, struct sockaddr_un *datasock, int intno, int group)
+ {
+@@ -37,6 +52,9 @@
+ int fdctl;
+
+ struct sockaddr_un sock;
++#ifdef __FreeBSD__
++ struct timeval tv;
++#endif
+
+ if((fdctl = socket(AF_UNIX, SOCK_STREAM, 0)) < 0){
+ perror("socket");
+@@ -56,7 +74,14 @@
+
+ req.sock.sun_family=AF_UNIX;
+ memset(req.sock.sun_path, 0, sizeof(req.sock.sun_path));
++#ifdef __FreeBSD__
++ gettimeofday(&tv, NULL);
++ snprintf(req.sock.sun_path, sizeof(req.sock.sun_path), "%s.%i.%li",
++ VDEDATSOCK, pid, tv.tv_usec);
++ data_socket = strdup(req.sock.sun_path);
++#else
+ sprintf(&req.sock.sun_path[1], "%5d-%2d", pid, intno);
++#endif
+
+ if(bind(fddata, (struct sockaddr *) &req.sock, sizeof(req.sock)) < 0){
+ perror("bind");
+@@ -111,20 +136,23 @@
+ static void leave()
+ {
+ fprintf(stderr,"qemu exited: %s quits\n", vdeqname);
++#ifdef __FreeBSD__
++ cleanup(0, NULL);
++#endif
+ exit(0);
+ }
+
+ int main(int argc, char **argv)
+ {
+ int *fddata;
+- char *argsock,**sockname;
++ char *argsock = NULL,**sockname;
+ struct sockaddr_un *dataout,datain;
+ int datainsize;
+ int result;
+ int group=0;
+ int *connected_fd;
+ register ssize_t nx;
+- int args;
++ int args = 0;
+ int newargc;
+ char **newargv;
+ typedef int pair[2];
+@@ -154,10 +182,10 @@
+ )) {
+ usage();
+ } else if (argc > args+1 &&
+- (strcmp(argv[args],"-vdesock")==0) ||
++ ((strcmp(argv[args],"-vdesock")==0) ||
+ (strcmp(argv[args],"-sock")==0) ||
+ (strcmp(argv[args],"-unix")==0) ||
+- (strcmp(argv[args],"-s")==0)
++ (strcmp(argv[args],"-s")==0))
+ ){
+ argsock=argv[args+1];
+ args+=2;
diff --git a/net/vde2/files/patch-slirpvde::Makefile b/net/vde2/files/patch-slirpvde::Makefile
new file mode 100644
index 000000000000..05f3bea2367d
--- /dev/null
+++ b/net/vde2/files/patch-slirpvde::Makefile
@@ -0,0 +1,20 @@
+--- slirpvde/Makefile Sat Jan 29 15:02:08 2005
++++ slirpvde/Makefile Sun Jan 30 14:02:57 2005
+@@ -3,7 +3,7 @@
+ tcp_timer.o udp.o \
+ bootp.o
+
+-CFLAGS=-I. -DVDE
++CFLAGS+=-I. -DVDE
+
+ all: libslirp.a slirpvde
+
+@@ -34,7 +34,7 @@
+ udp.o: udp.c ip_icmp.h
+
+ slirpvde: slirpvde.o libslirp.a
+- $(CC) -o slirpvde slirpvde.o libslirp.a
++ $(CC) $(LDFLAGS) -o slirpvde slirpvde.o libslirp.a
+
+ clean:
+ rm -rf *.o slirpvde libslirp.a
diff --git a/net/vde2/files/patch-slirpvde::ip.h b/net/vde2/files/patch-slirpvde::ip.h
new file mode 100644
index 000000000000..7f19d53739d6
--- /dev/null
+++ b/net/vde2/files/patch-slirpvde::ip.h
@@ -0,0 +1,34 @@
+--- slirpvde/ip.h Sat Jan 29 15:02:08 2005
++++ slirpvde/ip.h Sun Jan 30 14:00:32 2005
+@@ -37,6 +37,31 @@
+ #ifndef _IP_H_
+ #define _IP_H_
+
++#ifdef __FreeBSD__
++#include <sys/endian.h>
++
++#if !defined(__BYTE_ORDER)
++#if defined(_BYTE_ORDER)
++#define __BYTE_ORDER _BYTE_ORDER
++#elif defined(BYTE_ORDER)
++#define __BYTE_ORDER BYTE_ORDER
++#else
++#error BYTE_ORDER not defined
++#endif
++#endif /* !defined(__BYTE_ORDER) */
++
++#if !defined(__BIG_ENDIAN)
++#if defined(_BIG_ENDIAN)
++#define __BIG_ENDIAN _BIG_ENDIAN
++#elif defined(BIG_ENDIAN)
++#define __BIG_ENDIAN BIG_ENDIAN
++#else
++#error BIG_ENDIAN not defined
++#endif
++#endif /* !defined(__BIG_ENDIAN) */
++
++#endif /* __FreeBSD__ */
++
+ #if __BYTE_ORDER == __BIG_ENDIAN
+ # ifndef NTOHL
+ # define NTOHL(d)
diff --git a/net/vde2/files/patch-slirpvde::libslirp.h b/net/vde2/files/patch-slirpvde::libslirp.h
new file mode 100644
index 000000000000..b8a62739b93f
--- /dev/null
+++ b/net/vde2/files/patch-slirpvde::libslirp.h
@@ -0,0 +1,14 @@
+--- slirpvde/libslirp.h Sat Jan 29 15:02:08 2005
++++ slirpvde/libslirp.h Sun Jan 30 13:55:31 2005
+@@ -2,7 +2,11 @@
+ #define _LIBSLIRP_H
+
+ #include <sys/select.h>
++#ifdef __FreeBSD__
++#include <sys/types.h>
++#else
+ #include <stdint.h>
++#endif
+
+ void slirp_init(char *network);
+
diff --git a/net/vde2/files/patch-slirpvde::slirp_config.h b/net/vde2/files/patch-slirpvde::slirp_config.h
new file mode 100644
index 000000000000..dfd1288b6c2e
--- /dev/null
+++ b/net/vde2/files/patch-slirpvde::slirp_config.h
@@ -0,0 +1,33 @@
+--- slirpvde/slirp_config.h Sat Jan 29 15:02:08 2005
++++ slirpvde/slirp_config.h Sat Jan 29 15:15:18 2005
+@@ -61,10 +61,18 @@
+ #define HAVE_STDLIB_H
+
+ /* Define if you have sys/ioctl.h */
++#ifdef __FreeBSD__
++#define HAVE_SYS_IOCTL_H
++#else
+ #undef HAVE_SYS_IOCTL_H
++#endif
+
+ /* Define if you have sys/filio.h */
++#ifdef __FreeBSD__
++#define HAVE_SYS_FILIO_H
++#else
+ #undef HAVE_SYS_FILIO_H
++#endif
+
+ /* Define if you have strerror */
+ #define HAVE_STRERROR
+@@ -162,7 +170,11 @@
+ #define HAVE_MEMMOVE
+
+ /* Define if you have <termios.h> */
++#ifdef __FreeBSD__
++#define HAVE_TERMIOS_H
++#else
+ #undef HAVE_TERMIOS_H
++#endif
+
+ /* Define if you have gethostid */
+ #undef HAVE_GETHOSTID
diff --git a/net/vde2/files/patch-slirpvde::slirpvde.c b/net/vde2/files/patch-slirpvde::slirpvde.c
new file mode 100644
index 000000000000..f76790701b07
--- /dev/null
+++ b/net/vde2/files/patch-slirpvde::slirpvde.c
@@ -0,0 +1,95 @@
+--- slirpvde/slirpvde.c Sat Jan 29 15:02:08 2005
++++ slirpvde/slirpvde.c Sun Jan 30 14:24:33 2005
+@@ -7,7 +7,9 @@
+ #include <signal.h>
+ #include <errno.h>
+ #include <unistd.h>
++#ifndef __FreeBSD__
+ #include <stdint.h>
++#endif
+ #include <libgen.h>
+ #include <sys/ioctl.h>
+ #include <sys/socket.h>
+@@ -16,6 +18,10 @@
+ #include <sys/poll.h>
+ #include <libslirp.h>
+ #include <getopt.h>
++#ifdef __FreeBSD__
++#include <string.h>
++#include <sys/time.h>
++#endif
+
+ #define SWITCH_MAGIC 0xfeedface
+ #define BUFSIZE 2048
+@@ -32,6 +38,25 @@
+ struct sockaddr_un sock;
+ };
+
++#ifdef __FreeBSD__
++#include "../vde.h"
++static char *data_socket = NULL;
++
++static void cleanup()
++{
++ if(data_socket != NULL)
++ unlink(data_socket);
++}
++
++static void sig_handler(int sig)
++{
++ fprintf(stderr, "Caught signal %d, cleaning up and exiting\n", sig);
++ cleanup(1,NULL);
++ signal(sig, SIG_DFL);
++ kill(getpid(), sig);
++}
++#endif
++
+ static int send_fd(char *name, int fddata, struct sockaddr_un *datasock, int group)
+ {
+ int pid = getpid();
+@@ -39,6 +64,9 @@
+ int fdctl;
+
+ struct sockaddr_un sock;
++#ifdef __FreeBSD__
++ struct timeval tv;
++#endif
+
+ if((fdctl = socket(AF_UNIX, SOCK_STREAM, 0)) < 0){
+ perror("socket");
+@@ -58,7 +86,14 @@
+
+ req.sock.sun_family=AF_UNIX;
+ memset(req.sock.sun_path, 0, sizeof(req.sock.sun_path));
++#ifdef __FreeBSD__
++ gettimeofday(&tv, NULL);
++ snprintf(req.sock.sun_path, sizeof(req.sock.sun_path), "%s.%i.%li",
++ VDEDATSOCK, pid, tv.tv_usec);
++ data_socket = strdup(req.sock.sun_path);
++#else
+ sprintf(&req.sock.sun_path[1], "%5d", pid);
++#endif
+
+ if(bind(fddata, (struct sockaddr *) &req.sock, sizeof(req.sock)) < 0){
+ perror("bind");
+@@ -149,7 +184,6 @@
+ int group=0;
+ int connected_fd;
+ register ssize_t nx;
+- register int i;
+ fd_set rs,ws,xs;
+ int opt,longindx;
+ char *netw=NULL;
+@@ -175,6 +209,12 @@
+ exit(1);
+ }
+ connected_fd=send_fd(sockname, fddata, &dataout, group);
++#ifdef __FreeBSD__
++ if(signal(SIGINT, sig_handler) < 0) {
++ perror("signal");
++ }
++ signal(SIGPIPE, SIG_IGN); /* FreeBSD 4.x sends SIGPIPE on reset sockets */
++#endif
+ slirp_init(netw);
+
+ for(;;) {
diff --git a/net/vde2/files/patch-slirpvde::tcp.h b/net/vde2/files/patch-slirpvde::tcp.h
new file mode 100644
index 000000000000..1dade2d0986c
--- /dev/null
+++ b/net/vde2/files/patch-slirpvde::tcp.h
@@ -0,0 +1,34 @@
+--- slirpvde/tcp.h Sat Jan 29 15:02:08 2005
++++ slirpvde/tcp.h Sun Jan 30 14:00:50 2005
+@@ -37,6 +37,31 @@
+ #ifndef _TCP_H_
+ #define _TCP_H_
+
++#ifdef __FreeBSD__
++#include <sys/endian.h>
++
++#if !defined(__BYTE_ORDER)
++#if defined(_BYTE_ORDER)
++#define __BYTE_ORDER _BYTE_ORDER
++#elif defined(BYTE_ORDER)
++#define __BYTE_ORDER BYTE_ORDER
++#else
++#error BYTE_ORDER not defined
++#endif
++#endif /* !defined(__BYTE_ORDER) */
++
++#if !defined(__BIG_ENDIAN)
++#if defined(_BIG_ENDIAN)
++#define __BIG_ENDIAN _BIG_ENDIAN
++#elif defined(BIG_ENDIAN)
++#define __BIG_ENDIAN BIG_ENDIAN
++#else
++#error BIG_ENDIAN not defined
++#endif
++#endif /* !defined(__BIG_ENDIAN) */
++
++#endif /* __FreeBSD__ */
++
+ typedef u_int32_t tcp_seq;
+
+ #define PR_SLOWHZ 2 /* 2 slow timeouts per second (approx) */
diff --git a/net/vde2/files/patch-tuntap.c b/net/vde2/files/patch-tuntap.c
new file mode 100644
index 000000000000..43b31617ea17
--- /dev/null
+++ b/net/vde2/files/patch-tuntap.c
@@ -0,0 +1,45 @@
+--- tuntap.c Sat Jan 29 15:02:08 2005
++++ tuntap.c Sun Jan 30 00:27:23 2005
+@@ -11,8 +11,16 @@
+ #include <unistd.h>
+ #include <syslog.h>
+ #include <sys/ioctl.h>
++#ifdef __FreeBSD__
++#include <sys/types.h>
++#include <sys/socket.h>
++#endif
+ #include <net/if.h>
++#ifdef __FreeBSD__
++#include <net/if_tun.h>
++#else
+ #include <linux/if_tun.h>
++#endif
+ #include "port.h"
+ #include "switch.h"
+
+@@ -28,13 +36,16 @@
+
+ int open_tap(char *dev)
+ {
++#ifndef __FreeBSD__
+ struct ifreq ifr;
++#endif
+ int fd;
+
+- if((fd = open("/dev/net/tun", O_RDWR)) < 0){
+- printlog(LOG_ERR,"Failed to open /dev/net/tun %s",strerror(errno));
++ if((fd = open(dev, O_RDWR)) < 0){
++ printlog(LOG_ERR,"Failed to open %s %s", dev, strerror(errno));
+ return(-1);
+ }
++#ifndef __FreeBSD__
+ memset(&ifr, 0, sizeof(ifr));
+ ifr.ifr_flags = IFF_TAP | IFF_NO_PI;
+ strncpy(ifr.ifr_name, dev, sizeof(ifr.ifr_name) - 1);
+@@ -43,5 +54,6 @@
+ close(fd);
+ return(-1);
+ }
++#endif
+ return(fd);
+ }
diff --git a/net/vde2/files/patch-vde.h b/net/vde2/files/patch-vde.h
new file mode 100644
index 000000000000..8097ca0bcce2
--- /dev/null
+++ b/net/vde2/files/patch-vde.h
@@ -0,0 +1,15 @@
+--- vde.h Sat Jan 29 15:02:08 2005
++++ vde.h Sun Jan 30 11:39:43 2005
+@@ -2,6 +2,12 @@
+ #define VDESTDSOCK "/tmp/vde.ctl"
+ #endif
+
++#ifdef __FreeBSD__
++#ifndef VDEDATSOCK
++#define VDEDATSOCK "/tmp/.vde.data"
++#endif
++#endif
++
+ #define DO_SYSLOG
+ #define VDE_IP_LOG
+
diff --git a/net/vde2/files/patch-vde_plug.c b/net/vde2/files/patch-vde_plug.c
new file mode 100644
index 000000000000..416291e4337e
--- /dev/null
+++ b/net/vde2/files/patch-vde_plug.c
@@ -0,0 +1,98 @@
+--- vde_plug.c Sat Jan 29 15:02:08 2005
++++ vde_plug.c Sun Jan 30 13:52:57 2005
+@@ -7,7 +7,9 @@
+ #include <signal.h>
+ #include <errno.h>
+ #include <unistd.h>
++#ifndef __FreeBSD__
+ #include <stdint.h>
++#endif
+ #include <getopt.h>
+ #include <sys/ioctl.h>
+ #include <sys/socket.h>
+@@ -15,6 +17,11 @@
+ #include <sys/uio.h>
+ #include <sys/poll.h>
+ #include <sys/utsname.h>
++#ifdef __FreeBSD__
++#include <sys/time.h>
++#include <netinet/in.h>
++#include <string.h>
++#endif
+ #include "vde.h"
+ #ifdef VDE_IP_LOG
+ #define DO_SYSLOG
+@@ -47,6 +54,24 @@
+ static struct passwd *callerpwd;
+ static char host[256];
+
++#ifdef __FreeBSD__
++static char *data_socket = NULL;
++
++static void cleanup()
++{
++ if(data_socket != NULL)
++ unlink(data_socket);
++}
++
++static void sig_handler(int sig)
++{
++ fprintf(stderr, "Caught signal %d, cleaning up and exiting\n", sig);
++ cleanup(1,NULL);
++ signal(sig, SIG_DFL);
++ kill(getpid(), sig);
++}
++#endif
++
+ void write_syslog_entry(char *message)
+ {
+ char *ssh_client;
+@@ -183,6 +208,9 @@
+ int fdctl;
+
+ struct sockaddr_un sock;
++#ifdef __FreeBSD__
++ struct timeval tv;
++#endif
+
+ if((fdctl = socket(AF_UNIX, SOCK_STREAM, 0)) < 0){
+ perror("socket");
+@@ -202,7 +230,14 @@
+
+ req.sock.sun_family=AF_UNIX;
+ memset(req.sock.sun_path, 0, sizeof(req.sock.sun_path));
++#ifdef __FreeBSD__
++ gettimeofday(&tv, NULL);
++ snprintf(req.sock.sun_path, sizeof(req.sock.sun_path), "%s.%i.%li",
++ VDEDATSOCK, pid, tv.tv_usec);
++ data_socket = strdup(req.sock.sun_path);
++#else
+ sprintf(&req.sock.sun_path[1], "%5d", pid);
++#endif
+
+ if(bind(fddata, (struct sockaddr *) &req.sock, sizeof(req.sock)) < 0){
+ perror("bind");
+@@ -309,6 +344,10 @@
+ int connected_fd;
+ register ssize_t nx;
+
++#ifdef __FreeBSD__
++ atexit(cleanup);
++#endif
++
+ uname(&me);
+ if (argv[0][0] == '-')
+ netusage(); //implies exit
+@@ -383,6 +422,12 @@
+ }
+ connected_fd=send_fd(sockname, fddata, &dataout, group);
+ pollv[1].fd=fddata;
++
++#ifdef __FreeBSD__
++ if(signal(SIGINT, sig_handler) < 0) {
++ perror("signal");
++ }
++#endif
+
+ for(;;) {
+ result=poll(pollv,2,-1);
diff --git a/net/vde2/files/patch-vde_switch.c b/net/vde2/files/patch-vde_switch.c
new file mode 100644
index 000000000000..c95f04789071
--- /dev/null
+++ b/net/vde2/files/patch-vde_switch.c
@@ -0,0 +1,80 @@
+--- vde_switch.c Sat Jan 29 15:02:08 2005
++++ vde_switch.c Sun Jan 30 13:33:00 2005
+@@ -8,7 +8,9 @@
+ #include <stdlib.h>
+ #include <signal.h>
+ #include <fcntl.h>
++#ifndef __FreeBSD__
+ #include <stdint.h>
++#endif
+ #include <getopt.h>
+ #include <sys/socket.h>
+ #include <sys/un.h>
+@@ -17,7 +19,11 @@
+ #include <unistd.h>
+ #include <syslog.h>
+ #include <libgen.h>
++#ifdef __FreeBSD__
++#include <string.h>
++#else
+ #include <endian.h>
++#endif
+ #include "vde.h"
+ #include "switch.h"
+ #include "port.h"
+@@ -95,6 +101,13 @@
+ }
+ }
+
++#ifdef __FreeBSD__
++static void cleanupwrapper()
++{
++ cleanup(0, NULL);
++}
++#endif
++
+ void **g_fdsdata = NULL;
+ int g_nfds = 0;
+ int g_minfds = 0;
+@@ -276,19 +289,27 @@
+
+ void bind_data_socket(int fd, struct sockaddr_un *sun)
+ {
++ struct timeval tv;
++
++ sun->sun_family = AF_UNIX;
++#ifdef __FreeBSD__
++ gettimeofday(&tv, NULL);
++ snprintf(sun->sun_path, sizeof(sun->sun_path), "%s.%i.%li",
++ VDEDATSOCK, getpid(), tv.tv_usec);
++ data_socket = strdup(sun->sun_path);
++#else
+ struct {
+ char zero;
+ int pid;
+ int usecs;
+ } name;
+- struct timeval tv;
+
+ name.zero = 0;
+ name.pid = getpid();
+ gettimeofday(&tv, NULL);
+ name.usecs = tv.tv_usec;
+- sun->sun_family = AF_UNIX;
+ memcpy(sun->sun_path, &name, sizeof(name));
++#endif
+ if(bind(fd, (struct sockaddr *) sun, sizeof(*sun)) < 0){
+ printlog(LOG_ERR,"Binding to data socket %s",strerror(errno));
+ exit(1);
+@@ -338,7 +359,11 @@
+ int tap_fd = -1;
+ #endif
+
++#ifdef __FreeBSD__
++ atexit(cleanupwrapper);
++#else
+ on_exit(cleanup, NULL);
++#endif
+ prog = argv[0];
+ /* option parsing */
+ {
diff --git a/net/vde2/files/patch-vdetaplib::Makefile b/net/vde2/files/patch-vdetaplib::Makefile
new file mode 100644
index 000000000000..ff72703ce702
--- /dev/null
+++ b/net/vde2/files/patch-vdetaplib::Makefile
@@ -0,0 +1,11 @@
+--- vdetaplib/Makefile Sat Jan 29 15:02:08 2005
++++ vdetaplib/Makefile Sun Jan 30 12:21:39 2005
+@@ -9,7 +9,7 @@
+ all: vdetap libvdetap.so
+
+ libvdetap.so: libvdetap.a
+- $(LD) -E -o $@ -L./ -ldl -shared -export-dynamic -Bdynamic \
++ $(LD) -E -o $@ -L./ -shared -export-dynamic -Bdynamic \
+ --whole-archive libvdetap.a
+
+ libvdetap.a: libvdetap.o
diff --git a/net/vde2/files/patch-vdetaplib::libvdetap.c b/net/vde2/files/patch-vdetaplib::libvdetap.c
new file mode 100644
index 000000000000..7c304913b035
--- /dev/null
+++ b/net/vde2/files/patch-vdetaplib::libvdetap.c
@@ -0,0 +1,260 @@
+--- vdetaplib/libvdetap.c Sat Jan 29 15:02:08 2005
++++ vdetaplib/libvdetap.c Sun Jan 30 13:29:07 2005
+@@ -5,26 +5,39 @@
+ #include <sys/socket.h>
+ #include <sys/syscall.h>
+ #include <sys/stat.h>
++#include <limits.h>
++#include <dlfcn.h>
+ #include <stdarg.h>
+ #include <string.h>
+ #include <unistd.h>
+ #include <stdlib.h>
+-#define __USE_LARGEFILE64
+ #include <fcntl.h>
+ #include <errno.h>
+ #include <signal.h>
+-#include <linux/ioctl.h>
+-#include <linux/if.h>
+-#include <linux/if_tun.h>
++#include <stdio.h>
++#include <sys/ioctl.h>
++#include <net/if.h>
++#include <net/if_tun.h>
+
+-#define TUNTAPPATH "/dev/net/tun"
++#define TUNTAPPATH "/dev/tap"
+ #define VDETAPEXEC "vdetap"
+ #define VDEALLTAP "VDEALLTAP"
+ #define MAX 10
+
++#if defined(RTLD_NEXT)
++#define REAL_LIBC RTLD_NEXT
++#else
++#define REAL_LIBC ((void *) -1L)
++#endif
++
++#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__bsdi__)
++typedef unsigned long request_t;
++#else
++typedef int request_t;
++#endif
++
+ int tapfd[2] = {-1,-1};
+ static int tapcount=0;
+-static int tuncount=0;
+
+ static struct pidlist {
+ pid_t pid;
+@@ -39,11 +52,6 @@
+ return rv;
+ }
+
+-static void plfree (struct pidlist *el) {
+- el->next=flh;
+- flh=el;
+-}
+-
+ static int addpid(int pid) {
+ struct pidlist *plp;
+ if ((plp=plmalloc ()) != NULL) {
+@@ -74,105 +82,41 @@
+ }
+ }
+
+- int
+-native_open(const char *pathname, int flags, mode_t data)
+-{
+- return (syscall(SYS_open, pathname, flags, data));
+-}
+-
+- int
+-native_ioctl(int fd, unsigned long int command, char *data)
+-{
+- return (syscall(SYS_ioctl, fd, command, data));
+-}
+-
+-
+ int open(const char *path, int flags, ...)
+ {
+- static char buf[PATH_MAX];
++ static int (*func) (const char *, int, mode_t) = NULL;
++ char *vdesock;
++ int pid;
+ va_list ap;
+ mode_t data;
+
+- va_start(ap, flags);
+- data = va_arg(ap, mode_t);
+- va_end(ap);
+-
+- if (strcmp(path,TUNTAPPATH)==0 && tapfd[0] == -1) {
+- if (socketpair(PF_UNIX, SOCK_DGRAM, 0,tapfd) == 0) {
+- return tapfd[0];
+- }
+- else
+- return -1;
+-
+- } else
+- return native_open(path, flags, data);
+-}
+-
+-int open64(const char *path, int flags, ...)
+-{
+- static char buf[PATH_MAX];
+- va_list ap;
+- mode_t data;
++ if (!func)
++ func = (int (*) (const char *, int, mode_t))
++ dlsym (REAL_LIBC, "open");
+
+ va_start(ap, flags);
+- data = va_arg(ap, mode_t);
++ data = va_arg(ap, int);
+ va_end(ap);
+
+ if (strcmp(path,TUNTAPPATH)==0 && tapfd[0] == -1) {
+ if (socketpair(PF_UNIX, SOCK_DGRAM, 0,tapfd) == 0) {
+- return tapfd[0];
+- }
+- else
+- return -1;
+-
+- } else
+- return native_open(path, flags | O_LARGEFILE, data);
+-}
+-
+-int ioctl(int fd, unsigned long int command, ...)
+-{
+- va_list ap;
+- char *data;
+- char *vdesock;
+- int pid;
+-
+- va_start(ap, command);
+- data = va_arg(ap, char *);
+- va_end(ap);
+-
+- if (fd == tapfd[0]) {
+- if (command == TUNSETIFF) {
+- struct ifreq *ifr = (struct ifreq *) data;
+ char num[5];
+ char name[10];
+-
+- ifr->ifr_name[IFNAMSIZ-1] = '\0';
+- if (ifr->ifr_name[0] == 0) {
+- if (ifr->ifr_flags & IFF_TAP)
+- sprintf(name,"tap%d",tapcount++);
+- else
+- sprintf(name,"tun%d",tuncount++);
+- strncpy(ifr->ifr_name,name,IFNAMSIZ);
+- }
+- else if (strchr(ifr->ifr_name, '%') != NULL) {
+- sprintf(name,ifr->ifr_name,tapcount++);
+- strncpy(ifr->ifr_name,name,IFNAMSIZ);
+- }
+- if (ifr->ifr_flags & IFF_TAP &&
+- ((vdesock=getenv(ifr->ifr_name)) != NULL)
+- ||(vdesock=getenv(VDEALLTAP)) != NULL){
++ sprintf(name,"tap%d",tapcount++);
++ if (((vdesock=getenv(name)) != NULL)
++ ||(vdesock=getenv(VDEALLTAP)) != NULL){
+ if ((pid=fork()) < 0) {
+ close(tapfd[1]);
+ errno=EINVAL;
+ return -1;
+ } else if (pid > 0) { /*father*/
+- if(pid=addpid(pid) < 0) {
++ if((pid=addpid(pid)) < 0) {
+ close(tapfd[0]);
+ close(tapfd[1]);
+ return -1;
+ } else {
+ close(tapfd[1]);
+- return 0;
++ return tapfd[0];
+ }
+ } else { /*son*/
+ plh=NULL;
+@@ -181,34 +125,53 @@
+ execlp(VDETAPEXEC,"-",num,vdesock,(char *) 0);
+ }
+ }
+- else /*roll back to the native tuntap*/
+- {
+- int newfd;
+- int saverrno;
+- int resultioctl;
+- close(tapfd[1]);
+- if ((newfd=native_open(TUNTAPPATH, O_RDWR, 0)) < 0) {
+- saverrno=errno;
+- close(tapfd[0]);
+- errno=saverrno;
+- return -1;
+- } else
+- {
+- resultioctl=native_ioctl(fd, command, data);
+- if (resultioctl < 0) {
+- saverrno=errno;
+- close(tapfd[0]);
+- errno=saverrno;
+- return -1;
+- } else {
+- dup2(newfd,tapfd[0]);
+- return resultioctl;
+- }
+- }
+- }
+- } else
+- return 0;
++ return tapfd[0];
++ }
++ else
++ return -1;
++
+ } else
+- return (native_ioctl(fd, command, data));
++ return (*func)(path, flags, data);
++}
++
++int ioctl(int fd, unsigned long int command, ...)
++{
++ static int (*func) (int, request_t, void *) = NULL;
++ int dummy;
++ va_list ap;
++ char *data;
++ struct ifstat *ifs;
++
++ if (!func)
++ func = (int (*) (int, request_t, void *))
++ dlsym (REAL_LIBC, "ioctl");
++
++ va_start(ap, command);
++ data = va_arg(ap, char *);
++ va_end(ap);
++
++ if (fd == tapfd[0]) {
++ switch(command) {
++ case SIOCSIFFLAGS:
++ case SIOCADDMULTI:
++ case SIOCDELMULTI:
++ break;
++
++ case SIOCGIFSTATUS:
++ ifs = (struct ifstat *)data;
++ dummy = strlen(ifs->ascii);
++ if(plh && dummy < sizeof(ifs->ascii))
++ snprintf(ifs->ascii + dummy,
++ sizeof(ifs->ascii) - dummy,
++ "\tOpened by PID %d\n",
++ plh[0].pid);
++ break;
++
++ default:
++ return (*func) (fd, command, data);
++ }
++ }
++
++ return (*func) (fd, command, data);
+ }
+
diff --git a/net/vde2/files/patch-vdetaplib::test.c b/net/vde2/files/patch-vdetaplib::test.c
new file mode 100644
index 000000000000..d26ffa326253
--- /dev/null
+++ b/net/vde2/files/patch-vdetaplib::test.c
@@ -0,0 +1,46 @@
+--- vdetaplib/test.c Sat Jan 29 15:02:08 2005
++++ vdetaplib/test.c Sun Jan 30 12:27:35 2005
+@@ -6,35 +6,28 @@
+ #include <errno.h>
+ #include <string.h>
+ #include <unistd.h>
++#include <sys/types.h>
+ #include <sys/ioctl.h>
++#include <sys/socket.h>
+ #include <net/if.h>
+-#include <linux/if_tun.h>
++#include <net/if_tun.h>
+
+ static int tun_alloc(char *dev)
+ {
+- struct ifreq ifr;
++ struct ifstat ifs;
+ int fd, err;
+
+- if( (fd = open("/dev/net/tun", O_RDWR)) < 0 )
++ if( (fd = open("/dev/tap", O_RDWR)) < 0 )
+ return (-1);
+
+- memset(&ifr, 0, sizeof(ifr));
++ memset(&ifs, 0, sizeof(ifs));
+
+- /* Flags: IFF_TUN - TUN device (no Ethernet headers)
+- * IFF_TAP - TAP device
+- *
+- * IFF_NO_PI - Do not provide packet information
+- */
+- ifr.ifr_flags = IFF_TAP;
+- if( *dev )
+- strncpy(ifr.ifr_name, dev, IFNAMSIZ);
+-
+- if( (err = ioctl(fd, TUNSETIFF, (void *) &ifr)) < 0 ){
++ if( (err = ioctl(fd, SIOCGIFSTATUS, (void *) &ifs)) < 0 ){
+ close(fd);
+ return err;
+ }
+ printf("ioctl returns\n");
+- strcpy(dev, ifr.ifr_name);
++ puts(ifs.ascii);
+ printf("ioctl idev\n");
+ return fd;
+ }
diff --git a/net/vde2/files/patch-vdetaplib::vdetap.c b/net/vde2/files/patch-vdetaplib::vdetap.c
new file mode 100644
index 000000000000..3e5ded1cc07b
--- /dev/null
+++ b/net/vde2/files/patch-vdetaplib::vdetap.c
@@ -0,0 +1,107 @@
+--- vdetaplib/vdetap.c Sat Jan 29 15:02:08 2005
++++ vdetaplib/vdetap.c Sun Jan 30 14:05:26 2005
+@@ -2,11 +2,25 @@
+ * Reseased under the GPLv2 */
+
+ #include <stdio.h>
++#ifndef __FreeBSD__
+ #include <stdint.h>
++#endif
++#ifdef __FreeBSD__
++#include <sys/types.h>
++#include <sys/time.h>
++#include <unistd.h>
++#else
+ #include <sys/select.h>
++#endif
+ #include <sys/poll.h>
+ #include <sys/socket.h>
+ #include <sys/un.h>
++#ifdef __FreeBSD__
++#include "../vde.h"
++#include <signal.h>
++#include <stdlib.h>
++#include <string.h>
++#endif
+
+ #define SWITCH_MAGIC 0xfeedface
+ #define BUFSIZE 2048
+@@ -21,6 +35,23 @@
+
+ static unsigned char bufin[BUFSIZE];
+
++#ifdef __FreeBSD__
++static char *data_socket = NULL;
++
++static void cleanup()
++{
++ if(data_socket != NULL)
++ unlink(data_socket);
++}
++
++static void sig_handler(int sig)
++{
++ cleanup(1, NULL);
++ signal(sig, SIG_DFL);
++ kill(getpid(), sig);
++}
++#endif
++
+ static int send_fd(char *name, int fddata, struct sockaddr_un *datasock, int intno, int group)
+ {
+ int pid = getpid();
+@@ -28,6 +59,9 @@
+ int fdctl;
+
+ struct sockaddr_un sock;
++#ifdef __FreeBSD__
++ struct timeval tv;
++#endif
+
+ if((fdctl = socket(AF_UNIX, SOCK_STREAM, 0)) < 0){
+ perror("socket");
+@@ -47,7 +81,14 @@
+
+ req.sock.sun_family=AF_UNIX;
+ memset(req.sock.sun_path, 0, sizeof(req.sock.sun_path));
++#ifdef __FreeBSD__
++ gettimeofday(&tv, NULL);
++ snprintf(req.sock.sun_path, sizeof(req.sock.sun_path), "%s.%i.%li",
++ VDEDATSOCK, pid, tv.tv_usec);
++ data_socket = strdup(req.sock.sun_path);
++#else
+ sprintf(&req.sock.sun_path[1], "%5d-%2d", pid, intno);
++#endif
+
+ if(bind(fddata, (struct sockaddr *) &req.sock, sizeof(req.sock)) < 0){
+ perror("bind");
+@@ -69,7 +110,7 @@
+
+ static struct pollfd pollv[]={{0,POLLIN|POLLHUP,0},{0,POLLIN|POLLHUP,0}};
+
+-main(int argc,char *argv[])
++int main(int argc,char *argv[])
+ {
+ int fd,fddata;
+ struct sockaddr_un dataout,datain;
+@@ -96,6 +137,12 @@
+ send_fd(argv[2],fddata,&dataout,0,0);
+ pollv[0].fd=fd;
+ pollv[1].fd=fddata;
++
++#ifdef __FreeBSD__
++ if(signal(SIGINT, sig_handler) < 0) {
++ perror("signal");
++ }
++#endif
+ for(;;) {
+ result=poll(pollv,2,-1);
+ if (pollv[0].revents & POLLHUP || pollv[1].revents & POLLHUP)
+@@ -113,5 +160,7 @@
+ write(fd,bufin,nx);
+ }
+ }
++ cleanup(0, NULL);
++ return 0;
+ }
+
diff --git a/net/vde2/pkg-descr b/net/vde2/pkg-descr
new file mode 100644
index 000000000000..0787b5b905df
--- /dev/null
+++ b/net/vde2/pkg-descr
@@ -0,0 +1,7 @@
+Virtual Distributed Ethernet is a user-mode virtual network (layer
+2) infrastructure. It can be used for network simulations, joining
+multiple qemu instances together in a shared virtual network, or
+tunneling over the Internet. Physical hosts can be joined to the
+virtual network by means of the tap(4) driver.
+
+WWW: http://vde.sourceforge.net/
diff --git a/net/vde2/pkg-plist b/net/vde2/pkg-plist
new file mode 100644
index 000000000000..5d6c79f75ade
--- /dev/null
+++ b/net/vde2/pkg-plist
@@ -0,0 +1,8 @@
+bin/dpipe
+bin/slirpvde
+bin/vde_plug
+bin/vde_switch
+bin/vdeq
+bin/vdeqemu
+bin/vdetap
+lib/libvdetap.so