aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2021-08-14 10:13:29 +0000
committerJason A. Donenfeld <Jason@zx2c4.com>2021-08-14 10:13:29 +0000
commit0ab19b6a457b672bdb613b4c92d9786a48edd605 (patch)
treea4215dde29fc1cbbef21c09475ea0c1462bfbf51
parentembeddable-dll-service: csharp: specify stdcall, not cdecl (diff)
downloadwireguard-windows-0ab19b6a457b672bdb613b4c92d9786a48edd605.tar.xz
wireguard-windows-0ab19b6a457b672bdb613b4c92d9786a48edd605.zip
embeddable-dll-service: csharp: fix type conversions
ADDRESS_FAMILY is a u16, not a u32. C# promotes a ushort to an int, not to a short, so ntohl was being called instead of ntohs. Fix this with explicit casts. Reported-by: Neutron <dotneutron@protonmail.ch> Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
-rw-r--r--embeddable-dll-service/csharp/TunnelDll/Driver.cs4
-rw-r--r--embeddable-dll-service/csharp/TunnelDll/Win32.cs2
2 files changed, 3 insertions, 3 deletions
diff --git a/embeddable-dll-service/csharp/TunnelDll/Driver.cs b/embeddable-dll-service/csharp/TunnelDll/Driver.cs
index 857d6a63..ecb097df 100644
--- a/embeddable-dll-service/csharp/TunnelDll/Driver.cs
+++ b/embeddable-dll-service/csharp/TunnelDll/Driver.cs
@@ -74,13 +74,13 @@ namespace Tunnel
{
var ip = new byte[4];
Marshal.Copy((IntPtr)ioctlPeer->Endpoint.Ipv4.sin_addr.bytes, ip, 0, 4);
- peer.Endpoint = new IPEndPoint(new IPAddress(ip), IPAddress.NetworkToHostOrder(ioctlPeer->Endpoint.Ipv4.sin_port));
+ peer.Endpoint = new IPEndPoint(new IPAddress(ip), (ushort)IPAddress.NetworkToHostOrder((short)ioctlPeer->Endpoint.Ipv4.sin_port));
}
else if (ioctlPeer->Endpoint.si_family == Win32.ADDRESS_FAMILY.AF_INET6)
{
var ip = new byte[16];
Marshal.Copy((IntPtr)ioctlPeer->Endpoint.Ipv6.sin6_addr.bytes, ip, 0, 16);
- peer.Endpoint = new IPEndPoint(new IPAddress(ip), IPAddress.NetworkToHostOrder(ioctlPeer->Endpoint.Ipv6.sin6_port));
+ peer.Endpoint = new IPEndPoint(new IPAddress(ip), (ushort)IPAddress.NetworkToHostOrder((short)ioctlPeer->Endpoint.Ipv6.sin6_port));
}
}
peer.TxBytes = ioctlPeer->TxBytes;
diff --git a/embeddable-dll-service/csharp/TunnelDll/Win32.cs b/embeddable-dll-service/csharp/TunnelDll/Win32.cs
index 4987fe8f..b4084ccf 100644
--- a/embeddable-dll-service/csharp/TunnelDll/Win32.cs
+++ b/embeddable-dll-service/csharp/TunnelDll/Win32.cs
@@ -180,7 +180,7 @@ namespace Tunnel
public ADDRESS_FAMILY si_family;
}
- public enum ADDRESS_FAMILY : UInt32
+ public enum ADDRESS_FAMILY : UInt16
{
AF_UNSPEC = 0,
AF_INET = 2,