Improve code
This commit is contained in:
parent
af131f2615
commit
23bdc8694b
9
main.py
9
main.py
|
@ -108,18 +108,25 @@ def main():
|
||||||
print('connected!')
|
print('connected!')
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
|
handle_iface_data(conn, tun_iface, config)
|
||||||
|
handle_stream_data(conn, tun_iface, config)
|
||||||
|
|
||||||
|
def handle_iface_data(conn, tun_iface, config):
|
||||||
buf = tun_iface.read(tun_iface.mtu)
|
buf = tun_iface.read(tun_iface.mtu)
|
||||||
|
|
||||||
flags = buf[:2]
|
flags = buf[:2]
|
||||||
proto = buf[2:4]
|
proto = buf[2:4]
|
||||||
|
|
||||||
if proto != b'\x08\x00':
|
if proto != b'\x08\x00':
|
||||||
continue
|
return
|
||||||
|
|
||||||
ip_packet = IpPacket(IpHeader(buf[4:28]), buf[28:])
|
ip_packet = IpPacket(IpHeader(buf[4:28]), buf[28:])
|
||||||
|
|
||||||
handle_ip_packet(ip_packet, conn, tun_iface, config)
|
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):
|
def handle_ip_packet(ip_packet, conn, tun_iface, config):
|
||||||
print(
|
print(
|
||||||
ip_packet.header.src,
|
ip_packet.header.src,
|
||||||
|
|
Reference in New Issue