Reputation: 33
I want to use IPv6 using boost asio in Linux (fedora).
NIC is
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 bind code is...
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's 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 of v6 loopback address is ok, but specific ("fe80::215:17ff:fe62:d168") address is binding error.
exception error is "bind: Invalid argument".
Why binding error?
Upvotes: 3
Views: 547
Reputation: 392833
It looks like you might not have permission to access the external network adaptor.
Perhaps (parts of)
chroot
jail?);Now, try in environments with fewer restrictions (e.g. outside virtualization containers, as root...).
If this doesn't get you the information you need consider using strace
or ltrace
to see which syscalls are failing.
Your code is ok, I've tested it to work on Linux and MSVC (substituting my NIC addresses)
Upvotes: 1