Fix for OS X socket bugs

git-svn-id: file:///home/svn/framework3/trunk@3796 4d416f70-5f16-0410-b530-b9f4589650da
unstable
HD Moore 2006-07-31 19:22:21 +00:00
parent ce52979566
commit 8006479e6b
1 changed files with 11 additions and 10 deletions

View File

@ -123,18 +123,17 @@ module Socket
ip = "0.0.0.0" unless ip
ip = Rex::Socket.getaddress(ip)
af = ip.match(/:/) ? ::Socket::AF_INET6 : ::Socket::AF_INET
if (af == ::Socket::AF_INET)
data = [ af, port.to_i ] + ip.split('.').collect { |o| o.to_i } + [ "" ]
return data.pack('snCCCCa8')
end
if (af == ::Socket::AF_INET6)
data = [af, port.to_i, 0, self.gethostbyname(ip)[3], 0]
return data.pack('snNa16N')
end
raise RuntimeError, "Invalid address family"
# Mac OS X returns the wrong AF
if (true or af == ::Socket::AF_INET)
data = [ af, port.to_i ] + ip.split('.').collect { |o| o.to_i } + [ "" ]
return data.pack('snCCCCa8')
end
end
#
@ -147,11 +146,13 @@ module Socket
port = up.shift
case af
when ::Socket::AF_INET
return [ af, up.shift[0, 4].unpack('C*').join('.'), port ]
when ::Socket::AF_INET6
return [ af, up.shift[0,16].unpack('H*').gsub(/(....)/){ |r| r << ':' }.sub(/:$/, ''), port ]
# Mac OS X returns the wrong AF
# when ::Socket::AF_INET
else
return [ af, up.shift[0, 4].unpack('C*').join('.'), port ]
end
raise RuntimeError, "Invalid address family"