来自特定网卡的 UDP 多播 [英] UDP multicast from specific network card

查看:39
本文介绍了来自特定网卡的 UDP 多播的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一些网络专家来帮助我解决问题.我有很多计算机运行我的软件,它使用 UDP 多播.如果计算机仅连接到一个网络(网络 A),这可以正常工作.我的计算机(也运行上述软件)将在端口 XXXX 上侦听多播.这台计算机有两个网卡,当我将它连接到另一个网络 B 网络时,我的软件就出问题了.问题是我不知道给定的多播来自哪个网络.如果我发送多播,我不能告诉它使用网络 A 而不是网络 B,反之亦然.

I'm looking for some networking gurus to help me with a problem. I have many computers running my software which uses UDP multicasting. This works fine if the computers are connected ONLY to one network (network A). My computer (which is also running said software) will listen on port XXXX for the multicasts. This computer has two network cards and when I connect it to another network, network B, my software goes haywire. The problem is that I do not know what network a given multicast came from. And if I send out a multicast, I cannot tell it to use network A instead of network B or vice versa.

我的问题:

  1. 有没有办法区分来​​自不同网络的数据包??
  2. 有没有办法将多播发送到网络 A 而不是网络 B?

我正在使用 C++ 和 Win32 套接字.感谢所有回复的人.

I'm using C++ and Win32 sockets. Thanks to anyone that replies.

推荐答案

您应该在您加入组的一个接口上侦听多播数据包.您应该明确设置用于发送多播数据包的接口(否则它们将作为其他所有内容、默认路由等进行路由).两者都是通过 setsockopt 调用完成的.这里有一些链接供您参考:

You should listen for multicast packets on one interface where you joined the group. You should explicitly set the interface used for sending the multicast packets (otherwise they are routed as everything else, default route, etc.). Both are accomplished via setsockopt calls. Here are some links for you:

  • Multicast programming - talks about setting "send" interface,
  • IP Multicast Extensions - talks about both "send" and "receive" interfaces.

免责声明:这些链接无疑是以 Unix 为中心的,因此您的 Windows 里程可能会有所不同 :)

Disclaimer: the links are admittedly Unix-centric, so your Windows mileage may vary :)

这篇关于来自特定网卡的 UDP 多播的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆