Skip to content

IPAddr#global_unicast?#116

Open
HoneyryderChuck wants to merge 2 commits into
ruby:masterfrom
HoneyryderChuck:global-unicast
Open

IPAddr#global_unicast?#116
HoneyryderChuck wants to merge 2 commits into
ruby:masterfrom
HoneyryderChuck:global-unicast

Conversation

@HoneyryderChuck

Copy link
Copy Markdown
Contributor

the added method follows the same semantics as defined in go's IsGlobalUnicast:

https://github.com/golang/go/blob/master/src/net/ip.go#L188-L203 .

The RFCs are explicit about what a global unicast IPv6 address is, less so for IPv4, so this impl just implements the same approach as implemented in go, where any non-broadcast IPv4 address is considered global unicast (and that includes private addresses).

This adds the following predicate methods to IPAddr objects:

* `#multicast?`: whether the ip address is multicast
* `#link_local_multicast?`: whether the ip address is a link-local
  multicast

it also alias `IPAddr#link_local?` as `IPAddr#link_local_unicast?`,
which is more accurate (whether the original should be deprecated is
probably a separate discussion).
the added method follows the same semantics as defined in go's
IsGlobalUnicast:
https://github.com/golang/go/blob/master/src/net/ip.go#L188-L203 .

The RFCs are explicit about what a global unicast IPv6 address is, less
so for IPv4, so this impl just implements the same approach as
implemented in go, where any non-broadcast IPv4 address is considered
global unicast (and that includes private addresses).
@HoneyryderChuck
HoneyryderChuck requested a review from knu as a code owner July 15, 2026 10:10
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.

1 participant