-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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: typo in IPNet.String documentation #33433
Comments
It looks correct to me. 192.0.2.1 is the host IP, and /24 is the prefix. What is wrong here ? |
Nope, the base IP address of 192.0.2.1/24 is 192.0.2.0, and the String() method use the base, see the test or the source: |
Oh that's right. |
@clairerhoda perhaps you might be interested in this issue? |
Up to you and @clairerhoda to figure out. I would suggest to wait for @clairerhoda to have a chance to respond. |
Sure. Will wait for @clairerhoda to decide. |
@odeke-em @agnivade if @bharaththiruveedula has it done he can open the PR. |
sure... then I will send PR |
Change https://golang.org/cl/189117 mentions this issue: |
Sorry, actually this example is correct. I did not analyze @gaissmai's example in detail. @gaissmai - what your playground example is doing with Please see the following code (https://play.golang.org/p/-1UYrVvjtTs): package main
import (
"fmt"
"net"
)
func main() {
ip := net.IPNet{IP: net.IPv4(192, 168, 1, 4), Mask: net.CIDRMask(24, 32)}
fmt.Println(ip.String())
} And as a further confirmation, (*IPNet).String calls networkNumberAndMask which has if ip = n.IP.To4(); ip == nil {
ip = n.IP
if len(ip) != IPv6len {
return nil, nil
}
} Therefore, I think the docs are correct and there is no issue here. |
@agnivade Hi, sorry but I disagree. Your example is a little bit contrived. The type IPNet consists of the netnumber and related CIDR mask. Your example misuse the public fileds of type IPNet to put an IP address in this slot which is not a netnumber for the related CIDR mask..
If you use ParseCIDR to generate the IPNet struct you will never get the wrong IP address in this field. |
Well yes, but the docs are technically right. Although, EDIT: to clarify, I am agreeing with you. Just waiting for a second opinion. |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
currently latest stable
What operating system and processor architecture are you using (
go env
)?What did you do?
read the documentation
What did you expect to see?
What did you see instead?
The text was updated successfully, but these errors were encountered: