diff --git a/src/Servers/Kestrel/Transport.Sockets/src/SocketConnectionListener.cs b/src/Servers/Kestrel/Transport.Sockets/src/SocketConnectionListener.cs index 013b5a0448ee..6f6e10f867e4 100644 --- a/src/Servers/Kestrel/Transport.Sockets/src/SocketConnectionListener.cs +++ b/src/Servers/Kestrel/Transport.Sockets/src/SocketConnectionListener.cs @@ -64,14 +64,10 @@ internal void Bind() Socket listenSocket; - if (EndPoint is UnixDomainSocketEndPoint) - { - listenSocket = new Socket(EndPoint.AddressFamily, SocketType.Stream, ProtocolType.Unspecified); - } - else - { - listenSocket = new Socket(EndPoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp); - } + // Unix domain sockets are unspecified + var protocolType = EndPoint is UnixDomainSocketEndPoint ? ProtocolType.Unspecified : ProtocolType.Tcp; + + listenSocket = new Socket(EndPoint.AddressFamily, SocketType.Stream, protocolType); // Kestrel expects IPv6Any to bind to both IPv6 and IPv4 if (EndPoint is IPEndPoint ip && ip.Address == IPAddress.IPv6Any)