Skip to content

Commit

Permalink
copies read string into struct instead of hoping it will stay long en…
Browse files Browse the repository at this point in the history
…ough to use a cast pointer
  • Loading branch information
javierguerragiraldez committed Aug 25, 2014
1 parent 9ff53ff commit 8def591
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
2 changes: 0 additions & 2 deletions src/apps/packet_filter/packet_filter.lua
Original file line number Diff line number Diff line change
Expand Up @@ -335,10 +335,8 @@ local function generateConformFunctionString(rules)
local T = make_code_concatter()
T"local ffi = require(\"ffi\")"
T"local bit = require(\"bit\")"
T"local jit = require(\"jit\")"
T"return function(buffer, size)"
T:indent()
T"jit.off(true,true)"

for i = 1, #rules do
if rules[i].ethertype == "ipv4" then
Expand Down
9 changes: 5 additions & 4 deletions src/lib/pcap/pcap.lua
Original file line number Diff line number Diff line change
Expand Up @@ -75,20 +75,21 @@ function records (filename)
local packet = file:read(datalen)
local extra = nil
if record.incl_len == #packet + ffi.sizeof("struct pcap_record_extra") then
extra = readc(file, "struct pcap_record_extra")
extra = readc(file, "struct pcap_record_extra")
end
return packet, record, extra
end
return pcap_records_it, true, true
end

-- Read a C object of TYPE from FILE. Return a pointer to the result.
-- Read a C object of TYPE from FILE
function readc(file, type)
local string = file:read(ffi.sizeof(type))
if string == nil then return nil end
if #string ~= ffi.sizeof(type) then
error("short read of " .. type .. " from " .. tostring(file))
end
return ffi.cast(type.."*", string)
local obj = ffi.new(type)
ffi.copy(obj, string)
return obj
end

0 comments on commit 8def591

Please sign in to comment.