问题
I am trying to list all opened multicast sockets on a linux system? netstat -g lists the groups joined though. Is there any other utility that I can use for this sake?
Thanks a lot for the help.
回答1:
In addition to netstat -g
you can use this to see all sockets which are bound to a multicast address:
netstat -anu|sort -nk4
This is a list of all UDP sockets (whether multicast or not). Look for all addresses in the range 224.0.0.0 to 239.255.255.255. These are sockets bound to multicast addresses, regardless whether they joined the multicast group or not. These will only receive traffic for this multicast group.
But:
In practice UDP sockets which are used to receive multicast traffic are usually bound to address 0.0.0.0. These can receive UDP packets for all unicast and multicast addresses, and the server usually does some additional filtering based on the source-IP-address.
So in that list above you may want to look also at UDP sockets bound to 0.0.0.0, for example 0.0.0.0:5353 which is most likely the mDNS (avahi, zeroconf) server.
回答2:
I don't think there is a tool that can give you that information.
The reason is that a multicast socket is not bound to an address, it only participates in a multicast group (IP_ADD_MEMBERSHIP). A socket can join multiple different groups on the same interface, or same group on different interfaces, so it would make little sense to maintain these cross refences. The only information exposed by the kernel is in /proc/net, and in this case /proc/net/igmp (<- netstat -g).
来源:https://stackoverflow.com/questions/15892675/listing-multicast-sockets