Skip to content

Invalidly assumes the memory layout of SocketAddrV{4,6} #38

Closed
@faern

Description

@faern

miow assumes that the memory layout of std::net::SocketAddrV{4,6} matches libc::sockaddr, but this can't be assumed. std makes no such promise to the outside world.

The offending code is here:

miow/src/net.rs

Lines 459 to 470 in c863739

fn socket_addr_to_ptrs(addr: &SocketAddr) -> (*const SOCKADDR, c_int) {
match *addr {
SocketAddr::V4(ref a) => (
a as *const _ as *const _,
mem::size_of::<SOCKADDR_IN>() as c_int,
),
SocketAddr::V6(ref a) => (
a as *const _ as *const _,
mem::size_of::<SOCKADDR_IN6_LH>() as c_int,
),
}
}

Some other crates made the same assumptions, and they are being fixed in tokio-rs/mio#1388, rust-lang/socket2#120 and deprecrated/net2-rs#106.

Until this is fixed and published it kind of blocks moving these fundamental network types into core and also stops them from having const fn constructors. See this PR on std for reference: rust-lang/rust#78802.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions