summaryrefslogtreecommitdiff
path: root/src/sys
diff options
context:
space:
mode:
Diffstat (limited to 'src/sys')
-rw-r--r--src/sys/socket/addr.rs21
-rw-r--r--src/sys/stat.rs14
2 files changed, 24 insertions, 11 deletions
diff --git a/src/sys/socket/addr.rs b/src/sys/socket/addr.rs
index 4a16eea9..c7b5f29e 100644
--- a/src/sys/socket/addr.rs
+++ b/src/sys/socket/addr.rs
@@ -40,23 +40,22 @@ use std::{fmt, mem, net, ptr, slice};
/// Convert a std::net::Ipv4Addr into the libc form.
#[cfg(feature = "net")]
-pub(crate) fn ipv4addr_to_libc(addr: net::Ipv4Addr) -> libc::in_addr {
- let octets = addr.octets();
- libc::in_addr {
- s_addr: u32::to_be(
- ((octets[0] as u32) << 24)
- | ((octets[1] as u32) << 16)
- | ((octets[2] as u32) << 8)
- | (octets[3] as u32),
- ),
+pub(crate) const fn ipv4addr_to_libc(addr: net::Ipv4Addr) -> libc::in_addr {
+ static_assertions::assert_eq_size!(net::Ipv4Addr, libc::in_addr);
+ // Safe because both types have the same memory layout, and no fancy Drop
+ // impls.
+ unsafe {
+ mem::transmute(addr)
}
}
/// Convert a std::net::Ipv6Addr into the libc form.
#[cfg(feature = "net")]
pub(crate) const fn ipv6addr_to_libc(addr: &net::Ipv6Addr) -> libc::in6_addr {
- libc::in6_addr {
- s6_addr: addr.octets(),
+ static_assertions::assert_eq_size!(net::Ipv6Addr, libc::in6_addr);
+ // Safe because both are Newtype wrappers around the same libc type
+ unsafe {
+ mem::transmute(*addr)
}
}
diff --git a/src/sys/stat.rs b/src/sys/stat.rs
index 94be4107..78203bfb 100644
--- a/src/sys/stat.rs
+++ b/src/sys/stat.rs
@@ -33,19 +33,33 @@ libc_bitflags!(
libc_bitflags! {
/// "File mode / permissions" flags.
pub struct Mode: mode_t {
+ /// Read, write and execute for owner.
S_IRWXU;
+ /// Read for owner.
S_IRUSR;
+ /// Write for owner.
S_IWUSR;
+ /// Execute for owner.
S_IXUSR;
+ /// Read write and execute for group.
S_IRWXG;
+ /// Read fr group.
S_IRGRP;
+ /// Write for group.
S_IWGRP;
+ /// Execute for group.
S_IXGRP;
+ /// Read, write and execute for other.
S_IRWXO;
+ /// Read for other.
S_IROTH;
+ /// Write for other.
S_IWOTH;
+ /// Execute for other.
S_IXOTH;
+ /// Set user id on execution.
S_ISUID as mode_t;
+ /// Set group id on execution.
S_ISGID as mode_t;
S_ISVTX as mode_t;
}