# mw0mwz/amitcp_ng architecture

> Architecture diagram of the GitHub repository mw0mwz/amitcp_ng, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-01). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/mw0mwz/amitcp_ng
- Repository: https://github.com/mw0mwz/amitcp_ng

## Overview

#### Purpose and deliverables
AmiTCP_NG is a 68k AmigaOS TCP/IP stack descended from AmiTCP/IP, packaged primarily as a self-starting, Roadshow-ABI-compatible `LIBS:bsdsocket.library`. It also produces Roadshow-compatible network commands, an independent `usergroup.library`, installer assets, and optional standalone stack tooling. Core build definitions are in `src/GNUmakefile`, `src/Smakefile`, and `src/amitcp_ng_glue.c`.

#### Startup, OS integration, and library ABI
Opening `bsdsocket.library` is the principal runtime entry point; it initializes and hosts the stack within the Amiga shared-library lifecycle. Amiga-specific startup, configuration, logging, control, ARexx, timing, synchronization, and memory integration form the OS boundary in `src/kern/amiga_main.c`, `src/kern/amiga_config.c`, and `src/lib/bsdsocket_lib.c`. The public compatible ABI and library-vector dispatch are implemented under `src/api/amiga_libcalls.c`, `src/api/amiga_libtables.c`, and `src/api/amiga_libcallentry.h`.

#### Socket API and name services
Application socket calls cross from the Amiga library ABI into BSD-style socket/domain machinery. API adapters cover socket operations, send/receive, syscall-style argument handling, compatibility behavior, and resolver APIs in `src/api/amiga_socket.c`, `src/api/amiga_sendrecv.c`, and `src/api/amiga_roadshow_compat.c`. DNS query construction, transport, parsing, cache, and host lookup are concentrated in `src/api/res_query.c`, `src/api/res_send.c`, and `src/api/dns_cache.c`; local/network database integration is in `src/kern/amiga_netdb.c`.

#### Kernel networking substrate
The stack’s internal boundary uses BSD domains, protocol-switch registration, sockets, socket buffers, mbufs, and routing. Key ownership and buffering structures live in `src/kern/uipc_domain.c`, `src/kern/uipc_socket.c`, and `src/kern/uipc_mbuf.c`. Interface-independent network dispatch and route lookup use `src/net/netisr.c`, `src/net/route.c`, and `src/net/radix.c`. This is the principal control path between socket requests and protocol implementations.

#### IPv4, transport, and packet flow
Inbound frames enter interface code, are dispatched through network ISR handling, processed by IPv4, then delivered to ICMP/TCP/UDP/raw protocol handlers. Outbound application data moves through TCP/UDP/IP output, route selection, ARP resolution, then interface transmission. IPv4 and ICMP are in `src/netinet/ip_input.c`, `src/netinet/ip_output.c`, and `src/netinet/ip_icmp.c`; TCP state, input, output, timers, and SACK behavior are in `src/netinet/tcp_input.c`, `src/netinet/tcp_output.c`, and `src/netinet/tcp_sack.c`; UDP is in `src/netinet/udp_usrreq.c`.

#### Network-device and capture boundary
Physical networking is abstracted through Amiga SANA-II devices. Interface lifecycle/configuration and SANA request handling are in `src/net/if_sana.c`, `src/net/sana2config.c`, and `src/net/sana2request.h`; loopback is always available through `src/net/if_loop.c`. ARP bridges IPv4 routing to link-layer delivery in `src/net/sana2arp.c`. BPF permits filtering, capture, and injection at the frame boundary via `src/net/bpf.c` and `src/net/bpf_filter.c`.

#### Operations, installation, and runtime environment
Roadshow-compatible commands configure interfaces, inspect/control the stack, and provide diagnostics; representative entry points are `src/tools/AddNetInterface.c`, `src/tools/AmiTCPControl.c`, and `src/tools/PacketCapture.c`. Installation deploys the library, commands, startup script, database, and example SANA-II configurations through `install/Install-AmiTCP_NG`, `install/S/Network-Startup`, and `install/Storage/NetInterfaces/`. Docker is the material build/test infrastructure, including cross-compilation and FS-UAE/Amiberry emulator-network validation: `docker/build-lib.sh`, `docker/run-fsuae.sh`, and `docker/run-amiberry.sh`. Emulator runs require externally supplied licensed Amiga ROM/OS assets; DHCP, DNS servers, SANA-II drivers, and host networking are external runtime dependencies.

Main entry points: [`src/net/netisr.c`](https://github.com/mw0mwz/amitcp_ng/blob/main/src/net/netisr.c) (Network dispatch & routing), [`src/lib/bsdsocket_lib.c`](https://github.com/mw0mwz/amitcp_ng/blob/main/src/lib/bsdsocket_lib.c) (bsdsocket.library), [`src/netinet/ip_input.c`](https://github.com/mw0mwz/amitcp_ng/blob/main/src/netinet/ip_input.c) (IPv4 & ICMP), [`src/net/if_sana.c`](https://github.com/mw0mwz/amitcp_ng/blob/main/src/net/if_sana.c) (SANA-II interfaces)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_library["Shared Library"]
  node_bsdsocket["bsdsocket.library<br/>shared library<br/>[bsdsocket_lib.c]"]
  node_startup["Amiga startup &amp; OS integration<br/>lifecycle<br/>[amiga_main.c]"]
  node_abi["Roadshow ABI dispatch<br/>library vectors<br/>[amiga_libcalls.c]"]
  node_socket_api["Socket API adapters<br/>API layer"]
  node_resolver["DNS &amp; netdb<br/>name services<br/>[res_query.c]"]
end

subgraph group_network["Network Stack"]
  node_socket_core["BSD socket core<br/>kernel substrate<br/>[uipc_socket.c]"]
  node_dispatch_route["Network dispatch &amp; routing<br/>IPv4 substrate<br/>[netisr.c]"]
  node_ipv4["IPv4 &amp; ICMP<br/>network protocol<br/>[ip_input.c]"]
  node_transport["TCP / UDP / raw<br/>transport protocols<br/>[tcp_input.c]"]
  node_arp["ARP<br/>link resolution<br/>[sana2arp.c]"]
  node_sana{{"SANA-II interfaces<br/>device boundary<br/>[if_sana.c]"}}
  node_loopback["Loopback interface<br/>virtual interface<br/>[if_loop.c]"]
  node_bpf["BPF capture &amp; injection<br/>frame capture<br/>[bpf.c]"]
end

subgraph group_operations["Operations &amp; Delivery"]
  node_commands["Roadshow-compatible commands<br/>CLI tools<br/>[AmiTCPControl.c]"]
  node_installer["Installer &amp; startup assets<br/>deployment"]
  node_docker["Docker build &amp; validation<br/>build infrastructure<br/>[build-lib.sh]"]
  node_emulators["FS-UAE / Amiberry<br/>emulator validation<br/>[run-fsuae.sh]"]
end

node_applications(("Amiga applications<br/>clients"))
node_network_devices(("SANA-II drivers &amp; network<br/>external runtime"))

node_applications -->|"opens"| node_bsdsocket
node_bsdsocket -->|"initializes"| node_startup
node_bsdsocket -->|"exports"| node_abi
node_abi -->|"dispatches calls to"| node_socket_api
node_socket_api -->|"uses"| node_socket_core
node_socket_api -->|"exposes"| node_resolver
node_resolver -->|"uses sockets for DNS"| node_socket_core
node_socket_core -->|"sends network requests"| node_dispatch_route
node_dispatch_route -->|"dispatches packets"| node_ipv4
node_ipv4 -->|"delivers inbound traffic"| node_transport
node_transport -->|"emits outbound packets"| node_ipv4
node_ipv4 -->|"uses route lookup"| node_dispatch_route
node_dispatch_route -->|"selects next hop"| node_arp
node_arp -->|"resolves for transmission"| node_sana
node_sana -->|"uses"| node_network_devices
node_sana -->|"inbound frames"| node_dispatch_route
node_loopback -->|"local packet path"| node_dispatch_route
node_bpf -->|"captures and injects frames"| node_sana
node_commands -->|"configures and controls"| node_bsdsocket
node_commands -->|"packet capture"| node_bpf
node_installer -->|"installs"| node_bsdsocket
node_installer -->|"installs"| node_commands
node_docker -->|"runs validation"| node_emulators
node_emulators -.->|"tests against"| node_network_devices

click node_bsdsocket "https://github.com/mw0mwz/amitcp_ng/blob/main/src/lib/bsdsocket_lib.c"
click node_startup "https://github.com/mw0mwz/amitcp_ng/blob/main/src/kern/amiga_main.c"
click node_abi "https://github.com/mw0mwz/amitcp_ng/blob/main/src/api/amiga_libcalls.c"
click node_resolver "https://github.com/mw0mwz/amitcp_ng/blob/main/src/api/res_query.c"
click node_socket_core "https://github.com/mw0mwz/amitcp_ng/blob/main/src/kern/uipc_socket.c"
click node_dispatch_route "https://github.com/mw0mwz/amitcp_ng/blob/main/src/net/netisr.c"
click node_ipv4 "https://github.com/mw0mwz/amitcp_ng/blob/main/src/netinet/ip_input.c"
click node_transport "https://github.com/mw0mwz/amitcp_ng/blob/main/src/netinet/tcp_input.c"
click node_arp "https://github.com/mw0mwz/amitcp_ng/blob/main/src/net/sana2arp.c"
click node_sana "https://github.com/mw0mwz/amitcp_ng/blob/main/src/net/if_sana.c"
click node_loopback "https://github.com/mw0mwz/amitcp_ng/blob/main/src/net/if_loop.c"
click node_bpf "https://github.com/mw0mwz/amitcp_ng/blob/main/src/net/bpf.c"
click node_commands "https://github.com/mw0mwz/amitcp_ng/blob/main/src/tools/AmiTCPControl.c"
click node_installer "https://github.com/mw0mwz/amitcp_ng/blob/main/install/Install-AmiTCP_NG"
click node_docker "https://github.com/mw0mwz/amitcp_ng/blob/main/docker/build-lib.sh"
click node_emulators "https://github.com/mw0mwz/amitcp_ng/blob/main/docker/run-fsuae.sh"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_bsdsocket,node_startup,node_abi,node_socket_api,node_resolver toneBlue
class node_socket_core,node_dispatch_route,node_ipv4,node_transport,node_arp,node_sana,node_loopback,node_bpf toneAmber
class node_commands,node_installer,node_docker,node_emulators toneMint
class node_applications,node_network_devices toneNeutral
```

## Components

### Shared Library

Roadshow-compatible stack hosted by bsdsocket.library.

- [bsdsocket.library](https://github.com/mw0mwz/amitcp_ng/blob/main/src/lib/bsdsocket_lib.c): shared library · Primary self-starting TCP/IP stack deliverable. · `src/lib/bsdsocket_lib.c`
- [Amiga startup & OS integration](https://github.com/mw0mwz/amitcp_ng/blob/main/src/kern/amiga_main.c): lifecycle · Configuration, logging, control, timing, and memory boundary. · `src/kern/amiga_main.c`
- [Roadshow ABI dispatch](https://github.com/mw0mwz/amitcp_ng/blob/main/src/api/amiga_libcalls.c): library vectors · Public calls and vector-table dispatch. · `src/api/amiga_libcalls.c`
- **Socket API adapters**: API layer · Socket, send/receive, syscall arguments, and compatibility calls.
- [DNS & netdb](https://github.com/mw0mwz/amitcp_ng/blob/main/src/api/res_query.c): name services · Resolver transport, cache, host lookup, and network databases. · `src/api/res_query.c`

### Network Stack

BSD socket, IPv4, transport, and device layers.

- [BSD socket core](https://github.com/mw0mwz/amitcp_ng/blob/main/src/kern/uipc_socket.c): kernel substrate · Domains, protocol registration, sockets, buffers, and mbufs. · `src/kern/uipc_socket.c`
- [Network dispatch & routing](https://github.com/mw0mwz/amitcp_ng/blob/main/src/net/netisr.c): IPv4 substrate · Network ISR dispatch and route lookup. · `src/net/netisr.c`
- [IPv4 & ICMP](https://github.com/mw0mwz/amitcp_ng/blob/main/src/netinet/ip_input.c): network protocol · IPv4 input/output and ICMP processing. · `src/netinet/ip_input.c`
- [TCP / UDP / raw](https://github.com/mw0mwz/amitcp_ng/blob/main/src/netinet/tcp_input.c): transport protocols · TCP state/output/timers and UDP protocol handling. · `src/netinet/tcp_input.c`
- [ARP](https://github.com/mw0mwz/amitcp_ng/blob/main/src/net/sana2arp.c): link resolution · Resolves IPv4 routes for SANA-II delivery. · `src/net/sana2arp.c`
- [SANA-II interfaces](https://github.com/mw0mwz/amitcp_ng/blob/main/src/net/if_sana.c): device boundary · Interface lifecycle and asynchronous device requests. · `src/net/if_sana.c`
- [Loopback interface](https://github.com/mw0mwz/amitcp_ng/blob/main/src/net/if_loop.c): virtual interface · Always-available local network interface. · `src/net/if_loop.c`
- [BPF capture & injection](https://github.com/mw0mwz/amitcp_ng/blob/main/src/net/bpf.c): frame capture · Frame filtering, capture, and injection. · `src/net/bpf.c`

### Operations & Delivery

Commands, installation, and emulator validation.

- [Roadshow-compatible commands](https://github.com/mw0mwz/amitcp_ng/blob/main/src/tools/AmiTCPControl.c): CLI tools · Configure, control, diagnose, and capture packets. · `src/tools/AmiTCPControl.c`
- [Installer & startup assets](https://github.com/mw0mwz/amitcp_ng/blob/main/install/Install-AmiTCP_NG): deployment · Deploys library, commands, databases, and interface configurations. · `install/Install-AmiTCP_NG`
- [Docker build & validation](https://github.com/mw0mwz/amitcp_ng/blob/main/docker/build-lib.sh): build infrastructure · Cross-compilation and emulator-network test runners. · `docker/build-lib.sh`
- [FS-UAE / Amiberry](https://github.com/mw0mwz/amitcp_ng/blob/main/docker/run-fsuae.sh): emulator validation · Requires externally supplied licensed Amiga ROM/OS assets. · `docker/run-fsuae.sh`

### Other components

- **Amiga applications**: clients · Consumers of the Roadshow socket ABI.
- **SANA-II drivers & network**: external runtime · External drivers, DHCP/DNS services, and host networking.

## Connections

- Amiga applications → bsdsocket.library: opens
- bsdsocket.library → Amiga startup & OS integration: initializes
- bsdsocket.library → Roadshow ABI dispatch: exports
- Roadshow ABI dispatch → Socket API adapters: dispatches calls to
- Socket API adapters → BSD socket core: uses
- Socket API adapters → DNS & netdb: exposes
- DNS & netdb → BSD socket core: uses sockets for DNS
- BSD socket core → Network dispatch & routing: sends network requests
- Network dispatch & routing → IPv4 & ICMP: dispatches packets
- IPv4 & ICMP → TCP / UDP / raw: delivers inbound traffic
- TCP / UDP / raw → IPv4 & ICMP: emits outbound packets
- IPv4 & ICMP → Network dispatch & routing: uses route lookup
- Network dispatch & routing → ARP: selects next hop
- ARP → SANA-II interfaces: resolves for transmission
- SANA-II interfaces → SANA-II drivers & network: uses
- SANA-II interfaces → Network dispatch & routing: inbound frames
- Loopback interface → Network dispatch & routing: local packet path
- BPF capture & injection → SANA-II interfaces: captures and injects frames
- Roadshow-compatible commands → bsdsocket.library: configures and controls
- Roadshow-compatible commands → BPF capture & injection: packet capture
- Installer & startup assets → bsdsocket.library: installs
- Installer & startup assets → Roadshow-compatible commands: installs
- Docker build & validation → FS-UAE / Amiberry: runs validation
- FS-UAE / Amiberry → SANA-II drivers & network: tests against
