MCPcopy Create free account
hub / github.com/bytecodealliance/rustix / encode_sockaddr_v4

Function encode_sockaddr_v4

src/backend/libc/net/write_sockaddr.rs:8–32  ·  view source on GitHub ↗
(v4: &SocketAddrV4)

Source from the content-addressed store, hash-verified

6use crate::net::{SocketAddrV4, SocketAddrV6};
7
8pub(crate) fn encode_sockaddr_v4(v4: &SocketAddrV4) -> c::sockaddr_in {
9 c::sockaddr_in {
10 #[cfg(any(
11 bsd,
12 target_os = "aix",
13 target_os = "espidf",
14 target_os = "haiku",
15 target_os = "hurd",
16 target_os = "nto",
17 target_os = "vita",
18 ))]
19 sin_len: core::mem::size_of::<c::sockaddr_in>() as _,
20 sin_family: c::AF_INET as _,
21 sin_port: u16::to_be(v4.port()),
22 sin_addr: in_addr_new(u32::from_ne_bytes(v4.ip().octets())),
23 #[cfg(not(any(target_os = "haiku", target_os = "vita")))]
24 sin_zero: [0; 8_usize],
25 #[cfg(target_os = "haiku")]
26 sin_zero: [0; 24_usize],
27 #[cfg(target_os = "vita")]
28 sin_zero: [0; 6_usize],
29 #[cfg(target_os = "vita")]
30 sin_vport: 0,
31 }
32}
33
34pub(crate) fn encode_sockaddr_v6(v6: &SocketAddrV6) -> c::sockaddr_in6 {
35 #[cfg(any(

Callers 1

with_sockaddrMethod · 0.50

Calls 1

in_addr_newFunction · 0.85

Tested by

no test coverage detected