indexing description: "[ Common network helper functions. This class may be used as ancestor by classes needing its facilities. ]" date: "$Date$" revision: "$Revision$" class EM_NETWORK_HELPER_FUNCTIONS inherit EM_NETWORK_CONSTANTS feature -- Status report is_valid_ip_string (an_ip_string: STRING): BOOLEAN is -- Is `an_ip_string' a valid IP string? require an_ip_string_not_void: an_ip_string /= Void local a_splitter: ST_SPLITTER a_list: DS_LIST[STRING] do create a_splitter.make a_splitter.set_separators (".") a_list := a_splitter.split (an_ip_string) if a_list.count = 4 then Result := True from a_list.start until a_list.after loop Result := a_list.item_for_iteration.is_integer and Result a_list.forth end else Result := False end end feature -- Conversion convert_to_big_endian_32 (value: INTEGER): INTEGER is -- Convert a 32 bit `value' from the byte order of the this system -- to network byte order (big endian). local buffer: MANAGED_POINTER do create buffer.make (4) buffer.put_integer_32 (value, 0) Result := buffer.read_integer_32_be (0) end convert_from_big_endian_32 (value: INTEGER): INTEGER is -- Convert a 32 bit `value' from network byte order (big endian) to the -- byte order of this system. local buffer: MANAGED_POINTER do create buffer.make (4) buffer.put_integer_32_be (value, 0) Result := buffer.read_integer_32 (0) end convert_to_big_endian_16 (value: INTEGER): INTEGER is -- Convert a 16 bit `value' from the byte order of the this system -- to network byte order (big endian). local buffer: MANAGED_POINTER do create buffer.make (2) buffer.put_integer_16 (value.to_integer_16, 0) Result := buffer.read_integer_16_be (0).to_integer_32.bit_and (65535) end convert_from_big_endian_16 (value: INTEGER): INTEGER is -- Convert a 16 bit `value' from network byte order (big endian) to the -- byte order of this system. local buffer: MANAGED_POINTER do create buffer.make (2) buffer.put_integer_16_be (value.to_integer_16, 0) Result := buffer.read_integer_16 (0).to_integer_32.bit_and (65535) end convert_ip_string_to_ip (an_ip_string: STRING): INTEGER is -- Convert an_ip_string to an integer ip. require an_ip_string_not_void: an_ip_string /= Void is_valid_ip_string: is_valid_ip_string(an_ip_string) local a_splitter: ST_SPLITTER a_list: DS_LIST[STRING] do create a_splitter.make a_splitter.set_separators (".") a_list := a_splitter.split (an_ip_string) from a_list.start until a_list.after loop Result := a_list.item_for_iteration.to_integer + Result.bit_shift_left (8) a_list.forth end end end