socklibpp::addr_in Class Reference

Derived class for handling IPv4 addesses (including the port number). More...

#include <sockaddr.h>

Inheritance diagram for socklibpp::addr_in:

socklibpp::addr List of all members.

Public Types

enum  address { addr_any, addr_loopback, addr_broadcast, addr_none }
 Default IPv4 addresses. More...
enum  family {
  af_unspec, af_unix, af_inet, af_inet6,
  af_max
}
 Address families. More...

Public Member Functions

 addr_in () throw ()
 Default constructor.
 addr_in (address _addr, uint16_t _port) throw ()
 Constructor taking a default address and a port.
 addr_in (uint32_t _addr, uint16_t _port) throw ()
 Constructor taking an address and a port.
 addr_in (const std::string &, uint16_t) throw (std::invalid_argument)
 Constructor taking a string argument and a port.
 addr_in (const std::string &) throw (std::invalid_argument)
 Constructor taking a string argument.
bool resolve (const std::string &) throw ()
 Resolves a host name.
bool resolve_port (const std::string &) throw ()
 Convenience method that calls resolve() and port().
bool resolve_port (const std::string &, uint16_t) throw ()
 Convenience method that calls resolve() and port().
bool resolve_port (const std::string &, const std::string &) throw ()
 Convenience method that calls resolve() and port().
uint16_t port () const throw ()
 Get the port.
void port (uint16_t _port) throw ()
 Set the port.
bool port (const std::string &, const std::string &) throw ()
 Set the port using a service name and a protocol name.
bool port (const std::string &) throw ()
 Set the port using a service name.
uint32_t ip () const throw ()
 Get the ip.
void ip (uint32_t _host) throw ()
 Set the ip.
bool ip (const std::string &) throw ()
 Set the ip using a string.
bool ip_port (const std::string &, uint16_t) throw ()
 Convenience method that wraps ip() and port().
bool ip_port (const std::string &) throw ()
 Convenience method that wraps ip() and port().
bool ip_port (const std::string &, const std::string &) throw ()
 Convenience method that wraps ip() and port().
std::string ip_str () const
 Returns a string representation of the ip only.

Static Public Member Functions

static bool validate_addr (const std::string &) throw ()
 Validates a string to see if has the correct "X.X.X.X" format.
static bool validate_addr_port (const std::string &) throw ()
 Validates a string to see if has the correct "X.X.X.X:P" format.

Protected Member Functions

virtual void reset () throw ()
 Resets the internal size to the correct value.
sockaddr * data ()
 Returns a pointer to the sockaddr representation.
sockaddr * data () const
 Returns a read-only pointer to the sockaddr representation.
int size () const
 Returns the size of the sockaddr representation.
void size (int _size)
 Sets the size of the sockaddr representation.

Protected Attributes

int _M_size
 Holds the data size.

Friends

std::ostream & operator<< (std::ostream &, const addr_in &)
 Operator for printing an address in a stream.
std::istream & operator>> (std::istream &, addr_in &)
 Operator for reading an address from a stream.
class sock

Detailed Description

Derived class for handling IPv4 addesses (including the port number).

All the integer values handled by the class user are in host-byte-order.

Examples:

daytimed.cpp, echod.cpp, listener.cpp, and streamechod.cpp.


Member Enumeration Documentation

enum socklibpp::addr_in::address

Default IPv4 addresses.

Enumerator:
addr_any  Any.
addr_loopback  Loopback.
addr_broadcast  Broadcast.
addr_none  None.

enum socklibpp::addr::family [inherited]

Address families.

Enumerator:
af_unspec  Unspecified.
af_unix  Unix (pipes).
af_inet  IPv4.
af_inet6  IPv6.
af_max  not used


Constructor & Destructor Documentation

socklibpp::addr_in::addr_in (  )  throw ()

Default constructor.

Initializes the family to sock_addr_in::af_inet, the port to 0, and the address to sock_addr_in::addr_none.

socklibpp::addr_in::addr_in ( address  addr_,
uint16_t  port_ 
) throw ()

Constructor taking a default address and a port.

Parameters:
addr_ A default IPv4 address
port_ A 16-bit IPv4 port

socklibpp::addr_in::addr_in ( uint32_t  addr_,
uint16_t  port_ 
) throw ()

Constructor taking an address and a port.

Parameters:
addr_ A 32-bit IPv4 address, in host-byte-order
port_ A 16-bit IPv4 port, in host-byte-order

socklibpp::addr_in::addr_in ( const std::string &  str_,
uint16_t  port_ 
) throw (std::invalid_argument)

Constructor taking a string argument and a port.

Parameters:
str_ A string in the format "X.X.X.X", where "X" is an integer in [0,255]
port_ A 16-bit IPv4 port

socklibpp::addr_in::addr_in ( const std::string &  str_  )  throw (std::invalid_argument)

Constructor taking a string argument.

Parameters:
str_ A string in the format "X.X.X.X:P", where "X" is an integer in [0,255] and "P" is an integer in [0,65535]


Member Function Documentation

bool socklibpp::addr_in::resolve ( const std::string &  str  )  throw ()

Resolves a host name.

This is thread safe; you can call the resolve() method from multiple threads without problems.

Parameters:
str A domain name to be resolved
Returns:
true if the name was resolved successfully
Note:
This method blocks until the resolving operation is done.

bool socklibpp::addr_in::resolve_port ( const std::string &  addrport  )  throw ()

Convenience method that calls resolve() and port().

Parameters:
addrport A string in the format "name:port", where port is in [0,65535]
Returns:
true if the name was resolved successfully and the port is valid
Note:
This method blocks until the resolving operation is done.
See also:
resolve(), port()

bool socklibpp::addr_in::resolve_port ( const std::string &  a,
uint16_t  p 
) throw ()

Convenience method that calls resolve() and port().

Parameters:
a A string with the domain name to be resolved
p A 16-bit IPv4 port
Returns:
true if the name was resolved successfully
Note:
This method blocks until the resolving operation is done.
See also:
resolve(), port()

bool socklibpp::addr_in::resolve_port ( const std::string &  a,
const std::string &  p 
) throw ()

Convenience method that calls resolve() and port().

Parameters:
a A string with the domain name to be resolved
p A string representing the port
Returns:
true if the name was resolved successfully and the port is valid
Note:
This method blocks until the resolving operation is done.
See also:
resolve(), port()

bool socklibpp::addr_in::port ( const std::string &  port_,
const std::string &  proto_ 
) throw ()

Set the port using a service name and a protocol name.

Parameters:
port_ A string representing a port number or a service name
proto_ A string representing a protocol name where the given service is valid
Returns:
true if the operatin was successful

bool socklibpp::addr_in::port ( const std::string &  p  )  throw ()

Set the port using a service name.

Parameters:
p A string representing a port number or a service name
Returns:
true if the operation ws successful

void socklibpp::addr_in::ip ( uint32_t  host  )  throw ()

Set the ip.

Parameters:
host A 32-bit unsigned integer representing the ip, in host-byte order.

bool socklibpp::addr_in::ip ( const std::string &  addr_  )  throw ()

Set the ip using a string.

Parameters:
addr_ A string in the format "X.X.X.X" where "X" is a number in [0,255]
Returns:
true if the string is valid

bool socklibpp::addr_in::ip_port ( const std::string &  addr_,
uint16_t  port_ 
) throw ()

Convenience method that wraps ip() and port().

Parameters:
addr_ A string in the format "X.X.X.X" where "X" is a number in [0,255]
port_ A 16-bit port
Returns:
true if the string is valid
See also:
ip(), port()

bool socklibpp::addr_in::ip_port ( const std::string &  addrp  )  throw ()

Convenience method that wraps ip() and port().

Parameters:
addrp A string in the format "X.X.X.X:P" where "X" is a number in [0,255] and "P" is a number in [0,65535]
Returns:
true if the string is valid
See also:
ip(), port()

bool socklibpp::addr_in::ip_port ( const std::string &  addr_,
const std::string &  port_ 
) throw ()

Convenience method that wraps ip() and port().

Parameters:
addr_ A string in the format "X.X.X.X" where "X" is a number in [0,255]
port_ A string representing the port
Returns:
true if the address and the port are valid
See also:
ip(), port()

string socklibpp::addr_in::ip_str (  )  const

Returns a string representation of the ip only.

Returns a string in the format X.Y.Z.W. Notice that it doesn't include the port.


Friends And Related Function Documentation

std::ostream& operator<< ( std::ostream &  os,
const addr_in si 
) [friend]

Operator for printing an address in a stream.

Converts a addr_in object in a string representation, in the form: X.Y.Z.W:P

std::istream& operator>> ( std::istream &  is,
addr_in sai 
) [friend]

Operator for reading an address from a stream.

Reads a addr_in object from a string representation, in the form: X.Y.Z.W:P


The documentation for this class was generated from the following files:
Generated on Thu Jan 18 19:26:35 2007 for socklib++ by  doxygen 1.5.1