Missing outbound_interface creating via address_v6
The code
const boost::asio::ip::address_v4 addr = endpoint.address().to_v4();
const boost::asio::ip::multicast::outbound_interface oif(addr);
this->_socket.set_option(oif);
compiles, but not
const boost::asio::ip::address_v6 addr = endpoint.address().to_v6();
const boost::asio::ip::multicast::outbound_interface oif(addr);
this->_socket.set_option(oif);
It would be nice to have full IPv6-Support.
However, there is an issue: outbound_interfacesupports IPv6, and my compiler indicates that a boost::asio::ip::address_v6object cannot be directly passed to its constructor. You should initialize it using an interface index (of type unsigned int). Additionally, my Boost library version is 1.8.9. I hope this information is helpful to you.
Since my code is primarily intended for Linux, I am now using POSIX's if_nametoindex:
unsigned int PosixWrapper::if_nametoindex(const std::string& ifname)
{
const unsigned int result = ::if_nametoindex(ifname.c_str());
if (result == 0)
{
throw std::system_error(
errno, std::generic_category(), "Failed to get interface index.");
}
return result;
}
https://codeberg.org/mark22k/mping-sender/src/commit/58a791a9dcfe7cec23fdccb5fba2e3d26d928bfd/src/posix_wrapper.cpp
Looks good!