nidas v1.2.3
Public Member Functions | Protected Attributes | List of all members
nidas::util::Inet4SocketAddress Class Reference

A IP version 4 socket address, containing a host address, and a port number. More...

#include <Inet4SocketAddress.h>

Inheritance diagram for nidas::util::Inet4SocketAddress:
Inheritance graph
[legend]

Public Member Functions

 Inet4SocketAddress ()
 Default constructor, address of 0.0.0.0 (INADDR_ANY), port 0.
 
 Inet4SocketAddress (int port)
 Address of 0.0.0.0 (INADDR_ANY), with a given port number.
 
 Inet4SocketAddress (const Inet4Address &, int port)
 
 Inet4SocketAddress (const struct sockaddr_in *_sockaddr)
 
 Inet4SocketAddress (const Inet4SocketAddress &)
 Copy constructor.
 
Inet4SocketAddressoperator= (const Inet4SocketAddress &x)
 Assignment operator.
 
Inet4SocketAddressclone () const
 Virtual constructor.
 
int getFamily () const
 Return the address family, AF_INET.
 
int getPort () const
 Return the port number.
 
void setPort (int val)
 Set the port number.
 
Inet4Address getInet4Address () const
 Return the IP address portion.
 
struct sockaddr * getSockAddrPtr ()
 Provide non-const pointer to struct sockaddr_in.
 
const struct sockaddr * getConstSockAddrPtr () const
 Provide const pointer to struct sockaddr_in.
 
socklen_t getSockAddrLen () const
 Return the length of the struct sockaddr_XX for this address family.
 
std::string toString () const
 Java style toString: returns "inet:hostname:port".
 
std::string toAddressString () const
 Java style toString, but no DNS lookup: returns "inet:w.x.y.z:port".
 
bool operator< (const Inet4SocketAddress &x) const
 Comparator operator for addresses.
 
bool operator== (const Inet4SocketAddress &x) const
 Equality operator for addresses.
 

Protected Attributes

struct sockaddr_in _sockaddr
 

Detailed Description

A IP version 4 socket address, containing a host address, and a port number.

The only data element is a struct sockaddr_in, so the default copy constructor and assignment operators work fine.

Constructor & Destructor Documentation

◆ Inet4SocketAddress() [1/5]

Inet4SocketAddress::Inet4SocketAddress ( )

Default constructor, address of 0.0.0.0 (INADDR_ANY), port 0.

References _sockaddr.

Referenced by clone().

◆ Inet4SocketAddress() [2/5]

Inet4SocketAddress::Inet4SocketAddress ( int port)

Address of 0.0.0.0 (INADDR_ANY), with a given port number.

References _sockaddr, and port.

◆ Inet4SocketAddress() [3/5]

Inet4SocketAddress::Inet4SocketAddress ( const Inet4Address & addr,
int port )

◆ Inet4SocketAddress() [4/5]

Inet4SocketAddress::Inet4SocketAddress ( const struct sockaddr_in * _sockaddr)

◆ Inet4SocketAddress() [5/5]

Inet4SocketAddress::Inet4SocketAddress ( const Inet4SocketAddress & x)

Copy constructor.

Member Function Documentation

◆ clone()

Inet4SocketAddress * Inet4SocketAddress::clone ( ) const
virtual

Virtual constructor.

Implements nidas::util::SocketAddress.

References Inet4SocketAddress().

◆ getConstSockAddrPtr()

const struct sockaddr * nidas::util::Inet4SocketAddress::getConstSockAddrPtr ( ) const
inlinevirtual

Provide const pointer to struct sockaddr_in.

Implements nidas::util::SocketAddress.

References _sockaddr.

◆ getFamily()

int nidas::util::Inet4SocketAddress::getFamily ( ) const
inlinevirtual

Return the address family, AF_INET.

Implements nidas::util::SocketAddress.

References _sockaddr.

◆ getInet4Address()

Inet4Address nidas::util::Inet4SocketAddress::getInet4Address ( ) const
inline

Return the IP address portion.

References _sockaddr.

Referenced by nidas::core::Socket::connect(), nidas::util::McSocketListener::run(), toAddressString(), and toString().

◆ getPort()

int nidas::util::Inet4SocketAddress::getPort ( ) const
inlinevirtual

Return the port number.

Implements nidas::util::SocketAddress.

References _sockaddr.

Referenced by nidas::util::McSocketListener::run(), toAddressString(), and toString().

◆ getSockAddrLen()

socklen_t nidas::util::Inet4SocketAddress::getSockAddrLen ( ) const
inlinevirtual

Return the length of the struct sockaddr_XX for this address family.

Implements nidas::util::SocketAddress.

References _sockaddr.

◆ getSockAddrPtr()

struct sockaddr * nidas::util::Inet4SocketAddress::getSockAddrPtr ( )
inlinevirtual

Provide non-const pointer to struct sockaddr_in.

This is needed for recvfrom methods. recvfrom updates the struct sockaddr_in, so we can't cache the other portions of the address.

Implements nidas::util::SocketAddress.

References _sockaddr.

◆ operator<()

bool Inet4SocketAddress::operator< ( const Inet4SocketAddress & x) const

Comparator operator for addresses.

Useful if this address is a key in an STL map.

References _sockaddr.

◆ operator=()

Inet4SocketAddress & Inet4SocketAddress::operator= ( const Inet4SocketAddress & x)

Assignment operator.

References _sockaddr.

◆ operator==()

bool Inet4SocketAddress::operator== ( const Inet4SocketAddress & x) const

Equality operator for addresses.

References _sockaddr.

◆ setPort()

void nidas::util::Inet4SocketAddress::setPort ( int val)
inline

Set the port number.

References _sockaddr.

Referenced by nidas::dynld::UDPSampleOutput::ConnectionMonitor::addDestination().

◆ toAddressString()

std::string Inet4SocketAddress::toAddressString ( ) const
virtual

Java style toString, but no DNS lookup: returns "inet:w.x.y.z:port".

Implements nidas::util::SocketAddress.

References nidas::util::Inet4Address::getHostAddress(), getInet4Address(), and getPort().

Referenced by nidas::core::StatusListener::run().

◆ toString()

std::string Inet4SocketAddress::toString ( ) const
virtual

Java style toString: returns "inet:hostname:port".

Implements nidas::util::SocketAddress.

References nidas::util::Inet4Address::getHostName(), getInet4Address(), and getPort().

Referenced by nidas::util::McSocketListener::run().

Member Data Documentation

◆ _sockaddr

struct sockaddr_in nidas::util::Inet4SocketAddress::_sockaddr
protected

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