CnC_Remastered_Collection

Command and Conquer: Red Alert
Log | Files | Refs | README | LICENSE

IPXADDR.CPP (24320B)


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