1 /* Copyright 2004 Renzo Davoli
2 * Reseased under the GPLv2 */
10 #include <sys/ioctl.h>
12 #include <linux/if_tun.h>
14 static int tun_alloc(char *dev
)
19 if( (fd
= open("/dev/net/tun", O_RDWR
)) < 0 )
22 memset(&ifr
, 0, sizeof(ifr
));
24 /* Flags: IFF_TUN - TUN device (no Ethernet headers)
25 * IFF_TAP - TAP device
27 * IFF_NO_PI - Do not provide packet information
29 ifr
.ifr_flags
= IFF_TAP
;
31 strncpy(ifr
.ifr_name
, dev
, IFNAMSIZ
);
33 if( (err
= ioctl(fd
, TUNSETIFF
, (void *) &ifr
)) < 0 ){
37 printf("ioctl returns\n");
38 strcpy(dev
, ifr
.ifr_name
);
39 printf("ioctl idev\n");
43 char interface
[IFNAMSIZ
]="tap0";