1 | /* |
1 | /* |
2 | device-tincd.C -- include one of the tincd low level implementations. |
2 | device-tincd.C -- include one of the tincd low level implementations. |
3 | Copyright (C) 2003-2004 Marc Lehmann <pcg@goof.com> |
3 | Copyright (C) 2003-2005 Marc Lehmann <gvpe@schmorp.de> |
4 | |
4 | |
|
|
5 | This file is part of GVPE. |
|
|
6 | |
5 | This program is free software; you can redistribute it and/or modify |
7 | GVPE is free software; you can redistribute it and/or modify |
6 | it under the terms of the GNU General Public License as published by |
8 | it under the terms of the GNU General Public License as published by |
7 | the Free Software Foundation; either version 2 of the License, or |
9 | the Free Software Foundation; either version 2 of the License, or |
8 | (at your option) any later version. |
10 | (at your option) any later version. |
9 | |
11 | |
10 | This program is distributed in the hope that it will be useful, |
12 | This program is distributed in the hope that it will be useful, |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 | GNU General Public License for more details. |
15 | GNU General Public License for more details. |
14 | |
16 | |
15 | You should have received a copy of the GNU General Public License |
17 | You should have received a copy of the GNU General Public License |
16 | along with this program; if not, write to the Free Software |
18 | along with gvpe; if not, write to the Free Software |
17 | Foundation, Inc. 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
19 | Foundation, Inc. 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
18 | */ |
20 | */ |
19 | |
21 | |
20 | #include <cstdio> |
22 | #include <cstdio> |
21 | #include <cstring> |
23 | #include <cstring> |
… | |
… | |
119 | |
121 | |
120 | #elif IF_raw_socket |
122 | #elif IF_raw_socket |
121 | # define IF_istun 1 |
123 | # define IF_istun 1 |
122 | # include "tincd/raw_socket/device.c" |
124 | # include "tincd/raw_socket/device.c" |
123 | |
125 | |
|
|
126 | #elif IF_uml_socket |
|
|
127 | # include "tincd/uml_socket/device.c" |
|
|
128 | |
124 | #else |
129 | #else |
125 | # error No interface implementation for your IFTYPE/IFSUBTYPE combination. |
130 | # error No interface implementation for your IFTYPE/IFSUBTYPE combination. |
126 | #endif |
131 | #endif |
127 | |
132 | |
128 | #if IF_istun |
133 | #if IF_istun |
… | |
… | |
137 | |
142 | |
138 | tap_device::tap_device () |
143 | tap_device::tap_device () |
139 | { |
144 | { |
140 | device = "(null)"; |
145 | device = "(null)"; |
141 | |
146 | |
142 | if (setup_device ()) |
147 | bool ok = setup_device (); |
|
|
148 | |
|
|
149 | if (device_info) |
|
|
150 | device = device_info; |
|
|
151 | |
|
|
152 | if (ok) |
143 | { |
153 | { |
144 | slog (L_DEBUG, _("interface %s on %s initialized"), info (), device); |
154 | slog (L_DEBUG, _("interface %s on %s initialized"), info (), device); |
145 | fd = device_fd; |
155 | fd = device_fd; |
146 | strcpy (ifrname, iface); |
156 | strcpy (ifrname, iface); |
147 | } |
157 | } |
… | |
… | |
163 | tap_packet *pkt = new tap_packet; |
173 | tap_packet *pkt = new tap_packet; |
164 | |
174 | |
165 | if (!read_packet (reinterpret_cast<vpn_packet_t *>(pkt))) |
175 | if (!read_packet (reinterpret_cast<vpn_packet_t *>(pkt))) |
166 | { |
176 | { |
167 | delete pkt; |
177 | delete pkt; |
168 | slog (L_ERR, _("can't read from to %s %s: %s"), info (), DEFAULT_DEVICE, |
178 | slog (L_ERR, _("can't read from to %s %s: %s"), info (), device, |
169 | strerror (errno)); |
179 | strerror (errno)); |
170 | return 0; |
180 | return 0; |
171 | } |
181 | } |
172 | |
182 | |
173 | #if IF_istun |
183 | #if IF_istun |
… | |
… | |
191 | if ( |
201 | if ( |
192 | #if IF_istun |
202 | #if IF_istun |
193 | ether_emu.tap_to_tun (pkt) && |
203 | ether_emu.tap_to_tun (pkt) && |
194 | #endif |
204 | #endif |
195 | !write_packet (reinterpret_cast<vpn_packet_t *>(pkt))) |
205 | !write_packet (reinterpret_cast<vpn_packet_t *>(pkt))) |
196 | slog (L_ERR, _("can't write to %s %s: %s"), info (), DEFAULT_DEVICE, |
206 | slog (L_ERR, _("can't write to %s %s: %s"), info (), device, |
197 | strerror (errno)); |
207 | strerror (errno)); |
198 | } |
208 | } |
199 | |
209 | |
200 | |
210 | |