--- gvpe/src/device-linux.C 2003/10/16 02:41:21 1.5 +++ gvpe/src/device-linux.C 2015/01/29 00:21:39 1.19 @@ -1,20 +1,32 @@ /* device-linux.C -- Interaction with Linux tun/tap device - Copyright (C) 2003 Marc Lehmann + Copyright (C) 2003-2008 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 - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc. 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + This file is part of GVPE. + + GVPE is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 3 of the License, or (at your + option) any later version. + + This program is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General + Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, see . + + Additional permission under GNU GPL version 3 section 7 + + If you modify this Program, or any covered work, by linking or + combining it with the OpenSSL project's OpenSSL library (or a modified + version of that library), containing parts covered by the terms of the + OpenSSL or SSLeay licenses, the licensors of this Program grant you + additional permission to convey the resulting work. Corresponding + Source for a non-source form of such a combination shall include the + source code for the parts of OpenSSL used as well as that of the + covered work. */ #include "config.h" @@ -45,6 +57,7 @@ #include "conf.h" #if TEST_ETHEREMU +# define IF_istun # include "ether_emu.C" #endif @@ -54,18 +67,24 @@ return _("Linux tun/tap device"); } +const char * +tap_device::if_up () +{ + return "/sbin/ifconfig $IFNAME hw ether $MAC mtu $MTU"; +} + tap_device::tap_device () { struct ifreq ifr; - device = DEFAULT_DEVICE; + device = (char *)DEFAULT_DEVICE; fd = open (device, O_RDWR); if (fd < 0) { slog (L_ERR, _("could not open device %s: %s"), device, strerror (errno)); - exit (1); + exit (EXIT_FAILURE); } memset (&ifr, 0, sizeof (ifr)); @@ -87,10 +106,20 @@ } else { - slog (L_CRIT, _("unable to configure tun/tap interface: %s"), strerror (errno)); - exit (1); + slog (L_CRIT, _("unable to configure tun/tap interface, exiting: %s"), strerror (errno)); + exit (EXIT_FAILURE); } +#if 0 + does not work + id2mac (THISNODE->id, &ifr.ifr_hwaddr.sa_data); + if (ioctl (fd, SIOCSIFHWADDR, &ifr)) + { + slog (L_ERR, _("cannot set MAC address for device %s, exiting: %s"), ifrname, strerror (errno)); + exit (EXIT_FAILURE); + } +#endif + if (ioctl (fd, TUNSETPERSIST, conf.ifpersist ? 1 : 0)) slog (L_WARN, _("cannot set persistency mode for device %s: %s"), ifrname, strerror (errno)); @@ -147,7 +176,7 @@ #else if (write (fd, &((*pkt)[0]), pkt->len) < 0) #endif - slog (L_ERR, _("can't write to %s %s: %s"), info (), DEFAULT_DEVICE, + slog (L_ERR, _("can't write %d byte packet to %s %s: %s"), pkt->len, info (), DEFAULT_DEVICE, strerror (errno)); }