Back to index

glibc  2.9
setsourcefilter.c File Reference
#include <alloca.h>
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include <netinet/in.h>
#include <sys/socket.h>

Go to the source code of this file.


int __get_sol (int af, socklen_t len)
int setsourcefilter (int s, uint32_t interface, const struct sockaddr *group, socklen_t grouplen, uint32_t fmode, uint32_t numsrc, const struct sockaddr_storage *slist)

Function Documentation

int __get_sol ( int  af,
socklen_t  len 

Definition at line 61 of file getsourcefilter.c.

  int first_size_sol = -1;

  for (size_t cnt = 0; cnt < NSOL_MAP; ++cnt)
      /* Just a test so that we make sure the special value used to
        signal the "we have so far no socket level value" is OK.  */
      assert (sol_map[cnt].sol != -1);

      if (len == sol_map[cnt].size)
         /* The size matches, which is a requirement.  If the family
            matches, too, we have a winner.  Otherwise we remember the
            socket level value for this protocol if it is the first
            match.  */
         if (af == sol_map[cnt].af)
           /* Bingo!  */
           return sol_map[cnt].sol;

         if (first_size_sol == -1)
           first_size_sol = sol_map[cnt].sol;

  return first_size_sol;

Here is the caller graph for this function:

int setsourcefilter ( int  s,
uint32_t  interface,
const struct sockaddr group,
socklen_t  grouplen,
uint32_t  fmode,
uint32_t  numsrc,
const struct sockaddr_storage slist 

Definition at line 34 of file setsourcefilter.c.

  /* We have to create an struct ip_msfilter object which we can pass
     to the kernel.  */
  size_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);
      gf = (struct group_filter *) malloc (needed);
      if (gf == NULL)
       return -1;

  gf->gf_interface = interface;
  memcpy (&gf->gf_group, group, grouplen);
  gf->gf_fmode = fmode;
  gf->gf_numsrc = numsrc;
  memcpy (gf->gf_slist, slist, numsrc * sizeof (struct sockaddr_storage));

  /* 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;
    result = __setsockopt (s, sol, MCAST_MSFILTER, gf, needed);

  if (! use_alloca)
      int save_errno = errno;
      free (gf);
      __set_errno (save_errno);

  return result;

Here is the call graph for this function: