# `MobDev.Tunnel`
[🔗](https://github.com/genericjam/mob_dev/blob/master/lib/mob_dev/tunnel.ex#L1)

Manages port tunnels for Android and physical iOS devices.

Android (adb):
  adb reverse tcp:4369 tcp:4369   — Android BEAM registers in Mac's EPMD
  adb forward tcp:<dist> tcp:9100 — Mac reaches device's dist port

Physical iOS (direct networking — USB preferred, WiFi/LAN fallback):
  mob_beam.m finds the device's own IP via getifaddrs() and starts the BEAM
  as mob_qa_ios@<device-ip>. The in-process EPMD binds 0.0.0.0:4369 so Mac
  can query it at <device-ip>:4369. The dist port is directly reachable.

  Connection priority (mirrors mob_beam.m priority):
    1. USB link-local (169.254.x.x) — detected from Mac ARP table
    2. WiFi/LAN (10.x, 172.16-31.x, 192.168.x) — EPMD scan of ARP table
    3. Tailscale (100.64-127.x) — EPMD scan of ARP table

iOS simulator:
  Shares Mac network stack — no tunnels needed.

# `dist_port`

```elixir
@spec dist_port(non_neg_integer()) :: non_neg_integer()
```

Returns the dist port for a given device index (same formula used in setup/2).

# `setup`

```elixir
@spec setup(MobDev.Device.t(), non_neg_integer()) ::
  {:ok, MobDev.Device.t()} | {:error, String.t()}
```

Assigns a dist port and sets up tunnels for a device.
Returns {:ok, %Device{}} with dist_port and host_ip filled in, or {:error, reason}.

# `teardown`

```elixir
@spec teardown(MobDev.Device.t()) :: :ok
```

Tears down tunnels for a device.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
