4 * The secure anycast tunneling protocol (satp) defines a protocol used
5 * for communication between any combination of unicast and anycast
6 * tunnel endpoints. It has less protocol overhead than IPSec in Tunnel
7 * mode and allows tunneling of every ETHER TYPE protocol (e.g.
8 * ethernet, ip, arp ...). satp directly includes cryptography and
9 * message authentication based on the methodes used by SRTP. It is
10 * intended to deliver a generic, scaleable and secure solution for
11 * tunneling and relaying of packets of any protocol.
14 * Copyright (C) 2007 anytun.org <satp@wirdorange.org>
16 * This program is free software; you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License version 2
18 * as published by the Free Software Foundation.
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
25 * You should have received a copy of the GNU General Public License
26 * along with this program (see the file COPYING included with this
27 * distribution); if not, write to the Free Software Foundation, Inc.,
28 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
35 #include "openvpn/config.h"
36 #include "openvpn/syshead.h"
37 #include "openvpn/tun.h"
40 #include "tunDevice.h"
43 TunDevice::TunDevice(const char* dev_name
, const char* ifcfg_lp
, const char* ifcfg_rnmp
)
47 // init_tun (const char *dev, /* --dev option */
48 // const char *dev_type, /* --dev-type option */
49 // const char *ifconfig_local_parm, /* --ifconfig parm 1 */
50 // const char *ifconfig_remote_netmask_parm, /* --ifconfig parm 2 */
51 // in_addr_t local_public,
52 // in_addr_t remote_public,
53 // const bool strict_warn,
54 // struct env_set *es)
56 // init_tun_post (struct tuntap *tt,
57 // const struct frame *frame,
58 // const struct tuntap_options *options)
60 // open_tun (const char *dev,
61 // const char *dev_type,
62 // const char *dev_node,
66 // -------------------------------------------
68 // c->c1.tuntap = init_tun (c->options.dev,
69 // c->options.dev_type,
70 // c->options.ifconfig_local,
71 // c->options.ifconfig_remote_netmask,
72 // addr_host (&c->c1.link_socket_addr.local),
73 // addr_host (&c->c1.link_socket_addr.remote),
74 // !c->options.ifconfig_nowarn,
77 // init_tun_post (c->c1.tuntap,
79 // &c->options.tuntap_options);
81 // open_tun (c->options.dev,
82 // c->options.dev_type,
83 // c->options.dev_node,
84 // c->options.tun_ipv6,
91 // lp = inet_addr("192.168.198.1");
92 // rp = inet_addr("192.168.199.1");
94 dev_
= init_tun(dev_name
, NULL
, ifcfg_lp
, ifcfg_rnmp
, lp
, rp
, 0, NULL
);
95 //init_tun_post(dev_, NULL, NULL);
97 throw std::runtime_error("can't init tun/tap device");
99 open_tun (dev_name
, NULL
, NULL
, false, dev_
);
100 do_ifconfig(dev_
, dev_
->actual_name
, 1500, NULL
);
103 TunDevice::~TunDevice()
109 short TunDevice::read(Buffer
& buf
)
114 struct pollfd pfd
[1];
115 pfd
[0].fd
= tun_event_handle(dev_
);
116 // pfd[0].events = POLLIN | POLLRDNORM | POLLRDBAND | POLLPRI | POLLOUT | POLLWRNORM | POLLWRBAND | POLLERR | POLLHUP | POLLNVAL;
117 pfd
[0].events
= POLLIN
| POLLRDNORM
| POLLRDBAND
| POLLPRI
;
119 return pfd
[0].revents
;//read_tun(dev_, buf, buf.getLength());
122 int TunDevice::write(Buffer
& buf
)
127 return write_tun(dev_
, buf
, buf
.getLength());
130 char* TunDevice::getActualName()
135 return dev_
->actual_name
;
138 char* TunDevice::getType()
145 case DEV_TYPE_UNDEF
: return "undef"; break;
146 case DEV_TYPE_TUN
: return "tun"; break;
147 case DEV_TYPE_TAP
: return "tap"; break;