Address.cs 995 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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 &&
  12. this.address.port == enetAddr.port;
  13. }
  14. public string IP
  15. {
  16. get
  17. {
  18. var hostIP = new StringBuilder(256);
  19. Native.enet_address_get_host_ip(ref this.address, hostIP, (uint)hostIP.Length);
  20. return hostIP.ToString();
  21. }
  22. }
  23. public string Host
  24. {
  25. get
  26. {
  27. var hostName = new StringBuilder(256);
  28. Native.enet_address_get_host(ref this.address, hostName, (uint)hostName.Length);
  29. return hostName.ToString();
  30. }
  31. set
  32. {
  33. Native.enet_address_set_host(ref this.address, value);
  34. }
  35. }
  36. public ENetAddress Struct
  37. {
  38. get
  39. {
  40. return this.address;
  41. }
  42. }
  43. public ushort Port
  44. {
  45. get
  46. {
  47. return this.address.port;
  48. }
  49. set
  50. {
  51. this.address.port = value;
  52. }
  53. }
  54. }
  55. }