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

On 20 October 2010 03:31, Qwerty <qwerty123451910@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