public static unsafe SafeCloseSocket CreateSocket(SocketInformation socketInformation, out AddressFamily addressFamily, out SocketType socketType, out ProtocolType protocolType)
{
SafeCloseSocket handle;
Interop.Winsock.WSAPROTOCOL_INFO protocolInfo;
fixed(byte *pinnedBuffer = socketInformation.ProtocolInformation)
{
handle = SafeCloseSocket.CreateWSASocket(pinnedBuffer);
protocolInfo = (Interop.Winsock.WSAPROTOCOL_INFO)Marshal.PtrToStructure <Interop.Winsock.WSAPROTOCOL_INFO>((IntPtr)pinnedBuffer);
}
if (handle.IsInvalid)
{
SocketException e = new SocketException();
if (e.SocketErrorCode == SocketError.InvalidArgument)
{
throw new ArgumentException(SR.net_sockets_invalid_socketinformation, "socketInformation");
}
else
{
throw e;
}
}
addressFamily = protocolInfo.iAddressFamily;
socketType = (SocketType)protocolInfo.iSocketType;
protocolType = (ProtocolType)protocolInfo.iProtocol;
return(handle);
}