开发者

setsockopt is trying to send IGMP packet to interface down

I am working on a system that has two different interfaces with same IPs and routing table (for redundancy purpose).

At every specific time only one interface is up.

I'm using:

setsockopt(MSock, IPPROTO_IP, IP_ADD_MEMBERSHIP, &ipMreq, sizeof(ipMreq));

to send IGMP join messages.

I expect that if I'll send IGM开发者_运维问答P message from specific interface IP the kernel will find the first interface that is UP and will send the message from it, but actually the message is sent from the first interface that has this IP (even if it's down).

Is my assumption correct in this case?

Any way what can I do to make it work?

Thanks, Itamar


When populating your struct ip_mreq ipMreq; you can specify an interface . If you use htonl(INADDR_ANY); it will bind to default interface which may be different than what you want. Try like this by giving an ip address explicitely.

ipMreq.imr_multiaddr.s_addr = inet_addr("226.0.0.1");//multicast group
ipMreq.imr_interface.s_addr = inet_addr("192.168.2.235");//interface name
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜