-
-
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
IPAddress#loopback?
should consider ::ffff:127.0.0.1/104
loopback too
#12783
IPAddress#loopback?
should consider ::ffff:127.0.0.1/104
loopback too
#12783
Conversation
IPAddress#loopback?
should consider ::ffff:127.0.0.1/104
loopback too
Co-authored-by: Johannes Müller <[email protected]>
src/socket/address.cr
Outdated
ipv6_addr8(addr) == StaticArray[0_u8, 0_u8, 0_u8, 0_u8, 0_u8, 0_u8, 0_u8, 0_u8, 0_u8, 0_u8, 0_u8, 0_u8, 0_u8, 0_u8, 0_u8, 1_u8] | ||
addr8 = ipv6_addr8(addr) | ||
addr8 == StaticArray[0_u8, 0_u8, 0_u8, 0_u8, 0_u8, 0_u8, 0_u8, 0_u8, 0_u8, 0_u8, 0_u8, 0_u8, 0_u8, 0_u8, 0_u8, 1_u8] || # "::1" | ||
addr8.to_slice[0, 13] == Bytes[0_u8, 0_u8, 0_u8, 0_u8, 0_u8, 0_u8, 0_u8, 0_u8, 0_u8, 0_u8, 255_u8, 255_u8, 127_u8] # "::ffff:127.0.0.1/104" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be turned into a constant to avoid having to allocate the Bytes
on every call (and the StaticArray
above too if you wish)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or StaticArray#to_slice? will only stack allocate.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it might be simpler to turn the raw bytes into UInt64
or whatever and compare things against numbers. It should also be faster.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same speed for StaticArray[...]#to_slice
and .unsafe_as(UInt128)
(1ns to do the check), I guess it comes down to readability. See for comparison: 3663384
c128672
to
fe512dd
Compare
As they aren't supported in older crystal versions Co-authored-by: Johannes Müller <[email protected]>
fe512dd
to
f9a212b
Compare
@carlhoerberg Something went wrong with your rebase. I suppose you intended to update the branch on master. But somewhow that got botched and there were some weird commits that don't belong here. |
No description provided.