Can I get data from more than one multicast group on the same socket?
For instance:
void AddGroup(int sock, const char* mc_addr_str, int mc_port, const char* interface) { struct sockaddr_in mc_addr; memset(&mc_addr, 0, sizeof(mc_addr)); mc_addr.sin_family = AF_INET; mc_addr.sin_addr.s_addr = inet_addr(mc_addr_str); mc_addr.sin_port = htons(mc_port); if ((bind(sock, (struct sockaddr *) &mc_addr, sizeof(mc_addr))) < 0) { perror("bind() failed"); exit(1); }
This code works when I add one multicast group. But when I try to add another, bind fails. I do not quite understand why the bunch should be there in the first place? (but the code does not work without it).
Ideally, I would like to call AddGroup several times on the same socket. Is it possible? Or do I need one socket per group and then just use polling?
source share