Skip to content

Commit 75e4138

Browse files
committed
Add (set_)ip_bindany_v6 for target_os=freebsd
1 parent f68763e commit 75e4138

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

src/sys/unix.rs

+35
Original file line numberDiff line numberDiff line change
@@ -3274,6 +3274,41 @@ impl crate::Socket {
32743274
)
32753275
}
32763276
}
3277+
3278+
/// Get the value of the `IPV6_BINDANY` option on this socket.
3279+
///
3280+
/// For more information about this option, see [`set_ip_bindany_v6`].
3281+
///
3282+
/// [`set_ip_bindany_v6`]: crate::Socket::set_ip_bindany_v6
3283+
#[cfg(all(feature = "all", target_os = "freebsd"))]
3284+
#[cfg_attr(docsrs, doc(cfg(all(feature = "all", target_os = "freebsd"))))]
3285+
pub fn ip_bindany_v6(&self) -> io::Result<bool> {
3286+
unsafe {
3287+
getsockopt::<c_int>(self.as_raw(), libc::IPPROTO_IPV6, libc::IPV6_BINDANY)
3288+
.map(|bindany| bindany != 0)
3289+
}
3290+
}
3291+
3292+
/// Set the value of the `IPV6_BINDANY` option on this socket.
3293+
///
3294+
/// If the IPV6_BINDANY option is enabled on a SOCK_STREAM, SOCK_DGRAM or a
3295+
/// SOCK_RAW socket, one can bind(2) to any address, even one not bound to
3296+
/// any available network interface in the system. This functionality (in
3297+
/// conjunction with special firewall rules) can be used for implementing a
3298+
/// transparent proxy. The PRIV_NETINET_BINDANY privilege is needed to set
3299+
/// this option.
3300+
#[cfg(all(feature = "all", target_os = "freebsd"))]
3301+
#[cfg_attr(docsrs, doc(cfg(all(feature = "all", target_os = "freebsd"))))]
3302+
pub fn set_ip_bindany_v6(&self, bindany: bool) -> io::Result<()> {
3303+
unsafe {
3304+
setsockopt(
3305+
self.as_raw(),
3306+
libc::IPPROTO_IPV6,
3307+
libc::IPV6_BINDANY,
3308+
bindany as c_int,
3309+
)
3310+
}
3311+
}
32773312
}
32783313

32793314
/// See [`Socket::dccp_available_ccids`].

tests/socket.rs

+6
Original file line numberDiff line numberDiff line change
@@ -1384,6 +1384,12 @@ test!(
13841384
ip_bindany_v4,
13851385
set_ip_bindany_v4(true)
13861386
);
1387+
#[cfg(all(feature = "all", target_os = "freebsd"))]
1388+
test!(
1389+
#[ignore = "setting `IPV6_BINDANY` requires the `PRIV_NETINET_BINDANY` privilege (works when running as root)"]
1390+
ip_bindany_v6,
1391+
set_ip_bindany_v6(true)
1392+
);
13871393
#[cfg(all(feature = "all", any(target_os = "fuchsia", target_os = "linux")))]
13881394
test!(
13891395
#[ignore = "setting `SO_MARK` requires the `CAP_NET_ADMIN` capability (works when running as root)"]

0 commit comments

Comments
 (0)