-/* --- @t_open@ --- *
- *
- * Arguments: @char **ifn@ = where to put the interface name
- *
- * Returns: A file descriptor, or @-1@ on failure.
- *
- * Use: Opens a tunnel device. This will run with root privileges
- * even if the rest of the server has dropped them.
- */
-
-static int t_open(char **ifn)
-{
- int fd;
- struct ifreq iff;
-
- if ((fd = open("/dev/net/tun", O_RDWR)) < 0) {
- a_warn("TUN", "-", "linux",
- "open-error", "/dev/net/tun", "?ERRNO",
- A_END);
- return (-1);
- }
- memset(&iff, 0, sizeof(iff));
- iff.ifr_name[0] = 0;
- iff.ifr_flags = IFF_TUN | IFF_NO_PI;
- if (ioctl(fd, TUNSETIFF, &iff) < 0) {
- a_warn("TUN", "-", "linux", "config-error", "?ERRNO", A_END);
- close(fd);
- return (-1);
- }
- iff.ifr_name[IFNAMSIZ - 1] = 0;
- *ifn = xstrdup(iff.ifr_name);
- return (fd);
-}
-