can't join a udp/ip multicast group

Below part of my code. Previously I already successfully create the socket.


// If receiving from a multicast group, register for it.
if (inet_addr(IconCtrlStruct.StringParam[1]) > 0)
{
if ((inet_addr(IconCtrlStruct.StringParam[1]) & inet_addr(“240.0.0.0”)) == inet_addr(“224.0.0.0”))
{
mreq.imr_multiaddr.s_addr = inet_addr(IconCtrlStruct.StringParam[1]);
mreq.imr_interface.s_addr = INADDR_ANY;
// Have the multicast socket join the multicast group
if ([color=darkred]setsockopt(sd, IPPROTO_IP, IP_ADD_MEMBERSHIP, (char*)&mreq, sizeof(mreq)) == -1)
{
MyPrint("%s: ERROR: Could not join multicast group (%d), %s\n group IP is %s \n", PROGNAME, errno,strerror(errno),IconCtrlStruct.StringParam[1]);

return(EIO);
}


I have the errno=249 for setsockopt:Can’t assign requested address .

Is there anything wrong with line:
mreq.imr_interface.s_addr = INADDR_ANY; ?

Zoug,

Nope, the INADDR_ANY is what the doc’s specify for joining a multicast group on the default interface (search for IP_ADD_MEMBERSHIP in the helpviewer). The only caveat is that you can’t be multihomed (multiple network cards) if you use INADDR_ANY.

Are you sure the IconCtrlStruct.StringParam[1] value is correct?

Tim

Thanks Tim,

The IconCtrlStruct.StringParam[1] is a string, here I set it “234.5.6.7”. I’m sure it’s correct.
I’ll check if there are multi NIC in my machine.

Zoug

Ahhhh, Yes, I found that I have 2 NIC’s on my machine.


Class = Network (Ethernet)
Vendor ID = 8086h, Intel Corporation
Device ID = 103ah, Unknown Unknown
PCI index = 0h
PCI Mem Address = de120000h enabled
PCI IO Address = c400h enabled
PCI Int Pin = INT A
Interrupt line = 10

Class = Network (Ethernet)
Vendor ID = 11b0h, V3 Semiconductor Inc.
Device ID = 4750h, Unknown Unknown
PCI index = 0h
PCI Mem Address = de000000h enabled
PCI Mem Address = dc000000h enabled
PCI Mem Address = dd000000h enabled
PCI Int Pin = INT A
Interrupt line = 11


How to disable one?

Zoug

Zoug,

Are you sure you want to disable one?

If your running photon, you can run the utility ‘phlip’ as root and then click the disable device box on the NIC you want to disable. Or you can manually edit the file /etc/net.cfg. I think you just add disable or disabled under the NIC you want to disable (I hope someone who knows will post the exact wording if I’ve gotten it wrong).

On the other hand if you want to support 2 or more NIC cards (I am not sure what your final setup will be) you just have to replace the INADDR_ANY with the IP address of your NIC card then make the setsockopt call. If both NIC cards can be used to reach the group you’d have to make the setsockopt call twice, once for each NIC.

Tim