2 * Worldvisions Weaver Software:
3 * Copyright (C) 1997-2002 Net Integration Technologies, Inc.
5 * WvTunDev provides a convenient way of using Linux tunnel devices.
7 * If you don't have the /dev/net/tun device, try doing:
8 * mknod /dev/net/tun c 10 200
10 #include <sys/ioctl.h>
11 #include <sys/socket.h>
18 WvTunDev::WvTunDev(const WvIPNet
&addr
, int mtu
) :
19 WvFile("/dev/net/tun", O_RDWR
)
24 void WvTunDev::init(const WvIPNet
&addr
, int mtu
)
26 WvLog
log("New tundev", WvLog::Debug2
);
29 log("Could not open /dev/net/tun: %s\n", strerror(errno
));
35 memset(&ifr
, 0, sizeof(ifr
));
36 ifr
.ifr_flags
= IFF_NO_PI
| IFF_TUN
;
38 if (ioctl(getfd(), TUNSETIFF
, (void *) &ifr
) < 0 ||
39 ioctl(getfd(), TUNSETNOCSUM
, 1) < 0)
41 log("Could not initialize the interface: %s\n", strerror(errno
));
46 WvInterface
iface(ifr
.ifr_name
);
47 iface
.setipaddr(addr
);
50 ifcname
= ifr
.ifr_name
;
53 log(WvLog::Debug2
, "Now up (%s).\n", addr
);