mirror of https://github.com/dswd/vpncloud.git
24 lines
631 B
C
24 lines
631 B
C
#include <stdint.h>
|
|
#include <net/if.h>
|
|
#include <linux/if_tun.h>
|
|
#include <string.h>
|
|
#include <sys/ioctl.h>
|
|
|
|
int32_t setup_device(int32_t fd, char *ifname, int32_t flags) {
|
|
struct ifreq ifr;
|
|
memset(&ifr, 0, sizeof(ifr));
|
|
ifr.ifr_flags = flags;
|
|
strncpy(ifr.ifr_name, ifname, IFNAMSIZ);
|
|
if (ioctl(fd, TUNSETIFF, (void *)&ifr) < 0) return 1;
|
|
strncpy(ifname, ifr.ifr_name, IFNAMSIZ);
|
|
return 0;
|
|
}
|
|
|
|
int32_t setup_tap_device(int32_t fd, char *ifname) {
|
|
return setup_device(fd, ifname, IFF_TAP | IFF_NO_PI);
|
|
}
|
|
|
|
int32_t setup_tun_device(int32_t fd, char *ifname) {
|
|
return setup_device(fd, ifname, IFF_TUN | IFF_NO_PI);
|
|
}
|