- if(!get_config_string(lookup_config(config_tree, "Interface"), &interface))
-#ifdef HAVE_TUNTAP
- interface = netname;
-#else
- interface = rindex(device, '/')?rindex(device, '/')+1:device;
-#endif
-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;
-
-#ifdef HAVE_TUNTAP
- /* Ok now check if this is an old ethertap or a new tun/tap thingie */
-
- memset(&ifr, 0, sizeof(ifr));
-cp
- ifr.ifr_flags = IFF_TAP | IFF_NO_PI;
- if (interface)
- strncpy(ifr.ifr_name, interface, IFNAMSIZ);
-cp
- if (!ioctl(device_fd, TUNSETIFF, (void *) &ifr))
- {
- device_info = _("Linux tun/tap device");
- device_type = DEVICE_TYPE_TUNTAP;
- strncpy(ifrname, ifr.ifr_name, IFNAMSIZ);
- interface = ifrname;
- }
- else
- if (!ioctl(device_fd, (('T'<< 8) | 202), (void *) &ifr))
- {
- syslog(LOG_WARNING, _("Old ioctl() request was needed for %s"), device);
- device_type = DEVICE_TYPE_TUNTAP;
- device_info = _("Linux tun/tap device");
- strncpy(ifrname, ifr.ifr_name, IFNAMSIZ);
- interface = ifrname;
- }
- else
-#endif
- {
- device_info = _("Linux ethertap device");
- device_type = DEVICE_TYPE_ETHERTAP;
- interface = rindex(device, '/')?rindex(device, '/')+1:device;
- }
-
- syslog(LOG_INFO, _("%s is a %s"), device, device_info);
-cp
- return 0;