--- gvpe/src/device-tincd.C 2003/10/14 15:48:15 1.3 +++ gvpe/src/device-tincd.C 2004/09/30 12:46:16 1.11 @@ -1,5 +1,6 @@ /* device-tincd.C -- include one of the tincd low level implementations. + Copyright (C) 2003-2004 Marc Lehmann This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -68,8 +69,6 @@ u8 data[MAXSIZE]; }; -static tap_device *self; - static bool overwrite_mac; static bool @@ -92,24 +91,44 @@ #if IF_linux # include "tincd/linux/device.c" + #elif IF_freebsd # include "tincd/freebsd/device.c" + #elif IF_netbsd +# define IF_istun 1 # include "tincd/netbsd/device.c" + +#elif IF_openbsd +# define IF_istun 1 +# include "tincd/openbsd/device.c" + #elif IF_solaris +# define IF_istun 1 # include "tincd/solaris/device.c" + #elif IF_cygwin # include "tincd/cygwin/device.c" + #elif IF_mingw # include "tincd/mingw/device.c" + #elif IF_darwin +# define IF_istun 1 # include "tincd/darwin/device.c" + #elif IF_raw_socket +# define IF_istun 1 # include "tincd/raw_socket/device.c" + #else # error No interface implementation for your IFTYPE/IFSUBTYPE combination. #endif +#if IF_istun +# include "ether_emu.C" +#endif + const char * tap_device::info () { @@ -118,18 +137,18 @@ tap_device::tap_device () { - self = this; + device = "(null)"; if (setup_device ()) { - //slog (L_DEBUG, _("%s is a %s"), device, info ()); + slog (L_DEBUG, _("interface %s on %s initialized"), info (), device); fd = device_fd; strcpy (ifrname, iface); } else { - slog (L_ERR, _("error while configuring tincd device (%s/%s)"), device, info ()); - exit (1); + slog (L_ERR, _("error while configuring tincd device %s on %s"), info (), device); + exit (EXIT_FAILURE); } } @@ -151,13 +170,29 @@ return 0; } +#if IF_istun + // assume ipv4 + (*pkt)[12] = 0x08; + (*pkt)[13] = 0x00; + + if (!ether_emu.tun_to_tap (pkt)) + { + delete pkt; + return 0; + } +#endif + return pkt; } void tap_device::send (tap_packet *pkt) { - if (!write_packet (reinterpret_cast(pkt))) + if ( +#if IF_istun + ether_emu.tap_to_tun (pkt) && +#endif + !write_packet (reinterpret_cast(pkt))) slog (L_ERR, _("can't write to %s %s: %s"), info (), DEFAULT_DEVICE, strerror (errno)); }