Class EndPointAddress

Nested Relationships

Nested Types

Class Documentation

class EndPointAddress

Class containing the IP address and port of a network endpoint.

The IP is stored as a string and as a numeric value for faster comparisons.

Public Functions

EndPointAddress() = default
EndPointAddress(const std::string &ip, unsigned short port)

Construct an EndPointAddress object from an IP address and port.

Parameters:
  • ip – IP address

  • port – Port number

explicit EndPointAddress(const std::string &str)

Construct an EndPointAddress object from a string containing the IP address and port.

Format of the string: “IP:port” or “IP” (assumes port 0)

Parameters:

str – String containing the IP address and port

explicit EndPointAddress(const sockaddr *addr, std::size_t addrlen)

Construct an EndPointAddress object from a sockaddr structure.

This constructor is used to create an EndPointAddress from a sockaddr structure, which is typically used in network programming to represent an endpoint address.

Parameters:

addr – Pointer to a sockaddr structure containing the endpoint address

inline const std::string &address() const

Get the IP address.

Returns:

IP address

inline unsigned short port() const

Get the port.

Returns:

Port number

inline std::uint64_t address_numeric() const

Get the IP address as a numeric value.

For IPv4 addresses, returns the actual 32-bit network address extended to 64-bit. For IPv6 addresses, returns a cryptographically robust 64-bit hash representation with the high bit set to distinguish from IPv4.

The 64-bit representation provides excellent collision resistance:

  • Collision probability ~50% only after 5.1 billion different addresses

  • Suitable for production use with millions of network endpoints

Returns:

IP address as a 64-bit numeric value suitable for indexing and comparison

inline void port(unsigned short port)

Set the IP address.

Parameters:

ip – IP address

sockaddr_storage to_sockaddr_storage() const

Convert the EndPointAddress to a sockaddr_storage structure.

Returns a sockaddr_storage that can hold both IPv4 and IPv6 addresses, making it compatible with libfabric which accepts sockaddr, sockaddr_in, and sockaddr_in6. The returned structure can be safely cast to the appropriate type based on the sa_family field.

Throws:

std::invalid_argument – if the IP address format is invalid

Returns:

sockaddr_storage structure representing the endpoint address

inline auto operator<=>(const EndPointAddress &other) const

Compare two EndPointAddress objects using numeric IP and port.

Parameters:

otherEndPointAddress object to compare with

Returns:

Comparison result

inline bool operator==(const EndPointAddress &other) const

Compare two EndPointAddress objects for equality using numeric IP and port.

Parameters:

otherEndPointAddress object to compare with

Returns:

Comparison result

inline bool operator!=(const EndPointAddress &other) const

Compare two EndPointAddress objects for inequality using numeric IP and port.

Parameters:

otherEndPointAddress object to compare with

Returns:

Comparison result

bool is_ipv4() const

Check if the address is IPv4.

Returns:

true if the address is IPv4, false if IPv6

bool is_ipv6() const

Check if the address is IPv6.

Returns:

true if the address is IPv6, false if IPv4

Friends

friend std::ostream &operator<<(std::ostream&, const EndPointAddress&)

Overload the << operator to print the IP address and port.

Parameters:
Returns:

Output stream

template<typename H>
inline friend H AbslHashValue(H h, const EndPointAddress &endpoint)

Enable hashing with absl::Hash.

Template Parameters:

HHash state type

Parameters:
Returns:

Updated hash state

struct Hash

Hash function for EndPointAddress objects.

Golden ratio hash function combining the 64-bit IP numeric representation with the 16-bit port into a 128-bit intermediate value before mixing, ensuring both components contribute meaningfully to the final hash.

Public Functions

inline std::size_t operator()(const EndPointAddress &endpoint) const noexcept