Jpp
Public Member Functions | Static Public Member Functions | List of all members
JNET::JSocketAddress Class Reference

The JSocketAddress class encapsulates the sockaddr_in data structure. More...

#include <JSocketAddress.hh>

Inheritance diagram for JNET::JSocketAddress:
JNET::JSocket JNET::JClient JNET::JServerSocket JNET::JSocketBlocking JNET::JSocketNonblockingReader JNET::JSocketNonblockingWriter JNET::JUDPSocket JNET::JControlHostServer JNET::JLigierObjectIterator< T > JNET::JControlHost KM3NETDAQ::JTarget JNET::JSocketInputChannel< JPrefix_t > JNET::JSocketOutputChannel< JPrefix_t > JNET::JControlHostObjectOutput< JHead_t > JNET::JControlHostObjectOutput< JTail_t > JLOGGER::JControlHostLogger JNET::JControlHostObjectIterator< T > JNET::JControlHostObjectOutput< T > JNET::JControlHostObjectOutput< JTypeList< JHead_t, JNullType > > JNET::JControlHostObjectOutput< JTypeList< JHead_t, JTail_t > > JNET::JControlHostObjectOutput< JTypeList< JHead_t, JTail_t > >

Public Member Functions

 JSocketAddress ()
 Default constructor. More...
 
const sockaddr * getSockaddr () const
 Get sockaddr. More...
 
sockaddr * getSockaddr ()
 Get sockaddr. More...
 
int getFamily () const
 Get family. More...
 
void setFamily (const int family)
 Set family. More...
 
std::string getHostname () const
 Get host name. More...
 
int getIPnumber () const
 Get IP number. More...
 
void setIPnumber (const int ip_number)
 Set IP number. More...
 
void setIPnumber ()
 Set any IP number. More...
 
int getPort () const
 Get port number. More...
 
void setPort (const int port)
 Set port number. More...
 

Static Public Member Functions

static int sizeOf ()
 Get size of object. More...
 

Detailed Description

The JSocketAddress class encapsulates the sockaddr_in data structure.

Definition at line 26 of file JSocketAddress.hh.

Constructor & Destructor Documentation

◆ JSocketAddress()

JNET::JSocketAddress::JSocketAddress ( )
inline

Default constructor.

Definition at line 33 of file JSocketAddress.hh.

34  {
35  bzero((char*) &(*this), sizeof(sockaddr_in));
36  }

Member Function Documentation

◆ getSockaddr() [1/2]

const sockaddr* JNET::JSocketAddress::getSockaddr ( ) const
inline

Get sockaddr.

Returns
pointer to sockaddr structure

Definition at line 44 of file JSocketAddress.hh.

45  {
46  return (const sockaddr*) static_cast<const sockaddr_in*>(this);
47  }

◆ getSockaddr() [2/2]

sockaddr* JNET::JSocketAddress::getSockaddr ( )
inline

Get sockaddr.

Returns
pointer to sockaddr structure

Definition at line 55 of file JSocketAddress.hh.

56  {
57  return (sockaddr*) static_cast<sockaddr_in*>(this);
58  }

◆ getFamily()

int JNET::JSocketAddress::getFamily ( ) const
inline

Get family.

Returns
family

Definition at line 66 of file JSocketAddress.hh.

67  {
68  return sin_family;
69  }

◆ setFamily()

void JNET::JSocketAddress::setFamily ( const int  family)
inline

Set family.

Parameters
familyfamily

Definition at line 77 of file JSocketAddress.hh.

78  {
79  sin_family = family;
80  }

◆ getHostname()

std::string JNET::JSocketAddress::getHostname ( ) const
inline

Get host name.

Returns
host name

Definition at line 88 of file JSocketAddress.hh.

89  {
90  return JSYSTEM::getHostname(this->getIPnumber());
91  }

◆ getIPnumber()

int JNET::JSocketAddress::getIPnumber ( ) const
inline

Get IP number.

Returns
IP number

Definition at line 99 of file JSocketAddress.hh.

100  {
101  return sin_addr.s_addr;
102  }

◆ setIPnumber() [1/2]

void JNET::JSocketAddress::setIPnumber ( const int  ip_number)
inline

Set IP number.

Parameters
ip_numberIP number

Definition at line 110 of file JSocketAddress.hh.

111  {
112  sin_addr.s_addr = ip_number;
113  }

◆ setIPnumber() [2/2]

void JNET::JSocketAddress::setIPnumber ( )
inline

Set any IP number.

Definition at line 119 of file JSocketAddress.hh.

120  {
121  sin_addr.s_addr = htonl(INADDR_ANY);
122  }

◆ getPort()

int JNET::JSocketAddress::getPort ( ) const
inline

Get port number.

Returns
port number

Definition at line 130 of file JSocketAddress.hh.

131  {
132  return ntohs(this->sin_port);
133  }

◆ setPort()

void JNET::JSocketAddress::setPort ( const int  port)
inline

Set port number.

Parameters
portport number

Definition at line 141 of file JSocketAddress.hh.

142  {
143  if (port >= 0 && port <= std::numeric_limits<u_short>::max())
144  sin_port = htons((u_short) port);
145  else
146  THROW(JCastException, "JSocketAddress::setPort() illegal value.");
147  }

◆ sizeOf()

static int JNET::JSocketAddress::sizeOf ( )
inlinestatic

Get size of object.

Returns
number of bytes

Definition at line 155 of file JSocketAddress.hh.

156  {
157  return sizeof(sockaddr_in);
158  }

The documentation for this class was generated from the following file:
THROW
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:670
JNET::JSocketAddress::getIPnumber
int getIPnumber() const
Get IP number.
Definition: JSocketAddress.hh:99
JSYSTEM::getHostname
std::string getHostname()
Get host name.
Definition: JNetwork.hh:77