IGeneralService.cs 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. using Ryujinx.Common.Logging;
  2. using Ryujinx.HLE.HOS.Ipc;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Net;
  7. using System.Net.NetworkInformation;
  8. using System.Net.Sockets;
  9. using static Ryujinx.HLE.HOS.ErrorCode;
  10. namespace Ryujinx.HLE.HOS.Services.Nifm
  11. {
  12. class IGeneralService : IpcService
  13. {
  14. private Dictionary<int, ServiceProcessRequest> _commands;
  15. public override IReadOnlyDictionary<int, ServiceProcessRequest> Commands => _commands;
  16. public IGeneralService()
  17. {
  18. _commands = new Dictionary<int, ServiceProcessRequest>
  19. {
  20. { 4, CreateRequest },
  21. { 12, GetCurrentIpAddress }
  22. };
  23. }
  24. public long CreateRequest(ServiceCtx context)
  25. {
  26. int unknown = context.RequestData.ReadInt32();
  27. MakeObject(context, new IRequest(context.Device.System));
  28. Logger.PrintStub(LogClass.ServiceNifm);
  29. return 0;
  30. }
  31. public long GetCurrentIpAddress(ServiceCtx context)
  32. {
  33. if (!NetworkInterface.GetIsNetworkAvailable())
  34. {
  35. return MakeError(ErrorModule.Nifm, NifmErr.NoInternetConnection);
  36. }
  37. IPHostEntry host = Dns.GetHostEntry(Dns.GetHostName());
  38. IPAddress address = host.AddressList.FirstOrDefault(a => a.AddressFamily == AddressFamily.InterNetwork);
  39. context.ResponseData.Write(BitConverter.ToUInt32(address.GetAddressBytes()));
  40. Logger.PrintInfo(LogClass.ServiceNifm, $"Console's local IP is \"{address}\".");
  41. return 0;
  42. }
  43. }
  44. }