Repository navigation
Mac: IPGlobalProperties.GetIPGlobalProperties().GetActiveTcpListeners() does not list NodeJs listener #27585
Description
Activity
@IlyaBiryukov can you please try it with ASP.NET Core local server as well? Is it specific to NodeJs server only?
Would you be able to tell if the Mac OS APIs truly return correct info? We basically just return what the OS tells us:
https://github.com/dotnet/corefx/blob/a10890f4ffe0fadf090c922578ba0e606ebdd16c/src/System.Net.NetworkInformation/src/System/Net/NetworkInformation/OsxIPGlobalProperties.cs#L10-L23GetActiveTcpListeners() seems totally broken @karelz. On OSX it gives me TCP connections but no actual listeners. e.g. socket in LISTEN state. I did run on Linux for comparison and there it does list listening sockets but it also includes other sockets.
@wfurt is it broken on our side, or is the OS API giving us useless information?
I don't know yet. I did not find any tests for this function. I'll do basic triage for both OSX and Linux since I have repro code running.
It seems like GetActiveTcpConnections() is also not working right on LInux.
According to documentation:The objects returned by this method include connections in all TCP states except the Listen state. You can check the state of a connection by calling State.
Console.WriteLine("Active"); TcpConnectionInformation[] tcp = ipProperties.GetActiveTcpConnections(); foreach (TcpConnectionInformation ti in tcp) { Console.WriteLine("{0} = {1} {2}", ti.LocalEndPoint, ti.RemoteEndPoint, ti.State); }
gives
Active 0.0.0.0:139 = 0.0.0.0:0 Listen 0.0.0.0:80 = 0.0.0.0:0 Listen 0.0.0.0:22 = 0.0.0.0:0 Listen 127.0.0.1:6010 = 0.0.0.0:0 Listen 127.0.0.1:6011 = 0.0.0.0:0 Listen 127.0.0.1:6012 = 0.0.0.0:0 Listen 127.0.0.1:6013 = 0.0.0.0:0 Listen 0.0.0.0:445 = 0.0.0.0:0 Listen 127.0.0.1:6014 = 0.0.0.0:0 Listen 10.211.55.5:22 = 10.211.55.2:61630 Established 10.211.55.5:22 = 10.211.55.2:50357 Established 10.211.55.5:22 = 10.211.55.2:50356 Established 10.211.55.5:22 = 10.211.55.2:57085 Established 10.211.55.5:22 = 10.211.55.2:60080 Established [::]:139 = [::]:0 Listen [::]:80 = [::]:0 Listen [::]:22 = [::]:0 Listen [::1.0.0.0]:6010 = [::]:0 Listen [::1.0.0.0]:6011 = [::]:0 Listen [::1.0.0.0]:6012 = [::]:0 Listen [::1.0.0.0]:6013 = [::]:0 Listen [::]:445 = [::]:0 Listen [::1.0.0.0]:6014 = [::]:0 Listenand the listener list returns:
Listeners 0.0.0.0:139 0.0.0.0:80 0.0.0.0:22 127.0.0.1:6010 127.0.0.1:6011 127.0.0.1:6012 127.0.0.1:6013 0.0.0.0:445 127.0.0.1:6014 10.211.55.5:22 10.211.55.5:22 10.211.55.5:22 10.211.55.5:22 10.211.55.5:22 [::]:139 [::]:80 [::]:22 [::1.0.0.0]:6010 [::1.0.0.0]:6011 [::1.0.0.0]:6012 [::1.0.0.0]:6013 [::]:445 [::1.0.0.0]:6014Problem with OSX is that kernel provides port numbers in network byte order but PAL does not convert them to host order. To workaround this you can call GetActiveTcpConnections() and look for State==Listen and port == 36895 (8080 -> 0x1f90 -> 0x901f -> 36895)
- ghost locked as resolved and limited conversation to collaborators
on Dec 15, 2020
OS: Mac OS High Sierra 10.13.6
DotNet Core 2.1.402
Repro Steps:
Connect to localhost:8080 in browser and ensure that this server works.
Now create and run a dotnet core 2.1.402 console app program that would enumerate all tcp listeners:
Expected:
ipEndPointscontains port 8080 where NodeJs app is listeningActual:
There is no such port in
ipEndPoints.Other OS:
The issue doesn't repro on Windows 10 and Linux Ubuntu 16.04.