10 #include <sys/ioctl.h>
11 #include <sys/socket.h>
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));
47 iface.setipaddr(addr);
53 log(WvLog::Debug2,
"Now up (%s).\n", addr);
An IP network comprises two WvIPAddr structures: an address and a netmask.
WvFile implements a stream connected to a file or Unix device.
static WvString strerror(int errnum)
A replacement for the operating system ::strerror() function that can map more kinds of error strings...
virtual void seterr(int _errnum)
Override seterr() from WvError so that it auto-closes the stream.
A WvLog stream accepts log messages from applications and forwards them to all registered WvLogRcv's.
int getfd() const
Returns the Unix file descriptor for reading and writing.
A WvInterface manages a particular network interface.
WvTunDev(const WvIPNet &addr, int mtu=1400)
Creates a tunnel device and its associated interface.
WvString ifcname
Contains the name of the interface associated with the device.