00001 /***************************************************************************** 00002 * Copyright (C) 2011 by Benjamin Hadorn (b_hadorn@bluewin.ch) 00003 ***************************************************************************** 00004 * Project : Zeus Base Library 00005 * Module : IPv4Address 00006 * Package : Zeus.ZeusBase.Net 00007 * Author : Benjamin Hadorn 00008 * Date : 27.12.2011 00009 * System : Zeus-Framework 00010 ***************************************************************************** 00011 * Licence: * 00012 * This library is free software; you can redistribute it and/or modify * 00013 * it under the terms of the GNU Lesser General Public License as * 00014 * published by the Free Software Foundation; either version * 00015 * 2.1 of the License, or (at your option) any later version. * 00016 * * 00017 * This library is distributed in the hope that it will be useful, * 00018 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00019 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00020 * GNU Lesser General Public License for more details. * 00021 * * 00022 * You should have received a copy of the GNU Lesser General Public * 00023 * License along with this library; if not, write to the Free Software * 00024 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA * 00025 *****************************************************************************/ 00026 00027 /***************************************************************************** 00028 * Changes: 00029 * 27.12.2011 bha: created zeus 2.0 00030 *****************************************************************************/ 00031 00032 #ifndef IPv4AddressH 00033 #define IPv4AddressH 00034 00035 //--------------------------------------------------------------------------- 00036 #include <zeusbase/Net/IPAddress.h> 00037 #include <zeusbase/System/SingleLinkedList.hpp> 00038 00039 BEGIN_NAMESPACE_Zeus 00040 00041 /***************************************************************************/ 00044 /***************************************************************************/ 00045 zeusbase_class TIPv4Address : public TIPAddress 00046 { 00047 public: 00048 TIPv4Address(); 00049 TIPv4Address(const IString& rHostAddress, Uint uiPort); 00050 TIPv4Address(const TIPv4Address& rAddress); 00051 TIPv4Address(const struct sockaddr_in& rSocketAddress); 00052 virtual ~TIPv4Address(); 00053 00054 virtual TIPAddress* createNewAddress(); 00055 virtual TString getHostName() const; 00056 virtual bool getRawAddress(IList<Uint16>& rArray) const; 00057 virtual bool isValid() const; 00058 virtual const struct sockaddr& getSocketAddress() const; 00059 virtual Int getSocketAddressSize() const; 00060 virtual int getSocketFamily() const; 00061 virtual void setPort(Uint uiPort); 00062 virtual void reset(); 00063 00064 protected: 00066 struct sockaddr_in m_SocketAddress; 00067 00068 bool getRawAddress_internal(); 00069 00070 private: 00072 TSingleLinkedList<Uint16> m_lstAddressWords; 00073 00074 void initClass(); 00075 void initClass(const struct sockaddr_in& rSocketAddress); 00076 00077 //prohibited operators 00078 TIPv4Address& operator=(const TIPv4Address& /*rInPar*/) { return *this; } 00079 }; 00080 00081 /***************************************************************************/ 00084 /***************************************************************************/ 00085 inline TIPAddress* TIPv4Address::createNewAddress() 00086 { 00087 return new TIPv4Address(); 00088 } 00089 00090 /****************************************************************************/ 00093 /****************************************************************************/ 00094 inline bool TIPv4Address::getRawAddress(IList<Uint16>& rArray) const 00095 { 00096 m_lstAddressWords.copyToList(rArray); 00097 return isValid(); 00098 } 00099 00100 /***************************************************************************/ 00103 /***************************************************************************/ 00104 inline const struct sockaddr& TIPv4Address::getSocketAddress() const 00105 { 00106 return (struct sockaddr&)m_SocketAddress; 00107 } 00108 00109 /***************************************************************************/ 00112 /***************************************************************************/ 00113 inline Int TIPv4Address::getSocketAddressSize() const 00114 { 00115 return sizeof(sockaddr_in); 00116 } 00117 00118 /***************************************************************************/ 00121 /***************************************************************************/ 00122 inline int TIPv4Address::getSocketFamily() const 00123 { 00124 return AF_INET; 00125 } 00126 00127 00128 END_NAMESPACE_Zeus 00129 00130 #endif