# Problem with multicast client

## Azdo

Hello,

I have a multicast server and another computer acting as a client. The server sends packets from a Windows program. I have a code snippet that joins the multicast channel and tries to read the packets. However, it is not working in Gentoo while the same code is ok in Windows. Some information:

* My kernel supports multicast. The MULTICAST word is shown when issuing an 'ifconfig eth0':

```
eth0      Link encap:Ethernet

          BROADCAST MULTICAST  MTU:1500  Metric:1

          RX packets:0 errors:0 dropped:0 overruns:0 frame:0

          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0

          collisions:0 txqueuelen:1000 

          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

```

* The client program binds the UDP socket and joins the channel without errors:

```
DataSocket = socket(AF_INET, SOCK_DGRAM, 0);

struct sockaddr_in MySocketAddr;

memset(&MySocketAddr, 0, sizeof(MySocketAddr));

MySocketAddr.sin_family = AF_INET;

MySocketAddr.sin_port = htons(1001);

MySocketAddr.sin_addr = MyAddress; 

if (bind(DataSocket, (struct sockaddr *)&MySocketAddr, sizeof(struct sockaddr)) == -1)

{

  printf("[PacketClient] bind failed (error: )\n");

  return 0;

}

// join multicast group

struct ip_mreq Mreq;

Mreq.imr_multiaddr = MultiCastAddress;

Mreq.imr_interface = MyAddress;

retval = setsockopt(DataSocket, IPPROTO_IP, IP_ADD_MEMBERSHIP, (char *)&Mreq, sizeof(Mreq));

```

  where MyAddress is "224.0.0.1", since the server sends packets to 224.0.0.1:1001

* I added a route rule for the multicast packets:

```

route add 224.0.0.1 eth0

```

* Using wireshark, I can see the server sending the UDP packets to 224.0.0.1 and port 1001, but the call to recvfrom() from the client waits forever.

* When the client is running, it seems that the join is succesful:

```
# cat /proc/net/igmp 

Idx   Device    : Count Querier   Group    Users Timer   Reporter

1   lo        :     1      V3

            010000E0     1 0:00000000      0

4   eth0     :     1      V3

            010000E0     2 0:00000000      0

```

What else could be failing?

Thank you for any hint!

P.S.: A good hint would be how to know if my kernel is discarding those packets. I have no firewall set up.

----------

## Ant P.

You shouldn't need to manually add any routes. Try it without that if you haven't already done so.

Also you might want to see whether other multicast stuff (e.g. avahi) works first.

----------

## Azdo

You are right, Ant_P. No other routing needed. I indeed tried my multicast setup with VLC and it worked fine, so it's working for my system.

I found a code snippet at http://www.tenouk.com/Module41c.html implementing a multicast client and server. I could narrow down the problem to my program. For the snippet, I can see with Wireshark that join requests to the multicast group are sent. This is not happening for my program. The only difference is that my program tries to join 224.0.0.1 while the snippet does it to 226.0.0.1.

This is very weird, 224.0.0.1 should be a valid multicast address and furthermore, the socket option function doesn't return any error. What could be happening?

----------

## Azdo

Ooops, I think I have a big problem. Following the weird behaviour of the 224.0.0.1, I arrived to this page of the multicast HowTo that says that addresses from 224.0.0.0 to 224.0.0.255 are reserved for local administrative purposes, so they are "never" forwarded by multicast routers, http://tldp.org/HOWTO/Multicast-HOWTO-2.html

It seems I have to talk with the writers of the server for them to change the multicast address they are using to stream their data or make a ssh tunneling hack in order to feed my program.

----------

## Azdo

What I have to do in order to route the packets sent to 224.0.0.1 to 226.0.0.1? I don't know if I have to use route or iptables. I fail to set the correct parameters to accomplish this.

----------

