#include <sockaddr.h>
Inheritance diagram for socklibpp::addr_in:
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 |
All the integer values handled by the class user are in host-byte-order.
enum socklibpp::addr::family [inherited] |
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.
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.
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.
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.
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] |
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.
str | A domain name to be resolved |
bool socklibpp::addr_in::resolve_port | ( | const std::string & | addrport | ) | throw () |
bool socklibpp::addr_in::resolve_port | ( | const std::string & | a, | |
uint16_t | p | |||
) | throw () |
bool socklibpp::addr_in::resolve_port | ( | const std::string & | a, | |
const std::string & | p | |||
) | throw () |
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.
port_ | A string representing a port number or a service name | |
proto_ | A string representing a protocol name where the given service is valid |
bool socklibpp::addr_in::port | ( | const std::string & | p | ) | throw () |
Set the port using a service name.
p | A string representing a port number or a service name |
void socklibpp::addr_in::ip | ( | uint32_t | host | ) | throw () |
Set the ip.
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.
addr_ | A string in the format "X.X.X.X" where "X" is a number in [0,255] |
bool socklibpp::addr_in::ip_port | ( | const std::string & | addr_, | |
uint16_t | port_ | |||
) | throw () |
bool socklibpp::addr_in::ip_port | ( | const std::string & | addrp | ) | throw () |
bool socklibpp::addr_in::ip_port | ( | const std::string & | addr_, | |
const std::string & | port_ | |||
) | throw () |
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.
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