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

Socket option for IP_MULTICAST_ALL & IPV6_MULTICAST_ALL for linux #485

Merged
merged 1 commit into from
Dec 18, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 74 additions & 0 deletions src/socket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1377,6 +1377,43 @@ impl Socket {
}
}

/// Get the value of the `IP_MULTICAST_ALL` option for this socket.
///
/// For more information about this option, see [`set_multicast_all_v4`].
///
/// [`set_multicast_all_v4`]: Socket::set_multicast_all_v4
#[cfg(all(feature = "all", target_os = "linux"))]
#[cfg_attr(docsrs, doc(cfg(all(feature = "all", target_os = "linux"))))]
pub fn multicast_all_v4(&self) -> io::Result<bool> {
unsafe {
getsockopt::<c_int>(self.as_raw(), sys::IPPROTO_IP, libc::IP_MULTICAST_ALL)
.map(|all| all != 0)
}
}

/// Set the value of the `IP_MULTICAST_ALL` option for this socket.
///
/// This option can be used to modify the delivery policy of
/// multicast messages. The argument is a boolean
/// (defaults to true). If set to true, the socket will receive
/// messages from all the groups that have been joined
/// globally on the whole system. Otherwise, it will deliver
/// messages only from the groups that have been explicitly
/// joined (for example via the `IP_ADD_MEMBERSHIP` option) on
/// this particular socket.
#[cfg(all(feature = "all", target_os = "linux"))]
#[cfg_attr(docsrs, doc(cfg(all(feature = "all", target_os = "linux"))))]
pub fn set_multicast_all_v4(&self, all: bool) -> io::Result<()> {
unsafe {
setsockopt(
self.as_raw(),
sys::IPPROTO_IP,
libc::IPV6_MULTICAST_ALL,
all as c_int,
)
}
}

/// Get the value of the `IP_MULTICAST_IF` option for this socket.
///
/// For more information about this option, see [`set_multicast_if_v4`].
Expand Down Expand Up @@ -1659,6 +1696,43 @@ impl Socket {
}
}

/// Get the value of the `IPV6_MULTICAST_ALL` option for this socket.
///
/// For more information about this option, see [`set_multicast_all_v6`].
///
/// [`set_multicast_all_v6`]: Socket::set_multicast_all_v6
#[cfg(all(feature = "all", target_os = "linux"))]
#[cfg_attr(docsrs, doc(cfg(all(feature = "all", target_os = "linux"))))]
pub fn multicast_all_v6(&self) -> io::Result<bool> {
unsafe {
getsockopt::<c_int>(self.as_raw(), sys::IPPROTO_IPV6, libc::IPV6_MULTICAST_ALL)
.map(|all| all != 0)
}
}

/// Set the value of the `IPV6_MULTICAST_ALL` option for this socket.
///
/// This option can be used to modify the delivery policy of
/// multicast messages. The argument is a boolean
/// (defaults to true). If set to true, the socket will receive
/// messages from all the groups that have been joined
/// globally on the whole system. Otherwise, it will deliver
/// messages only from the groups that have been explicitly
/// joined (for example via the `IPV6_ADD_MEMBERSHIP` option) on
/// this particular socket.
#[cfg(all(feature = "all", target_os = "linux"))]
#[cfg_attr(docsrs, doc(cfg(all(feature = "all", target_os = "linux"))))]
pub fn set_multicast_all_v6(&self, all: bool) -> io::Result<()> {
unsafe {
setsockopt(
self.as_raw(),
sys::IPPROTO_IPV6,
libc::IPV6_MULTICAST_ALL,
all as c_int,
)
}
}

/// Get the value of the `IPV6_MULTICAST_IF` option for this socket.
///
/// For more information about this option, see [`set_multicast_if_v6`].
Expand Down