Joincap
Merge multiple pcap files together, gracefully.
Install / Use
/learn @assafmo/JoincapREADME
joincap
Merge multiple pcap files together, gracefully.
Installation
-
Download a precompiled binary from https://github.com/assafmo/joincap/releases
-
Or... Use
go get:go get -u github.com/assafmo/joincap -
Or use Ubuntu PPA:
curl -SsL https://assafmo.github.io/ppa/ubuntu/KEY.gpg | sudo apt-key add - sudo curl -SsL -o /etc/apt/sources.list.d/assafmo.list https://assafmo.github.io/ppa/ubuntu/assafmo.list sudo apt update sudo apt install joincap
Basic Usage
Usage:
joincap [OPTIONS] InFiles...
Application Options:
-v, --verbose Explain when skipping packets or entire input files
-V, --version Print the version and exit
-w= Sets the output filename. If the name is '-', stdout will be used (default: -)
-c= An integer argument for limiting the pcap size (default: 9223372036854775807)
-p=[micros|nanos] Sets timestamp precision (default: micros)
Help Options:
-h, --help Show this help message
Why?
I believe skipping corrupt packets is better than failing the entire merge job.
When using tcpslice or mergecap sometimes pcapfix is needed to fix bad input pcap files.
- One option is to try and run merge (
mergecap/tcpslice), if we get errors then runpcapfixon the bad pcaps and then run merge again.- Adds complexity (run -> check errors -> fix -> rerun)
- (If errors) Demands more resources (
pcapfixprocesses) - (If errors) Extends the total run time
- Another option is to run
pcapfixon the input pcap files and then merge.- Extends the total run time by a lot (read and write each pcap twice instead of once)
- Demands more storage (for the fixed pcaps)
- Demands more resources (
pcapfixprocesses)
- We can use
pcapfix"in memory" with process substitution:mergecap -w out.pcap <(pcapfix -o /dev/stdout 1.pcap) <(pcapfix -o /dev/stdout 2.pcap).- Adds complexity (build a complex command line)
- Demands more resources (
pcapfixprocesses) - Harder for us to use pathname expansion (e.g.
tcpslice -w out.pcap *.pcap) - We have to mind the command line character limit (in case of long pathnames)
- Doesn't work for
tcpslice(seeks the last packets to calculate time ranges - cannot do this with pipes)
Error handling: joincap vs mergecap vs tcpslice
Results
| Use case | joincap | mergecap v2.4.5 | tcpslice v1.2a3 | | ----------------------------------------------------------------------------------------------------- | ------------------ | ------------------ | ------------------ | | Corrupt input global header | :heavy_check_mark: | :x: | :x: | | Corrupt input packet header | :heavy_check_mark: | :x: | :x: | | Unexpectd EOF<br>(last packet data is truncated) | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | | Input pcap has no packets<br>(global header is ok, no first packet header) | :heavy_check_mark: | :heavy_check_mark: | :x: | | Input file size is smaller than 24 bytes<br>(global header is truncated) | :heavy_check_mark: | :heavy_check_mark: | :x: | | Input file size is between 24 and 40 bytes<br>(global header is ok, first packet header is truncated) | :heavy_check_mark: | :x: | :x: | | Input file doesn't exists | :heavy_check_mark: | :x: | :x: | | Input file is a directory | :heavy_check_mark: | :x: | :x: | | Input file end is garbage | :heavy_check_mark: | :heavy_check_mark: | :x: | | Input file is gzipped (.pcap.gz) | :heavy_check_mark: | :heavy_check_mark: | :x: |
Error outputs
| Use case | Error outputs |
| ----------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Corrupt input global header | <ul><li>tcpslice: bad tcpdump file test_pcaps/bad_global.pcap: archaic pcap savefile format</li><li>mergecap: The file "test_pcaps/bad_global.pcap" contains record data that mergecap doesn't support. (pcap: major version 0 unsupported)</li></ul> |
| Corrupt input packet header | <ul><li>tcpslice: Infinite loop?</li><li>mergecap: The file "test_pcaps/bad_first_header.pcap" appears to be damaged or corrupt. (pcap: File has 2368110654-byte packet, bigger than maximum of 262144)</li></ul> |
| Unexpectd EOF<br>(last packet data is truncated) | |
| Input pcap has no packets<br>(global header is ok, no first packet header) | <ul><li>tcpslice: Outputs empty pcap (Only global header)</li></ul> |
| Input file size is smaller than 24 bytes<br>(global header is truncated) | <ul><li>tcpslice: bad tcpdump file test_pcaps/empty: truncated dump file; tried to read 4 file header bytes, only got 0</li></ul> |
| Input file size is between 24 and 40 bytes<br>(global header is ok, first packet header is truncated) | <ul><li>tcpslice: bad status reading first packet in test_pcaps/partial_first_header.pcap: truncated dump file; tried to read 16 header bytes, only got 11</li><li>mergecap: The file "test_pcaps/partial_first_header.pcap" appears to have been cut short in the middle of a paket.</li></ul> |
| Input file doesn't exists | <ul><li>tcpslice: bad tcpdump file ./not_here: ./not_here: No such file or directory</li><li>mergecap: The file "./not_here" doesn't exist.</li></ul> |
| Input file is a directory | <ul><li>tcpslice: bad tcpdump file examples: error reading dump file: Is a directory</li><li>mergecap: "examples" is a directory (folder), not a file.</li></ul> |
| Input file end is garbage | <ul><li>tcpslice: problems finding end packet of file test_pcaps/bad_end.pcap</li></ul> |
| Input file is gzipped (.pcap.gz) | <ul><li>tcpslice: bad tcpdump file test_pcaps/ok.pcap.gz: unknown file format</li></ul> |
How to reproduce
| Use case
Related Skills
node-connect
345.9kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
106.4kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
345.9kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
345.9kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
