Spicy
Public Member Functions | List of all members
hilti::rt::Address Class Reference

#include <address.h>

Public Member Functions

 Address (const std::string &addr)
 
 Address (struct in_addr addr4)
 
 Address (struct in6_addr addr6)
 
 Address (uint32_t addr4)
 
 Address (uint64_t addr6a, uint64_t addr6b, AddressFamily family=AddressFamily::IPv6)
 
 Address (const Address &)=default
 
 Address (Address &&) noexcept=default
 
Addressoperator= (const Address &)=default
 
Addressoperator= (Address &&) noexcept=default
 
AddressFamily family () const
 
Address mask (unsigned int width) const
 
std::variant< struct in_addr, struct in6_addr > asInAddr () const
 
bool operator== (const Address &other) const
 
bool operator!= (const Address &other) const
 
 operator std::string () const
 

Detailed Description

Represents HILTI address type. This treats IPv4 and IPv6 addresses transparently by internally embedding the former into the latter's space.

Constructor & Destructor Documentation

◆ Address() [1/5]

hilti::rt::Address::Address ( const std::string &  addr)
inlineexplicit

Constructs an address from a IPv4 or IPv6 string representation.

Parameters
addrstring representation, as in 1.2.3.4 or 2001:db8:85a3:8d3:1319:8a2e:370:7348.
Exceptions
RuntimeErrorif it cannot parse the address into a valid IPv4 or IPv6 address.

◆ Address() [2/5]

hilti::rt::Address::Address ( struct in_addr  addr4)
inlineexplicit

Constructs an address from a C in_addr struct.

◆ Address() [3/5]

hilti::rt::Address::Address ( struct in6_addr  addr6)
inlineexplicit

Constructs an address from a C in6_addr struct.

◆ Address() [4/5]

hilti::rt::Address::Address ( uint32_t  addr4)
inlineexplicit

Constructs an address from binary representation of an IPv4 address.

Parameters
addr4IPv4 address in host byte order

◆ Address() [5/5]

hilti::rt::Address::Address ( uint64_t  addr6a,
uint64_t  addr6b,
AddressFamily  family = AddressFamily::IPv6 
)
inlineexplicit

Constructs an address from binary representation of an IPv6 address.

Parameters
addr6aupper bits of IPv6 address in host byte order
addr6alower bits of IPv6 address in host byte order

Member Function Documentation

◆ asInAddr()

std::variant< struct in_addr, struct in6_addr > Address::asInAddr ( ) const

Returns the address as in{,6}_addr depending on whether it's a v4 or v6 value. For an unset address, returns an IPv4 0.0.0.0.

◆ family()

AddressFamily Address::family ( ) const

Returns the address family of the address, which can be either IPv4 or IPv6.

◆ mask()

Address Address::mask ( unsigned int  width) const

Returns a network prefix by masking out lower bits of the address.

Parameters
widthnumber of upper bits to keep.

◆ operator std::string()

Address::operator std::string ( ) const

Returns a string representation of the address. For addresses in the IPv4 space, this will returns the standard IPv4 notation, whereas IPv6 addresses will be formatted as such. The returned format corresponds to what the corresponding constructor parses.


The documentation for this class was generated from the following files: