### Create Wintun Adapters Source: https://github.com/alananisimov/olcbox/blob/main/androidApp/src/main/jni/hev-socks5-tunnel/third-part/wintun/README.md Demonstrates how to create multiple Wintun adapters with different names and GUIDs. Ensure you have unique GUIDs for each adapter. ```C WINTUN_ADAPTER_HANDLE Adapter1 = WintunCreateAdapter(L"OfficeNet", L"Wintun", &SomeFixedGUID1); WINTUN_ADAPTER_HANDLE Adapter2 = WintunCreateAdapter(L"HomeNet", L"Wintun", &SomeFixedGUID2); WINTUN_ADAPTER_HANDLE Adapter3 = WintunCreateAdapter(L"Data Center", L"Wintun", &SomeFixedGUID3); ``` -------------------------------- ### Android Keystore Properties Example Source: https://github.com/alananisimov/olcbox/blob/main/README.MD Example configuration for Android release builds, requiring a `keystore.properties` file in the repository root. ```properties storeFile=/absolute/path/to/release.keystore storePassword=... keyAlias=... keyPassword=... ``` -------------------------------- ### Start SOCKS5 Tunnel from File Source: https://github.com/alananisimov/olcbox/blob/main/androidApp/src/main/jni/hev-socks5-tunnel/README.md Start and run the SOCKS5 tunnel using a configuration file. This function blocks until the tunnel is quit or an error occurs. ```c /** * hev_socks5_tunnel_main: * @config_path: config file path * @tun_fd: tunnel file descriptor * * Start and run the socks5 tunnel, this function will blocks until the * hev_socks5_tunnel_quit is called or an error occurs. * * Alias of hev_socks5_tunnel_main_from_file * * Returns: returns zero on successful, otherwise returns -1. * * Since: 2.4.6 */ int hev_socks5_tunnel_main (const char *config_path, int tun_fd); ``` -------------------------------- ### Start Wintun Session Source: https://github.com/alananisimov/olcbox/blob/main/androidApp/src/main/jni/hev-socks5-tunnel/third-part/wintun/README.md Starts a Wintun session for a given adapter with a specified capacity. The capacity determines the size of the ring buffer. ```C WINTUN_SESSION_HANDLE Session = WintunStartSession(Adapter2, 0x400000); ``` -------------------------------- ### Start SOCKS5 Tunnel from File (Specific Version) Source: https://github.com/alananisimov/olcbox/blob/main/androidApp/src/main/jni/hev-socks5-tunnel/README.md Start and run the SOCKS5 tunnel using a configuration file. This function blocks until the tunnel is quit or an error occurs. ```c /** * hev_socks5_tunnel_main_from_file: * @config_path: config file path * @tun_fd: tunnel file descriptor * * Start and run the socks5 tunnel, this function will blocks until the * hev_socks5_tunnel_quit is called or an error occurs. * * Returns: returns zero on successful, otherwise returns -1. * * Since: 2.6.7 */ int hev_socks5_tunnel_main_from_file (const char *config_path, int tun_fd); ``` -------------------------------- ### Start SOCKS5 Tunnel from String Source: https://github.com/alananisimov/olcbox/blob/main/androidApp/src/main/jni/hev-socks5-tunnel/README.md Start and run the SOCKS5 tunnel using a configuration string. This function blocks until the tunnel is quit or an error occurs. ```c /** * hev_socks5_tunnel_main_from_str: * @config_str: string config * @config_len: the byte length of string config * @tun_fd: tunnel file descriptor * * Start and run the socks5 tunnel, this function will blocks until the * hev_socks5_tunnel_quit is called or an error occurs. * * Returns: returns zero on successful, otherwise returns -1. * * Since: 2.6.7 */ int hev_socks5_tunnel_main_from_str (const unsigned char *config_str, unsigned int config_len, int tun_fd); ``` -------------------------------- ### Install and Manage HevSocks5Tunnel on OpenWrt Source: https://github.com/alananisimov/olcbox/blob/main/androidApp/src/main/jni/hev-socks5-tunnel/README.md Install the HevSocks5Tunnel package using opkg, edit its configuration, and restart the service. ```sh # Install package opkg install hev-socks5-tunnel # Edit /etc/config/hev-socks5-tunnel # Restart service /etc/init.d/hev-socks5-tunnel restart ``` -------------------------------- ### HevSocks5Core Server Example Source: https://github.com/alananisimov/olcbox/blob/main/androidApp/src/main/jni/hev-socks5-tunnel/src/core/README.md Sets up a SOCKS5 server that listens on port 1080 for incoming IPv6 connections. It handles new client connections by creating a new server instance and task for each. ```c #include #include #include #include #include #include #include static void server_entry (void *data) { HevSocks5Server *server = data; hev_socks5_server_run (server); hev_object_unref (HEV_OBJECT (server)); } static void listener_entry (void *data) { struct addrinfo hints = { 0 }; struct addrinfo *result; int fd; hints.ai_family = AF_INET6; hints.ai_socktype = SOCK_STREAM; hints.ai_flags = AI_PASSIVE; hev_task_dns_getaddrinfo (NULL, "1080", &hints, &result); fd = hev_task_io_socket_socket (AF_INET6, SOCK_STREAM, 0); bind (fd, result->ai_addr, result->ai_addrlen); freeaddrinfo (result); listen (fd, 5); hev_task_add_fd (hev_task_self (), fd, POLLIN); for (;;) { HevSocks5Server *server; HevTask *task; int nfd; nfd = hev_task_io_socket_accept (fd, NULL, NULL, NULL, NULL); task = hev_task_new (-1); server = hev_socks5_server_new (nfd); hev_task_run (task, server_entry, server); } close (fd); } int main (int argc, char *argv[]) { HevTask *task; hev_task_system_init (); task = hev_task_new (-1); hev_task_run (task, listener_entry, NULL); hev_task_system_run (); hev_task_system_fini (); return 0; } ``` -------------------------------- ### Linux Privilege Override Examples Source: https://github.com/alananisimov/olcbox/blob/main/README.MD Demonstrates how to run the Gradle desktopApp task with elevated privileges on Linux using `sudo` or `pkexec`. ```bash OLCBOX_LINUX_PRIVILEGE=sudo ./gradlew :desktopApp:run ``` ```bash OLCBOX_LINUX_PRIVILEGE=pkexec ./gradlew :desktopApp:run ``` -------------------------------- ### HevSocks5Tunnel Configuration Example Source: https://github.com/alananisimov/olcbox/blob/main/androidApp/src/main/jni/hev-socks5-tunnel/README.md A sample YAML configuration file for HevSocks5Tunnel, detailing settings for the tunnel, SOCKS5 proxy, and optional DNS mapping. ```yaml tunnel: # Interface name name: tun0 # Interface MTU mtu: 8500 # Multi-queue multi-queue: false # IPv4 address ipv4: 198.18.0.1 # IPv6 address ipv6: 'fc00::1' # Post up script # post-up-script: up.sh # Pre down script # pre-down-script: down.sh socks5: # Socks5 server port port: 1080 # Socks5 server address (ipv4/ipv6) address: 127.0.0.1 # Socks5 UDP relay mode (tcp|udp) udp: 'udp' # Override the UDP address provided by the Socks5 server (ipv4/ipv6) # udp-address: '' # Socks5 handshake using pipeline mode # pipeline: false # Socks5 server username # username: 'username' # Socks5 server password # password: 'password' # Socket mark # mark: 0 #mapdns: # Mapped DNS address # address: 198.18.0.2 # Mapped DNS port # port: 53 # Mapped IP network base # network: 100.64.0.0 # Mapped IP network mask # netmask: 255.192.0.0 # Mapped DNS cache size # cache-size: 10000 #misc: # task stack size (bytes) # task-stack-size: 86016 # tcp buffer size (bytes) # tcp-buffer-size: 65536 # udp socket recv buffer (SO_RCVBUF) size (bytes) # udp-recv-buffer-size: 524288 # number of udp buffers in splice, 1500 bytes per buffer. # udp-copy-buffer-nums: 10 # maximum session count (0: unlimited) # max-session-count: 0 # connect timeout (ms) # connect-timeout: 10000 # TCP read-write timeout (ms) # tcp-read-write-timeout: 300000 # UDP read-write timeout (ms) # udp-read-write-timeout: 60000 # stdout, stderr or file-path # log-file: stderr # debug, info, warn or error # log-level: warn # If present, run as a daemon with this pid file # pid-file: /run/hev-socks5-tunnel.pid # If present, set rlimit nofile; else use default value # limit-nofile: 65535 ``` -------------------------------- ### hev_socks5_tunnel_main_from_file Source: https://github.com/alananisimov/olcbox/blob/main/androidApp/src/main/jni/hev-socks5-tunnel/README.md Starts and runs the SOCKS5 tunnel using a configuration file. This function blocks until the tunnel is quit or an error occurs. ```APIDOC ## hev_socks5_tunnel_main_from_file ### Description Starts and runs the SOCKS5 tunnel using a configuration file. This function blocks until `hev_socks5_tunnel_quit` is called or an error occurs. ### Parameters * **config_path** (const char *) - Path to the configuration file. * **tun_fd** (int) - File descriptor for the tunnel interface. ### Returns Returns zero on success, otherwise returns -1. ### Since 2.6.7 ``` -------------------------------- ### WintunStartSession Source: https://github.com/alananisimov/olcbox/blob/main/androidApp/src/main/jni/hev-socks5-tunnel/third-part/wintun/README.md Starts a Wintun session on a given adapter with a specified ring capacity. The session must be ended using WintunEndSession. ```APIDOC ## WintunStartSession ### Description Starts a Wintun session on the specified adapter with a given ring capacity. ### Parameters - **Adapter** (WINTUN_ADAPTER_HANDLE) - The adapter handle obtained from WintunOpenAdapter or WintunCreateAdapter. - **Capacity** (DWORD) - The capacity of the rings. Must be between WINTUN_MIN_RING_CAPACITY and WINTUN_MAX_RING_CAPACITY (inclusive) and must be a power of two. ### Returns - **WINTUN_SESSION_HANDLE** - A handle to the Wintun session if successful, otherwise NULL. Call GetLastError for extended error information. The session must be released with WintunEndSession. ``` -------------------------------- ### HevSocks5Core Client Examples Source: https://github.com/alananisimov/olcbox/blob/main/androidApp/src/main/jni/hev-socks5-tunnel/src/core/README.md Demonstrates how to establish TCP and UDP client connections through a SOCKS5 proxy. The TCP client connects to a specified host and port, while the UDP client supports UDP-in-TCP mode. ```c #include #include #include #include #include static void tcp_client_entry (void *data) { HevSocks5ClientTCP *tcp; tcp = hev_socks5_client_tcp_new_name ("www.google.com", 443); hev_socks5_client_connect (HEV_SOCKS5_CLIENT (tcp), "127.0.0.1", 1080); hev_socks5_client_handshake (HEV_SOCKS5_CLIENT (tcp)); /* * splice data to/from a socket fd: * hev_socks5_tcp_splice (HEV_SOCKS5_TCP (tcp), fd); */ hev_object_unref (HEV_OBJECT (tcp)); } static void udp_client_entry (void *data) { HevSocks5ClientUDP *udp; udp = hev_socks5_client_udp_new (HEV_SOCKS5_TYPE_UDP_IN_TCP); hev_socks5_client_connect (HEV_SOCKS5_CLIENT (udp), "127.0.0.1", 1080); hev_socks5_client_handshake (HEV_SOCKS5_CLIENT (udp)); /* * HevSocks5UDPMsg msgv[num]; * * send udp packets: * hev_socks5_udp_sendmmsg (HEV_SOCKS5_UDP (udp), msgv, num); * * recv udp packets: * hev_socks5_udp_recvmmsg (HEV_SOCKS5_UDP (udp), msgv, num, 0); */ hev_object_unref (HEV_OBJECT (udp)); } int main (int argc, char *argv[]) { HevTask *task; hev_task_system_init (); task = hev_task_new (-1); hev_task_run (task, tcp_client_entry, NULL); task = hev_task_new (-1); hev_task_run (task, udp_client_entry, NULL); hev_task_system_run (); hev_task_system_fini (); return 0; } ``` -------------------------------- ### hev_socks5_tunnel_main_from_str Source: https://github.com/alananisimov/olcbox/blob/main/androidApp/src/main/jni/hev-socks5-tunnel/README.md Starts and runs the SOCKS5 tunnel using a configuration string. This function blocks until the tunnel is quit or an error occurs. ```APIDOC ## hev_socks5_tunnel_main_from_str ### Description Starts and runs the SOCKS5 tunnel using a configuration string. This function blocks until `hev_socks5_tunnel_quit` is called or an error occurs. ### Parameters * **config_str** (const unsigned char *) - String containing the configuration. * **config_len** (unsigned int) - The byte length of the configuration string. * **tun_fd** (int) - File descriptor for the tunnel interface. ### Returns Returns zero on success, otherwise returns -1. ### Since 2.6.7 ``` -------------------------------- ### Docker Compose Setup Source: https://github.com/alananisimov/olcbox/blob/main/androidApp/src/main/jni/hev-socks5-tunnel/README.md Set up a Docker Compose environment for the HEV SOCKS5 Tunnel, including client and tun services with necessary configurations and environment variables. ```yaml version: "3.9" services: client: image: alpine:latest # just for network testing tty: true # you can test network in terminal depends_on: tun: condition: service_healthy network_mode: "service:tun" tun: image: ghcr.io/heiher/hev-socks5-tunnel:latest # `latest` for the latest published version; `nightly` for the latest source build; `vX.Y.Z` for the specific version cap_add: - NET_ADMIN # needed devices: - /dev/net/tun:/dev/net/tun # needed environment: TUN: tun0 # optional, tun interface name, default `tun0` MTU: 8500 # optional, MTU is MTU, default `8500` IPV4: 198.18.0.1 # optional, tun interface ip, default `198.18.0.1` TABLE: 20 # optional, ip route table id, default `20` MARK: 438 # optional, ip route rule mark, dec or hex format, default `438` SOCKS5_ADDR: a.b.c.d # socks5 proxy server address SOCKS5_PORT: 1080 # socks5 proxy server port SOCKS5_USERNAME: user # optional, socks5 proxy username, only set when need to auth SOCKS5_PASSWORD: pass # optional, socks5 proxy password, only set when need to auth SOCKS5_UDP_MODE: udp # optional, UDP relay mode, default `udp`, other option `tcp` SOCKS5_UDP_ADDR: a.b.c.d # optional, override the UDP address provided by the Socks5 server CONFIG_ROUTES: 1 # optional, set 0 to ignore TABLE, IPV4_INCLUDED_ROUTES and IPV4_EXCLUDED_ROUTES, with MARK defaults to 0 IPV4_INCLUDED_ROUTES: 0.0.0.0/0 # optional, demo means proxy all traffic. for multiple network segments, join with `,` or `\n` IPV4_EXCLUDED_ROUTES: a.b.c.d # optional, demo means exclude traffic from the proxy itself. for multiple network segments, join with `,` or `\n` LOG_LEVEL: warn # optional, default `warn`, other option `debug`/`info`/`error` dns: - 8.8.8.8 ``` -------------------------------- ### WintunCreateAdapter Source: https://github.com/alananisimov/olcbox/blob/main/androidApp/src/main/jni/hev-socks5-tunnel/third-part/wintun/README.md Creates a new Wintun adapter with a specified name, tunnel type, and optional GUID. The adapter must be released using WintunCloseAdapter. ```APIDOC ## WintunCreateAdapter ### Description Creates a new Wintun adapter. The adapter handle must be released with WintunCloseAdapter. ### Parameters - **Name** (const WCHAR *) - The requested name of the adapter. Zero-terminated string of up to MAX_ADAPTER_NAME-1 characters. - **TunnelType** (const WCHAR *) - Name of the adapter tunnel type. Zero-terminated string of up to MAX_ADAPTER_NAME-1 characters. - **RequestedGUID** (const GUID *) - The GUID of the created network adapter. If NULL, the GUID is chosen randomly by the system. ### Returns - **WINTUN_ADAPTER_HANDLE** - A handle to the created adapter if successful, otherwise NULL. Call GetLastError for extended error information. ``` -------------------------------- ### hev_socks5_tunnel_main Source: https://github.com/alananisimov/olcbox/blob/main/androidApp/src/main/jni/hev-socks5-tunnel/README.md Starts and runs the SOCKS5 tunnel using a configuration file. This function blocks until the tunnel is quit or an error occurs. It is an alias for `hev_socks5_tunnel_main_from_file`. ```APIDOC ## hev_socks5_tunnel_main ### Description Starts and runs the SOCKS5 tunnel using a configuration file. This function blocks until `hev_socks5_tunnel_quit` is called or an error occurs. It is an alias for `hev_socks5_tunnel_main_from_file`. ### Parameters * **config_path** (const char *) - Path to the configuration file. * **tun_fd** (int) - File descriptor for the tunnel interface. ### Returns Returns zero on success, otherwise returns -1. ### Since 2.4.6 ``` -------------------------------- ### UDP Accept Handler Source: https://github.com/alananisimov/olcbox/blob/main/androidApp/src/main/jni/hev-socks5-tunnel/third-part/lwip/README.md Callback function for handling new UDP connections or packet reception setup. It prepares a new UDP PCB for sending and receiving. ```c static void udp_accept_handler (void *arg, struct udp_pcb *pcb, struct pbuf *p, const ip_addr_t *addr, u16_t port) { // Similar to TCP accept, receive packets on new UDP PCB. // @pcb: An new UDP PCB for sending and receiving. // @p: Unused // @addr: Unused // @port: Unused udp_recv (pcb, udp_recv_handler, NULL); } ``` -------------------------------- ### Build YAML on Unix Source: https://github.com/alananisimov/olcbox/blob/main/androidApp/src/main/jni/hev-socks5-tunnel/third-part/yaml/README.md Clone the repository, navigate into the directory, and run 'make' to build on Unix systems. ```bash git clone https://gitlab.com/hev/yaml cd yaml make ``` -------------------------------- ### Build Static and Shared Libraries Source: https://github.com/alananisimov/olcbox/blob/main/androidApp/src/main/jni/hev-socks5-tunnel/README.md Clone the repository and use make to build either a static or a shared library. ```bash git clone --recursive https://github.com/heiher/hev-socks5-tunnel cd hev-socks5-tunnel # Static library make static # Shared library make shared ``` -------------------------------- ### Build LwIP on Unix Source: https://github.com/alananisimov/olcbox/blob/main/androidApp/src/main/jni/hev-socks5-tunnel/third-part/lwip/README.md Builds the LwIP library on a Unix-like system using Make. Clones the repository and executes the make command. ```bash git clone https://gitlab.com/hev/lwip cd lwip make ``` -------------------------------- ### Build YAML on Android Source: https://github.com/alananisimov/olcbox/blob/main/androidApp/src/main/jni/hev-socks5-tunnel/third-part/yaml/README.md Set up a directory, clone the repository into 'jni', and use 'ndk-build' for Android builds. ```bash mkdir yaml cd yaml git clone https://gitlab.com/hev/yaml jni ndk-build ``` -------------------------------- ### Build LwIP on Windows Source: https://github.com/alananisimov/olcbox/blob/main/androidApp/src/main/jni/hev-socks5-tunnel/third-part/lwip/README.md Builds the LwIP library on Windows using Make with a cross-compilation prefix. Clones the repository and executes the make command with the specified prefix. ```bash git clone https://gitlab.com/hev/lwip cd lwip make CROSS_PREFIX=x86_64-w64-mingw32- ``` -------------------------------- ### Build HevTaskSystem on Unix Source: https://github.com/alananisimov/olcbox/blob/main/androidApp/src/main/jni/hev-socks5-tunnel/third-part/hev-task-system/README.md Builds the HevTaskSystem library on Unix-like systems using Make. Includes options for linking with librt, disabling stack overflow detection, setting the stack backend, and disabling the sliced memory allocator. ```bash git clone https://gitlab.com/hev/hev-task-system cd hev-task-system make # Link with librt (only for glibc versions before 2.17) make LDFLAGS=-lrt # Disable stack overflow detection make ENABLE_STACK_OVERFLOW_DETECTION=0 # Set stack backend to heap (Recommended for 32-bit) make CONFIG_STACK_BACKEND=STACK_HEAP # Disable sliced memory allocator make ENABLE_MEMALLOC_SLICE=0 # Disable I/O splice by splice syscall (for old Linux kernel) make ENABLE_IO_SPLICE_SYSCALL=0 # Demos make apps # Tests make tests ``` -------------------------------- ### Build HevTaskSystem on Windows (MSYS2) Source: https://github.com/alananisimov/olcbox/blob/main/androidApp/src/main/jni/hev-socks5-tunnel/third-part/hev-task-system/README.md Builds the HevTaskSystem library on Windows using MSYS2 and Make, enabling native symbolic links. ```bash export MSYS=winsymlinks:native git clone https://gitlab.com/hev/hev-task-system cd hev-task-system make ``` -------------------------------- ### Build HevSocks5Tunnel on Windows (MSYS2) Source: https://github.com/alananisimov/olcbox/blob/main/androidApp/src/main/jni/hev-socks5-tunnel/README.md Set the MSYS environment variable for native symbolic links and use make to build on Windows via MSYS2. ```bash export MSYS=winsymlinks:native git clone --recursive https://github.com/heiher/hev-socks5-tunnel cd hev-socks5-tunnel make ``` -------------------------------- ### Clone and Build HevSocks5Tunnel on Unix Source: https://github.com/alananisimov/olcbox/blob/main/androidApp/src/main/jni/hev-socks5-tunnel/README.md Clone the repository recursively and build the project using make on Unix-like systems. ```bash git clone --recursive https://github.com/heiher/hev-socks5-tunnel cd hev-socks5-tunnel make ``` -------------------------------- ### Initialize UDP Gateway Source: https://github.com/alananisimov/olcbox/blob/main/androidApp/src/main/jni/hev-socks5-tunnel/third-part/lwip/README.md Initializes the network interface and sets up LwIP to receive UDP packets for hosts other than localhost. Binds to any IP and port for receiving. ```c static void gateway_init(void) { // Init netif netif_set_up (&netif); netif_set_link_up (&netif); netif_set_default (&netif); // Allow to pretend UDP on this netif netif_set_flags (&netif, NETIF_FLAG_PRETEND_UDP); udp = udp_new_ip_type (IPADDR_TYPE_ANY); // Bind TCP to netif first udp_bind_netif (udp, &netif); // Bind to receive packets to other hosts udp_bind (udp, NULL, 0); udp_recv (udp, udp_accept_handler, NULL); } ``` -------------------------------- ### Build HevTaskSystem on iOS and MacOS Source: https://github.com/alananisimov/olcbox/blob/main/androidApp/src/main/jni/hev-socks5-tunnel/third-part/hev-task-system/README.md Builds the HevTaskSystem library into an .xcframework for iOS and macOS. ```bash git clone https://gitlab.com/hev/hev-task-system cd hev-task-system # will generate HevTaskSystem.xcframework ./build-apple.sh ``` -------------------------------- ### Initialize TCP Gateway Source: https://github.com/alananisimov/olcbox/blob/main/androidApp/src/main/jni/hev-socks5-tunnel/third-part/lwip/README.md Initializes the network interface and sets up LwIP to handle incoming TCP connections for hosts other than localhost. Binds to any IP and port to listen for connections. ```c static void gateway_init(void) { // Init netif netif_set_up (&netif); netif_set_link_up (&netif); netif_set_default (&netif); // Allow to pretend TCP on this netif netif_set_flags (&netif, NETIF_FLAG_PRETEND_TCP); tcp = tcp_new_ip_type (IPADDR_TYPE_ANY); // Bind TCP to netif first tcp_bind_netif (tcp, &netif); // Bind to accept incoming connections to other hosts tcp_bind (tcp, NULL, 0); tcp_listen (tcp); tcp_accept (tcp, tcp_accept_handler); } ``` -------------------------------- ### Build HevTaskSystem on Android Source: https://github.com/alananisimov/olcbox/blob/main/androidApp/src/main/jni/hev-socks5-tunnel/third-part/hev-task-system/README.md Builds the HevTaskSystem library for Android using ndk-build. ```bash mkdir hev-task-system cd hev-task-system git clone https://gitlab.com/hev/hev-task-system jni ndk-build ``` -------------------------------- ### Run HevSocks5Tunnel on Windows Source: https://github.com/alananisimov/olcbox/blob/main/androidApp/src/main/jni/hev-socks5-tunnel/README.md Configure routing on Windows to bypass the upstream SOCKS5 server and route all other traffic through the tun interface. ```powershell # Bypass upstream socks5 server # 10.0.0.1: socks5 server # 10.0.2.2: default gateway route add 10.0.0.1/32 10.0.0.2 # Route others route change 0.0.0.0/0 0.0.0.0 if tun-index route change ::/0 :: if tun-index ``` -------------------------------- ### WintunOpenAdapter Source: https://github.com/alananisimov/olcbox/blob/main/androidApp/src/main/jni/hev-socks5-tunnel/third-part/wintun/README.md Opens an existing Wintun adapter by its name. The adapter handle must be released using WintunCloseAdapter. ```APIDOC ## WintunOpenAdapter ### Description Opens an existing Wintun adapter. ### Parameters - **Name** (const WCHAR *) - The name of the adapter to open. Zero-terminated string of up to MAX_ADAPTER_NAME-1 characters. ### Returns - **WINTUN_ADAPTER_HANDLE** - A handle to the opened adapter if successful, otherwise NULL. Call GetLastError for extended error information. ``` -------------------------------- ### Build HevSocks5Tunnel for iOS and macOS Source: https://github.com/alananisimov/olcbox/blob/main/androidApp/src/main/jni/hev-socks5-tunnel/README.md Clone the repository and run the build-apple.sh script to generate the HevSocks5Tunnel.xcframework. ```bash git clone --recursive https://github.com/heiher/hev-socks5-tunnel cd hev-socks5-tunnel ./build-apple.sh ``` -------------------------------- ### Build LwIP on Android Source: https://github.com/alananisimov/olcbox/blob/main/androidApp/src/main/jni/hev-socks5-tunnel/third-part/lwip/README.md Builds the LwIP library for Android using the NDK. Clones the repository into a jni directory and runs ndk-build. ```bash mkdir lwip cd lwip git clone https://gitlab.com/hev/lwip jni ndk-build ``` -------------------------------- ### Low Memory Configuration Source: https://github.com/alananisimov/olcbox/blob/main/androidApp/src/main/jni/hev-socks5-tunnel/README.md Configure task stack size, TCP buffer size, and maximum session count for low-memory systems like iOS to prevent out-of-memory issues. ```yaml misc: # task stack size (bytes) task-stack-size: 24576 # 20480 + tcp-buffer-size # tcp buffer size (bytes) tcp-buffer-size: 4096 # maximum session count max-session-count: 1200 ``` -------------------------------- ### Build HevSocks5Tunnel for Android Source: https://github.com/alananisimov/olcbox/blob/main/androidApp/src/main/jni/hev-socks5-tunnel/README.md Clone the repository into the jni directory and use ndk-build to build for Android. ```bash mkdir hev-socks5-tunnel cd hev-socks5-tunnel git clone --recursive https://github.com/heiher/hev-socks5-tunnel jni ndk-build ``` -------------------------------- ### WINTUN_MIN_RING_CAPACITY Definition Source: https://github.com/alananisimov/olcbox/blob/main/androidApp/src/main/jni/hev-socks5-tunnel/third-part/wintun/README.md Defines the minimum ring capacity for Wintun, set to 128kiB. ```C #define WINTUN_MIN_RING_CAPACITY 0x20000 /* 128kiB */ ``` -------------------------------- ### Run HevSocks5Tunnel on Linux Source: https://github.com/alananisimov/olcbox/blob/main/androidApp/src/main/jni/hev-socks5-tunnel/README.md Configure network settings for Linux to bypass upstream SOCKS5 server and route traffic through the tunnel interface. ```bash # Set socks5.mark = 438 bin/hev-socks5-tunnel conf/main.yml # Disable reverse path filter sudo sysctl -w net.ipv4.conf.all.rp_filter=0 sudo sysctl -w net.ipv4.conf.tun0.rp_filter=0 # Bypass upstream socks5 server sudo ip rule add fwmark 438 lookup main pref 10 sudo ip -6 rule add fwmark 438 lookup main pref 10 # Route others sudo ip route add default dev tun0 table 20 sudo ip rule add lookup 20 pref 20 sudo ip -6 route add default dev tun0 table 20 sudo ip -6 rule add lookup 20 pref 20 ``` -------------------------------- ### Multiple Route Rules Configuration Source: https://github.com/alananisimov/olcbox/blob/main/androidApp/src/main/jni/hev-socks5-tunnel/README.md Configure route rules with multiple network segments for included and excluded routes using YAML. ```yaml environment: IPV4_INCLUDED_ROUTES: 10.0.0.0/8,172.16.0.0/12,192.168.0.0/16 IPV4_EXCLUDED_ROUTES: |- a.b.c.d/24 a.b.c.f/24 ``` -------------------------------- ### Run HevSocks5Tunnel on FreeBSD/macOS Source: https://github.com/alananisimov/olcbox/blob/main/androidApp/src/main/jni/hev-socks5-tunnel/README.md Configure routing on FreeBSD/macOS to bypass the upstream SOCKS5 server and route all other traffic through the tun0 interface. ```zsh # Bypass upstream socks5 server # 10.0.0.1: socks5 server # 10.0.2.2: default gateway sudo route add -net 10.0.0.1/32 10.0.2.2 # Route others sudo route change -inet default -interface tun0 sudo route change -inet6 default -interface tun0 ``` -------------------------------- ### WINTUN_MAX_RING_CAPACITY Definition Source: https://github.com/alananisimov/olcbox/blob/main/androidApp/src/main/jni/hev-socks5-tunnel/third-part/wintun/README.md Defines the maximum ring capacity for Wintun, set to 64MiB. ```C #define WINTUN_MAX_RING_CAPACITY 0x4000000 /* 64MiB */ ``` -------------------------------- ### WintunSendPacket Source: https://github.com/alananisimov/olcbox/blob/main/androidApp/src/main/jni/hev-socks5-tunnel/third-part/wintun/README.md Sends a prepared packet and releases its internal buffer. This function is thread-safe, but the actual sending order is determined by the order of `WintunAllocateSendPacket` calls. ```APIDOC ## WintunSendPacket ### Description Sends the packet and releases its internal buffer. This function is thread-safe, but the order of calls to `WintunAllocateSendPacket` determines the packet sending order. The packet is not guaranteed to be sent immediately upon calling this function. ### Parameters #### Path Parameters - **Session** (WINTUN_SESSION_HANDLE) - Required - Wintun session handle obtained with `WintunStartSession`. - **Packet** (const BYTE *) - Required - Packet obtained with `WintunAllocateSendPacket`. ``` -------------------------------- ### WINTUN_ENUM_CALLBACK Typedef Source: https://github.com/alananisimov/olcbox/blob/main/androidApp/src/main/jni/hev-socks5-tunnel/third-part/wintun/README.md Defines the callback function signature for WintunEnumAdapters. It is called for each adapter found. ```C typedef BOOL(* WINTUN_ENUM_CALLBACK) (WINTUN_ADAPTER_HANDLE Adapter, LPARAM Param); ``` -------------------------------- ### WintunGetRunningDriverVersion Source: https://github.com/alananisimov/olcbox/blob/main/androidApp/src/main/jni/hev-socks5-tunnel/third-part/wintun/README.md Determines the version of the currently loaded Wintun driver. ```APIDOC ## WintunGetRunningDriverVersion ### Description Determines the version of the Wintun driver currently loaded. ### Returns - **DWORD** - The version number of the Wintun driver if successful, otherwise zero. Call GetLastError for extended error information. Possible errors include ERROR_FILE_NOT_FOUND if Wintun is not loaded. ``` -------------------------------- ### TCP Accept Handler Source: https://github.com/alananisimov/olcbox/blob/main/androidApp/src/main/jni/hev-socks5-tunnel/third-part/lwip/README.md Callback function for accepting new TCP connections. It provides details about the connection, including local and remote IP addresses and ports. ```c static err_t tcp_accept_handler (void *arg, struct tcp_pcb *pcb, err_t err) { // Accept new TCP connection // @pcb->local_ip: The real destination address // @pcb->local_port: The real destination port // @pcb->remote_ip: The real source address // @pcb->remote_port: The real source port } ``` -------------------------------- ### WintunEndSession Source: https://github.com/alananisimov/olcbox/blob/main/androidApp/src/main/jni/hev-socks5-tunnel/third-part/wintun/README.md Ends an active Wintun session and releases its resources. ```APIDOC ## WintunEndSession ### Description Ends an active Wintun session. ### Parameters - **Session** (WINTUN_SESSION_HANDLE) - The Wintun session handle obtained from WintunStartSession. ``` -------------------------------- ### Send Wintun Packet Source: https://github.com/alananisimov/olcbox/blob/main/androidApp/src/main/jni/hev-socks5-tunnel/third-part/wintun/README.md Allocates memory for an outgoing packet, copies data into it, and sends it through the Wintun session. Handles buffer overflow by dropping packets. ```C BYTE *OutgoingPacket = WintunAllocateSendPacket(Session, PacketDataSize); if (OutgoingPacket) { memcpy(OutgoingPacket, PacketData, PacketDataSize); WintunSendPacket(Session, OutgoingPacket); } else if (GetLastError() != ERROR_BUFFER_OVERFLOW) // Silently drop packets if the ring is full Log(L"Packet write failed"); ``` -------------------------------- ### WintunCloseAdapter Source: https://github.com/alananisimov/olcbox/blob/main/androidApp/src/main/jni/hev-socks5-tunnel/third-part/wintun/README.md Releases resources associated with a Wintun adapter and removes it if it was created by WintunCreateAdapter. ```APIDOC ## WintunCloseAdapter ### Description Releases Wintun adapter resources and removes the adapter if it was created with WintunCreateAdapter. ### Parameters - **Adapter** (WINTUN_ADAPTER_HANDLE) - The handle to the adapter obtained from WintunCreateAdapter or WintunOpenAdapter. ``` -------------------------------- ### WINTUN_MAX_IP_PACKET_SIZE Definition Source: https://github.com/alananisimov/olcbox/blob/main/androidApp/src/main/jni/hev-socks5-tunnel/third-part/wintun/README.md Defines the maximum size for an IP packet that Wintun can handle. ```C #define WINTUN_MAX_IP_PACKET_SIZE 0xFFFF ``` -------------------------------- ### WintunGetAdapterLuid Source: https://github.com/alananisimov/olcbox/blob/main/androidApp/src/main/jni/hev-socks5-tunnel/third-part/wintun/README.md Retrieves the LUID (Locally Unique Identifier) of a Wintun adapter. ```APIDOC ## WintunGetAdapterLuid ### Description Returns the LUID of the adapter. ### Parameters - **Adapter** (WINTUN_ADAPTER_HANDLE) - The adapter handle obtained from WintunOpenAdapter or WintunCreateAdapter. - **Luid** (NET_LUID *) - A pointer to a NET_LUID structure that will receive the adapter's LUID. ``` -------------------------------- ### WINTUN_ADAPTER_HANDLE Typedef Source: https://github.com/alananisimov/olcbox/blob/main/androidApp/src/main/jni/hev-socks5-tunnel/third-part/wintun/README.md Defines a handle representing a Wintun adapter. This is a void pointer. ```C typedef void* WINTUN_ADAPTER_HANDLE; ``` -------------------------------- ### WintunSetLogger Source: https://github.com/alananisimov/olcbox/blob/main/androidApp/src/main/jni/hev-socks5-tunnel/third-part/wintun/README.md Sets a callback function to receive diagnostic messages from the Wintun logger. Can be set to NULL to disable logging. ```APIDOC ## WintunSetLogger ### Description Sets a callback function to receive diagnostic messages from the Wintun logger. The callback may be invoked concurrently from multiple threads, so serialization must be handled within the callback if necessary. ### Parameters - **NewLogger** (WINTUN_LOGGER_CALLBACK) - A pointer to the callback function to be used as the global logger. Set to NULL to disable logging. ``` -------------------------------- ### WintunGetReadWaitEvent Source: https://github.com/alananisimov/olcbox/blob/main/androidApp/src/main/jni/hev-socks5-tunnel/third-part/wintun/README.md Retrieves the event handle for waiting on available data for reading from a Wintun session. This event is managed by the session and should not be closed by the client. ```APIDOC ## WintunGetReadWaitEvent ### Description Gets the Wintun session's read-wait event handle. This event can be used to wait for available data when reading packets. If `WintunReceivePackets` repeatedly returns `ERROR_NO_MORE_ITEMS`, waiting on this event can be used to retry the operation. ### Parameters #### Path Parameters - **Session** (WINTUN_SESSION_HANDLE) - Required - Wintun session handle obtained with `WintunStartSession`. ### Returns Pointer to the event handle. The client should not call `CloseHandle` on this event. ``` -------------------------------- ### UDP Receive Handler Source: https://github.com/alananisimov/olcbox/blob/main/androidApp/src/main/jni/hev-socks5-tunnel/third-part/lwip/README.md Callback function for receiving UDP packets. It processes incoming packets and sends them back using the source address. ```c static void udp_recv_handler (void *arg, struct udp_pcb *pcb, struct pbuf *p, const ip_addr_t *addr, u16_t port) { // Receive UDP packets // @pcb->local_ip: The real destination address // @pcb->local_port: The real destination port // @pcb->remote_ip: The real source address // @pcb->remote_port: The real source port // @addr: Unused // @port: Unused // Send with source address udp_sendfrom (pcb, p, real_src_ip, real_src_port); pbuf_free (p); } ``` -------------------------------- ### WintunReceivePacket Source: https://github.com/alananisimov/olcbox/blob/main/androidApp/src/main/jni/hev-socks5-tunnel/third-part/wintun/README.md Retrieves a single network packet from the Wintun session. The returned packet's content can be modified, and the buffer must be released using `WintunReleaseReceivePacket`. ```APIDOC ## WintunReceivePacket ### Description Retrieves one or more packets from the Wintun session. After consuming the packet content, the internal buffer must be released by calling `WintunReleaseReceivePacket`. This function is thread-safe. ### Parameters #### Path Parameters - **Session** (WINTUN_SESSION_HANDLE) - Required - Wintun session handle obtained with `WintunStartSession`. - **PacketSize** (DWORD *) - Required - Pointer to receive the packet size. ### Returns Pointer to a layer 3 IPv4 or IPv6 packet. The client may modify its content. Returns `NULL` on failure. Possible errors include `ERROR_HANDLE_EOF`, `ERROR_NO_MORE_ITEMS`, and `ERROR_INVALID_DATA`. ``` -------------------------------- ### Receive Wintun Packet Source: https://github.com/alananisimov/olcbox/blob/main/androidApp/src/main/jni/hev-socks5-tunnel/third-part/wintun/README.md Continuously receives packets from a Wintun session. If no packet is available, it waits on a read-event. Handles packet read failures. ```C for (;;) { DWORD IncomingPacketSize; BYTE *IncomingPacket = WintunReceivePacket(Session, &IncomingPacketSize); if (IncomingPacket) { DoSomethingWithPacket(IncomingPacket, IncomingPacketSize); WintunReleaseReceivePacket(Session, IncomingPacket); } else if (GetLastError() == ERROR_NO_MORE_ITEMS) WaitForSingleObject(WintunGetReadWaitEvent(Session), INFINITE); else { Log(L"Packet read failed"); break; } } ``` -------------------------------- ### WINTUN_MAX_POOL Definition Source: https://github.com/alananisimov/olcbox/blob/main/androidApp/src/main/jni/hev-socks5-tunnel/third-part/wintun/README.md Defines the maximum length for a Wintun pool name, including the null terminator. ```C #define WINTUN_MAX_POOL 256 ``` -------------------------------- ### WintunAllocateSendPacket Source: https://github.com/alananisimov/olcbox/blob/main/androidApp/src/main/jni/hev-socks5-tunnel/third-part/wintun/README.md Allocates memory for a packet intended for sending. The allocated memory should be filled with packet data and then sent using `WintunSendPacket`. This function is thread-safe and call order determines sending order. ```APIDOC ## WintunAllocateSendPacket ### Description Allocates memory for a packet to be sent. After filling the memory with packet data, call `WintunSendPacket` to send it and release the buffer. This function is thread-safe, and the order of calls determines the packet sending order. ### Parameters #### Path Parameters - **Session** (WINTUN_SESSION_HANDLE) - Required - Wintun session handle obtained with `WintunStartSession`. - **PacketSize** (DWORD) - Required - Exact packet size. Must be less than or equal to `WINTUN_MAX_IP_PACKET_SIZE`. ### Returns Returns a pointer to the memory where the layer 3 IPv4 or IPv6 packet should be prepared. Returns `NULL` on failure. Possible errors include `ERROR_HANDLE_EOF` and `ERROR_BUFFER_OVERFLOW`. ``` -------------------------------- ### WintunDeleteDriver Source: https://github.com/alananisimov/olcbox/blob/main/androidApp/src/main/jni/hev-socks5-tunnel/third-part/wintun/README.md Deletes the Wintun driver if no adapters are currently in use. ```APIDOC ## WintunDeleteDriver ### Description Deletes the Wintun driver if there are no more adapters in use. ### Returns - **BOOL** - Nonzero if the function succeeds, zero if it fails. Call GetLastError for extended error information. ``` -------------------------------- ### Stop SOCKS5 Tunnel Source: https://github.com/alananisimov/olcbox/blob/main/androidApp/src/main/jni/hev-socks5-tunnel/README.md Stop the HEV SOCKS5 tunnel. This function should be called to gracefully shut down the tunnel process. ```c /** * hev_socks5_tunnel_quit: * * Stop the socks5 tunnel. * * Since: 2.4.6 */ void hev_socks5_tunnel_quit (void); ``` -------------------------------- ### hev_socks5_tunnel_quit Source: https://github.com/alananisimov/olcbox/blob/main/androidApp/src/main/jni/hev-socks5-tunnel/README.md Stops the SOCKS5 tunnel. This function should be called to unblock the main tunnel function. ```APIDOC ## hev_socks5_tunnel_quit ### Description Stops the SOCKS5 tunnel. This function should be called to unblock the main tunnel function. ### Since 2.4.6 ``` -------------------------------- ### Retrieve Tunnel Traffic Statistics Source: https://github.com/alananisimov/olcbox/blob/main/androidApp/src/main/jni/hev-socks5-tunnel/README.md Retrieve tunnel interface traffic statistics, including transmitted and received packets and bytes. The output parameters will be populated with the current statistics. ```c /** * hev_socks5_tunnel_stats: * @tx_packets (out): transmitted packets * @tx_bytes (out): transmitted bytes * @rx_packets (out): received packets * @rx_bytes (out): received bytes * * Retrieve tunnel interface traffic statistics. * * Since: 2.6.5 */ void hev_socks5_tunnel_stats (size_t *tx_packets, size_t *tx_bytes, size_t *rx_packets, size_t *rx_bytes); ``` -------------------------------- ### hev_socks5_tunnel_stats Source: https://github.com/alananisimov/olcbox/blob/main/androidApp/src/main/jni/hev-socks5-tunnel/README.md Retrieves the tunnel interface traffic statistics, including transmitted and received packets and bytes. ```APIDOC ## hev_socks5_tunnel_stats ### Description Retrieves tunnel interface traffic statistics. ### Parameters * **tx_packets** (size_t *) - Output pointer for transmitted packets count. * **tx_bytes** (size_t *) - Output pointer for transmitted bytes count. * **rx_packets** (size_t *) - Output pointer for received packets count. * **rx_bytes** (size_t *) - Output pointer for received bytes count. ### Since 2.6.5 ``` -------------------------------- ### WintunReleaseReceivePacket Source: https://github.com/alananisimov/olcbox/blob/main/androidApp/src/main/jni/hev-socks5-tunnel/third-part/wintun/README.md Releases the internal buffer associated with a received packet after it has been processed. This function is thread-safe. ```APIDOC ## WintunReleaseReceivePacket ### Description Releases the internal buffer after the received packet has been processed by the client. This function is thread-safe. ### Parameters #### Path Parameters - **Session** (WINTUN_SESSION_HANDLE) - Required - Wintun session handle obtained with `WintunStartSession`. - **Packet** (const BYTE *) - Required - Packet obtained with `WintunReceivePacket`. ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.