TunnelForge.WinTun 3.0.2

dotnet add package TunnelForge.WinTun --version 3.0.2
                    
NuGet\Install-Package TunnelForge.WinTun -Version 3.0.2
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="TunnelForge.WinTun" Version="3.0.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="TunnelForge.WinTun" Version="3.0.2" />
                    
Directory.Packages.props
<PackageReference Include="TunnelForge.WinTun" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add TunnelForge.WinTun --version 3.0.2
                    
#r "nuget: TunnelForge.WinTun, 3.0.2"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package TunnelForge.WinTun@3.0.2
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=TunnelForge.WinTun&version=3.0.2
                    
Install as a Cake Addin
#tool nuget:?package=TunnelForge.WinTun&version=3.0.2
                    
Install as a Cake Tool

TunnelForge.WinTun

Поддерживаемые языки / Supported languages / Unterstützte Sprachen / 支持的语言:


Русский

TunnelForge.WinTun — это обёртка на C# для взаимодействия с нативным драйвером Wintun (Microsoft), который предоставляет высокопроизводительные виртуальные TUN-интерфейсы в Windows. Библиотека позволяет создавать адаптеры, открывать сессии для передачи сетевых пакетов и управлять их жизненным циклом с помощью удобного и низкоуровневого API.

Основные возможности

  • Создание и открытие адаптеров Wintun.
  • Управление сессиями чтения и записи сетевых пакетов.
  • Настройка логгирования нативных вызовов.
  • Получение событий готовности к чтению.
  • Полный контроль над памятью пакетов для минимизации копирований.

Быстрый старт — пример создания адаптера и сессии

using TunnelForge.WinTun;

var adapterName = "MyTunnelAdapter";
var tunnelType = "MyTunnelType"; // Обычно "Wintun"
var guid = new Guid(); // Можно передать пустой

// Создание адаптера
var adapter = WinTunNative.WintunCreateAdapter(adapterName, tunnelType, ref guid);
if (adapter == IntPtr.Zero)
{
    throw new Exception("Failed to create adapter");
}

// Запуск сессии с буфером на 1Мб
var session = WinTunNative.WintunStartSession(adapter, 1024 * 1024);
if (session == IntPtr.Zero)
{
    WinTunNative.WintunCloseAdapter(adapter);
    throw new Exception("Failed to start session");
}

// Получение события для ожидания данных
var waitEvent = WinTunNative.WintunGetReadWaitEvent(session);

// Получение пакета (если есть)
uint packetSize;
var packetPtr = WinTunNative.WintunReceivePacket(session, out packetSize);
if (packetPtr != IntPtr.Zero)
{
    byte[] packet = new byte[packetSize];
    Marshal.Copy(packetPtr, packet, 0, (int)packetSize);

    // Обработка пакета ...

    // Освобождение памяти пакета
    WinTunNative.WintunReleaseReceivePacket(session, packetPtr);
}

// Завершение сессии и закрытие адаптера
WinTunNative.WintunEndSession(session);
WinTunNative.WintunCloseAdapter(adapter);

Важные замечания

  • Работает только на Windows.
  • Требуются права администратора для создания адаптеров.
  • Следите за корректным освобождением ресурсов.
  • Размеры буферов влияют на производительность.

English

TunnelForge.WinTun is a C# wrapper for the native Wintun driver (by Microsoft), providing high-performance virtual TUN interfaces on Windows. This library allows creating adapters, opening sessions for packet transmission, and managing their lifecycle through a simple low-level API.

Key Features

  • Create and open Wintun adapters.
  • Manage read/write sessions for network packets.
  • Configure native logging callbacks.
  • Obtain read wait events for efficient async I/O.
  • Full control of packet memory to minimize copying.

Quick start example: create adapter and session

using TunnelForge.WinTun;

string adapterName = "MyTunnelAdapter";
string tunnelType = "MyTunnelType"; // Usually "Wintun"
Guid guid = new Guid(); // Empty GUID

// Create adapter
var adapter = WinTunNative.WintunCreateAdapter(adapterName, tunnelType, ref guid);
if (adapter == IntPtr.Zero)
{
    throw new Exception("Failed to create adapter");
}

// Start session with 1MB capacity
var session = WinTunNative.WintunStartSession(adapter, 1024 * 1024);
if (session == IntPtr.Zero)
{
    WinTunNative.WintunCloseAdapter(adapter);
    throw new Exception("Failed to start session");
}

// Get read wait event handle
var waitEvent = WinTunNative.WintunGetReadWaitEvent(session);

// Receive packet if available
uint packetSize;
var packetPtr = WinTunNative.WintunReceivePacket(session, out packetSize);
if (packetPtr != IntPtr.Zero)
{
    byte[] packet = new byte[packetSize];
    Marshal.Copy(packetPtr, packet, 0, (int)packetSize);

    // Process packet ...

    // Release packet memory
    WinTunNative.WintunReleaseReceivePacket(session, packetPtr);
}

// End session and close adapter
WinTunNative.WintunEndSession(session);
WinTunNative.WintunCloseAdapter(adapter);

Important Notes

  • Windows only.
  • Administrator privileges required to create adapters.
  • Proper resource cleanup is mandatory.
  • Buffer sizes affect performance.

Deutsch

TunnelForge.WinTun ist eine C#-Wrapper-Bibliothek für den nativen Wintun-Treiber (von Microsoft), die leistungsstarke virtuelle TUN-Schnittstellen unter Windows bereitstellt. Die Bibliothek ermöglicht das Erstellen von Adaptern, das Öffnen von Sessions für die Paketübertragung und die Verwaltung des Lebenszyklus über eine einfache Low-Level-API.

Hauptfunktionen

  • Erstellung und Öffnung von Wintun-Adaptern.
  • Verwaltung von Lese- und Schreib-Sessions für Netzwerkkarten.
  • Konfiguration von nativen Logger-Callbacks.
  • Empfang von Warte-Events für effizientes asynchrones IO.
  • Volle Kontrolle über Paket-Speicher zur Minimierung von Kopien.

Schnellstart-Beispiel: Adapter und Session erstellen

using TunnelForge.WinTun;

string adapterName = "MeinTunnelAdapter";
string tunnelType = "MeinTunnelTyp"; // Normalerweise "Wintun"
Guid guid = new Guid(); // Leerer GUID

// Adapter erstellen
var adapter = WinTunNative.WintunCreateAdapter(adapterName, tunnelType, ref guid);
if (adapter == IntPtr.Zero)
{
    throw new Exception("Adapter konnte nicht erstellt werden");
}

// Session mit 1MB Kapazität starten
var session = WinTunNative.WintunStartSession(adapter, 1024 * 1024);
if (session == IntPtr.Zero)
{
    WinTunNative.WintunCloseAdapter(adapter);
    throw new Exception("Session konnte nicht gestartet werden");
}

// Event für Lese-Wartezeit abrufen
var waitEvent = WinTunNative.WintunGetReadWaitEvent(session);

// Paket empfangen, falls vorhanden
uint packetSize;
var packetPtr = WinTunNative.WintunReceivePacket(session, out packetSize);
if (packetPtr != IntPtr.Zero)
{
    byte[] packet = new byte[packetSize];
    Marshal.Copy(packetPtr, packet, 0, (int)packetSize);

    // Paket verarbeiten ...

    // Paket-Speicher freigeben
    WinTunNative.WintunReleaseReceivePacket(session, packetPtr);
}

// Session beenden und Adapter schließen
WinTunNative.WintunEndSession(session);
WinTunNative.WintunCloseAdapter(adapter);

Wichtige Hinweise

  • Nur Windows wird unterstützt.
  • Administratorrechte sind zum Erstellen von Adaptern erforderlich.
  • Ressourcen müssen sorgfältig freigegeben werden.
  • Die Puffergrößen beeinflussen die Leistung.

简体中文

TunnelForge.WinTun 是微软 Wintun 驱动的 C# 封装库,提供高性能的虚拟 TUN 网络接口,仅限 Windows 平台。此库允许创建适配器、打开会话进行数据包传输,并通过简单的低级 API 管理其生命周期。

主要功能

  • 创建和打开 Wintun 适配器。
  • 管理网络数据包的读写会话。
  • 配置本地日志回调。
  • 获取读取等待事件,实现高效异步 IO。
  • 完全控制数据包内存,减少拷贝。

快速开始示例:创建适配器和会话

using TunnelForge.WinTun;

string adapterName = "MyTunnelAdapter";
string tunnelType = "MyTunnelType"; // 通常是 "Wintun"
Guid guid = new Guid(); // 空 GUID

// 创建适配器
var adapter = WinTunNative.WintunCreateAdapter(adapterName, tunnelType, ref guid);
if (adapter == IntPtr.Zero)
{
    throw new Exception("创建适配器失败");
}

// 启动容量为1MB的会话
var session = WinTunNative.WintunStartSession(adapter, 1024 * 1024);
if (session == IntPtr.Zero)
{
    WinTunNative.WintunCloseAdapter(adapter);
    throw new Exception("启动会话失败");
}

// 获取读取等待事件句柄
var waitEvent = WinTunNative.WintunGetReadWaitEvent(session);

// 如果有数据包则接收
uint packetSize;
var packetPtr = WinTunNative.WintunReceivePacket(session, out packetSize);
if (packetPtr != IntPtr.Zero)
{
    byte[] packet = new byte[packetSize];
    Marshal.Copy(packetPtr, packet, 0, (int)packetSize);

    // 处理数据包...

    // 释放数据包内存
    WinTunNative.WintunReleaseReceivePacket(session, packetPtr);
}

// 结束会话并关闭适配器
WinTunNative.WintunEndSession(session);
WinTunNative.WintunCloseAdapter(adapter);

重要提示

  • 仅支持 Windows。
  • 创建适配器需要管理员权限。
  • 必须正确释放资源。
  • 缓冲区大小影响性能。
Product Compatible and additional computed target framework versions.
.NET net5.0 is compatible.  net5.0-windows was computed.  net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 is compatible.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp3.0 was computed.  netcoreapp3.1 is compatible. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETCoreApp 3.1

    • No dependencies.
  • .NETStandard 2.1

    • No dependencies.
  • net5.0

    • No dependencies.
  • net6.0

    • No dependencies.
  • net7.0

    • No dependencies.
  • net8.0

    • No dependencies.
  • net9.0

    • No dependencies.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on TunnelForge.WinTun:

Package Downloads
TunnelForgeCoreNet

Cross-platform .NET Standard 2.1 library for TUN/TAP interface management on Windows and Linux with native interop.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
3.0.2 132 7/5/2025
3.0.1 98 7/5/2025 3.0.1 is deprecated because it has critical bugs.
3.0.0 100 7/5/2025 3.0.0 is deprecated because it has critical bugs.
2.1.22 307 6/24/2025 2.1.22 is deprecated because it is no longer maintained.
2.1.20 227 6/24/2025 2.1.20 is deprecated because it is no longer maintained.
2.1.19 263 6/23/2025 2.1.19 is deprecated because it is no longer maintained.
2.1.18 210 6/23/2025 2.1.18 is deprecated because it has critical bugs.
2.1.17 212 6/23/2025 2.1.17 is deprecated because it has critical bugs.
2.1.16 213 6/23/2025 2.1.16 is deprecated because it has critical bugs.
2.1.15 211 6/23/2025 2.1.15 is deprecated because it has critical bugs.
2.1.14 207 6/23/2025 2.1.14 is deprecated because it has critical bugs.
2.1.13 209 6/23/2025 2.1.13 is deprecated because it has critical bugs.
2.1.12 209 6/23/2025 2.1.12 is deprecated because it has critical bugs.
2.1.11 206 6/23/2025 2.1.11 is deprecated because it has critical bugs.
2.1.10 208 6/23/2025 2.1.10 is deprecated because it has critical bugs.
2.1.9 211 6/23/2025 2.1.9 is deprecated because it has critical bugs.
2.1.8 207 6/23/2025 2.1.8 is deprecated because it has critical bugs.
2.1.7 211 6/23/2025 2.1.7 is deprecated because it has critical bugs.
2.1.6 210 6/23/2025 2.1.6 is deprecated because it has critical bugs.
2.1.5 208 6/23/2025 2.1.5 is deprecated because it has critical bugs.
2.1.4 212 6/23/2025 2.1.4 is deprecated because it has critical bugs.
2.1.3 212 6/23/2025 2.1.3 is deprecated because it has critical bugs.
2.1.2 218 6/23/2025 2.1.2 is deprecated because it has critical bugs.
2.1.1 212 6/23/2025 2.1.1 is deprecated because it has critical bugs.
2.1.0 246 6/23/2025 2.1.0 is deprecated because it has critical bugs.
1.0.0 277 6/22/2025 1.0.0 is deprecated because it has critical bugs.

EN:
Version 2.1.22:
- Added full XML documentation to all WinTun P/Invoke bindings.
- Improved memory management and handle safety in low-level API.
- Fixed rare bug when closing TUN adapter on shutdown.

RU:
Версия 2.1.22:
- Добавлена полная XML-документация ко всем P/Invoke-функциям WinTun.
- Улучшено управление памятью и безопасностью дескрипторов в низкоуровневом API.
- Исправлена редкая ошибка при закрытии адаптера TUN при завершении работы.

DE:
Version 2.1.22:
- Vollständige XML-Dokumentation für alle WinTun-P/Invoke-Bindings hinzugefügt.
- Verbesserte Speicherverwaltung und Handle-Sicherheit in der Low-Level-API.
- Seltener Fehler beim Schließen des TUN-Adapters beim Herunterfahren behoben.

CN:
版本 2.1.22:
- 为所有 WinTun P/Invoke 绑定添加了完整的 XML 文档。
- 改进了底层 API 的内存管理和句柄安全性。
- 修复了关闭过程中偶发的 TUN 适配器关闭错误。