如何组播(发送)到第一个NIC? [英] How to Multicast (send) to first NIC?

查看:187
本文介绍了如何组播(发送)到第一个NIC?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近发现,如果我有一个拨号连接(这是用于自助服务终端)和一个局域网连接,则在建立拨号连接(可以访问Internet)时,我的多播sendto将默认为拨号而不是我的LAN NIC.这使多播发送到拨号连接,而不是到我的具有多个多播订户的LAN.

I found recently that if I have a dial-up connection (this is for a kiosk) and a local area network connection, when the dial-up connection is established (with internet access), my multicast sendto would default to the dial-up rather than my LAN NIC. This made the multicast go out to the dial-up connection instead rather than to my LAN which has several multicast subscribers.

我了解我需要使用IP_MULTICAST_IF来设置多播套接字上的接口.问题是如何枚举接口,以及如何在setsockopt中使用IP_MULTICAST_IF? 在Windows XP Embedded信息亭上,总是只有一个局域网连接NIC.如何获取该接口并将其IP地址(这是IP_MULTICAST_IF的期望值?)传递给setsockopt?

I understand that I need to use IP_MULTICAST_IF to set the interface on my multicast socket. Question is how do I enumerate the interfaces and how do I use IP_MULTICAST_IF in setsockopt? On the kiosk Windows XP Embedded, there's always going to be just one local area connection NIC. How do I get this interface and pass its IP address (is this what IP_MULTICAST_IF is expecting??) to setsockopt?

推荐答案

显然,如果使用wsock32.dll代替ws2_32.dll,则setsockoptIP_MULTICAST_IF不起作用.当以1.0.0.0作为IP地址时,我以为我做错了,即使这是我使用setsockopt设置的其他地址.有趣的是,在调用IP_MULTICAST_IF之前,它将返回0.0.0.0,因此setsockopt`确实做了一些更改,只是不正确.

Apparently setsockopt and IP_MULTICAST_IF don't work if wsock32.dll is used instead of ws2_32.dll. I thought I was doing it wrong when I kept getting 1.0.0.0 as the IP address even when it was something else that I've set with setsockopt. Funny thing is, before the call to IP_MULTICAST_IF, it would return 0.0.0.0, so setsockopt` did change something, just not correctly.

其他曾在2004年遇到过同样问题的人- http://us.generation-nt.com/ip-multicast-problem-help-37595922.html .当我们#include "winsock2.h"时,我们需要使用ws2_32.dll.但是,对于C ++ Builder,当我们使用winsock2.h时,不可能使用ws2_32.dll-RTL在wsock32.dll中隐式链接,即使您明确指定了#pragma comment(lib, "ws2_32.lib"),也无法链接ws2_32.dll. Embarcadero确实需要解决此问题! RTL团队中的某个人必须已经决定隐式包含wsock32.dll是 clever .它所做的唯一聪明" 事情是用户不必在代码中包含一行-#pragma comment(lib, "wsock32.lib").在这种情况下,它们可能还包括人类已知的每个DLL文件.

Someone else who had this same problem way back in 2004 - http://us.generation-nt.com/ip-multicast-problem-help-37595922.html. When we #include "winsock2.h" we need to use ws2_32.dll. However, with C++ Builder, it's impossible to use ws2_32.dll when we use winsock2.h - the RTL implicitly links in wsock32.dll and you can't link ws2_32.dll even if you explicitly specify #pragma comment(lib, "ws2_32.lib"). Embarcadero really need to fix this! Someone in the RTL team must've decided it's clever to implicitly include wsock32.dll. The only 'clever' thing it did was users didn't have to include one line in their code - #pragma comment(lib, "wsock32.lib"). While they're at that, they might as well include every single DLL files known to mankind.

这篇关于如何组播(发送)到第一个NIC?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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