nataddr.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. /*
  2. ** Command & Conquer Renegade(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /***********************************************************************************************
  19. *** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S ***
  20. ***********************************************************************************************
  21. * *
  22. * Project Name : Command & Conquer *
  23. * *
  24. * $Archive:: /Commando/Code/Commando/nataddr.h $*
  25. * *
  26. * $Author:: Steve_t $*
  27. * *
  28. * $Modtime:: 9/17/01 4:09p $*
  29. * *
  30. * $Revision:: 2 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #pragma once
  36. #ifndef NATADDR_H
  37. #define NATADDR_H
  38. #include "always.h"
  39. #ifdef WWASSERT
  40. #ifndef fw_assert
  41. #define fw_assert WWASSERT
  42. #endif //fw_assert
  43. #else //WWASSERT
  44. #define fw_assert assert
  45. #endif //WWASSERT
  46. /*
  47. ** Class to manage IP addresses for the NAT stuff only.
  48. */
  49. class IPAddressClass
  50. {
  51. /*
  52. ** Public Interface
  53. */
  54. public:
  55. /*
  56. ** Constructors:
  57. */
  58. IPAddressClass(void);
  59. IPAddressClass(unsigned char *address, unsigned short port = 0);
  60. IPAddressClass(unsigned long address, unsigned short port = 0);
  61. /*
  62. ** Set the address from explicit variables.
  63. */
  64. void Set_Address(unsigned char *address, unsigned short port = 0);
  65. void Set_Address(unsigned long address, unsigned short port = 0);
  66. void Set_Port(unsigned short port) {Port = port;};
  67. /*
  68. ** Get the address values explicitly.
  69. */
  70. void Get_Address(unsigned char *address, unsigned short *port = 0);
  71. unsigned long Get_Address(void);
  72. unsigned short Get_Port(void);
  73. /*
  74. ** Tells if this address is a broadcast address
  75. */
  76. bool Is_Broadcast(void);
  77. /*
  78. ** Is this address valid?
  79. */
  80. bool Is_Valid(void) {return(IsValid);};
  81. /*
  82. ** Convert address to human readable string
  83. */
  84. char *As_String(void);
  85. /*
  86. ** Compare IPs only, not ports.
  87. */
  88. bool Is_IP_Equal(IPAddressClass &address);
  89. /*
  90. ** Overloaded operators:
  91. */
  92. bool operator = (const IPAddressClass &address);
  93. bool operator == (IPAddressClass &address);
  94. bool operator != (IPAddressClass &address);
  95. bool operator == (IPAddressClass address);
  96. bool operator != (IPAddressClass address);
  97. /*
  98. ** Private Interface
  99. */
  100. private:
  101. /*
  102. ** Actual xxx.xxx.xxx.xxx IP address.
  103. */
  104. union {
  105. unsigned long WholeAddress;
  106. unsigned char Address[4];
  107. };
  108. /*
  109. ** Port number associated with this address.
  110. */
  111. unsigned short Port;
  112. /*
  113. ** Are the contents of the address array valid?
  114. */
  115. bool IsValid;
  116. };
  117. #endif