Project

General

Profile

Feature #11666

IPAddr#private?

Added by Glass_saga (Masaki Matsushita) over 3 years ago. Updated over 1 year ago.

Status:
Closed
Priority:
Normal
Target version:
-
[ruby-core:71384]

Description

I propose a new feature: IPAddr#private?.

Example:

IPAddr.new("192.168.1.1").private? #=> true.

Files

patch.diff (1.58 KB) patch.diff Glass_saga (Masaki Matsushita), 11/08/2015 07:19 AM

Related issues

Has duplicate Ruby trunk - Feature #10912: Add method(s) to IPAddr for determining whether an address is link localClosedActions

Associated revisions

Revision c2db917b
Added by knu (Akinori MUSHA) over 1 year ago

Import ipaddr 1.2.0

  • Add IPAddr#prefix
  • Add IPAddr#loopback?
  • Add IPAddr#private? [Feature #11666]
  • Add IPAddr#link_local? [Feature #10912]
  • Reject invalid address mask [Bug #13399]
  • Warn that IPAddr#ipv4_compat and #ipv4_compat? are deprecated [#Bug 13769]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60270 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

Revision 60270
Added by knu (Akinori MUSHA) over 1 year ago

Import ipaddr 1.2.0

  • Add IPAddr#prefix
  • Add IPAddr#loopback?
  • Add IPAddr#private? [Feature #11666]
  • Add IPAddr#link_local? [Feature #10912]
  • Reject invalid address mask [Bug #13399]
  • Warn that IPAddr#ipv4_compat and #ipv4_compat? are deprecated [#Bug 13769]

Revision 60270
Added by knu (Akinori MUSHA) over 1 year ago

Import ipaddr 1.2.0

  • Add IPAddr#prefix
  • Add IPAddr#loopback?
  • Add IPAddr#private? [Feature #11666]
  • Add IPAddr#link_local? [Feature #10912]
  • Reject invalid address mask [Bug #13399]
  • Warn that IPAddr#ipv4_compat and #ipv4_compat? are deprecated [#Bug 13769]

Revision 60270
Added by knu (Akinori MUSHA) over 1 year ago

Import ipaddr 1.2.0

  • Add IPAddr#prefix
  • Add IPAddr#loopback?
  • Add IPAddr#private? [Feature #11666]
  • Add IPAddr#link_local? [Feature #10912]
  • Reject invalid address mask [Bug #13399]
  • Warn that IPAddr#ipv4_compat and #ipv4_compat? are deprecated [#Bug 13769]

History

Updated by matz (Yukihiro Matsumoto) over 3 years ago

Accepted. But we have naming issue. private? or private_addr? or something else?
Any comments?

Matz.

Updated by Glass_saga (Masaki Matsushita) over 3 years ago

I think private? is better than private_addr? because private_addr? seems to be redundant in following code:

IPAddr.new("192.168.1.1").private_addr?

Updated by naruse (Yui NARUSE) over 3 years ago

  • Status changed from Open to Assigned
  • Assignee changed from Glass_saga (Masaki Matsushita) to knu (Akinori MUSHA)

The maintainer is knu.

  • feature issues
    • conflict with private visibility
    • “private?” is different from visivility
    • Behavior when address family is IPv6
    • nil? false?
    • or treat link-local, site-local (deprecated), unique-local as true?
    • Naming differencies with Addrinfo
  • The name “ipv4_private?” is clear that the method returns false on IPv6 addresses.

Updated by herwin (Herwin W) about 3 years ago

IPv6 has a private range too: d00::/8 (RFC 4193)

Also, there are more IP ranges that have been reserved for special use (there's an overview on https://en.wikipedia.org/wiki/Reserved_IP_addresses). I think it would be better to make 1 method that can return a pre-defined symbol of that range if the IP address is in that range. Otherwise, there would be an explosion in the number of IP addresses.

Updated by shyouhei (Shyouhei Urabe) about 3 years ago

As far as I understand RFC4193 never defines its range being "private". There also are other private-ish address ranges e.g. fd00::/8. And what about v4-mapped v6 addresses? IPv6's situation is complicated (at least to me). I'd suggest OP to leave IPv6 situations untouched.

#6

Updated by shyouhei (Shyouhei Urabe) over 2 years ago

  • Has duplicate Feature #10912: Add method(s) to IPAddr for determining whether an address is link local added
#7

Updated by knu (Akinori MUSHA) over 1 year ago

  • Status changed from Assigned to Closed

Applied in changeset trunk|r60270.


Import ipaddr 1.2.0

  • Add IPAddr#prefix
  • Add IPAddr#loopback?
  • Add IPAddr#private? [Feature #11666]
  • Add IPAddr#link_local? [Feature #10912]
  • Reject invalid address mask [Bug #13399]
  • Warn that IPAddr#ipv4_compat and #ipv4_compat? are deprecated [#Bug 13769]

Updated by knu (Akinori MUSHA) over 1 year ago

Added, thanks for the suggestion.

Also available in: Atom PDF