/natpp

(Going to be an) Asio integrated C++17 port mapping library (supports NATPMP and [soon] UPnP)

Primary LanguageC++MIT LicenseMIT

natpp

This library lets you create port mappings using the well established Asio C++ networking library.

Asio

This library integrates deeply with the Asio framework by providing an IO service backend and corresponding IO object classes for each protocol type. Currently it only works with the standalone version of Asio, but support for independent Asio sources (i.e. standalone or Boost) is in the plans.

Work-in-progress note

Since this library is work-in-progress, currently it only supports the NATPMP protocol. However, support for UPnP port forwarding is in the works and should land soon.

Usage

#include <asio.hpp>
#include <natpp/natpmp.hpp>

int main()
{
  asio::io_context io;
  nat::natpmp natpmp(io);
  
  natpmp.async_public_address([](nat::error_code error, asio::ip::address addr) {
        if(!error) {
          // TODO print addr
        }
      });
      
  nat::port_mapping mapping;
  mapping.private_port = 55555;
  mapping.public_port = 55555;
  mapping.duration = std::chrono::hours(2);
  natpmp.async_request_mapping(mapping,
      [](nat::error_code error, nat::port_mapping mapping) {
        if(!error) {
          // TODO print mapping
        }
      });
      
  io.run();
}