IGeneralService.cs 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. using Ryujinx.Common.Logging;
  2. using System;
  3. using System.Linq;
  4. using System.Net;
  5. using System.Net.NetworkInformation;
  6. using System.Net.Sockets;
  7. namespace Ryujinx.HLE.HOS.Services.Nifm
  8. {
  9. class IGeneralService : IpcService
  10. {
  11. public IGeneralService() { }
  12. [Command(4)]
  13. // CreateRequest(u32) -> object<nn::nifm::detail::IRequest>
  14. public ResultCode CreateRequest(ServiceCtx context)
  15. {
  16. int unknown = context.RequestData.ReadInt32();
  17. MakeObject(context, new IRequest(context.Device.System));
  18. Logger.PrintStub(LogClass.ServiceNifm);
  19. return ResultCode.Success;
  20. }
  21. [Command(12)]
  22. // GetCurrentIpAddress() -> nn::nifm::IpV4Address
  23. public ResultCode GetCurrentIpAddress(ServiceCtx context)
  24. {
  25. if (!NetworkInterface.GetIsNetworkAvailable())
  26. {
  27. return ResultCode.NoInternetConnection;
  28. }
  29. IPHostEntry host = Dns.GetHostEntry(Dns.GetHostName());
  30. IPAddress address = host.AddressList.FirstOrDefault(a => a.AddressFamily == AddressFamily.InterNetwork);
  31. context.ResponseData.Write(BitConverter.ToUInt32(address.GetAddressBytes()));
  32. Logger.PrintInfo(LogClass.ServiceNifm, $"Console's local IP is \"{address}\".");
  33. return ResultCode.Success;
  34. }
  35. }
  36. }