+ device_fd = open(device, O_RDWR | O_NONBLOCK);
+
+ if(device_fd < 0) {
+ logger(LOG_ERR, _("Could not open %s: %s"), device, strerror(errno));
+ return false;
+ }
+
+#ifdef HAVE_LINUX_IF_TUN_H
+ /* Ok now check if this is an old ethertap or a new tun/tap thingie */
+
+ memset(&ifr, 0, sizeof(ifr));
+ if(routing_mode == RMODE_ROUTER) {
+ ifr.ifr_flags = IFF_TUN;
+ device_type = DEVICE_TYPE_TUN;
+ device_info = _("Linux tun/tap device (tun mode)");
+ } else {
+ ifr.ifr_flags = IFF_TAP | IFF_NO_PI;
+ device_type = DEVICE_TYPE_TAP;
+ device_info = _("Linux tun/tap device (tap mode)");
+ }
+
+ if(iface)
+ strncpy(ifr.ifr_name, iface, IFNAMSIZ);
+
+ if(!ioctl(device_fd, TUNSETIFF, &ifr)) {
+ strncpy(ifrname, ifr.ifr_name, IFNAMSIZ);
+ iface = ifrname;
+ } else if(!ioctl(device_fd, (('T' << 8) | 202), &ifr)) {
+ logger(LOG_WARNING, _("Old ioctl() request was needed for %s"), device);
+ strncpy(ifrname, ifr.ifr_name, IFNAMSIZ);
+ iface = ifrname;
+ } else
+#endif
+ {
+ if(routing_mode == RMODE_ROUTER)
+ overwrite_mac = true;
+ device_info = _("Linux ethertap device");
+ device_type = DEVICE_TYPE_ETHERTAP;
+ iface = rindex(device, '/') ? rindex(device, '/') + 1 : device;
+ }
+
+ logger(LOG_INFO, _("%s is a %s"), device, device_info);
+
+ return true;