From 2ee3a99690d5e795309cd5199a9a3ca62221b14d Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Wed, 27 Mar 2019 10:54:25 +0100 Subject: [PATCH] Add basic usage info Signed-off-by: Jason A. Donenfeld --- README.md | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/README.md b/README.md index 248eda0..df77951 100644 --- a/README.md +++ b/README.md @@ -29,3 +29,47 @@ If you possess an EV certificate for kernel mode code signing you should switch Modify the `` to contain the full path to the cross-signing certificate of CA that issued your certificate. You should be able to find its `.crt` file in `C:\Program Files (x86)\Windows Kits\10\CrossCertificates`. Note that the `$(WDKContentRoot)` expands to `C:\Program Files (x86)\Windows Kits\10\`. If you already have `wintun.vcxproj.user` file, just add the `` section. + +## Usage + +After loading the driver and creating a network interface the typical way using [SetupAPI](https://docs.microsoft.com/en-us/windows-hardware/drivers/install/setupapi), open `\\.\Device\WINTUN%d` as Local System, where `%d` is the [LUID](https://docs.microsoft.com/en-us/windows/desktop/api/ifdef/ns-ifdef-_net_luid_lh) of the network device. You may then [`ReadFile`](https://docs.microsoft.com/en-us/windows/desktop/api/fileapi/nf-fileapi-readfile) and [`WriteFile`](https://docs.microsoft.com/en-us/windows/desktop/api/fileapi/nf-fileapi-writefile) bundles of packets of the following format: + +``` ++------------------------------+ +| size_0 | +| 4 bytes, native endian | ++------------------------------+ +| | +| padding | +| 12 bytes, all zero | +| | ++------------------------------+ +| | +| packet_0 | +| size_0 bytes | +| | +~ ~ +| | ++------------------------------+ +| padding | +| 16-((4+size_0)&15) bytes, | +| all zero | ++------------------------------+ +| size_1 | +| 4 bytes, native endian | ++------------------------------+ +| | +| padding | +| 12 bytes, all zero | +| | ++------------------------------+ +| | +| packet_1 | +| size_1 bytes | +| | +~ ~ +``` + +Each packet segment should contain a layer 3 IPv4 or IPv6 packet. Up to 256 packets may be read or written during each call to `ReadFile` or `WriteFile`. + +It is advisable to use [overlapped I/O](https://docs.microsoft.com/en-us/windows/desktop/sync/synchronization-and-overlapped-input-and-output) for this. If using blocking I/O instead, it may be desirable to open separate handles for reading and writing.