Skip to content

Virtual W5100 with DNS

Oliver Schmidt edited this page Jun 6, 2022 · 3 revisions

Emulations of the W5100 tend to not exactly emulate the UDP and TCP modes. Rather they forward UDP/TCP operations performed on the virtual W5100 directly to an already existing and configured TCP/IP stack.

Such a forwarding is way easier to implement and/or may be much more compatible with certain emulation environments than true W5100 emulation, which is necessary for the MACRAW and IP modes. Therefore it is interesting to consider W5100 emulations restricted to UDP/TCP mode.

Typical Apple II applications use DHCP and DNS to gather the necessary local and remote IP address information. Then they use some UDP/TCP-based transport protocol for their actual data transfer needs. DHCP is especially problematic in certain emulation environments. One solution is to implement a full virtual network environment incl. virtual DHCP server, but that is a pretty heavy-handed approach.

Here, an alternative solution is presented, that implies that the Apple II application is aware of the virtual W5100 and limits its operations to UDP/TCP mode.

DHCP Operation

UDP/TCP mode forwarding completely ignores the Gateway Address, Subnet mask Address, Source Hardware Address and Source IP Address registers. So any DHCP operation setting those registers has no effect on subsequent UDP/TCP mode operations. Therefore, the aware application simply omits any DHCP operation altogether.

DNS Operation

In contrast to DHCP, there's no conceptual problem with DNS operations. However, without having performed a DHCP operation, the application doesn't have access to the IP address of the DNS server. Therefore, the aware application uses DNS offloading.

Detection

In order to limit its operations to UDP/TCP mode, the Apple II application needs to be aware of the virtual W5100. This is done by reading the (PPP Link Control Protocol Request Timer Register at 0x0028. On a real W5100, its default value is 0x28. But on the virtual W5100, its default value is 0x00.

DNS Offloading

After successful detection of the virtual W5100, the Apple II offloads DNS operations to the virtual W5100. This is prepared by setting bit 3 in the Socket n Mode Register - aka P3 in the Protocol field. Additionally, the length-prefixed DNS name is placed in the Socket n Registers 0x2A - 0xFF (right after the Socket n RX Read Pointer Register).

Setting the Socket n Command Register to OPEN after this preparation, causes the given DNS name to be resolved and the resulting IP address being placed in the Socket n Destination IP Address Register.

The Socket n Status Register transitions to SOCK_INIT or SOCK_UDP after the DNS operation - no matter if the operation succeeds or fails. The Apple II program has basically two options:

  • Check the Socket n Destination IP Address Register for 0x0000, which means that the DNS operation failed.
  • Simply go ahead and try to use the socket - which then fails.