rumblinthebronx-system-getifaddrs 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,13 +1,13 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rumblinthebronx-system-getifaddrs (0.2.0)
4
+ rumblinthebronx-system-getifaddrs (0.2.1)
5
5
 
6
6
  GEM
7
7
  remote: http://rubygems.org/
8
8
  specs:
9
- rake (0.9.2)
10
- rake-compiler (0.7.9)
9
+ rake (10.1.0)
10
+ rake-compiler (0.8.3)
11
11
  rake
12
12
  rspec (1.3.2)
13
13
 
data/README.markdown CHANGED
@@ -27,7 +27,6 @@ Consider test.rb below:
27
27
  require "pp"
28
28
  require "system/getifaddrs"
29
29
  pp System.get_ifaddrs
30
- pp System.get_ifaddrs ip_version="6"
31
30
  ```
32
31
 
33
32
  When test.rb is executed:
data/Rakefile CHANGED
@@ -4,7 +4,10 @@ Bundler::GemHelper.install_tasks
4
4
  require 'spec/rake/spectask'
5
5
  Spec::Rake::SpecTask.new
6
6
 
7
- require 'rake/extensiontask'
8
- Rake::ExtensionTask.new('rb_getifaddrs')
9
-
10
- task :default => [:compile, :spec]
7
+ if RUBY_PLATFORM == "java"
8
+ task :default => [:spec]
9
+ else
10
+ require 'rake/extensiontask'
11
+ Rake::ExtensionTask.new('rb_getifaddrs')
12
+ task :default => [:compile, :spec]
13
+ end
@@ -1,5 +1,42 @@
1
- begin
2
- require File.join(File.dirname(__FILE__), 'rb_getifaddrs')
3
- rescue LoadError
4
- require File.join(File.dirname(__FILE__), '..', 'rb_getifaddrs')
1
+ if RUBY_ENGINE == "jruby"
2
+ module System
3
+ require 'netaddr'
4
+
5
+ # Jruby version of the system-getifaddrs gem. Gives info on all network
6
+ # interfaces.
7
+ #
8
+ # @return [Hash] Network interfaces and their addresses/netmasks.
9
+ def self.get_ifaddrs
10
+ ifaddrs = {}
11
+ interfaces = java.net.NetworkInterface.network_interfaces
12
+
13
+ interfaces.each do |interface|
14
+ name = interface.display_name.to_sym
15
+ ifaddrs[name] = {}
16
+
17
+ interface.interface_addresses.each do |interface_address|
18
+ ip_address, index = interface_address.address.host_address.split('%')
19
+ prefix = interface_address.network_prefix_length
20
+ netmask = NetAddr::CIDR.create("#{ip_address}/#{prefix}").wildcard_mask
21
+
22
+ if interface_address.address.is_a? Java::JavaNet::Inet4Address
23
+ ifaddrs[name][:inet_addr_v4] = ip_address
24
+ netmask = '255.0.0.0' if interface_address.address.is_loopback_address?
25
+ ifaddrs[name][:netmask_v4] = netmask
26
+ else
27
+ ifaddrs[name][:inet_addr_v6] = "#{ip_address}%#{index}"
28
+ ifaddrs[name][:netmask_v6] = NetAddr.shorten(netmask)
29
+ end
30
+ end
31
+ end
32
+
33
+ ifaddrs
34
+ end
35
+ end
36
+ else
37
+ begin
38
+ require File.join(File.dirname(__FILE__), 'rb_getifaddrs')
39
+ rescue LoadError
40
+ require File.join(File.dirname(__FILE__), '..', 'rb_getifaddrs')
41
+ end
5
42
  end
@@ -1,5 +1,5 @@
1
1
  module System
2
2
  class Getifaddrs
3
- VERSION = "0.2.0"
3
+ VERSION = "0.2.1"
4
4
  end
5
5
  end
@@ -6,14 +6,20 @@ Gem::Specification.new do |s|
6
6
  s.name = "rumblinthebronx-system-getifaddrs"
7
7
  s.version = System::Getifaddrs::VERSION
8
8
  s.platform = Gem::Platform::RUBY
9
+ s.platform = Gem::Platform.new(['universal', 'java']) if RUBY_PLATFORM == "java"
9
10
  s.authors = ["Sujin Philip", "Bruno Coimbra"]
10
11
  s.email = %q{sujin.phil@gmail.com}
11
12
  s.homepage = %q{http://github.com/rumblinthebronx/system-getifaddrs}
12
- s.summary = %q{This lib is a wrapper for get_ifaddrs C routine}
13
+ s.summary = %q{This library provides the information about the inet interfaces. }
13
14
  s.description = %q{This lib is a wrapper for get_ifaddrs C routine. The original routine returns a linked list that contains avaliable inet interfaces. This lib walks on list and return an hash that contains the interface names and sub-hashes with respectives ip addresses and netmasks.}
14
15
  s.add_development_dependency(%q<rspec>, "~> 1.3")
15
16
  s.add_development_dependency(%q<rake-compiler>, [">= 0"])
16
- s.extensions = `git ls-files -- ext/*`.split("\n").select{|f| f =~ /extconf/}
17
+ s.add_runtime_dependency(%q<netaddr>, "~> 1.5.0") if RUBY_PLATFORM == "java"
18
+
19
+ unless RUBY_PLATFORM.include?("mingw") || RUBY_PLATFORM == "java"
20
+ s.extensions = `git ls-files -- ext/*`.split("\n").select{|f| f =~ /extconf/}
21
+ end
22
+
17
23
  s.files = `git ls-files`.split("\n")
18
24
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
25
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rumblinthebronx-system-getifaddrs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-10-27 00:00:00.000000000 Z
13
+ date: 2013-06-24 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rspec
@@ -93,7 +93,7 @@ rubyforge_project:
93
93
  rubygems_version: 1.8.24
94
94
  signing_key:
95
95
  specification_version: 3
96
- summary: This lib is a wrapper for get_ifaddrs C routine
96
+ summary: This library provides the information about the inet interfaces.
97
97
  test_files:
98
98
  - spec/spec_helper.rb
99
99
  - spec/system-ifaddrs_spec.rb