Ryujinx/Ryujinx.HLE/HOS/Services/Nifm/IGeneralService.cs

59 lines
1.6 KiB
C#
Raw Normal View History

using Ryujinx.Common.Logging;
using Ryujinx.HLE.HOS.Ipc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.NetworkInformation;
using System.Net.Sockets;
using static Ryujinx.HLE.HOS.ErrorCode;
namespace Ryujinx.HLE.HOS.Services.Nifm
{
class IGeneralService : IpcService
{
2018-12-01 21:01:59 +01:00
private Dictionary<int, ServiceProcessRequest> _commands;
2018-12-01 21:01:59 +01:00
public override IReadOnlyDictionary<int, ServiceProcessRequest> Commands => _commands;
public IGeneralService()
{
2018-12-01 21:01:59 +01:00
_commands = new Dictionary<int, ServiceProcessRequest>()
{
{ 4, CreateRequest },
{ 12, GetCurrentIpAddress }
};
}
2018-12-01 21:01:59 +01:00
public long CreateRequest(ServiceCtx context)
{
2018-12-01 21:01:59 +01:00
int unknown = context.RequestData.ReadInt32();
2018-12-01 21:01:59 +01:00
MakeObject(context, new IRequest(context.Device.System));
Logger.PrintStub(LogClass.ServiceNifm, "Stubbed.");
return 0;
}
2018-12-01 21:01:59 +01:00
public long GetCurrentIpAddress(ServiceCtx context)
{
if (!NetworkInterface.GetIsNetworkAvailable())
{
return MakeError(ErrorModule.Nifm, NifmErr.NoInternetConnection);
}
2018-12-01 21:01:59 +01:00
IPHostEntry host = Dns.GetHostEntry(Dns.GetHostName());
2018-12-01 21:01:59 +01:00
IPAddress address = host.AddressList.FirstOrDefault(a => a.AddressFamily == AddressFamily.InterNetwork);
2018-12-01 21:01:59 +01:00
context.ResponseData.Write(BitConverter.ToUInt32(address.GetAddressBytes()));
2018-12-01 21:01:59 +01:00
Logger.PrintInfo(LogClass.ServiceNifm, $"Console's local IP is \"{address}\".");
return 0;
}
}
}