File tree Expand file tree Collapse file tree 1 file changed +17
-0
lines changed Expand file tree Collapse file tree 1 file changed +17
-0
lines changed Original file line number Diff line number Diff line change @@ -808,6 +808,23 @@ impl SockAddr {
808
808
/// of the structure. Note that in the case of a `sockaddr_un`, `len` need not
809
809
/// include the terminating null.
810
810
///
811
+ /// # Example
812
+ /// ```no_run
813
+ /// # fn main() -> nix::Result<()> {
814
+ /// # use nix::sys::socket::SockAddr;
815
+ /// use libc::{sockaddr, sockaddr_storage, socklen_t};
816
+ /// extern "C" {
817
+ /// fn get_me_an_address(addr: *mut sockaddr, addrlen: *mut socklen_t);
818
+ /// }
819
+ /// use std::mem;
820
+ /// let mut addr = mem::MaybeUninit::<sockaddr_storage>::uninit();
821
+ /// let mut addrlen = mem::size_of::<sockaddr_storage>() as socklen_t;
822
+ /// unsafe { get_me_an_address(addr.as_mut_ptr() as *mut sockaddr, &mut addrlen) };
823
+ /// let addr: SockAddr = unsafe { SockAddr::from_raw_sockaddr(addr.as_ptr() as *const sockaddr, addrlen as usize)? };
824
+ /// # let _ = addr;
825
+ /// # Ok(()) }
826
+ /// ```
827
+ ///
811
828
/// # Safety
812
829
/// `addr` must be a valid, non-null pointer, and `len` should describe the
813
830
/// number of bytes within `*addr` that are initialized and represent data.
You can’t perform that action at this time.
0 commit comments