getsourcefilter()--Retrieve a Socket's Multicast Filter


  Syntax
  #include <netinet/in.h>

  int getsourcefilter(int socket_descriptor,
                      uint32_t interface,
                      struct sockaddr *group_address,
                      socklen_t address_length,
                      uint32_t *filter_mode,
                      uint32_t *number_sources,
                      struct sockaddr_storage *source_list)

  Service Program Name: QSOSRV1IP6

  Default Public Authority: *USE

  Threadsafe: Yes

The getsourcefilter() function retrieves the multicast filtering state for a tuple that consists of a socket (socket_descriptor), an interface (interface), and a multicast group (group_address).


Parameters

socket_descriptor
(Input) A descriptor for a socket of type SOCK_DGRAM or SOCK_RAW.
interface
(Input) Interface index (IPv6) or the interface address (IPv4) of the interface.
group_address
(Input) Pointer to structure sockaddr that contains the multicast address.

The structure sockaddr is defined in <sys/socket.h>.

The BSD 4.3 structure is:

      struct sockaddr {
         u_short sa_family;
         char    sa_data[14];
      };

The BSD 4.4/UNIX 98 compatible structure is:

      typedef uchar   sa_family_t;

      struct sockaddr
      {
        uint8_t       sa_len;
        sa_family_t   sa_family;
        char          sa_data[14];
      };

The BSD 4.4 sa_len field is the length of the address. The sa_family field identifies the address family to which the address belongs, and sa_data is the address whose format is dependent on the address family.

Note: See the usage notes about using different address families with sockaddr_storage.

address_length
(Input) Size of the structure pointed to by group_address.
filter_mode
(Output) Value indicating the filter mode, MCAST_INCLUDE or MCAST_EXCLUDE.
number_sources
(I/O) This parameter is a value-result field. The caller passes a pointer to the number of addresses that can be stored in the source_list array. On return from the call, number_sources will contain the total number of source addresses available in the filter.
source_list
(I/O) A pointer to structure sockaddr_storage where the array of source addresses in the filter are to be stored. This list will only return as many entries as was initially specified for number_sources.

The structure sockaddr_storage is defined in <sys/socket.h>.

The BSD 4.3 structure is:

 #define _SS_MAXSIZE 304
 #define _SS_ALIGNSIZE (sizeof (char*))
 #define _SS_PAD1SIZE (_SS_ALIGNSIZE - sizeof(sa_family_t))
 #define _SS_PAD2SIZE (_SS_MAXSIZE - (sizeof(sa_family_t)+
                        _SS_PAD1SIZE + _SS_ALIGNSIZE))

 struct sockaddr_storage {
     sa_family_t   ss_family;
     char         _ss_pad1[_SS_PAD1SIZE];
     char*        _ss_align;
     char         _ss_pad2[_SS_PAD2SIZE];
 };

The BSD 4.4/UNIX 98 compatible structure is:

 #define _SS_MAXSIZE 304
 #define _SS_ALIGNSIZE (sizeof (char*))
 #define _SS_PAD1SIZE (_SS_ALIGNSIZE - (sizeof(uint8_t) + sizeof(sa_family_t)))
 #define _SS_PAD2SIZE (_SS_MAXSIZE - (sizeof(uint8_t) + sizeof(sa_family_t)+
                        _SS_PAD1SIZE + _SS_ALIGNSIZE))

 struct sockaddr_storage {
     uint8_t       ss_len;
     sa_family_t   ss_family;
     char         _ss_pad1[_SS_PAD1SIZE];
     char*        _ss_align;
     char         _ss_pad2[_SS_PAD2SIZE];
 };

Authorities

No authorization is required.


Return Value

getsourcefilter() returns an integer. Possible values are:


Error Conditions

When getsourcefilter() fails, errno can be set to one of the following:

[EADDRNOTAVAIL] Address is not available.

The tuple consisting of socket, interface, and multicast group values do not exist; group_address is not being listened to on interface by socket, socket_descriptor.

[EAFNOSUPPORT] The type of socket is not supported in this protocol family.

The address family specified in the sockaddr parameter is not AF_INET or AF_INET6.

[EBADF] Descriptor is not valid.
[EINVAL]Parameter not valid.

This error code indicates one of the following:

  • The group_address parameter contains an IPv4-mapped IPv6 address and the interface parameter contains an interface index instead of an interface address.

  • The group_address parameter contains an IPv6 address and the interface parameter contains an interface address instead of an interface index.

[ENOPROTOOPT] The protocol does not support the specified option.

The socket is not of type SOCK_DGRAM or SOCK_RAW.

The address family of the group_address parameter does not match the protocol family of the socket, socket_descriptor.

[ENOTSOCK] The specified descriptor does not reference a socket.
[ENXIO] No such device or address.

The interface argument, an index or an IPv4 address, does not identify a valid interface.



Usage Notes

  1. On successful return, source_list will contain as many addresses as was initially specified for number_sources, or the number of source addresses in the filter, which ever is smaller. number_sources is set to the total number of source addresses in the filter; therefore, it can contain a number larger than the number of addresses in the source_list array.
  2. To determine the number of addresses in the source filter list, an application can call getsourcefilter() with a value of 0 for number_sources and NULL for source_list. On successful return, number_sources will contain the number of addresses in the source filter list.
  3. To determine the IPv6 interface index to use for the interface parameter, the following APIs can be used:
  4. When you develop in C-based languages and an application is compiled with the _XOPEN_SOURCE macro defined to the value 520 or greater, the getsourcefilter() API is mapped to qso_getsourcefilter98().
  5. The structure sockaddr is a generic structure used for any address family but it is only 16 bytes long. The actual address returned for some address families may be much larger. You should declare storage for the address with the structure sockaddr_storage. This structure is large enough and aligned for any protocol-specific structure. It may then be cast as sockaddr structure for use on the APIs. The ss_family field of the sockaddr_storage will always align with the family field of any protocol-specific structure.

Related Information



API introduced: V6R1

[ Back to top | UNIX-Type APIs | APIs by category ]