-1
boost::asio::ip::address_v4 local_interface = 
boost::asio::ip::address_v4::from_string(ip);
boost::asio::ip::multicast::outbound_interface option(local_interface);
sock.set_option(option); //set interface

It does not work! I used wireshark to capture data, but the data source interface is not the local_interface, why??? and How to make it working?

Eric Xu
  • 69
  • 4
  • struct in_addr interface_addr; interface_addr.S_un.S_addr = inet_addr(ip.c_str()); if (-1 == setsockopt(sock.native_handle(), IPPROTO_IP, IP_MULTICAST_IF, (char*)&interface_addr, sizeof(interface_addr))) { LOG_INFO("setsockopt IP_MULTICAST_IF error!"); } – Eric Xu Nov 22 '18 at 07:51
  • set IP_MULTICAST_IF also invalid! – Eric Xu Nov 22 '18 at 07:52
  • Can you please provide [MCVE](https://stackoverflow.com/help/mcve)? Not sure what you are trying to achieve. – karastojko Nov 22 '18 at 07:53
  • io_service io; ip::udp::socket sock(io); ip::udp::endpoint endpoint_group(ip::address::from_string(group_ip), port); sock.open(ip::udp::v4()); sock.set_option(boost::asio::socket_base::send_buffer_size(1024*1024)); sock.set_option(ip::multicast::enable_loopback(false)); sock.set_option(ip::multicast::outbound_interface(ip::address::from_string(ip).to_v4())); – Eric Xu Nov 22 '18 at 11:46
  • I have two computers, both have 2 network cards. I set the specific interface on one success, the other is invalid. but my friend used libuv library to set on the host success. The libuv inside use setsockopt set IP_MULTICAST_IF. I use setsockopt ,but failed! I suspect there's something wrong with the system? – Eric Xu Nov 22 '18 at 11:54
  • Still it lacks a detailed explanation what it does not work and what you did expect. – karastojko Nov 22 '18 at 12:49
  • On Windows system , I use winsock2.h and pragma coment ws2_32.lib 。 My code link WSOCK32.DLL(Already exists and I don't know how to introduce it ) and WS2_32.DLL 。 It seems like that: when I use setsockopt to set IP_MULTICAST_IF the WSOCK32.DLL will make it not work. But when I use ws2_32.DLL in a new and separate project, it works! So I changed my code use winsock.h instead of winsock2.h. By the way, there is no such problem on Linux system – Eric Xu Nov 27 '18 at 06:40
  • I don't know how to use winsock2.h to avoid this problem: WSOCK32.DLL and WS2_32.DLL both exist in a program. Setting IP_MULTICAST_IF socket will have no effect. https://stackoverflow.com/questions/7681703/how-to-multicast-send-to-first-nic – Eric Xu Nov 27 '18 at 06:45

1 Answers1

0

WSOCK32.DLL WS2_32.DLL both exist in a program. We can set VS project linker input: Ignore specific default libraries(the WSOCK32.DLL).

Eric Xu
  • 69
  • 4