net-proto 1.1.1 → 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- checksums.yaml.gz.sig +1 -0
- data.tar.gz.sig +0 -0
- data/CHANGES +22 -0
- data/LICENSE +177 -0
- data/MANIFEST +4 -1
- data/Rakefile +7 -10
- data/certs/djberg96_pub.pem +26 -0
- data/doc/netproto.txt +2 -6
- data/lib/net-proto.rb +1 -0
- data/lib/net/proto/common.rb +1 -1
- data/lib/windows/net/proto.rb +65 -16
- data/net-proto.gemspec +25 -15
- data/spec/net_proto_spec.rb +123 -0
- metadata +71 -21
- metadata.gz.sig +0 -0
- data/test/test_net_proto.rb +0 -135
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 22fc633cd0a57112a8a74a3725ef8cf228a0e4d7234d092b154bd075fb6467e3
|
4
|
+
data.tar.gz: d1b70a57d424a8a9f8088c38f3551fd339ed9ba35b701de4d53354358555cee7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7bb84b41f65803a273e6343d3a2e6d7126a2589831529120bbd255b6fcae57e642ea76d1976bd4f44287be0ededc5941f9393136d2b3429558e1b63174101934
|
7
|
+
data.tar.gz: 0a9abc6743751706c141314275595f2162f69924ee4b8a63dd14a6fff9caa2f0a66edfa855031e9e563b62408b351e81afb012889355564e79bc807134eac2b0
|
checksums.yaml.gz.sig
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
N�
|
data.tar.gz.sig
ADDED
Binary file
|
data/CHANGES
CHANGED
@@ -1,3 +1,25 @@
|
|
1
|
+
== 1.4.0 - 17-Aug-2020
|
2
|
+
* Switched from test-unit to rspec.
|
3
|
+
|
4
|
+
== 1.3.1 - 30-Jul-2020
|
5
|
+
* Add a LICENSE file as required by the Apache-2.0 license.
|
6
|
+
|
7
|
+
== 1.3.0 - 10-Jan-2019
|
8
|
+
* Changed license to Apache-2.0.
|
9
|
+
* The VERSION constant is now frozen.
|
10
|
+
* Added metadata to the gemspec.
|
11
|
+
* Updated cert, should be good for about 10 years now.
|
12
|
+
|
13
|
+
== 1.2.1 - 4-Jan-2016
|
14
|
+
* This gem is now signed.
|
15
|
+
* The gem related tasks in the Rakefile now assume Rubygems 2.x.
|
16
|
+
* Added a net-proto.rb file for convenience.
|
17
|
+
|
18
|
+
== 1.2.0 - 3-Nov-2014
|
19
|
+
* The getprotobynumber and getprotobyname methods on MS Windows now accept
|
20
|
+
optional window and message arguments. If used, the method becomes
|
21
|
+
asynchronous and yields a block instead.
|
22
|
+
|
1
23
|
== 1.1.1 - 9-Oct-2014
|
2
24
|
* Implemented getprotoent on Windows using pure Ruby.
|
3
25
|
* Miscellaneous minor updates to the Rakefile, gemspec and docs.
|
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
|
data/MANIFEST
CHANGED
@@ -1,13 +1,16 @@
|
|
1
1
|
* CHANGES
|
2
|
+
* LICENSE
|
2
3
|
* MANIFEST
|
3
4
|
* README
|
4
5
|
* Rakefile
|
5
6
|
* doc/netproto.txt
|
6
7
|
* net-proto.gemspec
|
8
|
+
* certs/djberg96_pub.pem
|
9
|
+
* lib/net-proto.rb
|
7
10
|
* lib/net/proto.rb
|
8
11
|
* lib/net/proto/common.rb
|
9
12
|
* lib/generic/net/proto.rb
|
10
13
|
* lib/linux/net/proto.rb
|
11
14
|
* lib/sunos/net/proto.rb
|
12
15
|
* examples/example_net_proto.rb
|
13
|
-
*
|
16
|
+
* spec/net_proto_spec.rb
|
data/Rakefile
CHANGED
@@ -1,19 +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
6
|
CLEAN.include('**/*.gem', '**/*.rbx', '**/*.rbc')
|
6
7
|
|
7
8
|
namespace 'gem' do
|
8
9
|
desc 'Create the net-proto gem'
|
9
10
|
task :create => :clean do
|
11
|
+
require 'rubygems/package'
|
10
12
|
spec = eval(IO.read('net-proto.gemspec'))
|
11
|
-
|
12
|
-
|
13
|
-
else
|
14
|
-
require 'rubygems/package'
|
15
|
-
Gem::Package.build(spec)
|
16
|
-
end
|
13
|
+
spec.signing_key = File.join(Dir.home, '.ssh', 'gem-private_key.pem')
|
14
|
+
Gem::Package.build(spec, true)
|
17
15
|
end
|
18
16
|
|
19
17
|
desc 'Install the net-proto gem'
|
@@ -28,9 +26,8 @@ task :example do
|
|
28
26
|
ruby '-Ilib examples/example_net_proto.rb'
|
29
27
|
end
|
30
28
|
|
31
|
-
|
32
|
-
t.
|
33
|
-
t.verbose = true
|
29
|
+
RSpec::Core::RakeTask.new(:spec) do |t|
|
30
|
+
t.pattern = ['spec/net_proto_spec.rb']
|
34
31
|
end
|
35
32
|
|
36
|
-
task :default => :
|
33
|
+
task :default => :spec
|
@@ -0,0 +1,26 @@
|
|
1
|
+
-----BEGIN CERTIFICATE-----
|
2
|
+
MIIEcDCCAtigAwIBAgIBATANBgkqhkiG9w0BAQsFADA/MREwDwYDVQQDDAhkamJl
|
3
|
+
cmc5NjEVMBMGCgmSJomT8ixkARkWBWdtYWlsMRMwEQYKCZImiZPyLGQBGRYDY29t
|
4
|
+
MB4XDTE4MDMxODE1MjIwN1oXDTI4MDMxNTE1MjIwN1owPzERMA8GA1UEAwwIZGpi
|
5
|
+
ZXJnOTYxFTATBgoJkiaJk/IsZAEZFgVnbWFpbDETMBEGCgmSJomT8ixkARkWA2Nv
|
6
|
+
bTCCAaIwDQYJKoZIhvcNAQEBBQADggGPADCCAYoCggGBALgfaroVM6CI06cxr0/h
|
7
|
+
A+j+pc8fgpRgBVmHFaFunq28GPC3IvW7Nvc3Y8SnAW7pP1EQIbhlwRIaQzJ93/yj
|
8
|
+
u95KpkP7tA9erypnV7dpzBkzNlX14ACaFD/6pHoXoe2ltBxk3CCyyzx70mTqJpph
|
9
|
+
75IB03ni9a8yqn8pmse+s83bFJOAqddSj009sGPcQO+QOWiNxqYv1n5EHcvj2ebO
|
10
|
+
6hN7YTmhx7aSia4qL/quc4DlIaGMWoAhvML7u1fmo53CYxkKskfN8MOecq2vfEmL
|
11
|
+
iLu+SsVVEAufMDDFMXMJlvDsviolUSGMSNRTujkyCcJoXKYYxZSNtIiyd9etI0X3
|
12
|
+
ctu0uhrFyrMZXCedutvXNjUolD5r9KGBFSWH1R9u2I3n3SAyFF2yzv/7idQHLJJq
|
13
|
+
74BMnx0FIq6fCpu5slAipvxZ3ZkZpEXZFr3cIBtO1gFvQWW7E/Y3ijliWJS1GQFq
|
14
|
+
058qERadHGu1yu1dojmFRo6W2KZvY9al2yIlbkpDrD5MYQIDAQABo3cwdTAJBgNV
|
15
|
+
HRMEAjAAMAsGA1UdDwQEAwIEsDAdBgNVHQ4EFgQUFZsMapgzJimzsbaBG2Tm8j5e
|
16
|
+
AzgwHQYDVR0RBBYwFIESZGpiZXJnOTZAZ21haWwuY29tMB0GA1UdEgQWMBSBEmRq
|
17
|
+
YmVyZzk2QGdtYWlsLmNvbTANBgkqhkiG9w0BAQsFAAOCAYEAW2tnYixXQtKxgGXq
|
18
|
+
/3iSWG2bLwvxS4go3srO+aRXZHrFUMlJ5W0mCxl03aazxxKTsVVpZD8QZxvK91OQ
|
19
|
+
h9zr9JBYqCLcCVbr8SkmYCi/laxIZxsNE5YI8cC8vvlLI7AMgSfPSnn/Epq1GjGY
|
20
|
+
6L1iRcEDtanGCIvjqlCXO9+BmsnCfEVehqZkQHeYczA03tpOWb6pon2wzvMKSsKH
|
21
|
+
ks0ApVdstSLz1kzzAqem/uHdG9FyXdbTAwH1G4ZPv69sQAFAOCgAqYmdnzedsQtE
|
22
|
+
1LQfaQrx0twO+CZJPcRLEESjq8ScQxWRRkfuh2VeR7cEU7L7KqT10mtUwrvw7APf
|
23
|
+
DYoeCY9KyjIBjQXfbj2ke5u1hZj94Fsq9FfbEQg8ygCgwThnmkTrrKEiMSs3alYR
|
24
|
+
ORVCZpRuCPpmC8qmqxUnARDArzucjaclkxjLWvCVHeFa9UP7K3Nl9oTjJNv+7/jM
|
25
|
+
WZs4eecIcUc4tKdHxcAJ0MO/Dkqq7hGaiHpwKY76wQ1+8xAh
|
26
|
+
-----END CERTIFICATE-----
|
data/doc/netproto.txt
CHANGED
@@ -58,12 +58,8 @@ Proto.getprotoent{ |struct| ... }
|
|
58
58
|
None that I'm aware of. Please log any bug reports on the project page
|
59
59
|
at https://github.com/djberg96/net-proto.
|
60
60
|
|
61
|
-
== Future Plans
|
62
|
-
Use the asynchronous calls (WSAAsyncGetProtoByName and
|
63
|
-
WSAAsyncGetProtoByNumber) on MS Windows systems.
|
64
|
-
|
65
61
|
== Copyright
|
66
|
-
(C) 2003-
|
62
|
+
(C) 2003-2020 Daniel J. Berger
|
67
63
|
All rights reserved.
|
68
64
|
|
69
65
|
== Warranty
|
@@ -72,7 +68,7 @@ Proto.getprotoent{ |struct| ... }
|
|
72
68
|
warranties of merchantability and fitness for a particular purpose.
|
73
69
|
|
74
70
|
== License
|
75
|
-
|
71
|
+
Apache-2.0
|
76
72
|
|
77
73
|
== Author
|
78
74
|
Daniel J. Berger
|
data/lib/net-proto.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require_relative 'net/proto'
|
data/lib/net/proto/common.rb
CHANGED
data/lib/windows/net/proto.rb
CHANGED
@@ -15,9 +15,15 @@ module Net
|
|
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
|
20
|
+
attach_function :WSAGetLastError, [], :int
|
18
21
|
|
19
22
|
private_class_method :getprotobyname_c
|
20
23
|
private_class_method :getprotobynumber_c
|
24
|
+
private_class_method :WSAAsyncGetProtoByName
|
25
|
+
private_class_method :WSAAsyncGetProtoByNumber
|
26
|
+
private_class_method :WSAGetLastError
|
21
27
|
|
22
28
|
public
|
23
29
|
|
@@ -47,17 +53,38 @@ module Net
|
|
47
53
|
# Net::Proto.getprotobyname('tcp') # => 6
|
48
54
|
# Net::Proto.getprotobyname('bogus') # => nil
|
49
55
|
#
|
50
|
-
|
56
|
+
# On MS Windows, you may also pass a window handle and a message (int)
|
57
|
+
# that window will receive. If present, this method becomes asynchronous
|
58
|
+
# and yields a block instead, with the protocol and handle.
|
59
|
+
#
|
60
|
+
# Example:
|
61
|
+
#
|
62
|
+
# Net::Proto.getprotobyname('tcp', SOME_WINDOW, SOME_MSG){ |num, handle| ... }
|
63
|
+
#
|
64
|
+
def self.getprotobyname(protocol, hwnd = 0, msg = 0)
|
51
65
|
raise TypeError unless protocol.is_a?(String)
|
52
66
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
67
|
+
if hwnd && hwnd > 0
|
68
|
+
struct = ProtocolStruct.new
|
69
|
+
size_ptr = FFI::MemoryPointer.new(:int)
|
70
|
+
size_ptr.write_int(struct.size)
|
71
|
+
|
72
|
+
handle = WSAAsyncGetProtoByName(hwnd, msg, protocol, struct, size_ptr)
|
59
73
|
|
60
|
-
|
74
|
+
if handle == 0
|
75
|
+
raise SystemCallError.new('WSAAsyncGetProtoByName', WSAGetLastError())
|
76
|
+
end
|
77
|
+
|
78
|
+
yield struct[:p_proto], handle
|
79
|
+
else
|
80
|
+
begin
|
81
|
+
ptr = getprotobyname_c(protocol)
|
82
|
+
struct = ProtocolStruct.new(ptr) unless ptr.null?
|
83
|
+
ensure
|
84
|
+
endprotoent() if respond_to?(:endprotoent, true)
|
85
|
+
end
|
86
|
+
ptr.null? ? nil : struct[:p_proto]
|
87
|
+
end
|
61
88
|
end
|
62
89
|
|
63
90
|
# Given a protocol number, returns the corresponding string, or nil if
|
@@ -68,17 +95,39 @@ module Net
|
|
68
95
|
# Net::Proto.getprotobynumber(6) # => 'tcp'
|
69
96
|
# Net::Proto.getprotobynumber(999) # => nil
|
70
97
|
#
|
71
|
-
|
98
|
+
# On MS Windows, you may also pass a window handle and a message (int)
|
99
|
+
# that window will receive. If present, this method becomes asynchronous
|
100
|
+
# and yields a block instead, with the protocol and handle.
|
101
|
+
#
|
102
|
+
# Example:
|
103
|
+
#
|
104
|
+
# Net::Proto.getprotobynumber(6, SOME_WINDOW, SOME_MSG){ |name, handle| ... }
|
105
|
+
#
|
106
|
+
def self.getprotobynumber(protocol, hwnd = 0, msg = 0)
|
72
107
|
raise TypeError unless protocol.is_a?(Integer)
|
73
108
|
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
109
|
+
if hwnd && hwnd > 0
|
110
|
+
struct = ProtocolStruct.new
|
111
|
+
size_ptr = FFI::MemoryPointer.new(:int)
|
112
|
+
size_ptr.write_int(struct.size)
|
113
|
+
|
114
|
+
handle = WSAAsyncGetProtoByNumber(hwnd, msg, protocol, struct, size_ptr)
|
80
115
|
|
81
|
-
|
116
|
+
if handle == 0
|
117
|
+
raise SystemCallError.new('WSAAsyncGetProtoByNumber', WSAGetLastError())
|
118
|
+
end
|
119
|
+
|
120
|
+
yield struct[:p_name], handle
|
121
|
+
else
|
122
|
+
begin
|
123
|
+
ptr = getprotobynumber_c(protocol)
|
124
|
+
struct = ProtocolStruct.new(ptr) unless ptr.null?
|
125
|
+
ensure
|
126
|
+
endprotoent() if respond_to?(:endprotoent, true)
|
127
|
+
end
|
128
|
+
|
129
|
+
ptr.null? ? nil : struct[:p_name]
|
130
|
+
end
|
82
131
|
end
|
83
132
|
|
84
133
|
# In block form, yields each entry from /etc/protocol as a struct of type
|
data/net-proto.gemspec
CHANGED
@@ -1,23 +1,33 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
|
3
|
-
Gem::Specification.new do |
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
spec.name = 'net-proto'
|
5
|
+
spec.version = '1.4.0'
|
6
|
+
spec.author = 'Daniel J. Berger'
|
7
|
+
spec.license = 'Apache-2.0'
|
8
|
+
spec.email = 'djberg96@gmail.com'
|
9
|
+
spec.homepage = 'https://github.com/djberg96/net-proto'
|
10
|
+
spec.summary = 'A Ruby interface for determining protocol information'
|
11
|
+
spec.test_file = 'spec/net_proto_spec.rb'
|
12
|
+
spec.files = Dir['**/*'].reject{ |f| f.include?('git') }
|
13
|
+
spec.cert_chain = Dir['certs/*']
|
13
14
|
|
14
|
-
|
15
|
+
spec.extra_rdoc_files = ['CHANGES', 'README', 'MANIFEST', 'doc/netproto.txt']
|
15
16
|
|
16
|
-
|
17
|
-
|
18
|
-
|
17
|
+
spec.add_dependency('ffi', '~> 1.0')
|
18
|
+
spec.add_development_dependency('rspec', '~> 3.9')
|
19
|
+
spec.add_development_dependency('rake')
|
19
20
|
|
20
|
-
|
21
|
+
spec.metadata = {
|
22
|
+
'homepage_uri' => 'https://github.com/djberg96/net-proto',
|
23
|
+
'bug_tracker_uri' => 'https://github.com/djberg96/net-proto/issues',
|
24
|
+
'changelog_uri' => 'https://github.com/djberg96/net-proto/blob/ffi/CHANGES',
|
25
|
+
'documentation_uri' => 'https://github.com/djberg96/net-proto/wiki',
|
26
|
+
'source_code_uri' => 'https://github.com/djberg96/net-proto',
|
27
|
+
'wiki_uri' => 'https://github.com/djberg96/net-proto/wiki'
|
28
|
+
}
|
29
|
+
|
30
|
+
spec.description = <<-EOF
|
21
31
|
The net-proto library provides an interface for get protocol information
|
22
32
|
by name or by number. It can also iterate over the list of protocol
|
23
33
|
entries defined on your system.
|
@@ -0,0 +1,123 @@
|
|
1
|
+
###########################################################################
|
2
|
+
# net_netproto_spec.rb
|
3
|
+
#
|
4
|
+
# Test suite for net-proto 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.0')
|
23
|
+
expect(Net::Proto::VERSION.frozen?).to eq(true)
|
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,43 +1,70 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: net-proto
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel J. Berger
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
|
-
cert_chain:
|
11
|
-
|
10
|
+
cert_chain:
|
11
|
+
- |
|
12
|
+
-----BEGIN CERTIFICATE-----
|
13
|
+
MIIEcDCCAtigAwIBAgIBATANBgkqhkiG9w0BAQsFADA/MREwDwYDVQQDDAhkamJl
|
14
|
+
cmc5NjEVMBMGCgmSJomT8ixkARkWBWdtYWlsMRMwEQYKCZImiZPyLGQBGRYDY29t
|
15
|
+
MB4XDTE4MDMxODE1MjIwN1oXDTI4MDMxNTE1MjIwN1owPzERMA8GA1UEAwwIZGpi
|
16
|
+
ZXJnOTYxFTATBgoJkiaJk/IsZAEZFgVnbWFpbDETMBEGCgmSJomT8ixkARkWA2Nv
|
17
|
+
bTCCAaIwDQYJKoZIhvcNAQEBBQADggGPADCCAYoCggGBALgfaroVM6CI06cxr0/h
|
18
|
+
A+j+pc8fgpRgBVmHFaFunq28GPC3IvW7Nvc3Y8SnAW7pP1EQIbhlwRIaQzJ93/yj
|
19
|
+
u95KpkP7tA9erypnV7dpzBkzNlX14ACaFD/6pHoXoe2ltBxk3CCyyzx70mTqJpph
|
20
|
+
75IB03ni9a8yqn8pmse+s83bFJOAqddSj009sGPcQO+QOWiNxqYv1n5EHcvj2ebO
|
21
|
+
6hN7YTmhx7aSia4qL/quc4DlIaGMWoAhvML7u1fmo53CYxkKskfN8MOecq2vfEmL
|
22
|
+
iLu+SsVVEAufMDDFMXMJlvDsviolUSGMSNRTujkyCcJoXKYYxZSNtIiyd9etI0X3
|
23
|
+
ctu0uhrFyrMZXCedutvXNjUolD5r9KGBFSWH1R9u2I3n3SAyFF2yzv/7idQHLJJq
|
24
|
+
74BMnx0FIq6fCpu5slAipvxZ3ZkZpEXZFr3cIBtO1gFvQWW7E/Y3ijliWJS1GQFq
|
25
|
+
058qERadHGu1yu1dojmFRo6W2KZvY9al2yIlbkpDrD5MYQIDAQABo3cwdTAJBgNV
|
26
|
+
HRMEAjAAMAsGA1UdDwQEAwIEsDAdBgNVHQ4EFgQUFZsMapgzJimzsbaBG2Tm8j5e
|
27
|
+
AzgwHQYDVR0RBBYwFIESZGpiZXJnOTZAZ21haWwuY29tMB0GA1UdEgQWMBSBEmRq
|
28
|
+
YmVyZzk2QGdtYWlsLmNvbTANBgkqhkiG9w0BAQsFAAOCAYEAW2tnYixXQtKxgGXq
|
29
|
+
/3iSWG2bLwvxS4go3srO+aRXZHrFUMlJ5W0mCxl03aazxxKTsVVpZD8QZxvK91OQ
|
30
|
+
h9zr9JBYqCLcCVbr8SkmYCi/laxIZxsNE5YI8cC8vvlLI7AMgSfPSnn/Epq1GjGY
|
31
|
+
6L1iRcEDtanGCIvjqlCXO9+BmsnCfEVehqZkQHeYczA03tpOWb6pon2wzvMKSsKH
|
32
|
+
ks0ApVdstSLz1kzzAqem/uHdG9FyXdbTAwH1G4ZPv69sQAFAOCgAqYmdnzedsQtE
|
33
|
+
1LQfaQrx0twO+CZJPcRLEESjq8ScQxWRRkfuh2VeR7cEU7L7KqT10mtUwrvw7APf
|
34
|
+
DYoeCY9KyjIBjQXfbj2ke5u1hZj94Fsq9FfbEQg8ygCgwThnmkTrrKEiMSs3alYR
|
35
|
+
ORVCZpRuCPpmC8qmqxUnARDArzucjaclkxjLWvCVHeFa9UP7K3Nl9oTjJNv+7/jM
|
36
|
+
WZs4eecIcUc4tKdHxcAJ0MO/Dkqq7hGaiHpwKY76wQ1+8xAh
|
37
|
+
-----END CERTIFICATE-----
|
38
|
+
date:
|
12
39
|
dependencies:
|
13
40
|
- !ruby/object:Gem::Dependency
|
14
41
|
name: ffi
|
15
42
|
requirement: !ruby/object:Gem::Requirement
|
16
43
|
requirements:
|
17
|
-
- - "
|
44
|
+
- - "~>"
|
18
45
|
- !ruby/object:Gem::Version
|
19
|
-
version: 1.0
|
46
|
+
version: '1.0'
|
20
47
|
type: :runtime
|
21
48
|
prerelease: false
|
22
49
|
version_requirements: !ruby/object:Gem::Requirement
|
23
50
|
requirements:
|
24
|
-
- - "
|
51
|
+
- - "~>"
|
25
52
|
- !ruby/object:Gem::Version
|
26
|
-
version: 1.0
|
53
|
+
version: '1.0'
|
27
54
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
55
|
+
name: rspec
|
29
56
|
requirement: !ruby/object:Gem::Requirement
|
30
57
|
requirements:
|
31
|
-
- - "
|
58
|
+
- - "~>"
|
32
59
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
60
|
+
version: '3.9'
|
34
61
|
type: :development
|
35
62
|
prerelease: false
|
36
63
|
version_requirements: !ruby/object:Gem::Requirement
|
37
64
|
requirements:
|
38
|
-
- - "
|
65
|
+
- - "~>"
|
39
66
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
67
|
+
version: '3.9'
|
41
68
|
- !ruby/object:Gem::Dependency
|
42
69
|
name: rake
|
43
70
|
requirement: !ruby/object:Gem::Requirement
|
@@ -65,24 +92,48 @@ extra_rdoc_files:
|
|
65
92
|
- MANIFEST
|
66
93
|
- doc/netproto.txt
|
67
94
|
files:
|
95
|
+
- LICENSE
|
68
96
|
- CHANGES
|
69
97
|
- MANIFEST
|
98
|
+
- spec
|
99
|
+
- spec/net_proto_spec.rb
|
70
100
|
- README
|
71
101
|
- Rakefile
|
72
|
-
-
|
102
|
+
- certs
|
103
|
+
- certs/djberg96_pub.pem
|
104
|
+
- examples
|
73
105
|
- examples/example_net_proto.rb
|
74
|
-
- lib
|
75
|
-
- lib/
|
106
|
+
- lib
|
107
|
+
- lib/net
|
76
108
|
- lib/net/proto.rb
|
109
|
+
- lib/net/proto
|
77
110
|
- lib/net/proto/common.rb
|
111
|
+
- lib/sunos
|
112
|
+
- lib/sunos/net
|
78
113
|
- lib/sunos/net/proto.rb
|
114
|
+
- lib/net-proto.rb
|
115
|
+
- lib/linux
|
116
|
+
- lib/linux/net
|
117
|
+
- lib/linux/net/proto.rb
|
118
|
+
- lib/generic
|
119
|
+
- lib/generic/net
|
120
|
+
- lib/generic/net/proto.rb
|
121
|
+
- lib/windows
|
122
|
+
- lib/windows/net
|
79
123
|
- lib/windows/net/proto.rb
|
124
|
+
- doc
|
125
|
+
- doc/netproto.txt
|
80
126
|
- net-proto.gemspec
|
81
|
-
- test/test_net_proto.rb
|
82
127
|
homepage: https://github.com/djberg96/net-proto
|
83
128
|
licenses:
|
84
|
-
-
|
85
|
-
metadata:
|
129
|
+
- Apache-2.0
|
130
|
+
metadata:
|
131
|
+
homepage_uri: https://github.com/djberg96/net-proto
|
132
|
+
bug_tracker_uri: https://github.com/djberg96/net-proto/issues
|
133
|
+
changelog_uri: https://github.com/djberg96/net-proto/blob/ffi/CHANGES
|
134
|
+
documentation_uri: https://github.com/djberg96/net-proto/wiki
|
135
|
+
source_code_uri: https://github.com/djberg96/net-proto
|
136
|
+
wiki_uri: https://github.com/djberg96/net-proto/wiki
|
86
137
|
post_install_message:
|
87
138
|
rdoc_options: []
|
88
139
|
require_paths:
|
@@ -98,10 +149,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
98
149
|
- !ruby/object:Gem::Version
|
99
150
|
version: '0'
|
100
151
|
requirements: []
|
101
|
-
|
102
|
-
rubygems_version: 2.4.1
|
152
|
+
rubygems_version: 3.1.4
|
103
153
|
signing_key:
|
104
154
|
specification_version: 4
|
105
155
|
summary: A Ruby interface for determining protocol information
|
106
156
|
test_files:
|
107
|
-
-
|
157
|
+
- spec/net_proto_spec.rb
|
metadata.gz.sig
ADDED
Binary file
|
data/test/test_net_proto.rb
DELETED
@@ -1,135 +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.1.1', Net::Proto::VERSION)
|
28
|
-
end
|
29
|
-
|
30
|
-
test "get_protocol method basic functionality" do
|
31
|
-
assert_respond_to(Net::Proto, :get_protocol)
|
32
|
-
end
|
33
|
-
|
34
|
-
test "get_protocol method accepts a string or a number" do
|
35
|
-
assert_nothing_raised{ Net::Proto.get_protocol(1) }
|
36
|
-
assert_nothing_raised{ Net::Proto.get_protocol('tcp') }
|
37
|
-
end
|
38
|
-
|
39
|
-
test "get_protocol returns nil if protocol not found" do
|
40
|
-
assert_nil(Net::Proto.get_protocol(9999999))
|
41
|
-
end
|
42
|
-
|
43
|
-
test "get_protocol fails if an invalid type is passed" do
|
44
|
-
assert_raise(TypeError){ Net::Proto.get_protocol([]) }
|
45
|
-
end
|
46
|
-
|
47
|
-
test "getprotobynumber basic functionality" do
|
48
|
-
assert_respond_to(Net::Proto, :getprotobynumber)
|
49
|
-
assert_nothing_raised{ 0.upto(132){ |n| Net::Proto.getprotobynumber(n) } }
|
50
|
-
assert_kind_of(String, Net::Proto.getprotobynumber(1))
|
51
|
-
end
|
52
|
-
|
53
|
-
test "getprotobynumber returns the expected result" do
|
54
|
-
assert_equal('icmp', Net::Proto.getprotobynumber(1))
|
55
|
-
assert_equal('tcp', Net::Proto.getprotobynumber(6))
|
56
|
-
end
|
57
|
-
|
58
|
-
test "getprotobynumber returns nil if not found" do
|
59
|
-
assert_equal(nil, Net::Proto.getprotobynumber(9999999))
|
60
|
-
assert_equal(nil, Net::Proto.getprotobynumber(-1))
|
61
|
-
end
|
62
|
-
|
63
|
-
test "getprotobynumber raises a TypeError if a non-numeric arg is used" do
|
64
|
-
assert_raise(TypeError){ Net::Proto.getprotobynumber('foo') }
|
65
|
-
assert_raise(TypeError){ Net::Proto.getprotobynumber(nil) }
|
66
|
-
end
|
67
|
-
|
68
|
-
test "getprotobyname method basic functionality" do
|
69
|
-
assert_respond_to(Net::Proto, :getprotobyname)
|
70
|
-
@@protocols.each{ |n| assert_nothing_raised{ Net::Proto.getprotobyname(n) } }
|
71
|
-
end
|
72
|
-
|
73
|
-
test "getprotobyname returns the expected result" do
|
74
|
-
assert_equal(1, Net::Proto.getprotobyname('icmp'))
|
75
|
-
assert_equal(6, Net::Proto.getprotobyname('tcp'))
|
76
|
-
end
|
77
|
-
|
78
|
-
test "getprotobyname returns nil if the protocol is not found" do
|
79
|
-
assert_nil(Net::Proto.getprotobyname('foo'))
|
80
|
-
assert_nil(Net::Proto.getprotobyname('tcpx'))
|
81
|
-
assert_nil(Net::Proto.getprotobyname(''))
|
82
|
-
end
|
83
|
-
|
84
|
-
test "getprotobyname raises a TypeError if an invalid arg is passed" do
|
85
|
-
assert_raises(TypeError){ Net::Proto.getprotobyname(1) }
|
86
|
-
assert_raises(TypeError){ Net::Proto.getprotobyname(nil) }
|
87
|
-
end
|
88
|
-
|
89
|
-
test "getprotoent basic functionality" do
|
90
|
-
assert_respond_to(Net::Proto, :getprotoent)
|
91
|
-
assert_nothing_raised{ Net::Proto.getprotoent }
|
92
|
-
assert_kind_of(Array, Net::Proto.getprotoent)
|
93
|
-
end
|
94
|
-
|
95
|
-
test "getprotoent method returns the expected results" do
|
96
|
-
assert_kind_of(Struct::ProtoStruct, Net::Proto.getprotoent.first)
|
97
|
-
assert_nil(Net::Proto.getprotoent{})
|
98
|
-
end
|
99
|
-
|
100
|
-
test "struct returned by getprotoent method contains the expected data" do
|
101
|
-
@protoent = Net::Proto.getprotoent.first
|
102
|
-
assert_equal([:name, :aliases, :proto], @protoent.members)
|
103
|
-
assert_kind_of(String, @protoent.name)
|
104
|
-
assert_kind_of(Array, @protoent.aliases)
|
105
|
-
assert_kind_of(Integer, @protoent.proto)
|
106
|
-
end
|
107
|
-
|
108
|
-
test "all members of the aliases struct member are strings" do
|
109
|
-
@protoent = Net::Proto.getprotoent.first
|
110
|
-
assert_true(@protoent.aliases.all?{ |e| e.is_a?(String) })
|
111
|
-
end
|
112
|
-
|
113
|
-
test "struct returned by getprotoent method is frozen" do
|
114
|
-
@protoent = Net::Proto.getprotoent.first
|
115
|
-
assert_true(@protoent.frozen?)
|
116
|
-
end
|
117
|
-
|
118
|
-
test "there is no constructor" do
|
119
|
-
assert_raise(NoMethodError){ Net::Proto.new }
|
120
|
-
end
|
121
|
-
|
122
|
-
test "ffi functions are private" do
|
123
|
-
methods = Net::Proto.methods(false).map{ |m| m.to_sym }
|
124
|
-
assert_false(methods.include?(:setprotoent))
|
125
|
-
assert_false(methods.include?(:endprotoent))
|
126
|
-
end
|
127
|
-
|
128
|
-
def teardown
|
129
|
-
@protoent = nil
|
130
|
-
end
|
131
|
-
|
132
|
-
def self.shutdown
|
133
|
-
@@protocols = nil
|
134
|
-
end
|
135
|
-
end
|