fort/test/log_read.lua

46 lines
886 B
Lua
Raw Normal View History

2015-01-12 06:42:12 +00:00
-- WIPF Log Reader
local sys = require"sys"
2015-01-15 08:17:03 +00:00
local sock = require"sys.sock"
2015-01-12 06:42:12 +00:00
2015-01-18 07:55:04 +00:00
local wipf = require"wipflua"
2015-01-19 06:40:38 +00:00
local wipf_fs = require"wipf/util/fs"
2015-01-12 06:42:12 +00:00
2015-01-16 11:11:59 +00:00
2015-01-14 15:06:56 +00:00
function print_logs(buf)
local size = buf:seek()
local ptr = buf:getptr()
local off = 0
while off < size do
2015-01-18 07:55:04 +00:00
local len, ip, pid, dos_path = wipf.log_read(ptr, off)
2015-01-15 08:17:03 +00:00
local ip_str = sock.inet_ntop(ip)
2015-01-16 11:11:59 +00:00
2015-01-18 07:55:04 +00:00
if not dos_path then
2015-01-19 06:40:38 +00:00
dos_path = wipf_fs.pid_dospath(pid)
2015-01-16 11:11:59 +00:00
end
2015-01-19 06:40:38 +00:00
local path = wipf_fs.dospath_to_path(dos_path)
2015-01-18 07:55:04 +00:00
2015-01-15 08:17:03 +00:00
print(ip_str, pid, path)
2015-01-16 11:11:59 +00:00
off = off + len
2015-01-14 15:06:56 +00:00
end
buf:seek(0)
end
2015-01-12 12:49:02 +00:00
local device = assert(sys.handle():open(wipf.device_name(), "rw"))
2015-01-12 06:42:12 +00:00
2015-01-14 12:33:52 +00:00
local BUFSIZ = wipf.buffer_size()
2015-01-12 06:42:12 +00:00
local buf = assert(sys.mem.pointer(BUFSIZ))
2015-01-12 12:49:02 +00:00
assert(buf:write("test config"))
assert(device:ioctl(wipf.ioctl_setconf(), buf))
2015-01-12 06:42:12 +00:00
while true do
assert(device:ioctl(wipf.ioctl_getlog(), nil, buf))
2015-01-14 15:06:56 +00:00
print_logs(buf)
2015-01-12 06:42:12 +00:00
end