|
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
Referenced by local(), operator!=(), operator=(), operator==(), SocketAddr(), and unStringify().
|
inline |
Copy constructor
| value | Address to copy |
References address(), assign(), GenObject::GenObject(), length(), and SocketAddr().
|
explicit |
| SocketAddr | ( | const struct sockaddr * | addr, |
| socklen_t | len = 0 ) |
|
virtual |
Destructor that frees and zeroes out everything
|
inline |
Get the host and port of this address
| full | Retrieve the full address, interface included |
References updateAddr().
Referenced by appendAddr(), appendTo(), appendTo(), assign(), assign(), copyAddr(), copyAddr(), family(), isNullAddr(), scopeId(), scopeId(), SocketAddr(), split(), splitIface(), and stringify().
|
inline |
Get the contained socket address
Referenced by Socket::bind(), Socket::connect(), Socket::connectAsync(), operator=(), scopeId(), scopeId(), 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 |
References addr(), String::empty(), family(), and iface().
Referenced by appendTo().
|
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 |
References addr(), appendTo(), String::empty(), family(), iface(), and port().
|
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 |
References addr(), appendAddr(), String::empty(), family(), iface(), and port().
Referenced by appendTo().
| bool assign | ( | const DataBlock & | addr | ) |
| void assign | ( | const struct sockaddr * | addr, |
| socklen_t | len = 0 ) |
| bool assign | ( | int | family | ) |
Assigns an empty address of a specific type
References family().
Referenced by operator=(), and SocketAddr().
| 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 |
References addr().
Referenced by unStringify().
|
static |
|
static |
Retrieve the family name dictionary
Escape an interface name
| buf | Destination buffer |
| name | Interface name |
References ifaceNameExtraEscape(), and String::uriEscapeTo().
|
inline |
Get the family of the stored address
Referenced by appendAddr(), appendTo(), appendTo(), assign(), familyName(), isNullAddr(), isNullAddr(), lookupFamily(), SocketAddr(), supports(), and unStringify().
|
static |
|
inline |
|
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 appendAddr(), appendTo(), appendTo(), Socket::bind(), and splitIface().
|
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 |
Retrieve the string for interface name extra URI escape in address
Referenced by escapeIface().
|
static |
Retrieve IPv4 null address
|
static |
Retrieve IPv6 null address
|
inline |
Check if this address is empty or null
References family(), and isNullAddr().
Referenced by isNullAddr().
|
static |
|
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 |
References SocketAddr().
|
inlinestatic |
Retrieve address family name
| family | Address family to retrieve |
References family().
Referenced by familyName().
|
inline |
Check if a null address is held
|
inline |
Inequality comparation operator
| other | Address to compare to |
References operator==(), and SocketAddr().
|
inline |
Assignment operator
| value | Address to copy |
References address(), assign(), length(), and SocketAddr().
| bool operator== | ( | const SocketAddr & | other | ) | const |
Equality comparation operator
| other | Address to compare to |
References SocketAddr().
Referenced by operator!=().
| int port | ( | ) | const |
Get the port of the stored address (if supported)
Referenced by appendTo(), appendTo(), and split().
| bool port | ( | int | newport | ) |
Set the port of the stored address (if supported)
| newport | Port number to set in the socket address |
|
inline |
|
inlinestatic |
|
inlinestatic |
|
inline |
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
|
protectedvirtual |
Convert the host address to a String stored in m_host
|
static |
|
static |
|
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 address(), copyAddr(), family(), host(), and SocketAddr().
|
protectedvirtual |
Store host:port in m_addr Store hostiface:port in m_addrFull
| full | Build the full addr |
Referenced by addr().
|
inline |
Check if a non-null address is held