WvStreams
Main Page
Modules
Classes
Files
File List
File Members
linuxstreams
wvtundev.cc
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.
6
*
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>
14
15
#include "wvlog.h"
16
#include "wvtundev.h"
17
18
WvTunDev::WvTunDev
(
const
WvIPNet
&addr,
int
mtu) :
19
WvFile
(
"/dev/net/tun"
, O_RDWR)
20
{
21
init(addr, mtu);
22
}
23
24
void
WvTunDev::init(
const
WvIPNet
&addr,
int
mtu)
25
{
26
WvLog
log(
"New tundev"
, WvLog::Debug2);
27
if
(
getfd
() < 0)
28
{
29
log(
"Could not open /dev/net/tun: %s\n"
,
strerror
(errno));
30
seterr
(errno);
31
return
;
32
}
33
34
struct
ifreq ifr;
35
memset(&ifr, 0,
sizeof
(ifr));
36
ifr.ifr_flags = IFF_NO_PI | IFF_TUN;
37
38
if
(ioctl(
getfd
(), TUNSETIFF, (
void
*) &ifr) < 0 ||
39
ioctl(
getfd
(), TUNSETNOCSUM, 1) < 0)
40
{
41
log(
"Could not initialize the interface: %s\n"
,
strerror
(errno));
42
seterr
(errno);
43
return
;
44
}
45
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
;
52
53
log(WvLog::Debug2,
"Now up (%s).\n"
, addr);
54
}
Generated on Mon Jul 16 2012 13:15:40 for WvStreams by
1.8.1.1