6 #include <netinet/in.h> 11 #include <hilti/rt/extension-points.h> 12 #include <hilti/rt/result.h> 13 #include <hilti/rt/types/bytes.h> 14 #include <hilti/rt/types/stream.h> 18 enum class AddressFamily : int64_t { Undef, IPv4, IPv6 };
33 explicit Address(
const std::string& addr) { _parse(addr); }
36 explicit Address(
struct in_addr addr4) { _init(addr4); }
41 explicit Address(
struct in6_addr addr6) { _init(addr6); }
56 explicit Address(uint64_t addr6a, uint64_t addr6b, AddressFamily family = AddressFamily::IPv6)
57 : _a1(addr6a), _a2(addr6b), _family(family) {}
71 AddressFamily family()
const;
78 Address mask(
unsigned int width)
const;
84 std::variant<struct in_addr, struct in6_addr> asInAddr()
const;
86 bool operator==(
const Address& other)
const;
87 bool operator!=(
const Address& other)
const {
return ! (*
this == other); }
95 operator std::string()
const;
98 void _init(
struct in_addr addr);
99 void _init(
struct in6_addr addr);
102 void _parse(
const std::string& addr);
107 AddressFamily _family = AddressFamily::Undef;
119 namespace detail::adl {
120 extern std::string
to_string(
const AddressFamily& x, adl::tag );
124 inline std::ostream& operator<<(std::ostream& out,
const Address& x) {
129 inline std::ostream& operator<<(std::ostream& out,
const AddressFamily& family) {
return out <<
to_string(family); }
std::string to_string(T &&x)
Definition: extension-points.h:26
Address(uint32_t addr4)
Definition: address.h:48
Address(struct in_addr addr4)
Definition: address.h:36
Address(uint64_t addr6a, uint64_t addr6b, AddressFamily family=AddressFamily::IPv6)
Definition: address.h:56
ByteOrder
Definition: util.h:506
Address(struct in6_addr addr6)
Definition: address.h:41
Address(const std::string &addr)
Definition: address.h:33
std::string fmt(const char *fmt, const Args &... args)
Definition: fmt.h:13