Discussion:
How to record plain text in a pcap file?
Darren Reed
2011-04-05 05:09:38 UTC
Permalink
Is there a DLT type for "plain text"?

That is, can I record or insert text based comments or other data to a
pcap file?

Why could or would this be significant?

Well, if I was using DLT_PPI that allows multiple types of packets to be
recorded in a single file, why can't one of those DLT's be one that says
"this is plain text, not a packet"?

Darren
Guy Harris
2011-04-05 06:09:57 UTC
Permalink
Post by Darren Reed
Is there a DLT type for "plain text"?
No.
Post by Darren Reed
That is, can I record or insert text based comments or other data to a pcap file?
No, but you can record them in a pcap-NG file.

The tradeoffs:

With LINKTYPE_PPI+LINKTYPE_TEXT, with no changes, Wireshark will report the LINKTYPE_TEXT packets as an unknown encapsulation, and just show the raw hex and ASCII for the text, which is an ugly UI, but you can at least see the text; with pcap-NG, Wireshark would have to be changed to report the information.

With LINKTYPE_PPI+LINKTYPE_TEXT, with no changes, tcpdump, and probably at least some other libpcap/WinPcap-based programs, will reject the file as unreadable; with pcap-NG, libpcap-based programs using libpcap 1.1 or later (if dynamically-linked, even if they weren't built with libpcap 1.1) will read the file and just ignore the text comments.

With LINKTYPE_PPI+LINKTYPE_TEXT, if you *did* add LINKTYPE_PPI and LINKTYPE_TEXT support to libpcap/WinPcap-based programs such as tcpdump, they'd be able to handle the comments and even report them, as long as the libpcap/WinPcap they're using is recent enough not to throw up if you give even an empty filter string to pcap_compile() with a LINKTYPE_PPI capture, so it'd work with current versions of libpcap and WinPcap; with pcap-NG, in order to have libpcap/WinPcap-based programs report the text comments, we'd need to add APIs that expose the full capabilities of pcap-NG to libpcap/WinPcap, modify the programs to use those APIs and report the comments, and build them against and run them with a libpcap/WinPcap that supports the new APIs.

With LINKTYPE_PPI+LINKTYPE_TEXT, if you want to use libpcap/WinPcap filters on the capture in a libpcap/WinPcap-based program, the libpcap/WinPcap filtering code would have to be modified, possibly significantly, to handle a file where the *actual* encapsulation (as opposed to the "envelope" encapsulation of LINKTYPE_PPI) differs from packet to packet, even if it's just differing between some actual linktype and LINKTYPE_TEXT; with pcap-NG, libpcap filters will Just Work with no API changes or code changes with a libpcap that handles pcap-NG (which will reject mixed link-layer types, so that's not an issue).

With LINKTYPE_PPI+LINKTYPE_TEXT, we have a solution to a particular problem, with a bit of a special-purpose hack (LINKTYPE_TEXT isn't very useful by itself, it's only useful with LINKTYPE_PPI); with pcap-NG, we have something that's a bit cleaner and more cleanly extensible.-
This is the tcpdump-workers list.
Visit https://cod.sandelman.ca/ to unsubscribe.
Darren Reed
2011-04-05 18:41:34 UTC
Permalink
Post by Guy Harris
Post by Darren Reed
Is there a DLT type for "plain text"?
No.
Post by Darren Reed
That is, can I record or insert text based comments or other data to a pcap file?
No, but you can record them in a pcap-NG file.
My reading of your list of tradeoffs is that even for pcap-NG,
LINKTYPE_TEXT is required as it has no other way to record text (no
comment fields, for example, attached to packet blocks.)

The handling of the presence of LINKTYPE_TEXT will be the same for any
other link type that is unknown to the tools that encounter it, so
there's nothing new or special about that.

For that matter, it may be worthwhile improving the failure modes of
tcpdump, if only in dealing with LINKTYPE_PPI.

So I'll ask, does anyone think that LINKTYPE_TEXT should not be added?

Darren
Guy Harris
2011-04-05 19:37:21 UTC
Permalink
My reading of your list of tradeoffs is that even for pcap-NG, LINKTYPE_TEXT is required as it has no other way to record text (no comment fields, for example, attached to packet blocks.)
Actually, yes, it does - just about every block can have options attached to it, including Enhanced Packet Blocks:

http://www.winpcap.org/ntar/draft/PCAP-DumpFileFormat.html#sectionepb

(but not Simple Packet Blocks, but those don't even have timestamps, so they can't be used if your goal is to have a superset of pcap format's capabilities), and one of the options supported by all blocks that allow options is the Comment option:

http://www.winpcap.org/ntar/draft/PCAP-DumpFileFormat.html#sectionopt

which allows you to attach a UTF-8 string to the block.
The handling of the presence of LINKTYPE_TEXT will be the same for any other link type that is unknown to the tools that encounter it, so there's nothing new or special about that.
Nothing special, but tcpdump's handling of link types it doesn't understand is to reject the entire file - and LINKTYPE_PPI is one of the link types it doesn't understand, and I suspect that few if any other programs that read pcap files handle more types than tcpdump. A Google Code search for DLT_PPI didn't find anything, and a search for LINKTYPE_PPI found LINKTYPE_PPI_HDR in aircrack-ng, but the code appears to assume that *every* packet in a LINKTYPE_PPI file is an 802.11 packet preceded by a PPI header, without even looking at the LINKTYPE_ value in the PPI header; there's a comment referring to Kismet, so it might be able to read and write PPI, but it might also just be using it as an 802.11 metadata header rather than as a "meta-packet" header.
For that matter, it may be worthwhile improving the failure modes of tcpdump, if only in dealing with LINKTYPE_PPI.
There's not much you can do about the failure mode for handling an unknown link-layer header type; the only way to improve tcpdump's handling of LINKTYPE_PPI would be to add support for decoding and printing it, which might be a good idea, but note that you're not going to have much success with using filters on those files without the significant - and a bit ugly - changes to the way filtering is done.
So I'll ask, does anyone think that LINKTYPE_TEXT should not be added?
I think it should only be added if the goal is to quickly get something that Wireshark can sort-of handle and nobody cares whether any other tools will be able to read the files that have comments any time soon (and if I don't have to do any of the work, as, if I'm going to work on comment support in capture files, I'd rather work on adding a new API to libpcap that can let applications get the entire contents of all block types in a pcap-NG file and modifying tcpdump to use it if available). Otherwise, I'd vote for adding support for comments to Wireshark, adding the new APIs to libpcap, and modifying tcpdump to use them if available, complete with either always printing the comments or having an option to request the comments (although *that* change means we might want to consider another change, namely converting tcpdump to use getopt_long() - 1973 called, it wants its command-line flag conventions back).-
This is the tcpdump-workers list.
Visit https://cod.sandelman.ca/ to unsubscribe.

Loading...