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

Automatic IPv6 detection while converting long to IP #11

Merged
merged 2 commits into from
Nov 2, 2023
Merged

Automatic IPv6 detection while converting long to IP #11

merged 2 commits into from
Nov 2, 2023

Conversation

kovalensky
Copy link
Contributor

@kovalensky kovalensky commented Oct 3, 2023

Due to ip2long() function being able to handle both v4 and v6 addresses, it takes another step for the developer to save information about IP address, for it being decoded by long2ip.

Max long value coming from ipv4 -> 255.255.255.255 is 4294967295 (32bit max integer).

Smallest ipv6 address is 2000:: -> 42535295865117307932921825928971026432.

So it is safe to use this condition.

Additionally odd behaviour is about ::1 returning 1, while 127.0.0.1 is 2130706433.
:: returns 0.

src/Ip.php Show resolved Hide resolved
@akalongman akalongman merged commit 7c38137 into akalongman:master Nov 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants