-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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/gipv4: Ip2long is inconsistent with inet_addr in cpp #3984
Comments
I went to see the implementation of the net.parseIP method in GO. In the parseIP, the order of the IP addresses after parsing has been reversed, the []byte returned has been reversed. So if use BidEndian.Uint32 is inconsistent with inet_addr in cpp。But I don't know if this is a bug or if the author deliberately handled it this way. |
@berstpander The issue is not bug, 3232235777 is BigEndian result, 16885952 is LittleEndian result. |
@berstpander @oldme-git
Advantages of using Big-Endian:
In Go standard library:
Therefore, it's recommended to use big-endian when converting IP addresses to integers because:
|
Key Points:
Best Practices:
|
|
1 similar comment
|
@gqcn
|
Go version
go version go1.21.9 linux/amd64
GoFrame version
v2.7.4
Can this bug be reproduced with the latest release?
Option Yes
What did you do?
I use Ip2long to convert IP address from string to uint.
What did you see happen?
example: 122.168.1.1
Ip2long("192.168.1.1") = 3232235777
inet_addr("192.168.1.1") = 16885952
What did you expect to see?
I hope they are consistent
The text was updated successfully, but these errors were encountered: