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
34 #include "openvpn/config.h"
35 #include "openvpn/syshead.h"
36 #include "openvpn/tun.h"
39 #include "tunDevice.h"
42 TunDevice::TunDevice(const char* dev_name
, const char* ifcfg_lp
, const char* ifcfg_rnmp
)
49 strcpy(dev_name_
,dev_name
);
51 // init_tun (const char *dev, /* --dev option */
52 // const char *dev_type, /* --dev-type option */
53 // const char *ifconfig_local_parm, /* --ifconfig parm 1 */
54 // const char *ifconfig_remote_netmask_parm, /* --ifconfig parm 2 */
55 // in_addr_t local_public,
56 // in_addr_t remote_public,
57 // const bool strict_warn,
58 // struct env_set *es)
60 // init_tun_post (struct tuntap *tt,
61 // const struct frame *frame,
62 // const struct tuntap_options *options)
64 // -------------------------------------------
66 // c->c1.tuntap = init_tun (c->options.dev,
67 // c->options.dev_type,
68 // c->options.ifconfig_local,
69 // c->options.ifconfig_remote_netmask,
70 // addr_host (&c->c1.link_socket_addr.local),
71 // addr_host (&c->c1.link_socket_addr.remote),
72 // !c->options.ifconfig_nowarn,
75 // init_tun_post (c->c1.tuntap,
77 // &c->options.tuntap_options);
81 // lp = inet_addr("192.168.198.1");
82 // rp = inet_addr("192.168.199.1");
84 dev_
= init_tun(dev_name
, NULL
, ifcfg_lp
, ifcfg_rnmp
, lp
, rp
, 0, NULL
);
85 //init_tun_post(dev_, NULL, NULL);
87 throw std::runtime_error("can't init tun");
90 TunDevice::~TunDevice()
96 void TunDevice::open()
100 // open_tun (const char *dev,
101 // const char *dev_type,
102 // const char *dev_node,
104 // struct tuntap *tt)
106 // ------------------------
108 // open_tun (c->options.dev,
109 // c->options.dev_type,
110 // c->options.dev_node,
111 // c->options.tun_ipv6,
114 open_tun (dev_name_
, NULL
, NULL
, false, dev_
);
115 do_ifconfig(dev_
, dev_
->actual_name
, 1500, NULL
);
119 void TunDevice::close()
126 bool TunDevice::isOpen()
131 int TunDevice::read(Buffer
& buf
)
136 return read_tun(dev_
, buf
, buf
.getLength());
139 int TunDevice::write(Buffer
& buf
)
144 return write_tun(dev_
, buf
, buf
.getLength());
147 char* TunDevice::getActualName()
152 return dev_
->actual_name
;