fort/test/log_read.lua

36 lines
713 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
local wipf = require"wipflua"
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
local len, ip, pid, path = wipf.log_read(ptr, off)
2015-01-15 08:17:03 +00:00
local ip_str = sock.inet_ntop(ip)
2015-01-14 15:06:56 +00:00
off = off + len
2015-01-15 08:17:03 +00:00
print(ip_str, pid, path)
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