diff --git a/src/net/SocketAddress.hxx b/src/net/SocketAddress.hxx index f7a0d4e39..9d5297e21 100644 --- a/src/net/SocketAddress.hxx +++ b/src/net/SocketAddress.hxx @@ -79,6 +79,12 @@ public: size_type _size) noexcept :address(_address), size(_size) {} +#ifdef __cpp_lib_span + explicit SocketAddress(std::span src) noexcept + :address((const struct sockaddr *)(const void *)src.data()), + size(src.size()) {} +#endif + static constexpr SocketAddress Null() noexcept { return nullptr; } @@ -165,6 +171,14 @@ public: #endif #ifdef __cpp_lib_span + operator std::span() const noexcept { + const void *q = reinterpret_cast(address); + return { + (const std::byte *)q, + (std::size_t)size, + }; + } + /** * Return a buffer pointing to the "steady" portion of the * address, i.e. without volatile parts like the port number.