Method: IPAddress::IPv4.parse_data

Defined in:
lib/ipaddress/ipv4.rb

.parse_data(str, prefix = 32) ⇒ Object

Creates a new IPv4 object from binary data, like the one you get from a network stream.

For example, on a network stream the IP 172.16.0.1 is represented with the binary “254020n001”.

ip = IPAddress::IPv4::parse_data "\254\020\n\001"
ip.prefix = 24

ip.to_string
  #=> "172.16.10.1/24"


943
944
945
# File 'lib/ipaddress/ipv4.rb', line 943

def self.parse_data(str, prefix=32)
  self.new(str.unpack("C4").join(".")+"/#{prefix}")
end