Switches the socket class to use pack_sockaddr_in(). Fixes #58
git-svn-id: file:///home/svn/framework3/trunk@4545 4d416f70-5f16-0410-b530-b9f4589650daunstable
parent
1dd52c557d
commit
8c631e7063
|
@ -127,19 +127,7 @@ module Socket
|
|||
#
|
||||
def self.to_sockaddr(ip, port)
|
||||
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_INET6)
|
||||
data = [af, port.to_i, 0, self.gethostbyname(ip)[3], 0]
|
||||
return data.pack('snNa16N')
|
||||
end
|
||||
|
||||
# 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
|
||||
return ::Socket::pack_sockaddr_in(port, ip)
|
||||
end
|
||||
|
||||
#
|
||||
|
@ -147,21 +135,9 @@ module Socket
|
|||
# [ af, host, port ]
|
||||
#
|
||||
def self.from_sockaddr(saddr)
|
||||
up = saddr.unpack('snA*')
|
||||
af = up.shift
|
||||
port = up.shift
|
||||
|
||||
case af
|
||||
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"
|
||||
port, host = ::Socket::unpack_sockaddr_in(saddr)
|
||||
af = host.match(/:/) ? ::Socket::AF_INET6 : ::Socket::AF_INET
|
||||
return [ af, host, port ]
|
||||
end
|
||||
|
||||
#
|
||||
|
|
Loading…
Reference in New Issue