Class Endpoint.

Inherits Garbage

Endpoint parses and stores a Unix/IPv4/IPv6 address.

It can parse an IPv4/6 string representation, or a fully-qualified Unix path; and it stores a binary representation of those. If the Endpoint is valid(), its protocol(), address() and port() are all accessible.

The OS equivalent of an Endpoint, sockaddr, is available through sockaddr() and sockaddrSize().

Finally, it can generate a correct string() representation.

There is no DNS or /etc/hosts support.

Endpoint::Endpoint( Configuration::Text address, Configuration::Scalar port )

Constructs an Endpoint using configuration data. address and port are fetched using Configuration.

This constructor logs errors if anything goes wrong.

Endpoint::Endpoint( const EString & address, uint port )

Constructs an Endpoint representing port on address. If the address is a Unix path, the port is ignored.

Endpoint::Endpoint( const Endpoint & other )

Constructs a copy of other.

Endpoint::Endpoint( const struct sockaddr * sa )

Constructs an Endpoint corresponding to the sockaddr sa.

Endpoint::Endpoint()

Creates an empty Endpoint object.

Reimplements Garbage::Garbage().

EString Endpoint::address() const

Returns a string representation of this Endpoint's address. The return value is both human-readable and uniquely parsable. For example, the Endpoint constructor can parse the result of address().

If the Endpoint isn't valid(), address() returns an empty string.

Endpoint & Endpoint::operator=( const Endpoint & other )

Makes this Endpoint into a copy of other and returns a reference to this Endpoint.

uint Endpoint::port() const

And what port?

Protocol Endpoint::protocol() const

Returns the protocol to be used for this Endpoint.

struct sockaddr * Endpoint::sockaddr() const

Returns a pointer to a static sockaddr structure filled in with this Endpoint's information. Subsequent calls to sockaddr() will overwrite the result.

If the Endpoint is not valid, this function returns a null pointer.

uint Endpoint::sockaddrSize() const

Returns the size of the struct to which sockaddr() returns a pointer.

EString Endpoint::string() const

Returns the string representation of an endpoint. Note that this cannot be parsed - it's strictly for human consumption.

The returned value does not contain slash, backslash or parens.

bool Endpoint::valid() const

Returns true if this endpoint represents something sensible, and false if there was an error during parsing or similar.

void Endpoint::zeroPort()

This strange function exists only so that we can construct a valid sockaddr that has the port set to zero, so that we can pass it to bind(2) and ask it to fill in a random port for us. The calling convention is inconvenient, but makes it easy to locate callers.

This web page based on source code belonging to The Archiveopteryx Developers. All rights reserved.