Skip to content

Commit ec8db0d

Browse files
pcap: add support (#817)
1 parent aac6f1c commit ec8db0d

4 files changed

Lines changed: 17 additions & 2 deletions

File tree

‎internal/magic/binary.go‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,3 +272,15 @@ func Pyc(raw []byte, limit uint32) bool {
272272

273273
return false
274274
}
275+
276+
// Pcap identifies "libpcap" capture files.
277+
// https://www.tcpdump.org/manpages/pcap-savefile.5.html
278+
func Pcap(raw []byte, _ uint32) bool {
279+
if len(raw) < 4 {
280+
return false
281+
}
282+
be := binary.BigEndian.Uint32(raw)
283+
le := binary.LittleEndian.Uint32(raw)
284+
return be == 0xa1b2c3d4 || be == 0xa1b23c4d ||
285+
le == 0xa1b2c3d4 || le == 0xa1b23c4d
286+
}

‎mimetype_test.go‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,7 @@ a,"b`,
293293
{"odc", "PK\x03\x04\x14\x00\x00\x08\x00\x00zp2R\xab\xb8\xb2l(\x00\x00\x00(\x00\x00\x00\x08\x00\x00\x00mimetypeapplication/vnd.oasis.opendocument.chart", "application/vnd.oasis.opendocument.chart", one},
294294
{"owl", `<?xml version="1.0"?><Ontology xmlns="http://www.w3.org/2002/07/owl#">`, "application/owl+xml", one},
295295
{"pat", "\x00\x00\x00\x1c\x00\x00\x00\x01\x00\x00\x00\x01\x00\x00\x00\x01\x00\x00\x00\x03GPAT", "image/x-gimp-pat", one},
296+
{"pcap", "\xd4\xc3\xb2\xa1", "application/vnd.tcpdump.pcap", none},
296297
{"pdf", "%PDF-", "application/pdf", all},
297298
{"php", "#!/usr/bin/env php", "text/x-php", one},
298299
{"pl", "#!/usr/bin/perl", "text/x-perl", one},

‎supported_mimes.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
## 202 Supported MIME types
1+
## 203 Supported MIME types
22
This file is automatically generated when running tests. Do not edit manually.
33

44
Extension | MIME type <br> Aliases | Hierarchy
@@ -158,6 +158,7 @@ Extension | MIME type <br> Aliases | Hierarchy
158158
**.fm** | **application/vnd.framemaker** | fm>root
159159
**.bufr** | **application/bufr** | bufr>root
160160
**.pyc** | **application/x-bytecode.python** | pyc>root
161+
**.pcap** | **application/vnd.tcpdump.pcap** | pcap>root
161162
**.mp3** | **audio/mpeg** <br> audio/x-mpeg, audio/mp3 | mp3>root
162163
**.txt** | **text/plain** | txt>root
163164
**.svg** | **image/svg+xml** | svg>txt>root

‎tree.go‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ var root = newMIME("application/octet-stream", "",
2424
woff2, otf, ttc, eot, wasm, shx, dbf, dcm, rar, djvu, mobi, lit, bpg, cbor,
2525
sqlite3, dwg, nes, lnk, macho, qcp, icns, hdr, mrc, mdb, accdb, zstd, cab,
2626
rpm, xz, lzip, torrent, cpio, tzif, xcf, pat, gbr, glb, cabIS, jxr, parquet,
27-
oneNote, chm, wpd, dxf, grib, zlib, inf, hlp, fm, bufr, pyc,
27+
oneNote, chm, wpd, dxf, grib, zlib, inf, hlp, fm, bufr, pyc, pcap,
2828
// MP3 is late because it does a linear search in the input. That means
2929
// containers that embed an MP3, for example: an mp4 file, or a zip without
3030
// compression, would pass as MP3s.
@@ -302,4 +302,5 @@ var (
302302
hlp = newMIME("application/x-os2-hlp", ".hlp", magic.Hlp)
303303
fm = newMIME("application/vnd.framemaker", ".fm", magic.FrameMaker)
304304
bufr = newMIME("application/bufr", ".bufr", magic.BUFR)
305+
pcap = newMIME("application/vnd.tcpdump.pcap", ".pcap", magic.Pcap)
305306
)

0 commit comments

Comments
 (0)