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 Marc Lehmann <pcg@goof.com> |
3 | |
4 | |
4 | This program is free software; you can redistribute it and/or modify |
5 | This program is free software; you can redistribute it and/or modify |
5 | it under the terms of the GNU General Public License as published by |
6 | it under the terms of the GNU General Public License as published by |
6 | the Free Software Foundation; either version 2 of the License, or |
7 | the Free Software Foundation; either version 2 of the License, or |
7 | (at your option) any later version. |
8 | (at your option) any later version. |
… | |
… | |
93 | #if IF_linux |
94 | #if IF_linux |
94 | # include "tincd/linux/device.c" |
95 | # include "tincd/linux/device.c" |
95 | #elif IF_freebsd |
96 | #elif IF_freebsd |
96 | # include "tincd/freebsd/device.c" |
97 | # include "tincd/freebsd/device.c" |
97 | #elif IF_netbsd |
98 | #elif IF_netbsd |
|
|
99 | #define IF_istun 1 |
98 | # include "tincd/netbsd/device.c" |
100 | # include "tincd/netbsd/device.c" |
99 | #elif IF_solaris |
101 | #elif IF_solaris |
100 | # include "tincd/solaris/device.c" |
102 | # include "tincd/solaris/device.c" |
101 | #elif IF_cygwin |
103 | #elif IF_cygwin |
102 | # include "tincd/cygwin/device.c" |
104 | # include "tincd/cygwin/device.c" |
103 | #elif IF_mingw |
105 | #elif IF_mingw |
104 | # include "tincd/mingw/device.c" |
106 | # include "tincd/mingw/device.c" |
105 | #elif IF_darwin |
107 | #elif IF_darwin |
|
|
108 | #define IF_istun 1 |
106 | # include "tincd/darwin/device.c" |
109 | # include "tincd/darwin/device.c" |
107 | #elif IF_raw_socket |
110 | #elif IF_raw_socket |
|
|
111 | #define IF_istun 1 |
108 | # include "tincd/raw_socket/device.c" |
112 | # include "tincd/raw_socket/device.c" |
109 | #else |
113 | #else |
110 | # error No interface implementation for your IFTYPE/IFSUBTYPE combination. |
114 | # error No interface implementation for your IFTYPE/IFSUBTYPE combination. |
|
|
115 | #endif |
|
|
116 | |
|
|
117 | #if IF_istun |
|
|
118 | # include "ether_emu.C" |
111 | #endif |
119 | #endif |
112 | |
120 | |
113 | const char * |
121 | const char * |
114 | tap_device::info () |
122 | tap_device::info () |
115 | { |
123 | { |
… | |
… | |
149 | slog (L_ERR, _("can't read from to %s %s: %s"), info (), DEFAULT_DEVICE, |
157 | slog (L_ERR, _("can't read from to %s %s: %s"), info (), DEFAULT_DEVICE, |
150 | strerror (errno)); |
158 | strerror (errno)); |
151 | return 0; |
159 | return 0; |
152 | } |
160 | } |
153 | |
161 | |
|
|
162 | #if IF_istun |
|
|
163 | // assume ipv4 |
|
|
164 | (*pkt)[12] = 0x08; |
|
|
165 | (*pkt)[13] = 0x00; |
|
|
166 | |
|
|
167 | if (!ether_emu.tun_to_tap (pkt)) |
|
|
168 | { |
|
|
169 | delete pkt; |
|
|
170 | return 0; |
|
|
171 | } |
|
|
172 | #endif |
|
|
173 | |
154 | return pkt; |
174 | return pkt; |
155 | } |
175 | } |
156 | |
176 | |
157 | void |
177 | void |
158 | tap_device::send (tap_packet *pkt) |
178 | tap_device::send (tap_packet *pkt) |
159 | { |
179 | { |
|
|
180 | if ( |
|
|
181 | #if IF_istun |
|
|
182 | ether_emu.tap_to_tun (pkt) && |
|
|
183 | #endif |
160 | if (!write_packet (reinterpret_cast<vpn_packet_t *>(pkt))) |
184 | !write_packet (reinterpret_cast<vpn_packet_t *>(pkt))) |
161 | slog (L_ERR, _("can't write to %s %s: %s"), info (), DEFAULT_DEVICE, |
185 | slog (L_ERR, _("can't write to %s %s: %s"), info (), DEFAULT_DEVICE, |
162 | strerror (errno)); |
186 | strerror (errno)); |
163 | } |
187 | } |
164 | |
188 | |
165 | |
189 | |