libBsdSockets
C++ Wrapper classes to the BSD Socket API
BsdSockets::InetAddress Class Reference

Internet Address Class supporting IPv4 and IPv6 and creatable from hostnames and service names. More...

#include <InetAddress.h>

Inheritance diagram for BsdSockets::InetAddress:
Collaboration diagram for BsdSockets::InetAddress:

Public Types

typedef std::shared_ptr< InetAddressPtr
 
- Public Types inherited from BsdSockets::Address
typedef std::shared_ptr< AddressPtr
 

Public Member Functions

virtual ~InetAddress ()
 
const std::string & getRequestedAddress () const
 
const std::string & getActualAddress () const
 
const std::string & getServiceName () const
 
const unsigned int getPort () const
 
virtual std::shared_ptr< LowLevelAddressmakeTempLowLevelAddress () const
 
virtual Address::Ptr create (std::shared_ptr< LowLevelAddress > lowLevelAddress) const
 
virtual LowLevelAddressgetLowLevelAddress () const
 
- Public Member Functions inherited from BsdSockets::Address
virtual ~Address ()
 
SocketDomain getSocketDomain () const
 
SocketType getSocketType () const
 
int getProtocol () const
 

Static Public Member Functions

static int create (SocketType socketType, const std::string &serviceName, const std::string &address, std::vector< InetAddress::Ptr > &created, unsigned int max=0)
 
static InetAddress::Ptr create (SocketType socketType, const std::string &serviceName, const std::string &address="")
 

Additional Inherited Members

- Protected Member Functions inherited from BsdSockets::Address
 Address (SocketDomain theSocketDomain, SocketType theSocketType, int theProtocol)
 
 Address (const Address &rhs)
 

Detailed Description

Internet Address Class supporting IPv4 and IPv6 and creatable from hostnames and service names.

Most users will create addresses with a hostname and either a service name or port number. This supports that with ease. Additionally, create() can accept a std::vector<InetAddress> to put all matching Addresses into. For example, some hostnames are served by multiple IP addresses to load balance. The caller can use create() to either return the first match or populate a std::vector<InetAddress> with all matches.

Definition at line 41 of file InetAddress.h.

Member Typedef Documentation

◆ Ptr

Constructor & Destructor Documentation

◆ ~InetAddress()

BsdSockets::InetAddress::~InetAddress ( )
virtual

Virtual destructor to support derived classes

Definition at line 169 of file InetAddress.cpp.

Member Function Documentation

◆ create() [1/3]

int BsdSockets::InetAddress::create ( SocketType  socketType,
const std::string &  serviceName,
const std::string &  address,
std::vector< InetAddress::Ptr > &  created,
unsigned int  max = 0 
)
static

Create an address with the given parameters putting all matches into created.

Note
Either of address or serviceName may be empty, but not both.
Parameters
socketTypethe SocketType of the Address
serviceNamename of standard service or port number desired, may be empty if address is not
addressdesired, may be empty if serviceName is not empty
[out]createdthe container to add created Addresses to
maxthe limit on the count of Addresses to match, 0 means unlimited matches
Returns
count of Addresses added to created
Examples
ClientSocketExamples.cpp, CommandServerExample.cpp, EchoServerExample.cpp, InetAddressExamples.cpp, and ServerSocketExamples.cpp.

Definition at line 116 of file InetAddress.cpp.

◆ create() [2/3]

InetAddress::Ptr BsdSockets::InetAddress::create ( SocketType  socketType,
const std::string &  serviceName,
const std::string &  address = "" 
)
static

Create one address with the given parameters.

This is a convenience method equivalent to:

std::vector<InetAddress> found;
InetAddress::create(type, address, serviceName, found, 1);
return created.at(0);
static int create(SocketType socketType, const std::string &serviceName, const std::string &address, std::vector< InetAddress::Ptr > &created, unsigned int max=0)
Note
Either of address or serviceName may be empty, but not both.
Parameters
socketTypethe SocketType of the Address
serviceNamename of standard service or port number desired, may be empty if address is not
addressdesired, may be empty if serviceName is not empty
Returns
InetAddress created from first match of address and serviceName

Definition at line 162 of file InetAddress.cpp.

◆ create() [3/3]

Address::Ptr BsdSockets::InetAddress::create ( std::shared_ptr< LowLevelAddress lowLevelAddress) const
virtual

Create a new Address from a LowLevelAddress using this Address as a template.

Parameters
lowLevelAddressdata to create from
Returns
Address created

Implements BsdSockets::Address.

Definition at line 206 of file InetAddress.cpp.

◆ getActualAddress()

const std::string & BsdSockets::InetAddress::getActualAddress ( ) const
Returns
the computed string address that was actually created.
Note
This may be an IP if a hostname was requested, etc.

Definition at line 190 of file InetAddress.cpp.

◆ getLowLevelAddress()

LowLevelAddress & BsdSockets::InetAddress::getLowLevelAddress ( ) const
virtual

Method for derived classes to provide access to the LowLevelAddress information

Implements BsdSockets::Address.

Definition at line 221 of file InetAddress.cpp.

◆ getPort()

const unsigned int BsdSockets::InetAddress::getPort ( ) const
Returns
the actual port associated with this address

Definition at line 198 of file InetAddress.cpp.

◆ getRequestedAddress()

const std::string & BsdSockets::InetAddress::getRequestedAddress ( ) const
Returns
the string address used to create this

Definition at line 186 of file InetAddress.cpp.

◆ getServiceName()

const std::string & BsdSockets::InetAddress::getServiceName ( ) const
Returns
the service name or port number requested for this address may be blank

Definition at line 194 of file InetAddress.cpp.

◆ makeTempLowLevelAddress()

LowLevelAddress::Ptr BsdSockets::InetAddress::makeTempLowLevelAddress ( ) const
virtual
Returns
a LowLevelAddress suitable for create()

Implements BsdSockets::Address.

Definition at line 202 of file InetAddress.cpp.


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