using System.Net;

namespace TeslaConsole;

/// <summary>
/// Support for the DOSBox-X preservation pods. The emulator that runs the
/// original DOS build of a game is bridged onto the pod network with its last
/// octet enumerated 100 above the host pod's address, so when a game page is
/// driving the emulated version it must target host+100 instead of the
/// address stored in the site config. Only the game traffic shifts — the
/// launcher and provisioning services still run on the host itself.
/// </summary>
internal static class DosBox
{
	public const int AddressOffset = 100;

	/// <summary>
	/// Returns the address with its last octet raised by <see cref="AddressOffset"/>.
	/// The octet wraps modulo 256; real site configs keep host octets at or
	/// below 155 so the shifted address stays inside the subnet.
	/// </summary>
	public static IPAddress ShiftAddress(IPAddress address)
	{
		byte[] bytes = address.GetAddressBytes();
		bytes[bytes.Length - 1] = (byte)(bytes[bytes.Length - 1] + AddressOffset);
		return new IPAddress(bytes);
	}
}
