Source filter APIs enable an application to filter the datagrams
that it receives based on the source address. There are two categories
of source filter APIs: Basic and advanced. Both categories enable
multicast receiver applications to designate the unicast addresses
(source addresses) and the multicast group (destination address).
- Basic (delta-based) APIs
- Some applications need the simplicity of a delta-based API in
which each function call specifies a single source address to be added
to or removed from the filter. Such applications typically fall into
the following types:
- Any-source multicast
- By default, all source addresses are accepted. Individual source
addresses can be turned off and back on as needed. This type is also
known as the exclude mode, because the source filter contains a list
of excluded sources. The following SETSOCKOPT options are included.
Address family |
SETSOCKOPT options |
---|
IPv4 |
IP_ADD_MEMBERSHIP |
IP_BLOCK_SOURCE |
IP_DROP_MEMBERSHIP |
IP_UNBLOCK_SOURCE |
Protocol independent |
MCAST_BLOCK_SOURCE |
MCAST_JOIN_GROUP |
MCAST_LEAVE_GROUP |
MCAST_UNBLOCK_SOURCE |
- Source-specific multicast
- Only the source addresses that are specified in a list are accepted.
The list is initially empty; IP addresses can be added to or deleted
from the list one at a time. This filter type also is known as the
include mode, because the source filter contains a list of included
sources. The following SETSOCKOPT options are included.
Address family |
SETSOCKOPT options |
---|
IPv4 |
IP_ADD_SOURCE_MEMBERSHIP |
IP_DROP_MEMBERSHIP |
IP_DROP_SOURCE_MEMBERSHIP |
Protocol independent |
MCAST_JOIN_SOURCE_GROUP |
MCAST_LEAVE_GROUP |
MCAST_LEAVE_SOURCE_GROUP |
- Advanced (full-state) APIs
- These APIs enable an application to use a source filter that is
comprised of zero or more source addresses. The application can retrieve
the current filter or replace it with a new filter. The following
IOCTL commands are included:
- SIOCGIPMSFILTER
- SIOCGMSFILTER
- SIOCSIPMSFILTER
- SIOCSMSFILTER
Consider the following points about multicast source filters:
- Sockets cannot mix IPv4 group-membership APIs with protocol-independent
group-membership APIs. Within each API type, delta-based options cannot
be mixed with full-state options. Mixing these calls for the same
socket results in an EINVAL error.
- The number of groups that can be joined depends on the socket
type; there is a maximum of 20 groups for UDP sockets and a maximum
of 256 groups for RAW sockets. Exceeding this limit results in an
ETOOMANYREFS error.
- Within each group or group and interface pair, an application
can use calls for only one type of basic API, either any-source multicast
or source-specific multicast. Mixing options will result in an EINVAL
error. However, an application can use different methods for different
sockets.
- If the filter mode is set to include and the source list is empty,
then the entry corresponding to the requested interface and multicast
address is deleted, if present. If no such entry is present, then
the request is ignored.
- For each socket, you can specify a maximum of 64 source filters
for each multicast address and interface address pair. If the call
causes the number of filters to exceed this maximum, an ENOBUFS error
is returned.