rex-socket 0.1.68 → 0.1.69
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/lib/rex/socket/udp.rb +46 -23
- data/lib/rex/socket/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 06a8d5b9b8dff6b4e9ef66dbccf00522bacff3f3e7e7b011f13a3548cd595f6d
|
|
4
|
+
data.tar.gz: 3fb1e4a3d8a356468b9ff998d7001eacd001ff825d97bf7ffae41b88489d2be3
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: d75a50f35c0853ad85026916638d1cea6724d4fbdf52f704bc396872ee85228c0f1db096b443ad52bc1631fb52e220e6ef44c024352e958df50b554043a68930
|
|
7
|
+
data.tar.gz: cd78a56eec5f4b4e780cf496eca88452057786065d300a0db2cb7eba00fa962d94c9c0e0227e73cb78a3931f018ae58259546e874b945cd154829f397d635320
|
data/lib/rex/socket/udp.rb
CHANGED
|
@@ -135,37 +135,60 @@ module Rex::Socket::Udp
|
|
|
135
135
|
end
|
|
136
136
|
|
|
137
137
|
#
|
|
138
|
-
# Receives a datagram and returns the data and
|
|
139
|
-
#
|
|
138
|
+
# Receives a datagram and returns the data and sender address information as
|
|
139
|
+
# [ data, [address_family, port, host, host] ], matching stdlib
|
|
140
|
+
# UDPSocket#recvfrom. Like the stdlib method, this blocks until a datagram is
|
|
141
|
+
# available and has no timeout of its own (see #timed_recvfrom for a variant
|
|
142
|
+
# that does). The host appears in both the hostname and numeric address
|
|
143
|
+
# positions; no reverse-DNS lookup is performed.
|
|
144
|
+
#
|
|
145
|
+
# @param maxlen [Integer] maximum number of bytes to receive
|
|
146
|
+
# @param flags [Integer] flags passed to the underlying recvfrom(2) call (default: 0)
|
|
147
|
+
# @return [Array(String, Array)] the datagram and the sender address information
|
|
148
|
+
#
|
|
149
|
+
def recvfrom(maxlen, flags = 0)
|
|
150
|
+
# Block until the socket is readable to mirror the stdlib's blocking
|
|
151
|
+
# UDPSocket#recvfrom; a nil timeout waits indefinitely.
|
|
152
|
+
::IO.select([ fd ], nil, nil, nil)
|
|
153
|
+
data, saddr = recvfrom_nonblock(maxlen, flags)
|
|
154
|
+
[ data, sender_addr_info(saddr) ]
|
|
155
|
+
end
|
|
156
|
+
|
|
157
|
+
#
|
|
158
|
+
# Receives a datagram like #recvfrom but waits at most +timeout+ seconds for
|
|
159
|
+
# one to arrive, returning nil if the timeout elapses first. The return value
|
|
160
|
+
# otherwise matches #recvfrom: [ data, [address_family, port, host, host] ].
|
|
161
|
+
#
|
|
162
|
+
# @param maxlen [Integer] maximum number of bytes to receive
|
|
163
|
+
# @param timeout [Numeric] seconds to wait for a datagram before giving up
|
|
164
|
+
# @return [Array(String, Array), nil] the datagram and sender address
|
|
165
|
+
# information, or nil if no datagram arrived within +timeout+ seconds
|
|
140
166
|
#
|
|
141
|
-
def
|
|
167
|
+
def timed_recvfrom(maxlen = 65535, timeout = def_read_timeout)
|
|
168
|
+
return nil unless ::IO.select([ fd ], nil, nil, timeout)
|
|
142
169
|
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
af, host, port = Rex::Socket.from_sockaddr(saddr)
|
|
170
|
+
data, saddr = recvfrom_nonblock(maxlen)
|
|
171
|
+
[ data, sender_addr_info(saddr) ]
|
|
172
|
+
rescue ::Timeout::Error, ::Errno::ECONNREFUSED
|
|
173
|
+
nil
|
|
174
|
+
end
|
|
149
175
|
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
rescue ::Exception
|
|
159
|
-
return [ '', nil, nil ]
|
|
160
|
-
end
|
|
176
|
+
#
|
|
177
|
+
# Converts a packed sockaddr into the stdlib UDPSocket#recvfrom-style sender
|
|
178
|
+
# address tuple [ address_family, port, host, host ].
|
|
179
|
+
#
|
|
180
|
+
def sender_addr_info(saddr)
|
|
181
|
+
af, host, port = Rex::Socket.from_sockaddr(saddr)
|
|
182
|
+
af_name = ::Socket.constants.grep(/^AF_/).find { |c| ::Socket.const_get(c) == af }.to_s
|
|
183
|
+
[ af_name, port, host, host ]
|
|
161
184
|
end
|
|
185
|
+
private :sender_addr_info
|
|
162
186
|
|
|
163
187
|
#
|
|
164
|
-
# Calls
|
|
188
|
+
# Calls #timed_read and returns the data
|
|
165
189
|
#
|
|
166
190
|
def get(timeout=nil)
|
|
167
|
-
|
|
168
|
-
return data
|
|
191
|
+
timed_read(65535, timeout)
|
|
169
192
|
end
|
|
170
193
|
|
|
171
194
|
#
|
data/lib/rex/socket/version.rb
CHANGED