Make sure you bind to multicast address in the
receiver
program. Only time you need to specify interface
address in the receiver is during filling up
mr.imr_interface.s_addr. After making these changes
you should be able to see the packets. Also I am not
sure if you need to "connect". So you might comment
that out too.

-pkd

--- Matias Freytes <[EMAIL PROTECTED]>
wrote:
> Hello,
>       As you'll notice I'm new to this. I want to
> read/write to/from
> multicast adresses. I've followed the examples from
> Multicast-HOWTO, but I
> must be missing something. I'm sending/receiving
> from the same host (don't
> have access to another one yet) and I've tried LOOP
> on and LOOP off. There
> are no assertion fails, but the receiver never gets
> anything.
> These are the send and receive routines:
> 
> 
> SEND routine
>
----------------------------------------------------------
> #include <assert.h>
> #include <stdio.h>
> #include <sys/socket.h>
> #include <netinet/in.h>
> 
> int main(void)
> {     struct sockaddr_in da, la;
>       int ss;
>       unsigned char loop = 1, ttl=1;
>       int r;
>       
>       da.sin_family = AF_INET;
>       da.sin_port = htons (5004);
>       r = inet_aton ("224.168.1.1", &(da.sin_addr));
>       assert (r>=0);
> 
>       la.sin_family = AF_INET;
>       la.sin_port = htons (5004);
>       r = inet_aton ("192.168.1.1", &(la.sin_addr));
>       assert (r>=0);
> 
>       /* send configuration */
>       ss = socket(AF_INET, SOCK_DGRAM, 0);
>       assert (ss>=0);
>       r = connect (ss, (struct sockaddr*)&da,
> sizeof(da));
>       assert (r>=0);
>       r = setsockopt (ss, IPPROTO_IP, IP_MULTICAST_LOOP,
> &loop, sizeof(loop));
>       assert (r>=0);
>       r = setsockopt (ss, IPPROTO_IP, IP_MULTICAST_TTL,
> &ttl, sizeof(ttl));
>       assert (r>=0);
>       r = setsockopt (ss, IPPROTO_IP, IP_MULTICAST_IF,
> &(la.sin_addr),
>                       sizeof(la.sin_addr));
>       assert (r>=0);
> 
>       send (ss, "Msg one\0", 8, 0);
>       send (ss, "Msg two\0", 8, 0);
>       send (ss, "Msg three\0", 10, 0);
>       send (ss, "Msg four\0", 9, 0);
>       send (ss, "Msg five\0", 9, 0);
> 
>       close (ss);
>       return (0);
> }
>
-------------------------------------------------------------
> 
>
=*=*=*=*=*=*=*=*=*==*=*=*=*=*=*=*=*=*=*==*=*=*==*=*=*=*=*=*=*=*==*
> 
> RECEIVE routine
>
--------------------------------------------------------------
> #include <assert.h>
> 
> #include <stdio.h>
> #include <sys/socket.h>
> #include <sys/types.h>
> #include <netinet/in.h>
> 
> int main(void)
> {     struct sockaddr_in da, la;
>       struct ip_mreq mr;
>       int rs, r, n;
>       unsigned char msg[100];
>       
>       da.sin_family = AF_INET;
>       da.sin_port = htons (5004);
>       r = inet_aton ("224.168.1.1", &(da.sin_addr));
>       assert (r>=0);
> 
>       la.sin_family = AF_INET;
>       la.sin_port = htons (5004);
>       r = inet_aton ("192.168.1.1", &(la.sin_addr));
>       assert (r>=0);
> 
>       /* recv configuration */
>       rs = socket(AF_INET, SOCK_DGRAM, 0);
>       assert (rs>=0);
>       r = bind (rs, (struct sockaddr*)&la, sizeof(la));
>       assert (r>=0);
>       r = connect (rs, (struct sockaddr*)&da,
> sizeof(da));
>       assert (r>=0);
>       mr.imr_multiaddr.s_addr = da.sin_addr.s_addr;
>       mr.imr_interface.s_addr = la.sin_addr.s_addr;
>       r = setsockopt (rs, IPPROTO_IP, IP_ADD_MEMBERSHIP,
> &mr, sizeof(mr));
>       assert (r>=0);
> 
>       n = 0;
>       while (n<4) {
>               r = recv (rs, msg, 100, 0);
>               printf ("MSG: %s\n", msg);
>               n++;
>       }
> }
> 
>
*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
> I run the receive routine, switch to another
> terminal and run the send
> routine. Send routine finishes, but receive routine
> never get anything.
> Any hints?
> 
> Thank you.
> 
> --------------
> Matias Freytes
> Laboratorio de Comunicaciones Digitales
> Universidad Nacional de Cordoba
> Argentina
> 
> 
> -
> To unsubscribe from this list: send the line
> "unsubscribe linux-net" in
> the body of a message to [EMAIL PROTECTED]
> 
> 

__________________________________________________
Do You Yahoo!?
Talk to your friends online with Yahoo! Messenger.
http://im.yahoo.com
-
To unsubscribe from this list: send the line "unsubscribe linux-net" in
the body of a message to [EMAIL PROTECTED]

Reply via email to