class Lwes::Serialization::IpAddr

Public Instance Methods

get() click to toggle source
# File lib/lwes/serialization.rb, line 69
def get
  self.int32_to_ip(self.data)
end
int32_to_ip(num) click to toggle source
# File lib/lwes/serialization.rb, line 58
def int32_to_ip(num)
  ary = []
  
  4.times do
    ary << (num & 0xff)
    num = num >> 8
  end

  ary.join(".")
end
ip_to_int32(str) click to toggle source
# File lib/lwes/serialization.rb, line 53
def ip_to_int32(str)
  ary = str.to_s.split(".").collect{ |byte| byte.to_i }.slice(0,4)
  ((ary[3] & 0xff) << 24) + ((ary[2] & 0xff) << 16) + ((ary[1] & 0xff) << 8) + (ary[0] & 0xff)
end
set(val) click to toggle source
# File lib/lwes/serialization.rb, line 73
def set(val)
  self.data = ip_to_int32(val)
end