net-proto 1.1.1 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGES +5 -0
- data/doc/netproto.txt +0 -4
- data/lib/net/proto/common.rb +1 -1
- data/lib/windows/net/proto.rb +65 -16
- data/net-proto.gemspec +1 -1
- data/test/test_net_proto.rb +1 -1
- metadata +11 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9ad82469ee27db26ef64fc237b2f0997c128e491
|
4
|
+
data.tar.gz: b75d18a5640061415124e0db9a4c9d984a09e1af
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bc8b339c75aa05037c264351888309c7d65392f3db57cdaf89cab05ca46584a8747501e905b999e0fb0f2aa30b7a6f1fb12bbea84d0baaddf8c2995e694c58bd
|
7
|
+
data.tar.gz: b056f5cb415e6cbf756c5e9e4e36f77f29bf66844e493f243ace79ee5f1ce662a35a9924963f62c30c1f386ae29aa58f78a99275fa5204a3739e1a25d2906a1e
|
data/CHANGES
CHANGED
@@ -1,3 +1,8 @@
|
|
1
|
+
== 1.2.0 - 3-Nov-2014
|
2
|
+
* The getprotobynumber and getprotobyname methods on MS Windows now accept
|
3
|
+
optional window and message arguments. If used, the method becomes
|
4
|
+
asynchronous and yields a block instead.
|
5
|
+
|
1
6
|
== 1.1.1 - 9-Oct-2014
|
2
7
|
* Implemented getprotoent on Windows using pure Ruby.
|
3
8
|
* Miscellaneous minor updates to the Rakefile, gemspec and docs.
|
data/doc/netproto.txt
CHANGED
@@ -58,10 +58,6 @@ 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
62
|
(C) 2003-2014 Daniel J. Berger
|
67
63
|
All rights reserved.
|
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
data/test/test_net_proto.rb
CHANGED
metadata
CHANGED
@@ -1,55 +1,55 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: net-proto
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel J. Berger
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-11-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ffi
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - '>='
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: 1.0.0
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - '>='
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: 1.0.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: test-unit
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - '>='
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: 2.2.0
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - '>='
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: 2.2.0
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rake
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - '>='
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - '>='
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
55
|
description: |2
|
@@ -89,17 +89,17 @@ require_paths:
|
|
89
89
|
- lib
|
90
90
|
required_ruby_version: !ruby/object:Gem::Requirement
|
91
91
|
requirements:
|
92
|
-
- -
|
92
|
+
- - '>='
|
93
93
|
- !ruby/object:Gem::Version
|
94
94
|
version: '0'
|
95
95
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
96
96
|
requirements:
|
97
|
-
- -
|
97
|
+
- - '>='
|
98
98
|
- !ruby/object:Gem::Version
|
99
99
|
version: '0'
|
100
100
|
requirements: []
|
101
101
|
rubyforge_project:
|
102
|
-
rubygems_version: 2.4.
|
102
|
+
rubygems_version: 2.4.2
|
103
103
|
signing_key:
|
104
104
|
specification_version: 4
|
105
105
|
summary: A Ruby interface for determining protocol information
|