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

net: The result of net.Interfaces in go1.5.2 is different from go1.4.3 on windows #13476

Closed
chanxuehong opened this issue Dec 4, 2015 · 11 comments

Comments

Projects
None yet
7 participants
@chanxuehong
Copy link
Contributor

commented Dec 4, 2015

1.What version of Go are you using ( go version )?
go1.5.2 vs go1.4.3

2.What operating system and processor architecture are you using?
windows 10 pro
amd64

3.What did you do?

package main

import (
    "fmt"
    "net"
)

func main() {
    interfaces, err := net.Interfaces()
    if err != nil {
        fmt.Println(err)
        return
    }
    for _, itf := range interfaces {
        fmt.Println(itf.Index, itf.Name, itf.Flags, itf.HardwareAddr, itf.MTU)
        fmt.Println(itf.Addrs())
        fmt.Println()
    }
}

4.What did you expect to see?
the same result

5.What did you see instead?
go1.4.3:

  1. can't gets name
  2. can't gets ipv6
  3. if the interface is down, can't gets others flags
7 {2DF95280-F517-4E59-B5C4-9B3EC1664A70} up|broadcast|multicast a4:db:30:fe:d8:e1 1500
[192.168.1.80] <nil>

4 {18CABAEB-989A-44AF-8487-56FB9B6AC23A} 0 28:d2:44:2b:99:02 1500
[0.0.0.0] <nil>

16 {F28FF002-5F7A-41B6-8301-A1E883AE419A} 0 b0:05:94:fe:6a:dd 1500
[0.0.0.0] <nil>

go1.5.2:

  1. if the interface is down, can't gets.
7 无线网络连接 up|broadcast|multicast a4:db:30:fe:d8:e1:00:00 1500
[fe80::511e:c13a:2d03:aced/28 192.168.1.80/16] <nil>

1 Loopback Pseudo-Interface 1 up|loopback|multicast 00:00:00:00:00:00:00:00 4294967295
[::1/28 127.0.0.1/16] <nil>

my interfaces config:

C:\Users\chan>ipconfig /all

Windows IP 配置

   主机名  . . . . . . . . . . . . . : chan-PC
   主 DNS 后缀 . . . . . . . . . . . :
   节点类型  . . . . . . . . . . . . : 混合
   IP 路由已启用 . . . . . . . . . . : 是
   WINS 代理已启用 . . . . . . . . . : 否

以太网适配器 本地连接:

   媒体状态  . . . . . . . . . . . . : 媒体已断开连接
   连接特定的 DNS 后缀 . . . . . . . :
   描述. . . . . . . . . . . . . . . : Realtek PCIe GBE Family Controller
   物理地址. . . . . . . . . . . . . : 28-D2-44-2B-99-02
   DHCP 已启用 . . . . . . . . . . . : 是
   自动配置已启用. . . . . . . . . . : 是

无线局域网适配器 无线网络连接:

   连接特定的 DNS 后缀 . . . . . . . :
   描述. . . . . . . . . . . . . . . : 1x1 11b/g/n 无线局域网 PCI Express Half Mini Card 适配器
   物理地址. . . . . . . . . . . . . : A4-DB-30-FE-D8-E1
   DHCP 已启用 . . . . . . . . . . . : 否
   自动配置已启用. . . . . . . . . . : 是
   本地链接 IPv6 地址. . . . . . . . : fe80::511e:c13a:2d03:aced%7(首选)
   IPv4 地址 . . . . . . . . . . . . : 192.168.1.80(首选)
   子网掩码  . . . . . . . . . . . . : 255.255.255.0
   默认网关. . . . . . . . . . . . . : 192.168.1.1
   DHCPv6 IAID . . . . . . . . . . . : 312793904
   DHCPv6 客户端 DUID  . . . . . . . : 00-01-00-01-1C-4B-A4-0B-28-D2-44-2B-99-02
   DNS 服务器  . . . . . . . . . . . : 202.102.213.68
                                       61.132.163.68
   TCPIP 上的 NetBIOS  . . . . . . . : 已启用

以太网适配器 Bluetooth 网络连接:

   媒体状态  . . . . . . . . . . . . : 媒体已断开连接
   连接特定的 DNS 后缀 . . . . . . . :
   描述. . . . . . . . . . . . . . . : Bluetooth Device (Personal Area Network)
   物理地址. . . . . . . . . . . . . : B0-05-94-FE-6A-DD
   DHCP 已启用 . . . . . . . . . . . : 是
   自动配置已启用. . . . . . . . . . : 是

隧道适配器 Teredo Tunneling Pseudo-Interface:

   连接特定的 DNS 后缀 . . . . . . . :
   描述. . . . . . . . . . . . . . . : Microsoft Teredo Tunneling Adapter
   物理地址. . . . . . . . . . . . . : 00-00-00-00-00-00-00-E0
   DHCP 已启用 . . . . . . . . . . . : 否
   自动配置已启用. . . . . . . . . . : 是
   IPv6 地址 . . . . . . . . . . . . : 2001:0:9d38:6ab8:487:1bd:dbc0:8d96(首选) 
   本地链接 IPv6 地址. . . . . . . . : fe80::487:1bd:dbc0:8d96%17(首选)
   默认网关. . . . . . . . . . . . . : ::
   DHCPv6 IAID . . . . . . . . . . . : 335544320
   DHCPv6 客户端 DUID  . . . . . . . : 00-01-00-01-1C-4B-A4-0B-28-D2-44-2B-99-02
   TCPIP 上的 NetBIOS  . . . . . . . : 已禁用

隧道适配器 isatap.{2DF95280-F517-4E59-B5C4-9B3EC1664A70}:

   媒体状态  . . . . . . . . . . . . : 媒体已断开连接
   连接特定的 DNS 后缀 . . . . . . . :
   描述. . . . . . . . . . . . . . . : Microsoft ISATAP Adapter #2
   物理地址. . . . . . . . . . . . . : 00-00-00-00-00-00-00-E0
   DHCP 已启用 . . . . . . . . . . . : 否
   自动配置已启用. . . . . . . . . . : 是
@chanxuehong

This comment has been minimized.

Copy link
Contributor Author

commented Dec 4, 2015

additional bugs in go1.5.2:
if I change my Wireless interface from up state to down, the above code returns the same result.

7 无线网络连接 up|broadcast|multicast a4:db:30:fe:d8:e1:00:00 1500
[fe80::511e:c13a:2d03:aced/28 192.168.1.80/16] <nil>

1 Loopback Pseudo-Interface 1 up|loopback|multicast 00:00:00:00:00:00:00:00 4294967295
[::1/28 127.0.0.1/16] <nil>
C:\Users\chan>ipconfig /all

Windows IP 配置

   主机名  . . . . . . . . . . . . . : chan-PC
   主 DNS 后缀 . . . . . . . . . . . :
   节点类型  . . . . . . . . . . . . : 混合
   IP 路由已启用 . . . . . . . . . . : 是
   WINS 代理已启用 . . . . . . . . . : 否

以太网适配器 本地连接:

   媒体状态  . . . . . . . . . . . . : 媒体已断开连接
   连接特定的 DNS 后缀 . . . . . . . :
   描述. . . . . . . . . . . . . . . : Realtek PCIe GBE Family Controller
   物理地址. . . . . . . . . . . . . : 28-D2-44-2B-99-02
   DHCP 已启用 . . . . . . . . . . . : 是
   自动配置已启用. . . . . . . . . . : 是

无线局域网适配器 无线网络连接:

   媒体状态  . . . . . . . . . . . . : 媒体已断开连接
   连接特定的 DNS 后缀 . . . . . . . :
   描述. . . . . . . . . . . . . . . : 1x1 11b/g/n 无线局域网 PCI Express Half Mini Card 适配器
   物理地址. . . . . . . . . . . . . : A4-DB-30-FE-D8-E1
   DHCP 已启用 . . . . . . . . . . . : 否
   自动配置已启用. . . . . . . . . . : 是

以太网适配器 Bluetooth 网络连接:

   媒体状态  . . . . . . . . . . . . : 媒体已断开连接
   连接特定的 DNS 后缀 . . . . . . . :
   描述. . . . . . . . . . . . . . . : Bluetooth Device (Personal Area Network)
   物理地址. . . . . . . . . . . . . : B0-05-94-FE-6A-DD
   DHCP 已启用 . . . . . . . . . . . : 是
   自动配置已启用. . . . . . . . . . : 是

隧道适配器 Teredo Tunneling Pseudo-Interface:

   媒体状态  . . . . . . . . . . . . : 媒体已断开连接
   连接特定的 DNS 后缀 . . . . . . . :
   描述. . . . . . . . . . . . . . . : Microsoft Teredo Tunneling Adapter
   物理地址. . . . . . . . . . . . . : 00-00-00-00-00-00-00-E0
   DHCP 已启用 . . . . . . . . . . . : 否
   自动配置已启用. . . . . . . . . . : 是

@ianlancetaylor ianlancetaylor added this to the Go1.6 milestone Dec 4, 2015

@chanxuehong chanxuehong changed the title net: The result of net.Interfaces in go1.5.2 is different from go1.4.3 net: The result of net.Interfaces in go1.5.2 is different from go1.4.3 on windows Dec 4, 2015

@alexbrainman

This comment has been minimized.

Copy link
Member

commented Dec 4, 2015

4.What did you expect to see?
the same result

Some bugs where fixed in go1.5.2 (comparing to go1.4.3). So it is to be expected that your program output will be different. I don't see a problem here. Or don't you want us to fix bugs?

Alex

@mdempsky

This comment has been minimized.

Copy link
Member

commented Dec 4, 2015

It seems that net.Interfaces is no longer returning @chanxuehong's 28:d2:44:2b:99:02 or b0:05:94:fe:6a:dd interfaces in 1.5.2. At least on Linux and OpenBSD, we still list interfaces even if they're down and down have addresses, which seems consistent with the documentation for net.Interfaces.

I also note the HardwareAddr for interface 7 changed from "a4:db:30:fe:d8:e1" to "a4:db:30:fe:d8:e1**:00:00**". Linux and OpenBSD both report addresses in MAC-48 (6 octet) form, and if it was to be converted to EUI-64 (8 octet) form I would think it should be "a4:db:30:ff:ff:fe:d8:e1" (or maybe "a4:db:30:ff:fe:fe:d8:e1"), no?

@mdempsky

This comment has been minimized.

Copy link
Member

commented Dec 4, 2015

At least the HardwareAddr change appears due to CL 3024 (ea22a08) changed:

                           HardwareAddr: HardwareAddr(row.PhysAddr[:row.PhysAddrLen]),

to:

                           HardwareAddr: HardwareAddr(paddr.PhysicalAddress[:]),

I.e., without using paddr.PhysicalAddressLength.

@mdempsky

This comment has been minimized.

Copy link
Member

commented Dec 4, 2015

@chanxuehong Can you try https://go-review.googlesource.com/#/c/17422/? (Disclaimer: I don't have any Windows machines myself, so all I've been able to test so far is that it still compiles.)

@litg

This comment has been minimized.

Copy link

commented Dec 4, 2015

The GetAdaptersAddresses function can retrieve information for IPv4 and IPv6 addresses.
Addresses are returned as a linked list of IP_ADAPTER_ADDRESSES structures in the buffer pointed to by the AdapterAddresses parameter.

ref: https://msdn.microsoft.com/en-us/library/windows/desktop/aa365915(v=vs.85).aspx

@gopherbot

This comment has been minimized.

Copy link

commented Dec 4, 2015

CL https://golang.org/cl/17422 mentions this issue.

@mdempsky

This comment has been minimized.

Copy link
Member

commented Dec 4, 2015

@litg True, but it looks like we're using SIO_GET_INTERFACE_LIST, which documents that it returns an array:

The lpvOutBuffer parameter points to the buffer in which to store the information about interfaces as an array of INTERFACE_INFO structures for unicast IP addresses on the interfaces. The cbOutBuffer parameter specifies the length of the output buffer. The number of interfaces returned (number of structures returned in the buffer pointed to by lpvOutBuffer parameter) can be determined based on the actual length of the output buffer returned in lpcbBytesReturned parameter.

https://msdn.microsoft.com/en-us/library/windows/desktop/ms741621(v=vs.85).aspx

Am I missing something? Is it still necessary to traverse the INTERFACE_INFOs as a linked list rather than an array for some reason?

(Note: I have almost no experience with Windows programming, so I'm just making a best effort here until someone who knows what they're doing takes over. :-))

@gopherbot

This comment has been minimized.

Copy link

commented Dec 4, 2015

CL https://golang.org/cl/17412 mentions this issue.

@SR-G

This comment has been minimized.

Copy link

commented Feb 2, 2016

Hey.
I have the same problem listed above by @mdempsky about the format of the returned MAC address on windows : "a4:db:30:fe:d8:e1**:00:00**" (two extra :00 at the end).
It was indeed not the case on previous GO version (i'm using GO 1.5.3 right now).
Is it a bug or a feature ? (in that case, how am i supposed to get the correct MAC address (which would just be "a4:db:30:fe:d8:e1"). Thanks in advance.

@mdempsky

This comment has been minimized.

Copy link
Member

commented Feb 2, 2016

@SR-G It's a bug and will be fixed in Go 1.6. You can try with 1.6rc1 in the mean time: https://golang.org/dl/#go1.6rc1

@golang golang locked and limited conversation to collaborators Feb 3, 2017

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
You can’t perform that action at this time.