On Tue, 28 Mar 2000, Jeff Kann wrote:

> You need to join the multicast groups in order to receive the multicast
> traffic for that group (unless you run the machine as a multicast router).
> To join/leave a mcast group, use IP_ADD_MEMBERSHIP and IP_DROP_MEMBERSHIP
> socket options and pass ip_mreq structure as its parameter.

I'm using IP_ADD_MEMBERSHIP in the receive routine, it's the last
setsockopt (), just after initializing structure ip_mreq. Do I need it
anywhere else?

> 
> Jeff
> 
> On Tue, 28 Mar 2000, Matias Freytes 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]
> - 
> 
>  
> -----BEGIN PGP PUBLIC KEY BLOCK-----
> Version: PGP 6.5.2
> http://www.isi.edu/~kann/Kann.asc
> -----END PGP PUBLIC KEY BLOCK-----
> 

-
To unsubscribe from this list: send the line "unsubscribe linux-net" in
the body of a message to [EMAIL PROTECTED]

Reply via email to