{"id":41283540,"url":"https://github.com/emanuele-f/zdtun","last_synced_at":"2026-01-23T02:57:21.008Z","repository":{"id":40359386,"uuid":"139055080","full_name":"emanuele-f/zdtun","owner":"emanuele-f","description":"zdtun: add VPN-like features to any app without additional dependencies","archived":false,"fork":false,"pushed_at":"2025-02-20T09:02:17.000Z","size":1044,"stargazers_count":64,"open_issues_count":0,"forks_count":10,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-02-20T10:22:05.091Z","etag":null,"topics":["android","linux","proxy","vpn","windows"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"lgpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/emanuele-f.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"COPYING","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-06-28T18:32:43.000Z","updated_at":"2025-02-20T09:02:21.000Z","dependencies_parsed_at":"2025-02-20T10:21:56.166Z","dependency_job_id":"5994b557-0747-4a21-a235-3fcf12df253e","html_url":"https://github.com/emanuele-f/zdtun","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/emanuele-f/zdtun","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/emanuele-f%2Fzdtun","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/emanuele-f%2Fzdtun/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/emanuele-f%2Fzdtun/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/emanuele-f%2Fzdtun/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/emanuele-f","download_url":"https://codeload.github.com/emanuele-f/zdtun/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/emanuele-f%2Fzdtun/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28679139,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-23T01:00:35.747Z","status":"online","status_checked_at":"2026-01-23T02:00:08.296Z","response_time":59,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["android","linux","proxy","vpn","windows"],"created_at":"2026-01-23T02:57:20.491Z","updated_at":"2026-01-23T02:57:21.003Z","avatar_url":"https://github.com/emanuele-f.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# zdtun\n\nzdtun (short for \"Zero Dependency Tunnel\") is a C library which provides an API to integrate VPN like functionalities on existing programs without installing third-party software or drivers on the target device.\n\nThis library is used in [PCAPdroid](https://github.com/emanuele-f/PCAPdroid) to capture network packets on Android without root.\n\nThe library implements parts of a TCP/IP stack, for example the tracking of sessions and handling of TCP sequence numbers and window size.\nHowever, zdtun *does not* implement any TCP retransmission logic, as this feature is already provided by the TCP sockets used internally.\n\n## Features\n\nzdtun offers the following features:\n\n  - Simple API to integrate into existing programs\n  - Supports Windows, Linux and Android\n  - Support UDP, TCP, ICMP and IPv4/IPv6\n  - Just one header file, no additional dependencies\n  - No special interface / promisc mode is used, only standard sockets\n  - Generic API to parse TCP/IP packets into a `zdtun_pkt`\n\n## Sample Integration\n\nHere is how to use the zdtun api to integrate its VPN capabilities into an existing program:\n\n```c\n#include \"zdtun.h\"\n\n/* This is called when zdtun needs to send data to the client */\nint send_client_callback(zdtun_t *tun, zdtun_pkt_t *pkt, const zdtun_conn_t *conn_info) {\n  int cli_socket = *((int*) zdtun_userdata(tun));\n\n  send(cli_socket, pkt-\u003ebuf, pkt-\u003elen, 0);\n}\n\nint main() {\n  /* A TCP socket connected to the client */\n  socket_t cli_socket = ...;\n  zdtun_callbacks_t callbacks = {\n    .send_client = send_client_callback,\n  };\n  ...\n\n  // ignore SIGPIPE, which can occur while sending data\n  signal(SIGPIPE, SIG_IGN);\n\n  zdtun_t *tun = zdtun_init(\u0026callbacks, \u0026cli_socket);\n\n  while(1) {\n    int max_fd = 0;\n    fd_set fdset;\n    fd_set wrfds;\n  \n    /* get zdtun own fds */\n    zdtun_fds(tun, \u0026max_fd, \u0026fdset, \u0026wrfds);\n\n    /* Add client fd to the readable fds */\n    FD_SET(cli_socket, \u0026fdset);\n    max_fd = max(max_fd, cli_socket);\n\n    /* Wait for socket events */\n    select(max_fd + 1, \u0026fdset, \u0026wrfds, NULL, NULL);\n\n    if(FD_ISSET(cli_socket, \u0026fdset)) {\n      /* Got data from the client, forward it to the private network */\n      size = recv(cli_socket, buffer, sizeof(buffer), 0);\n      zdtun_easy_forward(tun, buffer, size);\n    } else {\n      /* let zdtun handle it */\n      zdtun_handle_fd(tun, \u0026fdset, \u0026wrfds);\n    }\n  }\n\n  zdtun_finalize(tun);\n}\n```\n\nSee `zdtun_gateway.c` for a complete example.\n\n## Run Local Gateway\n\nThe `zdtun_gateway` is a program which routes all the local/internet connections\nthrough zdtun via a TUN device. It can be useful to easily test the zdtun\nfunctionalities locally.\n\n\n## Motivation\n\nThe library was initially developed for Windows, as a way to provide VPN-like feature into an existing program, and later extended for the linux/Android world.\n\nTunneling traffic through Windows can be tricky:\n  - TUN/TAP interfaces require a specific driver\n  - RAW sockets cannot enstablish TCP/UDP connections for security reasons\n  - Using libpcap-like functionalities requires installing WinPcap\n\nExisting solutions are complex and not appropriate to be integrated as a library\ninto an existing program.\n\n## See Also\n\n- zdtun used on Android to capture packets: https://github.com/emanuele-f/PCAPdroid\n- Reverse tethering on Android devices, employing a similar tecnique: https://github.com/Genymobile/gnirehtet/blob/master/DEVELOP.md\n- Android firewall app, employing a similar tecnique: https://github.com/m66b/NetGuard\n- RAW sockets for pivoting, no Windows support, no API: https://github.com/0x36/VPNPivot\n- https://docs.microsoft.com/en-us/windows/desktop/winsock/maximum-number-of-sockets-supported-2\n- http://tangentsoft.net/wskfaq/advanced.html#maxsockets\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Femanuele-f%2Fzdtun","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Femanuele-f%2Fzdtun","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Femanuele-f%2Fzdtun/lists"}