TunnelForge.Tun
10.0.6
dotnet add package TunnelForge.Tun --version 10.0.6
NuGet\Install-Package TunnelForge.Tun -Version 10.0.6
<PackageReference Include="TunnelForge.Tun" Version="10.0.6" />
<PackageVersion Include="TunnelForge.Tun" Version="10.0.6" />
<PackageReference Include="TunnelForge.Tun" />
paket add TunnelForge.Tun --version 10.0.6
#r "nuget: TunnelForge.Tun, 10.0.6"
#:package TunnelForge.Tun@10.0.6
#addin nuget:?package=TunnelForge.Tun&version=10.0.6
#tool nuget:?package=TunnelForge.Tun&version=10.0.6
TunnelForge.Tun (v10.0.6)
Поддерживаемые языки / Supported languages / Unterstützte Sprachen / 支持的语言:
Русский
TunnelForge.Tun — кроссплатформенная библиотека для работы с виртуальными TUN-адаптерами. Предоставляет единый интерфейс ITunAdapter для Windows (через WinTun) и Linux (через /dev/net/tun). Все операции возвращают Result<T, E> — без исключений.
Установка
dotnet add package TunnelForge.Tun --version 10.0.6
Поддерживаемые платформы
| Платформа | Реализация |
|---|---|
| Windows (x64, x86, ARM, ARM64) | WinTun driver (wintun.dll) |
| Linux (x64, ARM, ARM64) | /dev/net/tun + ioctl |
Быстрый старт
Создание адаптера
// TunAdapterFactory возвращает Option<ITunAdapter>
// Some — на поддерживаемой ОС, None — на неподдерживаемой
TunAdapterFactory.Create("MyTunnel").Match(
some: adapter =>
{
adapter.SetAddress("10.0.0.2", "255.255.255.0")
.InspectErr(e => Console.WriteLine($"SetAddress failed: {e}"));
adapter.Up()
.InspectErr(e => Console.WriteLine($"Up failed: {e}"));
// ... работа с адаптером ...
adapter.Dispose();
return Unit.Value;
},
none: () =>
{
Console.WriteLine("Платформа не поддерживается");
return Unit.Value;
}
);
Получение и отправка пакетов
byte[] buffer = new byte[65535];
// ReceivePacket возвращает Result<int, string>
adapter.ReceivePacket(buffer).Match(
ok: bytes =>
{
if (bytes > 0)
Console.WriteLine($"Получено {bytes} байт");
},
err: e => Console.WriteLine($"Ошибка: {e}")
);
// SendPacket возвращает Result<Unit, string>
byte[] packet = /* данные IP-пакета */;
adapter.SendPacket(packet, 0, packet.Length)
.InspectErr(e => Console.WriteLine($"Отправка не удалась: {e}"));
Важные замечания
- На Windows требуются права администратора.
- На Linux требуются права root или capability CAP_NET_ADMIN.
ReadWaitHandleвозвращаетIntPtr.Zeroна Linux — используйте блокирующийReceivePacket.- Адаптер автоматически закрывается при вызове
Dispose(). - Все методы возвращают
Result<T, E>— проверяйтеIsOk/IsErrили используйтеMatch.
English
TunnelForge.Tun is a cross-platform library for virtual TUN adapters. It provides a unified ITunAdapter interface for Windows (via WinTun) and Linux (via /dev/net/tun). All operations return Result<T, E> — no exceptions.
Installation
dotnet add package TunnelForge.Tun --version 10.0.6
Supported Platforms
| Platform | Backend |
|---|---|
| Windows (x64, x86, ARM, ARM64) | WinTun driver (wintun.dll) |
| Linux (x64, ARM, ARM64) | /dev/net/tun + ioctl |
Quick Start
Create an adapter
// TunAdapterFactory returns Option<ITunAdapter>
// Some on supported OS, None on unsupported
TunAdapterFactory.Create("MyTunnel").Match(
some: adapter =>
{
adapter.SetAddress("10.0.0.2", "255.255.255.0")
.InspectErr(e => Console.WriteLine($"SetAddress failed: {e}"));
adapter.Up()
.InspectErr(e => Console.WriteLine($"Up failed: {e}"));
// ... use adapter ...
adapter.Dispose();
return Unit.Value;
},
none: () =>
{
Console.WriteLine("Platform not supported");
return Unit.Value;
}
);
Receive and send packets
byte[] buffer = new byte[65535];
// ReceivePacket returns Result<int, string>
adapter.ReceivePacket(buffer).Match(
ok: bytes =>
{
if (bytes > 0)
Console.WriteLine($"Received {bytes} bytes");
},
err: e => Console.WriteLine($"Error: {e}")
);
// SendPacket returns Result<Unit, string>
byte[] packet = /* IP packet data */;
adapter.SendPacket(packet, 0, packet.Length)
.InspectErr(e => Console.WriteLine($"Send failed: {e}"));
Important Notes
- Administrator privileges required on Windows.
- Root or CAP_NET_ADMIN capability required on Linux.
ReadWaitHandlereturnsIntPtr.Zeroon Linux — use blockingReceivePacketinstead.- Adapter is automatically cleaned up on
Dispose(). - All methods return
Result<T, E>— checkIsOk/IsError useMatch.
Deutsch
TunnelForge.Tun ist eine plattformübergreifende Bibliothek für virtuelle TUN-Adapter. Sie bietet eine einheitliche ITunAdapter-Schnittstelle für Windows (via WinTun) und Linux (via /dev/net/tun). Alle Operationen geben Result<T, E> zurück — keine Exceptions.
Installation
dotnet add package TunnelForge.Tun --version 10.0.6
Unterstützte Plattformen
| Plattform | Backend |
|---|---|
| Windows (x64, x86, ARM, ARM64) | WinTun-Treiber (wintun.dll) |
| Linux (x64, ARM, ARM64) | /dev/net/tun + ioctl |
Schnellstart
TunAdapterFactory.Create("MyTunnel").Match(
some: adapter =>
{
adapter.SetAddress("10.0.0.2", "255.255.255.0");
adapter.Up();
// ... Adapter verwenden ...
adapter.Dispose();
return Unit.Value;
},
none: () =>
{
Console.WriteLine("Plattform nicht unterstützt");
return Unit.Value;
}
);
Wichtige Hinweise
- Administratorrechte auf Windows erforderlich.
- Root oder CAP_NET_ADMIN auf Linux erforderlich.
- Alle Methoden geben
Result<T, E>zurück — keine Exceptions.
简体中文
TunnelForge.Tun 是一个跨平台虚拟 TUN 适配器库。提供统一的 ITunAdapter 接口,支持 Windows(通过 WinTun)和 Linux(通过 /dev/net/tun)。所有操作返回 Result<T, E> — 无异常。
安装
dotnet add package TunnelForge.Tun --version 10.0.6
支持的平台
| 平台 | 后端 |
|---|---|
| Windows (x64, x86, ARM, ARM64) | WinTun 驱动 (wintun.dll) |
| Linux (x64, ARM, ARM64) | /dev/net/tun + ioctl |
快速开始
TunAdapterFactory.Create("MyTunnel").Match(
some: adapter =>
{
adapter.SetAddress("10.0.0.2", "255.255.255.0");
adapter.Up();
// ... 使用适配器 ...
adapter.Dispose();
return Unit.Value;
},
none: () =>
{
Console.WriteLine("不支持的平台");
return Unit.Value;
}
);
重要提示
- Windows 上需要管理员权限。
- Linux 上需要 root 或 CAP_NET_ADMIN 权限。
- 所有方法返回
Result<T, E>— 无异常。
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. 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 was computed. 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 was computed. 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 was computed. 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 is compatible. 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 was computed. |
| .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. |
-
.NETStandard 2.1
- Rustly (>= 10.6.3)
- TunnelForge.WinTun (>= 10.1.1)
-
net10.0
- Rustly (>= 10.6.3)
- TunnelForge.WinTun (>= 10.1.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
EN:
Version 10.0.6:
- Updated dependecies: Rustly.{Analyzers, Generators} 10.6.3 and Rustly 10.6.3.
RU:
Версия 10.0.6:
- Обновлены зависимости: Rustly.{Analyzers, Generators} 10.6.3 и Rustly 10.6.3.