Skip to content

Commit

Permalink
add support of getpeername and getsockname
Browse files Browse the repository at this point in the history
  • Loading branch information
stlankes committed Aug 8, 2024
1 parent 36375c6 commit ebf94b7
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/fd/socket/vsock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,26 @@ impl ObjectInterface for Socket {
}
}

fn getpeername(&self) -> Option<Endpoint> {
let port = self.port.load(Ordering::Acquire);
let guard = VSOCK_MAP.lock();
let raw = guard.get_socket(port)?;

Some(Endpoint::Vsock(VsockEndpoint::new(
raw.remote_port,
raw.remote_cid,
)))
}

fn getsockname(&self) -> Option<Endpoint> {
let local_cid = hardware::get_vsock_driver().unwrap().lock().get_cid();

Some(Endpoint::Vsock(VsockEndpoint::new(
self.port.load(Ordering::Acquire),
local_cid.try_into().unwrap(),
)))
}

fn is_nonblocking(&self) -> bool {
self.nonblocking.load(Ordering::Acquire)
}
Expand Down

0 comments on commit ebf94b7

Please sign in to comment.