8 #include <linux/if_tun.h>
11 static constexpr
const char *
CLONEDEV =
"/dev/net/tun";
26 struct ifreq tun_req {};
28 tun_req.ifr_flags = (is_tun ? IFF_TUN : IFF_TAP) | IFF_NO_PI;
32 strncpy(
static_cast<char *
>(tun_req.ifr_name), devname.
data(), IFNAMSIZ - 1);
33 tun_req.ifr_name[IFNAMSIZ - 1] =
'\0';
35 SystemCall(
"ioctl", ioctl(
fd_num(), TUNSETIFF,
static_cast<void *
>(&tun_req)));
A reference-counted handle to a file descriptor.
int fd_num() const
underlying descriptor number
TunTapFD(const std::string &devname, const bool is_tun)
Open an existing persistent TUN or TAP device.
SystemCall("socketpair", ::socketpair(AF_UNIX, SOCK_STREAM, 0, fds.data()))
static constexpr const char * CLONEDEV