Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get all local IP addresses doesn't work on WSL2 using System.Net.DNS.GetHostAddresses #37785

Closed
sipsorcery opened this issue Jun 12, 2020 · 3 comments
Milestone

Comments

@sipsorcery
Copy link

(this issue was originally logged on the WSL2 repo and was verified not to be a WSL2 issue).

Environment

Windows build number: Microsoft Windows [Version 10.0.19041.172]
Your Distribution version: Release:        18.04
Whether the issue is on WSL 2 and/or WSL 1: Linux version 4.4.0-19041-Microsoft (Microsoft@Microsoft.com) (gcc version 5.4.0 (GCC) ) #1-Microsoft Fri Dec 06 14:06:00 PST 2019

Steps to reproduce

Minimal .Net Core project to demonstrate the problem:

using System;
using System.Net;

namespace GetLocalIPAddresses
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Get Local IP Addresses Test:");

            var addresses = Dns.GetHostAddresses(string.Empty);
            Console.WriteLine($"Address count {addresses?.Length}.");

            foreach(var address in addresses)
            {
                Console.WriteLine(address);
            }
        }
    }
}

Expected behavior

Based on documentation here a call to System.Net.DNS.GetHostAddresses with an empty string should return a list of all the local IP addresses.

Windows 10 cmd shell result

>dotnet run --framework netcoreapp3.1
Get Local IP Addresses Test:
Address count 6.
fe80::54a9:d238:b2ee:ceb%21
fe80::3c8d:dbf7:1710:efb4%64
fe80::64dc:7955:ef80:6bc4%33
192.168.11.50
172.29.0.1
172.31.32.1

Ubuntu 18.04.4 LTS vm result

$ dotnet run --framework netcoreapp3.1
Get Local IP Addresses Test:
Address count 2.
192.168.11.41
fe80::20c:29ff:fee7:4ce4

Actual behavior

wsl2 result

$ dotnet run --framework netcoreapp3.1
Get Local IP Addresses Test:
Address count 1.
127.0.1.1
$ ifconfig
ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.11.50  netmask 255.255.255.0  broadcast 192.168.11.255
        inet6 fe80::54a9:d238:b2ee:ceb  prefixlen 64  scopeid 0xfd<compat,link,site,host>
        ether c8:d3:ff:b7:83:26  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

eth3: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 172.31.32.1  netmask 255.255.240.0  broadcast 172.31.47.255
        inet6 fe80::64dc:7955:ef80:6bc4  prefixlen 64  scopeid 0xfd<compat,link,site,host>
        ether 00:15:5d:7a:f6:49  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

eth4: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 172.29.0.1  netmask 255.255.240.0  broadcast 172.29.15.255
        inet6 fe80::3c8d:dbf7:1710:efb4  prefixlen 64  scopeid 0xfd<compat,link,site,host>
        ether 00:15:5d:58:a3:2e  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 1500
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0xfe<compat,link,site,host>
        loop  (Local Loopback)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
@Dotnet-GitSync-Bot Dotnet-GitSync-Bot added area-System.Net untriaged New issue has not been triaged by the area owner labels Jun 12, 2020
@ghost
Copy link

ghost commented Jun 12, 2020

Tagging subscribers to this area: @dotnet/ncl
Notify danmosemsft if you want to be subscribed.

@ManickaP
Copy link
Member

This seems like #27534 which should be fixed now.
@sipsorcery, could you please try it with 5.0 preview?

@sipsorcery
Copy link
Author

Yes I can confirm the issue is fixed in net5.0 preview.

dotnet run --framework net5.0
Get Local IP Addresses Test:
Address count 7.
127.0.1.1
192.168.11.50
fe80::54a9:d238:b2ee:ceb%21
172.31.32.1
fe80::64dc:7955:ef80:6bc4%33
172.29.0.1
fe80::3c8d:dbf7:1710:efb4%64

Apols for not spotting the original issue.

@ManickaP ManickaP removed the untriaged New issue has not been triaged by the area owner label Jun 12, 2020
@ManickaP ManickaP added this to the 5.0 milestone Jun 12, 2020
@ghost ghost locked as resolved and limited conversation to collaborators Dec 8, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants