MCPcopy Create free account
hub / github.com/cloud-hypervisor/cloud-hypervisor / create_inet_socket

Function create_inet_socket

net_util/src/lib.rs:77–91  ·  view source on GitHub ↗
(addr: IpAddr)

Source from the content-addressed store, hash-verified

75}
76
77fn create_inet_socket(addr: IpAddr) -> Result<net::UdpSocket> {
78 let domain = match addr {
79 IpAddr::V4(_) => libc::AF_INET,
80 IpAddr::V6(_) => libc::AF_INET6,
81 };
82
83 // SAFETY: we check the return value.
84 let sock = unsafe { libc::socket(domain, libc::SOCK_DGRAM, 0) };
85 if sock < 0 {
86 return Err(Error::CreateSocket(IoError::last_os_error()));
87 }
88
89 // SAFETY: nothing else will use or hold onto the raw sock fd.
90 Ok(unsafe { net::UdpSocket::from_raw_fd(sock) })
91}
92
93fn create_unix_socket() -> Result<net::UdpSocket> {
94 // SAFETY: we check the return value.

Callers 1

set_ip_addrMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected