#include <errno.h> #include <sys/socket.h> #define SA struct sockaddr int mcast_block_source(int sockfd, const SA *src, socklen_t srclen,const SA *grp, socklen_t grplen) { #ifdef MCAST_BLOCK_SOURCE struct group_source_req req; req.gsr_interface = 0; if (grplen > sizeof(req.gsr_group) || srclen > sizeof(req.gsr_source)) { errno = EINVAL; return -1; } memcpy(&req.gsr_group, grp, grplen); memcpy(&req.gsr_source, src, srclen); return (setsockopt(sockfd, family_to_level(grp->sa_family), MCAST_BLOCK_SOURCE, &req, sizeof(req))); #else switch (grp->sa_family) { #ifdef IP_BLOCK_SOURCE case AF_INET: { struct ip_mreq_source mreq; memcpy(&mreq.imr_multiaddr, &((struct sockaddr_in *) grp)->sin_addr, sizeof(struct in_addr)); memcpy(&mreq.imr_sourceaddr, &((struct sockaddr_in *) src)->sin_addr, sizeof(struct in_addr)); mreq.imr_interface.s_addr = htonl(INADDR_ANY); return(setsockopt(sockfd, IPPROTO_IP, IP_BLOCK_SOURCE,&mreq, sizeof(mreq))); } #endif #ifdef IPV6 /* IPv6 source-specific API is MCAST_BLOCK_SOURCE */ case AF_INET6: {} #endif default: { errno = EAFNOSUPPORT; return(-1); } } #endif }