Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions lib/ipaddress/ipv6.rb
Original file line number Diff line number Diff line change
Expand Up @@ -566,14 +566,13 @@ def self.groups(str)
#
# With that data you can create a new IPv6 object:
#
# ip6 = IPAddress::IPv6::parse_data " \001\r\270\000\000\000\000\000\b\b\000 \fAz"
# ip6.prefix = 64
# ip6 = IPAddress::IPv6::parse_data " \001\r\270\000\000\000\000\000\b\b\000 \fAz", 64
#
# ip6.to_s
# #=> "2001:db8::8:800:200c:417a/64"
#
def self.parse_data(str)
self.new(IN6FORMAT % str.unpack("n8"))
def self.parse_data(str, prefix=128)
return self.new(IN6FORMAT % str.unpack("n8") + '/' + prefix.to_s)
end

#
Expand Down
6 changes: 6 additions & 0 deletions test/ipaddress/ipv6_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,12 @@ def test_classmethod_parse_data
assert_equal "2001:db8::8:800:200c:417a/128", ip.to_string
end

def test_classmethod_parse_data_with_prefix
str = " \001\r\270\000\000\000\000\000\b\b\000 \fAz"
ip = @klass.parse_data str, 64
assert_equal "2001:db8::8:800:200c:417a/64", ip.to_string
end

def test_classhmethod_parse_u128
@valid_ipv6.each do |ip,num|
assert_equal @klass.new(ip).to_s, @klass.parse_u128(num).to_s
Expand Down