Subject:
[ruby-ffi] Re: Linked list of structs
From:
Qwerty
Date:
10/20/10 5:39 PM
To:
ruby-ffi

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