How wangyu-/tinyportmapper works
Project type and purpose
• This is a single-process, event-driven, high-performance port forwarding utility written in C/C++. It uses an embedded copy of libev (a Reactor/event-loop library) to multiplex socket I/O and forwards traffic bidirectionally between a local listener and a remote endpoint for both TCP and UDP.
File structure
• Top-level source modules
• main.cpp – entry point, CLI parsing, configuration setup
• common.cpp/.h – helper utilities (e.g., address parsing, error reporting)
• fd_manager.cpp/.h – tracks active sockets and their state (maps FDs to connection objects)
• my_ev.cpp/.h – wrapper layer on top of libev (initializes the event loop, registers callbacks)
• Third-party library directory
• libev/ – embedded Reactor implementation (ev.c/.h, backends for epoll, select, etc.)
• Build artifacts
• makefile – orchestrates compilation of all modules, builds one binary
• configure/autogen – libev’s autotools scripts (only relevant if re-configuring libev)
README for additional insights
• Confirms the core architecture is an event-loop (epoll on Linux) that demultiplexes socket events and dispatches read/write handlers.
• Supports both TCP and UDP forwarding, IPv4/IPv6, and configurable socket buffers and logging options.