From 3b1edd8e3dce0bad933249c48781caa989353f91 Mon Sep 17 00:00:00 2001 From: Douile Date: Wed, 22 Nov 2023 01:11:50 +0000 Subject: [PATCH] socket: Add method to get local address --- crates/lib/src/socket.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/crates/lib/src/socket.rs b/crates/lib/src/socket.rs index 8ae6bef..e49872b 100644 --- a/crates/lib/src/socket.rs +++ b/crates/lib/src/socket.rs @@ -24,7 +24,10 @@ pub trait Socket { fn send(&mut self, data: &[u8]) -> GDResult<()>; fn receive(&mut self, size: Option) -> GDResult>; + /// Get the remote port fn port(&self) -> u16; + /// Get the local SocketAddr + fn local_addr(&self) -> std::io::Result; } pub struct TcpSocket { @@ -73,6 +76,7 @@ impl Socket for TcpSocket { } fn port(&self) -> u16 { self.address.port() } + fn local_addr(&self) -> std::io::Result { self.socket.local_addr() } } pub struct UdpSocket { @@ -121,6 +125,7 @@ impl Socket for UdpSocket { } fn port(&self) -> u16 { self.address.port() } + fn local_addr(&self) -> std::io::Result { self.socket.local_addr() } } #[cfg(test)]