Skip to content

Commit dddb455

Browse files
committed
Add some convenience functions
1 parent 828d2a8 commit dddb455

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/types/socket_info.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,21 @@ pub struct UdpSocketInfo {
4141
pub local_addr: IpAddr,
4242
pub local_port: u16,
4343
}
44+
45+
impl SocketInfo {
46+
/// Local address of this socket.
47+
pub fn local_addr(&self) -> IpAddr {
48+
match &self.protocol_socket_info {
49+
ProtocolSocketInfo::Tcp(s) => s.local_addr,
50+
ProtocolSocketInfo::Udp(s) => s.local_addr,
51+
}
52+
}
53+
54+
/// Local port of this socket.
55+
pub fn local_port(&self) -> u16 {
56+
match &self.protocol_socket_info {
57+
ProtocolSocketInfo::Tcp(s) => s.local_port,
58+
ProtocolSocketInfo::Udp(s) => s.local_port,
59+
}
60+
}
61+
}

0 commit comments

Comments
 (0)