multicast join group error : No such device

Discussion in 'Linux Networking' started by Pirabhu Raman, Nov 5, 2004.

  1. Hi,

    One of my multicast program dies on a specific set of machines with error No
    such Device when I try to join the multicast group with
    setsockopt(sock, IPPROTO_IP, IP_ADD_MEMBERSHIP, ...);
    The machines in question are running RHEL 3.0 (2.4.21-4ELsmp) and I also
    checked to find that multicast is enabled. Any pointers to resolve the issue
    is appreciated. I have attached a test program that reproduces the error.

    Thanks!


    #include <stdio.h>
    #include <stdlib.h>
    #include <arpa/inet.h>
    #include <sys/socket.h>
    #include <netinet/in.h>
    #include <netdb.h>
    #include <errno.h>
    #include <string.h>

    int main(void)
    {
    int sock;
    int one;
    int ret;
    struct sockaddr_in sock_addr;
    struct hostent *hent;
    struct ip_mreqn mreq;

    sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_IP);
    if(sock < 0)
    {
    perror("\nError in socket creation");
    exit(errno);
    }
    memset(&sock_addr, 0, sizeof(sock_addr));
    sock_addr.sin_family = AF_INET;
    sock_addr.sin_addr.s_addr = htonl(INADDR_ANY);
    sock_addr.sin_port = 0;

    one = 1;
    ret = setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (char *)&one,
    sizeof(one));
    if(ret < 0)
    {
    perror("\nError in reusing addr");
    exit(errno);
    }

    ret = bind(sock, (struct sockaddr *)&sock_addr, sizeof(sock_addr));
    if(ret < 0)
    {
    perror("\nError in bind");
    exit(errno);
    }

    hent = gethostbyname("224.1.1.11");
    if(!hent)
    {
    perror("\nInvalid address");
    exit(errno);
    }

    memset(&sock_addr, 0, sizeof(sock_addr));
    sock_addr.sin_family = AF_INET;
    memcpy(&sock_addr.sin_addr.s_addr, hent->h_addr, hent->h_length);
    if(!IN_MULTICAST(ntohl(sock_addr.sin_addr.s_addr)))
    {
    perror("\nInvalid address");
    exit(errno);
    }

    /* Join the multicast group */
    memset(&mreq, 0, sizeof(mreq));
    mreq.imr_multiaddr.s_addr = sock_addr.sin_addr.s_addr;
    mreq.imr_address.s_addr = htonl(INADDR_ANY);
    ret = setsockopt(sock, IPPROTO_IP, IP_ADD_MEMBERSHIP, &mreq,
    sizeof(mreq));
    if(ret<0)
    {
    perror("\nCannot join multicast group");
    exit(errno);
    }

    return 0;
    }
     
    Pirabhu Raman, Nov 5, 2004
    #1
    1. Advertisements

  2. Set imr_address to something other than zero. You need to specify the
    address of the interface on which you want to join this multicast
    group -- using the local address for broadcast-type interfaces, and
    the remote address for point-to-point interfaces.
     
    James Carlson, Nov 8, 2004
    #2
    1. Advertisements

  3. Thanks for the response. That fixed the issue.

    Thanks!
     
    Pirabhu Raman, Nov 9, 2004
    #3
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.