2018-10-17 19:15:50 +02:00
|
|
|
using Ryujinx.Common.Logging;
|
2021-03-24 18:43:23 +01:00
|
|
|
using Ryujinx.Cpu;
|
2022-01-03 22:12:50 +01:00
|
|
|
using Ryujinx.HLE.HOS.Services.Sockets.Nsd.Manager;
|
2021-03-24 18:43:23 +01:00
|
|
|
using Ryujinx.HLE.HOS.Services.Sockets.Sfdnsres.Proxy;
|
|
|
|
using Ryujinx.HLE.HOS.Services.Sockets.Sfdnsres.Types;
|
|
|
|
using Ryujinx.Memory;
|
2018-10-10 01:15:07 +02:00
|
|
|
using System;
|
2021-03-24 18:43:23 +01:00
|
|
|
using System.Buffers.Binary;
|
2018-02-28 21:58:04 +01:00
|
|
|
using System.Collections.Generic;
|
2021-03-24 18:43:23 +01:00
|
|
|
using System.Linq;
|
2018-10-10 01:15:07 +02:00
|
|
|
using System.Net;
|
|
|
|
using System.Net.Sockets;
|
2022-01-12 17:43:00 +01:00
|
|
|
using System.Runtime.InteropServices;
|
2018-10-10 01:15:07 +02:00
|
|
|
using System.Text;
|
|
|
|
|
2019-09-19 02:45:11 +02:00
|
|
|
namespace Ryujinx.HLE.HOS.Services.Sockets.Sfdnsres
|
2018-02-28 21:58:04 +01:00
|
|
|
{
|
2019-07-10 17:59:54 +02:00
|
|
|
[Service("sfdnsres")]
|
2018-04-06 06:01:52 +02:00
|
|
|
class IResolver : IpcService
|
2018-02-28 21:58:04 +01:00
|
|
|
{
|
2022-12-12 18:04:08 +01:00
|
|
|
public IResolver(ServiceCtx context)
|
|
|
|
{
|
|
|
|
DnsMitmResolver.Instance.ReloadEntries(context);
|
|
|
|
}
|
2018-10-10 01:15:07 +02:00
|
|
|
|
2023-04-15 01:00:34 +02:00
|
|
|
[CommandCmif(0)]
|
2021-03-24 18:43:23 +01:00
|
|
|
// SetDnsAddressesPrivateRequest(u32, buffer<unknown, 5, 0>)
|
|
|
|
public ResultCode SetDnsAddressesPrivateRequest(ServiceCtx context)
|
2018-10-10 01:15:07 +02:00
|
|
|
{
|
2021-03-24 18:43:23 +01:00
|
|
|
uint cancelHandleRequest = context.RequestData.ReadUInt32();
|
2021-04-24 12:16:01 +02:00
|
|
|
ulong bufferPosition = context.Request.SendBuff[0].Position;
|
|
|
|
ulong bufferSize = context.Request.SendBuff[0].Size;
|
2018-10-10 01:15:07 +02:00
|
|
|
|
2021-03-24 18:43:23 +01:00
|
|
|
// TODO: This is stubbed in 2.0.0+, reverse 1.0.0 version for the sake of completeness.
|
|
|
|
Logger.Stub?.PrintStub(LogClass.ServiceSfdnsres, new { cancelHandleRequest });
|
2018-10-10 01:15:07 +02:00
|
|
|
|
2021-03-24 18:43:23 +01:00
|
|
|
return ResultCode.NotAllocated;
|
|
|
|
}
|
2018-10-10 01:15:07 +02:00
|
|
|
|
2023-04-15 01:00:34 +02:00
|
|
|
[CommandCmif(1)]
|
2021-03-24 18:43:23 +01:00
|
|
|
// GetDnsAddressPrivateRequest(u32) -> buffer<unknown, 6, 0>
|
|
|
|
public ResultCode GetDnsAddressPrivateRequest(ServiceCtx context)
|
|
|
|
{
|
|
|
|
uint cancelHandleRequest = context.RequestData.ReadUInt32();
|
2021-04-24 12:16:01 +02:00
|
|
|
ulong bufferPosition = context.Request.ReceiveBuff[0].Position;
|
|
|
|
ulong bufferSize = context.Request.ReceiveBuff[0].Size;
|
2018-10-10 01:15:07 +02:00
|
|
|
|
2021-03-24 18:43:23 +01:00
|
|
|
// TODO: This is stubbed in 2.0.0+, reverse 1.0.0 version for the sake of completeness.
|
|
|
|
Logger.Stub?.PrintStub(LogClass.ServiceSfdnsres, new { cancelHandleRequest });
|
2018-10-10 01:15:07 +02:00
|
|
|
|
2021-03-24 18:43:23 +01:00
|
|
|
return ResultCode.NotAllocated;
|
|
|
|
}
|
2018-10-10 01:15:07 +02:00
|
|
|
|
2023-04-15 01:00:34 +02:00
|
|
|
[CommandCmif(2)]
|
2021-03-24 18:43:23 +01:00
|
|
|
// GetHostByNameRequest(u8, u32, u64, pid, buffer<unknown, 5, 0>) -> (u32, u32, u32, buffer<unknown, 6, 0>)
|
|
|
|
public ResultCode GetHostByNameRequest(ServiceCtx context)
|
|
|
|
{
|
2021-04-24 12:16:01 +02:00
|
|
|
ulong inputBufferPosition = context.Request.SendBuff[0].Position;
|
|
|
|
ulong inputBufferSize = context.Request.SendBuff[0].Size;
|
2018-10-10 01:15:07 +02:00
|
|
|
|
2021-04-24 12:16:01 +02:00
|
|
|
ulong outputBufferPosition = context.Request.ReceiveBuff[0].Position;
|
|
|
|
ulong outputBufferSize = context.Request.ReceiveBuff[0].Size;
|
2018-10-10 01:15:07 +02:00
|
|
|
|
2021-12-28 12:22:58 +01:00
|
|
|
return GetHostByNameRequestImpl(context, inputBufferPosition, inputBufferSize, outputBufferPosition, outputBufferSize, false, 0, 0);
|
2021-03-24 18:43:23 +01:00
|
|
|
}
|
|
|
|
|
2023-04-15 01:00:34 +02:00
|
|
|
[CommandCmif(3)]
|
2021-03-24 18:43:23 +01:00
|
|
|
// GetHostByAddrRequest(u32, u32, u32, u64, pid, buffer<unknown, 5, 0>) -> (u32, u32, u32, buffer<unknown, 6, 0>)
|
|
|
|
public ResultCode GetHostByAddrRequest(ServiceCtx context)
|
|
|
|
{
|
2021-04-24 12:16:01 +02:00
|
|
|
ulong inputBufferPosition = context.Request.SendBuff[0].Position;
|
|
|
|
ulong inputBufferSize = context.Request.SendBuff[0].Size;
|
2021-03-24 18:43:23 +01:00
|
|
|
|
2021-04-24 12:16:01 +02:00
|
|
|
ulong outputBufferPosition = context.Request.ReceiveBuff[0].Position;
|
|
|
|
ulong outputBufferSize = context.Request.ReceiveBuff[0].Size;
|
2021-03-24 18:43:23 +01:00
|
|
|
|
2021-12-28 12:22:58 +01:00
|
|
|
return GetHostByAddrRequestImpl(context, inputBufferPosition, inputBufferSize, outputBufferPosition, outputBufferSize, false, 0, 0);
|
2021-03-24 18:43:23 +01:00
|
|
|
}
|
|
|
|
|
2023-04-15 01:00:34 +02:00
|
|
|
[CommandCmif(4)]
|
2021-03-24 18:43:23 +01:00
|
|
|
// GetHostStringErrorRequest(u32) -> buffer<unknown, 6, 0>
|
|
|
|
public ResultCode GetHostStringErrorRequest(ServiceCtx context)
|
|
|
|
{
|
|
|
|
ResultCode resultCode = ResultCode.NotAllocated;
|
|
|
|
NetDbError errorCode = (NetDbError)context.RequestData.ReadInt32();
|
|
|
|
|
|
|
|
string errorString = errorCode switch
|
2018-10-10 01:15:07 +02:00
|
|
|
{
|
2021-03-24 18:43:23 +01:00
|
|
|
NetDbError.Success => "Resolver Error 0 (no error)",
|
|
|
|
NetDbError.HostNotFound => "Unknown host",
|
|
|
|
NetDbError.TryAgain => "Host name lookup failure",
|
|
|
|
NetDbError.NoRecovery => "Unknown server error",
|
|
|
|
NetDbError.NoData => "No address associated with name",
|
|
|
|
_ => (errorCode <= NetDbError.Internal) ? "Resolver internal error" : "Unknown resolver error"
|
|
|
|
};
|
|
|
|
|
2021-04-24 12:16:01 +02:00
|
|
|
ulong bufferPosition = context.Request.ReceiveBuff[0].Position;
|
|
|
|
ulong bufferSize = context.Request.ReceiveBuff[0].Size;
|
2021-03-24 18:43:23 +01:00
|
|
|
|
2021-04-24 12:16:01 +02:00
|
|
|
if ((ulong)(errorString.Length + 1) <= bufferSize)
|
2021-03-24 18:43:23 +01:00
|
|
|
{
|
2021-04-24 12:16:01 +02:00
|
|
|
context.Memory.Write(bufferPosition, Encoding.ASCII.GetBytes(errorString + '\0'));
|
2021-03-24 18:43:23 +01:00
|
|
|
|
|
|
|
resultCode = ResultCode.Success;
|
2018-10-10 01:15:07 +02:00
|
|
|
}
|
|
|
|
|
2021-03-24 18:43:23 +01:00
|
|
|
return resultCode;
|
2018-10-10 01:15:07 +02:00
|
|
|
}
|
|
|
|
|
2023-04-15 01:00:34 +02:00
|
|
|
[CommandCmif(5)]
|
2021-03-24 18:43:23 +01:00
|
|
|
// GetGaiStringErrorRequest(u32) -> buffer<byte, 6, 0>
|
|
|
|
public ResultCode GetGaiStringErrorRequest(ServiceCtx context)
|
2018-10-10 01:15:07 +02:00
|
|
|
{
|
2021-03-24 18:43:23 +01:00
|
|
|
ResultCode resultCode = ResultCode.NotAllocated;
|
|
|
|
GaiError errorCode = (GaiError)context.RequestData.ReadInt32();
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
if (errorCode > GaiError.Max)
|
2018-10-10 01:15:07 +02:00
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
errorCode = GaiError.Max;
|
2018-10-10 01:15:07 +02:00
|
|
|
}
|
|
|
|
|
2021-03-24 18:43:23 +01:00
|
|
|
string errorString = errorCode switch
|
|
|
|
{
|
|
|
|
GaiError.AddressFamily => "Address family for hostname not supported",
|
|
|
|
GaiError.Again => "Temporary failure in name resolution",
|
|
|
|
GaiError.BadFlags => "Invalid value for ai_flags",
|
|
|
|
GaiError.Fail => "Non-recoverable failure in name resolution",
|
|
|
|
GaiError.Family => "ai_family not supported",
|
|
|
|
GaiError.Memory => "Memory allocation failure",
|
|
|
|
GaiError.NoData => "No address associated with hostname",
|
|
|
|
GaiError.NoName => "hostname nor servname provided, or not known",
|
|
|
|
GaiError.Service => "servname not supported for ai_socktype",
|
|
|
|
GaiError.SocketType => "ai_socktype not supported",
|
|
|
|
GaiError.System => "System error returned in errno",
|
|
|
|
GaiError.BadHints => "Invalid value for hints",
|
|
|
|
GaiError.Protocol => "Resolved protocol is unknown",
|
|
|
|
GaiError.Overflow => "Argument buffer overflow",
|
|
|
|
GaiError.Max => "Unknown error",
|
|
|
|
_ => "Success"
|
|
|
|
};
|
|
|
|
|
2021-04-24 12:16:01 +02:00
|
|
|
ulong bufferPosition = context.Request.ReceiveBuff[0].Position;
|
|
|
|
ulong bufferSize = context.Request.ReceiveBuff[0].Size;
|
2021-03-24 18:43:23 +01:00
|
|
|
|
2021-04-24 12:16:01 +02:00
|
|
|
if ((ulong)(errorString.Length + 1) <= bufferSize)
|
2018-10-10 01:15:07 +02:00
|
|
|
{
|
2021-04-24 12:16:01 +02:00
|
|
|
context.Memory.Write(bufferPosition, Encoding.ASCII.GetBytes(errorString + '\0'));
|
2021-03-24 18:43:23 +01:00
|
|
|
|
|
|
|
resultCode = ResultCode.Success;
|
2018-10-10 01:15:07 +02:00
|
|
|
}
|
2021-03-24 18:43:23 +01:00
|
|
|
|
|
|
|
return resultCode;
|
2018-10-10 01:15:07 +02:00
|
|
|
}
|
|
|
|
|
2023-04-15 01:00:34 +02:00
|
|
|
[CommandCmif(6)]
|
2021-03-24 18:43:23 +01:00
|
|
|
// GetAddrInfoRequest(bool enable_nsd_resolve, u32, u64 pid_placeholder, pid, buffer<i8, 5, 0> host, buffer<i8, 5, 0> service, buffer<packed_addrinfo, 5, 0> hints) -> (i32 ret, u32 bsd_errno, u32 packed_addrinfo_size, buffer<packed_addrinfo, 6, 0> response)
|
|
|
|
public ResultCode GetAddrInfoRequest(ServiceCtx context)
|
2018-10-10 01:15:07 +02:00
|
|
|
{
|
2021-04-24 12:16:01 +02:00
|
|
|
ulong responseBufferPosition = context.Request.ReceiveBuff[0].Position;
|
|
|
|
ulong responseBufferSize = context.Request.ReceiveBuff[0].Size;
|
2018-10-10 01:15:07 +02:00
|
|
|
|
2021-12-26 15:17:13 +01:00
|
|
|
return GetAddrInfoRequestImpl(context, responseBufferPosition, responseBufferSize, false, 0, 0);
|
2018-10-10 01:15:07 +02:00
|
|
|
}
|
|
|
|
|
2023-04-15 01:00:34 +02:00
|
|
|
[CommandCmif(8)]
|
2021-03-24 18:43:23 +01:00
|
|
|
// GetCancelHandleRequest(u64, pid) -> u32
|
|
|
|
public ResultCode GetCancelHandleRequest(ServiceCtx context)
|
2018-10-10 01:15:07 +02:00
|
|
|
{
|
2021-03-24 18:43:23 +01:00
|
|
|
ulong pidPlaceHolder = context.RequestData.ReadUInt64();
|
|
|
|
uint cancelHandleRequest = 0;
|
|
|
|
|
|
|
|
context.ResponseData.Write(cancelHandleRequest);
|
|
|
|
|
|
|
|
Logger.Stub?.PrintStub(LogClass.ServiceSfdnsres, new { cancelHandleRequest });
|
|
|
|
|
|
|
|
return ResultCode.Success;
|
2018-10-10 01:15:07 +02:00
|
|
|
}
|
|
|
|
|
2023-04-15 01:00:34 +02:00
|
|
|
[CommandCmif(9)]
|
2021-03-24 18:43:23 +01:00
|
|
|
// CancelRequest(u32, u64, pid)
|
|
|
|
public ResultCode CancelRequest(ServiceCtx context)
|
2018-10-10 01:15:07 +02:00
|
|
|
{
|
2021-03-24 18:43:23 +01:00
|
|
|
uint cancelHandleRequest = context.RequestData.ReadUInt32();
|
|
|
|
ulong pidPlaceHolder = context.RequestData.ReadUInt64();
|
2018-10-10 01:15:07 +02:00
|
|
|
|
2021-03-24 18:43:23 +01:00
|
|
|
Logger.Stub?.PrintStub(LogClass.ServiceSfdnsres, new { cancelHandleRequest });
|
2018-10-10 01:15:07 +02:00
|
|
|
|
2021-03-24 18:43:23 +01:00
|
|
|
return ResultCode.Success;
|
2018-10-10 01:15:07 +02:00
|
|
|
}
|
|
|
|
|
2023-04-15 01:00:34 +02:00
|
|
|
[CommandCmif(10)] // 5.0.0+
|
2021-03-24 18:43:23 +01:00
|
|
|
// GetHostByNameRequestWithOptions(u8, u32, u64, pid, buffer<unknown, 21, 0>, buffer<unknown, 21, 0>) -> (u32, u32, u32, buffer<unknown, 22, 0>)
|
|
|
|
public ResultCode GetHostByNameRequestWithOptions(ServiceCtx context)
|
2018-10-10 01:15:07 +02:00
|
|
|
{
|
2021-04-24 12:16:01 +02:00
|
|
|
(ulong inputBufferPosition, ulong inputBufferSize) = context.Request.GetBufferType0x21();
|
|
|
|
(ulong outputBufferPosition, ulong outputBufferSize) = context.Request.GetBufferType0x22();
|
|
|
|
(ulong optionsBufferPosition, ulong optionsBufferSize) = context.Request.GetBufferType0x21();
|
2018-10-10 01:15:07 +02:00
|
|
|
|
2021-12-28 12:22:58 +01:00
|
|
|
return GetHostByNameRequestImpl(
|
|
|
|
context,
|
|
|
|
inputBufferPosition,
|
|
|
|
inputBufferSize,
|
|
|
|
outputBufferPosition,
|
|
|
|
outputBufferSize,
|
|
|
|
true,
|
|
|
|
optionsBufferPosition,
|
|
|
|
optionsBufferSize);
|
2021-03-24 18:43:23 +01:00
|
|
|
}
|
2018-10-10 01:15:07 +02:00
|
|
|
|
2023-04-15 01:00:34 +02:00
|
|
|
[CommandCmif(11)] // 5.0.0+
|
2021-03-24 18:43:23 +01:00
|
|
|
// GetHostByAddrRequestWithOptions(u32, u32, u32, u64, pid, buffer<unknown, 21, 0>, buffer<unknown, 21, 0>) -> (u32, u32, u32, buffer<unknown, 22, 0>)
|
|
|
|
public ResultCode GetHostByAddrRequestWithOptions(ServiceCtx context)
|
|
|
|
{
|
2021-04-24 12:16:01 +02:00
|
|
|
(ulong inputBufferPosition, ulong inputBufferSize) = context.Request.GetBufferType0x21();
|
|
|
|
(ulong outputBufferPosition, ulong outputBufferSize) = context.Request.GetBufferType0x22();
|
|
|
|
(ulong optionsBufferPosition, ulong optionsBufferSize) = context.Request.GetBufferType0x21();
|
2021-03-24 18:43:23 +01:00
|
|
|
|
2021-12-28 12:22:58 +01:00
|
|
|
return GetHostByAddrRequestImpl(
|
|
|
|
context,
|
|
|
|
inputBufferPosition,
|
|
|
|
inputBufferSize,
|
|
|
|
outputBufferPosition,
|
|
|
|
outputBufferSize,
|
|
|
|
true,
|
|
|
|
optionsBufferPosition,
|
|
|
|
optionsBufferSize);
|
2018-10-10 01:15:07 +02:00
|
|
|
}
|
|
|
|
|
2023-04-15 01:00:34 +02:00
|
|
|
[CommandCmif(12)] // 5.0.0+
|
2021-03-24 18:43:23 +01:00
|
|
|
// GetAddrInfoRequestWithOptions(bool enable_nsd_resolve, u32, u64 pid_placeholder, pid, buffer<i8, 5, 0> host, buffer<i8, 5, 0> service, buffer<packed_addrinfo, 5, 0> hints, buffer<unknown, 21, 0>) -> (i32 ret, u32 bsd_errno, u32 unknown, u32 packed_addrinfo_size, buffer<packed_addrinfo, 22, 0> response)
|
|
|
|
public ResultCode GetAddrInfoRequestWithOptions(ServiceCtx context)
|
|
|
|
{
|
2021-12-28 12:22:58 +01:00
|
|
|
(ulong outputBufferPosition, ulong outputBufferSize) = context.Request.GetBufferType0x22();
|
|
|
|
(ulong optionsBufferPosition, ulong optionsBufferSize) = context.Request.GetBufferType0x21();
|
2021-03-24 18:43:23 +01:00
|
|
|
|
2021-12-28 12:22:58 +01:00
|
|
|
return GetAddrInfoRequestImpl(context, outputBufferPosition, outputBufferSize, true, optionsBufferPosition, optionsBufferSize);
|
2021-03-24 18:43:23 +01:00
|
|
|
}
|
|
|
|
|
2023-04-15 01:00:34 +02:00
|
|
|
[CommandCmif(14)] // 5.0.0+
|
2022-08-03 00:10:28 +02:00
|
|
|
// ResolverSetOptionRequest(buffer<unknown, 5, 0>, u64 unknown, u64 pid_placeholder, pid) -> (i32 ret, u32 bsd_errno)
|
|
|
|
public ResultCode ResolverSetOptionRequest(ServiceCtx context)
|
|
|
|
{
|
|
|
|
ulong bufferPosition = context.Request.SendBuff[0].Position;
|
|
|
|
ulong bufferSize = context.Request.SendBuff[0].Size;
|
|
|
|
|
|
|
|
ulong unknown = context.RequestData.ReadUInt64();
|
|
|
|
|
|
|
|
byte[] buffer = new byte[bufferSize];
|
|
|
|
|
|
|
|
context.Memory.Read(bufferPosition, buffer);
|
|
|
|
|
|
|
|
// TODO: Parse and use options.
|
|
|
|
|
|
|
|
Logger.Stub?.PrintStub(LogClass.ServiceSfdnsres, new { unknown });
|
|
|
|
|
|
|
|
NetDbError netDbErrorCode = NetDbError.Success;
|
|
|
|
GaiError errno = GaiError.Success;
|
|
|
|
|
|
|
|
context.ResponseData.Write((int)errno);
|
|
|
|
context.ResponseData.Write((int)netDbErrorCode);
|
|
|
|
|
|
|
|
return ResultCode.Success;
|
|
|
|
}
|
|
|
|
|
2022-12-12 18:04:08 +01:00
|
|
|
// Atmosphère extension for dns_mitm
|
2023-04-15 01:00:34 +02:00
|
|
|
[CommandCmif(65000)]
|
2022-12-12 18:04:08 +01:00
|
|
|
// AtmosphereReloadHostsFile()
|
|
|
|
public ResultCode AtmosphereReloadHostsFile(ServiceCtx context)
|
|
|
|
{
|
|
|
|
DnsMitmResolver.Instance.ReloadEntries(context);
|
|
|
|
|
|
|
|
return ResultCode.Success;
|
|
|
|
}
|
|
|
|
|
2021-12-28 12:22:58 +01:00
|
|
|
private static ResultCode GetHostByNameRequestImpl(
|
|
|
|
ServiceCtx context,
|
|
|
|
ulong inputBufferPosition,
|
|
|
|
ulong inputBufferSize,
|
|
|
|
ulong outputBufferPosition,
|
|
|
|
ulong outputBufferSize,
|
|
|
|
bool withOptions,
|
|
|
|
ulong optionsBufferPosition,
|
|
|
|
ulong optionsBufferSize)
|
2018-10-10 01:15:07 +02:00
|
|
|
{
|
2022-01-03 22:12:50 +01:00
|
|
|
string host = MemoryHelper.ReadAsciiString(context.Memory, inputBufferPosition, (int)inputBufferSize);
|
2018-10-10 01:15:07 +02:00
|
|
|
|
2022-01-09 00:18:09 +01:00
|
|
|
if (!context.Device.Configuration.EnableInternetAccess)
|
|
|
|
{
|
|
|
|
Logger.Info?.Print(LogClass.ServiceSfdnsres, $"Guest network access disabled, DNS Blocked: {host}");
|
|
|
|
|
|
|
|
WriteResponse(context, withOptions, 0, GaiError.NoData, NetDbError.HostNotFound);
|
|
|
|
|
|
|
|
return ResultCode.Success;
|
|
|
|
}
|
|
|
|
|
2021-03-24 18:43:23 +01:00
|
|
|
// TODO: Use params.
|
|
|
|
bool enableNsdResolve = (context.RequestData.ReadInt32() & 1) != 0;
|
2018-12-06 12:16:24 +01:00
|
|
|
int timeOut = context.RequestData.ReadInt32();
|
|
|
|
ulong pidPlaceholder = context.RequestData.ReadUInt64();
|
2018-10-10 01:15:07 +02:00
|
|
|
|
2021-12-28 12:22:58 +01:00
|
|
|
if (withOptions)
|
2021-03-24 18:43:23 +01:00
|
|
|
{
|
|
|
|
// TODO: Parse and use options.
|
|
|
|
}
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
IPHostEntry hostEntry = null;
|
2018-10-10 01:15:07 +02:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
NetDbError netDbErrorCode = NetDbError.Success;
|
|
|
|
GaiError errno = GaiError.Overflow;
|
2022-01-12 17:43:00 +01:00
|
|
|
int serializedSize = 0;
|
2018-10-10 01:15:07 +02:00
|
|
|
|
2022-01-03 22:12:50 +01:00
|
|
|
if (host.Length <= byte.MaxValue)
|
2018-10-10 01:15:07 +02:00
|
|
|
{
|
2022-01-03 22:12:50 +01:00
|
|
|
if (enableNsdResolve)
|
|
|
|
{
|
|
|
|
if (FqdnResolver.Resolve(host, out string newAddress) == Nsd.ResultCode.Success)
|
|
|
|
{
|
|
|
|
host = newAddress;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
string targetHost = host;
|
2021-03-24 18:43:23 +01:00
|
|
|
|
2022-01-03 22:12:50 +01:00
|
|
|
if (DnsBlacklist.IsHostBlocked(host))
|
2018-10-10 01:15:07 +02:00
|
|
|
{
|
2022-01-03 22:12:50 +01:00
|
|
|
Logger.Info?.Print(LogClass.ServiceSfdnsres, $"DNS Blocked: {host}");
|
2021-03-24 18:43:23 +01:00
|
|
|
|
|
|
|
netDbErrorCode = NetDbError.HostNotFound;
|
|
|
|
errno = GaiError.NoData;
|
2018-10-10 01:15:07 +02:00
|
|
|
}
|
2021-03-24 18:43:23 +01:00
|
|
|
else
|
2018-10-10 01:15:07 +02:00
|
|
|
{
|
2022-01-03 22:12:50 +01:00
|
|
|
Logger.Info?.Print(LogClass.ServiceSfdnsres, $"Trying to resolve: {host}");
|
2018-10-10 01:15:07 +02:00
|
|
|
|
2021-03-24 18:43:23 +01:00
|
|
|
try
|
2018-10-10 01:15:07 +02:00
|
|
|
{
|
2022-12-12 18:04:08 +01:00
|
|
|
hostEntry = DnsMitmResolver.Instance.ResolveAddress(targetHost);
|
2018-10-10 01:15:07 +02:00
|
|
|
}
|
2021-03-24 18:43:23 +01:00
|
|
|
catch (SocketException exception)
|
2018-10-10 01:15:07 +02:00
|
|
|
{
|
2021-03-24 18:43:23 +01:00
|
|
|
netDbErrorCode = ConvertSocketErrorCodeToNetDbError(exception.ErrorCode);
|
|
|
|
errno = ConvertSocketErrorCodeToGaiError(exception.ErrorCode, errno);
|
2018-10-10 01:15:07 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
netDbErrorCode = NetDbError.HostNotFound;
|
2018-10-10 01:15:07 +02:00
|
|
|
}
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
if (hostEntry != null)
|
2018-10-10 01:15:07 +02:00
|
|
|
{
|
2021-03-24 18:43:23 +01:00
|
|
|
IEnumerable<IPAddress> addresses = GetIpv4Addresses(hostEntry);
|
2018-10-10 01:15:07 +02:00
|
|
|
|
2021-03-24 18:43:23 +01:00
|
|
|
if (!addresses.Any())
|
2018-10-10 01:15:07 +02:00
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
errno = GaiError.NoData;
|
|
|
|
netDbErrorCode = NetDbError.NoAddress;
|
2018-10-10 01:15:07 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-03-24 18:43:23 +01:00
|
|
|
errno = GaiError.Success;
|
|
|
|
serializedSize = SerializeHostEntries(context, outputBufferPosition, outputBufferSize, hostEntry, addresses);
|
2018-10-10 01:15:07 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-28 12:22:58 +01:00
|
|
|
WriteResponse(context, withOptions, serializedSize, errno, netDbErrorCode);
|
2018-10-10 01:15:07 +02:00
|
|
|
|
2019-07-14 21:04:38 +02:00
|
|
|
return ResultCode.Success;
|
2018-10-10 01:15:07 +02:00
|
|
|
}
|
|
|
|
|
2021-12-28 12:22:58 +01:00
|
|
|
private static ResultCode GetHostByAddrRequestImpl(
|
|
|
|
ServiceCtx context,
|
|
|
|
ulong inputBufferPosition,
|
|
|
|
ulong inputBufferSize,
|
|
|
|
ulong outputBufferPosition,
|
|
|
|
ulong outputBufferSize,
|
|
|
|
bool withOptions,
|
|
|
|
ulong optionsBufferPosition,
|
|
|
|
ulong optionsBufferSize)
|
2018-10-10 01:15:07 +02:00
|
|
|
{
|
2022-01-09 00:18:09 +01:00
|
|
|
if (!context.Device.Configuration.EnableInternetAccess)
|
|
|
|
{
|
|
|
|
Logger.Info?.Print(LogClass.ServiceSfdnsres, $"Guest network access disabled, DNS Blocked.");
|
|
|
|
|
|
|
|
WriteResponse(context, withOptions, 0, GaiError.NoData, NetDbError.HostNotFound);
|
|
|
|
|
|
|
|
return ResultCode.Success;
|
|
|
|
}
|
|
|
|
|
2021-03-24 18:43:23 +01:00
|
|
|
byte[] rawIp = new byte[inputBufferSize];
|
2020-05-04 00:54:50 +02:00
|
|
|
|
2021-04-24 12:16:01 +02:00
|
|
|
context.Memory.Read(inputBufferPosition, rawIp);
|
2018-10-10 01:15:07 +02:00
|
|
|
|
2021-03-24 18:43:23 +01:00
|
|
|
// TODO: Use params.
|
2018-12-06 12:16:24 +01:00
|
|
|
uint socketLength = context.RequestData.ReadUInt32();
|
|
|
|
uint type = context.RequestData.ReadUInt32();
|
|
|
|
int timeOut = context.RequestData.ReadInt32();
|
|
|
|
ulong pidPlaceholder = context.RequestData.ReadUInt64();
|
2018-10-10 01:15:07 +02:00
|
|
|
|
2021-12-28 12:22:58 +01:00
|
|
|
if (withOptions)
|
2021-03-24 18:43:23 +01:00
|
|
|
{
|
|
|
|
// TODO: Parse and use options.
|
|
|
|
}
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
IPHostEntry hostEntry = null;
|
2018-10-10 01:15:07 +02:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
NetDbError netDbErrorCode = NetDbError.Success;
|
|
|
|
GaiError errno = GaiError.AddressFamily;
|
2022-01-12 17:43:00 +01:00
|
|
|
int serializedSize = 0;
|
2018-10-10 01:15:07 +02:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
if (rawIp.Length == 4)
|
2018-10-10 01:15:07 +02:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
IPAddress address = new IPAddress(rawIp);
|
2018-10-10 01:15:07 +02:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
hostEntry = Dns.GetHostEntry(address);
|
2018-10-10 01:15:07 +02:00
|
|
|
}
|
2018-12-06 12:16:24 +01:00
|
|
|
catch (SocketException exception)
|
2018-10-10 01:15:07 +02:00
|
|
|
{
|
2021-03-24 18:43:23 +01:00
|
|
|
netDbErrorCode = ConvertSocketErrorCodeToNetDbError(exception.ErrorCode);
|
|
|
|
errno = ConvertSocketErrorCodeToGaiError(exception.ErrorCode, errno);
|
2018-10-10 01:15:07 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
netDbErrorCode = NetDbError.NoAddress;
|
2018-10-10 01:15:07 +02:00
|
|
|
}
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
if (hostEntry != null)
|
2018-10-10 01:15:07 +02:00
|
|
|
{
|
2021-03-24 18:43:23 +01:00
|
|
|
errno = GaiError.Success;
|
|
|
|
serializedSize = SerializeHostEntries(context, outputBufferPosition, outputBufferSize, hostEntry, GetIpv4Addresses(hostEntry));
|
2018-10-10 01:15:07 +02:00
|
|
|
}
|
|
|
|
|
2021-12-28 12:22:58 +01:00
|
|
|
WriteResponse(context, withOptions, serializedSize, errno, netDbErrorCode);
|
2018-10-10 01:15:07 +02:00
|
|
|
|
2019-07-14 21:04:38 +02:00
|
|
|
return ResultCode.Success;
|
2018-10-10 01:15:07 +02:00
|
|
|
}
|
|
|
|
|
2022-01-12 17:43:00 +01:00
|
|
|
private static int SerializeHostEntries(ServiceCtx context, ulong outputBufferPosition, ulong outputBufferSize, IPHostEntry hostEntry, IEnumerable<IPAddress> addresses = null)
|
2018-10-10 01:15:07 +02:00
|
|
|
{
|
2021-04-24 12:16:01 +02:00
|
|
|
ulong originalBufferPosition = outputBufferPosition;
|
|
|
|
ulong bufferPosition = originalBufferPosition;
|
2018-10-10 01:15:07 +02:00
|
|
|
|
2021-03-24 18:43:23 +01:00
|
|
|
string hostName = hostEntry.HostName + '\0';
|
|
|
|
|
|
|
|
// h_name
|
2021-04-24 12:16:01 +02:00
|
|
|
context.Memory.Write(bufferPosition, Encoding.ASCII.GetBytes(hostName));
|
|
|
|
bufferPosition += (ulong)hostName.Length;
|
2021-03-24 18:43:23 +01:00
|
|
|
|
|
|
|
// h_aliases list size
|
2021-04-24 12:16:01 +02:00
|
|
|
context.Memory.Write(bufferPosition, BinaryPrimitives.ReverseEndianness(hostEntry.Aliases.Length));
|
|
|
|
bufferPosition += sizeof(int);
|
2021-03-24 18:43:23 +01:00
|
|
|
|
|
|
|
// Actual aliases
|
|
|
|
foreach (string alias in hostEntry.Aliases)
|
2018-10-10 01:15:07 +02:00
|
|
|
{
|
2021-04-24 12:16:01 +02:00
|
|
|
context.Memory.Write(bufferPosition, Encoding.ASCII.GetBytes(alias + '\0'));
|
|
|
|
bufferPosition += (ulong)(alias.Length + 1);
|
2018-10-10 01:15:07 +02:00
|
|
|
}
|
|
|
|
|
2021-03-24 18:43:23 +01:00
|
|
|
// h_addrtype but it's a short (also only support IPv4)
|
2021-04-24 12:16:01 +02:00
|
|
|
context.Memory.Write(bufferPosition, BinaryPrimitives.ReverseEndianness((short)AddressFamily.InterNetwork));
|
|
|
|
bufferPosition += sizeof(short);
|
2021-03-24 18:43:23 +01:00
|
|
|
|
|
|
|
// h_length but it's a short
|
2021-04-24 12:16:01 +02:00
|
|
|
context.Memory.Write(bufferPosition, BinaryPrimitives.ReverseEndianness((short)4));
|
|
|
|
bufferPosition += sizeof(short);
|
2021-03-24 18:43:23 +01:00
|
|
|
|
|
|
|
// Ip address count, we can only support ipv4 (blame Nintendo)
|
2021-04-24 12:16:01 +02:00
|
|
|
context.Memory.Write(bufferPosition, addresses != null ? BinaryPrimitives.ReverseEndianness(addresses.Count()) : 0);
|
|
|
|
bufferPosition += sizeof(int);
|
2021-03-24 18:43:23 +01:00
|
|
|
|
|
|
|
if (addresses != null)
|
|
|
|
{
|
|
|
|
foreach (IPAddress ip in addresses)
|
|
|
|
{
|
2021-04-24 12:16:01 +02:00
|
|
|
context.Memory.Write(bufferPosition, BinaryPrimitives.ReverseEndianness(BitConverter.ToInt32(ip.GetAddressBytes(), 0)));
|
|
|
|
bufferPosition += sizeof(int);
|
2021-03-24 18:43:23 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-12 17:43:00 +01:00
|
|
|
return (int)(bufferPosition - originalBufferPosition);
|
2018-10-10 01:15:07 +02:00
|
|
|
}
|
|
|
|
|
2021-12-28 12:22:58 +01:00
|
|
|
private static ResultCode GetAddrInfoRequestImpl(
|
2021-12-26 15:17:13 +01:00
|
|
|
ServiceCtx context,
|
|
|
|
ulong responseBufferPosition,
|
|
|
|
ulong responseBufferSize,
|
|
|
|
bool withOptions,
|
|
|
|
ulong optionsBufferPosition,
|
|
|
|
ulong optionsBufferSize)
|
2018-10-10 01:15:07 +02:00
|
|
|
{
|
2021-03-24 18:43:23 +01:00
|
|
|
bool enableNsdResolve = (context.RequestData.ReadInt32() & 1) != 0;
|
|
|
|
uint cancelHandle = context.RequestData.ReadUInt32();
|
|
|
|
|
2021-04-24 12:16:01 +02:00
|
|
|
string host = MemoryHelper.ReadAsciiString(context.Memory, context.Request.SendBuff[0].Position, (long)context.Request.SendBuff[0].Size);
|
|
|
|
string service = MemoryHelper.ReadAsciiString(context.Memory, context.Request.SendBuff[1].Position, (long)context.Request.SendBuff[1].Size);
|
2021-03-24 18:43:23 +01:00
|
|
|
|
2022-01-09 00:18:09 +01:00
|
|
|
if (!context.Device.Configuration.EnableInternetAccess)
|
|
|
|
{
|
|
|
|
Logger.Info?.Print(LogClass.ServiceSfdnsres, $"Guest network access disabled, DNS Blocked: {host}");
|
|
|
|
|
|
|
|
WriteResponse(context, withOptions, 0, GaiError.NoData, NetDbError.HostNotFound);
|
|
|
|
|
|
|
|
return ResultCode.Success;
|
|
|
|
}
|
|
|
|
|
2021-03-24 18:43:23 +01:00
|
|
|
// NOTE: We ignore hints for now.
|
2022-01-12 17:43:00 +01:00
|
|
|
List<AddrInfoSerialized> hints = DeserializeAddrInfos(context.Memory, context.Request.SendBuff[2].Position, context.Request.SendBuff[2].Size);
|
2018-10-10 01:15:07 +02:00
|
|
|
|
2021-12-26 15:17:13 +01:00
|
|
|
if (withOptions)
|
2018-10-10 01:15:07 +02:00
|
|
|
{
|
2021-03-24 18:43:23 +01:00
|
|
|
// TODO: Find unknown, Parse and use options.
|
|
|
|
uint unknown = context.RequestData.ReadUInt32();
|
2018-10-10 01:15:07 +02:00
|
|
|
}
|
|
|
|
|
2021-03-24 18:43:23 +01:00
|
|
|
ulong pidPlaceHolder = context.RequestData.ReadUInt64();
|
|
|
|
|
|
|
|
IPHostEntry hostEntry = null;
|
|
|
|
|
|
|
|
NetDbError netDbErrorCode = NetDbError.Success;
|
|
|
|
GaiError errno = GaiError.AddressFamily;
|
2022-01-12 17:43:00 +01:00
|
|
|
int serializedSize = 0;
|
2021-03-24 18:43:23 +01:00
|
|
|
|
|
|
|
if (host.Length <= byte.MaxValue)
|
|
|
|
{
|
2022-01-03 22:12:50 +01:00
|
|
|
if (enableNsdResolve)
|
|
|
|
{
|
|
|
|
if (FqdnResolver.Resolve(host, out string newAddress) == Nsd.ResultCode.Success)
|
|
|
|
{
|
|
|
|
host = newAddress;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-24 18:43:23 +01:00
|
|
|
string targetHost = host;
|
|
|
|
|
|
|
|
if (DnsBlacklist.IsHostBlocked(host))
|
|
|
|
{
|
|
|
|
Logger.Info?.Print(LogClass.ServiceSfdnsres, $"DNS Blocked: {host}");
|
|
|
|
|
|
|
|
netDbErrorCode = NetDbError.HostNotFound;
|
|
|
|
errno = GaiError.NoData;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Logger.Info?.Print(LogClass.ServiceSfdnsres, $"Trying to resolve: {host}");
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
2022-12-12 18:04:08 +01:00
|
|
|
hostEntry = DnsMitmResolver.Instance.ResolveAddress(targetHost);
|
2021-03-24 18:43:23 +01:00
|
|
|
}
|
|
|
|
catch (SocketException exception)
|
|
|
|
{
|
|
|
|
netDbErrorCode = ConvertSocketErrorCodeToNetDbError(exception.ErrorCode);
|
|
|
|
errno = ConvertSocketErrorCodeToGaiError(exception.ErrorCode, errno);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
netDbErrorCode = NetDbError.NoAddress;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (hostEntry != null)
|
|
|
|
{
|
|
|
|
int.TryParse(service, out int port);
|
|
|
|
|
|
|
|
errno = GaiError.Success;
|
|
|
|
serializedSize = SerializeAddrInfos(context, responseBufferPosition, responseBufferSize, hostEntry, port);
|
|
|
|
}
|
|
|
|
|
2021-12-28 12:22:58 +01:00
|
|
|
WriteResponse(context, withOptions, serializedSize, errno, netDbErrorCode);
|
2021-03-24 18:43:23 +01:00
|
|
|
|
|
|
|
return ResultCode.Success;
|
2018-10-10 01:15:07 +02:00
|
|
|
}
|
|
|
|
|
2022-01-12 17:43:00 +01:00
|
|
|
private static List<AddrInfoSerialized> DeserializeAddrInfos(IVirtualMemoryManager memory, ulong address, ulong size)
|
2018-10-10 01:15:07 +02:00
|
|
|
{
|
2022-11-28 02:53:57 +01:00
|
|
|
List<AddrInfoSerialized> result = new();
|
2021-03-24 18:43:23 +01:00
|
|
|
|
2022-01-12 17:43:00 +01:00
|
|
|
ReadOnlySpan<byte> data = memory.GetSpan(address, (int)size);
|
|
|
|
|
|
|
|
while (!data.IsEmpty)
|
2021-03-24 18:43:23 +01:00
|
|
|
{
|
2022-01-12 17:43:00 +01:00
|
|
|
AddrInfoSerialized info = AddrInfoSerialized.Read(data, out data);
|
2018-10-10 01:15:07 +02:00
|
|
|
|
2022-01-12 17:43:00 +01:00
|
|
|
if (info == null)
|
2021-03-24 18:43:23 +01:00
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
2018-10-10 01:15:07 +02:00
|
|
|
|
2022-01-12 17:43:00 +01:00
|
|
|
result.Add(info);
|
2021-03-24 18:43:23 +01:00
|
|
|
}
|
2022-01-12 17:43:00 +01:00
|
|
|
|
|
|
|
return result;
|
2018-10-10 01:15:07 +02:00
|
|
|
}
|
|
|
|
|
2022-01-12 17:43:00 +01:00
|
|
|
private static int SerializeAddrInfos(ServiceCtx context, ulong responseBufferPosition, ulong responseBufferSize, IPHostEntry hostEntry, int port)
|
2018-10-10 01:15:07 +02:00
|
|
|
{
|
2022-01-12 17:43:00 +01:00
|
|
|
ulong originalBufferPosition = responseBufferPosition;
|
2021-03-24 18:43:23 +01:00
|
|
|
ulong bufferPosition = originalBufferPosition;
|
2018-10-10 01:15:07 +02:00
|
|
|
|
2022-01-12 17:43:00 +01:00
|
|
|
byte[] hostName = Encoding.ASCII.GetBytes(hostEntry.HostName + '\0');
|
2018-10-10 01:15:07 +02:00
|
|
|
|
2022-01-12 17:43:00 +01:00
|
|
|
using (WritableRegion region = context.Memory.GetWritableRegion(responseBufferPosition, (int)responseBufferSize))
|
2021-03-24 18:43:23 +01:00
|
|
|
{
|
2022-01-12 17:43:00 +01:00
|
|
|
Span<byte> data = region.Memory.Span;
|
2021-03-24 18:43:23 +01:00
|
|
|
|
2022-01-12 17:43:00 +01:00
|
|
|
for (int i = 0; i < hostEntry.AddressList.Length; i++)
|
2021-03-24 18:43:23 +01:00
|
|
|
{
|
2022-01-12 17:43:00 +01:00
|
|
|
IPAddress ip = hostEntry.AddressList[i];
|
2021-03-24 18:43:23 +01:00
|
|
|
|
2022-01-12 17:43:00 +01:00
|
|
|
if (ip.AddressFamily != AddressFamily.InterNetwork)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
2021-03-24 18:43:23 +01:00
|
|
|
|
2022-01-12 17:43:00 +01:00
|
|
|
// NOTE: 0 = Any
|
2022-11-28 02:53:57 +01:00
|
|
|
AddrInfoSerializedHeader header = new(ip, 0);
|
|
|
|
AddrInfo4 addr = new(ip, (short)port);
|
|
|
|
AddrInfoSerialized info = new(header, addr, null, hostEntry.HostName);
|
2021-03-24 18:43:23 +01:00
|
|
|
|
2022-01-12 17:43:00 +01:00
|
|
|
data = info.Write(data);
|
|
|
|
}
|
2021-03-24 18:43:23 +01:00
|
|
|
|
2022-01-12 17:43:00 +01:00
|
|
|
uint sentinel = 0;
|
|
|
|
MemoryMarshal.Write(data, ref sentinel);
|
|
|
|
data = data[sizeof(uint)..];
|
2021-03-24 18:43:23 +01:00
|
|
|
|
2022-01-12 17:43:00 +01:00
|
|
|
return region.Memory.Span.Length - data.Length;
|
|
|
|
}
|
2018-10-10 01:15:07 +02:00
|
|
|
}
|
|
|
|
|
2021-12-28 12:22:58 +01:00
|
|
|
private static void WriteResponse(
|
|
|
|
ServiceCtx context,
|
|
|
|
bool withOptions,
|
2022-01-12 17:43:00 +01:00
|
|
|
int serializedSize,
|
2021-12-28 12:22:58 +01:00
|
|
|
GaiError errno,
|
|
|
|
NetDbError netDbErrorCode)
|
|
|
|
{
|
|
|
|
if (withOptions)
|
|
|
|
{
|
2022-01-12 17:43:00 +01:00
|
|
|
context.ResponseData.Write(serializedSize);
|
2021-12-28 12:22:58 +01:00
|
|
|
context.ResponseData.Write((int)errno);
|
|
|
|
context.ResponseData.Write((int)netDbErrorCode);
|
|
|
|
context.ResponseData.Write(0);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
context.ResponseData.Write((int)netDbErrorCode);
|
|
|
|
context.ResponseData.Write((int)errno);
|
2022-08-03 00:10:28 +02:00
|
|
|
context.ResponseData.Write(serializedSize);
|
2021-12-28 12:22:58 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private static IEnumerable<IPAddress> GetIpv4Addresses(IPHostEntry hostEntry)
|
2018-10-10 01:15:07 +02:00
|
|
|
{
|
2021-03-24 18:43:23 +01:00
|
|
|
return hostEntry.AddressList.Where(x => x.AddressFamily == AddressFamily.InterNetwork);
|
|
|
|
}
|
2018-10-10 01:15:07 +02:00
|
|
|
|
2021-12-28 12:22:58 +01:00
|
|
|
private static NetDbError ConvertSocketErrorCodeToNetDbError(int errorCode)
|
2021-03-24 18:43:23 +01:00
|
|
|
{
|
|
|
|
return errorCode switch
|
|
|
|
{
|
|
|
|
11001 => NetDbError.HostNotFound,
|
|
|
|
11002 => NetDbError.TryAgain,
|
|
|
|
11003 => NetDbError.NoRecovery,
|
|
|
|
11004 => NetDbError.NoData,
|
|
|
|
_ => NetDbError.Internal
|
|
|
|
};
|
|
|
|
}
|
2018-10-10 01:15:07 +02:00
|
|
|
|
2021-12-28 12:22:58 +01:00
|
|
|
private static GaiError ConvertSocketErrorCodeToGaiError(int errorCode, GaiError errno)
|
2021-03-24 18:43:23 +01:00
|
|
|
{
|
|
|
|
return errorCode switch
|
|
|
|
{
|
|
|
|
11001 => GaiError.NoData,
|
|
|
|
10060 => GaiError.Again,
|
|
|
|
_ => errno
|
|
|
|
};
|
2018-10-10 01:15:07 +02:00
|
|
|
}
|
2018-02-28 21:58:04 +01:00
|
|
|
}
|
2019-07-12 03:13:43 +02:00
|
|
|
}
|