I've attached a self contained program that exhibits the problem. I'm hoping I've merely missed some detail... Wes -- http://www.woahnelly.net/~wes/ OpenPGP key = 0xA5CA6644 fingerprint = FDE5 21D8 9D8B 386F 128F DF52 3F52 D582 A5CA 6644
/** \file A tool for subscribing to multicast addresses. */ #include <stdlib.h> #include <iostream> #include <unistd.h> #include <net/if.h> #include <netinet/in.h> #include <netdb.h> #include <arpa/inet.h> #include <sys/ioctl.h> #include <sys/time.h> #include <sys/socket.h> #include <sys/un.h> int main(int argc, char **argv) { if (argc != 4) { std::cout << "usage: mcasttest dev mcastaddr port" << std::endl; return 1; } const char *dev = argv[1]; const char *mcastaddr = argv[2]; int port = atoi(argv[3]); int fd = socket(AF_INET, SOCK_DGRAM, 0); try { // reuse socket if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, reinterpret_cast<const char*>(&port), sizeof(port)) != 0) throw "couldn't set socket to reuse"; // bind socket struct sockaddr_in saddr; saddr.sin_family = AF_INET; saddr.sin_port = htons(port); saddr.sin_addr.s_addr = htonl(INADDR_ANY); if (bind(fd, (struct sockaddr *) &saddr, sizeof(saddr)) != 0) throw "couldn't bind address"; // join mcast group struct ip_mreq mreq; bzero(&mreq, sizeof(mreq)); if (inet_pton(AF_INET, mcastaddr, &mreq.imr_multiaddr) <= 0) throw "couldn't set mcast address"; struct ifreq ifreq; strncpy(ifreq.ifr_name, dev, IFNAMSIZ); if (ioctl(fd, SIOCGIFADDR, &ifreq) < 0) throw "couldn't get iface address"; memcpy(&mreq.imr_interface, &((struct sockaddr_in *) &ifreq.ifr_addr)->sin_addr, sizeof(struct in_addr)); if (setsockopt(fd, IPPROTO_IP, IP_ADD_MEMBERSHIP, reinterpret_cast<const char*>(&mreq), sizeof(mreq)) != 0) throw "couldn't join mcast group"; } catch (const char *err) { std::cout << "error: " << err << std::endl; return 1; } const unsigned int bufsize = 1024; char buf[bufsize]; size_t amt = 0; while ( (amt = read(fd, buf, bufsize)) > 0) std::cout << "got " << amt << " bytes" << std::endl; return 0; }