added tun
git-svn-id: svn://anubis/misc/tun@244 bd8a9e45-a331-0410-811e-c64571078777
This commit is contained in:
commit
61a3cb27a6
38
tun.c
Normal file
38
tun.c
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
|
||||||
|
#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;
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user