{"id":36924077,"url":"https://github.com/WireGuard/wintun","last_synced_at":"2026-01-19T18:00:38.282Z","repository":{"id":39972404,"uuid":"181283419","full_name":"WireGuard/wintun","owner":"WireGuard","description":"Mirror only. Official repository is at https://git.zx2c4.com/wintun","archived":false,"fork":false,"pushed_at":"2025-05-21T08:35:05.000Z","size":830,"stargazers_count":469,"open_issues_count":3,"forks_count":93,"subscribers_count":19,"default_branch":"master","last_synced_at":"2025-05-25T03:03:13.000Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://www.wintun.net","language":"C","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/WireGuard.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":"2019-04-14T08:58:54.000Z","updated_at":"2025-05-21T10:44:09.000Z","dependencies_parsed_at":"2024-11-13T15:43:48.539Z","dependency_job_id":"3a9ef870-5ac8-4408-a87e-c144de010381","html_url":"https://github.com/WireGuard/wintun","commit_stats":null,"previous_names":[],"tags_count":23,"template":false,"template_full_name":null,"purl":"pkg:github/WireGuard/wintun","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WireGuard%2Fwintun","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WireGuard%2Fwintun/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WireGuard%2Fwintun/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WireGuard%2Fwintun/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/WireGuard","download_url":"https://codeload.github.com/WireGuard/wintun/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WireGuard%2Fwintun/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28578952,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-19T17:42:58.221Z","status":"ssl_error","status_checked_at":"2026-01-19T17:40:54.158Z","response_time":67,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: 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":[],"created_at":"2026-01-12T19:00:25.485Z","updated_at":"2026-01-19T18:00:38.275Z","avatar_url":"https://github.com/WireGuard.png","language":"C","readme":"# [Wintun Network Adapter](https://www.wintun.net/)\n### TUN Device Driver for Windows\n\nThis is a layer 3 TUN driver for Windows 7, 8, 8.1, 10, and 11. Originally created for [WireGuard](https://www.wireguard.com/), it is intended to be useful to a wide variety of projects that require layer 3 tunneling devices with implementations primarily in userspace.\n\n## Installation\n\nWintun is deployed as a platform-specific `wintun.dll` file. Install the `wintun.dll` file side-by-side with your application. Download the dll from [wintun.net](https://www.wintun.net/), alongside the header file for your application described below.\n\n## Usage\n\nInclude the [`wintun.h` file](https://git.zx2c4.com/wintun/tree/api/wintun.h) in your project simply by copying it there and dynamically load the `wintun.dll` using [`LoadLibraryEx()`](https://docs.microsoft.com/en-us/windows/win32/api/libloaderapi/nf-libloaderapi-loadlibraryexa) and [`GetProcAddress()`](https://docs.microsoft.com/en-us/windows/win32/api/libloaderapi/nf-libloaderapi-getprocaddress) to resolve each function, using the typedefs provided in the header file. The [`InitializeWintun` function in the example.c code](https://git.zx2c4.com/wintun/tree/example/example.c) provides this in a function that you can simply copy and paste.\n\nWith the library setup, Wintun can then be used by first creating an adapter, configuring it, and then setting its status to \"up\". Adapters have names (e.g. \"OfficeNet\") and types (e.g. \"Wintun\").\n\n```C\nWINTUN_ADAPTER_HANDLE Adapter1 = WintunCreateAdapter(L\"OfficeNet\", L\"Wintun\", \u0026SomeFixedGUID1);\nWINTUN_ADAPTER_HANDLE Adapter2 = WintunCreateAdapter(L\"HomeNet\", L\"Wintun\", \u0026SomeFixedGUID2);\nWINTUN_ADAPTER_HANDLE Adapter3 = WintunCreateAdapter(L\"Data Center\", L\"Wintun\", \u0026SomeFixedGUID3);\n```\n\nAfter creating an adapter, we can use it by starting a session:\n\n```C\nWINTUN_SESSION_HANDLE Session = WintunStartSession(Adapter2, 0x400000);\n```\n\nThen, the `WintunAllocateSendPacket` and `WintunSendPacket` functions can be used for sending packets ([used by `SendPackets` in the example.c code](https://git.zx2c4.com/wintun/tree/example/example.c)):\n\n```C\nBYTE *OutgoingPacket = WintunAllocateSendPacket(Session, PacketDataSize);\nif (OutgoingPacket)\n{\n    memcpy(OutgoingPacket, PacketData, PacketDataSize);\n    WintunSendPacket(Session, OutgoingPacket);\n}\nelse if (GetLastError() != ERROR_BUFFER_OVERFLOW) // Silently drop packets if the ring is full\n    Log(L\"Packet write failed\");\n```\n\nAnd the `WintunReceivePacket` and `WintunReleaseReceivePacket` functions can be used for receiving packets ([used by `ReceivePackets` in the example.c code](https://git.zx2c4.com/wintun/tree/example/example.c)):\n\n```C\nfor (;;)\n{\n    DWORD IncomingPacketSize;\n    BYTE *IncomingPacket = WintunReceivePacket(Session, \u0026IncomingPacketSize);\n    if (IncomingPacket)\n    {\n        DoSomethingWithPacket(IncomingPacket, IncomingPacketSize);\n        WintunReleaseReceivePacket(Session, IncomingPacket);\n    }\n    else if (GetLastError() == ERROR_NO_MORE_ITEMS)\n        WaitForSingleObject(WintunGetReadWaitEvent(Session), INFINITE);\n    else\n    {\n        Log(L\"Packet read failed\");\n        break;\n    }\n}\n```\n\nSome high performance use cases may want to spin on `WintunReceivePackets` for a number of cycles before falling back to waiting on the read-wait event.\n\nYou are **highly encouraged** to read the [**example.c short example**](https://git.zx2c4.com/wintun/tree/example/example.c) to see how to put together a simple userspace network tunnel.\n\nThe various functions and definitions are [documented in the reference below](#Reference).\n\n## Reference\n\n### Macro Definitions\n\n#### WINTUN\\_MAX\\_POOL\n\n`#define WINTUN_MAX_POOL   256`\n\nMaximum pool name length including zero terminator\n\n#### WINTUN\\_MIN\\_RING\\_CAPACITY\n\n`#define WINTUN_MIN_RING_CAPACITY   0x20000 /* 128kiB */`\n\nMinimum ring capacity.\n\n#### WINTUN\\_MAX\\_RING\\_CAPACITY\n\n`#define WINTUN_MAX_RING_CAPACITY   0x4000000 /* 64MiB */`\n\nMaximum ring capacity.\n\n#### WINTUN\\_MAX\\_IP\\_PACKET\\_SIZE\n\n`#define WINTUN_MAX_IP_PACKET_SIZE   0xFFFF`\n\nMaximum IP packet size\n\n### Typedefs\n\n#### WINTUN\\_ADAPTER\\_HANDLE\n\n`typedef void* WINTUN_ADAPTER_HANDLE`\n\nA handle representing Wintun adapter\n\n#### WINTUN\\_ENUM\\_CALLBACK\n\n`typedef BOOL(* WINTUN_ENUM_CALLBACK) (WINTUN_ADAPTER_HANDLE Adapter, LPARAM Param)`\n\nCalled by WintunEnumAdapters for each adapter in the pool.\n\n**Parameters**\n\n- *Adapter*: Adapter handle, which will be freed when this function returns.\n- *Param*: An application-defined value passed to the WintunEnumAdapters.\n\n**Returns**\n\nNon-zero to continue iterating adapters; zero to stop.\n\n#### WINTUN\\_LOGGER\\_CALLBACK\n\n`typedef void(* WINTUN_LOGGER_CALLBACK) (WINTUN_LOGGER_LEVEL Level, DWORD64 Timestamp, const WCHAR *Message)`\n\nCalled by internal logger to report diagnostic messages\n\n**Parameters**\n\n- *Level*: Message level.\n- *Timestamp*: Message timestamp in in 100ns intervals since 1601-01-01 UTC.\n- *Message*: Message text.\n\n#### WINTUN\\_SESSION\\_HANDLE\n\n`typedef void* WINTUN_SESSION_HANDLE`\n\nA handle representing Wintun session\n\n### Enumeration Types\n\n#### WINTUN\\_LOGGER\\_LEVEL\n\n`enum WINTUN_LOGGER_LEVEL`\n\nDetermines the level of logging, passed to WINTUN\\_LOGGER\\_CALLBACK.\n\n- *WINTUN\\_LOG\\_INFO*: Informational\n- *WINTUN\\_LOG\\_WARN*: Warning\n- *WINTUN\\_LOG\\_ERR*: Error\n\nEnumerator\n\n### Functions\n\n#### WintunCreateAdapter()\n\n`WINTUN_ADAPTER_HANDLE WintunCreateAdapter (const WCHAR * Name, const WCHAR * TunnelType, const GUID * RequestedGUID)`\n\nCreates a new Wintun adapter.\n\n**Parameters**\n\n- *Name*: The requested name of the adapter. Zero-terminated string of up to MAX\\_ADAPTER\\_NAME-1 characters.\n- *Name*: Name of the adapter tunnel type. Zero-terminated string of up to MAX\\_ADAPTER\\_NAME-1 characters.\n- *RequestedGUID*: The GUID of the created network adapter, which then influences NLA generation deterministically. If it is set to NULL, the GUID is chosen by the system at random, and hence a new NLA entry is created for each new adapter. It is called \"requested\" GUID because the API it uses is completely undocumented, and so there could be minor interesting complications with its usage.\n\n**Returns**\n\nIf the function succeeds, the return value is the adapter handle. Must be released with WintunCloseAdapter. If the function fails, the return value is NULL. To get extended error information, call GetLastError.\n\n#### WintunOpenAdapter()\n\n`WINTUN_ADAPTER_HANDLE WintunOpenAdapter (const WCHAR * Name)`\n\nOpens an existing Wintun adapter.\n\n**Parameters**\n\n- *Name*: The requested name of the adapter. Zero-terminated string of up to MAX\\_ADAPTER\\_NAME-1 characters.\n\n**Returns**\n\nIf the function succeeds, the return value is adapter handle. Must be released with WintunCloseAdapter. If the function fails, the return value is NULL. To get extended error information, call GetLastError.\n\n#### WintunCloseAdapter()\n\n`void WintunCloseAdapter (WINTUN_ADAPTER_HANDLE Adapter)`\n\nReleases Wintun adapter resources and, if adapter was created with WintunCreateAdapter, removes adapter.\n\n**Parameters**\n\n- *Adapter*: Adapter handle obtained with WintunCreateAdapter or WintunOpenAdapter.\n\n#### WintunDeleteDriver()\n\n`BOOL WintunDeleteDriver ()`\n\nDeletes the Wintun driver if there are no more adapters in use.\n\n**Returns**\n\nIf the function succeeds, the return value is nonzero. If the function fails, the return value is zero. To get extended error information, call GetLastError.\n\n#### WintunGetAdapterLuid()\n\n`void WintunGetAdapterLuid (WINTUN_ADAPTER_HANDLE Adapter, NET_LUID * Luid)`\n\nReturns the LUID of the adapter.\n\n**Parameters**\n\n- *Adapter*: Adapter handle obtained with WintunOpenAdapter or WintunCreateAdapter\n- *Luid*: Pointer to LUID to receive adapter LUID.\n\n#### WintunGetRunningDriverVersion()\n\n`DWORD WintunGetRunningDriverVersion (void )`\n\nDetermines the version of the Wintun driver currently loaded.\n\n**Returns**\n\nIf the function succeeds, the return value is the version number. If the function fails, the return value is zero. To get extended error information, call GetLastError. Possible errors include the following: ERROR\\_FILE\\_NOT\\_FOUND Wintun not loaded\n\n#### WintunSetLogger()\n\n`void WintunSetLogger (WINTUN_LOGGER_CALLBACK NewLogger)`\n\nSets logger callback function.\n\n**Parameters**\n\n- *NewLogger*: Pointer to callback function to use as a new global logger. NewLogger may be called from various threads concurrently. Should the logging require serialization, you must handle serialization in NewLogger. Set to NULL to disable.\n\n#### WintunStartSession()\n\n`WINTUN_SESSION_HANDLE WintunStartSession (WINTUN_ADAPTER_HANDLE Adapter, DWORD Capacity)`\n\nStarts Wintun session.\n\n**Parameters**\n\n- *Adapter*: Adapter handle obtained with WintunOpenAdapter or WintunCreateAdapter\n- *Capacity*: Rings capacity. Must be between WINTUN\\_MIN\\_RING\\_CAPACITY and WINTUN\\_MAX\\_RING\\_CAPACITY (incl.) Must be a power of two.\n\n**Returns**\n\nWintun session handle. Must be released with WintunEndSession. If the function fails, the return value is NULL. To get extended error information, call GetLastError.\n\n#### WintunEndSession()\n\n`void WintunEndSession (WINTUN_SESSION_HANDLE Session)`\n\nEnds Wintun session.\n\n**Parameters**\n\n- *Session*: Wintun session handle obtained with WintunStartSession\n\n#### WintunGetReadWaitEvent()\n\n`HANDLE WintunGetReadWaitEvent (WINTUN_SESSION_HANDLE Session)`\n\nGets Wintun session's read-wait event handle.\n\n**Parameters**\n\n- *Session*: Wintun session handle obtained with WintunStartSession\n\n**Returns**\n\nPointer to receive event handle to wait for available data when reading. Should WintunReceivePackets return ERROR\\_NO\\_MORE\\_ITEMS (after spinning on it for a while under heavy load), wait for this event to become signaled before retrying WintunReceivePackets. Do not call CloseHandle on this event - it is managed by the session.\n\n#### WintunReceivePacket()\n\n`BYTE* WintunReceivePacket (WINTUN_SESSION_HANDLE Session, DWORD * PacketSize)`\n\nRetrieves one or packet. After the packet content is consumed, call WintunReleaseReceivePacket with Packet returned from this function to release internal buffer. This function is thread-safe.\n\n**Parameters**\n\n- *Session*: Wintun session handle obtained with WintunStartSession\n- *PacketSize*: Pointer to receive packet size.\n\n**Returns**\n\nPointer to layer 3 IPv4 or IPv6 packet. Client may modify its content at will. If the function fails, the return value is NULL. To get extended error information, call GetLastError. Possible errors include the following: ERROR\\_HANDLE\\_EOF Wintun adapter is terminating; ERROR\\_NO\\_MORE\\_ITEMS Wintun buffer is exhausted; ERROR\\_INVALID\\_DATA Wintun buffer is corrupt\n\n#### WintunReleaseReceivePacket()\n\n`void WintunReleaseReceivePacket (WINTUN_SESSION_HANDLE Session, const BYTE * Packet)`\n\nReleases internal buffer after the received packet has been processed by the client. This function is thread-safe.\n\n**Parameters**\n\n- *Session*: Wintun session handle obtained with WintunStartSession\n- *Packet*: Packet obtained with WintunReceivePacket\n\n#### WintunAllocateSendPacket()\n\n`BYTE* WintunAllocateSendPacket (WINTUN_SESSION_HANDLE Session, DWORD PacketSize)`\n\nAllocates memory for a packet to send. After the memory is filled with packet data, call WintunSendPacket to send and release internal buffer. WintunAllocateSendPacket is thread-safe and the WintunAllocateSendPacket order of calls define the packet sending order.\n\n**Parameters**\n\n- *Session*: Wintun session handle obtained with WintunStartSession\n- *PacketSize*: Exact packet size. Must be less or equal to WINTUN\\_MAX\\_IP\\_PACKET\\_SIZE.\n\n**Returns**\n\nReturns pointer to memory where to prepare layer 3 IPv4 or IPv6 packet for sending. If the function fails, the return value is NULL. To get extended error information, call GetLastError. Possible errors include the following: ERROR\\_HANDLE\\_EOF Wintun adapter is terminating; ERROR\\_BUFFER\\_OVERFLOW Wintun buffer is full;\n\n#### WintunSendPacket()\n\n`void WintunSendPacket (WINTUN_SESSION_HANDLE Session, const BYTE * Packet)`\n\nSends the packet and releases internal buffer. WintunSendPacket is thread-safe, but the WintunAllocateSendPacket order of calls define the packet sending order. This means the packet is not guaranteed to be sent in the WintunSendPacket yet.\n\n**Parameters**\n\n- *Session*: Wintun session handle obtained with WintunStartSession\n- *Packet*: Packet obtained with WintunAllocateSendPacket\n\n## Building\n\n**Do not distribute drivers or files named \"Wintun\", as they will most certainly clash with official deployments. Instead distribute [`wintun.dll` as downloaded from wintun.net](https://www.wintun.net).**\n\nGeneral requirements:\n\n- [Visual Studio 2019](https://visualstudio.microsoft.com/downloads/) with Windows SDK\n- [Windows Driver Kit](https://docs.microsoft.com/en-us/windows-hardware/drivers/download-the-wdk)\n\n`wintun.sln` may be opened in Visual Studio for development and building. Be sure to run `bcdedit /set testsigning on` and then reboot before to enable unsigned driver loading. The default run sequence (F5) in Visual Studio will build the example project and its dependencies.\n\n## License\n\nThe entire contents of [the repository](https://git.zx2c4.com/wintun/), including all documentation and example code, is \"Copyright © 2018-2021 WireGuard LLC. All Rights Reserved.\" Source code is licensed under the [GPLv2](COPYING). Prebuilt binaries from [wintun.net](https://www.wintun.net/) are released under a more permissive license suitable for more forms of software contained inside of the .zip files distributed there.\n","funding_links":[],"categories":["C"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FWireGuard%2Fwintun","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FWireGuard%2Fwintun","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FWireGuard%2Fwintun/lists"}