ipaddr 1.2.5 → 1.2.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/ipaddr.rb +25 -17
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f58727d4b57c7d063e7f6671b34b03f93de0b0b38f035528f9e3b6ef77842512
|
4
|
+
data.tar.gz: 71c172f3e9506cfaacd857ad27099ca01f7862737590c3fd6ac4ca01952f96c1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f97223995de559e291ba8058014e3ba23606f36670c2cf8360aa1f35c2dfa716fc0956cda1ceead863715ecd5065457c295f8c8653e999e63757f88c2d937a11
|
7
|
+
data.tar.gz: 20d8934e68d7f4be367267661c398c452f65d066b8a623e0e6fc2d17569fca3e82381606001eb0a56294132cd438e98ba5e7a34faf18098093bb71ea3aee9e86
|
data/lib/ipaddr.rb
CHANGED
@@ -40,7 +40,7 @@ require 'socket'
|
|
40
40
|
# p ipaddr3 #=> #<IPAddr: IPv4:192.168.2.0/255.255.255.0>
|
41
41
|
|
42
42
|
class IPAddr
|
43
|
-
VERSION = "1.2.
|
43
|
+
VERSION = "1.2.6"
|
44
44
|
|
45
45
|
# 32 bit mask for IPv4
|
46
46
|
IN4MASK = 0xffffffff
|
@@ -176,9 +176,7 @@ class IPAddr
|
|
176
176
|
def include?(other)
|
177
177
|
other = coerce_other(other)
|
178
178
|
return false unless other.family == family
|
179
|
-
|
180
|
-
other = other.to_range
|
181
|
-
range.begin <= other.begin && range.end >= other.end
|
179
|
+
begin_addr <= other.begin_addr && end_addr >= other.end_addr
|
182
180
|
end
|
183
181
|
alias === include?
|
184
182
|
|
@@ -263,7 +261,8 @@ class IPAddr
|
|
263
261
|
# Returns true if the ipaddr is a private address. IPv4 addresses
|
264
262
|
# in 10.0.0.0/8, 172.16.0.0/12 and 192.168.0.0/16 as defined in RFC
|
265
263
|
# 1918 and IPv6 Unique Local Addresses in fc00::/7 as defined in RFC
|
266
|
-
# 4193 are considered private.
|
264
|
+
# 4193 are considered private. Private IPv4 addresses in the
|
265
|
+
# IPv4-mapped IPv6 address range are also considered private.
|
267
266
|
def private?
|
268
267
|
case @family
|
269
268
|
when Socket::AF_INET
|
@@ -271,7 +270,12 @@ class IPAddr
|
|
271
270
|
@addr & 0xfff00000 == 0xac100000 || # 172.16.0.0/12
|
272
271
|
@addr & 0xffff0000 == 0xc0a80000 # 192.168.0.0/16
|
273
272
|
when Socket::AF_INET6
|
274
|
-
@addr & 0xfe00_0000_0000_0000_0000_0000_0000_0000 == 0xfc00_0000_0000_0000_0000_0000_0000_0000
|
273
|
+
@addr & 0xfe00_0000_0000_0000_0000_0000_0000_0000 == 0xfc00_0000_0000_0000_0000_0000_0000_0000 ||
|
274
|
+
(@addr & 0xffff_0000_0000 == 0xffff_0000_0000 && (
|
275
|
+
@addr & 0xff000000 == 0x0a000000 || # ::ffff:10.0.0.0/8
|
276
|
+
@addr & 0xfff00000 == 0xac100000 || # ::ffff::172.16.0.0/12
|
277
|
+
@addr & 0xffff0000 == 0xc0a80000 # ::ffff::192.168.0.0/16
|
278
|
+
))
|
275
279
|
else
|
276
280
|
raise AddressFamilyError, "unsupported address family"
|
277
281
|
end
|
@@ -400,17 +404,6 @@ class IPAddr
|
|
400
404
|
|
401
405
|
# Creates a Range object for the network address.
|
402
406
|
def to_range
|
403
|
-
begin_addr = (@addr & @mask_addr)
|
404
|
-
|
405
|
-
case @family
|
406
|
-
when Socket::AF_INET
|
407
|
-
end_addr = (@addr | (IN4MASK ^ @mask_addr))
|
408
|
-
when Socket::AF_INET6
|
409
|
-
end_addr = (@addr | (IN6MASK ^ @mask_addr))
|
410
|
-
else
|
411
|
-
raise AddressFamilyError, "unsupported address family"
|
412
|
-
end
|
413
|
-
|
414
407
|
self.class.new(begin_addr, @family)..self.class.new(end_addr, @family)
|
415
408
|
end
|
416
409
|
|
@@ -491,6 +484,21 @@ class IPAddr
|
|
491
484
|
|
492
485
|
protected
|
493
486
|
|
487
|
+
def begin_addr
|
488
|
+
@addr & @mask_addr
|
489
|
+
end
|
490
|
+
|
491
|
+
def end_addr
|
492
|
+
case @family
|
493
|
+
when Socket::AF_INET
|
494
|
+
@addr | (IN4MASK ^ @mask_addr)
|
495
|
+
when Socket::AF_INET6
|
496
|
+
@addr | (IN6MASK ^ @mask_addr)
|
497
|
+
else
|
498
|
+
raise AddressFamilyError, "unsupported address family"
|
499
|
+
end
|
500
|
+
end
|
501
|
+
|
494
502
|
# Set +@addr+, the internal stored ip address, to given +addr+. The
|
495
503
|
# parameter +addr+ is validated using the first +family+ member,
|
496
504
|
# which is +Socket::AF_INET+ or +Socket::AF_INET6+.
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ipaddr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Akinori MUSHA
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2023-12-16 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: |
|
15
15
|
IPAddr provides a set of methods to manipulate an IP address.
|
@@ -45,7 +45,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
45
45
|
- !ruby/object:Gem::Version
|
46
46
|
version: '0'
|
47
47
|
requirements: []
|
48
|
-
rubygems_version: 3.
|
48
|
+
rubygems_version: 3.5.0.dev
|
49
49
|
signing_key:
|
50
50
|
specification_version: 4
|
51
51
|
summary: A class to manipulate an IP address in ruby
|