Add Socket::IPAddress predicates and constants#6710
Merged
sdogruyol merged 5 commits intocrystal-lang:masterfrom Oct 15, 2018
Merged
Add Socket::IPAddress predicates and constants#6710sdogruyol merged 5 commits intocrystal-lang:masterfrom
sdogruyol merged 5 commits intocrystal-lang:masterfrom
Conversation
9dff90a to
d396d5d
Compare
d396d5d to
fa4de53
Compare
bew
reviewed
Sep 13, 2018
src/socket/address.cr
Outdated
| if family == Family::INET | ||
| @addr4.not_nil!.s_addr & 0x00000000ff_u32 == 0x0000007f_u32 | ||
| else | ||
| @address == LOOPBACK6 |
Contributor
There was a problem hiding this comment.
What if the address is 0000:0000:0000:0000:0000:0000:0000:0001 ? It should work too IMO
Member
Author
There was a problem hiding this comment.
Yeah, true. But maybe it's better to normalize the address...
4915338 to
314ac75
Compare
314ac75 to
0a43ed2
Compare
26528aa to
a15d4f1
Compare
bew
reviewed
Oct 3, 2018
src/socket/address.cr
Outdated
| private def ipv6_addr8(addr : LibC::In6Addr) | ||
| {% if flag?(:darwin) || flag?(:openbsd) || flag?(:freebsd) %} | ||
| addr.__u6_addr.__u6_addr8 | ||
| {% elsif flag?(:linux) && flag?(:musl) %} |
Contributor
There was a problem hiding this comment.
there's a double space here.
Also, can you indent the code in the macro conditions?
747e21a to
8b0756a
Compare
RX14
reviewed
Oct 3, 2018
| puts "Listening on http://#{address}" | ||
| if host == "0.0.0.0" | ||
| puts "WARNING running playground with 0.0.0.0 is unsecure." | ||
| if address.unspecified? |
Member
There was a problem hiding this comment.
Perhaps a later PR to make this have better behaviour: test for not-loopback not 0.0.0.0 specifically
RX14
approved these changes
Oct 3, 2018
sdogruyol
approved these changes
Oct 15, 2018
Member
sdogruyol
left a comment
There was a problem hiding this comment.
Thank you @straight-shoota 👍
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR adds methods to query information of
IPAddressinstancesSocket::IPAddress#loopback?returns whether the address is a loopback address (127.0.0.0/24or::1)Socket::IPAddress#unspecified?returns whether the address is unspecified (0.0.0.0or::)Default values for
LOOPBACK,UNSPECIFIEDandBROADCASTare also added as constants for both IPv4 and IPv6.