Skip to content

Commit

Permalink
Add tests for sockopt::IpMulticastTtl #2073
Browse files Browse the repository at this point in the history
On Linux and Android, sockopt::IpMulticastTtl can be set for both IPv4
and IPv6 sockets, but not on FreeBSD.
  • Loading branch information
sgasse committed Nov 27, 2023
1 parent 3ce514c commit ab7f996
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
2 changes: 1 addition & 1 deletion changelog/2072.fixed.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Fixed `::sys::socket::sockopt::IpMulticastTtl` by fixing the value of optlen passed to `libc::setsockopt`.
Fixed `::sys::socket::sockopt::IpMulticastTtl` by fixing the value of optlen passed to `libc::setsockopt` and added tests.
30 changes: 29 additions & 1 deletion test/sys/test_sockopt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ fn test_get_mtu() {
}

#[test]
#[cfg(any(target_os = "android", target_os = "freebsd", target_os = "linux"))]
#[cfg(any(linux_android, target_os = "freebsd"))]
fn test_ttl_opts() {
let fd4 = socket(
AddressFamily::Inet,
Expand All @@ -325,6 +325,34 @@ fn test_ttl_opts() {
.expect("setting ipv6ttl on an inet6 socket should succeed");
}

#[test]
#[cfg(any(linux_android, target_os = "freebsd"))]
fn test_multicast_ttl_opts_ipv4() {
let fd4 = socket(
AddressFamily::Inet,
SockType::Datagram,
SockFlag::empty(),
None,
)
.unwrap();
setsockopt(&fd4, sockopt::IpMulticastTtl, &2)
.expect("setting ipmulticastttl on an inet socket should succeed");
}

#[test]
#[cfg(linux_android)]
fn test_multicast_ttl_opts_ipv6() {
let fd6 = socket(
AddressFamily::Inet6,
SockType::Datagram,
SockFlag::empty(),
None,
)
.unwrap();
setsockopt(&fd6, sockopt::IpMulticastTtl, &2)
.expect("setting ipmulticastttl on an inet6 socket should succeed");
}

#[test]
#[cfg(apple_targets)]
fn test_dontfrag_opts() {
Expand Down

0 comments on commit ab7f996

Please sign in to comment.