linux/esptun.c
int tun_alloc(char *dev, int flags)
{
    struct ifreq ifr;
    int fd, err;
    static const char *clonedev = "/dev/net/tun";

    if ((fd = open(clonedev, O_RDWR)) < 0) {
        my_err("Opening /dev/net/tun (%s)", strerror(errno));
    }

    memset(&ifr, 0, sizeof(ifr));

    ifr.ifr_flags = flags;

    if (*dev) {
        strncpy(ifr.ifr_name, dev, IFNAMSIZ);
    }

    if ((err = ioctl(fd, TUNSETIFF, (void *)&ifr)) < 0) {
        close(fd);
        my_err("ioctl(TUNSETIFF) (%s)", strerror(errno));
    }

    strcpy(dev, ifr.ifr_name);

    return fd;
}
/**
 * Allocates or reconnects to a tun/tap device. *dev specifies the name of the
 * interface (e.g. tunX).  This will be overwritten with the actual name. The
 * caller must reserve enough space (IFNAMSIZ) in *dev.
 */
Allocates or reconnects to a tun/tap device. *dev specifies the name of the
interface .  This will be overwritten with the actual name. The
caller must reserve enough space (IFNAMSIZ) in *dev.
Allocates or reconnects to a tun / tap device . * dev specifies the name of the interface . This will be overwritten with the actual name . The caller must reserve enough space ( IFNAMSIZ ) in * dev .
int tun_alloc(char *dev, int flags)
{
    struct ifreq ifr;
    int fd, err;
    static const char *clonedev = "/dev/net/tun";
    if ((fd = open(clonedev, O_RDWR)) < 0) {
        my_err("Opening /dev/net/tun (%s)", strerror(errno));
    }
    memset(&ifr, 0, sizeof(ifr));
    ifr.ifr_flags = flags;
    if (*dev) {
        strncpy(ifr.ifr_name, dev, IFNAMSIZ);
    }
    if ((err = ioctl(fd, TUNSETIFF, (void *)&ifr)) < 0) {
        close(fd);
        my_err("ioctl(TUNSETIFF) (%s)", strerror(errno));
    }
    strcpy(dev, ifr.ifr_name);
    return fd;
}
int tun_alloc ( char * dev , int flags ) { struct ifreq ifr ; int fd , err ; static const char * clonedev = " " ; if ( ( fd = open ( clonedev , O_RDWR ) ) < 0 ) { my_err ( " " , strerror ( errno ) ) ; } memset ( & ifr , 0 , sizeof ( ifr ) ) ; ifr . ifr_flags = flags ; if ( * dev ) { strncpy ( ifr . ifr_name , dev , IFNAMSIZ ) ; } if ( ( err = ioctl ( fd , TUNSETIFF , ( void * ) & ifr ) ) < 0 ) { close ( fd ) ; my_err ( " " , strerror ( errno ) ) ; } strcpy ( dev , ifr . ifr_name ) ; return fd ; }
Allocates or reconnects to a tun/tap device.
Allocates or reconnects to a tun / tap device .