Documentation
/// These constants seem to have been removed in netlink_packet_route v0.18.
///
/// <https://github.com/rust-netlink/netlink-packet-route/commit/88b1348cc0a257c55e520cae3bde3c66d5bc65a3>
/// <https://github.com/rust-netlink/netlink-packet-route/issues/88>
/// <https://github.com/rust-netlink/rtnetlink/commit/ba4825a661752bb3bb436511f602cf1d21f6f9ba>
pub mod constants {
	pub const RTNLGRP_LINK: u32 = 1;
	pub const RTNLGRP_NEIGH: u32 = 3;
	pub const RTNLGRP_IPV4_IFADDR: u32 = 5;
	pub const RTNLGRP_IPV4_MROUTE: u32 = 6;
	pub const RTNLGRP_IPV4_ROUTE: u32 = 7;
	pub const RTNLGRP_IPV4_RULE: u32 = 8;
	pub const RTNLGRP_IPV6_IFADDR: u32 = 9;
	pub const RTNLGRP_IPV6_MROUTE: u32 = 10;
	pub const RTNLGRP_IPV6_ROUTE: u32 = 11;
	pub const RTNLGRP_IPV6_RULE: u32 = 19;
	pub const RTNLGRP_IPV4_NETCONF: u32 = 24;
	pub const RTNLGRP_IPV6_NETCONF: u32 = 25;
}

/// Bit-shift `RTNLGRP_*` constant to use for [`netlink_sys::SocketAddr`]
///
/// Taken from the `ip_monitor` example of the [`rtnetlink`] crate, where it is called `nl_mgrp`.
pub const fn multicast_group(group: u32) -> u32 {
	if group > 31 {
		panic!("use netlink_sys::Socket::add_membership() for this group");
	}
	if group == 0 {0}
	else {1 << (group - 1)}
}

/// Create bitmask for [`netlink_sys::SocketAddr`] from `RTNLGRP_*` constants
pub const fn multicast_groups(groups: &[u32]) -> u32 {
	if let Some((&first, rest)) = groups.split_first() {
		multicast_group(first) | multicast_groups(rest)
	}
	else {0}
}