From 108362cf95ebdf5d1d84fcb29918c85929ad4fb8 Mon Sep 17 00:00:00 2001 From: HD Moore Date: Sat, 10 Apr 2010 17:31:40 +0000 Subject: [PATCH] Switch to recvfrom_nonsock, solves a hang with win32 + 1.9.1 git-svn-id: file:///home/svn/framework3/trunk@9045 4d416f70-5f16-0410-b530-b9f4589650da --- lib/rex/socket/udp.rb | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/lib/rex/socket/udp.rb b/lib/rex/socket/udp.rb index 661c041f93..17099ce2b5 100644 --- a/lib/rex/socket/udp.rb +++ b/lib/rex/socket/udp.rb @@ -51,8 +51,8 @@ module Rex::Socket::Udp begin return syswrite(gram) rescue ::Errno::EHOSTUNREACH,::Errno::ENETDOWN,::Errno::ENETUNREACH,::Errno::ENETRESET,::Errno::EHOSTDOWN,::Errno::EACCES,::Errno::EINVAL,::Errno::EADDRNOTAVAIL - return nil - end + return nil + end end alias put write @@ -81,9 +81,9 @@ module Rex::Socket::Udp end rescue Exception return '' - end + end end - + #alias send write #alias recv read @@ -97,7 +97,7 @@ module Rex::Socket::Udp # Sends a datagram to the supplied host:port with optional flags. # def sendto(gram, peerhost, peerport, flags = 0) - + # Catch unconnected IPv6 sockets talking to IPv4 addresses peer = Rex::Socket.resolv_nbo(peerhost) if (peer.length == 4 and self.ipv == 6) @@ -109,7 +109,7 @@ module Rex::Socket::Udp rescue ::Errno::EHOSTUNREACH,::Errno::ENETDOWN,::Errno::ENETUNREACH,::Errno::ENETRESET,::Errno::EHOSTDOWN,::Errno::EACCES,::Errno::EINVAL,::Errno::EADDRNOTAVAIL return nil end - + end # @@ -117,11 +117,12 @@ module Rex::Socket::Udp # as [ data, host, port ]. # def recvfrom(length = 65535, timeout=def_read_timeout) + begin if ((rv = Kernel.select([ fd ], nil, nil, timeout)) and (rv[0]) and (rv[0][0] == fd) ) - data, saddr = super(length) + data, saddr = recvfrom_nonblock(length) af, host, port = Rex::Socket.from_sockaddr(saddr) return [ data, host, port ] @@ -132,7 +133,7 @@ module Rex::Socket::Udp return [ '', nil, nil ] end end - + # # Calls recvfrom and only returns the data # @@ -140,16 +141,17 @@ module Rex::Socket::Udp data, saddr, sport = recvfrom(65535, timeout) return data end - + # # The default number of seconds to wait for a read operation to timeout. # def def_read_timeout 10 - end + end def type? return 'udp' end end +