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: UDPConn.LocalAddr() of ListenUDP returns "0.0.0.0:11110" instead of "127.0.0.1:11110" or "10.16.83.185:11110" #26347
Comments
cc @mikioh |
The LocalAddr method of UDPConn returns an address requested to the protocol stack inside the kernel that represents what traffic you want to receive. It's part of the convention how to represent an identifier that allows us to receive traffic on all available unicast and anycast IP addresses of the local system, and not Go standard library-specific (well, I guess it was born at and came from Berkeley.) The net package documentation tries to describe the convention a bit; please take a look at https://godoc.org/net#ListenUDP and https://godoc.org/net#ListenPacket. If you think we can do more better on the documentation, feel free to open a new issue for documentation improvement. In general, network-layer identifiers must be opaque to application-layer users. I'm still not sure the reason why application-layer people want to know the hidden structure on the identifiers without knowing the architecture and design limitations on functional planes that need the identifiers. |
"The LocalAddr method of UDPConn returns an address requested to the protocol stack inside the kernel that represents what traffic you want to receive." That makes sense for LocalAddr method of UDPConn. " It's part of the convention how to represent an identifier that allows us to receive traffic on all available unicast and anycast IP addresses of the local system, and not Go standard library-specific (well, I guess it was born at and came from Berkeley.) The net package documentation tries to describe the convention a bit; please take a look at https://godoc.org/net#ListenUDP and https://godoc.org/net#ListenPacket." Yes, it's a convention to use "0.0.0.0:port" or ":port" format for receiving traffic on all available ip address. But with C++, though bind m_iSock with address like ":port" or "0.0.0.0:port", I can get the server's "real" localAddr which is the client's remote address by "::getsockname(m_iSock, addr, &addr_len)". So, regardless of UDPConn. How can i get the server's "real" localAddr while i want to recevie udp traffic on all available unicast and anycast IP addresses of the local system with golang? Thanks. |
Please use other forums: https://github.com/golang/go/wiki/Questions. In general, if your running kernels or libraries in other languages provide something useful for you, it's easy to recreate in your own packages. I can guess that the word "real" you are saying means that something per-packet information because you are using "connection-less or stateless" datagram-based transport protocols such as UDP. Well, it's better to ask your question in more appropriate forums. |
Yes, in the example i mentioned, "real" address means : I'll refer to the forums for some guides. Thank you. |
Please answer these questions before submitting your issue. Thanks!
What version of Go are you using (
go version
)?go version go1.9.2 linux/amd64
What did you do?
Server side:
Client side:
What did you expect to see?
What did you see instead?
So what shoud i do to get the "expect" result? Thanks.
The text was updated successfully, but these errors were encountered: