Poco::Net

class SocketAddress

Library: Net
Package: NetCore
Header: Poco/Net/SocketAddress.h

Description

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.

Member Summary

Member Functions: addr, af, host, init, length, operator =, port, resolveService, swap, toString

Enumerations

Anonymous

MAX_ADDRESS_LENGTH = sizeof (struct sockaddr_in)

Maximum length in bytes of a socket address.

Constructors

SocketAddress

SocketAddress();

Creates a wildcard (all zero) IPv4 SocketAddress.

SocketAddress

explicit SocketAddress(
    const std::string & hostAndPort
);

Creates a SocketAddress from an IP address or host name and a 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

SocketAddress(
    const SocketAddress & addr
);

Creates a SocketAddress by copying another one.

SocketAddress

SocketAddress(
    const IPAddress & host,
    Poco::UInt16 port
);

Creates a SocketAddress from an IP address and a port number.

SocketAddress

SocketAddress(
    const std::string & host,
    Poco::UInt16 port
);

Creates a SocketAddress from an IP address and a 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

SocketAddress(
    const std::string & host,
    const std::string & port
);

Creates a SocketAddress from an IP address and a 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

SocketAddress(
    const struct sockaddr * addr,
    int length
);

Creates a SocketAddress from a native socket address.

Destructor

~SocketAddress

~SocketAddress();

Destroys the SocketAddress.

Member Functions

addr

const struct sockaddr * addr() const;

Returns a pointer to the internal native socket address.

af

int af() const;

Returns the address family (AF_INET or AF_INET6) of the address.

host

IPAddress host() const;

Returns the host IP address.

length

int length() const;

Returns the length of the internal native socket address.

operator =

SocketAddress & operator = (
    const SocketAddress & addr
);

Assigns another SocketAddress.

port

Poco::UInt16 port() const;

Returns the port number.

swap

void swap(
    SocketAddress & addr
);

Swaps the SocketAddress with another one.

toString

std::string toString() const;

Returns a string representation of the address.

init protected

void init(
    const IPAddress & host,
    Poco::UInt16 port
);

init protected

void init(
    const std::string & host,
    Poco::UInt16 port
);

resolveService protected

Poco::UInt16 resolveService(
    const std::string & service
);