1
0
Fork 0

Improve code

This commit is contained in:
Alex Kotov 2020-04-17 21:13:09 +05:00
parent af131f2615
commit 23bdc8694b
Signed by: kotovalexarian
GPG Key ID: 553C0EBBEB5D5F08
1 changed files with 14 additions and 7 deletions

21
main.py
View File

@ -108,17 +108,24 @@ def main():
print('connected!')
while True:
buf = tun_iface.read(tun_iface.mtu)
handle_iface_data(conn, tun_iface, config)
handle_stream_data(conn, tun_iface, config)
flags = buf[:2]
proto = buf[2:4]
def handle_iface_data(conn, tun_iface, config):
buf = tun_iface.read(tun_iface.mtu)
if proto != b'\x08\x00':
continue
flags = buf[:2]
proto = buf[2:4]
ip_packet = IpPacket(IpHeader(buf[4:28]), buf[28:])
if proto != b'\x08\x00':
return
handle_ip_packet(ip_packet, conn, tun_iface, config)
ip_packet = IpPacket(IpHeader(buf[4:28]), buf[28:])
handle_ip_packet(ip_packet, conn, tun_iface, config)
def handle_stream_data(conn, tun_iface, config):
data = conn.recv(10000)
def handle_ip_packet(ip_packet, conn, tun_iface, config):
print(