MLIB
|
sockaddr wrapper More...
#include <inaddr.h>
Public Member Functions | |
inaddr (unsigned long host=INADDR_ANY, unsigned short port=0) | |
Fill sockaddr structure with host number and port. | |
inaddr (const std::string &hostname, unsigned short port) | |
Fill sockaddr structure after resolving hostname. | |
inaddr (const std::string &hostname, const std::string &service, const std::string &proto=std::string()) | |
Fill sockaddr structure after resolving host and service names. | |
inaddr (const sockaddr &adr) | |
Construct from a sockaddr structure. | |
inaddr & | operator= (const inaddr &rhs) |
Assignment operator. | |
operator sockaddr * () const | |
convert to a pointer to sockaddr | |
bool | operator== (const inaddr &other) const |
Equality operator. | |
bool | operator!= (const inaddr &other) const |
Inequality operator. | |
operator const sockaddr & () const | |
convert to a reference to sockaddr (const variant) | |
operator sockaddr & () | |
convert to a reference to sockaddr (nonconst variant) | |
unsigned short | port () const |
return port number in host order | |
void | port (unsigned short p) |
set port number | |
erc | port (const std::string &service, const std::string &proto=std::string()) |
set port number based on well-known service ports | |
unsigned | host () const |
return host address in host order | |
void | host (unsigned int h) |
set host address | |
erc | host (const std::string &hostname) |
Set host address after resolving name. | |
std::string | hostname () const |
Find hostname from the host address in sockaddr. | |
const char * | ntoa () const |
return host address in dotted format | |
bool | is_multicast () const |
check if it's multicast host | |
Static Public Member Functions | |
static unsigned | localhost () |
Return local address in HOST order. | |
sockaddr wrapper
This is a wrapper for sockaddr structure, providing functions that go between host and network order.
All parameters and returned values are in host order.
mlib::inaddr::inaddr | ( | unsigned long | host = INADDR_ANY , |
unsigned short | port = 0 |
||
) |
Fill sockaddr structure with host number and port.
Parameters are in HOST order
mlib::inaddr::inaddr | ( | const std::string & | hostname, |
const std::string & | service, | ||
const std::string & | proto = std::string () |
||
) |
Fill sockaddr structure after resolving host and service names.
hostname | host name or IP address |
service | well-known service or port number |
proto | service protocol |
erc mlib::inaddr::port | ( | const std::string & | service, |
const std::string & | proto = std::string () |
||
) |
set port number based on well-known service ports
service | service name |
proto | protocol name |
The name
parameter can be either one of the well-known service names or a numeric port value. If it is a numeric value, the function converts it to a port number using the strtoul
function.