| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438 |
- /*
- ** Command & Conquer Renegade(tm)
- ** Copyright 2025 Electronic Arts Inc.
- **
- ** This program is free software: you can redistribute it and/or modify
- ** it under the terms of the GNU General Public License as published by
- ** the Free Software Foundation, either version 3 of the License, or
- ** (at your option) any later version.
- **
- ** This program is distributed in the hope that it will be useful,
- ** but WITHOUT ANY WARRANTY; without even the implied warranty of
- ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- ** GNU General Public License for more details.
- **
- ** You should have received a copy of the GNU General Public License
- ** along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
- /***********************************************************************************************
- *** 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 ***
- ***********************************************************************************************
- * *
- * Project Name : Command & Conquer *
- * *
- * $Archive:: /Commando/Code/Commando/nataddr.cpp $*
- * *
- * $Author:: Steve_t $*
- * *
- * $Modtime:: 9/17/01 3:55p $*
- * *
- * $Revision:: 2 $*
- * *
- *---------------------------------------------------------------------------------------------*
- * Functions: *
- * IPAddressClass::IPAddressClass -- Class constructor *
- * IPAddressClass::IPAddressClass -- Class constructor *
- * IPAddressClass::IPAddressClass -- Class constructor *
- * IPAddressClass::Set_Address -- Sets a valid IP address into the class *
- * IPAddressClass::Set_Address -- Sets a valid IP address into the class *
- * IPAddressClass::Get_Address -- Get the address value of this class *
- * IPAddressClass::Get_Address -- Get the address value of this class *
- * IPAddressClass::Is_Broadcast -- Does this class represent a broadcast address? *
- * IPAddressClass::As_String -- Get address in human readable form *
- * IPAddressClass::operator == - Equality operator for the class *
- * IPAddressClass::operator != - Non-equality operator for the class *
- * IPAddressClass::operator = Assignment operator *
- * IPXAddressClass::As_String -- Get address in human readable form *
- * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
- #include "always.h"
- #include "assert.h"
- #include "nataddr.h"
- #include <stdio.h>
- #include <string.h>
- /***********************************************************************************************
- * IPAddressClass::IPAddressClass -- Class constructor *
- * *
- * *
- * *
- * INPUT: Nothing *
- * *
- * OUTPUT: Nothing *
- * *
- * WARNINGS: None *
- * *
- * HISTORY: *
- * 3/9/00 12:58PM ST : Created *
- *=============================================================================================*/
- IPAddressClass::IPAddressClass(void)
- {
- WholeAddress = 0x00000000;
- Port = 0;
- IsValid = false;
- }
- /***********************************************************************************************
- * IPAddressClass::IPAddressClass -- Class constructor *
- * *
- * *
- * *
- * INPUT: Ptr to valid IP address *
- * *
- * OUTPUT: Nothing *
- * *
- * WARNINGS: None *
- * *
- * HISTORY: *
- * 3/9/00 12:59PM ST : Created *
- *=============================================================================================*/
- IPAddressClass::IPAddressClass(unsigned char *address, unsigned short port)
- {
- WholeAddress = *((unsigned long*)address);
- Port = port;
- IsValid = true;
- }
- /***********************************************************************************************
- * IPAddressClass::IPAddressClass -- Class constructor *
- * *
- * *
- * *
- * INPUT: 32 bit IP address *
- * *
- * OUTPUT: Nothing *
- * *
- * WARNINGS: None *
- * *
- * HISTORY: *
- * 3/9/00 1:00PM ST : Created *
- *=============================================================================================*/
- IPAddressClass::IPAddressClass(unsigned long address, unsigned short port)
- {
- WholeAddress = address;
- Port = port;
- IsValid = true;
- }
- /***********************************************************************************************
- * IPAddressClass::Set_Address -- Sets a valid IP address into the class *
- * *
- * *
- * *
- * INPUT: Ptr to IP address *
- * *
- * OUTPUT: Nothing *
- * *
- * WARNINGS: None *
- * *
- * HISTORY: *
- * 3/9/00 1:01PM ST : Created *
- *=============================================================================================*/
- void IPAddressClass::Set_Address(unsigned char *address, unsigned short port)
- {
- WholeAddress = *((unsigned long*)address);
- Port = port;
- IsValid = true;
- }
- /***********************************************************************************************
- * IPAddressClass::Set_Address -- Sets a valid IP address into the class *
- * *
- * *
- * *
- * INPUT: 32 bit IP address *
- * *
- * OUTPUT: Nothing *
- * *
- * WARNINGS: None *
- * *
- * HISTORY: *
- * 3/9/00 1:01PM ST : Created *
- *=============================================================================================*/
- void IPAddressClass::Set_Address(unsigned long address, unsigned short port)
- {
- WholeAddress = address;
- Port = port;
- IsValid = true;
- }
- /***********************************************************************************************
- * IPAddressClass::Get_Address -- Get the address value of this class *
- * *
- * *
- * *
- * INPUT: Ptr to area to store the address into *
- * *
- * OUTPUT: Nothing *
- * *
- * WARNINGS: None *
- * *
- * HISTORY: *
- * 3/9/00 1:03PM ST : Created *
- *=============================================================================================*/
- void IPAddressClass::Get_Address(unsigned char *address, unsigned short *port)
- {
- fw_assert(IsValid);
- *((unsigned long*)address) = WholeAddress;
- if (port) {
- *port = Port;
- }
- }
- /***********************************************************************************************
- * IPAddressClass::Get_Address -- Get the address value of this class *
- * *
- * *
- * *
- * INPUT: Nothing *
- * *
- * OUTPUT: 32 bit IP address *
- * *
- * WARNINGS: None *
- * *
- * HISTORY: *
- * 3/9/00 1:03PM ST : Created *
- *=============================================================================================*/
- unsigned long IPAddressClass::Get_Address(void)
- {
- fw_assert(IsValid);
- return (WholeAddress);
- }
- /***********************************************************************************************
- * IPAddressClass::Get_Port -- Get the port number associated with this address *
- * *
- * *
- * *
- * INPUT: Nothing *
- * *
- * OUTPUT: Port number *
- * *
- * WARNINGS: None *
- * *
- * HISTORY: *
- * 10/24/00 11:51AM ST : Created *
- *=============================================================================================*/
- unsigned short IPAddressClass::Get_Port(void)
- {
- fw_assert(IsValid);
- return(Port);
- }
- /***********************************************************************************************
- * IPAddressClass::Is_Broadcast -- Does this class represent a broadcast address? *
- * *
- * *
- * *
- * INPUT: Nothing *
- * *
- * OUTPUT: True if broadcast address *
- * *
- * WARNINGS: None *
- * *
- * HISTORY: *
- * 3/9/00 1:06PM ST : Created *
- *=============================================================================================*/
- bool IPAddressClass::Is_Broadcast(void)
- {
- if (IsValid && WholeAddress == 0xffffffff) {
- return(true);
- }
- return(false);
- }
- /***********************************************************************************************
- * IPAddressClass::As_String -- Get address in human readable form *
- * *
- * *
- * *
- * INPUT: ptr to address *
- * *
- * OUTPUT: ptr to string *
- * *
- * WARNINGS: None *
- * *
- * HISTORY: *
- * 3/9/00 1:07PM ST : Created *
- *=============================================================================================*/
- char *IPAddressClass::As_String(void)
- {
- static char _addr_str[128];
- sprintf (_addr_str, "%d.%d.%d.%d ; %d", Address[0], Address[1], Address[2], Address[3], (unsigned int)Port);
- return (_addr_str);
- }
- /***********************************************************************************************
- * IPAddressClass::Is_IP_Equal -- Compare the IP portion of the address only, ignore the port *
- * *
- * *
- * *
- * INPUT: Address to compare to *
- * *
- * OUTPUT: True if equal *
- * *
- * WARNINGS: None *
- * *
- * HISTORY: *
- * 10/25/00 2:23PM ST : Created *
- *=============================================================================================*/
- bool IPAddressClass::Is_IP_Equal(IPAddressClass &address)
- {
- if (IsValid && address.Is_Valid() && address.Get_Address() == WholeAddress) {
- return(true);
- }
- return(false);
- }
- /***********************************************************************************************
- * IPAddressClass::operator == - Equality operator for the class *
- * *
- * *
- * *
- * INPUT: Class to compare to *
- * *
- * OUTPUT: True if the same *
- * *
- * WARNINGS: None *
- * *
- * HISTORY: *
- * 3/9/00 1:10PM ST : Created *
- *=============================================================================================*/
- bool IPAddressClass::operator == (IPAddressClass &address)
- {
- if (IsValid && address.Is_Valid() && address.Get_Address() == WholeAddress && address.Get_Port() == Port) {
- return(true);
- }
- return(false);
- }
- /***********************************************************************************************
- * IPAddressClass::operator != - Non-equality operator for the class *
- * *
- * *
- * *
- * INPUT: Class to compare to *
- * *
- * OUTPUT: True if not the same *
- * *
- * WARNINGS: None *
- * *
- * HISTORY: *
- * 3/9/00 1:10PM ST : Created *
- *=============================================================================================*/
- bool IPAddressClass::operator != (IPAddressClass &address)
- {
- if (!IsValid || !address.Is_Valid() || address.Get_Address() != WholeAddress || address.Get_Port() != Port) {
- return(true);
- }
- return(false);
- }
- /***********************************************************************************************
- * IPAddressClass::operator == - Equality operator for the class *
- * *
- * *
- * *
- * INPUT: Class to compare to *
- * *
- * OUTPUT: True if the same *
- * *
- * WARNINGS: None *
- * *
- * HISTORY: *
- * 3/9/00 1:10PM ST : Created *
- *=============================================================================================*/
- bool IPAddressClass::operator == (IPAddressClass address)
- {
- if (IsValid && address.Is_Valid() && address.Get_Address() == WholeAddress && address.Get_Port() == Port) {
- return(true);
- }
- return(false);
- }
- /***********************************************************************************************
- * IPAddressClass::operator != - Non-equality operator for the class *
- * *
- * *
- * *
- * INPUT: Class to compare to *
- * *
- * OUTPUT: True if not the same *
- * *
- * WARNINGS: None *
- * *
- * HISTORY: *
- * 3/9/00 1:10PM ST : Created *
- *=============================================================================================*/
- bool IPAddressClass::operator != (IPAddressClass address)
- {
- if (!IsValid || !address.Is_Valid() || address.Get_Address() != WholeAddress || address.Get_Port() != Port) {
- return(true);
- }
- return(false);
- }
- /***********************************************************************************************
- * IPAddressClass::operator = Assignment operator *
- * *
- * *
- * *
- * INPUT: Class to store into this class *
- * *
- * OUTPUT: Nothing *
- * *
- * WARNINGS: None *
- * *
- * HISTORY: *
- * 3/9/00 1:10PM ST : Created *
- *=============================================================================================*/
- bool IPAddressClass::operator = (const IPAddressClass &address)
- {
- IsValid = ((IPAddressClass &)address).Is_Valid();
- /*
- ** Can't read an invalid address without causing an assert.
- */
- if (IsValid) {
- WholeAddress = ((IPAddressClass &)address).Get_Address();
- Port = ((IPAddressClass &)address).Get_Port();
- } else {
- WholeAddress = 0xffffffff;
- Port = 0;
- }
- return(IsValid);
- }
|