Skip to content

Commit 037eac5

Browse files
committed
Add target_os=freebsd/openbsd for (set_)ip_bindany_(v4|v6)
1 parent adc2b3a commit 037eac5

File tree

2 files changed

+86
-10
lines changed

2 files changed

+86
-10
lines changed

src/sys/unix.rs

+80-8
Original file line numberDiff line numberDiff line change
@@ -3188,18 +3188,34 @@ impl crate::Socket {
31883188
/// [`set_ip_bindany_v4`]: crate::Socket::set_ip_bindany_v4
31893189
#[cfg(all(
31903190
feature = "all",
3191-
any(target_os = "android", target_os = "fuchsia", target_os = "linux")
3191+
any(
3192+
target_os = "android",
3193+
target_os = "fuchsia",
3194+
target_os = "linux",
3195+
target_os = "freebsd",
3196+
target_os = "openbsd"
3197+
)
31923198
))]
31933199
#[cfg_attr(
31943200
docsrs,
31953201
doc(cfg(all(
31963202
feature = "all",
3197-
any(target_os = "android", target_os = "fuchsia", target_os = "linux")
3203+
any(
3204+
target_os = "android",
3205+
target_os = "fuchsia",
3206+
target_os = "linux",
3207+
target_os = "freebsd",
3208+
target_os = "openbsd"
3209+
)
31983210
)))
31993211
)]
32003212
pub fn ip_bindany_v4(&self) -> io::Result<bool> {
32013213
#[cfg(any(target_os = "android", target_os = "fuchsia", target_os = "linux"))]
32023214
let (level, opt) = (libc::SOL_IP, libc::IP_FREEBIND);
3215+
#[cfg(target_os = "freebsd")]
3216+
let (level, opt) = (libc::IPPROTO_IP, libc::IP_BINDANY);
3217+
#[cfg(target_os = "openbsd")]
3218+
let (level, opt) = (libc::SOL_SOCKET, libc::SO_BINDANY);
32033219

32043220
unsafe { getsockopt::<c_int>(self.as_raw(), level, opt).map(|bindany| bindany != 0) }
32053221
}
@@ -3214,18 +3230,34 @@ impl crate::Socket {
32143230
/// be up at the time that the application is trying to bind to it.
32153231
#[cfg(all(
32163232
feature = "all",
3217-
any(target_os = "android", target_os = "fuchsia", target_os = "linux")
3233+
any(
3234+
target_os = "android",
3235+
target_os = "fuchsia",
3236+
target_os = "linux",
3237+
target_os = "freebsd",
3238+
target_os = "openbsd"
3239+
)
32183240
))]
32193241
#[cfg_attr(
32203242
docsrs,
32213243
doc(cfg(all(
32223244
feature = "all",
3223-
any(target_os = "android", target_os = "fuchsia", target_os = "linux")
3245+
any(
3246+
target_os = "android",
3247+
target_os = "fuchsia",
3248+
target_os = "linux",
3249+
target_os = "freebsd",
3250+
target_os = "openbsd"
3251+
)
32243252
)))
32253253
)]
32263254
pub fn set_ip_bindany_v4(&self, bindany: bool) -> io::Result<()> {
32273255
#[cfg(any(target_os = "android", target_os = "fuchsia", target_os = "linux"))]
32283256
let (level, opt) = (libc::SOL_IP, libc::IP_FREEBIND);
3257+
#[cfg(target_os = "freebsd")]
3258+
let (level, opt) = (libc::IPPROTO_IP, libc::IP_BINDANY);
3259+
#[cfg(target_os = "openbsd")]
3260+
let (level, opt) = (libc::SOL_SOCKET, libc::SO_BINDANY);
32293261

32303262
unsafe { setsockopt(self.as_raw(), level, opt, bindany as c_int) }
32313263
}
@@ -3237,14 +3269,34 @@ impl crate::Socket {
32373269
/// For more information about this option, see [`set_ip_bindany_v6`].
32383270
///
32393271
/// [`set_ip_bindany_v6`]: crate::Socket::set_ip_bindany_v6
3240-
#[cfg(all(feature = "all", any(target_os = "android", target_os = "linux")))]
3272+
#[cfg(all(
3273+
feature = "all",
3274+
any(
3275+
target_os = "android",
3276+
target_os = "linux",
3277+
target_os = "freebsd",
3278+
target_os = "openbsd"
3279+
)
3280+
))]
32413281
#[cfg_attr(
32423282
docsrs,
3243-
doc(cfg(all(feature = "all", any(target_os = "android", target_os = "linux"))))
3283+
doc(cfg(all(
3284+
feature = "all",
3285+
any(
3286+
target_os = "android",
3287+
target_os = "linux",
3288+
target_os = "freebsd",
3289+
target_os = "openbsd"
3290+
)
3291+
)))
32443292
)]
32453293
pub fn ip_bindany_v6(&self) -> io::Result<bool> {
32463294
#[cfg(any(target_os = "android", target_os = "linux"))]
32473295
let (level, opt) = (libc::SOL_IPV6, libc::IPV6_FREEBIND);
3296+
#[cfg(target_os = "freebsd")]
3297+
let (level, opt) = (libc::IPPROTO_IPV6, libc::IPV6_BINDANY);
3298+
#[cfg(target_os = "openbsd")]
3299+
let (level, opt) = (libc::SOL_SOCKET, libc::SO_BINDANY);
32483300

32493301
unsafe { getsockopt::<c_int>(self.as_raw(), level, opt).map(|bindany| bindany != 0) }
32503302
}
@@ -3257,14 +3309,34 @@ impl crate::Socket {
32573309
/// For more information about this option, see [`set_ip_bindany_v4`].
32583310
///
32593311
/// [`set_ip_bindany_v4`]: crate::Socket::set_ip_bindany_v4
3260-
#[cfg(all(feature = "all", any(target_os = "android", target_os = "linux")))]
3312+
#[cfg(all(
3313+
feature = "all",
3314+
any(
3315+
target_os = "android",
3316+
target_os = "linux",
3317+
target_os = "freebsd",
3318+
target_os = "openbsd"
3319+
)
3320+
))]
32613321
#[cfg_attr(
32623322
docsrs,
3263-
doc(cfg(all(feature = "all", any(target_os = "android", target_os = "linux"))))
3323+
doc(cfg(all(
3324+
feature = "all",
3325+
any(
3326+
target_os = "android",
3327+
target_os = "linux",
3328+
target_os = "freebsd",
3329+
target_os = "openbsd"
3330+
)
3331+
)))
32643332
)]
32653333
pub fn set_ip_bindany_v6(&self, bindany: bool) -> io::Result<()> {
32663334
#[cfg(any(target_os = "android", target_os = "linux"))]
32673335
let (level, opt) = (libc::SOL_IPV6, libc::IPV6_FREEBIND);
3336+
#[cfg(target_os = "freebsd")]
3337+
let (level, opt) = (libc::IPPROTO_IPV6, libc::IPV6_BINDANY);
3338+
#[cfg(target_os = "openbsd")]
3339+
let (level, opt) = (libc::SOL_SOCKET, libc::SO_BINDANY);
32683340

32693341
unsafe { setsockopt(self.as_raw(), level, opt, bindany as c_int) }
32703342
}

tests/socket.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -1410,15 +1410,19 @@ test!(keepalive, set_keepalive(true));
14101410
any(
14111411
target_os = "android",
14121412
target_os = "fuchsia",
1413-
target_os = "linux"
1413+
target_os = "linux",
1414+
target_os = "freebsd",
1415+
target_os = "openbsd"
14141416
)
14151417
))]
14161418
test!(ip_bindany_v4, set_ip_bindany_v4(true));
14171419
#[cfg(all(
14181420
feature = "all",
14191421
any(
14201422
target_os = "android",
1421-
target_os = "linux"
1423+
target_os = "linux",
1424+
target_os = "freebsd",
1425+
target_os = "openbsd"
14221426
)
14231427
))]
14241428
test!(IPv6 ip_bindany_v6, set_ip_bindany_v6(true));

0 commit comments

Comments
 (0)