RE: Pointer to pointer handling in LuaJIT

  • From: William Adams <william_a_adams@xxxxxxx>
  • To: "luajit@xxxxxxxxxxxxx" <luajit@xxxxxxxxxxxxx>
  • Date: Fri, 20 Dec 2013 18:43:39 -0800

ffi.new("char *[1]")

Would be an array of one chr*, which
Since arrays are just pointers, this would be a pointer to a 'char *', which is 
the same as 'char * *'.

Substitute any type for 'char' and the principle should be the same.


Would

Sent from my Windows Phone
________________________________
From: Delyan Nestorov<mailto:delyan.nestorov@xxxxxxxxx>
Sent: ‎12/‎20/‎2013 5:23 PM
To: luajit@xxxxxxxxxxxxx<mailto:luajit@xxxxxxxxxxxxx>
Subject: Pointer to pointer handling in LuaJIT

Hi,

I am experimenting with LuaJIT, FFI and libpcap to read packets from live
capture and "save file". I want to use Lua for parsing pcap files instead
of Python's dpkt library.

I have test function that will have to read the next packet from live
capture or pcap file:

function pcap.read_packet(self)
local p_data = pcap.ffi.new("unsigned char **")
local p_pkthdr = pcap.ffi.new("struct pcap_pkthdr **")
 local ret = self.lib.pcap_next_ex(self.pp, p_pkthdr, p_data)
assert(ret >= 0, "end")
end

The original C definition is:

int pcap_next_ex(pcap_t *, struct pcap_pkthdr** pkt_header, u_char**
pkt_data);

The question is: how to define, use and dereference pointers to pointers?

Thank you!

Kind regards,
Delyan

Other related posts: