简体   繁体   English

如何接收多播加入报告 (IGMP v3)

[英]How to receive multicast join reports (IGMP v3)

I want to see which Multicast-Join-Reports fly through the.network in which my host computer resides in. For that I've written a little TypeScript program, that joins the multicast group '224.0.0.22', which is defined in RFC3376 under 4.2.14 as the IP Destination for Multicast-Join-Reports.我想看看哪个 Multicast-Join-Reports 飞过我的主机所在的.network。为此我写了一个小程序 TypeScript,它加入了RFC3376中定义的多播组“224.0.0.22”在 4.2.14 下作为多播加入报告的 IP 目的地。 But I receive no requests even when I should, because I'am watching traffic via Wireshark and there Multicast-Join-Reports are send and received.但是即使我应该收到请求,我也没有收到任何请求,因为我正在通过 Wireshark 观看流量,并且发送和接收了 Multicast-Join-Reports。

Edit 1 : Attached is the receiving part:编辑1 :附件是接收部分:

const interfaces = os.networkInterfaces();

const IGMP_V3_REPORT_MULTICAST_ADDRESS = '224.0.0.22';
const socket = dgram.createSocket('udp4');

const ipv4Interface = interfaces['eth0'].find((i) => i.family === 'IPv4');

if (ipv4Interface) {
    socket.on('error', (e: Error) => {
        console.log(`${ifaceName}: socket error: ${e}`);
        sockResults[index] = false;
    });

    socket.on('listening', () => {
        const address = socket.address();
        console.log(`${ifaceName}: listening on ${address.address}:${address.port}`);

        console.log(`${ifaceName}: joining multicast group with address: ${IGMP_V3_REPORT_MULTICAST_ADDRESS} for local address: ${ipv4Interface.address}`);
        socket.addMembership(IGMP_V3_REPORT_MULTICAST_ADDRESS, ipv4Interface.address);
    })

    socket.on('message', (msg, rinfo) => {
        console.log(`${ifaceName}: got ${msg}`);
    });

    socket.bind(0);

    setTimeout(() => {
        console.log(`${ifaceName}: dropping multicast membership for ${IGMP_V3_REPORT_MULTICAST_ADDRESS}`);
        socket.dropMembership(IGMP_V3_REPORT_MULTICAST_ADDRESS,  ipv4Interface.address);

        console.log(`${ifaceName}: closing socket`);
        socket.close();

        resolve();
    }, 120 * 1000);
}

Let's ignore IGMP, multicast-join, switches, and all that stuff for a moment, as you're already physically receiving the desired packets.让我们暂时忽略 IGMP、多播加入、交换机和所有这些东西,因为您已经在物理上接收到所需的数据包。

If you want to receive packets that are destined to 239.255.255.250 , you're gonna have to use that address (and for UPnP the relevant port) in socket.bind() .如果你想接收发往239.255.255.250的数据包,你将不得不在socket.bind()

These are all Python implementations, but hopefully converting to TypeScript won't be difficult: https://github.com/leslie-wang/py-multicast-example/blob/master/mcast.py and this .这些都是 Python 的实现,但希望转换为 TypeScript 不会很困难: https://github.com/leslie-wang/py-multicast-example/blob/master/mcast.py这个.

Specifically, you need to:具体来说,您需要:

socket.bind((MCAST_GRP, MCAST_PORT))

which in your case should be ('239.255.255.250', 1900) , which are the default for UPnP.在您的情况下应该是('239.255.255.250', 1900) ,这是 UPnP 的默认设置。

Whereas, you are binding to "any available port" with socket.bind(0) .然而,您使用socket.bind(0)绑定到“任何可用端口”。

And I believe the parameters given to socket.addMembership() , should be the mcast group you want to receive messages from.而且我相信socket.addMembership()的参数应该是您要从中接收消息的 mcast 组。 The kernel, specifically the code that handles IP, needs to know to "forward" these packets upwards towards UDP. kernel,特别是处理 IP 的代码,需要知道将这些数据包向上“转发”到 UDP。


By the way... there's also the option of sniffing instead of listening, in your use-case, but it may require higher privileges.顺便说一句......在您的用例中,还可以选择嗅探而不是聆听,但它可能需要更高的权限。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM