Gather all IP addresses of a host as a vector I have the following working code to get IPv4/v6 addresses from host names:
#include &lt;array&gt;
using std::array;

#include &lt;iostream&gt;
using std::cout;

#include &lt;netdb.h&gt;

#include &lt;stdexcept&gt;
using std::domain_error;

#include &lt;sys/socket.h&gt;

#include &lt;string&gt;
using std::string;

#include &lt;vector&gt;
using std::vector;

#include &lt;boost/asio.hpp&gt;
using boost::asio::ip::address;
using boost::asio::ip::address_v4;
using boost::asio::ip::address_v6;

vector&lt;address&gt; getAddresses(string const &amp;hostname)
{
    struct addrinfo req = {.ai_family = AF_UNSPEC, .ai_socktype = SOCK_STREAM};
    struct addrinfo *pai;
    int error = getaddrinfo(hostname.c_str(), nullptr, &amp;req, &amp;pai);
    if (error)
        throw domain_error(&quot;Could not resolve host name.&quot;);

    vector&lt;address&gt; addresses;

    for(struct addrinfo *info = pai; info != nullptr; info = info-&gt;ai_next) {
        if (info-&gt;ai_family == AF_INET) {
            auto ipv4socket = reinterpret_cast&lt;struct sockaddr_in*&gt;(info-&gt;ai_addr);
            auto ipv4addr = address_v4(htonl(ipv4socket-&gt;sin_addr.s_addr));
            addresses.emplace_back(ipv4addr);
        } else {
            auto ipv6socket = reinterpret_cast&lt;struct sockaddr_in6*&gt;(info-&gt;ai_addr);
            auto ipv6base = reinterpret_cast&lt;unsigned char*&gt;(ipv6socket-&gt;sin6_addr.s6_addr);
            array&lt;unsigned char, 16&gt; bytearray = {
                ipv6socket-&gt;sin6_addr.s6_addr[0],
                ipv6socket-&gt;sin6_addr.s6_addr[1],
                ipv6socket-&gt;sin6_addr.s6_addr[2],
                ipv6socket-&gt;sin6_addr.s6_addr[3],
                ipv6socket-&gt;sin6_addr.s6_addr[4],
                ipv6socket-&gt;sin6_addr.s6_addr[5],
                ipv6socket-&gt;sin6_addr.s6_addr[6],
                ipv6socket-&gt;sin6_addr.s6_addr[7],
                ipv6socket-&gt;sin6_addr.s6_addr[8],
                ipv6socket-&gt;sin6_addr.s6_addr[9],
                ipv6socket-&gt;sin6_addr.s6_addr[10],
                ipv6socket-&gt;sin6_addr.s6_addr[11],
                ipv6socket-&gt;sin6_addr.s6_addr[12],
                ipv6socket-&gt;sin6_addr.s6_addr[13],
                ipv6socket-&gt;sin6_addr.s6_addr[14],
                ipv6socket-&gt;sin6_addr.s6_addr[15]
            };
            auto ipv6addr = address_v6(bytearray, ipv6socket-&gt;sin6_scope_id);
            addresses.emplace_back(ipv6addr);
        }
    }

    return addresses;
}

int main()
{
    auto addresses = getAddresses(&quot;heise.de&quot;);

    for (auto ipa : addresses)
        cout &lt;&lt; &quot;Address: &quot; &lt;&lt; ipa &lt;&lt; &quot;\n&quot;;

    return 0;
}

I find the conversion fom uint8_t[16] (ipv6socket-&gt;sin6_addr.s6_addr) to std::array&lt;unsigned char, 16&gt; a bit verbose.
I also considered doing it in a for-loop, but this would still seem cumbersome to me, somehow.
I tried static_cast and reinterpret_cast to no avail.
Is there a possibility to do this conversion in a simpler way, preferably a one-liner?
I agree with you that the copying of data from s6_addr seems cumbersome.  I would instead just cast without copying:
auto&amp; bytearray = reinterpret_cast&lt;std::array&lt;unsigned char,16&gt;&amp;&gt;(ipv6socket-&gt;sin6_addr.s6_addr);

(If we had needed to copy, we could change auto&amp; to plain auto).
Apart from this, the variable ipv6base is never used, so should just be removed.