/* Copyright 2004 Renzo Davoli
* Reseased under the GPLv2 */
#include <stdio.h>
#include <fcntl.h>
#include <errno.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <net/if.h>
#include <net/if_tun.h>
static int tun_alloc(char *dev)
{
struct ifstat ifs;
int fd, err;
if( (fd = open("/dev/tap", O_RDWR)) < 0 )
return (-1);
memset(&ifs, 0, sizeof(ifs));
if( (err = ioctl(fd, SIOCGIFSTATUS, (void *) &ifs)) < 0 ){
close(fd);
return err;
}
printf("ioctl returns\n");
puts(ifs.ascii);
printf("ioctl idev\n");
return fd;
}
char interface[IFNAMSIZ]="tap0";
main()
{
tun_alloc(interface);
pause();
}
syntax highlighted by Code2HTML, v. 0.9.1