class Poco::Net::SocketAddress
Overview
This class represents an internet (IP) endpoint/socket address. More…
#include <SocketAddress.h> class SocketAddress { public: // enums enum { MAX_ADDRESS_LENGTH = sizeof(struct sockaddr_in), }; // construction SocketAddress(); SocketAddress( const IPAddress& hostAddress, Poco::UInt16 portNumber ); SocketAddress(Poco::UInt16 port); SocketAddress( const std::string& hostAddress, Poco::UInt16 portNumber ); SocketAddress( const std::string& hostAddress, const std::string& portNumber ); SocketAddress(const std::string& hostAndPort); SocketAddress(const SocketAddress& addr); SocketAddress( const struct sockaddr* addr, poco_socklen_t length ); // methods SocketAddress& operator=(const SocketAddress& socketAddress); IPAddress host() const; Poco::UInt16 port() const; poco_socklen_t length() const; const struct sockaddr* addr() const; int af() const; std::string toString() const; IPAddress::Family family() const; bool operator<(const SocketAddress& socketAddress) const; bool operator==(const SocketAddress& socketAddress) const; bool operator!=(const SocketAddress& socketAddress) const; protected: // methods void init( const IPAddress& hostAddress, Poco::UInt16 portNumber ); void init( const std::string& hostAddress, Poco::UInt16 portNumber ); Poco::UInt16 resolveService(const std::string& service); };
Detailed Documentation
This class represents an internet (IP) endpoint/socket address.
The address can belong either to the IPv4 or the IPv6 address family and consists of a host address and a port number.
Construction
SocketAddress()
Creates a wildcard (all zero) IPv4 SocketAddress.
SocketAddress( const IPAddress& hostAddress, Poco::UInt16 portNumber )
Creates a SocketAddress from an IP address and given port number.
SocketAddress(Poco::UInt16 port)
Creates a SocketAddress with unspecified (wildcard) IP address and given port number.
SocketAddress( const std::string& hostAddress, Poco::UInt16 portNumber )
Creates a SocketAddress from an IP address and given port number.
The IP address must either be a domain name, or it must be in dotted decimal (IPv4) or hex string (IPv6) format.
SocketAddress( const std::string& hostAddress, const std::string& portNumber )
Creates a SocketAddress from an IP address and the service name or port number.
The IP address must either be a domain name, or it must be in dotted decimal (IPv4) or hex string (IPv6) format.
The given port must either be a decimal port number, or a service name.
SocketAddress(const std::string& hostAndPort)
Creates a SocketAddress from an IP address or host name and the port number/service name.
Host name/address and port number must be separated by a colon. In case of an IPv6 address, the address part must be enclosed in brackets.
Examples:
192.168.1.10:80 [::ffff:192.168.1.120]:2040 www.appinf.com:8080
SocketAddress(const SocketAddress& addr)
Creates a SocketAddress by copying another one.
SocketAddress( const struct sockaddr* addr, poco_socklen_t length )
Creates a SocketAddress from a native socket address.
Methods
SocketAddress& operator=(const SocketAddress& socketAddress)
Assigns another SocketAddress.
IPAddress host() const
Returns the host IP address.
Poco::UInt16 port() const
Returns the port number.
poco_socklen_t length() const
Returns the length of the internal native socket address.
const struct sockaddr* addr() const
Returns a pointer to the internal native socket address.
int af() const
Returns the address family (AF_INET or AF_INET6) of the address.
std::string toString() const
Returns a string representation of the address.
IPAddress::Family family() const
Returns the address family of the host’s address.