@@ -564,11 +564,36 @@ impl Socket {
564564 /// `peek_from` makes the same safety guarantees regarding the `buf`fer as
565565 /// [`recv`].
566566 ///
567+ /// # Note: Datagram Sockets
568+ /// For datagram sockets, the behavior of this method when `buf` is smaller than
569+ /// the datagram at the head of the receive queue differs between Windows and
570+ /// Unix-like platforms (Linux, macOS, BSDs, etc: colloquially termed "*nix").
571+ ///
572+ /// On *nix platforms, the datagram is truncated to the length of `buf`.
573+ ///
574+ /// On Windows, an error corresponding to `WSAEMSGSIZE` will be returned.
575+ ///
576+ /// For consistency between platforms, be sure to provide a sufficiently large buffer to avoid
577+ /// truncation; the exact size required depends on the underlying protocol.
578+ ///
579+ /// If you just want to know the sender of the data, try [`peek_sender`].
580+ ///
567581 /// [`recv`]: Socket::recv
582+ /// [`peek_sender`]: Socket::peek_sender
568583 pub fn peek_from ( & self , buf : & mut [ MaybeUninit < u8 > ] ) -> io:: Result < ( usize , SockAddr ) > {
569584 self . recv_from_with_flags ( buf, sys:: MSG_PEEK )
570585 }
571586
587+ /// Retrieve the sender for the data at the head of the receive queue.
588+ ///
589+ /// This is equivalent to calling [`peek_from`] with a zero-sized buffer,
590+ /// but suppresses the `WSAEMSGSIZE` error on Windows.
591+ ///
592+ /// [`peek_from`]: Socket::peek_from
593+ pub fn peek_sender ( & self ) -> io:: Result < SockAddr > {
594+ sys:: peek_sender ( self . as_raw ( ) )
595+ }
596+
572597 /// Sends data on the socket to a connected peer.
573598 ///
574599 /// This is typically used on TCP sockets or datagram sockets which have
0 commit comments