Skip to content

Support join_multicast_v4 with interface index rather than address #283

Closed
@tamird

Description

@tamird

Currently join_multicast_v4 takes the interface by its address and calls setsockopt with an argument of type ip_mreq on unix. Meanwhile join_multicast_v6 takes the interface by its index.

Per man 7 ip:

       IP_ADD_MEMBERSHIP (since Linux 1.2)
              Join a multicast group.  Argument is an ip_mreqn structure.

           struct ip_mreqn {
               struct in_addr imr_multiaddr; /* IP multicast group
                                                address */
               struct in_addr imr_address;   /* IP address of local
                                                interface */
               int            imr_ifindex;   /* interface index */
           };

       imr_multiaddr contains the address of the multicast group the application wants to join or leave.  It must be a valid multicast address (or setsockopt(2) fails with the error  EINVAL).   imr_address
       is  the  address of the local interface with which the system should join the multicast group; if it is equal to INADDR_ANY, an appropriate interface is chosen by the system.  imr_ifindex is the in‐
       terface index of the interface that should join/leave the imr_multiaddr group, or 0 to indicate any interface.

              The ip_mreqn structure is available only since Linux 2.2.  For compatibility, the old ip_mreq structure (present since Linux 1.2) is still supported; it differs from ip_mreqn only by not  in‐
              cluding the imr_ifindex field.  (The kernel determines which structure is being passed based on the size passed in optlen.)

Joining an IPv4 multicast group by interface index has been support since Linux 2.2 (released > 20 years ago on August 14th, 2000); it would be nice to expose this to users of this library.

The same is also supported in Win32 though the mechanism is different. Per https://docs.microsoft.com/en-us/windows/win32/api/ws2ipdef/ns-ws2ipdef-ip_mreq:

Members
imr_multiaddr

The address of the IPv4 multicast group.

imr_interface

The local IPv4 address of the interface or the interface index on which the multicast group should be joined or dropped. This value is in network byte order. If this member specifies an IPv4 address of 0.0.0.0, the default IPv4 multicast interface is used.

To use an interface index of 1 would be the same as an IP address of 0.0.0.1.

cc @brunowonka

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions