19#define _XOPEN_SOURCE 600
29#include <linux/if_tun.h>
39using namespace std::placeholders;
74 if (!
fUrl.
Set(url,
"",
"tap", emsg))
return false;
76 if (
fUrl.
Path().size() >= IFNAMSIZ-1) {
77 emsg.
Init(
"Rw11VirtEthTap::Open()",
78 string(
"device name '") +
fUrl.
Path() +
"' too long");
82 int fd = ::open(
"/dev/net/tun", O_RDWR);
85 "open(/dev/net/tun) failed: ", errno);
89 struct ifreq ifr = {};
90 ::strncpy(ifr.ifr_name,
fUrl.
Path().c_str(), IFNAMSIZ-1);
91 ifr.ifr_flags = IFF_TAP|IFF_NO_PI;
93 if (::ioctl(fd, TUNSETIFF, &ifr) < 0) {
95 string(
"ioctl for '") +
fUrl.
Path() +
"' failed:", errno);
114 if (irc != ssize_t(ebuf.
Size())) {
115 emsg.
InitErrno(
"Rw11VirtEthTap::Snd",
"write() failed: ", errno);
129 if (pfd.revents & (~pfd.events))
return -1;
132 ssize_t irc = pbuf->Read(
fFd);
150 os << bl << (text?text:
"--") <<
"Rw11VirtEthTap @ " <<
this << endl;
152 os << bl <<
" fFd: " <<
fFd << endl;
void Init(const std::string &meth, const std::string &text)
FIXME_docs.
void InitErrno(const std::string &meth, const std::string &text, int errnum)
FIXME_docs.
std::shared_ptr< RethBuf > pbuf_t
uint16_t Size() const
FIXME_docs.
ssize_t Write(int fd) const
FIXME_docs.
void RemovePollHandler(int fd, short events, bool nothrow=false)
FIXME_docs.
void AddPollHandler(pollhdl_t &&pollhdl, int fd, short events=POLLIN)
FIXME_docs.
I/O appicator to generate fill characters.
bool Set(const std::string &url, const std::string &optlist, RerrMsg &emsg)
FIXME_docs.
const std::string & Path() const
FIXME_docs.
void Inc(size_t ind, double val=1.)
FIXME_docs.
virtual void Dump(std::ostream &os, int ind=0, const char *text=0, int detail=0) const
FIXME_docs.
int fFd
fd for pty master side
Rw11VirtEthTap(Rw11Unit *punit)
Default constructor.
virtual bool Snd(const RethBuf &ebuf, RerrMsg &emsg)
FIXME_docs.
~Rw11VirtEthTap()
Destructor.
int RcvPollHandler(const pollfd &pfd)
FIXME_docs.
virtual bool Open(const std::string &url, RerrMsg &emsg)
FIXME_docs.
virtual void Dump(std::ostream &os, int ind=0, const char *text=0, int detail=0) const
FIXME_docs.
rcvcbfo_t fRcvCb
receive callback fobj
RlinkServer & Server() const
FIXME_docs.
Declaration of class ReventLoop.