-cp
- if(!get_config_string(lookup_config(config_tree, "Device"), &device))
- device = DEFAULT_DEVICE;
-
- if(!get_config_string(lookup_config(config_tree, "Interface"), &interface))
- interface = rindex(device, '/')?rindex(device, '/')+1:device;
-cp
- if((device_fd = open(device, O_RDWR | O_NONBLOCK)) < 0)
- {
- syslog(LOG_ERR, _("Could not open %s: %s"), device, strerror(errno));
- return -1;
- }
-cp
-
- /* Set default MAC address for ethertap devices */
-
- mymac.type = SUBNET_MAC;
- mymac.net.mac.address.x[0] = 0xfe;
- mymac.net.mac.address.x[1] = 0xfd;
- mymac.net.mac.address.x[2] = 0x00;
- mymac.net.mac.address.x[3] = 0x00;
- mymac.net.mac.address.x[4] = 0x00;
- mymac.net.mac.address.x[5] = 0x00;
-
- device_info = _("MacOS/X tun device");
-
- syslog(LOG_INFO, _("%s is a %s"), device, device_info);
-cp
- return 0;
+ char *type;
+
+ cp();
+
+ if(!get_config_string(lookup_config(config_tree, "Device"), &device))
+ device = DEFAULT_DEVICE;
+
+ if(!get_config_string(lookup_config(config_tree, "Interface"), &iface))
+ iface = rindex(device, '/') ? rindex(device, '/') + 1 : device;
+
+ if((device_fd = open(device, O_RDWR | O_NONBLOCK)) < 0) {
+ logger(LOG_ERR, _("Could not open %s: %s"), device, strerror(errno));
+ return false;
+ }
+
+ if(get_config_string(lookup_config(config_tree, "DeviceType"), &type)) {
+ if(!strcasecmp(type, "tun"))
+ device_type = DEVICE_TYPE_TUN;
+ else if(!strcasecmp(type, "tap"))
+ device_type = DEVICE_TYPE_TAP;
+ else {
+ logger(LOG_ERR, _("Unknown device type %s!"), type);
+ return false;
+ }
+ } else {
+ if(strstr(device, "tap"))
+ device_type = DEVICE_TYPE_TAP;
+ }
+
+ switch(device_type) {
+ default:
+ device_type = DEVICE_TYPE_TUN;
+ case DEVICE_TYPE_TUN:
+ device_info = _("MacOS/X tun device");
+ break;
+ case DEVICE_TYPE_TAP:
+ if(routing_mode == RMODE_ROUTER)
+ overwrite_mac = true;
+ device_info = _("MacOS/X tap device");
+ break;
+ }
+
+ logger(LOG_INFO, _("%s is a %s"), device, device_info);
+
+ return true;