Skip to content

Commit dabd816

Browse files
authored
Rollup merge of rust-lang#68313 - batrla:master, r=alexcrichton
Options IP_MULTICAST_TTL and IP_MULTICAST_LOOP are 1 byte on BSD Options IP_MULTICAST_TTL and IP_MULTICAST_LOOP are 1 byte on BSD and Solaris See ip(4P) man page: IP_MULTICAST_TTL Time to live for multicast datagrams. This option takes an unsigned character as an argument. Its value is the TTL that IP uses on outgoing multi- cast datagrams. The default is 1. IP_MULTICAST_LOOP Loopback for multicast datagrams. Normally multi- cast datagrams are delivered to members on the sending host (or sending zone). Setting the unsigned character argument to 0 causes the oppo- site behavior, meaning that when multiple zones are present, the datagrams are delivered to all zones except the sending zone. https://docs.oracle.com/cd/E88353_01/html/E37851/ip-4p.html https://man.openbsd.org/ip.4
2 parents 3484e2f + 5392442 commit dabd816

File tree

1 file changed

+51
-73
lines changed

1 file changed

+51
-73
lines changed

src/libstd/sys_common/net.rs

+51-73
Original file line numberDiff line numberDiff line change
@@ -13,75 +13,43 @@ use crate::time::Duration;
1313

1414
use libc::{c_int, c_void};
1515

16-
#[cfg(not(any(
17-
target_os = "dragonfly",
18-
target_os = "freebsd",
19-
target_os = "ios",
20-
target_os = "macos",
21-
target_os = "openbsd",
22-
target_os = "netbsd",
23-
target_os = "solaris",
24-
target_os = "haiku",
25-
target_os = "l4re"
26-
)))]
27-
use crate::sys::net::netc::IPV6_ADD_MEMBERSHIP;
28-
#[cfg(not(any(
29-
target_os = "dragonfly",
30-
target_os = "freebsd",
31-
target_os = "ios",
32-
target_os = "macos",
33-
target_os = "openbsd",
34-
target_os = "netbsd",
35-
target_os = "solaris",
36-
target_os = "haiku",
37-
target_os = "l4re"
38-
)))]
39-
use crate::sys::net::netc::IPV6_DROP_MEMBERSHIP;
40-
#[cfg(any(
41-
target_os = "dragonfly",
42-
target_os = "freebsd",
43-
target_os = "ios",
44-
target_os = "macos",
45-
target_os = "openbsd",
46-
target_os = "netbsd",
47-
target_os = "solaris",
48-
target_os = "haiku",
49-
target_os = "l4re"
50-
))]
51-
use crate::sys::net::netc::IPV6_JOIN_GROUP as IPV6_ADD_MEMBERSHIP;
52-
#[cfg(any(
53-
target_os = "dragonfly",
54-
target_os = "freebsd",
55-
target_os = "ios",
56-
target_os = "macos",
57-
target_os = "openbsd",
58-
target_os = "netbsd",
59-
target_os = "solaris",
60-
target_os = "haiku",
61-
target_os = "l4re"
62-
))]
63-
use crate::sys::net::netc::IPV6_LEAVE_GROUP as IPV6_DROP_MEMBERSHIP;
64-
65-
#[cfg(any(
66-
target_os = "linux",
67-
target_os = "android",
68-
target_os = "dragonfly",
69-
target_os = "freebsd",
70-
target_os = "openbsd",
71-
target_os = "netbsd",
72-
target_os = "haiku"
73-
))]
74-
use libc::MSG_NOSIGNAL;
75-
#[cfg(not(any(
76-
target_os = "linux",
77-
target_os = "android",
78-
target_os = "dragonfly",
79-
target_os = "freebsd",
80-
target_os = "openbsd",
81-
target_os = "netbsd",
82-
target_os = "haiku"
83-
)))]
84-
const MSG_NOSIGNAL: c_int = 0x0;
16+
cfg_if::cfg_if! {
17+
if #[cfg(any(
18+
target_os = "dragonfly", target_os = "freebsd",
19+
target_os = "ios", target_os = "macos",
20+
target_os = "openbsd", target_os = "netbsd",
21+
target_os = "solaris", target_os = "haiku", target_os = "l4re"))] {
22+
use crate::sys::net::netc::IPV6_JOIN_GROUP as IPV6_ADD_MEMBERSHIP;
23+
use crate::sys::net::netc::IPV6_LEAVE_GROUP as IPV6_DROP_MEMBERSHIP;
24+
} else {
25+
use crate::sys::net::netc::IPV6_ADD_MEMBERSHIP;
26+
use crate::sys::net::netc::IPV6_DROP_MEMBERSHIP;
27+
}
28+
}
29+
30+
cfg_if::cfg_if! {
31+
if #[cfg(any(
32+
target_os = "linux", target_os = "android",
33+
target_os = "dragonfly", target_os = "freebsd",
34+
target_os = "openbsd", target_os = "netbsd",
35+
target_os = "haiku"))] {
36+
use libc::MSG_NOSIGNAL;
37+
} else {
38+
const MSG_NOSIGNAL: c_int = 0x0;
39+
}
40+
}
41+
42+
cfg_if::cfg_if! {
43+
if #[cfg(any(
44+
target_os = "dragonfly", target_os = "freebsd",
45+
target_os = "openbsd", target_os = "netbsd",
46+
target_os = "solaris"))] {
47+
use libc::c_uchar;
48+
type IpV4MultiCastType = c_uchar;
49+
} else {
50+
type IpV4MultiCastType = c_int;
51+
}
52+
}
8553

8654
////////////////////////////////////////////////////////////////////////////////
8755
// sockaddr and misc bindings
@@ -566,20 +534,30 @@ impl UdpSocket {
566534
}
567535

568536
pub fn set_multicast_loop_v4(&self, multicast_loop_v4: bool) -> io::Result<()> {
569-
setsockopt(&self.inner, c::IPPROTO_IP, c::IP_MULTICAST_LOOP, multicast_loop_v4 as c_int)
537+
setsockopt(
538+
&self.inner,
539+
c::IPPROTO_IP,
540+
c::IP_MULTICAST_LOOP,
541+
multicast_loop_v4 as IpV4MultiCastType,
542+
)
570543
}
571544

572545
pub fn multicast_loop_v4(&self) -> io::Result<bool> {
573-
let raw: c_int = getsockopt(&self.inner, c::IPPROTO_IP, c::IP_MULTICAST_LOOP)?;
546+
let raw: IpV4MultiCastType = getsockopt(&self.inner, c::IPPROTO_IP, c::IP_MULTICAST_LOOP)?;
574547
Ok(raw != 0)
575548
}
576549

577550
pub fn set_multicast_ttl_v4(&self, multicast_ttl_v4: u32) -> io::Result<()> {
578-
setsockopt(&self.inner, c::IPPROTO_IP, c::IP_MULTICAST_TTL, multicast_ttl_v4 as c_int)
551+
setsockopt(
552+
&self.inner,
553+
c::IPPROTO_IP,
554+
c::IP_MULTICAST_TTL,
555+
multicast_ttl_v4 as IpV4MultiCastType,
556+
)
579557
}
580558

581559
pub fn multicast_ttl_v4(&self) -> io::Result<u32> {
582-
let raw: c_int = getsockopt(&self.inner, c::IPPROTO_IP, c::IP_MULTICAST_TTL)?;
560+
let raw: IpV4MultiCastType = getsockopt(&self.inner, c::IPPROTO_IP, c::IP_MULTICAST_TTL)?;
583561
Ok(raw as u32)
584562
}
585563

0 commit comments

Comments
 (0)