11#include <sys/socket.h>
19 WvFile(
"/dev/net/tun", O_RDWR)
24void 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);
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 (...
int getfd() const
Returns the Unix file descriptor for reading and writing.
WvFile()
Create an empty WvFile that you'll open later with open().
An IP network comprises two WvIPAddr structures: an address and a netmask.
A WvLog stream accepts log messages from applications and forwards them to all registered WvLogRcv's.
virtual void seterr(int _errnum)
Override seterr() from WvError so that it auto-closes the stream.
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.