23 #include <sys/ioctl.h> 26 #include <linux/if_tun.h> 43 if ( (f = ::open(
"/dev/net/tun", O_RDWR | O_CLOEXEC)) < 0 )
46 ::memset( &ifr, 0,
sizeof(ifr));
47 ifr.ifr_flags = IFF_TAP;
49 ifr.ifr_flags |= IFF_NO_PI;
50 interface_name.copy( ifr.ifr_name, IFNAMSIZ);
51 if (::ioctl(f, TUNSETIFF, (
void *) &ifr) < 0 ) {
55 ifaceIndex_ = if_nametoindex(ifr.ifr_name);
58 << ifr.ifr_name <<
"'.";
67 ssize_t l = ::recv(
fd(), 0, 0, MSG_PEEK | MSG_TRUNC);
104 char buf[IF_NAMESIZE];
105 if_indextoname(ifaceIndex_, buf);
106 return std::string(buf);
bool eof() const
returns always false.
#define SENF_THROW_SYSTEM_EXCEPTION(desc)
int fd() const
Get file descriptor.
unsigned int ifaceIndex() const
returns the index of the correspondent tap interface
void init_client() const
Open tap socket and create new tap interface.
FileHandle fh() const
Get a FileHandle for this instance.
unsigned available() const
Return (maximum) number of bytes available for reading without < blocking.
virtual void close()
Close socket.
PacketSocketProtocol and PacketSocketHandle public header.
std::string ifaceName() const
returns the actual name of the correspondent tap interface