import pty
import time
import threading
+import subprocess
+import struct
+import fcntl
messages= {
"EXIT": 0,
self.serial = master
self.serial_name = os.ttyname(slave)
+ os.system("openvpn --mktun --dev tap0")
+ os.system("ip link set tap0 up")
+ os.system("ip addr add 192.169.0.14/24 dev tap0")
+ os.system("iface tap0 inet")
+ os.system("mknod /dev/net/tap c 10 200")
+ os.system("chmod 600 /dev/net/tap")
+
+
self.ack = False
self._print_banner()
if hasattr(self, "socket"):
self.socket.shutdown(socket.SHUT_RDWR)
self.socket.close()
+ os.system("openvpn --rmtun --dev tap0")
+ os.system("rm -f /dev/net/tap")
self._cleanup_file()
# XXX proof of concept
server.accept()
print("Connection accepted")
+TUNSETIFF = 0x400454ca
+IFF_TAP = 0x0002
+IFF_NO_PI = 0x1000
+
def read():
while True:
packet = server.recv()
c = bytes(chr(packet[1]).encode('utf-8'))
os.write(server.serial, c)
elif packet[0] == messages["ETHERNET"]:
- print("received ethernet")
- for d in packet[1:]:
- print("{:02X}".format(d), end="")
- print("")
+ tap = os.open("/dev/net/tun", os.O_RDWR)
+ fcntl.ioctl(tap, TUNSETIFF, struct.pack("16sH", b"tap0", IFF_TAP | IFF_NO_PI))
+ os.write(tap, packet[1+8:-4])
+ os.close(tap)
elif packet[0] == messages["ACK"]:
server.ack = True
writethread = threading.Thread(target=write, daemon=True)
writethread.start()
-while True:
- time.sleep(1)
+try:
+ while True:
+ time.sleep(1)
+except KeyboardInterrupt:
+ server.close()
+
return 0;
}
+#ifdef ETH_SOURCE_STB
int eth_last_source_stb = 0;
int ethernet_service(struct sim *s) {
}
eth_last_source_stb = ETH_SOURCE_STB;
}
+#endif
void sim_tick(struct sim *s)
{
if (SYS_CLK) {
if (console_service(&s) != 0)
s.run = false;
+#ifdef ETH_SOURCE_STB
ethernet_service(&s);
+#endif
}
}
s.end = clock();