linux/tun_dev.c
static int tun_open_common0(char *dev, int istun)
{
    char tunname[14];
    int i, fd, err;

    if( *dev ) {
       sprintf(tunname, "/dev/%s", dev);
       return open(tunname, O_RDWR);
    }

    sprintf(tunname, "/dev/%s", istun ? "tun" : "tap");
    err = 0;
    for(i=0; i < 255; i++){
       sprintf(tunname + 8, "%d", i);
       /* Open device */
       if( (fd=open(tunname, O_RDWR)) > 0 ) {
          strcpy(dev, tunname + 5);
          return fd;
       }
       else if (errno != ENOENT)
          err = errno;
       else if (i)	/* don't try all 256 devices */
          break;
    }
    if (err)
	errno = err;
    return -1;
}
/* 
 * Allocate TUN device, returns opened fd. 
 * Stores dev name in the first arg(must be large enough).
 */
Allocate TUN device, returns opened fd.
Stores dev name in the first arg(must be large enough).
Allocate TUN device returns opened fd . Stores dev name in the first arg ( must be large enough ) .
static int tun_open_common0(char *dev, int istun)
{
    char tunname[14];
    int i, fd, err;
    if( *dev ) {
       sprintf(tunname, "/dev/%s", dev);
       return open(tunname, O_RDWR);
    }
    sprintf(tunname, "/dev/%s", istun ? "tun" : "tap");
    err = 0;
    for(i=0; i < 255; i++){
       sprintf(tunname + 8, "%d", i);
       if( (fd=open(tunname, O_RDWR)) > 0 ) {
          strcpy(dev, tunname + 5);
          return fd;
       }
       else if (errno != ENOENT)
          err = errno;
       else if (i)	
          break;
    }
    if (err)
	errno = err;
    return -1;
}
static int tun_open_common0 ( char * dev , int istun ) { char tunname [ 14 ] ; int i , fd , err ; if ( * dev ) { sprintf ( tunname , " " , dev ) ; return open ( tunname , O_RDWR ) ; } sprintf ( tunname , " " , istun ? " " : " " ) ; err = 0 ; for ( i = 0 ; i < 255 ; i ++ ) { sprintf ( tunname + 8 , " " , i ) ; if ( ( fd = open ( tunname , O_RDWR ) ) > 0 ) { strcpy ( dev , tunname + 5 ) ; return fd ; } else if ( errno != ENOENT ) err = errno ; else if ( i ) break ; } if ( err ) errno = err ; return -1 ; }
Allocate TUN device, returns opened fd.
Allocate TUN device returns opened fd .
/* Open device */ /* don't try all 256 devices */