dotnet / runtime

.NET is a cross-platform runtime for cloud, mobile, desktop, and IoT apps.
https://docs.microsoft.com/dotnet/core/
MIT License
14.89k stars 4.63k forks source link

IPAddresses returned from System.Net.NetworkInformation are missing ScopeID on OSX and Linux #17259

Closed mikeharder closed 4 years ago

mikeharder commented 8 years ago

Repro Steps

  1. Run the following code, and compare the results to ipconfig/ifconfig:
NetworkInterface.GetAllNetworkInterfaces()
    .SelectMany(i => i.GetIPProperties().UnicastAddresses)
    .Select(a => a.Address)
    .Where(a => a.IsIPv6LinkLocal)
    .ToList()
    .ForEach(ip => Console.WriteLine($"IP: {ip}, ScopeId: {ip.ScopeId}"));

Windows .NET Core

IP: fe80::1234:5678:90ab:cdef%18, ScopeId: 18
IP: fe80::1234:5.6.7.8%15, ScopeId: 15

ipconfig /all

Link-local IPv6 Address . . . . . : fe80::1234:5678:90ab:cdef%18(Preferred)

OS X .NET Core

IP: fe80::1, ScopeId: 0
IP: fe80::1234:5678:90ab:cdef, ScopeId: 0

ifconfig

inet6 fe80::1%lo0 prefixlen 64 scopeid 0x1
inet6 fe80::1234:5678:90ab:cdef%en0 prefixlen 64 scopeid 0x4

Linux .NET Core

IP: fe80::1234:5468:90ab:cdef, ScopeId: 0

ifconfig

eth0
inet6 addr: fe80::1234:5678:90ab:cdef/64 Scope:Link
davidsh commented 8 years ago

cc: @ericeil @stephentoub

mellinoe commented 8 years ago

I believe we just need to store the scopeID on line 82 of UnixNetworkInterface.cs. We already have the scope ID there.