net-proto 1.0.5 → 1.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGES +5 -0
- data/README +15 -11
- data/Rakefile +58 -55
- data/ext/version.h +1 -1
- data/net-proto.gemspec +20 -21
- data/test/test_net_proto.rb +119 -108
- metadata +36 -18
data/CHANGES
CHANGED
data/README
CHANGED
@@ -1,17 +1,21 @@
|
|
1
|
-
|
1
|
+
= Description
|
2
2
|
The net-proto package provides a way to get protocol information.
|
3
3
|
|
4
|
-
|
5
|
-
|
4
|
+
= Installation
|
5
|
+
gem install net-proto
|
6
|
+
|
7
|
+
= Synopsis
|
8
|
+
require 'net/proto'
|
6
9
|
|
7
|
-
|
8
|
-
|
10
|
+
Net::Proto.getprotobyname('tcp') # => 6
|
11
|
+
Net::Proto.getprotobynumber(0) # => 'ip'
|
9
12
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
+
Net::Proto.getprotoent{ |entry| p entry }
|
14
|
+
|
15
|
+
= Notes
|
16
|
+
This library is a wrapper for the getprotobyname(), getprotobynumber() and
|
17
|
+
the getprotoent() functions.
|
13
18
|
|
14
|
-
== Notes
|
15
19
|
The net-proto package uses reentrant code for sunos and linux. Otherwise, the
|
16
20
|
generic form of the functions are used (which may be reentrant by default
|
17
21
|
anway - check the man pages on your platform).
|
@@ -19,12 +23,12 @@ anway - check the man pages on your platform).
|
|
19
23
|
The Proto.getprotoent method is not supported on MS Windows because the
|
20
24
|
underlying function isn't supported by the MS Windows API.
|
21
25
|
|
22
|
-
|
26
|
+
= Why should I use this?
|
23
27
|
Ruby has a predefined set of constants in socket.c in the general form of
|
24
28
|
IPPROTO_XXX, Y. However, using constants in this fashion can be unreliable
|
25
29
|
because it's easy to define your own protocols (I set 'echo' to 7, for
|
26
30
|
example), or to modify/delete entries in /etc/protocols.
|
27
31
|
|
28
|
-
|
32
|
+
= Further Documentation
|
29
33
|
See the 'netproto.txt' file under the 'doc' directory for more details. There
|
30
34
|
is also an example under the 'examples' directory.
|
data/Rakefile
CHANGED
@@ -6,74 +6,77 @@ include Config
|
|
6
6
|
|
7
7
|
desc 'Clean the build files for the net-proto source'
|
8
8
|
task :clean do
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
9
|
+
Dir['*.gem'].each{ |f| File.delete(f) }
|
10
|
+
Dir['**/*.rbc'].each{ |f| File.delete(f) }
|
11
|
+
|
12
|
+
make = RUBY_PLATFORM.match('mswin') ? 'nmake' : 'make'
|
13
|
+
|
14
|
+
Dir.chdir('ext') do
|
15
|
+
proto_file = 'proto.' + Config::CONFIG['DLEXT']
|
16
|
+
if File.exists?('proto.o') || File.exists?(proto_file)
|
17
|
+
sh "#{make} distclean"
|
18
|
+
end
|
19
|
+
rm_rf('proto.c') if File.exists?('proto.c')
|
20
|
+
rm_rf('net') if File.exists?('net')
|
21
|
+
end
|
22
|
+
|
23
|
+
rm_rf('net') if File.exists?('net')
|
24
|
+
rm_rf('lib') if File.exists?('lib')
|
19
25
|
end
|
20
26
|
|
21
27
|
desc 'Build the net-proto library'
|
22
28
|
task :build => [:clean] do
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
29
|
+
make = RUBY_PLATFORM.match('mswin') ? 'nmake' : 'make'
|
30
|
+
Dir.chdir('ext') do
|
31
|
+
ruby 'extconf.rb'
|
32
|
+
sh make
|
33
|
+
build_file = 'proto.' + Config::CONFIG['DLEXT']
|
34
|
+
Dir.mkdir('net') unless File.exists?('net')
|
35
|
+
FileUtils.cp(build_file, 'net')
|
36
|
+
end
|
31
37
|
end
|
32
38
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
+
namespace :gem do
|
40
|
+
desc 'Build a standard gem'
|
41
|
+
task :create => :clean do
|
42
|
+
rm_rf('lib') if File.exists?('lib')
|
43
|
+
spec = eval(IO.read('net-proto.gemspec'))
|
44
|
+
Gem::Builder.new(spec).build
|
45
|
+
end
|
46
|
+
|
47
|
+
desc 'Build a binary gem'
|
48
|
+
task :create_binary => [:build] do
|
49
|
+
file = 'ext/net/proto.' + CONFIG['DLEXT']
|
50
|
+
mkdir_p('lib/net')
|
51
|
+
mv(file, 'lib/net')
|
52
|
+
|
53
|
+
spec = eval(IO.read('net-proto.gemspec'))
|
54
|
+
spec.extensions = nil
|
55
|
+
spec.files = spec.files.reject{ |f| f.include?('ext/') }
|
56
|
+
spec.platform = Gem::Platform::CURRENT
|
39
57
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
58
|
+
Gem::Builder.new(spec).build
|
59
|
+
end
|
60
|
+
|
61
|
+
desc 'Install the net-proto library (gem)'
|
62
|
+
task :install => [:create] do
|
63
|
+
ruby 'net-proto.gemspec'
|
64
|
+
file = Dir["net-proto*.gem"].last
|
65
|
+
sh "gem install #{file}"
|
66
|
+
end
|
45
67
|
end
|
46
68
|
|
47
69
|
desc 'Run the example net-proto program'
|
48
70
|
task :example => [:build] do
|
49
|
-
|
50
|
-
|
71
|
+
Dir.mkdir('net') unless File.exists?('net')
|
72
|
+
ruby '-Iext examples/example_net_proto.rb'
|
51
73
|
end
|
52
74
|
|
53
75
|
Rake::TestTask.new do |t|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
end
|
59
|
-
|
60
|
-
desc 'Build a standard gem'
|
61
|
-
task :build_gem => :clean do
|
62
|
-
rm_rf('lib') if File.exists?('lib')
|
63
|
-
spec = eval(IO.read('net-proto.gemspec'))
|
64
|
-
Gem::Builder.new(spec).build
|
76
|
+
task :test => :build
|
77
|
+
t.libs << 'ext'
|
78
|
+
t.warning = true
|
79
|
+
t.verbose = true
|
65
80
|
end
|
66
81
|
|
67
|
-
|
68
|
-
task :build_binary_gem => [:build] do
|
69
|
-
file = 'ext/net/proto.' + CONFIG['DLEXT']
|
70
|
-
mkdir_p('lib/net')
|
71
|
-
mv(file, 'lib/net')
|
72
|
-
|
73
|
-
spec = eval(IO.read('net-proto.gemspec'))
|
74
|
-
spec.extensions = nil
|
75
|
-
spec.files = spec.files.reject{ |f| f.include?('ext/') }
|
76
|
-
spec.platform = Gem::Platform::CURRENT
|
77
|
-
|
78
|
-
Gem::Builder.new(spec).build
|
79
|
-
end
|
82
|
+
task :default => :test
|
data/ext/version.h
CHANGED
@@ -1,2 +1,2 @@
|
|
1
1
|
/* version.h - there can be only one */
|
2
|
-
#define NET_PROTO_VERSION "1.0.
|
2
|
+
#define NET_PROTO_VERSION "1.0.6"
|
data/net-proto.gemspec
CHANGED
@@ -4,27 +4,26 @@ require 'rubygems'
|
|
4
4
|
# To build a binary gem => rake build_binary_gem
|
5
5
|
|
6
6
|
Gem::Specification.new do |gem|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
gem.files = Dir['**/*'].reject{ |f| f.include?('CVS') }
|
7
|
+
gem.name = 'net-proto'
|
8
|
+
gem.version = '1.0.6'
|
9
|
+
gem.author = 'Daniel J. Berger'
|
10
|
+
gem.license = 'Artistic 2.0'
|
11
|
+
gem.email = 'djberg96@gmail.com'
|
12
|
+
gem.homepage = 'http://www.rubyforge.org/projects/sysutils'
|
13
|
+
gem.platform = Gem::Platform::RUBY
|
14
|
+
gem.summary = 'A Ruby interface for determining protocol information'
|
15
|
+
gem.test_file = 'test/test_net_proto.rb'
|
16
|
+
gem.extensions = ['ext/extconf.rb']
|
17
|
+
gem.files = Dir['**/*'].reject{ |f| f.include?('git') }
|
19
18
|
|
20
|
-
|
21
|
-
|
19
|
+
gem.rubyforge_project = 'sysutils'
|
20
|
+
gem.extra_rdoc_files = ['CHANGES', 'README', 'MANIFEST', 'doc/netproto.txt']
|
22
21
|
|
23
|
-
|
22
|
+
gem.add_development_dependency('test-unit', '>= 2.1.1')
|
24
23
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
end
|
24
|
+
gem.description = <<-EOF
|
25
|
+
The net-proto library provides an interface for get protocol information
|
26
|
+
by name or by number. It can also iterate over the list of protocol
|
27
|
+
entries defined on your system.
|
28
|
+
EOF
|
29
|
+
end
|
data/test/test_net_proto.rb
CHANGED
@@ -12,115 +12,126 @@ require 'test/unit'
|
|
12
12
|
|
13
13
|
class TC_Net_Proto < Test::Unit::TestCase
|
14
14
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
15
|
+
# These were the protocols listed in my own /etc/protocols file on Solaris 9
|
16
|
+
def self.startup
|
17
|
+
@@windows = Config::CONFIG['host_os'] =~ /win32|msdos|mswin|cygwin|mingw/i
|
18
|
+
|
19
|
+
@@protocols = %w/
|
20
|
+
ip icmp igmp ggp ipip tcp cbt egp igp pup udp mux hmp
|
21
|
+
xns-idp rdp idpr idpr-cmtp sdrp idrp rsvp gre
|
22
|
+
mobile ospf pim ipcomp vrrp sctp hopopt ipv6
|
23
|
+
ipv6-route ipv6-frag esp ah ipv6-icmp ipv6-nonxt ipv6-opts
|
24
|
+
/
|
25
|
+
end
|
26
|
+
|
27
|
+
def setup
|
28
|
+
@protoent = nil
|
29
|
+
end
|
30
|
+
|
31
|
+
test "version number returns expected value" do
|
32
|
+
assert_equal('1.0.6', Net::Proto::VERSION)
|
33
|
+
end
|
34
|
+
|
35
|
+
test "getprotobynumber basic functionality" do
|
36
|
+
assert_respond_to(Net::Proto, :getprotobynumber)
|
37
|
+
assert_nothing_raised{ 0.upto(132){ |n| Net::Proto.getprotobynumber(n) } }
|
38
|
+
assert_kind_of(String, Net::Proto.getprotobynumber(1))
|
39
|
+
end
|
40
|
+
|
41
|
+
test "getprotobynumber returns the expected result" do
|
42
|
+
assert_equal('icmp', Net::Proto.getprotobynumber(1))
|
43
|
+
assert_equal('tcp', Net::Proto.getprotobynumber(6))
|
44
|
+
end
|
45
|
+
|
46
|
+
test "getprotobynumber returns nil if the protocol cannot be found" do
|
47
|
+
assert_equal(nil, Net::Proto.getprotobynumber(9999999))
|
48
|
+
assert_equal(nil, Net::Proto.getprotobynumber(-1))
|
49
|
+
end
|
50
|
+
|
51
|
+
test "getprotobynumber requires a numeric argument" do
|
52
|
+
assert_raise(TypeError){ Net::Proto.getprotobynumber('foo') }
|
53
|
+
assert_raise(TypeError){ Net::Proto.getprotobynumber(nil) }
|
54
|
+
end
|
55
|
+
|
56
|
+
test "getprotobyname basic functionality" do
|
57
|
+
assert_respond_to(Net::Proto, :getprotobyname)
|
58
|
+
@@protocols.each{ |n| assert_nothing_raised{ Net::Proto.getprotobyname(n) } }
|
59
|
+
assert_kind_of(Fixnum, Net::Proto.getprotobyname('tcp'))
|
60
|
+
end
|
61
|
+
|
62
|
+
test "getprotobyname returns expected result" do
|
63
|
+
assert_equal(1, Net::Proto.getprotobyname('icmp'))
|
64
|
+
assert_equal(6, Net::Proto.getprotobyname('tcp'))
|
65
|
+
end
|
66
|
+
|
67
|
+
test "getprotobyname returns nil if the protocol cannot be found" do
|
68
|
+
assert_equal(nil, Net::Proto.getprotobyname('foo'))
|
69
|
+
assert_equal(nil, Net::Proto.getprotobyname('tcpx'))
|
70
|
+
assert_equal(nil, Net::Proto.getprotobyname(''))
|
71
|
+
end
|
72
|
+
|
73
|
+
test "getprotobyname requires a string argument" do
|
74
|
+
assert_raises(TypeError){ Net::Proto.getprotobyname(1) }
|
75
|
+
assert_raises(TypeError){ Net::Proto.getprotobyname(nil) }
|
76
|
+
end
|
77
|
+
|
78
|
+
test "getprotoent basic functionality" do
|
79
|
+
omit_if(@@windows, 'Skipped on MS Windows')
|
80
|
+
assert_respond_to(Net::Proto, :getprotoent)
|
81
|
+
assert_nothing_raised{ Net::Proto.getprotoent }
|
82
|
+
end
|
83
|
+
|
84
|
+
test "getprotoent returns an array if no block is provided" do
|
85
|
+
omit_if(@@windows, 'Skipped on MS Windows')
|
86
|
+
assert_kind_of(Array, Net::Proto.getprotoent)
|
87
|
+
end
|
88
|
+
|
89
|
+
test "getprotoent accepts a block" do
|
90
|
+
omit_if(@@windows, 'Skipped on MS Windows')
|
91
|
+
assert_nothing_raised{ Net::Proto.getprotoent{} }
|
92
|
+
assert_nil(Net::Proto.getprotoent{})
|
93
|
+
end
|
94
|
+
|
95
|
+
test "getprotoent returns an array of structs" do
|
96
|
+
omit_if(@@windows, 'Skipped on MS Windows')
|
97
|
+
assert_kind_of(Struct::ProtoStruct, Net::Proto.getprotoent.first)
|
98
|
+
end
|
99
|
+
|
100
|
+
test "structs returned by getprotoent contain specific members" do
|
101
|
+
omit_if(@@windows, 'Skipped on MS Windows')
|
102
|
+
@protoent = Net::Proto.getprotoent.first
|
103
|
+
assert_equal(['name', 'aliases', 'proto'], @protoent.members)
|
104
|
+
end
|
105
|
+
|
106
|
+
test "struct members are of a specific type" do
|
107
|
+
omit_if(@@windows, 'Skipped on MS Windows')
|
108
|
+
@protoent = Net::Proto.getprotoent.first
|
109
|
+
assert_kind_of(String, @protoent.name)
|
110
|
+
assert_kind_of(Array, @protoent.aliases)
|
111
|
+
assert_kind_of(Integer, @protoent.proto)
|
112
|
+
end
|
113
|
+
|
114
|
+
test "aliases struct member returns an array of strings" do
|
115
|
+
omit_if(@@windows, 'Skipped on MS Windows')
|
116
|
+
@protoent = Net::Proto.getprotoent.first
|
117
|
+
assert_true(@protoent.aliases.all?{ |e| e.is_a?(String) })
|
118
|
+
end
|
119
|
+
|
120
|
+
test "the structs returned by getprotoent are frozen" do
|
121
|
+
omit_if(@@windows, 'Skipped on MS Windows')
|
122
|
+
@protoent = Net::Proto.getprotoent.first
|
123
|
+
assert_true(@protoent.frozen?)
|
124
|
+
end
|
114
125
|
|
115
|
-
|
116
|
-
|
117
|
-
|
126
|
+
test "there is no constructor for the Proto class" do
|
127
|
+
assert_raise(NoMethodError){ Net::Proto.new }
|
128
|
+
end
|
118
129
|
|
119
|
-
|
120
|
-
|
121
|
-
|
130
|
+
def teardown
|
131
|
+
@protoent = nil
|
132
|
+
end
|
122
133
|
|
123
|
-
|
124
|
-
|
125
|
-
|
134
|
+
def self.shutdown
|
135
|
+
@@protocols = nil
|
136
|
+
end
|
126
137
|
end
|
metadata
CHANGED
@@ -1,7 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: net-proto
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
hash: 27
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 1
|
8
|
+
- 0
|
9
|
+
- 6
|
10
|
+
version: 1.0.6
|
5
11
|
platform: ruby
|
6
12
|
authors:
|
7
13
|
- Daniel J. Berger
|
@@ -9,20 +15,26 @@ autorequire:
|
|
9
15
|
bindir: bin
|
10
16
|
cert_chain: []
|
11
17
|
|
12
|
-
date:
|
18
|
+
date: 2010-10-22 00:00:00 -06:00
|
13
19
|
default_executable:
|
14
20
|
dependencies:
|
15
21
|
- !ruby/object:Gem::Dependency
|
16
22
|
name: test-unit
|
17
|
-
|
18
|
-
|
19
|
-
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
20
26
|
requirements:
|
21
27
|
- - ">="
|
22
28
|
- !ruby/object:Gem::Version
|
23
|
-
|
24
|
-
|
25
|
-
|
29
|
+
hash: 9
|
30
|
+
segments:
|
31
|
+
- 2
|
32
|
+
- 1
|
33
|
+
- 1
|
34
|
+
version: 2.1.1
|
35
|
+
type: :development
|
36
|
+
version_requirements: *id001
|
37
|
+
description: " The net-proto library provides an interface for get protocol information\n by name or by number. It can also iterate over the list of protocol\n entries defined on your system.\n"
|
26
38
|
email: djberg96@gmail.com
|
27
39
|
executables: []
|
28
40
|
|
@@ -34,20 +46,20 @@ extra_rdoc_files:
|
|
34
46
|
- MANIFEST
|
35
47
|
- doc/netproto.txt
|
36
48
|
files:
|
37
|
-
-
|
49
|
+
- Rakefile
|
50
|
+
- README
|
38
51
|
- doc/netproto.txt
|
52
|
+
- net-proto.gemspec
|
53
|
+
- CHANGES
|
39
54
|
- examples/example_net_proto.rb
|
55
|
+
- test/test_net_proto.rb
|
56
|
+
- MANIFEST
|
40
57
|
- ext/extconf.rb
|
58
|
+
- ext/version.h
|
41
59
|
- ext/generic/generic.c
|
42
60
|
- ext/linux/linux.c
|
43
61
|
- ext/sunos/sunos.c
|
44
|
-
- ext/version.h
|
45
62
|
- ext/windows/windows.c
|
46
|
-
- MANIFEST
|
47
|
-
- net-proto.gemspec
|
48
|
-
- Rakefile
|
49
|
-
- README
|
50
|
-
- test/test_net_proto.rb
|
51
63
|
has_rdoc: true
|
52
64
|
homepage: http://www.rubyforge.org/projects/sysutils
|
53
65
|
licenses:
|
@@ -58,21 +70,27 @@ rdoc_options: []
|
|
58
70
|
require_paths:
|
59
71
|
- lib
|
60
72
|
required_ruby_version: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
61
74
|
requirements:
|
62
75
|
- - ">="
|
63
76
|
- !ruby/object:Gem::Version
|
77
|
+
hash: 3
|
78
|
+
segments:
|
79
|
+
- 0
|
64
80
|
version: "0"
|
65
|
-
version:
|
66
81
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
82
|
+
none: false
|
67
83
|
requirements:
|
68
84
|
- - ">="
|
69
85
|
- !ruby/object:Gem::Version
|
86
|
+
hash: 3
|
87
|
+
segments:
|
88
|
+
- 0
|
70
89
|
version: "0"
|
71
|
-
version:
|
72
90
|
requirements: []
|
73
91
|
|
74
92
|
rubyforge_project: sysutils
|
75
|
-
rubygems_version: 1.3.
|
93
|
+
rubygems_version: 1.3.7
|
76
94
|
signing_key:
|
77
95
|
specification_version: 3
|
78
96
|
summary: A Ruby interface for determining protocol information
|