ipaddr 1.2.4 → 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/README.md +1 -1
- data/ipaddr.gemspec +11 -3
- data/lib/ipaddr.rb +27 -19
- metadata +6 -6
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/README.md
CHANGED
@@ -55,7 +55,7 @@ than `ipaddr` has, try this library instead.
|
|
55
55
|
|
56
56
|
## Development
|
57
57
|
|
58
|
-
After checking out the repo, run `
|
58
|
+
After checking out the repo, run `bundle install` to install dependencies. Then, run `rake test` to run the tests.
|
59
59
|
|
60
60
|
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
61
61
|
|
data/ipaddr.gemspec
CHANGED
@@ -1,9 +1,17 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
# coding: utf-8
|
3
|
-
lib = File.expand_path("../lib", __FILE__)
|
4
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
3
|
|
6
|
-
|
4
|
+
if File.exist?(File.expand_path("ipaddr.gemspec"))
|
5
|
+
lib = File.expand_path("../lib", __FILE__)
|
6
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
7
|
+
|
8
|
+
file = File.expand_path("ipaddr.rb", lib)
|
9
|
+
else
|
10
|
+
# for ruby-core
|
11
|
+
file = File.expand_path("../ipaddr.rb", __FILE__)
|
12
|
+
end
|
13
|
+
|
14
|
+
version = File.foreach(file).find do |line|
|
7
15
|
/^\s*VERSION\s*=\s*["'](.*)["']/ =~ line and break $1
|
8
16
|
end
|
9
17
|
|
data/lib/ipaddr.rb
CHANGED
@@ -40,14 +40,14 @@ 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
|
47
47
|
# 128 bit mask for IPv6
|
48
48
|
IN6MASK = 0xffffffffffffffffffffffffffffffff
|
49
49
|
# Format string for IPv6
|
50
|
-
IN6FORMAT = (["%.4x"] * 8).join(':')
|
50
|
+
IN6FORMAT = (["%.4x"] * 8).join(':').freeze
|
51
51
|
|
52
52
|
# Regexp _internally_ used for parsing IPv4 address.
|
53
53
|
RE_IPV4ADDRLIKE = %r{
|
@@ -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+.
|
@@ -736,7 +744,7 @@ end
|
|
736
744
|
unless Socket.const_defined? :AF_INET6
|
737
745
|
class Socket < BasicSocket
|
738
746
|
# IPv6 protocol family
|
739
|
-
AF_INET6 = Object.new
|
747
|
+
AF_INET6 = Object.new.freeze
|
740
748
|
end
|
741
749
|
|
742
750
|
class << IPSocket
|
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
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
|
8
8
|
- Hajimu UMEMOTO
|
9
|
-
autorequire:
|
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.
|
@@ -30,7 +30,7 @@ licenses:
|
|
30
30
|
- Ruby
|
31
31
|
- BSD-2-Clause
|
32
32
|
metadata: {}
|
33
|
-
post_install_message:
|
33
|
+
post_install_message:
|
34
34
|
rdoc_options: []
|
35
35
|
require_paths:
|
36
36
|
- lib
|
@@ -45,8 +45,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
45
45
|
- !ruby/object:Gem::Version
|
46
46
|
version: '0'
|
47
47
|
requirements: []
|
48
|
-
rubygems_version: 3.0.
|
49
|
-
signing_key:
|
48
|
+
rubygems_version: 3.5.0.dev
|
49
|
+
signing_key:
|
50
50
|
specification_version: 4
|
51
51
|
summary: A class to manipulate an IP address in ruby
|
52
52
|
test_files: []
|