--- BasiliskII/src/dummy/ether_dummy.cpp 1999/10/03 14:16:26 1.1.1.1 +++ BasiliskII/src/dummy/ether_dummy.cpp 2008/01/01 09:40:34 1.11 @@ -1,7 +1,7 @@ /* * ether_dummy.cpp - Ethernet device driver, dummy implementation * - * Basilisk II (C) 1997-1999 Christian Bauer + * Basilisk II (C) 1997-2008 Christian Bauer * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -19,6 +19,12 @@ */ #include "sysdeps.h" + +#if SUPPORTS_UDP_TUNNEL +#include +#include +#endif + #include "cpu_emulation.h" #include "main.h" #include "macos_util.h" @@ -33,12 +39,20 @@ #define MONITOR 0 +// Global variables +#if SUPPORTS_UDP_TUNNEL +static int fd = -1; // UDP tunnel socket fd +static bool udp_tunnel_active = false; +#endif + + /* * Initialization */ -void EtherInit(void) +bool ether_init(void) { + return true; } @@ -46,7 +60,7 @@ void EtherInit(void) * Deinitialization */ -void EtherExit(void) +void ether_exit(void) { } @@ -55,7 +69,7 @@ void EtherExit(void) * Reset */ -void EtherReset(void) +void ether_reset(void) { } @@ -114,9 +128,54 @@ int16 ether_write(uint32 wds) /* + * Start UDP packet reception thread + */ + +bool ether_start_udp_thread(int socket_fd) +{ +#if SUPPORTS_UDP_TUNNEL + fd = socket_fd; + udp_tunnel_active = true; + return true; +#else + return false; +#endif +} + + +/* + * Stop UDP packet reception thread + */ + +void ether_stop_udp_thread(void) +{ +#if SUPPORTS_UDP_TUNNEL + udp_tunnel_active = false; +#endif +} + + +/* * Ethernet interrupt - activate deferred tasks to call IODone or protocol handlers */ void EtherInterrupt(void) { +#if SUPPORTS_UDP_TUNNEL + if (udp_tunnel_active) { + EthernetPacket ether_packet; + uint32 packet = ether_packet.addr(); + ssize_t length; + + // Read packets from socket and hand to ether_udp_read() for processing + while (true) { + struct sockaddr_in from; + socklen_t from_len = sizeof(from); + length = recvfrom(fd, Mac2HostAddr(packet), 1514, 0, (struct sockaddr *)&from, &from_len); + if (length < 14) + break; + ether_udp_read(packet, length, &from); + } + } +#endif }