This guide covers the minimal concepts and common workflows for Paclo.
For installation and CLI entry examples, start from README.md.
paclo.core is the user-facing API.packets returns lazy packet maps from a file (:path) or device (:device).reduce-packets synchronously folds large or live captures without an
intermediate sequence.bpf converts a small Clojure DSL to BPF strings.write-pcap! writes byte records back to a PCAP file.paclo.decode-ext) annotate decoded packets.(require '[paclo.core :as core])
(->> (core/packets {:path "test/resources/dns-sample.pcap"
:decode? true})
(map #(select-keys % [:caplen :decoded :decode-error]))
(take 2)
doall)
(require '[paclo.core :as core])
(->> (core/packets {:device "en0"
:filter (core/bpf [:and [:udp] [:port 53]])
:timeout-ms 50})
(take 10)
doall)
(core/reduce-packets
{:path "large.pcap"
:decode? true
:max Long/MAX_VALUE
:max-time-ms 3600000
:xform (keep #(get-in % [:decoded :l3 :flow-key]))}
(fn [counts flow]
(update counts flow (fnil inc 0)))
{})
The reducer may return (reduced value) to stop capture immediately. This
path avoids the producer future, blocking queue, and lazy-seq nodes used by
packets; use packets when interactive lazy consumption is more useful.
For live overload experiments, packets also accepts a bounded dropping
queue. Blocking remains the default and preserves existing behavior:
(core/packets
{:device "en0"
:queue-cap 4096
:queue-mode :dropping
:on-queue-stats println})
The callback receives final enqueued, dropped, blocking, and maximum-depth counters. A dropping queue never returns dropped packets to the consumer.
(require '[paclo.core :as core])
(core/write-pcap! [(byte-array (repeat 60 (byte 0)))
{:bytes (byte-array (repeat 60 (byte -1)))
:sec 1700000000
:usec 123456}]
"out.pcap")
(core/bpf [:and [:ipv6] [:udp] [:dst-port-range 8000 9000]])
;; => "(ip6) and (udp) and (dst portrange 8000-9000)"
(core/bpf [:and [:net "10.0.0.0/8"] [:not [:port 22]]])
;; => "(net 10.0.0.0/8) and (not (port 22))"
(require '[paclo.core :as core]
'[paclo.proto.dns-ext :as dns-ext])
(dns-ext/register!)
(->> (core/packets {:path "test/resources/dns-sample.pcap"
:decode? true})
(take 1)
doall)
See docs/extensions.md for hook contract and TLS/DNS extension notes.
Paclo ships practical CLI examples under dev/examples.
Use README.md as the command index, and use this guide for API behavior.
:decode? true does not throw on parse failure.:decode-error in each packet map.:filter type) throw ex-info.:xform transducers in packets for early map/filter and lower allocation.reduce-packets to fuse transformation and reduction
without full materialization../cljdoc-api-contract.md./extensions.md./ROADMAP.mdCan you improve this documentation? These fine people already did:
nanto & NantoEdit on GitHub
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |