Liking cljdoc? Tell your friends :D

paclo.pcap


breakloop!clj

(breakloop! pcap)
source

bytes-seq->pcap!clj

(bytes-seq->pcap! packets
                  {:keys [out linktype snaplen]
                   :or {linktype DLT_EN10MB snaplen 65536}})

バイト列のシーケンスを PCAP に書き出す。 packets: シーケンス。要素は byte-array または {:bytes <ba> :sec <long> :usec <long>} opts: {:out "out.pcap" :linktype DLT_* :snaplen 65536}

バイト列のシーケンスを PCAP に書き出す。
packets: シーケンス。要素は `byte-array` または
         `{:bytes <ba> :sec <long> :usec <long>}`
opts: {:out "out.pcap" :linktype DLT_* :snaplen 65536}
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)

ライブでキャプチャして out.pcap に保存。 opts: {:device "en0" :filter "tcp port 80" ; 省略可 :max 100 ; 取れたパケット数がこの件数に達したら終了 :snaplen 65536 :promiscuous? true :timeout-ms 10 ; pcap_next_ex のタイムアウト :max-time-ms 10000 ; 壁時計タイム上限(ms) :idle-max-ms 3000} ; 連続アイドル上限(ms)

ライブでキャプチャして out.pcap に保存。
opts:
{:device "en0"
 :filter "tcp port 80"     ; 省略可
 :max 100                    ; 取れたパケット数がこの件数に達したら終了
 :snaplen 65536
 :promiscuous? true
 :timeout-ms 10              ; pcap_next_ex のタイムアウト
 :max-time-ms 10000          ; 壁時計タイム上限(ms)
 :idle-max-ms 3000}          ; 連続アイドル上限(ms)
sourceraw docstring

capture->seqclj

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

パケットを lazy-seq で返す高レベルAPI。 opts:

  • ライブ: {:device "en1" :filter "tcp" :snaplen 65536 :promiscuous? true :timeout-ms 10}
  • オフライン: {:path "sample.pcap" :filter "..."}
  • 共有停止条件(指定なければ安全な既定値で自動手仕舞い): :max <int> ; 取得最大件数(default 100) :max-time-ms <int> ; 経過時間上限(default 10000) :idle-max-ms <int> ; 無通信連続上限(default 3000)
  • 内部キュー: :queue-cap <int> ; バックグラウンド→呼び出し側のバッファ(default 1024)
  • エラー処理: :on-error (fn [throwable]) ; 背景スレッドで例外発生時に呼ばれる(任意) :error-mode :throw|:pass ; 既定 :throw(lazy側に再スロー)/:pass はスキップ
  • ★停止条件フック(新規): :stop? (fn [pkt] boolean) ; 受信pktを見て true なら即 stop(breakloop!)

返り値: lazy-seq of packet-maps (loop! ハンドラで渡している {:ts-sec … :bytes …})

パケットを lazy-seq で返す高レベルAPI。
opts:
- ライブ:  {:device "en1" :filter "tcp" :snaplen 65536 :promiscuous? true :timeout-ms 10}
- オフライン: {:path "sample.pcap" :filter "..."}
- 共有停止条件(指定なければ安全な既定値で自動手仕舞い):
    :max <int>               ; 取得最大件数(default 100)
    :max-time-ms <int>       ; 経過時間上限(default 10000)
    :idle-max-ms <int>       ; 無通信連続上限(default 3000)
- 内部キュー:
    :queue-cap <int>         ; バックグラウンド→呼び出し側のバッファ(default 1024)
- エラー処理:
    :on-error (fn [throwable])   ; 背景スレッドで例外発生時に呼ばれる(任意)
    :error-mode :throw|:pass     ; 既定 :throw(lazy側に再スロー)/:pass はスキップ
- ★停止条件フック(新規):
    :stop? (fn [pkt] boolean)    ; 受信pktを見て true なら即 stop(breakloop!)

返り値: lazy-seq of packet-maps (loop! ハンドラで渡している {:ts-sec … :bytes …})
sourceraw docstring

close!clj

(close! pcap)
source

close-dumper!clj

(close-dumper! dumper)
source

DLT_EN10MBclj

source

dump!clj

(dump! dumper hdr data)
source

flush-dumper!clj

(flush-dumper! dumper)
source

list-devicesclj

(list-devices)

利用可能デバイスの簡易一覧。macOSでは networksetup で desc を補完する。

  • name が空/空白のエントリはスキップ
  • desc が空/空白なら fallback を適用
利用可能デバイスの簡易一覧。macOSでは networksetup で desc を補完する。
- name が空/空白のエントリはスキップ
- desc が空/空白なら fallback を適用
sourceraw docstring

lookupnetclj

(lookupnet dev)

デバイス名 dev のネットワークアドレス/マスクを取得。 成功: {:net int :mask int} 失敗: ex-info(:phase :lookupnet を含む)

デバイス名 dev のネットワークアドレス/マスクを取得。
成功: {:net int :mask int}
失敗: ex-info(:phase :lookupnet を含む)
sourceraw docstring

loop!clj

(loop! pcap handler)

pcap_next_ex をポーリング。handlerは (fn {:ts-sec :ts-usec :caplen :len :bytes}) を受け取る。 終端: rc<0(pcap EOF/err)で終了。

pcap_next_ex をポーリング。handlerは (fn {:ts-sec :ts-usec :caplen :len :bytes}) を受け取る。
終端: rc<0(pcap EOF/err)で終了。
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]})

開始から duration-ms 経過したら停止(壁時計基準)。 オプション: {:idle-max-ms <ms> :timeout-ms <ms>} 例: (loop-for-ms! h 3000 handler) (loop-for-ms! h 3000 handler {:idle-max-ms 1000 :timeout-ms 50})

開始から duration-ms 経過したら停止(壁時計基準)。
オプション: {:idle-max-ms <ms> :timeout-ms <ms>}
例: (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]})

pcap_next_ex を最大 n 件処理して停止。 オプション: {:idle-max-ms <ms> :timeout-ms <ms>} 例: (loop-n! h 10 handler) ; 従来どおり (loop-n! h 10 handler {:idle-max-ms 3000 :timeout-ms 100})

pcap_next_ex を最大 n 件処理して停止。
オプション: {:idle-max-ms <ms> :timeout-ms <ms>}
例: (loop-n! h 10 handler) ; 従来どおり
    (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?]} handler)

n件到達 or duration-ms 経過の早い方で停止。 conf: {:n <long> :ms <long> :idle-max-ms <ms-optional> :timeout-ms <ms-optional> :stop? <fn-optional>}

n件到達 or duration-ms 経過の早い方で停止。
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)

生成用の pcap ハンドルを作る(linktype は DLT_*、snaplen 既定 65536)

生成用の pcap ハンドルを作る(linktype は DLT_*、snaplen 既定 65536)
sourceraw docstring

open-dumperclj

(open-dumper pcap path)
source

open-liveclj

(open-live {:keys [device snaplen promiscuous? timeout-ms netmask]
            :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

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]})

デバイスを開いて、必要ならBPFを設定して、duration-msだけ処理して閉じる。 追加オプション: {:idle-max-ms <ms>} 例: (run-live-for-ms! {:device "en1" :timeout-ms 50} 5000 handler {:idle-max-ms 1000})

デバイスを開いて、必要ならBPFを設定して、duration-msだけ処理して閉じる。
追加オプション: {:idle-max-ms <ms>}
例: (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-live-for-ms! と同等の処理を行い、サマリを返す。 例: (run-live-for-ms-summary! {:device "en0" :filter "tcp" :timeout-ms 50} 3000 (fn [_]) {:idle-max-ms 1000})

run-live-for-ms! と同等の処理を行い、サマリを返す。
例: (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]})

デバイスを開いて、必要ならBPFを設定して、n件だけ処理して閉じる。 追加オプション: :idle-max-ms (:timeout-ms は open-live と共有) 例: (run-live-n! {:device "en1" :filter "tcp" :timeout-ms 100} 50 handler {:idle-max-ms 3000})

デバイスを開いて、必要ならBPFを設定して、n件だけ処理して閉じる。
追加オプション: :idle-max-ms (:timeout-ms は open-live と共有)
例: (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-live-n! と同等の処理を行い、サマリを返す。 例: (run-live-n-summary! {:device "en0" :filter "udp" :timeout-ms 50} 100 (fn [_]) {:idle-max-ms 3000})

run-live-n! と同等の処理を行い、サマリを返す。
例: (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)

pcap に BPF を適用。optimize=1、netmask=0(未知時)で apply-filter! に委譲。成功で true。

pcap に BPF を適用。optimize=1、netmask=0(未知時)で apply-filter! に委譲。成功で true。
sourceraw docstring

set-bpf-on-device!clj

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

デバイス dev の netmask を lookup して BPF を適用(内部で set-bpf-with-netmask!)。成功で true。

デバイス dev の netmask を lookup して BPF を適用(内部で set-bpf-with-netmask!)。成功で true。
sourceraw docstring

set-bpf-with-netmask!clj

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

pcap に BPF を適用。optimize=1、netmask 明示で apply-filter! に委譲。成功で true。

pcap に BPF を適用。optimize=1、netmask 明示で apply-filter! に委譲。成功で true。
sourceraw docstring

vlan-tag->strclj

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

VLANタグマップ {:tpid .. :vid .. :pcp .. :dei ..} を表示用文字列にする。

VLANタグマップ {:tpid .. :vid .. :pcp .. :dei ..} を表示用文字列にする。
sourceraw docstring

with-dumpercljmacro

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

例: (with-dumper [d (open-dumper h "out.pcap")] (dump! d hdr data))

例: (with-dumper [d (open-dumper h "out.pcap")]
(dump! d hdr data))
sourceraw docstring

with-livecljmacro

(with-live [sym opts] & body)

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

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

with-offlinecljmacro

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

例: (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))

例:
(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)

例: (with-pcap [h (open-live {:device "en0"})] (loop-n! h 10 prn))

例: (with-pcap [h (open-live {:device "en0"})]
(loop-n! h 10 prn))
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