net-proto 1.1.0 → 1.3.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 43aeb8ae73964b0d03c6897ecf87b6e41cc1b5728976c9d40765d0965ce3038b
4
+ data.tar.gz: b819851e28b890bb5545017e6da3706eec374116f94a0b9abf90334cd94c1562
5
+ SHA512:
6
+ metadata.gz: 6120909386e31c152f93c7905549a7b10332f731f9d99677d1908c96322c6f864002aab62e4f89e02f00d0a5a556d0949dfe30b1fb708d28c4b752cd7db50724
7
+ data.tar.gz: 5b77d5ea65999cb40b588d1f1a0f0d59de71d18db4baf5379523fb419affe8ddecec332928a83ee17b89ba207a0bc9f8f4a5d94616fa0cffa2efbd3377214b38
Binary file
Binary file
data/CHANGES CHANGED
@@ -1,3 +1,26 @@
1
+ == 1.3.1 - 30-Jul-2020
2
+ * Add a LICENSE file as required by the Apache-2.0 license.
3
+
4
+ == 1.3.0 - 10-Jan-2019
5
+ * Changed license to Apache-2.0.
6
+ * The VERSION constant is now frozen.
7
+ * Added metadata to the gemspec.
8
+ * Updated cert, should be good for about 10 years now.
9
+
10
+ == 1.2.1 - 4-Jan-2016
11
+ * This gem is now signed.
12
+ * The gem related tasks in the Rakefile now assume Rubygems 2.x.
13
+ * Added a net-proto.rb file for convenience.
14
+
15
+ == 1.2.0 - 3-Nov-2014
16
+ * The getprotobynumber and getprotobyname methods on MS Windows now accept
17
+ optional window and message arguments. If used, the method becomes
18
+ asynchronous and yields a block instead.
19
+
20
+ == 1.1.1 - 9-Oct-2014
21
+ * Implemented getprotoent on Windows using pure Ruby.
22
+ * Miscellaneous minor updates to the Rakefile, gemspec and docs.
23
+
1
24
  == 1.1.0 - 18-Jan-2012
2
25
  * Switched to FFI instead of C backend. Now works with JRuby, too.
3
26
  * Added the generic get_protocol instance method that accepts either a
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,9 +1,12 @@
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
data/README CHANGED
@@ -26,10 +26,6 @@ Net::Proto.getprotoent do |ent|
26
26
  p ent
27
27
  end
28
28
 
29
- == MS Windows
30
- The Proto.getprotoent method is not supported on MS Windows because the
31
- underlying function isn't supported by the MS Windows API.
32
-
33
29
  == Why should I use this?
34
30
  Ruby has a predefined set of constants in socket.c in the general form of
35
31
  IPPROTO_XXX, Y. However, using constants in this fashion can be unreliable
data/Rakefile CHANGED
@@ -7,14 +7,16 @@ CLEAN.include('**/*.gem', '**/*.rbx', '**/*.rbc')
7
7
  namespace 'gem' do
8
8
  desc 'Create the net-proto gem'
9
9
  task :create => :clean do
10
+ require 'rubygems/package'
10
11
  spec = eval(IO.read('net-proto.gemspec'))
11
- Gem::Builder.new(spec).build
12
+ spec.signing_key = File.join(Dir.home, '.ssh', 'gem-private_key.pem')
13
+ Gem::Package.build(spec, true)
12
14
  end
13
15
 
14
16
  desc 'Install the net-proto gem'
15
17
  task :install => [:create] do
16
18
  file = Dir["net-proto*.gem"].last
17
- sh "gem install #{file}"
19
+ sh "gem install -l #{file}"
18
20
  end
19
21
  end
20
22
 
@@ -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-----
@@ -39,8 +39,6 @@ Proto.getprotoent{ |struct| ... }
39
39
 
40
40
  The fields are 'name' (a String), 'aliases' (an Array of String's,
41
41
  though often only one element), and 'proto' (a Fixnum).
42
-
43
- This method is NOT supported on MS Windows.
44
42
 
45
43
  == Notes
46
44
  This module uses the reentrant (i.e. thread safe) functions on those
@@ -52,19 +50,16 @@ Proto.getprotoent{ |struct| ... }
52
50
  separate method calls. Rather, these are called internally by the various
53
51
  methods, except on Windows, which does not support them.
54
52
 
55
- The 'getprotoent()' method is not supported on the MS Windows platform.
56
- It's not part of the API as of Windows XP.
53
+ The 'getprotoent()' method on Windows is using Ruby to read directly from
54
+ your %SystemRoot%\system32\drivers\etc\protocol file. If you do not have
55
+ read access to that file, the method will fail.
57
56
 
58
57
  == Known Bugs
59
- None that I'm aware of. Please log any bug reports on the project page
58
+ None that I'm aware of. Please log any bug reports on the project page
60
59
  at https://github.com/djberg96/net-proto.
61
60
 
62
- == Future Plans
63
- Use the asynchronous calls (WSAAsyncGetProtoByName and
64
- WSAAsyncGetProtoByNumber) on MS Windows systems.
65
-
66
61
  == Copyright
67
- (C) 2003-2012 Daniel J. Berger
62
+ (C) 2003-2020 Daniel J. Berger
68
63
  All rights reserved.
69
64
 
70
65
  == Warranty
@@ -73,7 +68,7 @@ Proto.getprotoent{ |struct| ... }
73
68
  warranties of merchantability and fitness for a particular purpose.
74
69
 
75
70
  == License
76
- Artistic 2.0
71
+ Apache-2.0
77
72
 
78
73
  == Author
79
74
  Daniel J. Berger
@@ -0,0 +1 @@
1
+ require_relative 'net/proto'
@@ -1,10 +1,12 @@
1
1
  require 'rbconfig'
2
2
 
3
3
  case RbConfig::CONFIG['host_os']
4
- when /linux/i
5
- require 'linux/net/proto'
6
- when /sunos|solaris/i
7
- require 'sunos/net/proto'
8
- else
9
- require 'generic/net/proto'
4
+ when /linux/i
5
+ require 'linux/net/proto'
6
+ when /sunos|solaris/i
7
+ require 'sunos/net/proto'
8
+ when /mingw|cygwin|win32|windows|mswin/i
9
+ require 'windows/net/proto'
10
+ else
11
+ require 'generic/net/proto'
10
12
  end
@@ -5,7 +5,7 @@ module Net
5
5
  extend FFI::Library
6
6
 
7
7
  # The version of the net-proto library
8
- VERSION = '1.1.0'
8
+ VERSION = '1.3.1'.freeze
9
9
 
10
10
  private_class_method :new
11
11
 
@@ -0,0 +1,172 @@
1
+ require 'net/proto/common'
2
+
3
+ # The Net module serves as a namespace only.
4
+ module Net
5
+ # The Proto class serves as the base class for the various protocol methods.
6
+ class Proto
7
+ extend FFI::Library
8
+
9
+ ffi_lib FFI::Library::LIBC
10
+ ffi_lib 'ws2_32'
11
+ ffi_convention :stdcall
12
+
13
+ private
14
+
15
+ # These should exist on every platform.
16
+ attach_function :getprotobyname_c, :getprotobyname, [:string], :pointer
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
21
+
22
+ private_class_method :getprotobyname_c
23
+ private_class_method :getprotobynumber_c
24
+ private_class_method :WSAAsyncGetProtoByName
25
+ private_class_method :WSAAsyncGetProtoByNumber
26
+ private_class_method :WSAGetLastError
27
+
28
+ public
29
+
30
+ # If given a protocol string, returns the corresponding number. If
31
+ # given a protocol number, returns the corresponding string.
32
+ #
33
+ # Returns nil if not found in either case.
34
+ #
35
+ # Examples:
36
+ #
37
+ # Net::Proto.get_protocol('tcp') # => 6
38
+ # Net::Proto.get_protocol(1) # => 'icmp'
39
+ #
40
+ def self.get_protocol(arg)
41
+ if arg.is_a?(String)
42
+ getprotobyname(arg)
43
+ else
44
+ getprotobynumber(arg)
45
+ end
46
+ end
47
+
48
+ # Given a protocol string, returns the corresponding number, or nil if
49
+ # not found.
50
+ #
51
+ # Examples:
52
+ #
53
+ # Net::Proto.getprotobyname('tcp') # => 6
54
+ # Net::Proto.getprotobyname('bogus') # => nil
55
+ #
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)
65
+ raise TypeError unless protocol.is_a?(String)
66
+
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)
73
+
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
88
+ end
89
+
90
+ # Given a protocol number, returns the corresponding string, or nil if
91
+ # not found.
92
+ #
93
+ # Examples:
94
+ #
95
+ # Net::Proto.getprotobynumber(6) # => 'tcp'
96
+ # Net::Proto.getprotobynumber(999) # => nil
97
+ #
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)
107
+ raise TypeError unless protocol.is_a?(Integer)
108
+
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)
115
+
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
131
+ end
132
+
133
+ # In block form, yields each entry from /etc/protocol as a struct of type
134
+ # Proto::ProtoStruct. In non-block form, returns an array of structs.
135
+ #
136
+ # The fields are 'name' (a string), 'aliases' (an array of strings,
137
+ # though often only one element), and 'proto' (a number).
138
+ #
139
+ # Example:
140
+ #
141
+ # Net::Proto.getprotoent.each{ |prot|
142
+ # p prot.name
143
+ # p prot.aliases
144
+ # p prot.proto
145
+ # }
146
+ #
147
+ # Note that on Windows this code reads directly out of a %SystemRoot%
148
+ # subfolder using pure Ruby, so you will need read access or this method
149
+ # will fail.
150
+ #
151
+ def self.getprotoent
152
+ structs = block_given? ? nil : []
153
+ file = ENV['SystemRoot'] + '/system32/drivers/etc/protocol'
154
+
155
+ IO.foreach(file) do |line|
156
+ next if line.lstrip[0] == '#' # Skip comments
157
+ next if line.lstrip.size == 0 # Skip blank lines
158
+ line = line.split
159
+
160
+ ruby_struct = ProtoStruct.new(line[0], line[2].split(','), line[1].to_i).freeze
161
+
162
+ if block_given?
163
+ yield ruby_struct
164
+ else
165
+ structs << ruby_struct
166
+ end
167
+ end
168
+
169
+ structs
170
+ end
171
+ end
172
+ end
@@ -1,24 +1,33 @@
1
1
  require 'rubygems'
2
2
 
3
- Gem::Specification.new do |gem|
4
- gem.name = 'net-proto'
5
- gem.version = '1.1.0'
6
- gem.author = 'Daniel J. Berger'
7
- gem.license = 'Artistic 2.0'
8
- gem.email = 'djberg96@gmail.com'
9
- gem.homepage = 'http://www.rubyforge.org/projects/sysutils'
10
- gem.platform = Gem::Platform::RUBY
11
- gem.summary = 'A Ruby interface for determining protocol information'
12
- gem.test_file = 'test/test_net_proto.rb'
13
- gem.files = Dir['**/*'].reject{ |f| f.include?('git') }
3
+ Gem::Specification.new do |spec|
4
+ spec.name = 'net-proto'
5
+ spec.version = '1.3.1'
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 = 'test/test_net_proto.rb'
12
+ spec.files = Dir['**/*'].reject{ |f| f.include?('git') }
13
+ spec.cert_chain = Dir['certs/*']
14
14
 
15
- gem.rubyforge_project = 'sysutils'
16
- gem.extra_rdoc_files = ['CHANGES', 'README', 'MANIFEST', 'doc/netproto.txt']
15
+ spec.extra_rdoc_files = ['CHANGES', 'README', 'MANIFEST', 'doc/netproto.txt']
17
16
 
18
- gem.add_dependency('ffi', '>= 1.0.0')
19
- gem.add_development_dependency('test-unit', '>= 2.2.0')
17
+ spec.add_dependency('ffi', '>= 1.0')
18
+ spec.add_development_dependency('test-unit', '>= 2.2')
19
+ spec.add_development_dependency('rake')
20
20
 
21
- gem.description = <<-EOF
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
22
31
  The net-proto library provides an interface for get protocol information
23
32
  by name or by number. It can also iterate over the list of protocol
24
33
  entries defined on your system.
@@ -4,10 +4,8 @@
4
4
  # Test suite for net-proto - all platforms. This test suite should be run
5
5
  # via the 'rake test' task.
6
6
  ###########################################################################
7
- require 'rubygems'
8
- gem 'test-unit'
9
7
  require 'net/proto'
10
- require 'test/unit'
8
+ require 'test-unit'
11
9
 
12
10
  class TC_Net_Proto < Test::Unit::TestCase
13
11
 
@@ -19,8 +17,6 @@ class TC_Net_Proto < Test::Unit::TestCase
19
17
  mobile ospf pim ipcomp vrrp sctp hopopt ipv6
20
18
  ipv6-route ipv6-frag esp ah ipv6-icmp ipv6-nonxt ipv6-opts
21
19
  /
22
-
23
- @@windows = File::ALT_SEPARATOR
24
20
  end
25
21
 
26
22
  def setup
@@ -28,7 +24,8 @@ class TC_Net_Proto < Test::Unit::TestCase
28
24
  end
29
25
 
30
26
  test "version number is set to expected value" do
31
- assert_equal('1.1.0', Net::Proto::VERSION)
27
+ assert_equal('1.3.1', Net::Proto::VERSION)
28
+ assert_true(Net::Proto::VERSION.frozen?)
32
29
  end
33
30
 
34
31
  test "get_protocol method basic functionality" do
@@ -91,35 +88,30 @@ class TC_Net_Proto < Test::Unit::TestCase
91
88
  end
92
89
 
93
90
  test "getprotoent basic functionality" do
94
- omit_if(@@windows, 'getprotoent tests skipped on MS Windows')
95
91
  assert_respond_to(Net::Proto, :getprotoent)
96
92
  assert_nothing_raised{ Net::Proto.getprotoent }
97
93
  assert_kind_of(Array, Net::Proto.getprotoent)
98
94
  end
99
95
 
100
96
  test "getprotoent method returns the expected results" do
101
- omit_if(@@windows, 'getprotoent tests skipped on MS Windows')
102
97
  assert_kind_of(Struct::ProtoStruct, Net::Proto.getprotoent.first)
103
98
  assert_nil(Net::Proto.getprotoent{})
104
99
  end
105
100
 
106
101
  test "struct returned by getprotoent method contains the expected data" do
107
- omit_if(@@windows, 'getprotoent tests skipped on MS Windows')
108
102
  @protoent = Net::Proto.getprotoent.first
109
- assert_equal(['name', 'aliases', 'proto'], @protoent.members)
103
+ assert_equal([:name, :aliases, :proto], @protoent.members)
110
104
  assert_kind_of(String, @protoent.name)
111
105
  assert_kind_of(Array, @protoent.aliases)
112
106
  assert_kind_of(Integer, @protoent.proto)
113
107
  end
114
108
 
115
109
  test "all members of the aliases struct member are strings" do
116
- omit_if(@@windows, 'getprotoent tests on MS Windows')
117
110
  @protoent = Net::Proto.getprotoent.first
118
111
  assert_true(@protoent.aliases.all?{ |e| e.is_a?(String) })
119
112
  end
120
113
 
121
114
  test "struct returned by getprotoent method is frozen" do
122
- omit_if(@@windows, 'getprotoent tests skipped on MS Windows')
123
115
  @protoent = Net::Proto.getprotoent.first
124
116
  assert_true(@protoent.frozen?)
125
117
  end
metadata CHANGED
@@ -1,111 +1,157 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: net-proto
3
- version: !ruby/object:Gem::Version
4
- hash: 19
5
- prerelease:
6
- segments:
7
- - 1
8
- - 1
9
- - 0
10
- version: 1.1.0
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.3.1
11
5
  platform: ruby
12
- authors:
6
+ authors:
13
7
  - Daniel J. Berger
14
8
  autorequire:
15
9
  bindir: bin
16
- cert_chain: []
17
-
18
- date: 2012-01-18 00:00:00 Z
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
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:
39
+ dependencies:
40
+ - !ruby/object:Gem::Dependency
21
41
  name: ffi
22
- prerelease: false
23
- requirement: &id001 !ruby/object:Gem::Requirement
24
- none: false
25
- requirements:
42
+ requirement: !ruby/object:Gem::Requirement
43
+ requirements:
26
44
  - - ">="
27
- - !ruby/object:Gem::Version
28
- hash: 23
29
- segments:
30
- - 1
31
- - 0
32
- - 0
33
- version: 1.0.0
45
+ - !ruby/object:Gem::Version
46
+ version: '1.0'
34
47
  type: :runtime
35
- version_requirements: *id001
36
- - !ruby/object:Gem::Dependency
48
+ prerelease: false
49
+ version_requirements: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '1.0'
54
+ - !ruby/object:Gem::Dependency
37
55
  name: test-unit
56
+ requirement: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: '2.2'
61
+ type: :development
38
62
  prerelease: false
39
- requirement: &id002 !ruby/object:Gem::Requirement
40
- none: false
41
- requirements:
63
+ version_requirements: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: '2.2'
68
+ - !ruby/object:Gem::Dependency
69
+ name: rake
70
+ requirement: !ruby/object:Gem::Requirement
71
+ requirements:
42
72
  - - ">="
43
- - !ruby/object:Gem::Version
44
- hash: 7
45
- segments:
46
- - 2
47
- - 2
48
- - 0
49
- version: 2.2.0
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
50
75
  type: :development
51
- version_requirements: *id002
52
- 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"
76
+ prerelease: false
77
+ version_requirements: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ description: |2
83
+ The net-proto library provides an interface for get protocol information
84
+ by name or by number. It can also iterate over the list of protocol
85
+ entries defined on your system.
53
86
  email: djberg96@gmail.com
54
87
  executables: []
55
-
56
88
  extensions: []
57
-
58
- extra_rdoc_files:
89
+ extra_rdoc_files:
59
90
  - CHANGES
60
91
  - README
61
92
  - MANIFEST
62
93
  - doc/netproto.txt
63
- files:
94
+ files:
95
+ - LICENSE
96
+ - test
97
+ - test/test_net_proto.rb
64
98
  - CHANGES
65
- - doc/netproto.txt
99
+ - MANIFEST
100
+ - README
101
+ - Rakefile
102
+ - certs
103
+ - certs/djberg96_pub.pem
104
+ - examples
66
105
  - examples/example_net_proto.rb
67
- - lib/generic/net/proto.rb
68
- - lib/linux/net/proto.rb
69
- - lib/net/proto/common.rb
106
+ - lib
107
+ - lib/net
70
108
  - lib/net/proto.rb
109
+ - lib/net/proto
110
+ - lib/net/proto/common.rb
111
+ - lib/sunos
112
+ - lib/sunos/net
71
113
  - lib/sunos/net/proto.rb
72
- - MANIFEST
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
123
+ - lib/windows/net/proto.rb
124
+ - doc
125
+ - doc/netproto.txt
73
126
  - net-proto.gemspec
74
- - Rakefile
75
- - README
76
- - test/test_net_proto.rb
77
- homepage: http://www.rubyforge.org/projects/sysutils
78
- licenses:
79
- - Artistic 2.0
127
+ homepage: https://github.com/djberg96/net-proto
128
+ licenses:
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
80
137
  post_install_message:
81
138
  rdoc_options: []
82
-
83
- require_paths:
139
+ require_paths:
84
140
  - lib
85
- required_ruby_version: !ruby/object:Gem::Requirement
86
- none: false
87
- requirements:
141
+ required_ruby_version: !ruby/object:Gem::Requirement
142
+ requirements:
88
143
  - - ">="
89
- - !ruby/object:Gem::Version
90
- hash: 3
91
- segments:
92
- - 0
93
- version: "0"
94
- required_rubygems_version: !ruby/object:Gem::Requirement
95
- none: false
96
- requirements:
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ required_rubygems_version: !ruby/object:Gem::Requirement
147
+ requirements:
97
148
  - - ">="
98
- - !ruby/object:Gem::Version
99
- hash: 3
100
- segments:
101
- - 0
102
- version: "0"
149
+ - !ruby/object:Gem::Version
150
+ version: '0'
103
151
  requirements: []
104
-
105
- rubyforge_project: sysutils
106
- rubygems_version: 1.8.10
152
+ rubygems_version: 3.0.3
107
153
  signing_key:
108
- specification_version: 3
154
+ specification_version: 4
109
155
  summary: A Ruby interface for determining protocol information
110
- test_files:
156
+ test_files:
111
157
  - test/test_net_proto.rb
Binary file