Address.cs 992 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. using System;
  2. using System.Text;
  3. namespace ENet
  4. {
  5. public struct Address: IEquatable<Address>
  6. {
  7. private ENetAddress address;
  8. public bool Equals(Address addr)
  9. {
  10. ENetAddress enetAddr = addr.Struct;
  11. return this.address.host == enetAddr.host && this.address.port == enetAddr.port;
  12. }
  13. public string IP
  14. {
  15. get
  16. {
  17. var hostIP = new StringBuilder(256);
  18. Native.enet_address_get_host_ip(ref this.address, hostIP, (uint) hostIP.Length);
  19. return hostIP.ToString();
  20. }
  21. }
  22. public string Host
  23. {
  24. get
  25. {
  26. var hostName = new StringBuilder(256);
  27. Native.enet_address_get_host(ref this.address, hostName, (uint) hostName.Length);
  28. return hostName.ToString();
  29. }
  30. set
  31. {
  32. Native.enet_address_set_host(ref this.address, value);
  33. }
  34. }
  35. public ENetAddress Struct
  36. {
  37. get
  38. {
  39. return this.address;
  40. }
  41. }
  42. public ushort Port
  43. {
  44. get
  45. {
  46. return this.address.port;
  47. }
  48. set
  49. {
  50. this.address.port = value;
  51. }
  52. }
  53. }
  54. }