---
title: llarp/vpn/common.hpp

---

# llarp/vpn/common.hpp



## Namespaces

| Name           |
| -------------- |
| **[llarp](Namespaces/namespacellarp.md)** <br>[crypto.hpp] |
| **[llarp::vpn](Namespaces/namespacellarp_1_1vpn.md)**  |

## Classes

|                | Name           |
| -------------- | -------------- |
| class | **[llarp::vpn::permission_error](Classes/classllarp_1_1vpn_1_1permission__error.md)**  |
| struct | **[llarp::vpn::IOCTL](Classes/structllarp_1_1vpn_1_1IOCTL.md)**  |




## Source code

```cpp
#pragma once

#include <sys/types.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <cerrno>

namespace llarp::vpn
{
  class permission_error : public std::runtime_error
  {
   public:
    using std::runtime_error::runtime_error;
  };

  struct IOCTL
  {
    const int _fd;

    explicit IOCTL(int af) : _fd{::socket(af, SOCK_DGRAM, IPPROTO_IP)}
    {
      if (_fd == -1)
        throw std::invalid_argument{strerror(errno)};
    };

    ~IOCTL()
    {
      ::close(_fd);
    }

    template <typename Command, typename... Args>
    void
    ioctl(Command cmd, Args&&... args)
    {
      if (::ioctl(_fd, cmd, std::forward<Args>(args)...) == -1)
      {
        if (errno == EACCES)
        {
          throw permission_error{"we are not allowed to call this ioctl"};
        }
        else
          throw std::runtime_error("ioctl failed: " + std::string{strerror(errno)});
      }
    }
  };
}  // namespace llarp::vpn
```


-------------------------------

Updated on 2025-03-02 at 05:10:06 +0000
