-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
136 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,27 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<Nullable>enable</Nullable> | ||
<PropertyGroup> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<Nullable>enable</Nullable> | ||
<AllowUnsafeBlocks>True</AllowUnsafeBlocks> | ||
<IsPackable>false</IsPackable> | ||
</PropertyGroup> | ||
|
||
<IsPackable>false</IsPackable> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.11.0" /> | ||
<PackageReference Include="xunit" Version="2.4.1" /> | ||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3"> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
<PrivateAssets>all</PrivateAssets> | ||
</PackageReference> | ||
<PackageReference Include="coverlet.collector" Version="3.1.0"> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
<PrivateAssets>all</PrivateAssets> | ||
</PackageReference> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.11.0" /> | ||
<PackageReference Include="xunit" Version="2.4.1" /> | ||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3"> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
<PrivateAssets>all</PrivateAssets> | ||
</PackageReference> | ||
<PackageReference Include="coverlet.collector" Version="3.1.0"> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
<PrivateAssets>all</PrivateAssets> | ||
</PackageReference> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\WindivertDotnet\WindivertDotnet.csproj" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\WindivertDotnet\WindivertDotnet.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
using System.Net; | ||
using Xunit; | ||
|
||
namespace WindivertDotnet.Test | ||
{ | ||
public class WindivertRouterTest | ||
{ | ||
[Fact] | ||
public void IPv4LoopbackTest() | ||
{ | ||
var router = new WinDivertRouter(IPAddress.Loopback); | ||
Assert.Equal(IPAddress.Loopback, router.SrcAddress); | ||
Assert.Equal(IPAddress.Loopback, router.DstAddress); | ||
Assert.True(router.IsOutbound); | ||
Assert.True(router.IsLoopback); | ||
} | ||
|
||
[Fact] | ||
public unsafe void IPv4LoopbackAddrTest() | ||
{ | ||
var router = new WinDivertRouter(IPAddress.Loopback); | ||
using var addr = router.CreateAddress(); | ||
|
||
Assert.Equal(addr.Network->IfIdx, router.InterfaceIndex); | ||
Assert.True(addr.Flags.HasFlag(WinDivertAddressFlag.Outbound)); | ||
Assert.True(addr.Flags.HasFlag(WinDivertAddressFlag.Loopback)); | ||
} | ||
|
||
[Fact] | ||
public void IPv6LoopbackTest() | ||
{ | ||
var router = new WinDivertRouter(IPAddress.IPv6Loopback); | ||
Assert.Equal(IPAddress.IPv6Loopback, router.SrcAddress); | ||
Assert.Equal(IPAddress.IPv6Loopback, router.DstAddress); | ||
Assert.True(router.IsOutbound); | ||
Assert.True(router.IsLoopback); | ||
} | ||
|
||
[Fact] | ||
public void IPv41111Test() | ||
{ | ||
var dstAddrr = IPAddress.Parse("1.1.1.1"); | ||
var router = new WinDivertRouter(dstAddrr); | ||
Assert.NotEqual(IPAddress.Any, router.SrcAddress); | ||
Assert.Equal(dstAddrr, router.DstAddress); | ||
Assert.True(router.IsOutbound); | ||
Assert.False(router.IsLoopback); | ||
} | ||
|
||
[Fact] | ||
public unsafe void IPv41111AddrTest() | ||
{ | ||
var dstAddrr = IPAddress.Parse("1.1.1.1"); | ||
var router = new WinDivertRouter(dstAddrr); | ||
|
||
using var addr = new WinDivertAddress | ||
{ | ||
Flags = WinDivertAddressFlag.Loopback | ||
}; | ||
router.ApplyToAddress(addr); | ||
|
||
Assert.Equal(addr.Network->IfIdx, router.InterfaceIndex); | ||
Assert.True(addr.Flags.HasFlag(WinDivertAddressFlag.Outbound)); | ||
Assert.False(addr.Flags.HasFlag(WinDivertAddressFlag.Loopback)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters