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

#include <CADatagramSocket.hpp>

Collaboration diagram for CADatagramSocket:

Public Member Functions

 CADatagramSocket ()
 
 ~CADatagramSocket ()
 
SINT32 create ()
 
SINT32 create (int type)
 
SINT32 close ()
 
SINT32 bind (CASocketAddr &psa)
 
SINT32 bind (UINT16 port)
 
SINT32 send (UINT8 *buff, UINT32 len, CASocketAddr &to)
 
SINT32 receive (UINT8 *buff, UINT32 len, CASocketAddr *from)
 
SOCKET getSocket ()
 

Private Attributes

SOCKET m_Socket
 

Detailed Description

Definition at line 33 of file CADatagramSocket.hpp.

Constructor & Destructor Documentation

◆ CADatagramSocket()

CADatagramSocket::CADatagramSocket ( )

Definition at line 38 of file CADatagramSocket.cpp.

39  {
40  m_Socket=0;
41 // localPort=-1;
42  }

References m_Socket.

◆ ~CADatagramSocket()

CADatagramSocket::~CADatagramSocket ( )
inline

Definition at line 37 of file CADatagramSocket.hpp.

37 {close();}

References close().

Here is the call graph for this function:

Member Function Documentation

◆ bind() [1/2]

SINT32 CADatagramSocket::bind ( CASocketAddr psa)

Definition at line 86 of file CADatagramSocket.cpp.

87  {
88 // localPort=-1;
89  if(m_Socket==0&&create(from.getType())!=E_SUCCESS)
90  return SOCKET_ERROR;
91  if(::bind(m_Socket,from.LPSOCKADDR(),from.getSize())==SOCKET_ERROR)
92  return SOCKET_ERROR;
93  return E_SUCCESS;
94  }
#define SOCKET_ERROR
Definition: StdAfx.h:464
SINT32 bind(CASocketAddr &psa)
const SINT32 E_SUCCESS
Definition: errorcodes.hpp:2

References create(), E_SUCCESS, CASocketAddr::getSize(), CASocketAddr::getType(), CASocketAddr::LPSOCKADDR(), m_Socket, and SOCKET_ERROR.

Referenced by bind().

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

◆ bind() [2/2]

SINT32 CADatagramSocket::bind ( UINT16  port)

Definition at line 96 of file CADatagramSocket.cpp.

97  {
98  CASocketAddrINet oSocketAddr(port);
99  return bind(oSocketAddr);
100  }
This class represents a socket address for Internet (IP) connections.

References bind().

Here is the call graph for this function:

◆ close()

SINT32 CADatagramSocket::close ( )

Definition at line 60 of file CADatagramSocket.cpp.

61  {
62 // EnterCriticalSection(&csClose);
63 // localPort=-1;
64  int ret;
65  if(m_Socket!=0)
66  {
67  /* LINGER linger;
68  linger.l_onoff=1;
69  linger.l_linger=0;
70  if(::setsockopt(m_Socket,SOL_SOCKET,SO_LINGER,(char*)&linger,sizeof(linger))!=0)
71  CAMsg::printMsg(LOG_DEBUG,"Fehler bei setsockopt - LINGER!\n");
73 #ifdef _DEBUG
74  sockets--;
75 #endif
76  m_Socket=0;
77  ret=0;
78  }
79  else
80  ret=SOCKET_ERROR;
81 // LeaveCriticalSection(&csClose);
82  return ret;
83  }
#define closesocket(s)
Definition: StdAfx.h:463

References closesocket, m_Socket, and SOCKET_ERROR.

Referenced by ~CADatagramSocket().

Here is the caller graph for this function:

◆ create() [1/2]

SINT32 CADatagramSocket::create ( )

Definition at line 44 of file CADatagramSocket.cpp.

45  {
46  return create(AF_INET);
47  }

Referenced by bind().

Here is the caller graph for this function:

◆ create() [2/2]

SINT32 CADatagramSocket::create ( int  type)

Definition at line 50 of file CADatagramSocket.cpp.

51  {
52  if(m_Socket==0)
53  m_Socket=::socket(type,SOCK_DGRAM,0);
55  return SOCKET_ERROR;
56 // localPort=-1;
57  return E_SUCCESS;
58  }
#define INVALID_SOCKET
Definition: StdAfx.h:465
UINT8 type
Definition: typedefs.hpp:1

References E_SUCCESS, INVALID_SOCKET, m_Socket, SOCKET_ERROR, and type.

◆ getSocket()

SOCKET CADatagramSocket::getSocket ( )
inline

Definition at line 47 of file CADatagramSocket.hpp.

47 {return m_Socket;}

References m_Socket.

◆ receive()

SINT32 CADatagramSocket::receive ( UINT8 buff,
UINT32  len,
CASocketAddr from 
)

Definition at line 110 of file CADatagramSocket.cpp.

111  {
112  int ret;
113  if(from!=NULL)
114  {
115  socklen_t fromlen=from->getSize();
116  ret=::recvfrom(m_Socket,(char*)buff,len,MSG_NOSIGNAL,(LPSOCKADDR)from->LPSOCKADDR(),&fromlen);
117  }
118  else
119  {
120  ret=::recv(m_Socket,(char*)buff,len,MSG_NOSIGNAL);
121  }
122  return ret;
123  }
SOCKADDR * LPSOCKADDR
Definition: StdAfx.h:459
int socklen_t
Definition: StdAfx.h:393
#define MSG_NOSIGNAL
Definition: StdAfx.h:408
virtual const SOCKADDR * LPSOCKADDR() const =0
Casts to a SOCKADDR struct.
virtual SINT32 getSize() const =0
The size of the SOCKADDR struct needed by function of CASocket and other.
UINT16 len
Definition: typedefs.hpp:0

References CASocketAddr::getSize(), len, CASocketAddr::LPSOCKADDR(), m_Socket, and MSG_NOSIGNAL.

Here is the call graph for this function:

◆ send()

SINT32 CADatagramSocket::send ( UINT8 buff,
UINT32  len,
CASocketAddr to 
)

Definition at line 102 of file CADatagramSocket.cpp.

103  {
104  if(::sendto(m_Socket,(char*)buff,len,MSG_NOSIGNAL,to.LPSOCKADDR(),to.getSize())==SOCKET_ERROR)
105  return E_UNKNOWN;
106  return E_SUCCESS;
107  }
#define E_UNKNOWN
Definition: errorcodes.hpp:3

References E_SUCCESS, E_UNKNOWN, CASocketAddr::getSize(), len, CASocketAddr::LPSOCKADDR(), m_Socket, MSG_NOSIGNAL, and SOCKET_ERROR.

Here is the call graph for this function:

Member Data Documentation

◆ m_Socket

SOCKET CADatagramSocket::m_Socket
private

Definition at line 56 of file CADatagramSocket.hpp.

Referenced by bind(), CADatagramSocket(), close(), create(), getSocket(), receive(), and send().


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