| Yate
    | 
A socket address holder. More...
#include <yateclass.h>
 
  
| Public Types | |
| enum | Family { Unknown = AF_UNSPEC , IPv4 = AF_INET , AfMax = AF_MAX , AfUnsupported = AfMax , IPv6 = AF_INET6 , IPv6 = AF_INET6 , Unix = AF_UNIX , Unix = AF_UNIX } | 
| Public Member Functions | |
| SocketAddr () | |
| SocketAddr (const SocketAddr &value) | |
| SocketAddr (int family, const void *raw=0) | |
| SocketAddr (const struct sockaddr *addr, socklen_t len=0) | |
| virtual | ~SocketAddr () | 
| SocketAddr & | operator= (const SocketAddr &value) | 
| bool | operator== (const SocketAddr &other) const | 
| bool | operator!= (const SocketAddr &other) const | 
| void | clear () | 
| bool | assign (int family) | 
| void | assign (const struct sockaddr *addr, socklen_t len=0) | 
| bool | assign (const DataBlock &addr) | 
| bool | local (const SocketAddr &remote) | 
| bool | valid () const | 
| bool | null () const | 
| int | family () const | 
| const char * | familyName () const | 
| unsigned int | scopeId () const | 
| bool | scopeId (unsigned int val) | 
| const String & | host () const | 
| const String & | addr (bool full=false) const | 
| const String & | iface () const | 
| bool | iface (const char *name, bool uriUnescape=false) | 
| virtual bool | host (const String &name) | 
| int | port () const | 
| bool | port (int newport) | 
| struct sockaddr * | address () const | 
| socklen_t | length () const | 
| bool | isNullAddr () const | 
| int | copyAddr (DataBlock &addr) const | 
|  Public Member Functions inherited from GenObject | |
| GenObject () | |
| virtual | ~GenObject () | 
| virtual bool | alive () const | 
| virtual void | destruct () | 
| virtual const String & | toString () const | 
| virtual const String & | traceId () const | 
| virtual void * | getObject (const String &name) const | 
| NamedCounter * | getObjCounter () const | 
| NamedCounter * | setObjCounter (NamedCounter *counter) | 
| Static Public Member Functions | |
| static bool | supports (int family) | 
| static int | family (const String &addr) | 
| static bool | stringify (String &buf, struct sockaddr *addr) | 
| static int | unStringify (uint8_t *buf, const String &host, int family=Unknown) | 
| static int | copyAddr (uint8_t *buf, struct sockaddr *addr) | 
| static unsigned int | scopeId (struct sockaddr *addr) | 
| static bool | scopeId (struct sockaddr *addr, unsigned int val) | 
| static String & | appendAddr (String &buf, const String &addr, int family=Unknown, const String &iface=String::empty()) | 
| static String & | appendTo (String &buf, const String &addr, int port, int family=Unknown, const String &iface=String::empty()) | 
| static String | appendTo (const String &addr, int port, int family=Unknown, const String &iface=String::empty()) | 
| static bool | isNullAddr (const String &addr, int family=Unknown) | 
| static void | splitIface (const String &buf, String &addr, String *iface=0) | 
| static void | split (const String &buf, String &addr, int &port, bool portPresent=false) | 
| static const char * | lookupFamily (int family) | 
| static const String & | ipv4NullAddr () | 
| static const String & | ipv6NullAddr () | 
| static const TokenDict * | dictFamilyName () | 
| static const char * | ifaceNameExtraEscape () | 
| static String & | escapeIface (String &buf, const char *name) | 
|  Static Public Member Functions inherited from GenObject | |
| static void * | getObject (const String &name, const GenObject *obj) | 
| static bool | getObjCounting () | 
| static void | setObjCounting (bool enable) | 
| static NamedCounter * | getObjCounter (const String &name, bool create=true) | 
| static ObjList & | getObjCounters () | 
| Protected Member Functions | |
| virtual void | stringify () | 
| virtual void | updateAddr (bool full=false) const | 
| Protected Attributes | |
| struct sockaddr * | m_address | 
| socklen_t | m_length | 
| String | m_host | 
| String | m_iface | 
| String | m_addr | 
| String | m_addrFull | 
A socket address holder.
Wrapper class to keep a socket address
| enum Family | 
Known address families
| 
 | inline | 
Default constructor of an empty address
| 
 | inline | 
| 
 | explicit | 
Constructor of a null address
| family | Family of the address to create | 
| raw | Raw address data | 
| SocketAddr | ( | const struct sockaddr * | addr, | 
| socklen_t | len = 0 ) | 
Constructor that stores a copy of an address
| addr | Pointer to the address to store | 
| len | Length of the stored address, zero to use default | 
| 
 | virtual | 
Destructor that frees and zeroes out everything
| 
 | inline | 
Get the host and port of this address
| full | Retrieve the full address, interface included | 
| 
 | inline | 
Get the contained socket address
Referenced by Socket::bind(), Socket::connect(), Socket::connectAsync(), operator=(), Socket::sendTo(), SocketAddr(), and unStringify().
| 
 | static | 
Append an address to a buffer
| buf | Destination buffer | 
| addr | Address to append | 
| family | Address family, set it to Unknown to detect | 
| iface | Optional interface name | 
| 
 | inlinestatic | 
Append an address to a buffer in the form addr:port
| addr | Address to append | 
| port | Port to append | 
| family | Address family, set it to Unknown to detect | 
| iface | Optional interface name | 
| 
 | inlinestatic | 
Append an address to a buffer in the form addr:port
| buf | Destination buffer | 
| addr | Address to append | 
| port | Port to append | 
| family | Address family, set it to Unknown to detect | 
| iface | Optional interface name | 
| bool assign | ( | const DataBlock & | addr | ) | 
Assigns a new address
| addr | Packed binary address to store | 
| void assign | ( | const struct sockaddr * | addr, | 
| socklen_t | len = 0 ) | 
Assigns a new address
| addr | Pointer to the address to store | 
| len | Length of the stored address, zero to use default | 
| bool assign | ( | int | family | ) | 
Assigns an empty address of a specific type
| family | Family of the address to create | 
| void clear | ( | ) | 
Clears up the address, frees the memory
| int copyAddr | ( | DataBlock & | addr | ) | const | 
Copy the host address to a buffer
| addr | Buffer to put the packed address into | 
| 
 | static | 
Copy a host address to a buffer
| buf | Destination buffer. It must be large enough to keep the address (4 bytes for IPv4, 16 bytes for IPv6) | 
| addr | The host address | 
| 
 | static | 
Retrieve the family name dictionary
Escape an interface name
| buf | Destination buffer | 
| name | Interface name | 
References String::uriEscapeTo().
| 
 | inline | 
Get the family of the stored address
| 
 | static | 
Retrieve the family of an address
| addr | The address to check | 
| 
 | inline | 
Retrieve address family name
| 
 | inline | 
| 
 | virtual | 
Set the hostname of this address. Guess address family if not initialized
| name | Host to set | 
| 
 | inline | 
Get the interface to use for this address
Referenced by Socket::bind().
| 
 | inline | 
Set the interface to use for this address
| name | Interface to use for this address | 
| uriUnescape | Set it to true to URI unescape the value | 
| 
 | inlinestatic | 
| 
 | static | 
Retrieve IPv4 null address
| 
 | static | 
Retrieve IPv6 null address
| 
 | inline | 
Check if this address is empty or null
| 
 | static | 
Check if an address is empty or null
| addr | Address to check | 
| family | Address family, set it to Unknown to detect | 
| 
 | inline | 
Get the length of the address
Referenced by Socket::bind(), Socket::connect(), Socket::connectAsync(), operator=(), Socket::sendTo(), and SocketAddr().
| bool local | ( | const SocketAddr & | remote | ) | 
Attempt to guess a local address that will be used to reach a remote one
| remote | Remote address to reach | 
| 
 | inlinestatic | 
Retrieve address family name
| family | Address family to retrieve | 
| 
 | inline | 
Check if a null address is held
| 
 | inline | 
Inequality comparation operator
| other | Address to compare to | 
| 
 | inline | 
| bool operator== | ( | const SocketAddr & | other | ) | const | 
Equality comparation operator
| other | Address to compare to | 
| int port | ( | ) | const | 
Get the port of the stored address (if supported)
| bool port | ( | int | newport | ) | 
Set the port of the stored address (if supported)
| newport | Port number to set in the socket address | 
| 
 | inline | 
Retrieve the sin6_scope_id value of an IPv6 address
| 
 | inlinestatic | 
Retrieve the scope id value of an IPv6 address
| addr | The address | 
| 
 | inlinestatic | 
Set the scope id value of an IPv6 address
| addr | Address to set | 
| val | Value to set | 
| 
 | inline | 
Set the sin6_scope_id value of an IPv6 address
| val | Value to set | 
| 
 | static | 
Split an address into ip/port. Handled formats: addr, addr:port, [addr], [addr]:port It is safe to call this method with the same destination and source string
| buf | Source buffer | 
| addr | Destination buffer for address | 
| port | Destination port | 
| portPresent | Set it to true if the port is always present after the last ':'. This will handle IPv6 addresses without square brackets and port present (e.g. fe80::23:5060 will split into addr=fe80::23 and port=5060) | 
Split an interface from address An interface may be present in addr after a percent char (e.g. fe80::23eth0) It is safe call this method with the same destination and source string
| buf | Source buffer | 
| addr | Destination buffer for address | 
| iface | Optional pointer to be filled with interface name | 
| 
 | protectedvirtual | 
Convert the host address to a String stored in m_host
| 
 | static | 
| 
 | static | 
Check if an address family is supported by the library
| family | Family of the address to check | 
| 
 | inlinestatic | 
| 
 | protectedvirtual | 
Store host:port in m_addr Store hostiface:port in m_addrFull
| full | Build the full addr | 
| 
 | inline | 
Check if a non-null address is held