Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
asio::ip::address_v6
takes a
bytes_type
for a parameter, which is basically a
boost::array
in network-byte order.
I have a RAW IPv6 address in a
void *
variable. What's the quickest way to turn a
void *
into a
asio::ip::address_v6
? Preferably using the constructor.
You can't do better than initializing an
asio::ip::address_v6::bytes_type
, which can actually be a
std::array
or a
boost::array
:
// We need an unsigned char* pointer to the IP address
unsigned char *youraddr = reinterpret_cast<unsigned char*>(your_void_ptr);
asio::ip::address_v6::bytes_type myaddr;
// Copy the address into our array
std::copy(youraddr, youraddr + myaddr.size(), myaddr.data());
// Finally, initialize.
asio::ip::address_v6 ipv6(myaddr);
Note that it would be better to directly store a bytes_type
instead of that void*
, if you are able to modify that structure, obviously.
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.