Mixe for Privacy and Anonymity in the Internet
Public Member Functions | Static Public Member Functions | Static Private Attributes | List of all members
CASocketAddrINet Class Reference

This class represents a socket address for Internet (IP) connections. More...

#include <CASocketAddrINet.hpp>

Inheritance diagram for CASocketAddrINet:
Collaboration diagram for CASocketAddrINet:

Public Member Functions

SINT32 getType () const
 The type (family) of socket for which this address is useful. More...
 
 CASocketAddrINet ()
 Must be called once before using one of the CAsocketAddrINet functions. More...
 
 CASocketAddrINet (UINT16 port)
 Constructs an IP-Address for port and ANY local host ip. More...
 
 CASocketAddrINet (const CASocketAddrINet &addr)
 Constructs an IP-Address from an other IP Adress. More...
 
CASocketAddrclone () const
 Creates a copy of the Address. More...
 
const SOCKADDRLPSOCKADDR () const
 Makes a cast to struct SOCKADDR*. More...
 
SINT32 getSize () const
 Returns the Size of the SOCKADDR struct used. More...
 
SINT32 setAddr (const UINT8 *szIP, UINT16 port)
 Sets the address to szIP and port. More...
 
SINT32 setIP (UINT8 ip[4])
 Sets the IP-Numbers for this address. More...
 
SINT32 setPort (UINT16 port)
 Changes only(!) the port value of the address. More...
 
UINT16 getPort () const
 Returns the port value of the address. More...
 
SINT32 getHostName (UINT8 *buff, UINT32 len) const
 Returns the hostname for this address. More...
 
SINT32 getIP (UINT8 buff[4]) const
 Returns the IP-Numbers for this address. More...
 
SINT32 getIPAsStr (UINT8 *buff, UINT32 len) const
 Returns the IP-Number as an address string (doted-format). More...
 
bool isAnyIP ()
 
bool equalsIP (UINT8 ip[4]) const
 
virtual SINT32 toString (UINT8 *buff, UINT32 bufflen) const
 Returns a human readable representation of this address. More...
 
- Public Member Functions inherited from CASocketAddr
virtual ~CASocketAddr ()
 

Static Public Member Functions

static SINT32 init ()
 
static SINT32 cleanup ()
 
static SINT32 getLocalHostName (UINT8 *buff, UINT32 len)
 Returns the name of the local host. More...
 
static SINT32 getLocalHostIP (UINT8 ip[4])
 Returns the local IP-Address as four bytes. More...
 
static SINT32 getIPForString (UINT8 *strIP, UINT8 ip[4])
 

Static Private Attributes

static CAMutexm_pcsGet =NULL
 

Detailed Description

This class represents a socket address for Internet (IP) connections.

Definition at line 34 of file CASocketAddrINet.hpp.

Constructor & Destructor Documentation

◆ CASocketAddrINet() [1/3]

CASocketAddrINet::CASocketAddrINet ( )

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.

59  {
60  memset((SOCKADDR*)LPSOCKADDR(),0,getSize());
61  sin_family=AF_INET;
62  sin_addr.s_addr=INADDR_ANY;
63  sin_port=0;
64  }
struct sockaddr SOCKADDR
Definition: StdAfx.h:458
const SOCKADDR * LPSOCKADDR() const
Makes a cast to struct SOCKADDR*.
SINT32 getSize() const
Returns the Size of the SOCKADDR struct used.

References getSize(), and LPSOCKADDR().

Referenced by clone().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ CASocketAddrINet() [2/3]

CASocketAddrINet::CASocketAddrINet ( UINT16  port)

Constructs an IP-Address for port and ANY local host ip.

Definition at line 67 of file CASocketAddrINet.cpp.

68  {
69  memset((SOCKADDR*)LPSOCKADDR(),0,getSize());
70  sin_family=AF_INET;
71  sin_port=htons(port);
72  sin_addr.s_addr=INADDR_ANY;
73  }

References getSize(), and LPSOCKADDR().

Here is the call graph for this function:

◆ CASocketAddrINet() [3/3]

CASocketAddrINet::CASocketAddrINet ( const CASocketAddrINet addr)

Constructs an IP-Address from an other IP Adress.

Definition at line 76 of file CASocketAddrINet.cpp.

77  {
78  memset((SOCKADDR*)LPSOCKADDR(),0,getSize());
79  sin_family=AF_INET;
80  sin_port=addr.sin_port;
81  sin_addr.s_addr=addr.sin_addr.s_addr;
82  }

References getSize(), and LPSOCKADDR().

Here is the call graph for this function:

Member Function Documentation

◆ cleanup()

static SINT32 CASocketAddrINet::cleanup ( )
inlinestatic

Definition at line 42 of file CASocketAddrINet.hpp.

43  {
44  delete m_pcsGet;
45  m_pcsGet = NULL;
46  return E_SUCCESS;
47  }
static CAMutex * m_pcsGet
const SINT32 E_SUCCESS
Definition: errorcodes.hpp:2

References E_SUCCESS, and m_pcsGet.

Referenced by CALibProxytest::cleanup().

Here is the caller graph for this function:

◆ clone()

CASocketAddr* CASocketAddrINet::clone ( ) const
inlinevirtual

Creates a copy of the Address.

Implements CASocketAddr.

Definition at line 59 of file CASocketAddrINet.hpp.

60  {
61  return new CASocketAddrINet(*this);
62  }
CASocketAddrINet()
Must be called once before using one of the CAsocketAddrINet functions.

References CASocketAddrINet().

Here is the call graph for this function:

◆ equalsIP()

bool CASocketAddrINet::equalsIP ( UINT8  ip[4]) const
inline

Definition at line 94 of file CASocketAddrINet.hpp.

95  {
96  return (memcmp(ip,&sin_addr.s_addr,4)==0);
97  }

◆ getHostName()

SINT32 CASocketAddrINet::getHostName ( UINT8 buff,
UINT32  len 
) const

Returns the hostname for this address.

Parameters
buffbuffer for the returned zero terminated hostname
lenthe size of the buffer
Return values
E_SUCCESSif no error occured
E_UNKNOWN_HOSTif the name of the host could not be resolved
E_UNSPECIFIEDif buff was NULL
E_SPACEif size of the buffer is to small

Definition at line 145 of file CASocketAddrINet.cpp.

146  {
147  if(buff==NULL)
148  return E_UNSPECIFIED;
149  SINT32 ret;
150  m_pcsGet->lock();
151  HOSTENT* hosten=gethostbyaddr((const char*)&sin_addr,4,AF_INET);
152  if(hosten==NULL||hosten->h_name==NULL)
153  ret=E_UNKNOWN_HOST;
154  else if(strlen(hosten->h_name)>=len)
155  ret=E_SPACE;
156  else
157  {
158  strcpy((char*)buff,hosten->h_name);
159  ret=E_SUCCESS;
160  }
161  m_pcsGet->unlock();
162  return ret;
163  }
struct hostent HOSTENT
Definition: StdAfx.h:461
signed int SINT32
Definition: basetypedefs.h:132
SINT32 unlock()
Definition: CAMutex.hpp:52
SINT32 lock()
Definition: CAMutex.hpp:41
#define E_SPACE
Definition: errorcodes.hpp:7
#define E_UNKNOWN_HOST
Definition: errorcodes.hpp:18
#define E_UNSPECIFIED
Definition: errorcodes.hpp:6
UINT16 len
Definition: typedefs.hpp:0

References E_SPACE, E_SUCCESS, E_UNKNOWN_HOST, E_UNSPECIFIED, len, CAMutex::lock(), m_pcsGet, and CAMutex::unlock().

Referenced by CAAccountingBIInterface::initBIConnection().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getIP()

SINT32 CASocketAddrINet::getIP ( UINT8  buff[4]) const

Returns the IP-Numbers for this address.

Parameters
buffbuffer for the returned IP-Address (4 Bytes)
Return values
E_SUCCESSif no error occured

Definition at line 169 of file CASocketAddrINet.cpp.

170  {
171  memcpy(buff,&sin_addr.s_addr,4);
172  return E_SUCCESS;
173  }

References E_SUCCESS.

Referenced by getIPAsStr(), isAllowedToPassRestrictions(), and CALastMix::setTargets().

Here is the caller graph for this function:

◆ getIPAsStr()

SINT32 CASocketAddrINet::getIPAsStr ( UINT8 buff,
UINT32  len 
) const

Returns the IP-Number as an address string (doted-format).

Parameters
buffbuffer for the returned IP-Address
lenbuffer-space
Return values
E_SUCCESSif no error occured

Definition at line 190 of file CASocketAddrINet.cpp.

191  {
192  if(buff==NULL)
193  return E_UNKNOWN;
194  UINT8 ip[4];
195  if(getIP(ip)!=E_SUCCESS)
196  return E_UNKNOWN;
197  char* strAddr=inet_ntoa(sin_addr);
198  if(strAddr==NULL)
199  return E_UNKNOWN;
200  if(strlen(strAddr)>=len)
201  return E_UNKNOWN;
202  strcpy((char*)buff,strAddr);
203  return E_SUCCESS;
204  }
unsigned char UINT8
Definition: basetypedefs.h:135
SINT32 getIP(UINT8 buff[4]) const
Returns the IP-Numbers for this address.
#define E_UNKNOWN
Definition: errorcodes.hpp:3

References E_SUCCESS, E_UNKNOWN, getIP(), and len.

Referenced by CAInfoService::getPaymentInstance(), CAInfoService::sendCascadeHelo(), CAInfoService::sendMixHelo(), CAInfoService::sendStatus(), and toString().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getIPForString()

static SINT32 CASocketAddrINet::getIPForString ( UINT8 strIP,
UINT8  ip[4] 
)
inlinestatic

Definition at line 103 of file CASocketAddrINet.hpp.

104  {
105  in_addr addr;
106  SINT32 ret = inet_pton(AF_INET,(const char*)strIP,&addr); //is it a doted string (a.b.c.d) ?
107  if (ret!=1) //no..
108  {
109  return E_UNKNOWN;
110  }
111  UINT32 uAddr = ntohl(addr.s_addr);
112  ip[0] = (uAddr >> 24) & 0xFF;
113  ip[1] = (uAddr >> 16) & 0xFF;
114  ip[2] = (uAddr >> 8) & 0xFF;
115  ip[3] = (uAddr) & 0xFF;
116  return E_SUCCESS;
117  }
unsigned int UINT32
Definition: basetypedefs.h:131

References E_SUCCESS, and E_UNKNOWN.

◆ getLocalHostIP()

SINT32 CASocketAddrINet::getLocalHostIP ( UINT8  ip[4])
static

Returns the local IP-Address as four bytes.

Parameters
ipbuffer for the returned IP-Address
Return values
E_SUCCESSif no error occurs
E_UNKNOWNin case of an error

Definition at line 244 of file CASocketAddrINet.cpp.

245  {
246  SINT32 ret;
247  char buff[256];
248  m_pcsGet->lock();
249  if(gethostname(buff,256)==-1)
250  ret=E_UNKNOWN;
251  else
252  {
253  HOSTENT* hosten=gethostbyname((char*)buff);
254  if(hosten==NULL)
255  ret=E_UNKNOWN;
256  else
257  {
258  memcpy((char*)ip,hosten->h_addr_list[0],4);
259  ret=E_SUCCESS;
260  }
261  }
262  m_pcsGet->unlock();
263  return ret;
264  }

References E_SUCCESS, E_UNKNOWN, CAMutex::lock(), m_pcsGet, and CAMutex::unlock().

Here is the call graph for this function:

◆ getLocalHostName()

SINT32 CASocketAddrINet::getLocalHostName ( UINT8 buff,
UINT32  len 
)
static

Returns the name of the local host.

Parameters
buffbuffer for the returned zero terminated hostname
lenthe size of the buffer
Return values
E_SUCCESSif no error occured
E_UNKNOWN_HOSTif the name of the host could not be resolved
E_UNSPECIFIEDif buff was NULL
E_SPACEif size of the buffer is to small

Definition at line 214 of file CASocketAddrINet.cpp.

215  {
216  if(buff==NULL)
217  return E_UNSPECIFIED;
218  SINT32 ret;
219  m_pcsGet->lock();
220  if(gethostname((char*)buff,len)==-1)
221  ret=E_SPACE;
222  else
223  {
224  HOSTENT* hosten=gethostbyname((char*)buff);
225  if(hosten==NULL||hosten->h_name==NULL)
226  ret=E_UNKNOWN_HOST;
227  else if(strlen(hosten->h_name)>=len)
228  ret=E_SPACE;
229  else
230  {
231  strcpy((char*)buff,hosten->h_name);
232  ret=E_SUCCESS;
233  }
234  }
235  m_pcsGet->unlock();
236  return ret;
237  }

References E_SPACE, E_SUCCESS, E_UNKNOWN_HOST, E_UNSPECIFIED, len, CAMutex::lock(), m_pcsGet, and CAMutex::unlock().

Here is the call graph for this function:

◆ getPort()

UINT16 CASocketAddrINet::getPort ( ) const

Returns the port value of the address.

Returns
port

Definition at line 132 of file CASocketAddrINet.cpp.

133  {
134  return ntohs(sin_port);
135  }

Referenced by CAInfoService::getPaymentInstance(), CALocalProxy::init(), CAAccountingBIInterface::initBIConnection(), CAInfoService::sendCascadeHelo(), CAInfoService::sendMixHelo(), CAInfoService::sendStatus(), CALastMix::setTargets(), and toString().

Here is the caller graph for this function:

◆ getSize()

SINT32 CASocketAddrINet::getSize ( ) const
inlinevirtual

Returns the Size of the SOCKADDR struct used.

Returns
sizeof(sockaddr_in)

Implements CASocketAddr.

Definition at line 77 of file CASocketAddrINet.hpp.

78  {
79  return sizeof(sockaddr_in);
80  }

Referenced by CASocketAddrINet().

Here is the caller graph for this function:

◆ getType()

SINT32 CASocketAddrINet::getType ( ) const
inlinevirtual

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.

51  {
52  return AF_INET;
53  }

◆ init()

static SINT32 CASocketAddrINet::init ( )
inlinestatic

Definition at line 37 of file CASocketAddrINet.hpp.

38  {
39  m_pcsGet=new CAMutex();
40  return E_SUCCESS;
41  }

References E_SUCCESS, and m_pcsGet.

Referenced by CALibProxytest::init().

Here is the caller graph for this function:

◆ isAnyIP()

bool CASocketAddrINet::isAnyIP ( )
inline

Definition at line 89 of file CASocketAddrINet.hpp.

90  {
91  return sin_addr.s_addr==INADDR_ANY;
92  }

Referenced by CALocalProxy::init().

Here is the caller graph for this function:

◆ LPSOCKADDR()

const SOCKADDR* CASocketAddrINet::LPSOCKADDR ( ) const
inlinevirtual

Makes a cast to struct SOCKADDR*.

Implements CASocketAddr.

Definition at line 65 of file CASocketAddrINet.hpp.

66  {
67  #if defined(_WIN32) &&!defined(MSC_VER) //for Borland C++ under Windows
68  return (const ::LPSOCKADDR)(sockaddr_in*)this;
69  #else
70  return (const ::LPSOCKADDR)(static_cast<const sockaddr_in* const>(this));
71  #endif
72  }
SOCKADDR * LPSOCKADDR
Definition: StdAfx.h:459

Referenced by CASocketAddrINet().

Here is the caller graph for this function:

◆ setAddr()

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

Parameters
szIPnew value for IP-Address or hostname (zero terminated string)
portnew value for port
Return values
E_SUCCESSif no error occurs
E_UNKNOWN_HOSTif 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.

94  {
95  UINT32 newAddr=INADDR_ANY;
96  if(szIP!=NULL)
97  {
98  newAddr=inet_addr((const char*)szIP); //is it a doted string (a.b.c.d) ?
99  if(newAddr==INADDR_NONE) //if not try to find the hostname
100  {
101  m_pcsGet->lock();
102  HOSTENT* hostent=gethostbyname((const char*)szIP); //lookup
103  if(hostent!=NULL) //get it!
104  memcpy(&newAddr,hostent->h_addr_list[0],hostent->h_length);
105  else
106  {
107  m_pcsGet->unlock();
108  return E_UNKNOWN_HOST; //not found!
109  }
110  m_pcsGet->unlock();
111  }
112  }
113  sin_addr.s_addr=newAddr;
114  sin_port=htons(port);
115  return E_SUCCESS;
116  }
#define INADDR_NONE
Definition: StdAfx.h:479

References E_SUCCESS, E_UNKNOWN_HOST, INADDR_NONE, CAMutex::lock(), m_pcsGet, and CAMutex::unlock().

Referenced by CAInfoService::getPaymentInstance(), CALocalProxy::init(), and CAAccountingBIInterface::setPIServerConfiguration().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setIP()

SINT32 CASocketAddrINet::setIP ( UINT8  ip[4])

Sets the IP-Numbers for this address.

Parameters
ipbuffer with the IP-Address (4 Bytes)
Return values
E_SUCCESSif no error occured

Definition at line 179 of file CASocketAddrINet.cpp.

180  {
181  memcpy(&sin_addr.s_addr,ip,4);
182  return E_SUCCESS;
183  }

References E_SUCCESS.

◆ setPort()

SINT32 CASocketAddrINet::setPort ( UINT16  port)

Changes only(!) the port value of the address.

Parameters
portnew value for port
Returns
always E_SUCCESS

Definition at line 123 of file CASocketAddrINet.cpp.

124  {
125  sin_port=htons(port);
126  return E_SUCCESS;
127  }

References E_SUCCESS.

◆ toString()

virtual SINT32 CASocketAddrINet::toString ( UINT8 buff,
UINT32  bufflen 
) const
inlinevirtual

Returns a human readable representation of this address.

Parameters
buffbuffer which stores the address string
bufflensize of the buffer
Return values
E_SPACEif the buffer is to small
E_UNKNOWNif an error occured
E_SUCCESSif successfull

Implements CASocketAddr.

Definition at line 128 of file CASocketAddrINet.hpp.

129  {
130  UINT8 tmpbuff[255];
131  if(getIPAsStr(tmpbuff,255)!=E_SUCCESS)
132  return E_UNKNOWN;
133  if(snprintf((char*)buff,bufflen,"INet address: %s:%u",tmpbuff,getPort())<0)
134  return E_SPACE;
135  return E_SUCCESS;
136  }
SINT32 getIPAsStr(UINT8 *buff, UINT32 len) const
Returns the IP-Number as an address string (doted-format).
UINT16 getPort() const
Returns the port value of the address.

References E_SPACE, E_SUCCESS, E_UNKNOWN, getIPAsStr(), and getPort().

Here is the call graph for this function:

Member Data Documentation

◆ m_pcsGet

CAMutex * CASocketAddrINet::m_pcsGet =NULL
staticprivate

The documentation for this class was generated from the following files: