Class to wrap the various POSIX sockaddrs and resolve hostnames.
#include <nrg_netaddress.h>
Public Member Functions | |
NetAddress () | |
Default constructor. | |
NetAddress (const char *name, const char *port) | |
Construct and resolve an address from IP/Hostname and Port/Service. | |
NetAddress (const struct sockaddr_in &in) | |
Implicitly construct from a IPv4 sockaddr_in. | |
NetAddress (const struct sockaddr_in6 &in6) | |
Implicitly construct from a IPv6 sockaddr_in6. | |
NetAddress (const struct sockaddr_storage &s) | |
Implicitly construct from a sockaddr_storage. | |
NetAddress (const struct sockaddr &s) | |
Implicitly construct from a generic sockaddr. | |
bool | resolve (const char *name, const char *port) |
Resolve the given IP/Hostname and Port/Service into an address, returning true on success. | |
bool | isValid () const |
Queries whether or not the contained address is valid. | |
const char * | getIP () const |
Returns the contained IP address as a string, if no address is contained it returns "" - do not free. | |
int | getFamily () const |
Returns the family of the contained address, (AF_INET, AF_INET6 or AF_UNSPEC) | |
uint16_t | getPort () const |
Returns the contained address' port as a short in host byte order. | |
const struct sockaddr * | toSockAddr (socklen_t &out_size) const |
Returns a sockaddr* representation of the NetAddress to be used with POSIX socket functions - do not free. | |
Friends | |
bool | operator== (const NetAddress &a, const NetAddress &b) |
Equality operator. | |
bool | operator!= (const NetAddress &a, const NetAddress &b) |
Unequality operator. | |
bool | operator< (const NetAddress &a, const NetAddress &b) |
Less-than operator for total-ordered containers like std::map. | |