Skip to content

Commit 3e718cc

Browse files
committed
Add (set_)ip_bindany_v6 for target_os=freebsd
1 parent 4f22a6b commit 3e718cc

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
@@ -1393,6 +1393,12 @@ test!(
13931393
ip_bindany_v4,
13941394
set_ip_bindany_v4(true)
13951395
);
1396+
#[cfg(all(feature = "all", target_os = "freebsd"))]
1397+
test!(
1398+
#[ignore = "setting `IPV6_BINDANY` requires the `PRIV_NETINET_BINDANY` privilege (works when running as root)"]
1399+
ip_bindany_v6,
1400+
set_ip_bindany_v6(true)
1401+
);
13961402
#[cfg(all(feature = "all", any(target_os = "fuchsia", target_os = "linux")))]
13971403
test!(
13981404
#[ignore = "setting `SO_MARK` requires the `CAP_NET_ADMIN` capability (works when running as root)"]

0 commit comments

Comments
 (0)