Added interface request options and ioctl'd it (confirmed working)

This commit is contained in:
Tristan B. Velloza Kildaire 2021-07-18 19:23:02 +02:00
parent e7044563dd
commit 8e3796f586
1 changed files with 11 additions and 1 deletions

View File

@ -17,16 +17,26 @@
#include<linux/if.h>
#include<linux/if_tun.h>
#include<fcntl.h>
#include<string.h>
#include<sys/ioctl.h>
int createTun(char* interfaceName, short iffFlags)
int createTun(char* interfaceName, int iffFlags)
{
/* TODO: Add all required error checking */
int tunFD = open("/dev/net/tun", O_RDWR);
/* TUN properties */
struct ifreq interfaceReqData;
/* Set the flags for the tun adapter */
interfaceReqData.ifr_flags = iffFlags;
/* Set the requested interface's name */
strcpy(interfaceReqData.ifr_name, interfaceName);
/* Attempt to bring up the tun device node */
tunFD = ioctl(tunFD, TUNSETIFF, &interfaceReqData);
return tunFD;
}