Trivial ::sockaddr structures enhanced with methods. More...
#include <sockaddr.hpp>
Public Member Functions | |
SSockaddr (const SSockaddr &) | |
Copy constructor, also needed for copy assignment operator. | |
SSockaddr & | operator= (SSockaddr) |
Copy assignment operator, needs user defined copy contructor. | |
bool | is_loopback () const |
Get if the socket address is a loopback address. | |
Setter | |
void | operator= (const std::string &a_addr_str) |
Set socket address from a netaddress. | |
void | operator= (const in_port_t a_port) |
Set port number from integer. | |
void | operator= (const ::sockaddr_storage &a_ss) |
Set socket address from a trivial socket address structure. | |
Getter | |
bool | operator== (const SSockaddr &) const |
Test if another socket address is logical equal to this. | |
const std::string | netaddr () noexcept |
Get the assosiated netaddress without port. | |
const std::string | netaddrp () noexcept |
Get the assosiated netaddress with port. | |
in_port_t | port () const |
Get the numeric port. | |
socklen_t | sizeof_saddr () const |
Get sizeof the current filled (sin6 or sin) Sockaddr Structure. | |
Public Attributes | |
sockaddr_storage & | ss = m_sa_union.ss |
Reference to sockaddr_storage struct. | |
sockaddr_un & | sun = m_sa_union.sun |
Reference to sockaddr_un struct. | |
sockaddr_in6 & | sin6 = m_sa_union.sin6 |
Reference to sockaddr_in6 struct. | |
sockaddr_in & | sin = m_sa_union.sin |
Reference to sockaddr_in struct. | |
sockaddr & | sa = m_sa_union.sa |
Reference to sockaddr struct. | |
Trivial ::sockaddr structures enhanced with methods.
This structure should be usable on a low level like the trival C struct ::sockaddr_storage
but provides additional methods to manage its data. When ever this SDK manage a network address it uses an object of this class.
Definition at line 94 of file sockaddr.hpp.
UPnPsdk::SSockaddr::SSockaddr | ( | ) |
Definition at line 349 of file sockaddr.cpp.
|
virtual |
Definition at line 354 of file sockaddr.cpp.
UPnPsdk::SSockaddr::SSockaddr | ( | const SSockaddr & | that | ) |
Copy constructor, also needed for copy assignment operator.
Definition at line 368 of file sockaddr.cpp.
Copy assignment operator, needs user defined copy contructor.
Definition at line 375 of file sockaddr.cpp.
void UPnPsdk::SSockaddr::operator= | ( | const std::string & | a_addr_str | ) |
Set socket address from a netaddress.
Assign rules are:
a netaddress consists of two parts, ip address and port. A netaddress has always a port. A cleared socket address is empty. On an empty socket address
SSockaddr::netaddr() returns "" (empty string)
SSockaddr::netaddrp() returns ":0"
Valid special cases are these well defined unspecified addresses:
"" results to ":0" ":0" results to ":0" "::" results to "[::]:0" "[::]" results to "[::]:0" "[::]:" results to "[::]:0" "[::]:0" results to "[::]:0" "[::]:65535" results to "[::]:65535" // port 0 to 65535 "0.0.0.0" results to "0.0.0.0:0" "0.0.0.0:" results to "0.0.0.0:0" "0.0.0.0:0" results to "0.0.0.0:0" "0.0.0.0:65535" results to "0.0.0.0:65535" // port 0 to 65535
A valid address with an invalid port results to port 0, for example
"[2001:db8::51]:98765" results to "[2001:db8::51]:0"
Setting only the port number does not modify the address part.
"[2001:db8::52]:50001" results to "[2001:db8::52]:50001" ":55555" results to "[2001:db8::52]:55555" (address prev setting)
std::invalid_argument | Invalid netaddress. |
[in] | a_addr_str | String with a possible netaddress |
Definition at line 385 of file sockaddr.cpp.
void UPnPsdk::SSockaddr::operator= | ( | const in_port_t | a_port | ) |
Set port number from integer.
Definition at line 447 of file sockaddr.cpp.
void UPnPsdk::SSockaddr::operator= | ( | const ::sockaddr_storage & | a_ss | ) |
Set socket address from a trivial socket address structure.
Definition at line 456 of file sockaddr.cpp.
bool UPnPsdk::SSockaddr::operator== | ( | const SSockaddr & | a_saddr | ) | const |
Test if another socket address is logical equal to this.
It only supports AF_INET6 and AF_INET. For all other address families false is returned.
Definition at line 462 of file sockaddr.cpp.
|
noexcept |
Get the assosiated netaddress without port.
Definition at line 469 of file sockaddr.cpp.
|
noexcept |
Get the assosiated netaddress with port.
Definition at line 519 of file sockaddr.cpp.
in_port_t UPnPsdk::SSockaddr::port | ( | ) | const |
Get the numeric port.
Definition at line 545 of file sockaddr.cpp.
socklen_t UPnPsdk::SSockaddr::sizeof_saddr | ( | ) | const |
Get sizeof the current filled (sin6 or sin) Sockaddr Structure.
Definition at line 555 of file sockaddr.cpp.
bool UPnPsdk::SSockaddr::is_loopback | ( | ) | const |
Get if the socket address is a loopback address.
Definition at line 571 of file sockaddr.cpp.
sockaddr_storage& UPnPsdk::SSockaddr::ss = m_sa_union.ss |
Reference to sockaddr_storage struct.
Definition at line 96 of file sockaddr.hpp.
sockaddr_un& UPnPsdk::SSockaddr::sun = m_sa_union.sun |
Reference to sockaddr_un struct.
Definition at line 98 of file sockaddr.hpp.
sockaddr_in6& UPnPsdk::SSockaddr::sin6 = m_sa_union.sin6 |
Reference to sockaddr_in6 struct.
Definition at line 100 of file sockaddr.hpp.
sockaddr_in& UPnPsdk::SSockaddr::sin = m_sa_union.sin |
Reference to sockaddr_in struct.
Definition at line 102 of file sockaddr.hpp.
sockaddr& UPnPsdk::SSockaddr::sa = m_sa_union.sa |
Reference to sockaddr struct.
Definition at line 104 of file sockaddr.hpp.