Skip to content

Commit

Permalink
Improve style
Browse files Browse the repository at this point in the history
  • Loading branch information
marek22k committed Mar 12, 2024
1 parent 210fa09 commit 3a1be57
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions bindings/cpp/tuntap++.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,23 @@
namespace tuntap {

tuntap::tuntap(int mode, int id)
: _dev{tuntap_init()}, _started{true}
: _dev{::tuntap_init()}, _started{true}
{
if (mode != TUNTAP_MODE_ETHERNET && mode != TUNTAP_MODE_TUNNEL) {
throw std::invalid_argument("Unknown tuntap mode");
}
if (id < 0 || id > TUNTAP_ID_MAX) {
throw std::invalid_argument("Tunnel ID is invalid");
}
if (tuntap_start(_dev, mode, id)) {
if (::tuntap_start(_dev, mode, id)) {
throw std::runtime_error("tuntap_start failed");
}
}

tuntap::~tuntap()
{
if (_started) {
tuntap_destroy(_dev);
::tuntap_destroy(_dev);
}
}

Expand All @@ -36,50 +36,50 @@ tuntap::tuntap(tuntap &&t) noexcept
void
tuntap::release() noexcept
{
tuntap_release(_dev);
::tuntap_release(_dev);
_started = false;
}

std::string
tuntap::name() const noexcept
{
return std::string(tuntap_get_ifname(_dev));
return std::string(::tuntap_get_ifname(_dev));
}

void
tuntap::name(std::string const &s)
{
if (tuntap_set_ifname(_dev, s.c_str())) {
if (::tuntap_set_ifname(_dev, s.c_str())) {
throw std::runtime_error("Failed to set ifname");
}
}

t_tun
tuntap::native_handle() const noexcept
{
return tuntap_get_fd(this->_dev);
return ::tuntap_get_fd(this->_dev);
}

void
tuntap::up()
{
if (tuntap_up(_dev)) {
if (::tuntap_up(_dev)) {
throw std::runtime_error("Failed to bring up tuntap device");
}
}

void
tuntap::down()
{
if (tuntap_down(_dev)) {
if (::tuntap_down(_dev)) {
throw std::runtime_error("Failed to bring down tuntap device");
}
}

int
tuntap::mtu() const noexcept
{
return tuntap_get_mtu(_dev);
return ::tuntap_get_mtu(_dev);
}

void
Expand All @@ -88,7 +88,7 @@ tuntap::mtu(int m)
if (m < 1 || m > 65535) {
throw std::invalid_argument("Invalid mtu");
}
if (tuntap_set_mtu(_dev, m)) {
if (::tuntap_set_mtu(_dev, m)) {
throw std::runtime_error("Failed to set mtu for tuntap device");
}
}
Expand All @@ -99,27 +99,27 @@ tuntap::ip(std::string const &s, int netmask)
if (netmask > 128) {
throw std::invalid_argument("Invalid netmask");
}
if (tuntap_set_ip(_dev, s.c_str(), netmask)) {
if (::tuntap_set_ip(_dev, s.c_str(), netmask)) {
throw std::runtime_error("Failed to set ip for tuntap device");
}
}

int
tuntap::read(void *buf, size_t len) noexcept
{
return tuntap_read(_dev, buf, len);
return ::tuntap_read(_dev, buf, len);
}

int
tuntap::write(void *buf, size_t len) noexcept
{
return tuntap_write(_dev, buf, len);
return ::tuntap_write(_dev, buf, len);
}

void
tuntap::nonblocking(bool b)
{
if (tuntap_set_nonblocking(_dev, int(b))) {
if (::tuntap_set_nonblocking(_dev, int(b))) {
throw std::runtime_error("Failed to change non-blocking state for tuntap device");
}
}
Expand Down

0 comments on commit 3a1be57

Please sign in to comment.