Linux 列出多播套接字
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15892675/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
listing multicast sockets
提问by Sreeram Ravinoothala
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?
我想列出 Linux 系统上所有打开的多播套接字?netstat -g 列出了加入的组。为此,我可以使用其他任何实用程序吗?
Thanks a lot for the help.
非常感谢您的帮助。
回答by Catalin
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).
原因是多播套接字不绑定地址,它只参与多播组(IP_ADD_MEMBERSHIP)。一个套接字可以在同一个接口上加入多个不同的组,或者在不同接口上加入同一个组,因此维护这些交叉引用几乎没有意义。内核公开的唯一信息在 /proc/net 中,在本例中为 /proc/net/igmp (<- netstat -g)。
回答by Johannes Overmann
In addition to netstat -g
you can use this to see all sockets which are bound to a multicast address:
除此之外,netstat -g
您可以使用它来查看绑定到多播地址的所有套接字:
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 onlyreceive traffic for this multicast group.
这是所有 UDP 套接字的列表(无论是否多播)。查找 224.0.0.0 到 239.255.255.255 范围内的所有地址。这些是绑定到多播地址的套接字,无论它们是否加入多播组。这些将只接收此多播组的流量。
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.
实际上,用于接收多播流量的 UDP 套接字通常绑定到地址 0.0.0.0。这些可以接收所有单播和多播地址的 UDP 数据包,服务器通常会根据源 IP 地址进行一些额外的过滤。
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.
因此,在上面的列表中,您可能还想查看绑定到 0.0.0.0 的 UDP 套接字,例如 0.0.0.0:5353,这很可能是 mDNS(avahi,zeroconf)服务器。