39 lines
661 B
C
39 lines
661 B
C
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
#include <fcntl.h>
|
|
#include <sys/ioctl.h>
|
|
#include <net/if.h>
|
|
#include <linux/if_tun.h>
|
|
|
|
int main()
|
|
{
|
|
struct ifreq ifr;
|
|
int fd, err;
|
|
if ( (fd = open("/dev/net/tun", O_RDWR)) < 0)
|
|
{
|
|
fprintf(stderr, "Couldn't open /dev/net/tun!\n");
|
|
return -1;
|
|
}
|
|
|
|
memset(&ifr, 0, sizeof(ifr));
|
|
|
|
ifr.ifr_flags = IFF_TUN;
|
|
strncpy(ifr.ifr_name, "tun99", IFNAMSIZ);
|
|
|
|
if ( (err = ioctl(fd, TUNSETIFF, &ifr)) < 0)
|
|
{
|
|
close(fd);
|
|
fprintf(stderr, "Couldn't ioctl(fd, TUNSETIFF, &ifr)!\n");
|
|
return -2;
|
|
}
|
|
printf("Device name: %s\n", ifr.ifr_name);
|
|
|
|
printf("Hit enter\n");
|
|
char chr;
|
|
scanf("%c", &chr);
|
|
|
|
close(fd);
|
|
return 0;
|
|
}
|