Method: IPAddress::IPv6::Mapped#initialize
- Defined in:
- lib/ipaddress/ipv6.rb
#initialize(str) ⇒ Mapped
Creates a new IPv6 IPv4-mapped address
ip6 = IPAddress::IPv6::Mapped.new "::ffff:172.16.10.1/128"
ipv6.ipv4.class
#=> IPAddress::IPv4
An IPv6 IPv4-mapped address can also be created using the IPv6 only format of the address:
ip6 = IPAddress::IPv6::Mapped.new "::0d01:4403"
ip6.to_string
#=> "::ffff:13.1.68.3"
843 844 845 846 847 848 849 850 851 852 |
# File 'lib/ipaddress/ipv6.rb', line 843 def initialize(str) string, netmask = str.split("/") if string =~ /\./ # IPv4 in dotted decimal form @ipv4 = IPAddress::IPv4.extract(string) else # IPv4 in hex form groups = IPAddress::IPv6.groups(string) @ipv4 = IPAddress::IPv4.parse_u32((groups[-2]<< 16)+groups[-1]) end super("::ffff:#{@ipv4.to_ipv6}/#{netmask}") end |