Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.Sign up
net: error message for ListenIP is confusing #36436
The documentation of
However using one of the documented IP network names (like "ip" or "ip4") causes the function to return an error on Linux; e.g.
According to #7439:
I confirmed that this works on Linux, but the function is clearly not documented correctly. From #7439 I assume that the format of
The documentation of the network parameter of
@perillo Thanks for looking into this.
The following works for me on Linux:
I think what may be confusing here is the error message when the protocol is omitted, which is, as you said,
The documentation points to
Does that make sense? How could we improve this? Out of curiosity, what are you using
@toothrot, I was using the ListenIP function because I totally missed the second part of the Dial function documentation about IP networks.
The documentation is correct and probably is just the error message that should be more explicit.
The answer, as far as I can tell, is that the
On linux or similar systems, I believe it uses
I'm not sure if I can definitively answer a question about the portability of the
@toothrot, note that services is used for looking at the default TCP/UDP port for common services.
Looking at the
In iprawsock.go, parseNetwork is called with needProto = false, and in iprawsock_posix.go it is called with needProto = true.
I assume that in #7439, windows was not included in the build tags, so needProto was set to false, causing the call to the Windows API to fail with EPROTONOSUPPORT.
So the documentation is probably correct, since all know systems need the protocol number/name.
I tested on Windows 10 amd64 with the latest version of go.
@bradfitz: it is the same error
Other protocol 0, 1 and 17 works. Also
The cause seems to be a Windows restriction:
There is another small issue in the documentation, due to platform limitations.
One entry of the bug list for the net package says:
So, calling net.ListenPacket("ip4:proto", addr) will return a net.PacketConn, that is actually unusable.