/// <summary>
 /// Delete target peer for socket.
 /// </summary>
 /// <param name="socket">The socket to set.</param>
 /// <param name="peer_address">Peer address.</param>
 /// <param name="throw_on_error">True to throw on error.</param>
 /// <returns>The NT status code.</returns>
 public static NtStatus DeletePeerTargetName(this Socket socket, IPEndPoint peer_address, bool throw_on_error)
 {
     byte[] addr = peer_address.ToArray();
     return(SocketNativeMethods.WSADeleteSocketPeerTargetName(
                socket.Handle, addr, addr.Length, IntPtr.Zero,
                IntPtr.Zero).GetNtStatus(throw_on_error));
 }
 private static ulong[] ToSocketStorage(this IPEndPoint ep)
 {
     ulong[] ret = new ulong[16];
     if (ep == null)
     {
         return(ret);
     }
     byte[] buffer = ep.ToArray();
     Buffer.BlockCopy(buffer, 0, ret, 0, buffer.Length);
     return(ret);
 }
 /// <summary>
 /// Impersonate the socket's peer.
 /// </summary>
 /// <param name="socket">The socket to impersonate.</param>
 /// <param name="peer_address">Optional peer address. Only needed for datagram sockets.</param>
 /// <param name="throw_on_error">True to throw on error.</param>
 /// <returns>The impersonation context.</returns>
 public static NtResult <ThreadImpersonationContext> Impersonate(this Socket socket, IPEndPoint peer_address, bool throw_on_error)
 {
     byte[] addr = peer_address?.ToArray();
     return(SocketNativeMethods.WSAImpersonateSocketPeer(socket.Handle, addr, addr?.Length ?? 0)
            .CreateWSAResult(throw_on_error, () => new ThreadImpersonationContext()));
 }