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