Closed
Description
package main
import(
"fmt"
"net"
)
func main(){
ifs, err := net.Interfaces()
if err != nil {
fmt.Println(err)
}
for _, inf := range ifs {
x, _ := inf.Addrs()
fmt.Printf("%#v %s", inf, x)
}
}
In 1.4.1 returns:
net.Interface{Index:5, MTU:1500, Name:"{E36EC396-D578-48C0-82D5-F55217877570}", HardwareAddr:net.HardwareAddr{0x94, 0xde, 0x80, 0xaf, 0x4b, 0x62}, Flags:0x0} [192.168.1.70]
In 1.5 returns:
net.Interface{Index:1, MTU:4294967295, Name:"Loopback Pseudo-Interface 1", HardwareAddr:net.HardwareAddr{0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}, Flags:0x15} [::1/28 127.0.0.1/16]
Any code relying on net.Interfaces() breaks (for example making multicasts to all interfaces, since Windows by default multicasts to some single interface)
What version of Go are you using (go version)?
go version go1.5 windows/amd64
What operating system and processor architecture are you using?
Windows 8.1 x64
What did you do?
Called net.Interfaces()
What did you expect to see?
My one external interface
What did you see instead?
My one loopback interface
ipconfig /all
c:\Go\src\net>ipconfig /all
Windows IP Configuration
Host Name . . . . . . . . . . . . : Audrius
Primary Dns Suffix . . . . . . . :
Node Type . . . . . . . . . . . . : Hybrid
IP Routing Enabled. . . . . . . . : No
WINS Proxy Enabled. . . . . . . . : No
DNS Suffix Search List. . . . . . : lan
Ethernet adapter Ethernet 5:
Connection-specific DNS Suffix . : lan
Description . . . . . . . . . . . : Hyper-V Virtual Ethernet Adapter #2
Physical Address. . . . . . . . . : 94-DE-80-AF-4B-62
DHCP Enabled. . . . . . . . . . . : Yes
Autoconfiguration Enabled . . . . : Yes
Link-local IPv6 Address . . . . . : fe80::58d9:707e:1173:32c%5(Preferred)
IPv4 Address. . . . . . . . . . . : 192.168.1.70(Preferred)
Subnet Mask . . . . . . . . . . . : 255.255.255.0
Lease Obtained. . . . . . . . . . : 23 August 2015 13:46:11
Lease Expires . . . . . . . . . . : 25 August 2015 13:46:22
Default Gateway . . . . . . . . . : 192.168.1.254
DHCP Server . . . . . . . . . . . : 192.168.1.254
DHCPv6 IAID . . . . . . . . . . . : 1150606976
DHCPv6 Client DUID. . . . . . . . : 00-01-00-01-1D-3C-8E-0C-94-DE-80-AF-4B-62
DNS Servers . . . . . . . . . . . : fe80::9e97:26ff:fe78:cec2%5
8.8.8.8
4.4.8.8
NetBIOS over Tcpip. . . . . . . . : Enabled
Tunnel adapter isatap.lan:
Media State . . . . . . . . . . . : Media disconnected
Connection-specific DNS Suffix . : lan
Description . . . . . . . . . . . : Microsoft ISATAP Adapter #4
Physical Address. . . . . . . . . : 00-00-00-00-00-00-00-E0
DHCP Enabled. . . . . . . . . . . : No
Autoconfiguration Enabled . . . . : Yes
netsh interface show interface
Admin State State Type Interface Name
-------------------------------------------------------------------------
Enabled Connected Dedicated Ethernet 3
Enabled Connected Dedicated Ethernet 5
Test output:
c:\Go\src\net>go test -v -run=Interface
=== RUN TestInterfaces
--- PASS: TestInterfaces (0.00s)
interface_test.go:79: "Loopback Pseudo-Interface 1": flags "up|loopback|multicast", ifindex 1, mtu 4294967295
interface_test.go:80: hardware address "00:00:00:00:00:00:00:00"
interface_test.go:202: interface address "::1/28"
interface_test.go:202: interface address "127.0.0.1/16"
interface_test.go:223: joined group address "ff02::c"
interface_test.go:223: joined group address "239.255.255.250"
=== RUN TestInterfaceAddrs
--- PASS: TestInterfaceAddrs (0.00s)
interface_test.go:202: interface address "fe80::58d9:707e:1173:32c/28"
interface_test.go:202: interface address "192.168.1.70/16"
interface_test.go:202: interface address "::1/28"
interface_test.go:202: interface address "127.0.0.1/16"
interface_test.go:202: interface address "fe80::5efe:c0a8:146/28"
PASS
Socket statistical information:
(inet4, datagram, udp): opened=4, connected=0, listened=0, accepted=0, closed=4, openfailed=0, connectfailed=0, listenfailed=0, acceptfailed=0, closefailed=0
ok net 0.124s