Ryujinx/Ryujinx.HLE/HOS/Services/Sockets/Bsd/Types/BsdSockAddr.cs
TSRBerry ba5c0cf5d8
Bsd: Implement Select (#4017)
* bsd: Add gdkchan's Select implementation

Co-authored-by: TSRBerry <20988865+tsrberry@users.noreply.github.com>

* bsd: Fix Select() causing a crash with an ArgumentException

.NET Sockets have to be used for the Select() call

* bsd: Make Select more generic

* bsd: Adjust namespaces and remove unused imports

* bsd: Fix NullReferenceException in Select

Co-authored-by: gdkchan <gab.dark.100@gmail.com>
2022-12-12 14:59:31 +01:00

39 lines
1.1 KiB
C#

using Ryujinx.Common.Memory;
using System;
using System.Net;
using System.Runtime.InteropServices;
namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd.Types
{
[StructLayout(LayoutKind.Sequential, Pack = 1, Size = 0x10)]
struct BsdSockAddr
{
public byte Length;
public byte Family;
public ushort Port;
public Array4<byte> Address;
private Array8<byte> _reserved;
public IPEndPoint ToIPEndPoint()
{
IPAddress address = new IPAddress(Address.AsSpan());
int port = (ushort)IPAddress.NetworkToHostOrder((short)Port);
return new IPEndPoint(address, port);
}
public static BsdSockAddr FromIPEndPoint(IPEndPoint endpoint)
{
BsdSockAddr result = new BsdSockAddr
{
Length = 0,
Family = (byte)endpoint.AddressFamily,
Port = (ushort)IPAddress.HostToNetworkOrder((short)endpoint.Port)
};
endpoint.Address.GetAddressBytes().AsSpan().CopyTo(result.Address.AsSpan());
return result;
}
}
}