mirror of
https://github.com/bol-van/zapret2.git
synced 2026-03-14 06:13:09 +00:00
zapret-pcap.lua
This commit is contained in:
@@ -877,6 +877,20 @@ function genhost(len, template)
|
||||
end
|
||||
end
|
||||
|
||||
function is_absolute_path(path)
|
||||
if string.sub(path,1,1)=='/' then return true end
|
||||
local un = uname()
|
||||
return string.sub(un.sysname,1,6)=="CYGWIN" and string.sub(path,2,2)==':'
|
||||
end
|
||||
function append_path(path,file)
|
||||
return string.sub(path,#path,#path)=='/' and path..file or path.."/"..file
|
||||
end
|
||||
function writeable_file_name(filename)
|
||||
if is_absolute_path(filename) then return filename end
|
||||
local writedir = os.getenv("WRITEABLE")
|
||||
if not writedir then return filename end
|
||||
return append_path(writedir, filename)
|
||||
end
|
||||
|
||||
-- arg : wsize=N . tcp window size
|
||||
-- arg : scale=N . tcp option scale factor
|
||||
|
||||
22
lua/zapret-pcap.lua
Normal file
22
lua/zapret-pcap.lua
Normal file
@@ -0,0 +1,22 @@
|
||||
-- test case : nfqws2 --qnum 200 --debug --lua-init=@zapret-lib.lua --lua-init=@zapret-pcap.lua:file=test.pcap --writeable=zdir
|
||||
-- arg : file=<filename> - file for storing pcap data. if --writeable is specified and filename is relative - append filename to writeable path
|
||||
function pcap(ctx, desync)
|
||||
if not desync.arg.file or #desync.arg.file==0 then
|
||||
error("pcap requires 'file' parameter")
|
||||
end
|
||||
local fn = writeable_file_name(desync.arg.file)
|
||||
local f = io.open(fn, "a")
|
||||
if not f then
|
||||
error("pcap: could not write to '"..fn.."'")
|
||||
end
|
||||
local pos = f:seek()
|
||||
if (pos==0) then
|
||||
-- create pcap header
|
||||
f:write("\xA1\xB2\x3C\x4D\x00\x02\x00\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x40\x00\x00\x00\x00\x65")
|
||||
end
|
||||
local raw = raw_packet(ctx)
|
||||
local sec, nsec = clock_gettime();
|
||||
f:write(bu32(sec)..bu32(nsec)..bu32(#raw)..bu32(#raw))
|
||||
f:write(raw)
|
||||
f:close()
|
||||
end
|
||||
Reference in New Issue
Block a user