{"id":41941259,"url":"https://github.com/isotes/tun-open","last_synced_at":"2026-01-25T18:38:19.692Z","repository":{"id":146379464,"uuid":"184889385","full_name":"isotes/tun-open","owner":"isotes","description":"Small library without dependencies to open/create a tun device on Linux and macOS","archived":false,"fork":false,"pushed_at":"2024-11-17T20:17:54.000Z","size":12,"stargazers_count":6,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-11-17T21:23:22.320Z","etag":null,"topics":["c-library","cross-platform","linux","macos","tuntap"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/isotes.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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":"2019-05-04T12:03:20.000Z","updated_at":"2024-11-17T20:17:57.000Z","dependencies_parsed_at":null,"dependency_job_id":"270c968f-2f39-4e05-9dc0-6635c5a68302","html_url":"https://github.com/isotes/tun-open","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/isotes/tun-open","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/isotes%2Ftun-open","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/isotes%2Ftun-open/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/isotes%2Ftun-open/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/isotes%2Ftun-open/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/isotes","download_url":"https://codeload.github.com/isotes/tun-open/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/isotes%2Ftun-open/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28756442,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-25T16:32:25.380Z","status":"ssl_error","status_checked_at":"2026-01-25T16:32:09.189Z","response_time":113,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["c-library","cross-platform","linux","macos","tuntap"],"created_at":"2026-01-25T18:38:19.155Z","updated_at":"2026-01-25T18:38:19.687Z","avatar_url":"https://github.com/isotes.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# tun-open\nSmall library without dependencies to open/create a TUN device on Linux and macOS.\n\n\n## Use\nThe implementation consists of 1 header and 1 source file and can be included directly in other projects. Additionally, the project contains a CMake file to build a library.\n\n\n## API\nThere is only one function and a few helper defines. There is no inbuilt support for configuring the created network interface.\n\n```C\nTunOpenName tunName;\nint fd = tunOpen(NULL, \u0026tunName);\nif (fd \u003c 0) {\n    perror(\"Creating a tun device failed\");\n    exit(1);\n}\nprintf(\"Created tun device %s\\n\", tunName.name);\n// device configuration (address, ...) required\nunsigned char buf[2048];\nwhile (1) {\n    ssize_t n = read(fd, buf, sizeof(buf));\n    if (n \u003c 0) {\n        printf(\"Reading from tun device failed\");\n        break;\n    }\n    if (TUN_OPEN_IS_IP6(buf)) {\n        printf(\"IPv6 packet with %zu bytes\\n\", n - TUN_OPEN_PACKET_OFFSET);\n    } else if (TUN_OPEN_IS_IP4(buf)) {\n        printf(\"IPv4 packet with %zu bytes\\n\", n - TUN_OPEN_PACKET_OFFSET);\n    } else {\n        printf(\"Unknown packet with %zu bytes\\n\", n - TUN_OPEN_PACKET_OFFSET);\n    }\n}\nclose(fd);\n```\n\n\n## Configuration\nThe CMake project provides 2 options that are both disabled by default:\n - `TUN_OPEN_ENABLE_VERBOSE`: enable verbose error output\n - `TUN_OPEN_ENABLE_TEST`: build the test executable\n\nWith `TUN_OPEN_ENABLE_VERBOSE`, the library will print an error message to stderr when a system call fails. This is only recommended during development. E.g., when used without root rights on macOS, it prints the following error message:\n```\ntunOpen:60: 'connect(fd, (const struct sockaddr *) \u0026addr, sizeof(addr))' failed: Operation not permitted\n```\n\n\n## TUN Device Configuration\nThe configuration of the TUN device is not covered by this library. The [test/example executable](test/test-tun-open.c) contained in this project makes use of the `ip` command line utility and can be used as inspiration.\n\n\n## Example\nThe [test executable](test/test-tun-open.c) provides a more complete example for IPv6:\n - it must run as root or, on Linux, the TUN device must already have been created with appropriate permissions\n - it can be called with an address (default: `fddf:face:face::5555`) and/or a device name (provided by the OS by default and ignored on macOS)\n - it opens the device, and assigns the address using the `ip` command\n    - the `ip` command is usually installed on Linux systems and is made available for macOS by the [iproute2mac](https://github.com/brona/iproute2mac) project (available on Homebrew)\n- it starts the `ping6` command in the background to ping an address in the virtual network\n- it runs in a loop, shows some information for each packet, and responds to  ICMPv6-Echo-Request message\n\n\n## Portability\nThe library supports only TUN (vs. TAP) interfaces to be compatible with macOS. Nevertheless, there are a couple of additional limitations on macOS:\n - It is only possible to create new devices (in contrast to opening existing ones).\n - Names must follow the pattern 'utun[NUMBER]' with 0 being already in use on macOS Sierra and newer.\n\nOn Linux, the library uses the [TUN/TAP](https://www.kernel.org/doc/Documentation/networking/tuntap.txt) interface provided by the kernel. On macOS, the library uses the [utun kernel control](https://github.com/apple/darwin-xnu/blob/master/bsd/net/if_utun.h) interface.\n\n\n## Java\nI've also created a pure Java library (using JNA) called [tun-io](https://github.com/isotes/tun-io).\n\n\n## License\n[MIT](LICENSE) for the library and [The Unlicense](https://unlicense.org/) for the test/example code.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fisotes%2Ftun-open","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fisotes%2Ftun-open","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fisotes%2Ftun-open/lists"}