How to multicast (send) to the first network card?

I recently discovered that if I have a dial-up connection (this is for a kiosk) and a local network connection when an installation connection (with Internet access) is established, my default multicast forwarding will match and not my network adapter. This made multicast instead of remote access, and not to my local network, which has several multicast subscribers.

I understand that I need to use IP_MULTICAST_IF to set the interface on my multicast socket. The question is how do I list the interfaces and how to use IP_MULTICAST_IF in setsockopt? There will always be only one NIC on the Windows XP Embedded Kiosk. How to get this interface and pass its IP address (is that what IP_MULTICAST_IF expects?) For setsockopt?

+3
source share
2 answers

IP_MULTICAST_IF and IP_MULTICAST_IF not work if wsock32.dll 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 installed using setsockopt. Funny, before calling IP_MULTICAST_IF it will return 0.0.0.0 , so setsockopt` will change something, it’s just not right.

Someone who had this problem, 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 is not possible to use ws2_32.dll when we use winsock2.h - RTL implicitly refers to wsock32.dll, and you cannot link ws2_32.dll, even if you explicitly specify #pragma comment(lib, "ws2_32.lib") . Embarcadero really needs to fix it! Someone from the RTL team must have decided that he was smart to implicitly enable wsock32.dll. The only β€œsmart” thing she did was not to include one line in her code - #pragma comment(lib, "wsock32.lib") . Although they are, they can also include all the DLL files known to mankind.

+3
source

Use GetAdaptersAddresses () to list all available interface IP addresses.

IP_MULTICAST_IF is for IPv4 addresses only. It expects you to pass the DWORD value containing the required IPv4 address (in byte order of the network) to setsockopt() , for example:

 DWORD dwIP = ...; setsockopt(sock, IPPROTO_IP, IP_MULTICAST_IF, (char *)&dwIP, sizeof(dwIP)); 
0
source

Source: https://habr.com/ru/post/1401364/


All Articles