-
Notifications
You must be signed in to change notification settings - Fork 1
/
openwrt.lua
77 lines (71 loc) · 1.44 KB
/
openwrt.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
require 'socket'
require 'luci.jsonc'
require 'os'
-- wifi={ap={}}
net={IF_WIFI_AP=1,route={}}
tmr={}
sockets={}
sjson={encode=luci.jsonc.stringify,decode=luci.jsonc.parse}
function net.route.add(route)
local cmd='-net '..route.dest..'/'..route.prefixlen..' gw '..route.nexthop
local add='route add '..cmd
print(add)
os.execute(add)
end
function net.createUDPSocket()
ret = {
listen=function(self,port)
print('listen',port)
self._socket:setsockname('*',port)
end,
send=function(self,port,ip,data)
self._socket:sendto(data,ip,port)
end,
on=function(self,event,func)
self._events[event]=func
end,
_receive=function(self)
data,ip,port=self._socket:receivefrom()
self._events.receive(self,data,port,ip)
end,
_socket=socket.udp(),
_events={}
}
table.insert(sockets,ret)
return ret
end
function tmr.create()
return {
alarm=function()
end
}
end
-- function wifi.ap.getmac()
-- return 'none'
-- end
dofile 'router.lua'
router.topology={6,3,2,1,1,1,1,1}
router.state=router.ROOT
router.ssid='ESPTREE'
router.minip=0x0a0a0000
router.maxip=0x0a0af0ff
router.start()
while true do
fds={}
fdsocket={}
for i,socket in ipairs(sockets)
do
if (socket._events.receive)
then
table.insert(fds, socket._socket)
fdsocket[socket._socket]=socket
end
end
print(fds)
-- posix.poll.poll(fds)
rfds,wfds,msg=socket.select(fds, nil)
for i,fd in ipairs(rfds)
do
fdsocket[fd]:_receive()
end
end