# vkerob/ft_nmap architecture

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

- Interactive diagram: https://gitdiagram.com/vkerob/ft_nmap
- Repository: https://github.com/vkerob/ft_nmap

## Overview

ft_nmap is a raw-packet port scanner with TCP SYN, ACK, NULL, FIN and XMAS scans, UDP probes, multi-target input, and optional traceroute. The main workflow parses arguments and targets, selects interfaces, runs concurrent probe-sending and packet-capture workers, classifies replies and timeouts, then prints combined port states and reasons. UDP payload selection and traceroute are distinct capabilities. The README documents the scan modes; source excerpts show key send, capture, response, and trace behavior, but not every orchestration call, so uncertain links are omitted.

Main entry points: [`src/threads/send_routine.c`](https://github.com/vkerob/ft_nmap/blob/main/src/threads/send_routine.c) (Probe sender), [`src/main.c`](https://github.com/vkerob/ft_nmap/blob/main/src/main.c) (CLI orchestrator), [`src/threads/threads.c`](https://github.com/vkerob/ft_nmap/blob/main/src/threads/threads.c) (Scan coordinator), [`src/threads/capture_routine.c`](https://github.com/vkerob/ft_nmap/blob/main/src/threads/capture_routine.c) (Packet capture)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_cli["Input and setup"]
  node_main["CLI orchestrator<br/>[main.c]"]
  node_args["Argument parsing<br/>[args.c]"]
  node_targets["Target resolution<br/>[targets.c]"]
  node_interfaces["Interface selection<br/>[interface.c]"]
end

subgraph group_engine["Probe engine"]
  node_scanner["Scan coordinator<br/>[threads.c]"]
  node_shared["Shared queues<br/>[shared_data.c]"]
  node_requests["Probe requests<br/>[request.c]"]
  node_send["Probe sender<br/>[send_routine.c]"]
  node_capture["Packet capture<br/>[capture_routine.c]"]
  node_pending["Pending probes"]
end

subgraph group_protocol["Packet protocols"]
  node_payloads["UDP payload lookup<br/>[payloads.c]"]
  node_tcpbuild["TCP packet construction<br/>[tcp_build_header.c]"]
  node_udpbuild["UDP packet construction<br/>[udp_build_header.c]"]
  node_ipbuild["IP packet construction<br/>[ip_build_header.c]"]
  node_tcpresponse["TCP state classification<br/>[tcp_response.c]"]
  node_udpresponse["UDP state classification<br/>[udp_response.c]"]
end

subgraph group_results["Results and tracing"]
  node_results["Scan report"]
  node_traceroute["Traceroute<br/>[traceroute.c]"]
  node_traceprobe["Trace probe I/O<br/>[trace_probe.c]"]
  node_traceoutput["Trace display<br/>[print_traceroute.c]"]
end

node_user(("Operator"))
node_network(("Scanned hosts"))

node_user -->|"provides options"| node_main
node_main -->|"parses arguments"| node_args
node_main -->|"resolves targets"| node_targets
node_main -->|"selects interfaces"| node_interfaces
node_main -->|"starts scan"| node_scanner
node_scanner -->|"initializes queues"| node_shared
node_scanner -->|"creates probes"| node_requests
node_scanner -->|"starts sender"| node_send
node_scanner -->|"starts capture"| node_capture
node_send -->|"dequeues probes"| node_shared
node_send -->|"looks up payloads"| node_payloads
node_send -->|"builds TCP probes"| node_tcpbuild
node_send -->|"builds UDP probes"| node_udpbuild
node_send -->|"builds IP packets"| node_ipbuild
node_send -->|"transmits probes"| node_network
node_network -->|"returns packets"| node_capture
node_capture -->|"dispatches TCP replies"| node_tcpresponse
node_capture -->|"dispatches UDP replies"| node_udpresponse
node_capture -->|"expires or requeues probes"| node_pending
node_tcpresponse -->|"updates probe state"| node_shared
node_udpresponse -->|"updates probe state"| node_shared
node_main -->|"prints results"| node_results
node_results -.->|"runs optional trace"| node_traceroute
node_traceroute -->|"probes and receives"| node_traceprobe
node_results -->|"prints trace"| node_traceoutput

click node_main "https://github.com/vkerob/ft_nmap/blob/main/src/main.c"
click node_args "https://github.com/vkerob/ft_nmap/blob/main/src/parsing/args.c"
click node_targets "https://github.com/vkerob/ft_nmap/blob/main/src/parsing/targets.c"
click node_interfaces "https://github.com/vkerob/ft_nmap/blob/main/src/scan/interface.c"
click node_scanner "https://github.com/vkerob/ft_nmap/blob/main/src/threads/threads.c"
click node_shared "https://github.com/vkerob/ft_nmap/blob/main/src/threads/shared_data.c"
click node_requests "https://github.com/vkerob/ft_nmap/blob/main/src/scan/request.c"
click node_send "https://github.com/vkerob/ft_nmap/blob/main/src/threads/send_routine.c"
click node_capture "https://github.com/vkerob/ft_nmap/blob/main/src/threads/capture_routine.c"
click node_pending "https://github.com/vkerob/ft_nmap/blob/main/src/scan/update_pending_probe_request_list.c"
click node_payloads "https://github.com/vkerob/ft_nmap/blob/main/src/payloads/payloads.c"
click node_tcpbuild "https://github.com/vkerob/ft_nmap/blob/main/src/protocols/tcp_build_header.c"
click node_udpbuild "https://github.com/vkerob/ft_nmap/blob/main/src/protocols/udp_build_header.c"
click node_ipbuild "https://github.com/vkerob/ft_nmap/blob/main/src/protocols/ip_build_header.c"
click node_tcpresponse "https://github.com/vkerob/ft_nmap/blob/main/src/protocols/tcp_response.c"
click node_udpresponse "https://github.com/vkerob/ft_nmap/blob/main/src/protocols/udp_response.c"
click node_results "https://github.com/vkerob/ft_nmap/blob/main/src/scan/print_scan_results.c"
click node_traceroute "https://github.com/vkerob/ft_nmap/blob/main/src/traceroute/traceroute.c"
click node_traceprobe "https://github.com/vkerob/ft_nmap/blob/main/src/traceroute/trace_probe.c"
click node_traceoutput "https://github.com/vkerob/ft_nmap/blob/main/src/traceroute/print_traceroute.c"

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_main,node_args,node_targets,node_interfaces toneBlue
class node_scanner,node_shared,node_requests,node_send,node_capture,node_pending toneAmber
class node_payloads,node_tcpbuild,node_udpbuild,node_ipbuild,node_tcpresponse,node_udpresponse toneMint
class node_results,node_traceroute,node_traceprobe,node_traceoutput toneRose
class node_user,node_network toneIndigo
```

## Components

### Input and setup

- [CLI orchestrator](https://github.com/vkerob/ft_nmap/blob/main/src/main.c): `src/main.c`
- [Argument parsing](https://github.com/vkerob/ft_nmap/blob/main/src/parsing/args.c): `src/parsing/args.c`
- [Target resolution](https://github.com/vkerob/ft_nmap/blob/main/src/parsing/targets.c): `src/parsing/targets.c`
- [Interface selection](https://github.com/vkerob/ft_nmap/blob/main/src/scan/interface.c): `src/scan/interface.c`

### Probe engine

- [Scan coordinator](https://github.com/vkerob/ft_nmap/blob/main/src/threads/threads.c): `src/threads/threads.c`
- [Shared queues](https://github.com/vkerob/ft_nmap/blob/main/src/threads/shared_data.c): `src/threads/shared_data.c`
- [Probe requests](https://github.com/vkerob/ft_nmap/blob/main/src/scan/request.c): `src/scan/request.c`
- [Probe sender](https://github.com/vkerob/ft_nmap/blob/main/src/threads/send_routine.c): `src/threads/send_routine.c`
- [Packet capture](https://github.com/vkerob/ft_nmap/blob/main/src/threads/capture_routine.c): `src/threads/capture_routine.c`
- [Pending probes](https://github.com/vkerob/ft_nmap/blob/main/src/scan/update_pending_probe_request_list.c): `src/scan/update_pending_probe_request_list.c`

### Packet protocols

- [UDP payload lookup](https://github.com/vkerob/ft_nmap/blob/main/src/payloads/payloads.c): `src/payloads/payloads.c`
- [TCP packet construction](https://github.com/vkerob/ft_nmap/blob/main/src/protocols/tcp_build_header.c): `src/protocols/tcp_build_header.c`
- [UDP packet construction](https://github.com/vkerob/ft_nmap/blob/main/src/protocols/udp_build_header.c): `src/protocols/udp_build_header.c`
- [IP packet construction](https://github.com/vkerob/ft_nmap/blob/main/src/protocols/ip_build_header.c): `src/protocols/ip_build_header.c`
- [TCP state classification](https://github.com/vkerob/ft_nmap/blob/main/src/protocols/tcp_response.c): `src/protocols/tcp_response.c`
- [UDP state classification](https://github.com/vkerob/ft_nmap/blob/main/src/protocols/udp_response.c): `src/protocols/udp_response.c`

### Results and tracing

- [Scan report](https://github.com/vkerob/ft_nmap/blob/main/src/scan/print_scan_results.c): `src/scan/print_scan_results.c`
- [Traceroute](https://github.com/vkerob/ft_nmap/blob/main/src/traceroute/traceroute.c): `src/traceroute/traceroute.c`
- [Trace probe I/O](https://github.com/vkerob/ft_nmap/blob/main/src/traceroute/trace_probe.c): `src/traceroute/trace_probe.c`
- [Trace display](https://github.com/vkerob/ft_nmap/blob/main/src/traceroute/print_traceroute.c): `src/traceroute/print_traceroute.c`

### Other components

- **Operator**
- **Scanned hosts**

## Connections

- Operator → CLI orchestrator: provides options
- CLI orchestrator → Argument parsing: parses arguments
- CLI orchestrator → Target resolution: resolves targets
- CLI orchestrator → Interface selection: selects interfaces
- CLI orchestrator → Scan coordinator: starts scan
- Scan coordinator → Shared queues: initializes queues
- Scan coordinator → Probe requests: creates probes
- Scan coordinator → Probe sender: starts sender
- Scan coordinator → Packet capture: starts capture
- Probe sender → Shared queues: dequeues probes
- Probe sender → UDP payload lookup: looks up payloads
- Probe sender → TCP packet construction: builds TCP probes
- Probe sender → UDP packet construction: builds UDP probes
- Probe sender → IP packet construction: builds IP packets
- Probe sender → Scanned hosts: transmits probes
- Scanned hosts → Packet capture: returns packets
- Packet capture → TCP state classification: dispatches TCP replies
- Packet capture → UDP state classification: dispatches UDP replies
- Packet capture → Pending probes: expires or requeues probes
- TCP state classification → Shared queues: updates probe state
- UDP state classification → Shared queues: updates probe state
- CLI orchestrator → Scan report: prints results
- Scan report → Traceroute: runs optional trace
- Traceroute → Trace probe I/O: probes and receives
- Scan report → Trace display: prints trace
