diff options
| author | Linus Unnebäck <linus@folkdatorn.se> | 2019-03-11 16:07:31 +0000 |
|---|---|---|
| committer | Linus Unnebäck <linus@folkdatorn.se> | 2019-03-16 11:13:32 +0000 |
| commit | a7bd36c9e8cdfac6a6edd4124e0d1d99a41b99a2 (patch) | |
| tree | 17494930a8cd851269bbc8870b621c1b40561cc4 /src/libstd/net | |
| parent | 52e885628e4317aa3f158622435927eb29b812e9 (diff) | |
Add peer_addr function to UdpSocket
Diffstat (limited to 'src/libstd/net')
| -rw-r--r-- | src/libstd/net/udp.rs | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/src/libstd/net/udp.rs b/src/libstd/net/udp.rs index edc9d665444..c7ccf45b953 100644 --- a/src/libstd/net/udp.rs +++ b/src/libstd/net/udp.rs @@ -180,6 +180,23 @@ impl UdpSocket { } } + /// Returns the socket address of the remote peer this socket was connected to. + /// + /// # Examples + /// + /// ```no_run + /// use std::net::{Ipv4Addr, SocketAddr, SocketAddrV4, UdpSocket}; + /// + /// let socket = UdpSocket::bind("127.0.0.1:34254").expect("couldn't bind to address"); + /// socket.connect("192.168.0.1:41203").expect("couldn't connect to address"); + /// assert_eq!(socket.peer_addr().unwrap(), + /// SocketAddr::V4(SocketAddrV4::new(Ipv4Addr::new(192, 168, 0, 1), 41203))); + /// ``` + #[stable(feature = "rust1", since = "1.0.0")] + pub fn peer_addr(&self) -> io::Result<SocketAddr> { + self.0.peer_addr() + } + /// Returns the socket address that this socket was created from. /// /// # Examples |
