Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "Expose SockAddr::from_raw_sockaddr" #1546

Merged
merged 1 commit into from
Sep 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/ifaddrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ impl InterfaceAddress {
/// Create an `InterfaceAddress` from the libc struct.
fn from_libc_ifaddrs(info: &libc::ifaddrs) -> InterfaceAddress {
let ifname = unsafe { ffi::CStr::from_ptr(info.ifa_name) };
let address = unsafe { SockAddr::from_raw_sockaddr(info.ifa_addr) };
let netmask = unsafe { SockAddr::from_raw_sockaddr(info.ifa_netmask) };
let address = unsafe { SockAddr::from_libc_sockaddr(info.ifa_addr) };
let netmask = unsafe { SockAddr::from_libc_sockaddr(info.ifa_netmask) };
let mut addr = InterfaceAddress {
interface_name: ifname.to_string_lossy().to_string(),
flags: InterfaceFlags::from_bits_truncate(info.ifa_flags as i32),
Expand All @@ -59,9 +59,9 @@ impl InterfaceAddress {

let ifu = get_ifu_from_sockaddr(info);
if addr.flags.contains(InterfaceFlags::IFF_POINTOPOINT) {
addr.destination = unsafe { SockAddr::from_raw_sockaddr(ifu) };
addr.destination = unsafe { SockAddr::from_libc_sockaddr(ifu) };
} else if addr.flags.contains(InterfaceFlags::IFF_BROADCAST) {
addr.broadcast = unsafe { SockAddr::from_raw_sockaddr(ifu) };
addr.broadcast = unsafe { SockAddr::from_libc_sockaddr(ifu) };
}

addr
Expand Down
8 changes: 4 additions & 4 deletions src/sys/socket/addr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -802,7 +802,7 @@ impl SockAddr {
/// unsafe because it takes a raw pointer as argument. The caller must
/// ensure that the pointer is valid.
#[cfg(not(target_os = "fuchsia"))]
pub unsafe fn from_raw_sockaddr(addr: *const libc::sockaddr) -> Option<SockAddr> {
pub(crate) unsafe fn from_libc_sockaddr(addr: *const libc::sockaddr) -> Option<SockAddr> {
if addr.is_null() {
None
} else {
Expand Down Expand Up @@ -1381,7 +1381,7 @@ mod tests {
fn test_macos_loopback_datalink_addr() {
let bytes = [20i8, 18, 1, 0, 24, 3, 0, 0, 108, 111, 48, 0, 0, 0, 0, 0];
let sa = bytes.as_ptr() as *const libc::sockaddr;
let _sock_addr = unsafe { SockAddr::from_raw_sockaddr(sa) };
let _sock_addr = unsafe { SockAddr::from_libc_sockaddr(sa) };
assert!(_sock_addr.is_none());
}

Expand All @@ -1396,7 +1396,7 @@ mod tests {
let bytes = [20i8, 18, 7, 0, 6, 3, 6, 0, 101, 110, 48, 24, 101, -112, -35, 76, -80];
let ptr = bytes.as_ptr();
let sa = ptr as *const libc::sockaddr;
let _sock_addr = unsafe { SockAddr::from_raw_sockaddr(sa) };
let _sock_addr = unsafe { SockAddr::from_libc_sockaddr(sa) };

assert!(_sock_addr.is_some());

Expand All @@ -1418,7 +1418,7 @@ mod tests {
let bytes = [25u8, 0, 0, 0, 6, 0, 6, 0, 24, 101, 144, 221, 76, 176];
let ptr = bytes.as_ptr();
let sa = ptr as *const libc::sockaddr;
let _sock_addr = unsafe { SockAddr::from_raw_sockaddr(sa) };
let _sock_addr = unsafe { SockAddr::from_libc_sockaddr(sa) };

assert!(_sock_addr.is_some());

Expand Down