Address.cs 847 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. using System;
  2. using System.Net;
  3. namespace ENet
  4. {
  5. public struct Address
  6. {
  7. private uint ip;
  8. private ushort port;
  9. public uint Ip
  10. {
  11. get
  12. {
  13. return this.ip;
  14. }
  15. set
  16. {
  17. this.ip = value;
  18. }
  19. }
  20. public ushort Port
  21. {
  22. get
  23. {
  24. return this.port;
  25. }
  26. set
  27. {
  28. this.port = value;
  29. }
  30. }
  31. public string HostName
  32. {
  33. get
  34. {
  35. var hostInfo = Dns.GetHostEntry(new IPAddress(this.ip));
  36. return hostInfo.HostName;
  37. }
  38. set
  39. {
  40. var nameToIpAddress = Dns.GetHostEntry(value);
  41. foreach (IPAddress address in nameToIpAddress.AddressList)
  42. {
  43. this.ip = BitConverter.ToUInt32(address.GetAddressBytes(), 0);
  44. return;
  45. }
  46. }
  47. }
  48. public ENetAddress Struct
  49. {
  50. get
  51. {
  52. var address = new ENetAddress { host = this.ip, port = this.port };
  53. return address;
  54. }
  55. }
  56. }
  57. }