1
mirror of https://github.com/rapid7/metasploit-framework synced 2024-11-12 11:52:01 +01:00

use TCPServer instead of Socket + bind and work around JRuby's broken Socket#getsockname (see http://jira.codehaus.org/browse/JRUBY-5232)

git-svn-id: file:///home/svn/framework3/trunk@11211 4d416f70-5f16-0410-b530-b9f4589650da
This commit is contained in:
James Lee 2010-12-02 23:49:02 +00:00
parent 50d6c9659a
commit 185f50212f

View File

@ -503,10 +503,17 @@ module Socket
rsock = ::TCPSocket.new( laddr, lport )
}
}
server = ::Socket.new( ::Socket::AF_INET, ::Socket::SOCK_STREAM, 0 )
server.bind( ::Socket.sockaddr_in( 0, laddr ) )
lport, caddr = ::Socket.unpack_sockaddr_in( server.getsockname )
server.listen( 1 )
server = ::TCPServer.new(laddr, 0)
if (server.getsockname =~ /127\.0\.0\.1:/)
# JRuby ridiculousness
caddr, lport = server.getsockname.split(":")
caddr = caddr[1,caddr.length]
lport = lport.to_i
else
# Sane implementations where Socket#getsockname returns a
# sockaddr
lport, caddr = ::Socket.unpack_sockaddr_in( server.getsockname )
end
}
lsock, saddr = server.accept
server.close