Commit graph

26 commits

Author SHA1 Message Date
Taketo Takashima
687bd83724 [ruby/ipaddr] Added IPAddr#+/-
78b4f53bf5
2025-04-26 11:56:42 +00:00
Taketo Takashima
eb8cf1d60e [ruby/ipaddr] Added to_json/as_json method
Updated to use cidr method when return address with prefix in #as_json

cf8181d53e
2024-10-18 15:00:37 +00:00
Ben Fritsch
6ac8f6a10e
[ruby/ipaddr] Add IPAddr.cidr to return ip address in cidr notation
f5b006741f
2024-04-18 10:27:19 +09:00
Taketo Takashima
f9f25d0ed0 [ruby/ipaddr] Added IPAddr#wildcard_mask
2093cebc1d
2024-04-10 10:30:53 +00:00
Earlopain
86fa418dea [ruby/ipaddr] Consider IPv4-mapped IPv6 addresses link local/loopback if IPV4 address is private
Same as #57

d56acecb80
2023-12-25 21:12:49 +09:00
Kasumi Hanazuki
eb53131367 [ruby/ipaddr] ntop: Measure address size in bytes
`IPAddr.ntop` takes the binary representation of an IP address, whose
length should be 4 or 16 *bytes* (not characters/codepoints).

The current implementation accepts strings in any encoding, but for
some values in non-BINARY encoding, it fails proper length check and
raises an `AddressFamilyError`. Since passing strings in a multibyte
encoding has never worked correctly for years, this patch makes it an
explicit error with an `InvalidAddressError`.

Fixes: https://github.com/ruby/ipaddr/issues/56

a33fd14d4a
2023-12-25 21:12:49 +09:00
Jeremy Evans
de51a4a13e [ruby/ipaddr] Consider IPv4-mapped IPv6 addresses private if IPv4 address is private
Fixes [Bug #19479]

7faa0768d3
2023-06-22 16:40:46 +00:00
Espartaco Palma
9b768012f6
[ruby/ipaddr] Fix exception calling to_range' after freeze'
77fe1fca0a
2022-02-10 17:18:05 +09:00
Jean Boussier
100253c7f0
[ruby/ipaddr] Ipaddr#native must also coerce @mask_addr
Before it would be left as an IPv6 mask causing `to_range` to fail.

```
>> IPAddr.new("::2").native.to_range
/opt/rubies/3.0.3/lib/ruby/3.0.0/ipaddr.rb:479:in `set': invalid address (IPAddr::InvalidAddressError)
```

af485192f3
2022-02-10 17:18:05 +09:00
Jeremy Evans
9a321dd9b2
[ruby/ipaddr] Make IPAddr#include? consider range of argument
It would be nice to use Range#cover? here, but it doesn't work
correctly before Ruby 2.6. Switch to manual checks of the beginning
of end of the ranges.

Fixes Ruby Bug 14119

f45630da31
2021-10-11 13:50:54 +09:00
Jeremy Evans
bd6e1a0f08
[ruby/ipaddr] Support zone identifiers in IPv6 addresses
These are supported by Ruby's socket library if the operating system
supports zone indentifiers, so they should be supported by ipaddr.
See RFCs 4007 and 6874 for additional information.

Implements Ruby Feature #10911

09a6408fb2
2021-10-07 18:22:43 +09:00
Bogdan Irimie
74ed881e10
[ruby/ipaddr] Add netmask method that returns net mask as string.
283d16f3a3
2021-10-07 18:22:43 +09:00
Jeremy Evans
abad5e10e8
[ruby/ipaddr] Disallow leading zeros in mask
f49d2d49a4
2021-10-07 18:22:43 +09:00
Nobuyoshi Nakada
38da84296c
[ruby/ipaddr] Raise if extra slashes follow
https://bugs.ruby-lang.org/issues/15832

de9805d6fa
2021-10-07 18:22:42 +09:00
Espartaco Palma
b23fba91ae [ruby/ipaddr] Removing superfluos assingments & return
Also adding test for ntop

0ba16cca10
2021-10-07 17:46:00 +09:00
Nobuyoshi Nakada
6982a9049e
Assert obsolete method warnings in IPAddr 2019-07-01 13:02:23 +09:00
knu
ab364fb5a8 Import ipaddr 1.2.2
- Enable frozen_string_literal and do a bit of code cleanup


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66432 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-12-18 05:09:08 +00:00
knu
c2db917b3d 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
2017-10-21 13:34:19 +00:00
knu
2d8841791f IPAddr#== and IPAddr#<=> no longer raise an exception if coercion fails
* lib/ipaddr.rb (IPAddr#==): If coercion fails, return false
  instead of passing through the exception. [ruby-core:77451]
  [Bug #12799]

* lib/ipaddr.rb (IPAddr#<=>): If coercion fails, return nil
  instead of passing through the exception. [ruby-core:77451]
  [Bug #12799]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56594 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-11-05 13:53:38 +00:00
naruse
3e92b635fb Add frozen_string_literal: false for all files
When you change this to true, you may need to add more tests.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53141 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-12-16 05:07:31 +00:00
hsbt
2cd1f852e1 * lib/ipaddr.rb, test/test_ipaddr.rb: Reject invalid address contained
EOL string. Patch by @kachick [fix GH-942][Bug #11513]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52244 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-10-23 07:35:14 +00:00
nobu
ae042f21fb use assert_raise
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50727 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-06-02 02:18:44 +00:00
hsbt
f84ef81dad * lib/ipaddr.rb: extracted inline tests into test dir.
* test/test_ipaddr.rb: ditto.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46277 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-05-31 07:36:51 +00:00
akr
48d402db88 use require_relative.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@26542 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2010-02-02 13:58:56 +00:00
nahi
45c950c1df * test/test_*.rb: Pathname#parent -> Pathname#dirname.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@5455 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-01-13 04:06:31 +00:00
nahi
79c0e644a1 * test/inlinetest.rb, test/{test_generator.rb,test_ipaddr.rb,
test_pathname.rb,test_pp.rb,test_prettyprint.rb,test_set.rb,
          test_time.rb,test_tsort.rb: added.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@5385 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-01-06 02:34:24 +00:00