bugfix (fdctl is not used)
[vde.git] / vde-2 / vdetaplib / test.c
blob31841707a85b44ad8411296c1be027cc04068c3b
1 /* Copyright 2004 Renzo Davoli
2 * Reseased under the GPLv2 */
4 #include <config.h>
5 #include <stdio.h>
6 #include <fcntl.h>
7 #include <errno.h>
8 #include <string.h>
9 #include <unistd.h>
10 #include <sys/ioctl.h>
11 #include <net/if.h>
12 #include <linux/if_tun.h>
14 static int tun_alloc(char *dev)
16 struct ifreq ifr;
17 int fd, err;
19 if( (fd = open("/dev/net/tun", O_RDWR)) < 0 )
20 return (-1);
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
28 */
29 ifr.ifr_flags = IFF_TAP;
30 if( *dev )
31 strncpy(ifr.ifr_name, dev, IFNAMSIZ);
33 if( (err = ioctl(fd, TUNSETIFF, (void *) &ifr)) < 0 ){
34 close(fd);
35 return err;
37 printf("ioctl returns\n");
38 strcpy(dev, ifr.ifr_name);
39 printf("ioctl idev\n");
40 return fd;
43 char interface[IFNAMSIZ]="tap0";
45 main()
47 tun_alloc(interface);
48 pause();