diff options
| author | Mazdak Farrokhzad <twingoow@gmail.com> | 2019-03-22 19:31:16 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-03-22 19:31:16 +0100 |
| commit | 5481b4e1d719a7d6de349c2e7a09574093710554 (patch) | |
| tree | e001fd07aebdb4b00cbfa02d1663e33ef5911e9e /src/libstd/sys_common | |
| parent | ed196221d889ae8a87be677402e4319237ef67f4 (diff) | |
| parent | 81d5fb5c6fc65e947ff97c02997bfff9a1f6ce16 (diff) | |
| download | rust-5481b4e1d719a7d6de349c2e7a09574093710554.tar.gz rust-5481b4e1d719a7d6de349c2e7a09574093710554.zip | |
Rollup merge of #59106 - LinusU:udp-peer-addr, r=kennytm
Add peer_addr function to UdpSocket Fixes #59104 This is my first pull request to Rust, so opening early for some feedback. My biggest question is: where do I add tests? Any comments very much appreciated!
Diffstat (limited to 'src/libstd/sys_common')
| -rw-r--r-- | src/libstd/sys_common/net.rs | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/src/libstd/sys_common/net.rs b/src/libstd/sys_common/net.rs index b9505aaa69b..b77bcee4b9d 100644 --- a/src/libstd/sys_common/net.rs +++ b/src/libstd/sys_common/net.rs @@ -472,6 +472,12 @@ impl UdpSocket { pub fn into_socket(self) -> Socket { self.inner } + pub fn peer_addr(&self) -> io::Result<SocketAddr> { + sockname(|buf, len| unsafe { + c::getpeername(*self.inner.as_inner(), buf, len) + }) + } + pub fn socket_addr(&self) -> io::Result<SocketAddr> { sockname(|buf, len| unsafe { c::getsockname(*self.inner.as_inner(), buf, len) |
