diff --git a/cpu/native/include/tap.h b/cpu/native/include/tap.h index 0d44548dcc..105f8f7c8b 100644 --- a/cpu/native/include/tap.h +++ b/cpu/native/include/tap.h @@ -36,7 +36,11 @@ extern "C" { */ int tap_init(char *name); -extern int _native_tap_fd; +/** + * Close tap device + */ +void tap_cleanup(void); + extern unsigned char _native_tap_mac[ETHER_ADDR_LEN]; struct nativenet_header { diff --git a/cpu/native/native_cpu.c b/cpu/native/native_cpu.c index 7f372514ea..afc31c3120 100644 --- a/cpu/native/native_cpu.c +++ b/cpu/native/native_cpu.c @@ -73,9 +73,7 @@ int reboot_arch(int mode) /* TODO: close stdio fds */ #endif #ifdef MODULE_NATIVENET - if (_native_tap_fd != -1) { - real_close(_native_tap_fd); - } + tap_cleanup(); #endif if (real_execve(_native_argv[0], _native_argv, NULL) == -1) { diff --git a/cpu/native/net/tap.c b/cpu/native/net/tap.c index e5dbc78560..3c3a7ff156 100644 --- a/cpu/native/net/tap.c +++ b/cpu/native/net/tap.c @@ -351,4 +351,15 @@ int tap_init(char *name) DEBUG("RIOT native tap initialized.\n"); return _native_tap_fd; } + +void tap_cleanup(void) +{ + if (_native_tap_fd == -1) { + return; + } + + real_close(_native_tap_fd); + _native_tap_fd = -1; + +} /** @} */