$ show heiher/hev-socks5-tunnel
HevSocks5Tunnel is a lightweight, high-performance tun2socks proxy written in C. It creates a virtual TUN interface and forwards all TCP/UDP traffic through a SOCKS5 proxy, supporting IPv4/IPv6 dual-stack, UDP-in-UDP and UDP-in-TCP relay modes, optional local ICMP echo replies, and a mapped DNS feature for transparent DNS resolution. The architecture is monolithic but modular: a YAML-based configuration parser, platform-specific tunnel backends (Linux, FreeBSD, macOS, NetBSD, Windows via Wintun), and a session management layer built on top of lwIP and the hev-task-system cooperative multitasking library. It can be used as a standalone CLI tool, a static/shared library, or embedded via JNI on Android. The codebase demonstrates strong C craftsmanship with clean abstractions, efficient I/O patterns (ring buffer with iovec, scatter/gather), and careful platform abstraction.
The LLM identified 3 files worth highlighting for reuse:
A lightweight ring buffer implementation that uses alloca for stack allocation and provides iovec-based scatter/gather read/write interfaces. It is self-contained (only depends on hev-compiler.h) and can be extracted for any project needing a fixed-capacity circular buffer with efficient I/O. The design avoids dynamic allocation and supports partial reads/writes, making it suitable for high-performance network splicing.
A clean wrapper around the Wintun TUN driver for Windows. It dynamically loads wintun.dll functions via LoadLibrary/GetProcAddress, providing a simple C API for adapter creation, session management, and packet send/receive. This module is fully self-contained and can be reused in any Windows project that needs Wintun integration without dealing with the raw DLL function pointers.
A header-only utility providing READ_ONCE/WRITE_ONCE macros for safe volatile access, ALIGN_UP/DOWN for alignment, container_of for type-safe pointer conversion, and barrier() for memory ordering. These macros are essential for low-level C programming and can be dropped into any project to improve portability and correctness. The implementation is minimal and correct, following Linux kernel conventions.