Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support join_multicast_v4 with interface index rather than address #283

Closed
tamird opened this issue Jan 10, 2022 · 3 comments
Closed

Support join_multicast_v4 with interface index rather than address #283

tamird opened this issue Jan 10, 2022 · 3 comments

Comments

@tamird
Copy link
Contributor

tamird commented Jan 10, 2022

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

@Thomasdezeeuw
Copy link
Collaborator

Pr would be welcome, but it has two blocking issues:

  • The libc crate is missing ipv6_mreqn
  • Change the method would be a breaking change, but we can add a join_multicast_v62 and join the methods in v0.5.

@tamird
Copy link
Contributor Author

tamird commented Jan 11, 2022

ipv6_mreqn is not a thing; what we need here is ip_mreqn.

I'll work up a PR.

@Thomasdezeeuw
Copy link
Collaborator

Ah I think I misunderstood. You want join_multicast_v4 with an interface argument of type u32 rather then Ipv4Addr.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants