Boost.Asio IPv6 Why bind a bug?
I want to use IPv6 using boost asio on Linux (fedora).
NIC
ifconfig -a
em1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 172.16.16.109 netmask 255.255.255.0 broadcast 172.16.16.255
inet6 fe80::215:17ff:fe62:d168 prefixlen 64 scopeid 0x20<link>
ether 00:15:17:62:d1:68 txqueuelen 1000 (Ethernet)
RX packets 59516986 bytes 7105720351 (6.6 GiB)
RX errors 0 dropped 5015310 overruns 0 frame 0
TX packets 8680244 bytes 1666346667 (1.5 GiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
device interrupt 18 memory 0xb8820000-b8840000
and IPv6 udp binding code ...
int main(int argc, char* argv[])
{
try
{
boost::asio::io_service io_service;
const char* ip_address_string = "fe80::215:17ff:fe62:d168";
// const char* ip_address_string = "::1"; // It OK
boost::asio::ip::address my_address = boost::asio::ip::address::from_string(ip_address_string);
udp::endpoint local_endpoint(my_address, 15060);
udp my_protocol = udp::v6();
udp::socket sock(io_service);
sock.open(my_protocol);
sock.bind(local_endpoint);
std::cout << "ip:" << local_endpoint.address().to_string() << std::endl;
// -*/
}
catch (std::exception& e)
{
std::cerr << e.what() << std::endl;
}
return 0;
}
Binding the v6 return address is fine, but the specific ("fe80 :: 215: 17ff: fe62: d168") address is a bind error.
Exception error: "bind: Invalid argument".
Why do I need a communication error?
source to share
It looks like you may not have access to an external network adapter.
Perhaps (parts)
- ipv6 disabled (although the adapter is obviously capable and configured)
- / proc is not mounted (are you in a restricted environment like jail
chroot
?); - The ip address is actually different - it's a bit lame since you've checked this a bazillion times, but I felt like I should at least mention it.
Now try in environments with fewer restrictions (e.g. outside of virtualization containers like root ...).
If you don't need the information you need, use strace
or ltrace
to see which system calls are not working.
Your code is fine, I tested it to work with Linux and MSVC (replacing my NIC addresses)
source to share