Code Monkey home page Code Monkey logo

libplum's Introduction

libplum - Multi-protocol Port Mapping client library

License: MPL 2.0 Build

libplum (Port Lightweight and Universal Mapping) is a high-level library allowing to forward ports on Network Address Translators (NAT). It is written in C without dependencies and supports POSIX platforms (including GNU/Linux, Android, Apple macOS and iOS) and Microsoft Windows.

libplum has Node.js bindings, see node-portmapping.

Under the hood, it implements multiple protocols and automatically detects which one to use:

  • Port Control Protocol (PCP, RFC6887)
  • NAT Port Mapping Protocol (NAT-PMP, RFC6886)
  • UPnP Internet Gateway Device Protocol (UPnP-IGD)

It also contains an integrated client for the DummyTLS service.

libplum is licensed under MPL 2.0, see LICENSE.

Plum in Rayman (Ubisoft, 1995)

Dependencies

None!

Example

#include "plum/plum.h"

Initialize the library

plum_config_t config;
memset(&config, 0, sizeof(config));
config.log_level = PLUM_LOG_LEVEL_WARN;
plum_init(&config);

Create a mapping

void mapping_callback(int id, plum_state_t state, const plum_mapping_t *mapping) {
    // Called from another thread
    if (state == PLUM_STATE_SUCCESS)
        printf("External address: %s:%hu\n", mapping->external_host, mapping->external_port);
}
plum_mapping_t mapping;
memset(&mapping, 0, sizeof(mapping));
mapping.protocol = PLUM_IP_PROTOCOL_TCP;
mapping.internal_port = 8000;
mapping.user_ptr = NULL;

int id = plum_create_mapping(&mapping, mapping_callback);

Destroy a mapping

plum_destroy_mapping(id);

See example/main.c for a usage example.

Building

Clone repository

$ git clone https://github.com/paullouisageneau/libplum.git
$ cd libplum

Build with CMake

The CMake library targets libplum and libplum-static respectively correspond to the shared and static libraries. The default target will build the library and example.

POSIX-compliant operating systems (including Linux and Apple macOS)

$ cmake -B build
$ cd build
$ make -j2

Microsoft Windows with MinGW cross-compilation

$ cmake -B build -DCMAKE_TOOLCHAIN_FILE=/usr/share/mingw/toolchain-x86_64-w64-mingw32.cmake # replace with your toolchain file
$ cd build
$ make -j2

Microsoft Windows with Microsoft Visual C++

$ cmake -B build -G "NMake Makefiles"
$ cd build
$ nmake

Build directly with Make (Linux only)

$ make

libplum's People

Contributors

paullouisageneau avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.