Skip to content

Mac: IPGlobalProperties.GetIPGlobalProperties().GetActiveTcpListeners() does not list NodeJs listener #27585

Description

@IlyaBiryukov

OS: Mac OS High Sierra 10.13.6
DotNet Core 2.1.402

Repro Steps:

  1. Create and run the following NodeJS program to listen on port 8080:
var http = require('http');

http.createServer(function (req, res) {
    res.write('Hello world!');
    res.end();
}).listen(8080);
  1. Connect to localhost:8080 in browser and ensure that this server works.

  2. Now create and run a dotnet core 2.1.402 console app program that would enumerate all tcp listeners:

IPGlobalProperties ipProperties = IPGlobalProperties.GetIPGlobalProperties();
IPEndPoint[] ipEndPoints = ipProperties.GetActiveTcpListeners();

Expected:
ipEndPoints contains port 8080 where NodeJs app is listening

Actual:
There is no such port in ipEndPoints.

Other OS:
The issue doesn't repro on Windows 10 and Linux Ubuntu 16.04.

Activity

  1. karelz commented on Oct 11, 2018

    @karelz
    Member

    @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-L23

  2. wfurt commented on Oct 12, 2018

    @wfurt
    Member

    GetActiveTcpListeners() 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.

  3. karelz commented on Oct 12, 2018

    @karelz
    Member

    @wfurt is it broken on our side, or is the OS API giving us useless information?

  4. wfurt commented on Oct 12, 2018

    @wfurt
    Member

    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.

  5. wfurt commented on Oct 14, 2018

    @wfurt
    Member

    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 Listen
    

    and 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]:6014
    
  6. wfurt commented on Oct 15, 2018

    @wfurt
    Member

    Problem 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)

  7. self-assigned this
    on Oct 15, 2018
  8. transferred this issue fromdotnet/corefxon Jan 31, 2020
  9. added this to the 3.0 milestone on Jan 31, 2020
  10. ghost locked as resolved and limited conversation to collaborators on Dec 15, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions