From a8c8c1d4d95e2b96959aca0564cccb3ceed8e98c Mon Sep 17 00:00:00 2001 From: gbeauche <> Date: Sun, 9 May 2004 16:32:12 +0000 Subject: [PATCH] Move and fix tun interface shutdown call --- BasiliskII/src/Unix/ether_unix.cpp | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/BasiliskII/src/Unix/ether_unix.cpp b/BasiliskII/src/Unix/ether_unix.cpp index a63941f7..7390f937 100644 --- a/BasiliskII/src/Unix/ether_unix.cpp +++ b/BasiliskII/src/Unix/ether_unix.cpp @@ -81,7 +81,7 @@ static bool thread_active = false; // Flag: Packet reception thread installed static sem_t int_ack; // Interrupt acknowledge semaphore static bool udp_tunnel; // Flag: UDP tunnelling active, fd is the socket descriptor static int net_if_type = -1; // Ethernet device type -static const char *net_if_name = NULL; // TUN/TAP device name +static char *net_if_name = NULL; // TUN/TAP device name static const char *net_if_script = NULL; // Network config script // Attached network protocols, maps protocol type to MacOS handler address @@ -142,7 +142,7 @@ static bool execute_network_script(const char *action) if (pid == 0) { char *args[4]; args[0] = (char *)net_if_script; - args[1] = (char *)net_if_name; + args[1] = net_if_name; args[2] = (char *)action; args[3] = NULL; execv(net_if_script, args); @@ -226,7 +226,7 @@ bool ether_init(void) WarningAlert(str); goto open_error; } - net_if_name = ifr.ifr_name; + net_if_name = strdup(ifr.ifr_name); if (!execute_network_script("up")) { sprintf(str, GetString(STR_TUN_TAP_CONFIG_WARN), "script execute error"); WarningAlert(str); @@ -271,9 +271,6 @@ bool ether_init(void) open_error: stop_thread(); - if (net_if_type == NET_IF_TUNTAP) - execute_network_script("down"); - if (fd > 0) { close(fd); fd = -1; @@ -296,6 +293,14 @@ void ether_exit(void) thread_active = false; } + // Shut down TUN/TAP interface + if (net_if_type == NET_IF_TUNTAP) + execute_network_script("down"); + + // Free TUN/TAP device name + if (net_if_name) + free(net_if_name); + // Close sheep_net device if (fd > 0) close(fd);