module DhcpsApi::RubyStructAttrHelpers

@private

Public Instance Methods

dhcp_client_uid_to_mac(dhcp_client_uid) click to toggle source
# File lib/dhcpsapi/common.rb, line 31
def dhcp_client_uid_to_mac(dhcp_client_uid)
  dhcp_client_uid[:data].read_array_of_type(:uint8, :read_uint8, dhcp_client_uid[:data_length]).map {|w| "%02X" % w}.join(":")
end
ip_to_uint32(ip_address) click to toggle source
# File lib/dhcpsapi/common.rb, line 19
def ip_to_uint32(ip_address)
  ip_address.strip.split(".").inject(0) do |all_octets, current_octet|
    all_octets = all_octets << 8
    all_octets |= current_octet.to_i
    all_octets
  end
end
mac_address_to_array_of_uint8(mac_address) click to toggle source
# File lib/dhcpsapi/common.rb, line 35
def mac_address_to_array_of_uint8(mac_address)
  mac_address.split(":").map {|part| part.to_i(16)}
end
to_string(a_ptr) click to toggle source
# File lib/dhcpsapi/common.rb, line 6
def to_string(a_ptr)
  return "" if a_ptr.null?
  a_ptr.get_bytes(0, wchar_string_length(a_ptr)*2).force_encoding('utf-16LE').encode('utf-8')
end
to_wchar_string(a_string) click to toggle source
# File lib/dhcpsapi/common.rb, line 39
def to_wchar_string(a_string)
  (a_string + "\x00").encode('utf-16LE')
end
uint32_to_ip(encoded_ip) click to toggle source
# File lib/dhcpsapi/common.rb, line 27
def uint32_to_ip(encoded_ip)
  (0..3).inject([]) {|all_octets, current_octet| all_octets << ((encoded_ip >> 8*current_octet) & 0xFF)}.reverse.join(".")
end
wchar_string_length(a_ptr) click to toggle source
# File lib/dhcpsapi/common.rb, line 11
def wchar_string_length(a_ptr)
  str = FFI::Pointer.new(:uint16, a_ptr)
  (0..511).each do |i|
    return i if str[i].read_uint16 == 0
  end
  511
end