ipaddr 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +9 -1
- data/README.md +14 -2
- data/ipaddr.gemspec +2 -4
- data/lib/ipaddr.rb +31 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3cb27d00fb843e1943f1a7640504fc2ea8970a91
|
4
|
+
data.tar.gz: ab0c6306a7f5b36fce8e5f6c472864cf52598d0e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '0197f4cad3d5497974b2669b49d66c658dc21ce8f5f17df574c16badea57fd0cac83c776cf3f646555049789cd9c0184f226ac9ec90a32285f3d46bc4809aab6'
|
7
|
+
data.tar.gz: 37ac683429dd8c03202a50feb3c1b1155ebe1ff8e4f42e6707d8be5dae6ba5a21990a7b0e06c145c8e449f64deb446c664b90970ef2e3cb575dc0efe47255371
|
data/.travis.yml
CHANGED
@@ -1,6 +1,14 @@
|
|
1
1
|
sudo: false
|
2
2
|
language: ruby
|
3
3
|
rvm:
|
4
|
-
- 2.4
|
4
|
+
- 2.4
|
5
5
|
- ruby-head
|
6
|
+
- jruby
|
7
|
+
- jruby-head
|
8
|
+
matrix:
|
9
|
+
allow_failures:
|
10
|
+
# Even `rvm use jruby` does not work reliably on Travis:
|
11
|
+
# https://travis-ci.org/ruby/ipaddr/jobs/277222999
|
12
|
+
- rvm: jruby
|
13
|
+
- rvm: jruby-head
|
6
14
|
before_install: gem install bundler
|
data/README.md
CHANGED
@@ -5,10 +5,15 @@ IPv4 and IPv6 are supported.
|
|
5
5
|
|
6
6
|
## Installation
|
7
7
|
|
8
|
-
|
8
|
+
This library is part of the standard ruby distribution as default gem
|
9
|
+
and synchronized periodically, but you can explicitly depend on this
|
10
|
+
gem with version constraints as necessary, like when you need a newer
|
11
|
+
version than comes with older versions of ruby.
|
12
|
+
|
13
|
+
For example, you can add this line to your application's Gemfile:
|
9
14
|
|
10
15
|
```ruby
|
11
|
-
gem 'ipaddr'
|
16
|
+
gem 'ipaddr', '~> 1.1'
|
12
17
|
```
|
13
18
|
|
14
19
|
And then execute:
|
@@ -39,6 +44,13 @@ ipaddr3 = IPAddr.new "192.168.2.0/24"
|
|
39
44
|
p ipaddr3 #=> #<IPAddr: IPv4:192.168.2.0/255.255.255.0>
|
40
45
|
```
|
41
46
|
|
47
|
+
## Alternative
|
48
|
+
|
49
|
+
The [ipaddress](https://rubygems.org/gems/ipaddress) gem is a popular,
|
50
|
+
extensive library for manipulating IP addresses with a layer of
|
51
|
+
compatibility with `ipaddr`. If you need a richer set of features
|
52
|
+
than `ipaddr` has, try this library instead.
|
53
|
+
|
42
54
|
## Development
|
43
55
|
|
44
56
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
data/ipaddr.gemspec
CHANGED
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
|
5
5
|
Gem::Specification.new do |spec|
|
6
6
|
spec.name = "ipaddr"
|
7
|
-
spec.version = "1.
|
7
|
+
spec.version = "1.1.0"
|
8
8
|
spec.authors = ["Akinori MUSHA", "Hajimu UMEMOTO"]
|
9
9
|
spec.email = ["knu@idaemons.org", "ume@mahoroba.org"]
|
10
10
|
|
@@ -15,9 +15,7 @@ Both IPv4 and IPv6 are supported.
|
|
15
15
|
DESCRIPTION
|
16
16
|
spec.homepage = "https://github.com/ruby/ipaddr"
|
17
17
|
|
18
|
-
spec.files =
|
19
|
-
f.match(%r{^(test|spec|features)/})
|
20
|
-
end
|
18
|
+
spec.files = [".gitignore", ".travis.yml", "Gemfile", "LICENSE.txt", "README.md", "Rakefile", "bin/console", "bin/setup", "ipaddr.gemspec", "lib/ipaddr.rb"]
|
21
19
|
spec.bindir = "exe"
|
22
20
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
23
21
|
spec.require_paths = ["lib"]
|
data/lib/ipaddr.rb
CHANGED
@@ -371,6 +371,35 @@ class IPAddr
|
|
371
371
|
return clone.set(begin_addr, @family)..clone.set(end_addr, @family)
|
372
372
|
end
|
373
373
|
|
374
|
+
# Returns the prefix length in bits for the ipaddr.
|
375
|
+
def prefix
|
376
|
+
case @family
|
377
|
+
when Socket::AF_INET
|
378
|
+
n = IN4MASK ^ @mask_addr
|
379
|
+
i = 32
|
380
|
+
when Socket::AF_INET6
|
381
|
+
n = IN6MASK ^ @mask_addr
|
382
|
+
i = 128
|
383
|
+
else
|
384
|
+
raise AddressFamilyError, "unsupported address family"
|
385
|
+
end
|
386
|
+
while n.positive?
|
387
|
+
n >>= 1
|
388
|
+
i -= 1
|
389
|
+
end
|
390
|
+
i
|
391
|
+
end
|
392
|
+
|
393
|
+
# Sets the prefix length in bits
|
394
|
+
def prefix=(prefix)
|
395
|
+
case prefix
|
396
|
+
when Integer
|
397
|
+
mask!(prefix)
|
398
|
+
else
|
399
|
+
raise InvalidPrefixError, "prefix must be an integer"
|
400
|
+
end
|
401
|
+
end
|
402
|
+
|
374
403
|
# Returns a string containing a human-readable representation of the
|
375
404
|
# ipaddr. ("#<IPAddr: family:address/mask>")
|
376
405
|
def inspect
|
@@ -413,7 +442,8 @@ class IPAddr
|
|
413
442
|
|
414
443
|
# Set current netmask to given mask.
|
415
444
|
def mask!(mask)
|
416
|
-
|
445
|
+
case mask
|
446
|
+
when String
|
417
447
|
if mask =~ /\A\d+\z/
|
418
448
|
prefixlen = mask.to_i
|
419
449
|
else
|
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.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Akinori MUSHA
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date: 2017-
|
12
|
+
date: 2017-10-21 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -92,7 +92,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
92
92
|
version: '0'
|
93
93
|
requirements: []
|
94
94
|
rubyforge_project:
|
95
|
-
rubygems_version: 2.6.
|
95
|
+
rubygems_version: 2.6.14
|
96
96
|
signing_key:
|
97
97
|
specification_version: 4
|
98
98
|
summary: A class to manipulate an IP address in ruby
|