Skip to content

All your computers and your phone/iPhone, working as one desk. Screens, apps, files, clipboard, calls, texts, notifications, mouse and keyboard, shared between Mac, Windows, Linux , Android, Web and ios / ipados . Free and open source. No account, no cloud, and no shared network needed.

1.2 KB
Raw Blame
// TwinDesk — Copyright (C) 2026 inukaasith. GPL-3.0, see LICENSE.
// Whether an address is this network (or the USB cable, adb's 127.0.0.1): private, link-local or ULA.
// Never a tailnet (100.64.0.0/10, fd7a:115c:a1e0::/48), the internet, or the relay (relayAddrs: the
// addresses of sockets relay.js brought in). Biometric unlock goes only this way (docs/full-kvm.md).
'use strict';

function localAddress(addr, relayAddrs) {
  if (!relayAddrs) {
    try { relayAddrs = require('./relay.js').RelayHost.addrs; } catch (_) { /* no relay here */ }
  }
  relayAddrs = relayAddrs || new Set();
  const a = String(addr || '').replace(/^::ffff:/i, '').replace(/%.*$/, '').toLowerCase();
  if (!a || relayAddrs.has(a)) return false;
  const v4 = /^(\d+)\.(\d+)\.(\d+)\.(\d+)$/.exec(a);
  if (v4) {
    const [x, y] = [Number(v4[1]), Number(v4[2])];
    if (x === 100 && y >= 64 && y < 128) return false;
    return x === 10 || x === 127 || (x === 172 && y >= 16 && y < 32) || (x === 192 && y === 168) || (x === 169 && y === 254);
  }
  if (a === '::1') return true;
  if (/^fd7a:115c:a1e0:/.test(a)) return false;
  return /^fe[89ab][0-9a-f]:/.test(a) || /^f[cd][0-9a-f]{2}:/.test(a);
}

module.exports = { localAddress };