diff --git a/lib/rex/socket.rb b/lib/rex/socket.rb index faf1c648f9..85fcd45417 100644 --- a/lib/rex/socket.rb +++ b/lib/rex/socket.rb @@ -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 #