Describes a IPv4 or IPv6 address in sockaddr_in(6) format, suitable in using with sendto.
More...
#include <socket_address.hpp>
|
| SocketAddress (uint32_t ip=0, uint16_t port=0) |
| IPv4 Constructor.
|
|
| SocketAddress (uint8_t b1, uint8_t b2, uint8_t b3, uint8_t b4, uint16_t port=0) |
| IPv4 Constructor (4 bytes).
|
|
| SocketAddress (const std::string &str, uint16_t port_number=0, short family=AF_UNSPEC) |
|
| SocketAddress (const ENetAddress &ea) |
| ENetAddress constructor.
|
|
bool | operator== (const SocketAddress &other) const |
| Compares if ip address and port are identical.
|
|
bool | operator!= (const SocketAddress &other) const |
| Compares if ip address and port are not identical.
|
|
void | init (const std::string &str, uint16_t port_number=0, short family=AF_UNSPEC) |
| String initialization (Can be IPv4, IPv6 or domain).
|
|
bool | isLAN () const |
| Returns if this IP address belongs to a LAN, i.e.
|
|
bool | isUnset () const |
|
void | clear () |
| Resets ip and port to 0.
|
|
uint32_t | getIP () const |
| Returns the IPv4 address in decimal, it will handle IPv4 mapped IPv6 address too.
|
|
uint16_t | getPort () const |
| Returns the port number.
|
|
void | setIP (uint32_t ip) |
| Sets the ip address.
|
|
void | setPort (uint16_t port) |
| Set the port.
|
|
std::string | toString (bool show_port=true) const |
|
sockaddr * | getSockaddr () const |
|
socklen_t | getSocklen () const |
|
void | setSockAddrIn (short family, sockaddr *new_sockaddr, socklen_t len) |
|
short | getFamily () const |
|
void | setIPv6 (const uint8_t *bytes, uint16_t port=0) |
|
bool | isPublicAddressLocalhost () const |
| Returns this IP address is localhost which its equal to any interface address.
|
|
bool | isIPv6 () const |
| Return true if this is an IPv6 address, if it's an IPv4 mapped IPv6 address it will return false (::ffff:x.y.x.w).
|
|
bool | isLoopback () const |
| Returns if this IP is loopback (ie for IPv4 127.0.0.0/8, IPv6 ::1/128)
|
|
void | convertForIPv6Socket (bool ipv6) |
|
ENetAddress | toENetAddress () const |
|
|
static bool | g_ignore_error_message = false |
|
|
std::array< char, sizeof(sockaddr_storage)> | m_sockaddr |
|
short | m_family |
|
Describes a IPv4 or IPv6 address in sockaddr_in(6) format, suitable in using with sendto.
◆ init()
void SocketAddress::init |
( |
const std::string & |
str, |
|
|
uint16_t |
port_number = 0 , |
|
|
short |
family = AF_UNSPEC |
|
) |
| |
String initialization (Can be IPv4, IPv6 or domain).
- Parameters
-
str | The address (can have a port with :) |
port_number | The port number, default is 0 or overwritten if specified in str |
family | AF_UNSPEC, AF_INET or AF_INET6 for example |
◆ isLAN()
bool SocketAddress::isLAN |
( |
| ) |
const |
Returns if this IP address belongs to a LAN, i.e.
is in 192.168* or 10*, 172.16-31.*, or is on the same host, i.e. 127*.
◆ unitTesting()
void SocketAddress::unitTesting |
( |
| ) |
|
|
static |
Unit testing.
Test various LAN patterns to verify that isLAN() works as expected.
The documentation for this class was generated from the following files: