net-proto 1.3.0 → 1.4.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1daa42393b00eb774a8ad1e9b6ecf3f1b369ac47c46d974c9d671e695a2963c6
4
- data.tar.gz: 8b2437cc1ea12f09cad3b724307f24ea2172ad61cb6d764bcdac0a7bf4751f77
3
+ metadata.gz: 82de82e11a8d4cca74f1b807925b90c89a9dccf50907c5f29edfecf60e43d00d
4
+ data.tar.gz: 0f9f4da5409f7e6e6c1ba1b1ca6bb396964283edf1d01917fd168ccf666ec30c
5
5
  SHA512:
6
- metadata.gz: eba3abc747ec6d2f92ae05bbb907124d85f7ea13a9c03b86519e7fc5306f54ab4ac5abe1e5080c3904b9da295f7e845dcfb8e2d9780fc136e982d44539e83580
7
- data.tar.gz: d832391f70e27a8e8b4bdcadf1ad866e8f1083d6694b6269d944c2818fce546111d0a6fada3ccd93b9dd960d7f0ee496563545701c6d0e6bb001d988c7c2480a
6
+ metadata.gz: f31941974311642c93785c9885524cd724822cffc7d3e7a3954f033c6787125b6d50405a7edc2b41f9685114be2ec82c1dd758570fb0806cc769fa28fcafc777
7
+ data.tar.gz: 887a80b0657627809196abcbb4ae6966ab4d3147d79f9780bea662f3d5a1eb71e3180cb5c1af57746a61cc9ac57bb5d4c4e49fbf8ae4651aadcded2c67145040
checksums.yaml.gz.sig CHANGED
Binary file
data.tar.gz.sig CHANGED
Binary file
@@ -1,24 +1,38 @@
1
- == 1.3.0 - 10-Jan-2019
1
+ ## 1.4.2 - 3-Aug-2021
2
+ * Properly set the p_proto type (short, not int) for Windows.
3
+ * Minor updates suggested by rubocop.
4
+ * Added a Gemfile.
5
+
6
+ ## 1.4.1 - 18-Feb-2021
7
+ * Switch rdoc format to markdown where appropriate.
8
+
9
+ ## 1.4.0 - 17-Aug-2020
10
+ * Switched from test-unit to rspec.
11
+
12
+ ## 1.3.1 - 30-Jul-2020
13
+ * Add a LICENSE file as required by the Apache-2.0 license.
14
+
15
+ ## 1.3.0 - 10-Jan-2019
2
16
  * Changed license to Apache-2.0.
3
17
  * The VERSION constant is now frozen.
4
18
  * Added metadata to the gemspec.
5
19
  * Updated cert, should be good for about 10 years now.
6
20
 
7
- == 1.2.1 - 4-Jan-2016
21
+ ## 1.2.1 - 4-Jan-2016
8
22
  * This gem is now signed.
9
23
  * The gem related tasks in the Rakefile now assume Rubygems 2.x.
10
24
  * Added a net-proto.rb file for convenience.
11
25
 
12
- == 1.2.0 - 3-Nov-2014
26
+ ## 1.2.0 - 3-Nov-2014
13
27
  * The getprotobynumber and getprotobyname methods on MS Windows now accept
14
28
  optional window and message arguments. If used, the method becomes
15
29
  asynchronous and yields a block instead.
16
30
 
17
- == 1.1.1 - 9-Oct-2014
31
+ ## 1.1.1 - 9-Oct-2014
18
32
  * Implemented getprotoent on Windows using pure Ruby.
19
33
  * Miscellaneous minor updates to the Rakefile, gemspec and docs.
20
34
 
21
- == 1.1.0 - 18-Jan-2012
35
+ ## 1.1.0 - 18-Jan-2012
22
36
  * Switched to FFI instead of C backend. Now works with JRuby, too.
23
37
  * Added the generic get_protocol instance method that accepts either a
24
38
  string or an integer and does the right thing. This method should be
@@ -27,19 +41,19 @@
27
41
  * Refactored the test suite to use features of test-unit 2.x.
28
42
  * Added a default rake task.
29
43
 
30
- == 1.0.6 - 22-Oct-2010
44
+ ## 1.0.6 - 22-Oct-2010
31
45
  * Refactored the test suite and removed one test that was implementation
32
46
  dependent and not useful.
33
47
  * Updates to the README and gemspec.
34
48
 
35
- == 1.0.5 - 12-Sep-2009
49
+ ## 1.0.5 - 12-Sep-2009
36
50
  * Changed license to Artistic 2.0.
37
51
  * Added a build_binary_gem task.
38
52
  * Cleaned up and refactored the gemspec a bit, including the addition of
39
53
  a license and an updated description.
40
54
  * Switched test-unit from a runtime dependency to a dev dependency.
41
55
 
42
- == 1.0.4 - 6-Jan-2008
56
+ ## 1.0.4 - 6-Jan-2008
43
57
  * The struct returned by Net::Proto.getprotoent is now frozen. This is
44
58
  strictly read-only data.
45
59
  * It is now explicitly illegal to call Net::Proto.new.
@@ -48,31 +62,31 @@
48
62
  * Renamed and refactored the test suite. This library now requires test-unit
49
63
  version 2.0.2 or later.
50
64
 
51
- == 1.0.3 - 13-Aug-2007
65
+ ## 1.0.3 - 13-Aug-2007
52
66
  * Fix for OS X (whining about malloced pointer).
53
67
  * Added a Rakefile along with tasks for installation and testing.
54
68
  * Major internal reorganization.
55
69
  * Fixed Proto::VERSION test.
56
70
 
57
- == 1.0.2 - 18-Nov-2006
71
+ ## 1.0.2 - 18-Nov-2006
58
72
  * Updated the README, gemspec and netproto.txt files.
59
73
  * No code changes.
60
74
 
61
- == 1.0.1 - 30-Jun-2006
75
+ ## 1.0.1 - 30-Jun-2006
62
76
  * Added rdoc to the source files.
63
77
  * Added a gemspec.
64
78
 
65
- == 1.0.0 - 14-Jul-2005
79
+ ## 1.0.0 - 14-Jul-2005
66
80
  * Moved project to RubyForge.
67
81
  * Minor directory layout change.
68
82
  * Minor changes to the extconf.rb file.
69
83
  * Officially bumped VERSION to 1.0.0.
70
84
 
71
- == 0.2.5 - 18-Apr-2005
85
+ ## 0.2.5 - 18-Apr-2005
72
86
  * The Unix versions now call setprotoent(0) and endprotoent() internally
73
87
  before each call.
74
88
 
75
- == 0.2.4 - 12-Apr-2005
89
+ ## 0.2.4 - 12-Apr-2005
76
90
  * Added internal taint checking for the Proto.getprotobyname method.
77
91
  * Removed the INSTALL file. Installation instructions are now in the README.
78
92
  * Moved the sample script into the 'examples' directory.
@@ -81,13 +95,13 @@
81
95
  * Removed the netproto.rd and netproto.html files. The netproto.txt file is
82
96
  now rdoc friendly.
83
97
 
84
- == 0.2.3 - 13-Sep-2004
98
+ ## 0.2.3 - 13-Sep-2004
85
99
  * Replaced all instances of the deprecated STR2CSTR() function with the
86
100
  StringValuePtr() function. That means that, as of this release, this
87
101
  package requires Ruby 1.8.0 or later.
88
102
  * Minor documentation corrections.
89
103
 
90
- == 0.2.2 - 10-Apr-2004
104
+ ## 0.2.2 - 10-Apr-2004
91
105
  * No longer returns an Array in block form. Only the non-block form returns
92
106
  an array. The block form returns nil.
93
107
  * Updated the documentation, warranty information included, license changed
@@ -96,7 +110,7 @@
96
110
  * Changed "tc_all.rb" to "tc_netproto.rb".
97
111
  * Changed "netproto.rd2" to "netproto.rd".
98
112
 
99
- == 0.2.1 - 29-Jul-2003
113
+ ## 0.2.1 - 29-Jul-2003
100
114
  * Code cleanup (-Wall warnings on Linux)
101
115
  * Removed VERSION() class method. Use the constant instead
102
116
  * The getprotoent() method now returns an array of structs in non-block form
@@ -106,7 +120,7 @@
106
120
  TestUnit installed, instead of dynamically generating one
107
121
  * Fixed up TestUnit test suite
108
122
 
109
- == 0.2.0 - 26-Feb-2003
123
+ ## 0.2.0 - 26-Feb-2003
110
124
  * Added MS Windows support (except 'getprotoent()' - see docs)
111
125
  * For protocols that aren't defined, nil is now returned instead
112
126
  of crashing (always a good thing)
@@ -121,7 +135,7 @@
121
135
  * Manifest now MANIFEST
122
136
  * Package name changed to lower case
123
137
 
124
- == 0.1.0 - 13-Aug-2002
138
+ ## 0.1.0 - 13-Aug-2002
125
139
  * Fixed bug with getprotoent_r function for Linux
126
140
  * Added a 'generic' source file that uses the non-reentrant functions for
127
141
  those platforms that are not specifically supported.
@@ -130,5 +144,5 @@
130
144
  * Added a changelog :)
131
145
  * Added a manifest
132
146
 
133
- == 0.0.1 - 12-Aug-2002
147
+ ## 0.0.1 - 12-Aug-2002
134
148
  * Initial release (though written earlier)
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,177 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
@@ -1,6 +1,7 @@
1
- * CHANGES
2
- * MANIFEST
3
- * README
1
+ * CHANGES.md
2
+ * LICENSE
3
+ * MANIFEST.md
4
+ * README.md
4
5
  * Rakefile
5
6
  * doc/netproto.txt
6
7
  * net-proto.gemspec
@@ -12,4 +13,4 @@
12
13
  * lib/linux/net/proto.rb
13
14
  * lib/sunos/net/proto.rb
14
15
  * examples/example_net_proto.rb
15
- * test/test_net_proto.rb
16
+ * spec/net_proto_spec.rb
@@ -1,17 +1,18 @@
1
- == Description
1
+ ## Description
2
2
  The net-proto package provides a way to get protocol information.
3
3
 
4
- This is a wrapper for the getprotobyname(), getprotobynumber() and
5
- the getprotoent() functions.
4
+ This is a wrapper for the `getprotobyname`, `getprotobynumber` and
5
+ the `getprotoent` C functions.
6
6
 
7
- == Installation
8
- gem install net-proto
7
+ ## Installation
8
+ `gem install net-proto`
9
9
 
10
- == Prerequisites
11
- ffi 1.0.0 or later.
10
+ ## Prerequisites
11
+ * ffi 1.0.0 or later.
12
12
 
13
- == Synopsis
14
- require 'net/proto'
13
+ ## Synopsis
14
+ ```ruby
15
+ require 'net/proto' # or 'net-proto'
15
16
 
16
17
  # Using generic method
17
18
  Net::Proto.get_protocol(1) # => 'icmp'
@@ -25,13 +26,14 @@ Net::Proto.getprotobyname('tcp') # => 6
25
26
  Net::Proto.getprotoent do |ent|
26
27
  p ent
27
28
  end
29
+ ```
28
30
 
29
- == Why should I use this?
31
+ ## Why should I use this?
30
32
  Ruby has a predefined set of constants in socket.c in the general form of
31
33
  IPPROTO_XXX, Y. However, using constants in this fashion can be unreliable
32
34
  because it's easy to define your own protocols (I set 'echo' to 7, for
33
35
  example), or to modify/delete entries in /etc/protocols.
34
36
 
35
- == Further Documentation
36
- See the 'netproto.txt' file under the 'doc' directory for more details. There
37
+ ## Further Documentation
38
+ See the 'netproto.rdoc' file under the 'doc' directory for more details. There
37
39
  is also an example under the 'examples' directory.
data/Rakefile CHANGED
@@ -1,16 +1,17 @@
1
1
  require 'rake'
2
2
  require 'rake/testtask'
3
3
  require 'rake/clean'
4
+ require 'rspec/core/rake_task'
4
5
 
5
- CLEAN.include('**/*.gem', '**/*.rbx', '**/*.rbc')
6
+ CLEAN.include('**/*.gem', '**/*.rbx', '**/*.rbc', '**/*.lock')
6
7
 
7
8
  namespace 'gem' do
8
9
  desc 'Create the net-proto gem'
9
10
  task :create => :clean do
10
11
  require 'rubygems/package'
11
- spec = eval(IO.read('net-proto.gemspec'))
12
+ spec = Gem::Specification.load('net-proto.gemspec')
12
13
  spec.signing_key = File.join(Dir.home, '.ssh', 'gem-private_key.pem')
13
- Gem::Package.build(spec, true)
14
+ Gem::Package.build(spec)
14
15
  end
15
16
 
16
17
  desc 'Install the net-proto gem'
@@ -25,9 +26,8 @@ task :example do
25
26
  ruby '-Ilib examples/example_net_proto.rb'
26
27
  end
27
28
 
28
- Rake::TestTask.new do |t|
29
- t.warning = true
30
- t.verbose = true
29
+ RSpec::Core::RakeTask.new(:spec) do |t|
30
+ t.pattern = ['spec/net_proto_spec.rb']
31
31
  end
32
32
 
33
- task :default => :test
33
+ task :default => :spec
@@ -59,7 +59,7 @@ Proto.getprotoent{ |struct| ... }
59
59
  at https://github.com/djberg96/net-proto.
60
60
 
61
61
  == Copyright
62
- (C) 2003-2019 Daniel J. Berger
62
+ (C) 2003-2020 Daniel J. Berger
63
63
  All rights reserved.
64
64
 
65
65
  == Warranty
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'net/proto/common'
2
4
 
3
5
  # The Net module serves as a namespace only.
@@ -13,8 +15,6 @@ module Net
13
15
  ffi_convention :stdcall
14
16
  end
15
17
 
16
- private
17
-
18
18
  # These should exist on every platform.
19
19
  attach_function :getprotobyname_c, :getprotobyname, [:string], :pointer
20
20
  attach_function :getprotobynumber_c, :getprotobynumber, [:int], :pointer
@@ -35,8 +35,6 @@ module Net
35
35
  private_class_method :getprotobyname_c
36
36
  private_class_method :getprotobynumber_c
37
37
 
38
- public
39
-
40
38
  # If given a protocol string, returns the corresponding number. If
41
39
  # given a protocol number, returns the corresponding string.
42
40
  #
@@ -96,7 +94,7 @@ module Net
96
94
  endprotoent() if respond_to?(:endprotoent, true)
97
95
  end
98
96
 
99
- ptr.null? ? nil: struct[:p_name]
97
+ ptr.null? ? nil : struct[:p_name]
100
98
  end
101
99
 
102
100
  # In block form, yields each entry from /etc/protocols as a struct of type
@@ -1,25 +1,22 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'net/proto/common'
2
4
 
3
5
  # The Net module serves as a namespace only.
4
6
  module Net
5
-
6
7
  # The Proto class serves as the base class for the various protocol methods.
7
8
  class Proto
8
9
  ffi_lib FFI::Library::LIBC
9
10
 
10
- private
11
-
12
11
  attach_function :setprotoent, [:int], :void
13
12
  attach_function :endprotoent, [], :void
14
- attach_function :getprotobyname_r, [:string, :pointer, :pointer, :long, :pointer], :int
15
- attach_function :getprotobynumber_r, [:int, :pointer, :pointer, :long, :pointer], :int
16
- attach_function :getprotoent_r, [:pointer, :pointer, :long, :pointer], :int
13
+ attach_function :getprotobyname_r, %i[string pointer pointer long pointer], :int
14
+ attach_function :getprotobynumber_r, %i[int pointer pointer long pointer], :int
15
+ attach_function :getprotoent_r, %i[pointer pointer long pointer], :int
17
16
 
18
17
  private_class_method :setprotoent, :endprotoent, :getprotobyname_r
19
18
  private_class_method :getprotobynumber_r, :getprotoent_r
20
19
 
21
- public
22
-
23
20
  # If given a protocol string, returns the corresponding number. If
24
21
  # given a protocol number, returns the corresponding string.
25
22
  #
data/lib/net-proto.rb CHANGED
@@ -1 +1,3 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative 'net/proto'
data/lib/net/proto.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rbconfig'
2
4
 
3
5
  case RbConfig::CONFIG['host_os']
@@ -1,29 +1,45 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'ffi'
2
4
 
5
+ # The Net module serves as a namespace only.
3
6
  module Net
7
+ # The Proto class serves as the base class for the various protocol methods.
4
8
  class Proto
5
9
  extend FFI::Library
6
10
 
7
11
  # The version of the net-proto library
8
- VERSION = '1.3.0'.freeze
12
+ VERSION = '1.4.2'
9
13
 
10
14
  private_class_method :new
11
15
 
16
+ # Struct used internally by C functions
12
17
  class ProtocolStruct < FFI::Struct
13
- layout(
14
- :p_name, :string,
15
- :p_aliases, :pointer,
16
- :p_proto, :int
17
- )
18
+ if File::ALT_SEPARATOR
19
+ layout(
20
+ :p_name, :string,
21
+ :p_aliases, :pointer,
22
+ :p_proto, :short
23
+ )
24
+ else
25
+ layout(
26
+ :p_name, :string,
27
+ :p_aliases, :pointer,
28
+ :p_proto, :int
29
+ )
30
+ end
18
31
  end
19
32
 
33
+ private_constant :ProtocolStruct
34
+
35
+ # Reopen the FFI::Pointer class and add our own method.
20
36
  class FFI::Pointer
21
37
  def read_array_of_string
22
38
  elements = []
23
39
 
24
40
  loc = self
25
41
 
26
- until ((element = loc.read_pointer).null?)
42
+ until (element = loc.read_pointer).null?
27
43
  elements << element.read_string
28
44
  loc += FFI::Type::POINTER.size
29
45
  end
@@ -1,23 +1,22 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'net/proto/common'
2
4
 
3
5
  # The Net module serves as a namespace only.
4
6
  module Net
5
-
6
7
  # The Proto class serves as the base class for the various protocol methods.
7
8
  class Proto
8
9
  ffi_lib 'socket'
9
10
 
10
11
  attach_function :setprotoent, [:int], :void
11
12
  attach_function :endprotoent, [], :void
12
- attach_function :getprotobyname_r, [:string, :pointer, :pointer, :int], :pointer
13
- attach_function :getprotobynumber_r, [:int, :pointer, :pointer, :int], :pointer
14
- attach_function :getprotoent_r, [:pointer, :pointer, :int], :pointer
13
+ attach_function :getprotobyname_r, %i[string pointer pointer int], :pointer
14
+ attach_function :getprotobynumber_r, %i[int pointer pointer int], :pointer
15
+ attach_function :getprotoent_r, %i[pointer pointer int], :pointer
15
16
 
16
17
  private_class_method :setprotoent, :endprotoent, :getprotobyname_r
17
18
  private_class_method :getprotobynumber_r, :getprotoent_r
18
19
 
19
- public
20
-
21
20
  # If given a protocol string, returns the corresponding number. If
22
21
  # given a protocol number, returns the corresponding string.
23
22
  #
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'net/proto/common'
2
4
 
3
5
  # The Net module serves as a namespace only.
@@ -10,13 +12,11 @@ module Net
10
12
  ffi_lib 'ws2_32'
11
13
  ffi_convention :stdcall
12
14
 
13
- private
14
-
15
15
  # These should exist on every platform.
16
16
  attach_function :getprotobyname_c, :getprotobyname, [:string], :pointer
17
17
  attach_function :getprotobynumber_c, :getprotobynumber, [:int], :pointer
18
- attach_function :WSAAsyncGetProtoByName, [:uintptr_t, :uint, :string, :pointer, :pointer], :uintptr_t
19
- attach_function :WSAAsyncGetProtoByNumber, [:uintptr_t, :uint, :int, :pointer, :pointer], :uintptr_t
18
+ attach_function :WSAAsyncGetProtoByName, %i[uintptr_t uint string pointer pointer], :uintptr_t
19
+ attach_function :WSAAsyncGetProtoByNumber, %i[uintptr_t uint int pointer pointer], :uintptr_t
20
20
  attach_function :WSAGetLastError, [], :int
21
21
 
22
22
  private_class_method :getprotobyname_c
@@ -25,8 +25,6 @@ module Net
25
25
  private_class_method :WSAAsyncGetProtoByNumber
26
26
  private_class_method :WSAGetLastError
27
27
 
28
- public
29
-
30
28
  # If given a protocol string, returns the corresponding number. If
31
29
  # given a protocol number, returns the corresponding string.
32
30
  #
@@ -71,9 +69,7 @@ module Net
71
69
 
72
70
  handle = WSAAsyncGetProtoByName(hwnd, msg, protocol, struct, size_ptr)
73
71
 
74
- if handle == 0
75
- raise SystemCallError.new('WSAAsyncGetProtoByName', WSAGetLastError())
76
- end
72
+ raise SystemCallError.new('WSAAsyncGetProtoByName', WSAGetLastError()) if handle == 0
77
73
 
78
74
  yield struct[:p_proto], handle
79
75
  else
@@ -113,9 +109,7 @@ module Net
113
109
 
114
110
  handle = WSAAsyncGetProtoByNumber(hwnd, msg, protocol, struct, size_ptr)
115
111
 
116
- if handle == 0
117
- raise SystemCallError.new('WSAAsyncGetProtoByNumber', WSAGetLastError())
118
- end
112
+ raise SystemCallError.new('WSAAsyncGetProtoByNumber', WSAGetLastError()) if handle == 0
119
113
 
120
114
  yield struct[:p_name], handle
121
115
  else
@@ -150,11 +144,11 @@ module Net
150
144
  #
151
145
  def self.getprotoent
152
146
  structs = block_given? ? nil : []
153
- file = ENV['SystemRoot'] + '/system32/drivers/etc/protocol'
147
+ file = File.join(ENV['SystemRoot'], '/system32/drivers/etc/protocol')
154
148
 
155
149
  IO.foreach(file) do |line|
156
150
  next if line.lstrip[0] == '#' # Skip comments
157
- next if line.lstrip.size == 0 # Skip blank lines
151
+ next if line.lstrip.empty? # Skip blank lines
158
152
  line = line.split
159
153
 
160
154
  ruby_struct = ProtoStruct.new(line[0], line[2].split(','), line[1].to_i).freeze
data/net-proto.gemspec CHANGED
@@ -2,26 +2,26 @@ require 'rubygems'
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = 'net-proto'
5
- spec.version = '1.3.0'
5
+ spec.version = '1.4.2'
6
6
  spec.author = 'Daniel J. Berger'
7
7
  spec.license = 'Apache-2.0'
8
8
  spec.email = 'djberg96@gmail.com'
9
9
  spec.homepage = 'https://github.com/djberg96/net-proto'
10
10
  spec.summary = 'A Ruby interface for determining protocol information'
11
- spec.test_file = 'test/test_net_proto.rb'
12
- spec.files = Dir['**/*'].reject{ |f| f.include?('git') }
11
+ spec.test_file = 'spec/net_proto_spec.rb'
12
+ spec.files = Dir['**/*'].reject{ |f| f.include?('git') || f.include?('rubocop') }
13
13
  spec.cert_chain = Dir['certs/*']
14
14
 
15
- spec.extra_rdoc_files = ['CHANGES', 'README', 'MANIFEST', 'doc/netproto.txt']
15
+ spec.extra_rdoc_files = ['doc/netproto.rdoc']
16
16
 
17
- spec.add_dependency('ffi', '>= 1.0.0')
18
- spec.add_development_dependency('test-unit', '>= 2.2.0')
17
+ spec.add_dependency('ffi', '~> 1.0')
18
+ spec.add_development_dependency('rspec', '~> 3.9')
19
19
  spec.add_development_dependency('rake')
20
20
 
21
21
  spec.metadata = {
22
22
  'homepage_uri' => 'https://github.com/djberg96/net-proto',
23
23
  'bug_tracker_uri' => 'https://github.com/djberg96/net-proto/issues',
24
- 'changelog_uri' => 'https://github.com/djberg96/net-proto/blob/ffi/CHANGES',
24
+ 'changelog_uri' => 'https://github.com/djberg96/net-proto/blob/main/CHANGES.md',
25
25
  'documentation_uri' => 'https://github.com/djberg96/net-proto/wiki',
26
26
  'source_code_uri' => 'https://github.com/djberg96/net-proto',
27
27
  'wiki_uri' => 'https://github.com/djberg96/net-proto/wiki'
@@ -0,0 +1,123 @@
1
+ ###########################################################################
2
+ # net_proto_spec.rb
3
+ #
4
+ # Test suite for net-proto on all platforms. This test suite should be run
5
+ # via the 'rake spec' task.
6
+ ###########################################################################
7
+ require 'net/proto'
8
+ require 'rspec'
9
+
10
+ RSpec.describe Net::Proto do
11
+ # These were the protocols listed in my own /etc/protocols file on Solaris 9
12
+ let(:protocols) do
13
+ %w[
14
+ ip icmp igmp ggp ipip tcp cbt egp igp pup udp mux hmp
15
+ xns-idp rdp idpr idpr-cmtp sdrp idrp rsvp gre
16
+ mobile ospf pim ipcomp vrrp sctp hopopt ipv6
17
+ ipv6-route ipv6-frag esp ah ipv6-icmp ipv6-nonxt ipv6-opts
18
+ ]
19
+ end
20
+
21
+ example "version number is set to expected value" do
22
+ expect(Net::Proto::VERSION).to eq('1.4.2')
23
+ expect(Net::Proto::VERSION).to be_frozen
24
+ end
25
+
26
+ example "get_protocol method basic functionality" do
27
+ expect(Net::Proto).to respond_to(:get_protocol)
28
+ end
29
+
30
+ example "get_protocol method accepts a string or a number" do
31
+ expect{ Net::Proto.get_protocol(1) }.not_to raise_error
32
+ expect{ Net::Proto.get_protocol('tcp') }.not_to raise_error
33
+ end
34
+
35
+ example "get_protocol returns nil if protocol not found" do
36
+ expect(Net::Proto.get_protocol(9999999)).to be_nil
37
+ end
38
+
39
+ example "get_protocol fails if an invalid type is passed" do
40
+ expect{ Net::Proto.get_protocol([]) }.to raise_error(TypeError)
41
+ end
42
+
43
+ example "getprotobynumber basic functionality" do
44
+ expect(Net::Proto).to respond_to(:getprotobynumber)
45
+ expect{ 0.upto(132){ |n| Net::Proto.getprotobynumber(n) } }.not_to raise_error
46
+ expect(Net::Proto.getprotobynumber(1)).to be_kind_of(String)
47
+ end
48
+
49
+ example "getprotobynumber returns the expected result" do
50
+ expect(Net::Proto.getprotobynumber(1)).to eq('icmp')
51
+ expect(Net::Proto.getprotobynumber(6)).to eq('tcp')
52
+ end
53
+
54
+ example "getprotobynumber returns nil if not found" do
55
+ expect(Net::Proto.getprotobynumber(9999999)).to eq(nil)
56
+ expect(Net::Proto.getprotobynumber(-1)).to eq(nil)
57
+ end
58
+
59
+ example "getprotobynumber raises a TypeError if a non-numeric arg is used" do
60
+ expect{ Net::Proto.getprotobynumber('foo') }.to raise_error(TypeError)
61
+ expect{ Net::Proto.getprotobynumber(nil) }.to raise_error(TypeError)
62
+ end
63
+
64
+ example "getprotobyname method basic functionality" do
65
+ expect(Net::Proto).to respond_to(:getprotobyname)
66
+ protocols.each{ |n| expect{ Net::Proto.getprotobyname(n) }.not_to raise_error }
67
+ end
68
+
69
+ example "getprotobyname returns the expected result" do
70
+ expect(Net::Proto.getprotobyname('icmp')).to eq(1)
71
+ expect(Net::Proto.getprotobyname('tcp')).to eq(6)
72
+ end
73
+
74
+ example "getprotobyname returns nil if the protocol is not found" do
75
+ expect(Net::Proto.getprotobyname('foo')).to be_nil
76
+ expect(Net::Proto.getprotobyname('tcpx')).to be_nil
77
+ expect(Net::Proto.getprotobyname('')).to be_nil
78
+ end
79
+
80
+ example "getprotobyname raises a TypeError if an invalid arg is passed" do
81
+ expect{ Net::Proto.getprotobyname(1) }.to raise_error(TypeError)
82
+ expect{ Net::Proto.getprotobyname(nil) }.to raise_error(TypeError)
83
+ end
84
+
85
+ example "getprotoent basic functionality" do
86
+ expect(Net::Proto).to respond_to(:getprotoent)
87
+ expect{ Net::Proto.getprotoent }.not_to raise_error
88
+ expect(Net::Proto.getprotoent).to be_kind_of(Array)
89
+ end
90
+
91
+ example "getprotoent method returns the expected results" do
92
+ expect(Net::Proto.getprotoent.first).to be_kind_of(Struct::ProtoStruct)
93
+ expect(Net::Proto.getprotoent{}).to be_nil
94
+ end
95
+
96
+ example "struct returned by getprotoent method contains the expected data" do
97
+ protoent = Net::Proto.getprotoent.first
98
+ expect( protoent.members).to eq([:name, :aliases, :proto])
99
+ expect( protoent.name).to be_kind_of(String)
100
+ expect( protoent.aliases).to be_kind_of(Array)
101
+ expect( protoent.proto).to be_kind_of(Integer)
102
+ end
103
+
104
+ example "all members of the aliases struct member are strings" do
105
+ protoent = Net::Proto.getprotoent.first
106
+ expect(protoent.aliases.all?{ |e| e.is_a?(String) }).to eq(true)
107
+ end
108
+
109
+ example "struct returned by getprotoent method is frozen" do
110
+ protoent = Net::Proto.getprotoent.first
111
+ expect(protoent.frozen?).to eq(true)
112
+ end
113
+
114
+ example "there is no constructor" do
115
+ expect{ Net::Proto.new }.to raise_error(NoMethodError)
116
+ end
117
+
118
+ example "ffi functions are private" do
119
+ methods = Net::Proto.methods(false)
120
+ expect(methods.include?(:setprotoent)).to eq(false)
121
+ expect(methods.include?(:endprotoent)).to eq(false)
122
+ end
123
+ end
metadata CHANGED
@@ -1,11 +1,11 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: net-proto
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 1.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel J. Berger
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain:
11
11
  - |
@@ -35,36 +35,36 @@ cert_chain:
35
35
  ORVCZpRuCPpmC8qmqxUnARDArzucjaclkxjLWvCVHeFa9UP7K3Nl9oTjJNv+7/jM
36
36
  WZs4eecIcUc4tKdHxcAJ0MO/Dkqq7hGaiHpwKY76wQ1+8xAh
37
37
  -----END CERTIFICATE-----
38
- date:
38
+ date: 2021-08-03 00:00:00.000000000 Z
39
39
  dependencies:
40
40
  - !ruby/object:Gem::Dependency
41
41
  name: ffi
42
42
  requirement: !ruby/object:Gem::Requirement
43
43
  requirements:
44
- - - ">="
44
+ - - "~>"
45
45
  - !ruby/object:Gem::Version
46
- version: 1.0.0
46
+ version: '1.0'
47
47
  type: :runtime
48
48
  prerelease: false
49
49
  version_requirements: !ruby/object:Gem::Requirement
50
50
  requirements:
51
- - - ">="
51
+ - - "~>"
52
52
  - !ruby/object:Gem::Version
53
- version: 1.0.0
53
+ version: '1.0'
54
54
  - !ruby/object:Gem::Dependency
55
- name: test-unit
55
+ name: rspec
56
56
  requirement: !ruby/object:Gem::Requirement
57
57
  requirements:
58
- - - ">="
58
+ - - "~>"
59
59
  - !ruby/object:Gem::Version
60
- version: 2.2.0
60
+ version: '3.9'
61
61
  type: :development
62
62
  prerelease: false
63
63
  version_requirements: !ruby/object:Gem::Requirement
64
64
  requirements:
65
- - - ">="
65
+ - - "~>"
66
66
  - !ruby/object:Gem::Version
67
- version: 2.2.0
67
+ version: '3.9'
68
68
  - !ruby/object:Gem::Dependency
69
69
  name: rake
70
70
  requirement: !ruby/object:Gem::Requirement
@@ -87,53 +87,37 @@ email: djberg96@gmail.com
87
87
  executables: []
88
88
  extensions: []
89
89
  extra_rdoc_files:
90
- - CHANGES
91
- - README
92
- - MANIFEST
93
- - doc/netproto.txt
90
+ - doc/netproto.rdoc
94
91
  files:
95
- - CHANGES
96
- - test
97
- - test/test_net_proto.rb
98
- - net-proto.gemspec
99
- - examples
100
- - examples/example_net_proto.rb
101
- - doc
102
- - doc/netproto.txt
103
- - README
92
+ - CHANGES.md
93
+ - Gemfile
94
+ - LICENSE
95
+ - MANIFEST.md
96
+ - README.md
104
97
  - Rakefile
105
- - MANIFEST
106
- - lib
107
- - lib/windows
108
- - lib/windows/net
109
- - lib/windows/net/proto.rb
110
- - lib/sunos
111
- - lib/sunos/net
112
- - lib/sunos/net/proto.rb
113
- - lib/net-proto.rb
114
- - lib/linux
115
- - lib/linux/net
98
+ - certs/djberg96_pub.pem
99
+ - doc/netproto.rdoc
100
+ - examples/example_net_proto.rb
101
+ - lib/generic/net/proto.rb
116
102
  - lib/linux/net/proto.rb
117
- - lib/net
103
+ - lib/net-proto.rb
118
104
  - lib/net/proto.rb
119
- - lib/net/proto
120
105
  - lib/net/proto/common.rb
121
- - lib/generic
122
- - lib/generic/net
123
- - lib/generic/net/proto.rb
124
- - certs
125
- - certs/djberg96_pub.pem
106
+ - lib/sunos/net/proto.rb
107
+ - lib/windows/net/proto.rb
108
+ - net-proto.gemspec
109
+ - spec/net_proto_spec.rb
126
110
  homepage: https://github.com/djberg96/net-proto
127
111
  licenses:
128
112
  - Apache-2.0
129
113
  metadata:
130
114
  homepage_uri: https://github.com/djberg96/net-proto
131
115
  bug_tracker_uri: https://github.com/djberg96/net-proto/issues
132
- changelog_uri: https://github.com/djberg96/net-proto/blob/ffi/CHANGES
116
+ changelog_uri: https://github.com/djberg96/net-proto/blob/main/CHANGES.md
133
117
  documentation_uri: https://github.com/djberg96/net-proto/wiki
134
118
  source_code_uri: https://github.com/djberg96/net-proto
135
119
  wiki_uri: https://github.com/djberg96/net-proto/wiki
136
- post_install_message:
120
+ post_install_message:
137
121
  rdoc_options: []
138
122
  require_paths:
139
123
  - lib
@@ -148,9 +132,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
148
132
  - !ruby/object:Gem::Version
149
133
  version: '0'
150
134
  requirements: []
151
- rubygems_version: 3.0.2
152
- signing_key:
135
+ rubygems_version: 3.2.15
136
+ signing_key:
153
137
  specification_version: 4
154
138
  summary: A Ruby interface for determining protocol information
155
139
  test_files:
156
- - test/test_net_proto.rb
140
+ - spec/net_proto_spec.rb
metadata.gz.sig CHANGED
Binary file
@@ -1,136 +0,0 @@
1
- ###########################################################################
2
- # test_net_netproto.rb
3
- #
4
- # Test suite for net-proto - all platforms. This test suite should be run
5
- # via the 'rake test' task.
6
- ###########################################################################
7
- require 'net/proto'
8
- require 'test-unit'
9
-
10
- class TC_Net_Proto < Test::Unit::TestCase
11
-
12
- # These were the protocols listed in my own /etc/protocols file on Solaris 9
13
- def self.startup
14
- @@protocols = %w/
15
- ip icmp igmp ggp ipip tcp cbt egp igp pup udp mux hmp
16
- xns-idp rdp idpr idpr-cmtp sdrp idrp rsvp gre
17
- mobile ospf pim ipcomp vrrp sctp hopopt ipv6
18
- ipv6-route ipv6-frag esp ah ipv6-icmp ipv6-nonxt ipv6-opts
19
- /
20
- end
21
-
22
- def setup
23
- @protoent = nil
24
- end
25
-
26
- test "version number is set to expected value" do
27
- assert_equal('1.3.0', Net::Proto::VERSION)
28
- assert_true(Net::Proto::VERSION.frozen?)
29
- end
30
-
31
- test "get_protocol method basic functionality" do
32
- assert_respond_to(Net::Proto, :get_protocol)
33
- end
34
-
35
- test "get_protocol method accepts a string or a number" do
36
- assert_nothing_raised{ Net::Proto.get_protocol(1) }
37
- assert_nothing_raised{ Net::Proto.get_protocol('tcp') }
38
- end
39
-
40
- test "get_protocol returns nil if protocol not found" do
41
- assert_nil(Net::Proto.get_protocol(9999999))
42
- end
43
-
44
- test "get_protocol fails if an invalid type is passed" do
45
- assert_raise(TypeError){ Net::Proto.get_protocol([]) }
46
- end
47
-
48
- test "getprotobynumber basic functionality" do
49
- assert_respond_to(Net::Proto, :getprotobynumber)
50
- assert_nothing_raised{ 0.upto(132){ |n| Net::Proto.getprotobynumber(n) } }
51
- assert_kind_of(String, Net::Proto.getprotobynumber(1))
52
- end
53
-
54
- test "getprotobynumber returns the expected result" do
55
- assert_equal('icmp', Net::Proto.getprotobynumber(1))
56
- assert_equal('tcp', Net::Proto.getprotobynumber(6))
57
- end
58
-
59
- test "getprotobynumber returns nil if not found" do
60
- assert_equal(nil, Net::Proto.getprotobynumber(9999999))
61
- assert_equal(nil, Net::Proto.getprotobynumber(-1))
62
- end
63
-
64
- test "getprotobynumber raises a TypeError if a non-numeric arg is used" do
65
- assert_raise(TypeError){ Net::Proto.getprotobynumber('foo') }
66
- assert_raise(TypeError){ Net::Proto.getprotobynumber(nil) }
67
- end
68
-
69
- test "getprotobyname method basic functionality" do
70
- assert_respond_to(Net::Proto, :getprotobyname)
71
- @@protocols.each{ |n| assert_nothing_raised{ Net::Proto.getprotobyname(n) } }
72
- end
73
-
74
- test "getprotobyname returns the expected result" do
75
- assert_equal(1, Net::Proto.getprotobyname('icmp'))
76
- assert_equal(6, Net::Proto.getprotobyname('tcp'))
77
- end
78
-
79
- test "getprotobyname returns nil if the protocol is not found" do
80
- assert_nil(Net::Proto.getprotobyname('foo'))
81
- assert_nil(Net::Proto.getprotobyname('tcpx'))
82
- assert_nil(Net::Proto.getprotobyname(''))
83
- end
84
-
85
- test "getprotobyname raises a TypeError if an invalid arg is passed" do
86
- assert_raises(TypeError){ Net::Proto.getprotobyname(1) }
87
- assert_raises(TypeError){ Net::Proto.getprotobyname(nil) }
88
- end
89
-
90
- test "getprotoent basic functionality" do
91
- assert_respond_to(Net::Proto, :getprotoent)
92
- assert_nothing_raised{ Net::Proto.getprotoent }
93
- assert_kind_of(Array, Net::Proto.getprotoent)
94
- end
95
-
96
- test "getprotoent method returns the expected results" do
97
- assert_kind_of(Struct::ProtoStruct, Net::Proto.getprotoent.first)
98
- assert_nil(Net::Proto.getprotoent{})
99
- end
100
-
101
- test "struct returned by getprotoent method contains the expected data" do
102
- @protoent = Net::Proto.getprotoent.first
103
- assert_equal([:name, :aliases, :proto], @protoent.members)
104
- assert_kind_of(String, @protoent.name)
105
- assert_kind_of(Array, @protoent.aliases)
106
- assert_kind_of(Integer, @protoent.proto)
107
- end
108
-
109
- test "all members of the aliases struct member are strings" do
110
- @protoent = Net::Proto.getprotoent.first
111
- assert_true(@protoent.aliases.all?{ |e| e.is_a?(String) })
112
- end
113
-
114
- test "struct returned by getprotoent method is frozen" do
115
- @protoent = Net::Proto.getprotoent.first
116
- assert_true(@protoent.frozen?)
117
- end
118
-
119
- test "there is no constructor" do
120
- assert_raise(NoMethodError){ Net::Proto.new }
121
- end
122
-
123
- test "ffi functions are private" do
124
- methods = Net::Proto.methods(false).map{ |m| m.to_sym }
125
- assert_false(methods.include?(:setprotoent))
126
- assert_false(methods.include?(:endprotoent))
127
- end
128
-
129
- def teardown
130
- @protoent = nil
131
- end
132
-
133
- def self.shutdown
134
- @@protocols = nil
135
- end
136
- end