1
0
Fork 0

Fix write

This commit is contained in:
Alex Kotov 2020-04-19 11:50:10 +05:00
parent 7e3892a947
commit 844bb00dd5
Signed by: kotovalexarian
GPG Key ID: 553C0EBBEB5D5F08
2 changed files with 4 additions and 3 deletions

View File

@ -2,8 +2,7 @@ IP-туннель (VPN) с tun-интерфейсом на Python
============================================
Данный код был написан в рамках трансляции
(https://www.youtube.com/watch?v=tgXV1h_YMu4)
и будет доработан позже.
(https://www.youtube.com/watch?v=tgXV1h_YMu4).

View File

@ -175,7 +175,9 @@ def handle_ip_packet(ip_packet, conn, tun_iface, config):
if ip_packet.header.dst == config.iface_addr:
print('sending to tun iface')
buf = b'\x00\x00' + IP_V4_PROTO + ip_packet_packed
tun_iface.write(buf)
while len(buf):
nbytes = tun_iface.write(buf)
buf = buf[nbytes:]
elif ip_packet.header.dst == config.iface_dstaddr:
print('sending to remote peer')
ip_packet_length = struct.pack('>I', len(ip_packet_packed))