Home | nevrax.com |
|
inet_address.hGo to the documentation of this file.00001 00007 /* Copyright, 2000 Nevrax Ltd. 00008 * 00009 * This file is part of NEVRAX NEL. 00010 * NEVRAX NEL is free software; you can redistribute it and/or modify 00011 * it under the terms of the GNU General Public License as published by 00012 * the Free Software Foundation; either version 2, or (at your option) 00013 * any later version. 00014 00015 * NEVRAX NEL is distributed in the hope that it will be useful, but 00016 * WITHOUT ANY WARRANTY; without even the implied warranty of 00017 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00018 * General Public License for more details. 00019 00020 * You should have received a copy of the GNU General Public License 00021 * along with NEVRAX NEL; see the file COPYING. If not, write to the 00022 * Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, 00023 * MA 02111-1307, USA. 00024 */ 00025 00026 #ifndef NL_INET_ADDRESS_H 00027 #define NL_INET_ADDRESS_H 00028 00029 #include "nel/misc/types_nl.h" 00030 00031 #include <string> 00032 #include <vector> 00033 00034 00035 struct sockaddr_in; 00036 struct in_addr; 00037 00038 00039 #ifdef NL_OS_WINDOWS 00040 // automatically add the win socket library if you use nel network part 00041 #pragma comment(lib, "ws2_32.lib") 00042 #endif 00043 00044 namespace NLMISC 00045 { 00046 class IStream; 00047 } 00048 00049 00050 namespace NLNET 00051 { 00052 00053 struct ESocket; 00054 00055 00064 class CInetAddress 00065 { 00066 public: 00067 00069 CInetAddress(); 00070 00072 CInetAddress( const std::string& hostName, uint16 port ); 00073 00076 CInetAddress( const std::string& hostNameAndPort ); 00077 00079 CInetAddress( const CInetAddress& other ); 00080 00082 CInetAddress& operator=( const CInetAddress& other ); 00083 00085 friend bool operator==( const CInetAddress& a1, const CInetAddress& a2 ); 00086 00088 friend bool operator<( const CInetAddress& a1, const CInetAddress& a2 ); 00089 00091 ~CInetAddress(); 00092 00094 CInetAddress& setByName( const std::string& hostname ); 00095 00097 void setPort( uint16 port ); 00098 00100 void setNameAndPort( const std::string& hostNameAndPort ); 00101 00105 void setSockAddr( const sockaddr_in* saddr ); 00106 00108 bool isValid() const; 00109 00111 const sockaddr_in *sockAddr() const; 00112 00114 uint32 internalIPAddress() const; 00115 00117 std::string ipAddress() const; 00118 00120 const std::string& hostName() const; 00121 00123 uint16 port() const; 00124 00126 std::string asString() const; 00127 00129 std::string asIPString() const; 00130 00132 void serial( NLMISC::IStream& s ); 00133 00135 static CInetAddress localHost(); 00136 00140 static std::vector<CInetAddress> localAddresses(); 00141 00143 static bool RetrieveNames; 00144 00145 protected: 00146 00148 CInetAddress( const in_addr *ip ); 00149 00150 private: 00151 00152 // Called in all constructors. Calls CBaseSocket::init(). 00153 void init(); 00154 00155 std::string _HostName; 00156 sockaddr_in *_SockAddr; 00157 bool _Valid; 00158 00159 }; 00160 00161 } 00162 00163 #endif // NL_INET_ADDRESS_H 00164 00165 /* End of inet_address.h */ |