int getsourcefilter (int s, uint32_t interface, const struct sockaddr *group, socklen_t grouplen, uint32_t *fmode, uint32_t *numsrc, struct sockaddr_storage *slist) { /* We have to create an struct ip_msfilter object which we can pass to the kernel. */ socklen_t needed = GROUP_FILTER_SIZE (*numsrc); int use_alloca = __libc_use_alloca (needed); struct group_filter *gf; if (use_alloca) gf = (struct group_filter *) alloca (needed); else { gf = (struct group_filter *) malloc (needed); if (gf == NULL) return -1; } gf->gf_interface = interface; memcpy (&gf->gf_group, group, grouplen); gf->gf_numsrc = *numsrc; /* We need to provide the appropriate socket level value. */ int result; int sol = __get_sol (group->sa_family, grouplen); if (sol == -1) { __set_errno (EINVAL); result = -1; } else { result = __getsockopt (s, sol, MCAST_MSFILTER, gf, &needed); /* If successful, copy the results to the places the caller wants them in. */ if (result == 0) { *fmode = gf->gf_fmode; memcpy (slist, gf->gf_slist, MIN (*numsrc, gf->gf_numsrc) * sizeof (struct sockaddr_storage)); *numsrc = gf->gf_numsrc; } } if (! use_alloca) { int save_errno = errno; free (gf); __set_errno (save_errno); } return result; }
int getipv4sourcefilter (int s, struct in_addr interface, struct in_addr group, uint32_t *fmode, uint32_t *numsrc, struct in_addr *slist) { /* We have to create an struct ip_msfilter object which we can pass to the kernel. */ socklen_t needed = IP_MSFILTER_SIZE (*numsrc); int use_alloca = __libc_use_alloca (needed); struct ip_msfilter *imsf; if (use_alloca) imsf = (struct ip_msfilter *) alloca (needed); else { imsf = (struct ip_msfilter *) malloc (needed); if (imsf == NULL) return -1; } imsf->imsf_multiaddr = group; imsf->imsf_interface = interface; imsf->imsf_numsrc = *numsrc; int result = __getsockopt (s, SOL_IP, IP_MSFILTER, imsf, &needed); /* If successful, copy the results to the places the caller wants them in. */ if (result == 0) { *fmode = imsf->imsf_fmode; memcpy (slist, imsf->imsf_slist, MIN (*numsrc, imsf->imsf_numsrc) * sizeof (struct in_addr)); *numsrc = imsf->imsf_numsrc; } if (! use_alloca) { int save_errno = errno; free (imsf); __set_errno (save_errno); } return result; }