+ if(!device) {
+ if(device_type == DEVICE_TYPE_TAP)
+ device = xstrdup(DEFAULT_TAP_DEVICE);
+ else
+ device = xstrdup(DEFAULT_TUN_DEVICE);
+ }
+
+ if(!get_config_string(lookup_config(config_tree, "Interface"), &iface))
+ iface = NULL;
+#ifndef TAPGIFNAME
+ if (iface) {
+ logger(DEBUG_ALWAYS, LOG_WARNING, "Ignoring specified interface name '%s' as device rename is not supported on this platform", iface);
+ free(iface);
+ iface = NULL;
+ }
+#endif
+ if (!iface)
+ iface = xstrdup(strrchr(device, '/') ? strrchr(device, '/') + 1 : device);
+
+ switch(device_type) {
+#ifdef ENABLE_TUNEMU
+ case DEVICE_TYPE_TUNEMU: {
+ char dynamic_name[256] = "";
+ device_fd = tunemu_open(dynamic_name);
+ }
+ break;
+#endif
+ default:
+ device_fd = open(device, O_RDWR | O_NONBLOCK);
+ }
+
+ if(device_fd < 0) {
+ logger(DEBUG_ALWAYS, LOG_ERR, "Could not open %s: %s", device, strerror(errno));
+ return false;
+ }
+
+#ifdef FD_CLOEXEC
+ fcntl(device_fd, F_SETFD, FD_CLOEXEC);
+#endif
+