I’m writing multicast client/server application based on this and this; which work great.
However, I would also need to do something when the number of active network interfaces in the computer changes, something like what the program in the example section of this page does.
I guess I should use the tools in boost::asio::local, but I am unsure whether I should use boost::asio::local::datagram_protocol or boost::asio::local::stream_protocol or…
An example of how to do something as similar as possible would be really helpful. Thanks.
As you noticed there’s a little bit extra code that has to get written to do this.
Netlink uses its own Address Family (PF_NETLINK) and isn’t TCP or UDP. Instead it uses RAW sockets. Since it is a private family (not PF_INET or PF_INET6) we need to define it ourselves.
I used a basic unix local socket as a template to implement this (see the bottom for test program). If you don’t want to copy paste all the code, I also put it on github (http://github.com/gille/boost_netlink):
The protocol:
Then from here all we need to do is create a raw socket and read it: