Make WvStreams compile with gcc 4.4.
[wvstreams.git] / linuxstreams / wvtundev.cc
blob586838405397c5a3f8dde5de97f514e7cbd8558a
1 /*
2 * Worldvisions Weaver Software:
3 * Copyright (C) 1997-2002 Net Integration Technologies, Inc.
4 *
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
9 */
10 #include <sys/ioctl.h>
11 #include <sys/socket.h>
12 #include "if_tun.h"
13 #include <string.h>
15 #include "wvlog.h"
16 #include "wvtundev.h"
18 WvTunDev::WvTunDev(const WvIPNet &addr, int mtu) :
19 WvFile("/dev/net/tun", O_RDWR)
21 init(addr, mtu);
24 void WvTunDev::init(const WvIPNet &addr, int mtu)
26 WvLog log("New tundev", WvLog::Debug2);
27 if (getfd() < 0)
29 log("Could not open /dev/net/tun: %s\n", strerror(errno));
30 seterr(errno);
31 return;
34 struct ifreq ifr;
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));
42 seterr(errno);
43 return;
46 WvInterface iface(ifr.ifr_name);
47 iface.setipaddr(addr);
48 iface.setmtu(mtu);
49 iface.up(true);
50 ifcname = ifr.ifr_name;
51 log.app = ifcname;
53 log(WvLog::Debug2, "Now up (%s).\n", addr);