Liking cljdoc? Tell your friends :D

paclo.pcap


breakloop!clj

(breakloop! pcap)
source

bytes-seq->pcap!clj

(bytes-seq->pcap! packets {:keys [out] :as opts})

Write byte-arrays or packet maps as single-DLT Classic PCAP (microseconds). Validate explicit framing, timestamps and lengths before each record. opts: {:out "out.pcap" :linktype native-DLT :snaplen 65536}. Failure can leave partial output; output is not atomic.

Write byte-arrays or packet maps as single-DLT Classic PCAP (microseconds).
Validate explicit framing, timestamps and lengths before each record.
opts: {:out "out.pcap" :linktype native-DLT :snaplen 65536}.
Failure can leave partial output; output is not atomic.
sourceraw docstring

call-with-cleanupclj

(call-with-cleanup body cleanups)

Run body, then every cleanup in order. Preserve the first failure and attach subsequent cleanup failures as suppressed exceptions.

Run body, then every cleanup in order. Preserve the first failure and
attach subsequent cleanup failures as suppressed exceptions.
sourceraw docstring

capture->pcapclj

(capture->pcap {:keys [device filter max snaplen promiscuous? timeout-ms
                       max-time-ms idle-max-ms]
                :or {max 100
                     snaplen 65536
                     promiscuous? true
                     timeout-ms 10
                     max-time-ms 10000
                     idle-max-ms 3000}}
               out)

Capture live packets and save them to out.pcap. opts: {:device "en0" :filter "tcp port 80" ; optional :max 100 ; stop when captured count reaches this value :snaplen 65536 :promiscuous? true :timeout-ms 10 ; pcap_next_ex timeout :max-time-ms 10000 ; wall-clock max duration (ms) :idle-max-ms 3000} ; continuous idle max (ms)

Capture live packets and save them to out.pcap.
opts:
{:device "en0"
 :filter "tcp port 80"     ; optional
 :max 100                    ; stop when captured count reaches this value
 :snaplen 65536
 :promiscuous? true
 :timeout-ms 10              ; pcap_next_ex timeout
 :max-time-ms 10000          ; wall-clock max duration (ms)
 :idle-max-ms 3000}          ; continuous idle max (ms)
sourceraw docstring

capture->seqclj

(capture->seq {:keys [device path filter snaplen promiscuous? timeout-ms
                      buffer-size immediate? max max-time-ms idle-max-ms
                      queue-cap queue-mode on-error error-mode on-ready on-stats
                      on-queue-stats stop?]
               :or {snaplen 65536
                    promiscuous? true
                    timeout-ms 10
                    error-mode :throw
                    queue-mode :blocking}})

High-level API that returns packets as a lazy sequence. opts:

  • live: {:device "en1" :filter "tcp" :snaplen 65536 :promiscuous? true :timeout-ms 10} :buffer-size <bytes> ; opt-in pcap_create buffer size :immediate? <boolean> ; opt-in immediate delivery
  • offline: {:path "sample.pcap" :filter "..."}
  • shared stop conditions (safe defaults when omitted): :max <int> ; max packet count (default 100) :max-time-ms <int> ; max elapsed time (default 10000) :idle-max-ms <int> ; max continuous idle time (default 3000)
  • internal queue: :queue-cap <int> ; producer -> consumer buffer (default 1024) :queue-mode :blocking|:dropping ; default :blocking :on-queue-stats (fn [stats]) ; optional final queue counters
  • error handling: :on-error (fn [throwable]) ; optional callback on background thread errors :error-mode :throw|:pass ; default :throw, :pass skips background errors
  • live diagnostics: :on-ready (fn []) ; optional callback after open/filter setup :on-stats (fn [stats]) ; optional callback with final pcap_stats counters
  • stop hook: :stop? (fn [pkt] boolean) ; stop immediately when true (breakloop!)

Returns a lazy seq of packet maps with no close/cancel operation. Abandoning a full blocking queue can retain the producer and native handle indefinitely; count/time/predicate checks cannot interrupt a blocked packet put. Prefer synchronous reduction or the public managed capture for early termination.

High-level API that returns packets as a lazy sequence.
opts:
- live:    {:device "en1" :filter "tcp" :snaplen 65536 :promiscuous? true :timeout-ms 10}
    :buffer-size <bytes>     ; opt-in pcap_create buffer size
    :immediate? <boolean>    ; opt-in immediate delivery
- offline: {:path "sample.pcap" :filter "..."}
- shared stop conditions (safe defaults when omitted):
    :max <int>               ; max packet count (default 100)
    :max-time-ms <int>       ; max elapsed time (default 10000)
    :idle-max-ms <int>       ; max continuous idle time (default 3000)
- internal queue:
    :queue-cap <int>         ; producer -> consumer buffer (default 1024)
    :queue-mode :blocking|:dropping ; default :blocking
    :on-queue-stats (fn [stats])    ; optional final queue counters
- error handling:
    :on-error (fn [throwable])   ; optional callback on background thread errors
    :error-mode :throw|:pass     ; default :throw, :pass skips background errors
- live diagnostics:
    :on-ready (fn [])            ; optional callback after open/filter setup
    :on-stats (fn [stats])       ; optional callback with final pcap_stats counters
- stop hook:
    :stop? (fn [pkt] boolean)    ; stop immediately when true (breakloop!)

Returns a lazy seq of packet maps with no close/cancel operation. Abandoning
a full blocking queue can retain the producer and native handle indefinitely;
count/time/predicate checks cannot interrupt a blocked packet put. Prefer
synchronous reduction or the public managed capture for early termination.
sourceraw docstring

capture-statsclj

(capture-stats pcap)

Return portable libpcap counters for a live capture handle.

The counters are cumulative for the handle: :received, :dropped, and :interface-dropped. Throws ex-info when libpcap cannot provide statistics.

Return portable libpcap counters for a live capture handle.

The counters are cumulative for the handle:
`:received`, `:dropped`, and `:interface-dropped`.
Throws `ex-info` when libpcap cannot provide statistics.
sourceraw docstring

close!clj

(close! pcap)
source

close-after-error!clj

(close-after-error! handle error)

Close an owned handle without masking an earlier failure.

Close an owned handle without masking an earlier failure.
sourceraw docstring

close-dumper!clj

(close-dumper! dumper)
source

(datalink pcap)

Return the nonnegative DLT for an offline or activated live handle. Throws on native failure; never infers Ethernet. The caller owns the handle.

Return the nonnegative DLT for an offline or activated live handle.
Throws on native failure; never infers Ethernet. The caller owns the handle.
sourceraw docstring

DLT_EN10MBclj

source

dump!clj

(dump! dumper hdr data)
source

flush-dumper!clj

(flush-dumper! dumper)
source

initialize-handleclj

(initialize-handle handle initialize)

Own a newly acquired handle until initialize returns successfully. On failure close once, retaining the original cause and suppressed cleanup error.

Own a newly acquired handle until initialize returns successfully.
On failure close once, retaining the original cause and suppressed cleanup error.
sourceraw docstring

list-devicesclj

(list-devices)

Return a simple list of available devices. On macOS, fills missing descriptions using networksetup.

  • skips entries with blank names
  • applies fallback when description is blank
Return a simple list of available devices.
On macOS, fills missing descriptions using networksetup.
- skips entries with blank names
- applies fallback when description is blank
sourceraw docstring

lookupnetclj

(lookupnet dev)

Resolve network address/mask for device dev. Success: {:net int :mask int} Failure: throws ex-info with :phase :lookupnet.

Resolve network address/mask for device `dev`.
Success: {:net int :mask int}
Failure: throws ex-info with :phase :lookupnet.
sourceraw docstring

loop!clj

(loop! pcap handler)
(loop! pcap handler linktype)

Poll pcap_next_ex. handler receives maps with :ts-sec, :ts-usec, :caplen, :len, :bytes, :linktype. Terminates when rc<0 (EOF/error).

Poll `pcap_next_ex`.
`handler` receives maps with :ts-sec, :ts-usec, :caplen, :len, :bytes, :linktype.
Terminates when rc<0 (EOF/error).
sourceraw docstring

loop-for-ms!clj

(loop-for-ms! pcap duration-ms handler)
(loop-for-ms! pcap duration-ms handler {:keys [idle-max-ms timeout-ms]})

Stop after duration-ms elapsed (wall-clock). Options: {:idle-max-ms <ms> :timeout-ms <ms>} Example: (loop-for-ms! h 3000 handler) (loop-for-ms! h 3000 handler {:idle-max-ms 1000 :timeout-ms 50})

Stop after duration-ms elapsed (wall-clock).
Options: {:idle-max-ms <ms> :timeout-ms <ms>}
Example: (loop-for-ms! h 3000 handler)
    (loop-for-ms! h 3000 handler {:idle-max-ms 1000 :timeout-ms 50})
sourceraw docstring

loop-n!clj

(loop-n! pcap n handler)
(loop-n! pcap n handler {:keys [idle-max-ms timeout-ms]})

Process up to n packets via pcap_next_ex, then stop. Options: {:idle-max-ms <ms> :timeout-ms <ms>} Example: (loop-n! h 10 handler) ; default behavior (loop-n! h 10 handler {:idle-max-ms 3000 :timeout-ms 100})

Process up to n packets via pcap_next_ex, then stop.
Options: {:idle-max-ms <ms> :timeout-ms <ms>}
Example: (loop-n! h 10 handler) ; default behavior
    (loop-n! h 10 handler {:idle-max-ms 3000 :timeout-ms 100})
sourceraw docstring

loop-n-or-ms!clj

(loop-n-or-ms! pcap
               {:keys [n ms idle-max-ms timeout-ms stop?] :as opts}
               handler)

Stop when either n packets are processed or duration-ms is reached. conf: {:n <long> :ms <long> :idle-max-ms <ms-optional> :timeout-ms <ms-optional> :stop? <fn-optional>}

Stop when either n packets are processed or duration-ms is reached.
conf: {:n <long> :ms <long> :idle-max-ms <ms-optional> :timeout-ms <ms-optional> :stop? <fn-optional>}
sourceraw docstring

open-deadclj

(open-dead)
(open-dead linktype snaplen)

Create a dead pcap handle for generation/writing. linktype uses DLT_* constants. Default snaplen is 65536.

Create a dead pcap handle for generation/writing.
`linktype` uses DLT_* constants. Default snaplen is 65536.
sourceraw docstring

open-dumperclj

(open-dumper pcap path)
source

open-liveclj

(open-live {:keys [device snaplen promiscuous? timeout-ms netmask buffer-size
                   immediate?]
            :or {snaplen 65536 promiscuous? true timeout-ms 10}
            :as opts})
source

open-offlineclj

(open-offline path)
(open-offline path opts)
source

PCAP_ERRBUF_SIZEclj

source

PCAP_PKTHDR_BYTESclj

source

rc->statusclj

(rc->status rc)

Classify pcap_next_ex return code. 1 => :packet, 0 => :timeout, -2 => :eof, anything else => :error.

Classify pcap_next_ex return code.
1 => :packet, 0 => :timeout, -2 => :eof, anything else => :error.
sourceraw docstring

rc->status-detailclj

(rc->status-detail rc)

Return a map {:rc rc :status <kw> :summary <string|nil>} that is convenient for logging when pcap_next_ex finishes with EOF (-2) or an error (-1/others).

Return a map {:rc rc :status <kw> :summary <string|nil>} that is convenient for
logging when pcap_next_ex finishes with EOF (-2) or an error (-1/others).
sourceraw docstring

reduce-captureclj

(reduce-capture opts rf init)

Synchronously reduce live or offline packets without a queue or lazy seq.

This is an internal primitive. It accepts the same source, filtering, stopping, error, and final-statistics options as capture->seq. The reducing function may return reduced for immediate early termination.

Synchronously reduce live or offline packets without a queue or lazy seq.

This is an internal primitive. It accepts the same source, filtering,
stopping, error, and final-statistics options as `capture->seq`. The
reducing function may return `reduced` for immediate early termination.
sourceraw docstring

reduce-capture-reportclj

(reduce-capture-report
  {:keys [device path filter snaplen promiscuous? timeout-ms buffer-size
          immediate? max max-time-ms idle-max-ms on-error error-mode on-ready
          on-stats stop?]
   :or {snaplen 65536 promiscuous? true timeout-ms 10 error-mode :throw}}
  rf
  init)

Synchronously reduce packets and return both the accumulator and execution statistics. This is the internal reporting primitive behind the public paclo.core/reduce-packets-report API.

Synchronously reduce packets and return both the accumulator and execution
statistics. This is the internal reporting primitive behind the public
`paclo.core/reduce-packets-report` API.
sourceraw docstring

run-live-for-ms!clj

(run-live-for-ms! opts duration-ms handler)
(run-live-for-ms! {:keys [device filter snaplen promiscuous? timeout-ms]
                   :or {snaplen 65536 promiscuous? true timeout-ms 10}}
                  duration-ms
                  handler
                  {:keys [idle-max-ms]})

Open live capture, optionally apply BPF, process for duration-ms, then close. Additional option: {:idle-max-ms <ms>} Example: (run-live-for-ms! {:device "en1" :timeout-ms 50} 5000 handler {:idle-max-ms 1000})

Open live capture, optionally apply BPF, process for duration-ms, then close.
Additional option: {:idle-max-ms <ms>}
Example: (run-live-for-ms! {:device "en1" :timeout-ms 50}
                      5000
                      handler
                      {:idle-max-ms 1000})
sourceraw docstring

run-live-for-ms-summary!clj

(run-live-for-ms-summary! opts duration-ms handler)
(run-live-for-ms-summary! opts duration-ms handler loop-opts)

Run run-live-for-ms! and return a summary map. Example: (run-live-for-ms-summary! {:device "en0" :filter "tcp" :timeout-ms 50} 3000 (fn [_]) {:idle-max-ms 1000})

Run run-live-for-ms! and return a summary map.
Example: (run-live-for-ms-summary! {:device "en0" :filter "tcp" :timeout-ms 50} 3000 (fn [_]) {:idle-max-ms 1000})
sourceraw docstring

run-live-n!clj

(run-live-n! opts n handler)
(run-live-n! {:keys [device filter snaplen promiscuous? timeout-ms]
              :or {snaplen 65536 promiscuous? true timeout-ms 10}}
             n
             handler
             {:keys [idle-max-ms]})

Open live capture, optionally apply BPF, process n packets, then close. Additional option: :idle-max-ms (:timeout-ms is shared with open-live) Example: (run-live-n! {:device "en1" :filter "tcp" :timeout-ms 100} 50 handler {:idle-max-ms 3000})

Open live capture, optionally apply BPF, process n packets, then close.
Additional option: :idle-max-ms (:timeout-ms is shared with open-live)
Example: (run-live-n! {:device "en1" :filter "tcp" :timeout-ms 100}
                 50
                 handler
                 {:idle-max-ms 3000})
sourceraw docstring

run-live-n-summary!clj

(run-live-n-summary! opts n handler)
(run-live-n-summary! opts n handler loop-opts)

Run run-live-n! and return a summary map. Example: (run-live-n-summary! {:device "en0" :filter "udp" :timeout-ms 50} 100 (fn [_]) {:idle-max-ms 3000})

Run run-live-n! and return a summary map.
Example: (run-live-n-summary! {:device "en0" :filter "udp" :timeout-ms 50} 100 (fn [_]) {:idle-max-ms 3000})
sourceraw docstring

set-bpf!clj

(set-bpf! pcap expr)

Apply BPF with optimize=1 and netmask=0 (unknown). Returns true.

Apply BPF with optimize=1 and netmask=0 (unknown). Returns true.
sourceraw docstring

set-bpf-on-device!clj

(set-bpf-on-device! pcap dev expr)

Lookup device netmask for dev and apply BPF via set-bpf-with-netmask!. Returns true.

Lookup device netmask for `dev` and apply BPF via set-bpf-with-netmask!.
Returns true.
sourceraw docstring

set-bpf-with-netmask!clj

(set-bpf-with-netmask! pcap expr netmask)

Apply BPF with optimize=1 and explicit netmask. Returns true.

Apply BPF with optimize=1 and explicit netmask. Returns true.
sourceraw docstring

throwable->dataclj

(throwable->data error)
source

vlan-tag->strclj

(vlan-tag->str {:keys [tpid vid pcp dei]})

Render VLAN tag map {:tpid .. :vid .. :pcp .. :dei ..} as a display string.

Render VLAN tag map {:tpid .. :vid .. :pcp .. :dei ..} as a display string.
sourceraw docstring

with-dumpercljmacro

(with-dumper [sym open-expr] & body)

Run body owning a dumper; flush and close even when either step fails.

Run body owning a dumper; flush and close even when either step fails.
sourceraw docstring

with-livecljmacro

(with-live [sym opts] & body)

Example: (with-live [h {:device "en0" :filter "tcp"}] (loop-n! h 10 prn))

Example: (with-live [h {:device "en0" :filter "tcp"}]
(loop-n! h 10 prn))
sourceraw docstring

with-offlinecljmacro

(with-offline [sym open-expr] & body)

Example: (with-offline [h (open-offline "dev/resources/fixtures/sample.pcap")] (loop-for-ms! h 2000 prn)) (with-offline [h (open-offline "dev/resources/fixtures/sample.pcap" {:filter "udp"})] (loop-n! h 50 prn))

Example:
(with-offline [h (open-offline "dev/resources/fixtures/sample.pcap")]
  (loop-for-ms! h 2000 prn))
(with-offline [h (open-offline "dev/resources/fixtures/sample.pcap" {:filter "udp"})]
  (loop-n! h 50 prn))
sourceraw docstring

with-pcapcljmacro

(with-pcap [sym open-expr] & body)

Run body owning a handle; close once without masking the body failure.

Run body owning a handle; close once without masking the body failure.
sourceraw docstring

writer-optionsclj

(writer-options opts)

Validate explicit single-DLT Classic PCAP options before acquiring resources. DLT-to-savefile support is checked by native pcap_dump_open.

Validate explicit single-DLT Classic PCAP options before acquiring resources.
DLT-to-savefile support is checked by native pcap_dump_open.
sourceraw docstring

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
←Move to previous article
→Move to next article
Ctrl+/Jump to the search field
× close