|
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 () |
| unsigned int | scopeId () const |
| bool | scopeId (unsigned int val) |
| const String & | host () const |
| const String & | addr () const |
| 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 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) |
| static String & | appendTo (String &buf, const String &addr, int port, int family=Unknown) |
| static String | appendTo (const String &addr, int port, int family=Unknown) |
| 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 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 () const |
Protected Attributes | |
| struct sockaddr * | m_address |
| socklen_t | m_length |
| String | m_host |
| String | m_addr |
A socket address holder.
Wrapper class to keep a socket address
| enum Family |
Known address families
|
inline |
Default constructor of an empty address
|
inline |
Copy constructor
| value | Address to copy |
References SocketAddr::address(), SocketAddr::assign(), and SocketAddr::length().
|
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
References SocketAddr::updateAddr().
|
inline |
Get the contained socket address
Referenced by Socket::bind(), Socket::connect(), Socket::connectAsync(), SocketAddr::operator=(), SocketAddr::scopeId(), Socket::sendTo(), SocketAddr::SocketAddr(), and SocketAddr::unStringify().
Append an address to a buffer
| buf | Destination buffer |
| addr | Address to append |
| family | Address family, set it to Unknown to detect |
Referenced by SocketAddr::appendTo().
|
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 |
References SocketAddr::appendAddr(), SocketAddr::family(), and SocketAddr::port().
Referenced by SocketAddr::appendTo().
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 |
References SocketAddr::appendTo(), and SocketAddr::family().
| bool assign | ( | int | family | ) |
Assigns an empty address of a specific type
| family | Family of the address to create |
Referenced by SocketAddr::operator=(), and SocketAddr::SocketAddr().
| 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 | ( | const DataBlock & | addr | ) |
Assigns a new address
| addr | Packed binary address to store |
| 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 |
Referenced by SocketAddr::unStringify().
|
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
|
inline |
Get the family of the stored address
Referenced by SocketAddr::appendTo(), SocketAddr::familyName(), SocketAddr::isNullAddr(), and SocketAddr::unStringify().
|
static |
Retrieve the family of an address
| addr | The address to check |
|
inline |
Retrieve address family name
References SocketAddr::family(), and SocketAddr::lookupFamily().
|
inline |
|
virtual |
Set the hostname of this address. Guess address family if not initialized
| name | Host to set |
|
static |
Retrieve IPv4 null address
|
static |
Retrieve IPv6 null address
|
inline |
Check if this address is empty or null
References SocketAddr::family().
|
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(), SocketAddr::operator=(), Socket::sendTo(), and SocketAddr::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 |
References TelEngine::lookup().
Referenced by SocketAddr::familyName().
|
inline |
Check if a null address is held
|
inline |
Inequality comparation operator
| other | Address to compare to |
References SocketAddr::operator==().
|
inline |
Assignment operator
| value | Address to copy |
References SocketAddr::address(), SocketAddr::assign(), and SocketAddr::length().
| bool operator== | ( | const SocketAddr & | other | ) | const |
Equality comparation operator
| other | Address to compare to |
Referenced by SocketAddr::operator!=().
| int port | ( | ) | const |
Get the port of the stored address (if supported)
Referenced by SocketAddr::appendTo().
| 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
References SocketAddr::address().
Referenced by SocketAddr::scopeId().
|
inline |
Set the sin6_scope_id value of an IPv6 address
| val | Value to set |
References SocketAddr::address(), and SocketAddr::scopeId().
|
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 |
|
static |
Split an address into ip/port. Handled formats: addr, addr:port, [addr], [addr]:port It is safe 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 |
|
static |
|
protectedvirtual |
Convert the host address to a String stored in m_host
|
static |
Check if an address family is supported by the library
| family | Family of the address to check |
|
inlinestatic |
Put 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) |
| host | The host address |
| family | Address family, set it to Unknown to detect |
References SocketAddr::address(), SocketAddr::copyAddr(), SocketAddr::family(), and SocketAddr::host().
|
protectedvirtual |
Store host:port in m_addr
Referenced by SocketAddr::addr().
|
inline |
Check if a non-null address is held
1.8.8