From: Thomas Chust Date: 2009-08-02T21:13:35+09:00 Subject: Re: ffi, struct pointer question 2009/8/2 Daniel Berger : > [...] >      class GroupStruct < FFI::Struct >         layout( > [...] >            :gr_mem,    :pointer >         ) >      end > >      attach_function :getgrgid, [:int], :pointer > >      def self.get_group(gid) >         GroupStruct.new(getgrgid(gid)) >      end > [...] > # How do I unravel the gr_mem struct member? > struct = Sys::Admin.get_group(84) > p struct[:gr_mem] Hello, the gr_mem member of the group structure is a NULL terminated array of zero terminated strings, so you need to read all the string pointers from the array until you encounter a null pointer and then read the string data from each string pointer. I would suggest the use of an auxiliary method, which could actually be added to the FFI::Pointer class for convenience: class FFI::Pointer def read_string_array_to_null() elements = [] psz = self.class.size loc = self until ((element = loc.read_pointer).null?) elements << element.read_string_to_null loc += psz end elements end end Using this method, you can unravel the mysterious pointer member as follows: p struct[:gr_mem].read_string_array_to_null ;-) I hope that helps, Thomas -- When C++ is your hammer, every problem looks like your thumb.