Subject:
Re: [ruby-ffi] Re: Linked list of structs
From:
Wayne Meissner
Date:
10/20/10 6:14 PM
To:
ruby-ffi@googlegroups.com

As long as the parameter type on the function is declared as :pointer,
or :buffer_out (which is slightly more efficient for this case,
especially on JRuby), then either a string or a MemoryPointer will
work fine.


On 21 October 2010 08:39, Qwerty <qwerty123451910@hotmail.com> wrote:
> Thanks! That worked.
>
> Is the errbuff pointer necessary? A ruby string seems to work, are
> there any gotchas with that?
>
> On Oct 19, 6:34 pm, Wayne Meissner <wmeiss...@gmail.com> wrote:
>> On 20 October 2010 03:31, Qwerty <qwerty123451...@hotmail.com> wrote:
>>
>>
>>
>> > How do you iterate over the linked list using FFI?
>>
>> How about something like this:
>>
>> ptr = Pcap.find_devs
>> until ptr.null?
>>   devs = Pcap::Pcap_if_t.new ptr
>>   puts devs[:name]
>>   ptr=devs[:next]
>> end
>>
>> > Also is it true that FFI can not handle a multidimensional array? The
>>
>> You should be able to fix this one as follows:
>>
>> ppdev = FFI::MemoryPointer.new :pointer
>> errbuf = FFI::MemoryPointer.new :char, Pcap::PCAP_ERRBUF_SIZE
>> res = Pcap.pcap_findalldevs(ppdev, errbuf)
>> # ... check res for error conditions
>>
>> # now get the first device pointer
>> ptr = ppdev.read_pointer
>>
>> # now loop over them all as above
>> until ptr.null?
>>   devs = Pcap::Pcap_if_t.new ptr
>>   puts devs[:name]
>>   ptr=devs[:next]
>> end