Files
funstraw/lib/tun_tap_device.h

34 lines
707 B
C
Raw Normal View History

2016-09-25 15:56:37 -07:00
#include <string>
2016-09-25 17:37:37 -07:00
#include <fcntl.h>
2016-09-25 15:56:37 -07:00
#include <linux/if_tun.h>
2016-09-25 17:37:37 -07:00
#include <sys/stat.h>
#include <sys/types.h>
2016-09-25 15:56:37 -07:00
2016-09-25 17:37:37 -07:00
namespace funstraw {
class TunTapDevice {
2016-09-25 15:56:37 -07:00
public:
2016-09-25 17:37:37 -07:00
static const auto kIfFormatTun = IFF_TUN;
static const auto kIfFormatTap = IFF_TAP;
static const auto kIfNoPacketInfo = IFF_NO_PI;
static const auto kFdReadOnly = O_RDONLY;
static const auto kFdWriteOnly = O_WRONLY;
static const auto kFdReadWrite = O_RDWR;
TunTapDevice(const std::string& name, uint64_t if_flags, uint64_t fd_flags);
~TunTapDevice();
2016-09-25 15:56:37 -07:00
2016-09-25 17:37:37 -07:00
const std::string& Name() { return name_; }
2016-09-25 15:56:37 -07:00
2016-09-25 17:37:37 -07:00
// TODO: real buffer object
size_t Read(char* buf);
2016-09-25 15:56:37 -07:00
private:
2016-09-25 17:37:37 -07:00
int fd_;
2016-09-25 15:56:37 -07:00
std::string name_;
};
2016-09-25 17:37:37 -07:00
} // namespace funstraw