fix ipv6 handling for single addresses

git-svn-id: file:///home/svn/framework3/trunk@7706 4d416f70-5f16-0410-b530-b9f4589650da
unstable
James Lee 2009-12-04 19:55:58 +00:00
parent 5952e29040
commit 1e6b6b3d62
2 changed files with 8 additions and 3 deletions

View File

@ -39,8 +39,8 @@ class RangeWalker
# Then it's IPv6 # Then it's IPv6
# Can't really do much with IPv6 right now, just return it and # Can't really do much with IPv6 right now, just return it and
# hope for the best # hope for the best
addr = Rex::Socket.addr_itoa(Rex::Socket.addr_atoi(arg)) addr = Rex::Socket.addr_atoi(arg)
ranges.push [addr, addr] ranges.push [addr, addr, true]
elsif arg.include?("/") elsif arg.include?("/")
# Then it's CIDR notation and needs special case # Then it's CIDR notation and needs special case
if arg =~ /[,-]/ if arg =~ /[,-]/
@ -95,7 +95,7 @@ class RangeWalker
@curr_range += 1 @curr_range += 1
@curr_addr = @ranges[@curr_range][0] @curr_addr = @ranges[@curr_range][0]
end end
addr = Rex::Socket.addr_itoa(@curr_addr) addr = Rex::Socket.addr_itoa(@curr_addr, @ranges[@curr_range][2])
@curr_addr += 1 @curr_addr += 1
return addr return addr
end end

View File

@ -4,6 +4,11 @@ require 'rex/socket'
require 'rex/socket/range_walker' require 'rex/socket/range_walker'
describe Rex::Socket::RangeWalker do describe Rex::Socket::RangeWalker do
it "should handle single ipv6 addresses" do
walker = Rex::Socket::RangeWalker.new("::1")
walker.should be_valid
walker.length.should == 1
end
it "should handle ranges" do it "should handle ranges" do
walker = Rex::Socket::RangeWalker.new("10.1.1.1-2") walker = Rex::Socket::RangeWalker.new("10.1.1.1-2")
walker.should be_valid walker.should be_valid