rumblinthebronx-system-getifaddrs 0.2.4-x64-mingw32

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 1c1011833357e2d17383f98a1c8e029c3fabf424
4
+ data.tar.gz: a0a2319e382fa98172ba0b26b9eb6933e42cc93d
5
+ SHA512:
6
+ metadata.gz: fa21974ef1252b53784e1390ba4f4c0333697fbdaabe1641218048057dde802ac7e071d97b9ed8725e4f028a399d40ccdce71ca5103dfae9ee5fe1e1d8a54461
7
+ data.tar.gz: 4ec6d76556bab85643be33add5d69cdac2b7d2eabc8ca8e8118d3194ef4f21d18a96a8f57f66c9628efbe998c849a8e4280922be30aaff80858c1265ed971398
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ *.sw?
2
+ *~
3
+ .DS_Store
4
+ coverage
5
+ rdoc
6
+ pkg
7
+ tmp
8
+ *.so
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source :rubygems
2
+ gemspec
3
+ gem 'rake'
4
+
data/Gemfile.lock ADDED
@@ -0,0 +1,23 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ rumblinthebronx-system-getifaddrs (0.2.1-java)
5
+ netaddr (~> 1.5.0)
6
+
7
+ GEM
8
+ remote: http://rubygems.org/
9
+ specs:
10
+ netaddr (1.5.0)
11
+ rake (10.0.4)
12
+ rake-compiler (0.8.3)
13
+ rake
14
+ rspec (1.3.2)
15
+
16
+ PLATFORMS
17
+ java
18
+
19
+ DEPENDENCIES
20
+ rake
21
+ rake-compiler
22
+ rspec (~> 1.3)
23
+ rumblinthebronx-system-getifaddrs!
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Bruno Coimbra
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.markdown ADDED
@@ -0,0 +1,51 @@
1
+ # rumblinthebronx-system-ifaddrs
2
+
3
+ This lib is a wrapper for get\_ifaddrs C routine.
4
+
5
+ The original routine returns a linked list that contains avaliable inet interfaces.
6
+ This lib walks on list and return an hash that contains the interface names and sub-hashes with respectives ip addresses and netmasks.
7
+
8
+ ## Example
9
+
10
+ Supose that /sbin/ifconfig returns:
11
+
12
+ ```bash
13
+ lo Link encap:Local Loopback
14
+ inet addr:127.0.0.1 Mask:255.0.0.0
15
+ inet6 addr: ::1/128 Scope:Host
16
+ UP LOOPBACK RUNNING MTU:16436 Metric:1
17
+ RX packets:86688 errors:0 dropped:0 overruns:0 frame:0
18
+ TX packets:86688 errors:0 dropped:0 overruns:0 carrier:0
19
+ collisions:0 txqueuelen:0
20
+ RX bytes:10903658 (10.3 MiB) TX bytes:10903658 (10.3 MiB)
21
+ ```
22
+
23
+ Consider test.rb below:
24
+
25
+ ```ruby
26
+ # test.rb
27
+ require "pp"
28
+ require "system/getifaddrs"
29
+ pp System.get_ifaddrs
30
+ ```
31
+
32
+ When test.rb is executed:
33
+
34
+ ```bash
35
+ $ ruby test.rb
36
+ ```
37
+
38
+ Should return:
39
+
40
+ ```ruby
41
+ {:lo=>
42
+ {:inet_addr_v4=>"127.0.0.1",
43
+ :netmask_v4=>"255.0.0.0",
44
+ :inet_addr_v6=>"::1",
45
+ :netmask_v6=>"ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff"}}
46
+
47
+ ```
48
+
49
+ ## Copyright
50
+
51
+ Copyright (c) 2011 rumblinthebronx. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,13 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
3
+
4
+ require 'spec/rake/spectask'
5
+ Spec::Rake::SpecTask.new
6
+
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
@@ -0,0 +1,16 @@
1
+ require 'mkmf'
2
+
3
+ dir_config "rb_getifaddrs"
4
+
5
+ $CFLAGS = "-D_GNU_SOURCE -Wall"
6
+
7
+ have_header('arpa/inet.h')
8
+ have_header('sys/socket.h')
9
+ have_header('sys/types.h')
10
+ have_header('netdb.h')
11
+ have_header('ifaddrs.h')
12
+ have_header('stdio.h')
13
+ have_header('stdlib.h')
14
+ have_header('unistd.h')
15
+
16
+ create_makefile("system/rb_getifaddrs")
@@ -0,0 +1,105 @@
1
+ #include "ruby.h"
2
+ #include <arpa/inet.h>
3
+ #include <sys/socket.h>
4
+ #include <sys/types.h>
5
+ #include <netdb.h>
6
+ #include <ifaddrs.h>
7
+ #include <stdio.h>
8
+ #include <stdlib.h>
9
+ #include <unistd.h>
10
+
11
+ int get_if_family(struct ifaddrs *ifa){
12
+ if(ifa && ifa->ifa_addr)
13
+ return ifa->ifa_addr->sa_family;
14
+ return 0;
15
+ }
16
+
17
+ char * get_if_name(struct ifaddrs *ifa){
18
+ return ifa->ifa_name;
19
+ }
20
+
21
+ int get_if_host(struct ifaddrs *ifa, char *host){
22
+ int family = get_if_family(ifa);
23
+ if(getnameinfo(ifa->ifa_addr,
24
+ (family == AF_INET) ? sizeof(struct sockaddr_in) :
25
+ sizeof(struct sockaddr_in6),
26
+ host, NI_MAXHOST,
27
+ NULL, 0, NI_NUMERICHOST))
28
+ return 0;
29
+ return 1;
30
+ }
31
+
32
+ int get_if_netmask(struct ifaddrs *ifa, char *netmask){
33
+ int family = get_if_family(ifa);
34
+ if(getnameinfo(ifa->ifa_netmask,
35
+ (family == AF_INET) ? sizeof(struct sockaddr_in) :
36
+ sizeof(struct sockaddr_in6),
37
+ netmask, NI_MAXHOST,
38
+ NULL, 0, NI_NUMERICHOST))
39
+ return 0;
40
+ return 1;
41
+ }
42
+
43
+ VALUE set_if_hash(VALUE rb_if_hash, struct ifaddrs *ifa, int family){
44
+ char *if_host, *if_netmask, *if_name;
45
+ if_name = get_if_name(ifa);
46
+ if_host = malloc(sizeof(char) * NI_MAXHOST);
47
+ if (! get_if_host(ifa, if_host))
48
+ rb_raise(rb_eSystemCallError, "Can't get IP from %s", if_name);
49
+
50
+ if_netmask = malloc(sizeof(char) * NI_MAXHOST);
51
+ if (! get_if_netmask(ifa, if_netmask))
52
+ rb_raise(rb_eSystemCallError, "Can't get IP from %s", if_name);
53
+
54
+ char *str_inet_name = "inet_addr_v4";
55
+ char *str_inet_name6 = "inet_addr_v6";
56
+ char *str_netmask_name = "netmask_v4";
57
+ char *str_netmask_name6 = "netmask_v6";
58
+ VALUE rb_if_data_hash = rb_hash_aref(rb_if_hash, rb_str_intern(rb_str_new2(if_name)));
59
+
60
+ if (rb_if_data_hash == Qnil) {
61
+ rb_if_data_hash = rb_hash_new();
62
+ rb_hash_aset(rb_if_hash,
63
+ rb_str_intern(rb_str_new2(if_name)),
64
+ rb_if_data_hash);
65
+ }
66
+
67
+ rb_hash_aset(rb_if_data_hash,
68
+ rb_str_intern(rb_str_new2((family == AF_INET) ? str_inet_name : str_inet_name6)),
69
+ rb_str_new2(if_host));
70
+ rb_hash_aset(rb_if_data_hash,
71
+ rb_str_intern(rb_str_new2((family == AF_INET) ? str_netmask_name : str_netmask_name6)),
72
+ rb_str_new2(if_netmask));
73
+ return rb_if_data_hash;
74
+ }
75
+
76
+ VALUE rb_get_ifaddrs(void)
77
+ {
78
+ struct ifaddrs *ifaddr, *ifa;
79
+ VALUE rb_if_hash;
80
+
81
+ if (getifaddrs(&ifaddr) == -1)
82
+ {
83
+ rb_raise(rb_eSystemCallError, "Can't get info about interfaces");
84
+ }
85
+ rb_if_hash = rb_hash_new();
86
+ for (ifa = ifaddr; ifa != NULL; ifa = ifa->ifa_next)
87
+ {
88
+ int family;
89
+
90
+ family = get_if_family(ifa);
91
+ if (family == AF_INET || family == AF_INET6)
92
+ {
93
+ set_if_hash(rb_if_hash, ifa, family);
94
+ }
95
+ }
96
+ freeifaddrs(ifaddr);
97
+ return rb_if_hash;
98
+ }
99
+
100
+ VALUE mSystem;
101
+ void Init_rb_getifaddrs(){
102
+ mSystem = rb_define_module("System");
103
+ rb_define_module_function(mSystem, "get_ifaddrs", rb_get_ifaddrs, 0);
104
+ }
105
+
File without changes
@@ -0,0 +1,42 @@
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
42
+ end
@@ -0,0 +1,5 @@
1
+ module System
2
+ class Getifaddrs
3
+ VERSION = "0.2.4"
4
+ end
5
+ end
@@ -0,0 +1,9 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+ require 'system/getifaddrs'
4
+ require 'spec'
5
+ require 'spec/autorun'
6
+
7
+ Spec::Runner.configure do |config|
8
+
9
+ end
@@ -0,0 +1,60 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ def get_interfaces_from_ifconfig
4
+ str = `/sbin/ifconfig`
5
+ ary = str.split("\n\n")
6
+ ary.map!{|e| e.split("\n")}
7
+ ifs = Hash.new{|v| v = Array.new}
8
+ ary.each do |elem|
9
+ elem.map!{|e| e.squeeze(' ').strip}
10
+ end
11
+ ary.each do |elem|
12
+ key = elem.first.split(' ').first
13
+ ifs[key.to_sym] = elem.select{|e| e =~ /inet addr:/}
14
+ end
15
+ interfaces = {}
16
+ ifs.each_pair do |key,value|
17
+ unless value.empty?
18
+ value.first.gsub!('inet addr:','inet_addr:')
19
+ ary = value.first.split(' ')
20
+ temp_hash = {}
21
+ ary.each do |elem|
22
+ k, v = elem.split(':')
23
+ case k
24
+ when 'Mask'
25
+ k = 'netmask'
26
+ when 'Bcast'
27
+ k = 'broadcast'
28
+ end
29
+ temp_hash[k.to_sym] = v
30
+ end
31
+ interfaces[key] = temp_hash
32
+ end
33
+ end
34
+ interfaces
35
+ end
36
+
37
+
38
+ describe System do
39
+
40
+ context "getifaddrs" do
41
+ before :all do
42
+ @ifconfig_interfaces = get_interfaces_from_ifconfig
43
+ @get_ifaddrs_interfaces = System.get_ifaddrs
44
+ end
45
+
46
+ it 'should return a hash' do
47
+ @get_ifaddrs_interfaces.should be_kind_of(Hash)
48
+ end
49
+
50
+ it 'should have same number of interfaces than system' do
51
+ @get_ifaddrs_interfaces.keys.size.should have_at_least(@ifconfig_interfaces.keys.size).elements
52
+ end
53
+
54
+ it 'should have same interfaces than system' do
55
+ @ifconfig_interfaces.keys.each do |k|
56
+ @get_ifaddrs_interfaces.should include(k)
57
+ end
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,29 @@
1
+ # -*- encodign: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "system/getifaddrs/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "rumblinthebronx-system-getifaddrs"
7
+ s.version = System::Getifaddrs::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.platform = Gem::Platform.new(['universal', 'java']) if RUBY_PLATFORM == "java"
10
+ s.platform = Gem::Platform.new(['x64', 'mingw32']) if RUBY_PLATFORM.include?("x64-mingw")
11
+ s.authors = ["Sujin Philip", "Bruno Coimbra"]
12
+ s.email = %q{sujin.phil@gmail.com}
13
+ s.homepage = %q{http://github.com/rumblinthebronx/system-getifaddrs}
14
+ s.summary = %q{This library provides the information about the inet interfaces. }
15
+ 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.}
16
+ s.add_development_dependency(%q<rspec>, "~> 1.3")
17
+ s.add_development_dependency(%q<rake-compiler>, [">= 0"])
18
+ s.add_runtime_dependency(%q<netaddr>, "~> 1.5.0") if RUBY_PLATFORM == "java"
19
+
20
+ unless RUBY_PLATFORM.include?("mingw") || RUBY_PLATFORM == "java"
21
+ s.extensions = `git ls-files -- ext/*`.split("\n").select{|f| f =~ /extconf/}
22
+ end
23
+
24
+ s.files = `git ls-files`.split("\n")
25
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
26
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
27
+ s.require_paths = ["lib"]
28
+ end
29
+
metadata ADDED
@@ -0,0 +1,90 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rumblinthebronx-system-getifaddrs
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.4
5
+ platform: x64-mingw32
6
+ authors:
7
+ - Sujin Philip
8
+ - Bruno Coimbra
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-09-11 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ~>
19
+ - !ruby/object:Gem::Version
20
+ version: '1.3'
21
+ type: :development
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ~>
26
+ - !ruby/object:Gem::Version
27
+ version: '1.3'
28
+ - !ruby/object:Gem::Dependency
29
+ name: rake-compiler
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - '>='
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - '>='
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ description: This lib is a wrapper for get_ifaddrs C routine. The original routine
43
+ returns a linked list that contains avaliable inet interfaces. This lib walks on
44
+ list and return an hash that contains the interface names and sub-hashes with respectives
45
+ ip addresses and netmasks.
46
+ email: sujin.phil@gmail.com
47
+ executables: []
48
+ extensions: []
49
+ extra_rdoc_files: []
50
+ files:
51
+ - .document
52
+ - .gitignore
53
+ - .travis.yml
54
+ - Gemfile
55
+ - Gemfile.lock
56
+ - LICENSE
57
+ - README.markdown
58
+ - Rakefile
59
+ - ext/rb_getifaddrs/extconf.rb
60
+ - ext/rb_getifaddrs/rb_getifaddrs.c
61
+ - lib/system/.gitignore
62
+ - lib/system/getifaddrs.rb
63
+ - lib/system/getifaddrs/version.rb
64
+ - spec/spec_helper.rb
65
+ - spec/system-ifaddrs_spec.rb
66
+ - system-getifaddrs.gemspec
67
+ homepage: http://github.com/rumblinthebronx/system-getifaddrs
68
+ licenses: []
69
+ metadata: {}
70
+ post_install_message:
71
+ rdoc_options: []
72
+ require_paths:
73
+ - lib
74
+ required_ruby_version: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - '>='
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ required_rubygems_version: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - '>='
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ requirements: []
85
+ rubyforge_project:
86
+ rubygems_version: 2.0.3
87
+ signing_key:
88
+ specification_version: 4
89
+ summary: This library provides the information about the inet interfaces.
90
+ test_files: []