IPXADDR.CPP 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494
  1. /*
  2. ** Command & Conquer(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. /* $Header: F:\projects\c&c\vcs\code\ipxaddr.cpv 2.17 16 Oct 1995 16:50:58 JOE_BOSTIC $ */
  19. /***************************************************************************
  20. ** 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 **
  21. ***************************************************************************
  22. * *
  23. * Project Name : Command & Conquer *
  24. * *
  25. * File Name : IPXADDR.CPP *
  26. * *
  27. * Programmer : Bill Randolph *
  28. * *
  29. * Start Date : December 19, 1994 *
  30. * *
  31. * Last Update : December 19, 1994 [BR] *
  32. * *
  33. *-------------------------------------------------------------------------*
  34. * Functions: *
  35. * IPXAddressClass::IPXAddressClass -- class constructor *
  36. * IPXAddressClass::IPXAddressClass -- class constructor form 2 *
  37. * IPXAddressClass::IPXAddressClass -- class constructor form 3 *
  38. * IPXAddressClass::Set_Address -- sets the IPX address values *
  39. * IPXAddressClass::Set_Address -- sets the IPX values from a header *
  40. * IPXAddressClass::Get_Address -- retrieves the IPX address values *
  41. * IPXAddressClass::Get_Address -- copies address into an IPX header *
  42. * IPXAddressClass::Is_Broadcast -- tells if this is a broadcast address *
  43. * IPXAddressClass::operator== -- overloaded comparison operator *
  44. * IPXAddressClass::operator!= -- overloaded comparison operator *
  45. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  46. #include "function.h"
  47. #include "tcpip.h"
  48. /***************************************************************************
  49. * IPXAddressClass::IPXAddressClass -- class constructor *
  50. * *
  51. * This default constructor generates a broadcast address. *
  52. * *
  53. * INPUT: *
  54. * net Network Number for this address *
  55. * node Node Address for this address *
  56. * *
  57. * OUTPUT: *
  58. * none. *
  59. * *
  60. * WARNINGS: *
  61. * none. *
  62. * *
  63. * HISTORY: *
  64. * 12/19/1994 BR : Created. *
  65. *=========================================================================*/
  66. IPXAddressClass::IPXAddressClass(void)
  67. {
  68. NetworkNumber[0] = 0xff;
  69. NetworkNumber[1] = 0xff;
  70. NetworkNumber[2] = 0xff;
  71. NetworkNumber[3] = 0xff;
  72. NodeAddress[0] = 0xff;
  73. NodeAddress[1] = 0xff;
  74. NodeAddress[2] = 0xff;
  75. NodeAddress[3] = 0xff;
  76. NodeAddress[4] = 0xff;
  77. NodeAddress[5] = 0xff;
  78. } /* end of IPXAddressClass */
  79. /***************************************************************************
  80. * IPXAddressClass::IPXAddressClass -- class constructor form 2 *
  81. * *
  82. * INPUT: *
  83. * net Network Number for this address *
  84. * node Node Address for this address *
  85. * *
  86. * OUTPUT: *
  87. * none. *
  88. * *
  89. * WARNINGS: *
  90. * none. *
  91. * *
  92. * HISTORY: *
  93. * 12/19/1994 BR : Created. *
  94. *=========================================================================*/
  95. IPXAddressClass::IPXAddressClass(NetNumType net, NetNodeType node)
  96. {
  97. memcpy(NetworkNumber,net,4);
  98. memcpy(NodeAddress,node,6);
  99. } /* end of IPXAddressClass */
  100. /***************************************************************************
  101. * IPXAddressClass::IPXAddressClass -- class constructor form 3 *
  102. * *
  103. * This form of the constructor takes an IPX header as an argument. It *
  104. * extracts the address from the Source address fields in the header. *
  105. * *
  106. * INPUT: *
  107. * header Header from which to extract the address *
  108. * *
  109. * OUTPUT: *
  110. * none. *
  111. * *
  112. * WARNINGS: *
  113. * none. *
  114. * *
  115. * HISTORY: *
  116. * 12/19/1994 BR : Created. *
  117. *=========================================================================*/
  118. IPXAddressClass::IPXAddressClass(IPXHeaderType *header)
  119. {
  120. memcpy(NetworkNumber,header->SourceNetworkNumber,4);
  121. memcpy(NodeAddress,header->SourceNetworkNode,6);
  122. } /* end of IPXAddressClass */
  123. /***************************************************************************
  124. * IPXAddressClass::Set_Address -- sets the IPX address values *
  125. * *
  126. * INPUT: *
  127. * net Network Number for this address *
  128. * node Node Address for this address *
  129. * *
  130. * OUTPUT: *
  131. * none. *
  132. * *
  133. * WARNINGS: *
  134. * none. *
  135. * *
  136. * HISTORY: *
  137. * 12/19/1994 BR : Created. *
  138. *=========================================================================*/
  139. void IPXAddressClass::Set_Address(NetNumType net, NetNodeType node)
  140. {
  141. memcpy(NetworkNumber,net,4);
  142. memcpy(NodeAddress,node,6);
  143. } /* end of Set_Address */
  144. /***************************************************************************
  145. * IPXAddressClass::Set_Address -- sets the IPX values from a header *
  146. * *
  147. * This routine extracts the source addresses from the given IPX header. *
  148. * *
  149. * INPUT: *
  150. * net Network Number for this address *
  151. * node Node Address for this address *
  152. * *
  153. * OUTPUT: *
  154. * none. *
  155. * *
  156. * WARNINGS: *
  157. * none. *
  158. * *
  159. * HISTORY: *
  160. * 12/19/1994 BR : Created. *
  161. *=========================================================================*/
  162. void IPXAddressClass::Set_Address(IPXHeaderType *header)
  163. {
  164. #ifdef VIRTUAL_SUBNET_SERVER
  165. if (Winsock.Get_Connected()){
  166. memset(NetworkNumber, 1 ,4);
  167. memset(NodeAddress, 0, 6);
  168. unsigned short target_mask = *(unsigned short*)header;
  169. /*
  170. ** If this is a head to head game (no VSS) --
  171. ** If mask is 0 then this packet was broadcast from the other player
  172. ** Otherwise exclusive or with 3 to get other players mask
  173. */
  174. if (!UseVirtualSubnetServer){
  175. if (target_mask == 0){
  176. target_mask = 1 << PlanetWestwoodIsHost;
  177. }
  178. target_mask ^= 3;
  179. }
  180. *(unsigned short*) &NodeAddress[0] = target_mask;
  181. }else{
  182. memcpy(NetworkNumber,header->SourceNetworkNumber,4);
  183. memcpy(NodeAddress,header->SourceNetworkNode,6);
  184. }
  185. #else //VIRTUAL_SUBNET_SERVER
  186. if (header){
  187. memcpy(NetworkNumber,header->SourceNetworkNumber,4);
  188. memcpy(NodeAddress,header->SourceNetworkNode,6);
  189. }else{
  190. /*
  191. ** Address is meaningless when using winsock
  192. */
  193. memset(NetworkNumber, 1 ,4);
  194. memset(NodeAddress, 1, 6);
  195. }
  196. #endif //VIRTUAL_SUBNET_SERVER
  197. } /* end of Set_Address */
  198. /***************************************************************************
  199. * IPXAddressClass::Get_Address -- retrieves the IPX address values *
  200. * *
  201. * INPUT: *
  202. * net Network Number for this address *
  203. * node Node Address for this address *
  204. * *
  205. * OUTPUT: *
  206. * none. *
  207. * *
  208. * WARNINGS: *
  209. * none. *
  210. * *
  211. * HISTORY: *
  212. * 12/19/1994 BR : Created. *
  213. *=========================================================================*/
  214. void IPXAddressClass::Get_Address(NetNumType net, NetNodeType node)
  215. {
  216. memcpy(net,NetworkNumber,4);
  217. memcpy(node,NodeAddress,6);
  218. } /* end of Get_Address */
  219. /***************************************************************************
  220. * IPXAddressClass::Get_Address -- copies address into an IPX header *
  221. * *
  222. * INPUT: *
  223. * net Network Number for this address *
  224. * node Node Address for this address *
  225. * *
  226. * OUTPUT: *
  227. * none. *
  228. * *
  229. * WARNINGS: *
  230. * none. *
  231. * *
  232. * HISTORY: *
  233. * 12/19/1994 BR : Created. *
  234. *=========================================================================*/
  235. void IPXAddressClass::Get_Address(IPXHeaderType *header)
  236. {
  237. memcpy(header->DestNetworkNumber,NetworkNumber,4);
  238. memcpy(header->DestNetworkNode,NodeAddress,6);
  239. } /* end of Get_Address */
  240. /***************************************************************************
  241. * IPXAddressClass::Is_Broadcast -- tells if this is a broadcast address *
  242. * *
  243. * INPUT: *
  244. * none. *
  245. * *
  246. * OUTPUT: *
  247. * none. *
  248. * *
  249. * WARNINGS: *
  250. * none. *
  251. * *
  252. * HISTORY: *
  253. * 12/19/1994 BR : Created. *
  254. *=========================================================================*/
  255. bool IPXAddressClass::Is_Broadcast(void)
  256. {
  257. if ( NetworkNumber[0] == 0xff &&
  258. NetworkNumber[1] == 0xff &&
  259. NetworkNumber[2] == 0xff &&
  260. NetworkNumber[3] == 0xff &&
  261. NodeAddress[0] == 0xff &&
  262. NodeAddress[1] == 0xff &&
  263. NodeAddress[2] == 0xff &&
  264. NodeAddress[3] == 0xff &&
  265. NodeAddress[4] == 0xff &&
  266. NodeAddress[5] == 0xff) {
  267. return(true);
  268. } else {
  269. return(false);
  270. }
  271. }
  272. /***************************************************************************
  273. * IPXAddressClass::operator== -- overloaded comparison operator *
  274. * *
  275. * Since, if NETX isn't running, the network number on a received packet *
  276. * can be bogus (all 0's), only the node address is used for comparison *
  277. * purposes here. *
  278. * *
  279. * INPUT: *
  280. * addr address to compare to *
  281. * *
  282. * OUTPUT: *
  283. * 0 = not equal, 1 = equal *
  284. * *
  285. * WARNINGS: *
  286. * none. *
  287. * *
  288. * HISTORY: *
  289. * 12/19/1994 BR : Created. *
  290. *=========================================================================*/
  291. int IPXAddressClass::operator == (IPXAddressClass & addr)
  292. {
  293. /*------------------------------------------------------------------------
  294. If either Network Number is all 0's (which can happen if the system is
  295. not running NETX), compare only the Node Addresses.
  296. ------------------------------------------------------------------------*/
  297. if ( (NetworkNumber[0]==0 &&
  298. NetworkNumber[1]==0 &&
  299. NetworkNumber[2]==0 &&
  300. NetworkNumber[3]==0) ||
  301. (addr.NetworkNumber[0]==0 &&
  302. addr.NetworkNumber[1]==0 &&
  303. addr.NetworkNumber[2]==0 &&
  304. addr.NetworkNumber[3]==0) ) {
  305. if (memcmp(NodeAddress,addr.NodeAddress,6)==0) {
  306. return(true);
  307. } else {
  308. return(false);
  309. }
  310. } else {
  311. /*------------------------------------------------------------------------
  312. Otherwise, compare both the Network Numbers and Node Addresses
  313. ------------------------------------------------------------------------*/
  314. if (memcmp(NodeAddress,addr.NodeAddress,6)==0 && memcmp(NetworkNumber,addr.NetworkNumber,4)==0) {
  315. return(true);
  316. } else {
  317. return(false);
  318. }
  319. }
  320. }
  321. /***************************************************************************
  322. * IPXAddressClass::operator!= -- overloaded comparison operator *
  323. * *
  324. * Since, if NETX isn't running, the network number on a received packet *
  325. * can be bogus (all 0's), only the node address is used for comparison *
  326. * purposes here. *
  327. * *
  328. * INPUT: *
  329. * addr address to compare to *
  330. * *
  331. * OUTPUT: *
  332. * 0 = equal, 1 = not equal *
  333. * *
  334. * WARNINGS: *
  335. * none. *
  336. * *
  337. * HISTORY: *
  338. * 12/19/1994 BR : Created. *
  339. *=========================================================================*/
  340. int IPXAddressClass::operator != (IPXAddressClass & addr)
  341. {
  342. /*------------------------------------------------------------------------
  343. If either Network Number is all 0's (which can happen if the system is
  344. not running NETX), compare only the Node Addresses.
  345. ------------------------------------------------------------------------*/
  346. if ( (NetworkNumber[0]==0 &&
  347. NetworkNumber[1]==0 &&
  348. NetworkNumber[2]==0 &&
  349. NetworkNumber[3]==0) ||
  350. (addr.NetworkNumber[0]==0 &&
  351. addr.NetworkNumber[1]==0 &&
  352. addr.NetworkNumber[2]==0 &&
  353. addr.NetworkNumber[3]==0) ) {
  354. if (memcmp(NodeAddress,addr.NodeAddress,6)==0) {
  355. return(false);
  356. } else {
  357. return(true);
  358. }
  359. } else {
  360. /*------------------------------------------------------------------------
  361. Otherwise, compare both the Network Numbers and Node Addresses
  362. ------------------------------------------------------------------------*/
  363. if (memcmp(NodeAddress,addr.NodeAddress,6)==0 && memcmp(NetworkNumber,addr.NetworkNumber,4)==0) {
  364. return(false);
  365. } else {
  366. return(true);
  367. }
  368. }
  369. }
  370. /***************************************************************************
  371. * IPXAddressClass::operator > -- overloaded comparison operator *
  372. * *
  373. * INPUT: *
  374. * addr address to compare to *
  375. * *
  376. * OUTPUT: *
  377. * TRUE = greater, FALSE = not *
  378. * *
  379. * WARNINGS: *
  380. * none. *
  381. * *
  382. * HISTORY: *
  383. * 12/19/1994 BR : Created. *
  384. *=========================================================================*/
  385. int IPXAddressClass::operator > (IPXAddressClass & addr)
  386. {
  387. return(memcmp(this, &addr, 10) > 0);
  388. } /* end of operator != */
  389. /***************************************************************************
  390. * IPXAddressClass::operator < -- overloaded comparison operator *
  391. * *
  392. * INPUT: *
  393. * addr address to compare to *
  394. * *
  395. * OUTPUT: *
  396. * TRUE = less, FALSE = not *
  397. * *
  398. * WARNINGS: *
  399. * none. *
  400. * *
  401. * HISTORY: *
  402. * 12/19/1994 BR : Created. *
  403. *=========================================================================*/
  404. int IPXAddressClass::operator < (IPXAddressClass & addr)
  405. {
  406. return(memcmp(this, &addr, 10) < 0);
  407. } /* end of operator != */
  408. /***************************************************************************
  409. * IPXAddressClass::operator >= -- overloaded comparison operator *
  410. * *
  411. * INPUT: *
  412. * addr address to compare to *
  413. * *
  414. * OUTPUT: *
  415. * TRUE = greater or equal, FALSE = not *
  416. * *
  417. * WARNINGS: *
  418. * none. *
  419. * *
  420. * HISTORY: *
  421. * 12/19/1994 BR : Created. *
  422. *=========================================================================*/
  423. int IPXAddressClass::operator >= (IPXAddressClass & addr)
  424. {
  425. return(memcmp(this, &addr, 10) >= 0);
  426. } /* end of operator != */
  427. /***************************************************************************
  428. * IPXAddressClass::operator <= -- overloaded comparison operator *
  429. * *
  430. * INPUT: *
  431. * addr address to compare to *
  432. * *
  433. * OUTPUT: *
  434. * TRUE = less or equal, FALSE = not *
  435. * *
  436. * WARNINGS: *
  437. * none. *
  438. * *
  439. * HISTORY: *
  440. * 12/19/1994 BR : Created. *
  441. *=========================================================================*/
  442. int IPXAddressClass::operator <= (IPXAddressClass & addr)
  443. {
  444. return(memcmp(this, &addr, 10) <= 0);
  445. } /* end of operator != */