Skip to content

Commit 32b2bd7

Browse files
committed
as_ffi_pair returns a raw pointer
1 parent 720853a commit 32b2bd7

File tree

1 file changed

+10
-37
lines changed

1 file changed

+10
-37
lines changed

src/sys/socket/addr.rs

Lines changed: 10 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -907,60 +907,39 @@ impl SockAddr {
907907
/// with the size of the actual data type. sockaddr is commonly used as a proxy for
908908
/// a superclass as C doesn't support inheritance, so many functions that take
909909
/// a sockaddr * need to take the size of the underlying type as well and then internally cast it back.
910-
pub fn as_ffi_pair(&self) -> (&libc::sockaddr, libc::socklen_t) {
910+
pub fn as_ffi_pair(&self) -> (*const libc::sockaddr, libc::socklen_t) {
911911
match *self {
912912
SockAddr::Inet(InetAddr::V4(ref addr)) => (
913-
// This cast is always allowed in C
914-
unsafe {
915-
&*(addr as *const libc::sockaddr_in as *const libc::sockaddr)
916-
},
913+
addr as *const libc::sockaddr_in as *const libc::sockaddr,
917914
mem::size_of_val(addr) as libc::socklen_t
918915
),
919916
SockAddr::Inet(InetAddr::V6(ref addr)) => (
920-
// This cast is always allowed in C
921-
unsafe {
922-
&*(addr as *const libc::sockaddr_in6 as *const libc::sockaddr)
923-
},
917+
addr as *const libc::sockaddr_in6 as *const libc::sockaddr,
924918
mem::size_of_val(addr) as libc::socklen_t
925919
),
926920
SockAddr::Unix(UnixAddr { ref sun, path_len }) => (
927-
// This cast is always allowed in C
928-
unsafe {
929-
&*(sun as *const libc::sockaddr_un as *const libc::sockaddr)
930-
},
921+
sun as *const libc::sockaddr_un as *const libc::sockaddr,
931922
(path_len + offset_of!(libc::sockaddr_un, sun_path)) as libc::socklen_t
932923
),
933924
#[cfg(any(target_os = "android", target_os = "linux"))]
934925
SockAddr::Netlink(NetlinkAddr(ref sa)) => (
935-
// This cast is always allowed in C
936-
unsafe {
937-
&*(sa as *const libc::sockaddr_nl as *const libc::sockaddr)
938-
},
926+
sa as *const libc::sockaddr_nl as *const libc::sockaddr,
939927
mem::size_of_val(sa) as libc::socklen_t
940928
),
941929
#[cfg(any(target_os = "android", target_os = "linux"))]
942930
SockAddr::Alg(AlgAddr(ref sa)) => (
943-
// This cast is always allowed in C
944-
unsafe {
945-
&*(sa as *const libc::sockaddr_alg as *const libc::sockaddr)
946-
},
931+
sa as *const libc::sockaddr_alg as *const libc::sockaddr,
947932
mem::size_of_val(sa) as libc::socklen_t
948933
),
949934
#[cfg(any(target_os = "ios", target_os = "macos"))]
950935
SockAddr::SysControl(SysControlAddr(ref sa)) => (
951-
// This cast is always allowed in C
952-
unsafe {
953-
&*(sa as *const libc::sockaddr_ctl as *const libc::sockaddr)
954-
},
936+
sa as *const libc::sockaddr_ctl as *const libc::sockaddr,
955937
mem::size_of_val(sa) as libc::socklen_t
956938

957939
),
958940
#[cfg(any(target_os = "android", target_os = "linux"))]
959941
SockAddr::Link(LinkAddr(ref addr)) => (
960-
// This cast is always allowed in C
961-
unsafe {
962-
&*(addr as *const libc::sockaddr_ll as *const libc::sockaddr)
963-
},
942+
addr as *const libc::sockaddr_ll as *const libc::sockaddr,
964943
mem::size_of_val(addr) as libc::socklen_t
965944
),
966945
#[cfg(any(target_os = "dragonfly",
@@ -971,18 +950,12 @@ impl SockAddr {
971950
target_os = "netbsd",
972951
target_os = "openbsd"))]
973952
SockAddr::Link(LinkAddr(ref addr)) => (
974-
// This cast is always allowed in C
975-
unsafe {
976-
&*(addr as *const libc::sockaddr_dl as *const libc::sockaddr)
977-
},
953+
addr as *const libc::sockaddr_dl as *const libc::sockaddr,
978954
mem::size_of_val(addr) as libc::socklen_t
979955
),
980956
#[cfg(any(target_os = "android", target_os = "linux"))]
981957
SockAddr::Vsock(VsockAddr(ref sa)) => (
982-
// This cast is always allowed in C
983-
unsafe {
984-
&*(sa as *const libc::sockaddr_vm as *const libc::sockaddr)
985-
},
958+
sa as *const libc::sockaddr_vm as *const libc::sockaddr,
986959
mem::size_of_val(sa) as libc::socklen_t
987960
),
988961
}

0 commit comments

Comments
 (0)