|
Mixe for Privacy and Anonymity in the Internet
|
This class represents a socket address for Internet (IP) connections. More...
#include <CASocketAddrINet.hpp>
Public Member Functions | |
| SINT32 | getType () const |
| The type (family) of socket for which this address is useful. | |
| CASocketAddrINet () | |
| Must be called once before using one of the CAsocketAddrINet functions. | |
| CASocketAddrINet (UINT16 port) | |
| Constructs an IP-Address for port and ANY local host ip. | |
| CASocketAddrINet (const CASocketAddrINet &addr) | |
| Constructs an IP-Address from an other IP Adress. | |
| CASocketAddr * | clone () const |
| Creates a copy of the Address. | |
| const SOCKADDR * | LPSOCKADDR () const |
| Makes a cast to struct SOCKADDR*. | |
| SINT32 | getSize () const |
| Returns the Size of the SOCKADDR struct used. | |
| SINT32 | setAddr (const UINT8 *szIP, UINT16 port) |
| Sets the address to szIP and port. | |
| SINT32 | setIP (UINT8 ip[4]) |
| Sets the IP-Numbers for this address. | |
| SINT32 | setPort (UINT16 port) |
| Changes only(!) the port value of the address. | |
| UINT16 | getPort () const |
| Returns the port value of the address. | |
| SINT32 | getHostName (UINT8 *buff, UINT32 len) const |
| Returns the hostname for this address. | |
| SINT32 | getIP (UINT8 buff[4]) const |
| Returns the IP-Numbers for this address. | |
| SINT32 | getIPAsStr (UINT8 *buff, UINT32 len) const |
| Returns the IP-Number as an address string (doted-format). | |
| bool | isAnyIP () |
| bool | equalsIP (UINT8 ip[4]) const |
| virtual SINT32 | toString (UINT8 *buff, UINT32 bufflen) const |
| Returns a human readable representation of this address. | |
Static Public Member Functions | |
| static SINT32 | init () |
| static SINT32 | cleanup () |
| static SINT32 | getLocalHostName (UINT8 *buff, UINT32 len) |
| Returns the name of the local host. | |
| static SINT32 | getLocalHostIP (UINT8 ip[4]) |
| Returns the local IP-Address as four bytes. | |
Static Private Attributes | |
| static CAMutex * | m_pcsGet = NULL |
This class represents a socket address for Internet (IP) connections.
Definition at line 34 of file CASocketAddrINet.hpp.
Must be called once before using one of the CAsocketAddrINet functions.
Should be called if CASocketAddrINEt functions are not longer needed. If needed again init() must be called Constructs a IP-Address for port 0 and ANY local host ip
Definition at line 58 of file CASocketAddrINet.cpp.
References getSize(), and LPSOCKADDR().
Referenced by clone().
{
memset((SOCKADDR*)LPSOCKADDR(),0,getSize());
sin_family=AF_INET;
sin_addr.s_addr=INADDR_ANY;
sin_port=0;
}
Constructs an IP-Address for port and ANY local host ip.
Definition at line 67 of file CASocketAddrINet.cpp.
References getSize(), and LPSOCKADDR().
{
memset((SOCKADDR*)LPSOCKADDR(),0,getSize());
sin_family=AF_INET;
sin_port=htons(port);
sin_addr.s_addr=INADDR_ANY;
}
| CASocketAddrINet::CASocketAddrINet | ( | const CASocketAddrINet & | addr | ) |
Constructs an IP-Address from an other IP Adress.
Definition at line 76 of file CASocketAddrINet.cpp.
References getSize(), and LPSOCKADDR().
{
memset((SOCKADDR*)LPSOCKADDR(),0,getSize());
sin_family=AF_INET;
sin_port=addr.sin_port;
sin_addr.s_addr=addr.sin_addr.s_addr;
}
| static SINT32 CASocketAddrINet::cleanup | ( | ) | [inline, static] |
| CASocketAddr* CASocketAddrINet::clone | ( | ) | const [inline, virtual] |
Creates a copy of the Address.
Implements CASocketAddr.
Definition at line 59 of file CASocketAddrINet.hpp.
References CASocketAddrINet().
{
return new CASocketAddrINet(*this);
}
| bool CASocketAddrINet::equalsIP | ( | UINT8 | ip[4] | ) | const [inline] |
Definition at line 94 of file CASocketAddrINet.hpp.
{
return (memcmp(ip,&sin_addr.s_addr,4)==0);
}
| SINT32 CASocketAddrINet::getHostName | ( | UINT8 * | buff, |
| UINT32 | len | ||
| ) | const |
Returns the hostname for this address.
| buff | buffer for the returned zero terminated hostname |
| len | the size of the buffer |
| E_SUCCESS | if no error occured |
| E_UNKNOWN_HOST | if the name of the host could not be resolved |
| E_UNSPECIFIED | if buff was NULL |
| E_SPACE | if size of the buffer is to small |
Definition at line 145 of file CASocketAddrINet.cpp.
References E_SPACE, E_SUCCESS, E_UNKNOWN_HOST, E_UNSPECIFIED, CAMutex::lock(), m_pcsGet, and CAMutex::unlock().
Referenced by CAAccountingBIInterface::initBIConnection().
{
if(buff==NULL)
return E_UNSPECIFIED;
SINT32 ret;
m_pcsGet->lock();
HOSTENT* hosten=gethostbyaddr((const char*)&sin_addr,4,AF_INET);
if(hosten==NULL||hosten->h_name==NULL)
ret=E_UNKNOWN_HOST;
else if(strlen(hosten->h_name)>=len)
ret=E_SPACE;
else
{
strcpy((char*)buff,hosten->h_name);
ret=E_SUCCESS;
}
m_pcsGet->unlock();
return ret;
}
| SINT32 CASocketAddrINet::getIP | ( | UINT8 | buff[4] | ) | const |
Returns the IP-Numbers for this address.
| buff | buffer for the returned IP-Address (4 Bytes) |
| E_SUCCESS | if no error occured |
Definition at line 169 of file CASocketAddrINet.cpp.
References E_SUCCESS.
Referenced by getIPAsStr(), isAllowedToPassRestrictions(), and CALastMix::setTargets().
{
memcpy(buff,&sin_addr.s_addr,4);
return E_SUCCESS;
}
| SINT32 CASocketAddrINet::getIPAsStr | ( | UINT8 * | buff, |
| UINT32 | len | ||
| ) | const |
Returns the IP-Number as an address string (doted-format).
| buff | buffer for the returned IP-Address |
| len | buffer-space |
| E_SUCCESS | if no error occured |
Definition at line 190 of file CASocketAddrINet.cpp.
References E_SUCCESS, E_UNKNOWN, and getIP().
Referenced by CAInfoService::getPaymentInstance(), CAInfoService::sendCascadeHelo(), CAInfoService::sendMixHelo(), CAInfoService::sendStatus(), and toString().
{
if(buff==NULL)
return E_UNKNOWN;
UINT8 ip[4];
if(getIP(ip)!=E_SUCCESS)
return E_UNKNOWN;
char* strAddr=inet_ntoa(sin_addr);
if(strAddr==NULL)
return E_UNKNOWN;
if(strlen(strAddr)>=len)
return E_UNKNOWN;
strcpy((char*)buff,strAddr);
return E_SUCCESS;
}
| SINT32 CASocketAddrINet::getLocalHostIP | ( | UINT8 | ip[4] | ) | [static] |
Returns the local IP-Address as four bytes.
| ip | buffer for the returned IP-Address |
| E_SUCCESS | if no error occurs |
| E_UNKNOWN | in case of an error |
Definition at line 244 of file CASocketAddrINet.cpp.
References E_SUCCESS, E_UNKNOWN, CAMutex::lock(), m_pcsGet, and CAMutex::unlock().
{
SINT32 ret;
char buff[256];
m_pcsGet->lock();
if(gethostname(buff,256)==-1)
ret=E_UNKNOWN;
else
{
HOSTENT* hosten=gethostbyname((char*)buff);
if(hosten==NULL)
ret=E_UNKNOWN;
else
{
memcpy((char*)ip,hosten->h_addr_list[0],4);
ret=E_SUCCESS;
}
}
m_pcsGet->unlock();
return ret;
}
| SINT32 CASocketAddrINet::getLocalHostName | ( | UINT8 * | buff, |
| UINT32 | len | ||
| ) | [static] |
Returns the name of the local host.
| buff | buffer for the returned zero terminated hostname |
| len | the size of the buffer |
| E_SUCCESS | if no error occured |
| E_UNKNOWN_HOST | if the name of the host could not be resolved |
| E_UNSPECIFIED | if buff was NULL |
| E_SPACE | if size of the buffer is to small |
Definition at line 214 of file CASocketAddrINet.cpp.
References E_SPACE, E_SUCCESS, E_UNKNOWN_HOST, E_UNSPECIFIED, CAMutex::lock(), m_pcsGet, and CAMutex::unlock().
{
if(buff==NULL)
return E_UNSPECIFIED;
SINT32 ret;
m_pcsGet->lock();
if(gethostname((char*)buff,len)==-1)
ret=E_SPACE;
else
{
HOSTENT* hosten=gethostbyname((char*)buff);
if(hosten==NULL||hosten->h_name==NULL)
ret=E_UNKNOWN_HOST;
else if(strlen(hosten->h_name)>=len)
ret=E_SPACE;
else
{
strcpy((char*)buff,hosten->h_name);
ret=E_SUCCESS;
}
}
m_pcsGet->unlock();
return ret;
}
| UINT16 CASocketAddrINet::getPort | ( | ) | const |
Returns the port value of the address.
Definition at line 132 of file CASocketAddrINet.cpp.
Referenced by CAInfoService::getPaymentInstance(), CALocalProxy::init(), CAAccountingBIInterface::initBIConnection(), CAInfoService::sendCascadeHelo(), CAInfoService::sendMixHelo(), CAInfoService::sendStatus(), CALastMix::setTargets(), and toString().
{
return ntohs(sin_port);
}
| SINT32 CASocketAddrINet::getSize | ( | ) | const [inline, virtual] |
Returns the Size of the SOCKADDR struct used.
Implements CASocketAddr.
Definition at line 77 of file CASocketAddrINet.hpp.
Referenced by CASocketAddrINet().
{
return sizeof(sockaddr_in);
}
| SINT32 CASocketAddrINet::getType | ( | ) | const [inline, virtual] |
The type (family) of socket for which this address is useful.
Must be overwritten in subclasses.
Implements CASocketAddr.
Definition at line 50 of file CASocketAddrINet.hpp.
{
return AF_INET;
}
| static SINT32 CASocketAddrINet::init | ( | ) | [inline, static] |
| bool CASocketAddrINet::isAnyIP | ( | ) | [inline] |
Definition at line 89 of file CASocketAddrINet.hpp.
Referenced by CALocalProxy::init().
{
return sin_addr.s_addr==INADDR_ANY;
}
| const SOCKADDR* CASocketAddrINet::LPSOCKADDR | ( | ) | const [inline, virtual] |
Makes a cast to struct SOCKADDR*.
Implements CASocketAddr.
Definition at line 65 of file CASocketAddrINet.hpp.
Referenced by CASocketAddrINet().
{
#if defined(_WIN32) &&!defined(MSC_VER) //for Borland C++ under Windows
return (const ::LPSOCKADDR)(sockaddr_in*)this;
#else
return (const ::LPSOCKADDR)(static_cast<const sockaddr_in* const>(this));
#endif
}
| SINT32 CASocketAddrINet::setAddr | ( | const UINT8 * | szIP, |
| UINT16 | port | ||
| ) |
Sets the address to szIP and port.
szIP could be either a hostname or an IP-Address of the form a.b.c.d . If szIP==NULL, the the IP-Adredress ist set to ANY local IP Address
| szIP | new value for IP-Address or hostname (zero terminated string) |
| port | new value for port |
| E_SUCCESS | if no error occurs |
| E_UNKNOWN_HOST | if the hostname couldt not be resolved (or the ip is wrong). In this case the old values are NOT changed. |
Definition at line 93 of file CASocketAddrINet.cpp.
References E_SUCCESS, E_UNKNOWN_HOST, CAMutex::lock(), m_pcsGet, and CAMutex::unlock().
Referenced by CAInfoService::getPaymentInstance(), CALocalProxy::init(), and CAAccountingBIInterface::setPIServerConfiguration().
{
UINT32 newAddr=INADDR_ANY;
if(szIP!=NULL)
{
newAddr=inet_addr((const char*)szIP); //is it a doted string (a.b.c.d) ?
if(newAddr==INADDR_NONE) //if not try to find the hostname
{
m_pcsGet->lock();
HOSTENT* hostent=gethostbyname((const char*)szIP); //lookup
if(hostent!=NULL) //get it!
memcpy(&newAddr,hostent->h_addr_list[0],hostent->h_length);
else
{
m_pcsGet->unlock();
return E_UNKNOWN_HOST; //not found!
}
m_pcsGet->unlock();
}
}
sin_addr.s_addr=newAddr;
sin_port=htons(port);
return E_SUCCESS;
}
| SINT32 CASocketAddrINet::setIP | ( | UINT8 | ip[4] | ) |
Sets the IP-Numbers for this address.
| ip | buffer with the IP-Address (4 Bytes) |
| E_SUCCESS | if no error occured |
Definition at line 179 of file CASocketAddrINet.cpp.
References E_SUCCESS.
{
memcpy(&sin_addr.s_addr,ip,4);
return E_SUCCESS;
}
| SINT32 CASocketAddrINet::setPort | ( | UINT16 | port | ) |
Changes only(!) the port value of the address.
| port | new value for port |
Definition at line 123 of file CASocketAddrINet.cpp.
References E_SUCCESS.
{
sin_port=htons(port);
return E_SUCCESS;
}
| virtual SINT32 CASocketAddrINet::toString | ( | UINT8 * | buff, |
| UINT32 | bufflen | ||
| ) | const [inline, virtual] |
Returns a human readable representation of this address.
| buff | buffer which stores the address string |
| bufflen | size of the buffer |
| E_SPACE | if the buffer is to small |
| E_UNKNOWN | if an error occured |
| E_SUCCESS | if successfull |
Implements CASocketAddr.
Definition at line 111 of file CASocketAddrINet.hpp.
References E_SPACE, E_SUCCESS, E_UNKNOWN, getIPAsStr(), and getPort().
{
UINT8 tmpbuff[255];
if(getIPAsStr(tmpbuff,255)!=E_SUCCESS)
return E_UNKNOWN;
if(snprintf((char*)buff,bufflen,"INet address: %s:%u",tmpbuff,getPort())<0)
return E_SPACE;
return E_SUCCESS;
}
CAMutex * CASocketAddrINet::m_pcsGet = NULL [static, private] |
Definition at line 121 of file CASocketAddrINet.hpp.
Referenced by cleanup(), getHostName(), getLocalHostIP(), getLocalHostName(), init(), and setAddr().
1.7.6.1