IPXADDR.CPP 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506
  1. //
  2. // Copyright 2020 Electronic Arts Inc.
  3. //
  4. // TiberianDawn.DLL and RedAlert.dll and corresponding source code is free
  5. // software: you can redistribute it and/or modify it under the terms of
  6. // the GNU General Public License as published by the Free Software Foundation,
  7. // either version 3 of the License, or (at your option) any later version.
  8. // TiberianDawn.DLL and RedAlert.dll and corresponding source code is distributed
  9. // in the hope that it will be useful, but with permitted additional restrictions
  10. // under Section 7 of the GPL. See the GNU General Public License in LICENSE.TXT
  11. // distributed with this program. You should have received a copy of the
  12. // GNU General Public License along with permitted additional restrictions
  13. // with this program. If not, see https://github.com/electronicarts/CnC_Remastered_Collection
  14. /* $Header: /CounterStrike/IPXADDR.CPP 1 3/03/97 10:24a Joe_bostic $ */
  15. /***************************************************************************
  16. ** 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 **
  17. ***************************************************************************
  18. * *
  19. * Project Name : Command & Conquer *
  20. * *
  21. * File Name : IPXADDR.CPP *
  22. * *
  23. * Programmer : Bill Randolph *
  24. * *
  25. * Start Date : December 19, 1994 *
  26. * *
  27. * Last Update : December 19, 1994 [BR] *
  28. * *
  29. *-------------------------------------------------------------------------*
  30. * Functions: *
  31. * IPXAddressClass::IPXAddressClass -- class constructor *
  32. * IPXAddressClass::IPXAddressClass -- class constructor form 2 *
  33. * IPXAddressClass::IPXAddressClass -- class constructor form 3 *
  34. * IPXAddressClass::Set_Address -- sets the IPX address values *
  35. * IPXAddressClass::Set_Address -- sets the IPX values from a header *
  36. * IPXAddressClass::Get_Address -- retrieves the IPX address values *
  37. * IPXAddressClass::Get_Address -- copies address into an IPX header *
  38. * IPXAddressClass::Is_Broadcast -- tells if this is a broadcast address *
  39. * IPXAddressClass::operator== -- overloaded comparison operator *
  40. * IPXAddressClass::operator!= -- overloaded comparison operator *
  41. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  42. #include "function.h"
  43. #include <stdio.h>
  44. //#include <mem.h>
  45. #include "ipxaddr.h"
  46. #ifdef WINSOCK_IPX
  47. #include "WSProto.h"
  48. #endif //WINSOCK_IPX
  49. /***************************************************************************
  50. * IPXAddressClass::IPXAddressClass -- class constructor *
  51. * *
  52. * This default constructor generates a broadcast address. *
  53. * *
  54. * INPUT: *
  55. * net Network Number for this address *
  56. * node Node Address for this address *
  57. * *
  58. * OUTPUT: *
  59. * none. *
  60. * *
  61. * WARNINGS: *
  62. * none. *
  63. * *
  64. * HISTORY: *
  65. * 12/19/1994 BR : Created. *
  66. *=========================================================================*/
  67. IPXAddressClass::IPXAddressClass(void)
  68. {
  69. NetworkNumber[0] = 0xff;
  70. NetworkNumber[1] = 0xff;
  71. NetworkNumber[2] = 0xff;
  72. NetworkNumber[3] = 0xff;
  73. NodeAddress[0] = 0xff;
  74. NodeAddress[1] = 0xff;
  75. NodeAddress[2] = 0xff;
  76. NodeAddress[3] = 0xff;
  77. NodeAddress[4] = 0xff;
  78. NodeAddress[5] = 0xff;
  79. } /* end of IPXAddressClass */
  80. /***************************************************************************
  81. * IPXAddressClass::IPXAddressClass -- class constructor form 2 *
  82. * *
  83. * INPUT: *
  84. * net Network Number for this address *
  85. * node Node Address for this address *
  86. * *
  87. * OUTPUT: *
  88. * none. *
  89. * *
  90. * WARNINGS: *
  91. * none. *
  92. * *
  93. * HISTORY: *
  94. * 12/19/1994 BR : Created. *
  95. *=========================================================================*/
  96. IPXAddressClass::IPXAddressClass(NetNumType net, NetNodeType node)
  97. {
  98. memcpy(NetworkNumber, net, 4);
  99. memcpy(NodeAddress, node, 6);
  100. } /* end of IPXAddressClass */
  101. /***************************************************************************
  102. * IPXAddressClass::IPXAddressClass -- class constructor form 3 *
  103. * *
  104. * This form of the constructor takes an IPX header as an argument. It *
  105. * extracts the address from the Source address fields in the header. *
  106. * *
  107. * INPUT: *
  108. * header Header from which to extract the address *
  109. * *
  110. * OUTPUT: *
  111. * none. *
  112. * *
  113. * WARNINGS: *
  114. * none. *
  115. * *
  116. * HISTORY: *
  117. * 12/19/1994 BR : Created. *
  118. *=========================================================================*/
  119. IPXAddressClass::IPXAddressClass(IPXHeaderType *header)
  120. {
  121. memcpy(NetworkNumber,header->SourceNetworkNumber,4);
  122. memcpy(NodeAddress,header->SourceNetworkNode,6);
  123. } /* end of IPXAddressClass */
  124. /***************************************************************************
  125. * IPXAddressClass::Set_Address -- sets the IPX address values *
  126. * *
  127. * INPUT: *
  128. * net Network Number for this address *
  129. * node Node Address for this address *
  130. * *
  131. * OUTPUT: *
  132. * none. *
  133. * *
  134. * WARNINGS: *
  135. * none. *
  136. * *
  137. * HISTORY: *
  138. * 12/19/1994 BR : Created. *
  139. *=========================================================================*/
  140. void IPXAddressClass::Set_Address(NetNumType net, NetNodeType node)
  141. {
  142. memcpy(NetworkNumber,net,4);
  143. memcpy(NodeAddress,node,6);
  144. } /* end of Set_Address */
  145. /***************************************************************************
  146. * IPXAddressClass::Set_Address -- sets the IPX values from a header *
  147. * *
  148. * This routine extracts the source addresses from the given IPX header. *
  149. * *
  150. * INPUT: *
  151. * net Network Number for this address *
  152. * node Node Address for this address *
  153. * *
  154. * OUTPUT: *
  155. * none. *
  156. * *
  157. * WARNINGS: *
  158. * none. *
  159. * *
  160. * HISTORY: *
  161. * 12/19/1994 BR : Created. *
  162. *=========================================================================*/
  163. void IPXAddressClass::Set_Address(IPXHeaderType *header)
  164. {
  165. #ifdef WINSOCK_IPX
  166. ProtocolEnum protocol = PROTOCOL_IPX;
  167. if ( PacketTransport ) protocol = PacketTransport->Get_Protocol();
  168. switch ( protocol ) {
  169. case PROTOCOL_IPX:
  170. memcpy(NetworkNumber,header->SourceNetworkNumber,4);
  171. memcpy(NodeAddress,header->SourceNetworkNode,6);
  172. break;
  173. case PROTOCOL_UDP:
  174. unsigned char *addr = (unsigned char*) header;
  175. memset (NodeAddress, 0, 6);
  176. memcpy (NodeAddress, addr, 4);
  177. memset (NetworkNumber, 0, 4);
  178. break;
  179. }
  180. #else //WINSOCK_IPX
  181. if (header) {
  182. memcpy(NetworkNumber,header->SourceNetworkNumber,4);
  183. memcpy(NodeAddress,header->SourceNetworkNode,6);
  184. } else {
  185. /*
  186. ** Address is meaningless when using winsock
  187. */
  188. memset(NetworkNumber, 1 ,4);
  189. memset(NodeAddress, 1, 6);
  190. }
  191. #endif //WINSOCK_IPX
  192. } /* end of Set_Address */
  193. /***************************************************************************
  194. * IPXAddressClass::Get_Address -- retrieves the IPX address values *
  195. * *
  196. * INPUT: *
  197. * net Network Number for this address *
  198. * node Node Address for this address *
  199. * *
  200. * OUTPUT: *
  201. * none. *
  202. * *
  203. * WARNINGS: *
  204. * none. *
  205. * *
  206. * HISTORY: *
  207. * 12/19/1994 BR : Created. *
  208. *=========================================================================*/
  209. void IPXAddressClass::Get_Address(NetNumType net, NetNodeType node)
  210. {
  211. memcpy(net,NetworkNumber,4);
  212. memcpy(node,NodeAddress,6);
  213. } /* end of Get_Address */
  214. /***************************************************************************
  215. * IPXAddressClass::Get_Address -- copies address into an IPX header *
  216. * *
  217. * INPUT: *
  218. * net Network Number for this address *
  219. * node Node Address for this address *
  220. * *
  221. * OUTPUT: *
  222. * none. *
  223. * *
  224. * WARNINGS: *
  225. * none. *
  226. * *
  227. * HISTORY: *
  228. * 12/19/1994 BR : Created. *
  229. *=========================================================================*/
  230. void IPXAddressClass::Get_Address(IPXHeaderType *header)
  231. {
  232. memcpy(header->DestNetworkNumber,NetworkNumber,4);
  233. memcpy(header->DestNetworkNode,NodeAddress,6);
  234. } /* end of Get_Address */
  235. /***************************************************************************
  236. * IPXAddressClass::Is_Broadcast -- tells if this is a broadcast address *
  237. * *
  238. * INPUT: *
  239. * none. *
  240. * *
  241. * OUTPUT: *
  242. * none. *
  243. * *
  244. * WARNINGS: *
  245. * none. *
  246. * *
  247. * HISTORY: *
  248. * 12/19/1994 BR : Created. *
  249. *=========================================================================*/
  250. int IPXAddressClass::Is_Broadcast(void)
  251. {
  252. if ( NetworkNumber[0] == 0xff &&
  253. NetworkNumber[1] == 0xff &&
  254. NetworkNumber[2] == 0xff &&
  255. NetworkNumber[3] == 0xff &&
  256. NodeAddress[0] == 0xff &&
  257. NodeAddress[1] == 0xff &&
  258. NodeAddress[2] == 0xff &&
  259. NodeAddress[3] == 0xff &&
  260. NodeAddress[4] == 0xff &&
  261. NodeAddress[5] == 0xff) {
  262. return(1);
  263. }
  264. else {
  265. return(0);
  266. }
  267. } /* end of Is_Broadcast */
  268. /***************************************************************************
  269. * IPXAddressClass::operator== -- overloaded comparison operator *
  270. * *
  271. * Since, if NETX isn't running, the network number on a received packet *
  272. * can be bogus (all 0's), only the node address is used for comparison *
  273. * purposes here. *
  274. * *
  275. * INPUT: *
  276. * addr address to compare to *
  277. * *
  278. * OUTPUT: *
  279. * 0 = not equal, 1 = equal *
  280. * *
  281. * WARNINGS: *
  282. * none. *
  283. * *
  284. * HISTORY: *
  285. * 12/19/1994 BR : Created. *
  286. *=========================================================================*/
  287. int IPXAddressClass::operator == (IPXAddressClass & addr)
  288. {
  289. //------------------------------------------------------------------------
  290. // If either Network Number is all 0's (which can happen if the system is
  291. // not running NETX), compare only the Node Addresses.
  292. //------------------------------------------------------------------------
  293. if ( (NetworkNumber[0]==0 &&
  294. NetworkNumber[1]==0 &&
  295. NetworkNumber[2]==0 &&
  296. NetworkNumber[3]==0) ||
  297. (addr.NetworkNumber[0]==0 &&
  298. addr.NetworkNumber[1]==0 &&
  299. addr.NetworkNumber[2]==0 &&
  300. addr.NetworkNumber[3]==0) ) {
  301. if (memcmp(NodeAddress,addr.NodeAddress,6)==0) {
  302. return(1);
  303. }
  304. else {
  305. return(0);
  306. }
  307. }
  308. //------------------------------------------------------------------------
  309. // Otherwise, compare both the Network Numbers and Node Addresses
  310. //------------------------------------------------------------------------
  311. else {
  312. if (memcmp(NodeAddress,addr.NodeAddress,6)==0 &&
  313. memcmp(NetworkNumber,addr.NetworkNumber,4)==0) {
  314. return(1);
  315. }
  316. else {
  317. return(0);
  318. }
  319. }
  320. } /* end of operator== */
  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(0);
  356. }
  357. else {
  358. return(1);
  359. }
  360. }
  361. //------------------------------------------------------------------------
  362. // Otherwise, compare both the Network Numbers and Node Addresses
  363. //------------------------------------------------------------------------
  364. else {
  365. if (memcmp(NodeAddress,addr.NodeAddress,6)==0 &&
  366. memcmp(NetworkNumber,addr.NetworkNumber,4)==0) {
  367. return(0);
  368. }
  369. else {
  370. return(1);
  371. }
  372. }
  373. } /* end of operator!= */
  374. /***************************************************************************
  375. * IPXAddressClass::operator > -- overloaded comparison operator *
  376. * *
  377. * INPUT: *
  378. * addr address to compare to *
  379. * *
  380. * OUTPUT: *
  381. * TRUE = greater, FALSE = not *
  382. * *
  383. * WARNINGS: *
  384. * none. *
  385. * *
  386. * HISTORY: *
  387. * 12/19/1994 BR : Created. *
  388. *=========================================================================*/
  389. int IPXAddressClass::operator > (IPXAddressClass & addr)
  390. {
  391. return(memcmp(this, &addr, 10) > 0);
  392. } /* end of operator> */
  393. /***************************************************************************
  394. * IPXAddressClass::operator < -- overloaded comparison operator *
  395. * *
  396. * INPUT: *
  397. * addr address to compare to *
  398. * *
  399. * OUTPUT: *
  400. * TRUE = less, FALSE = not *
  401. * *
  402. * WARNINGS: *
  403. * none. *
  404. * *
  405. * HISTORY: *
  406. * 12/19/1994 BR : Created. *
  407. *=========================================================================*/
  408. int IPXAddressClass::operator < (IPXAddressClass & addr)
  409. {
  410. return(memcmp(this, &addr, 10) < 0);
  411. } /* end of operator< */
  412. /***************************************************************************
  413. * IPXAddressClass::operator >= -- overloaded comparison operator *
  414. * *
  415. * INPUT: *
  416. * addr address to compare to *
  417. * *
  418. * OUTPUT: *
  419. * TRUE = greater or equal, FALSE = not *
  420. * *
  421. * WARNINGS: *
  422. * none. *
  423. * *
  424. * HISTORY: *
  425. * 12/19/1994 BR : Created. *
  426. *=========================================================================*/
  427. int IPXAddressClass::operator >= (IPXAddressClass & addr)
  428. {
  429. return(memcmp(this, &addr, 10) >= 0);
  430. } /* end of operator>= */
  431. /***************************************************************************
  432. * IPXAddressClass::operator <= -- overloaded comparison operator *
  433. * *
  434. * INPUT: *
  435. * addr address to compare to *
  436. * *
  437. * OUTPUT: *
  438. * TRUE = less or equal, FALSE = not *
  439. * *
  440. * WARNINGS: *
  441. * none. *
  442. * *
  443. * HISTORY: *
  444. * 12/19/1994 BR : Created. *
  445. *=========================================================================*/
  446. int IPXAddressClass::operator <= (IPXAddressClass & addr)
  447. {
  448. return(memcmp(this, &addr, 10) <= 0);
  449. } /* end of operator<= */
  450. /************************** end of ipxaddr.cpp *****************************/