|
Mixe for Privacy and Anonymity in the Internet
|
00001 /* 00002 Copyright (c) 2000, The JAP-Team 00003 All rights reserved. 00004 Redistribution and use in source and binary forms, with or without modification, 00005 are permitted provided that the following conditions are met: 00006 00007 - Redistributions of source code must retain the above copyright notice, 00008 this list of conditions and the following disclaimer. 00009 00010 - Redistributions in binary form must reproduce the above copyright notice, 00011 this list of conditions and the following disclaimer in the documentation and/or 00012 other materials provided with the distribution. 00013 00014 - Neither the name of the University of Technology Dresden, Germany nor the names of its contributors 00015 may be used to endorse or promote products derived from this software without specific 00016 prior written permission. 00017 00018 00019 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS 00020 OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 00021 AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS 00022 BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 00023 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 00024 OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 00025 IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 00026 OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE 00027 */ 00028 #ifndef __CASOCKETADDRINET__ 00029 #define __CASOCKETADDRINET__ 00030 #include "CASocketAddr.hpp" 00031 #include "CAMutex.hpp" 00034 class CASocketAddrINet:private sockaddr_in,public CASocketAddr 00035 { 00036 public: 00037 static SINT32 init() 00038 { 00039 m_pcsGet=new CAMutex(); 00040 return E_SUCCESS; 00041 } 00042 static SINT32 cleanup() 00043 { 00044 delete m_pcsGet; 00045 m_pcsGet = NULL; 00046 return E_SUCCESS; 00047 } 00048 00049 //static SINT32 destroy(); 00050 SINT32 getType()const 00051 { 00052 return AF_INET; 00053 } 00054 CASocketAddrINet(); 00055 CASocketAddrINet(UINT16 port); 00056 00057 CASocketAddrINet(const CASocketAddrINet& addr); 00058 00059 CASocketAddr* clone() const 00060 { 00061 return new CASocketAddrINet(*this); 00062 } 00063 00065 const SOCKADDR* LPSOCKADDR()const 00066 { 00067 #if defined(_WIN32) &&!defined(MSC_VER) //for Borland C++ under Windows 00068 return (const ::LPSOCKADDR)(sockaddr_in*)this; 00069 #else 00070 return (const ::LPSOCKADDR)(static_cast<const sockaddr_in* const>(this)); 00071 #endif 00072 } 00073 00077 SINT32 getSize() const 00078 { 00079 return sizeof(sockaddr_in); 00080 } 00081 00082 SINT32 setAddr(const UINT8* szIP,UINT16 port); 00083 SINT32 setIP(UINT8 ip[4]); 00084 SINT32 setPort(UINT16 port); 00085 UINT16 getPort() const; 00086 SINT32 getHostName(UINT8* buff,UINT32 len)const; 00087 SINT32 getIP(UINT8 buff[4]) const; 00088 SINT32 getIPAsStr(UINT8* buff,UINT32 len) const; 00089 bool isAnyIP() 00090 { 00091 return sin_addr.s_addr==INADDR_ANY; 00092 } 00093 00094 bool equalsIP(UINT8 ip[4]) const 00095 { 00096 return (memcmp(ip,&sin_addr.s_addr,4)==0); 00097 } 00098 00099 static SINT32 getLocalHostName(UINT8* buff,UINT32 len); 00100 static SINT32 getLocalHostIP(UINT8 ip[4]); 00101 // operator LPSOCKADDR(){return (::LPSOCKADDR)m_pAddr;} 00102 00111 virtual SINT32 toString(UINT8* buff,UINT32 bufflen) const 00112 { 00113 UINT8 tmpbuff[255]; 00114 if(getIPAsStr(tmpbuff,255)!=E_SUCCESS) 00115 return E_UNKNOWN; 00116 if(snprintf((char*)buff,bufflen,"INet address: %s:%u",tmpbuff,getPort())<0) 00117 return E_SPACE; 00118 return E_SUCCESS; 00119 } 00120 private: 00121 static CAMutex* m_pcsGet; 00122 }; 00123 00124 #endif
1.7.6.1