Multicast not working in linux. - Unix

This is a discussion on Multicast not working in linux. - Unix ; I have created a multicast application. This works fine on windows but it fails on linux. On linux machine "sendto" API in multicast client application throws "Invalid argument" . I have used 1)getaddrinfo(0 , then socket(), then setsockopt() to set ...

+ Reply to Thread
Results 1 to 6 of 6

Thread: Multicast not working in linux.

  1. Multicast not working in linux.

    I have created a multicast application. This works fine on windows
    but
    it fails on linux. On linux machine "sendto" API in multicast client
    application throws "Invalid argument" .

    I have used
    1)getaddrinfo(0 , then socket(), then setsockopt() to set TTL (value
    is 1) of multicast packet, and then I used sendto().
    2)multicast IP address is FF02::1


    I tried to specify scope_id as follows to resolve this issue but it
    didnt work
    1)multicast IP address is FF02::1%
    2)multicast IP address is FF02::1%
    3)multicast IP address is FF02::1 and specified scope_id as follows
    ((struct sockaddr_in6 *) (mcastaddr->ai_addr))->sin6_scope_id=3 ;


    Please help.



  2. Re: Multicast not working in linux.

    On Aug 5, 12:21*pm, rashmising...@hotmail.com wrote:
    > I have created a multicast application. This works fine on windows
    > but
    > it fails on linux. On linux machine "sendto" API in multicast client
    > application throws "Invalid argument" .
    >
    > I have used
    > 1)getaddrinfo(0 , *then socket(), then setsockopt() to set TTL (value
    > is 1) of multicast packet, and then I used sendto().
    > 2)multicast IP address is FF02::1
    >
    > I tried to specify scope_id *as follows to resolve this issue but it
    > didnt work
    > 1)multicast IP address is FF02::1%
    > 2)multicast IP address is FF02::1%
    > 3)multicast IP address is FF02::1 and specified scope_id as follows
    > ((struct sockaddr_in6 *) (mcastaddr->ai_addr))->sin6_scope_id=3 ;
    >
    > Please help.


    You'd better post codes here so folks can help.

    Bin

  3. Re: Multicast not working in linux.

    rashmisingh02@hotmail.com wrote:
    > I have created a multicast application. This works fine on windows
    > but
    > it fails on linux. On linux machine "sendto" API in multicast client
    > application throws "Invalid argument" .
    >
    > I have used
    > 1)getaddrinfo(0 , then socket(), then setsockopt() to set TTL (value
    > is 1) of multicast packet, and then I used sendto().
    > 2)multicast IP address is FF02::1


    Dit you tell the kernel what multicast group to join ?

    Something like :

    setsockopt (socket, IPPROTO_IP, IP_ADD_MEMBERSHIP, &mreq, sizeof(mreq));


    Igmar

  4. Re: Multicast not working in linux.

    On Aug 5, 12:44*pm, Igmar Palsenberg wrote:
    > rashmising...@hotmail.com wrote:
    > > I have created a multicast application. This works fine on windows
    > > but
    > > it fails on linux. On linux machine "sendto" API in multicast client
    > > application throws "Invalid argument" .

    >
    > > I have used
    > > 1)getaddrinfo(0 , *then socket(), then setsockopt() to set TTL (value
    > > is 1) of multicast packet, and then I used sendto().
    > > 2)multicast IP address is FF02::1

    >
    > Dit you tell the kernel what multicast group to join ?
    >
    > Something like :
    >
    > setsockopt (socket, IPPROTO_IP, IP_ADD_MEMBERSHIP, &mreq, sizeof(mreq));
    >
    > Igmar


    Yes I have used setsockopt() in my code to tell the kernel what
    multicast group to join.


  5. Re: Multicast not working in linux.

    Igmar Palsenberg schrieb:
    > rashmisingh02@hotmail.com wrote:
    >> I have created a multicast application. This works fine on windows
    >> but
    >> it fails on linux. On linux machine "sendto" API in multicast client
    >> application throws "Invalid argument" .
    >>
    >> I have used
    >> 1)getaddrinfo(0 , then socket(), then setsockopt() to set TTL (value
    >> is 1) of multicast packet, and then I used sendto().
    >> 2)multicast IP address is FF02::1

    >
    > Dit you tell the kernel what multicast group to join ?
    >
    > Something like :
    >
    > setsockopt (socket, IPPROTO_IP, IP_ADD_MEMBERSHIP, &mreq, sizeof(mreq));
    >
    >
    > Igmar


    I had an issues with multicast sockets, where CYGWIN behaved
    incompatible to the rest of the world. I don't remember the exact
    symptoms, but now my code looks like this:


    #ifdef __CYGWIN__
    MA.sin_addr.s_addr = htonl(INADDR_ANY);
    mreq.imr_multiaddr.s_addr = inet_addr(McastAddr);
    mreq.imr_interface.s_addr = htonl(INADDR_ANY);
    #else
    if (-1 == inet_pton(AF_INET, McastAddr, &MA.sin_addr))
    error("cannot set multicast address:
    %s\n",strerror(errno));
    memcpy(&mreq.imr_multiaddr.s_addr,(void
    *)&MA.sin_addr,sizeof(struct in_addr));
    mreq.imr_interface.s_addr = htonl(INADDR_ANY);
    #endif
    if (-1 == bind(sock,(struct sockaddr *)&MA,sizeof(MA)))
    error("cannot bind socket: %s\n",strerror(errno));
    if (-1 ==
    setsockopt(sock,IPPROTO_IP,IP_ADD_MEMBERSHIP,&mreq,sizeof(mreq)))
    error("could not join multicast group:
    %s\n",strerror(errno));


    /* ... */

    #if defined(__CYGWIN__)
    num = recvfrom(sock,&msg,sizeof(msg)-1,0,0,0);
    #else
    num = recvfrom(sock,&msg,sizeof(msg)-1,0,(struct
    sockaddr *)&from,&len);
    #endif


    HTH,
    Thomas

  6. Re: Multicast not working in linux.

    On Aug 6, 2:48*pm, Thomas Maier-Komor wrote:
    > Igmar Palsenberg schrieb:
    >
    >
    >
    >
    >
    > > rashmising...@hotmail.com wrote:
    > >> I have created a multicast application. This works fine on windows
    > >> but
    > >> it fails on linux. On linux machine "sendto" API in multicast client
    > >> application throws "Invalid argument" .

    >
    > >> I have used
    > >> 1)getaddrinfo(0 , *then socket(), then setsockopt() to set TTL (value
    > >> is 1) of multicast packet, and then I used sendto().
    > >> 2)multicast IP address is FF02::1

    >
    > > Dit you tell the kernel what multicast group to join ?

    >
    > > Something like :

    >
    > > setsockopt (socket, IPPROTO_IP, IP_ADD_MEMBERSHIP, &mreq, sizeof(mreq));

    >
    > > Igmar

    >
    > I had an issues with multicast sockets, where CYGWIN behaved
    > incompatible to the rest of the world. I don't remember the exact
    > symptoms, but now my code looks like this:
    >
    > #ifdef __CYGWIN__
    > * * * * * * * * *MA.sin_addr.s_addr = htonl(INADDR_ANY);
    > * * * * * * * * *mreq.imr_multiaddr.s_addr = inet_addr(McastAddr);
    > * * * * * * * * *mreq.imr_interface.s_addr = htonl(INADDR_ANY);
    > #else
    > * * * * * * * * *if (-1 == inet_pton(AF_INET, McastAddr, &MA.sin_addr))
    > * * * * * * * * * * * * *error("cannot set multicast address:
    > %s\n",strerror(errno));
    > * * * * * * * * *memcpy(&mreq.imr_multiaddr.s_addr,(void
    > *)&MA.sin_addr,sizeof(struct in_addr));
    > * * * * * * * * *mreq.imr_interface.s_addr = htonl(INADDR_ANY);
    > #endif
    > * * * * * * * * *if (-1 == bind(sock,(struct sockaddr *)&MA,sizeof(MA)))
    > * * * * * * * * * * * * *error("cannot bind socket: %s\n",strerror(errno));
    > * * * * * * * * *if (-1 ==
    > setsockopt(sock,IPPROTO_IP,IP_ADD_MEMBERSHIP,&mreq,sizeof(mreq)))
    > * * * * * * * * * * * * *error("could not join multicast group:
    > %s\n",strerror(errno));
    >
    > /* ... */
    >
    > #if defined(__CYGWIN__)
    > * * * * * * * * *num = recvfrom(sock,&msg,sizeof(msg)-1,0,0,0);
    > #else
    > * * * * * * * * *num = recvfrom(sock,&msg,sizeof(msg)-1,0,(struct
    > sockaddr *)&from,&len);
    > #endif
    >
    > HTH,
    > Thomas- Hide quoted text -
    >
    > - Show quoted text -


    Thanks for response. Please note that I am facing issue in case of
    IPv6 multicast.Is there anything specific I have to do for IPv6
    multicast?

+ Reply to Thread