I have a project to add support for two new block types to Wireshark. This doesn't seem to be documented anywhere and so I'm hoping that my notes here may help someone in the future.

This is work in progress and so the notes here are not complete. Also, I'm using this as a notepad and I may make mistakes which I'll correct later. If you notice mistakes, please feel free to update this page.

PCAP-NG Block Basics

A PCAP-NG file contains blocks of data. Each block contains:

Block Types are grouped as follows:

I have requested two Standard Block Types for my project - see Appendix C below.

Within the groups of Block Types, there is a further sub-grouping:


The objective of the project is to add Wireshark support for the display, filtering, etc. of text log data (machine data). The data is presented to Wireshark in a PCAP-NG file that contains two new block types:

The initial data being used is Apache HTTPD Common format log records, but I'm designing the solution so that any format of log data can be supported. I've started with the Apache HTTPD log data as it is a fairly simple format; space separated variables in fixed columns.

Test PCAP-NG Generation

Of course, the above raises the question, "What creates the PCAP-NG file with the new blocks?". At this time I'm using the Babel function that comes with TribeLab Workbench. The project that should follow this one will be to write a Wiretap reader for log files.

Babel produces the PCAP-NG file like this:

    log_file -----------------------------------> TRBs
    apache-common.xml -----+--------------------> TSDB

An XML file describes the format of the log file. The XML is used to generate the TSDB, and some elements of it are used to help parse the log records to form TRBs.

NB: Although I'm using Babel to generate the file, anyone can use any tool to generate a suitable file. There is nothing proprietary about the TSDB or TRB formats.

Other points

I'm trying to add this support completely through the plugin framework, and avoid having to make any changes to core Wireshark code. There is an API to add support for new block types via plugins, but I think this may the first project to use this functionality; there could be bugs and it may not be complete.

Even though the code I am writing has nothing to do with network packets, Wireshark still refers to the list of events in the top pane as the Packet List, and various structures that we need to use refer to all events as packets, most notably the wtap_pkthdr structure.

TSDB Handling

The TSDB defines the type and meaning of fields. Wireshark should not generate a "Packet List" entry for this block. Later, I refer to this type of block as a silent block. If you want to add support for a new silent block to your dissector, think of the TSDB as a template.

The TSDB defines each field through TLVs (type-length-value). The types map to native Wireshark field types with two important exceptions.

Field Type Encoding

The encoded integer values for the field types are not the same as the integer values used within Wireshark. This is because the Wireshark types are generated via an enumerated list. A change to the list could change the enumerated values. If we used these values within the TSDB, we would have compatibility problems. Wireshark field tyoe values start at 0. The TSDB field type values start at 1001.

The Wireshark field types values can be found in epan/ftypes/ftype.h. The mapping of TSDB values to Wireshark field values is in the array babeltowsft.

Special Cases

We need to deal with two special cases. A log record could contain many date-time values. We need to indicate which value should be used in the Wireshark packet list. This is done through the EVENT_DATETIME field type.

A log often mixes IPv4 and IPv6 addresses in the same column; both Apache HTTPD and Microsoft IIS do this. To accommodate this we have a TS_FT_IPvx field type.

Non-Packet Block

This type of block carries information but doesn't generate an entry in the packet list; similar to the Interface Descriptor Block (IDB). This is the simplest kind of block to handle. There are two steps:

It looks something like this:

gboolean tsdb_read_block(FILE_T fh, guint32 block_data_len, gboolean c, struct wtap_pkthdr *d,
    Buffer *block_data_buffer, int *err, gchar **err_info)
    /* Use i as a general purpose index */
    size_t i;

    * Is the size of this block reasonable for a TSDB?
    if (block_data_len == 0 || block_data_len > block_data_buffer->allocated) {
        /* Not looking good. */
        *err = WTAP_ERR_BAD_FILE;
        *err_info = g_strdup_printf("tsdb_read_block: block data length of %u is invalid",
        return FALSE;

    /* read block content */
    if (!wtap_read_bytes(fh, block_data_buffer->data, block_data_len, err, err_info)) {
        g_strdup_printf("pcapng_read_if_descr_block: failed to read IDB");
        return FALSE;

    Do more stuff

    return TRUE;

    Do stuff
    register_pcapng_block_type_handler(BLOCK_TYPE_TSDB, tsdb_read_block, NULL);

Packet Block


Within the Wireshark code, any block that generates an entry in the packet list is referred to as a packet block. Here's an extract of the code from pcapng.c:

This area is called during the first scan:

        switch (wblock.type) {
              /* XXX - improve handling of "unknown" blocks */
          pcapng_debug("pcapng_read: Unknown block type 0x%08x", wblock.type);

This area is called during subsequent scans:

    /* block must be a "Packet Block", an "Enhanced Packet Block",
       a "Simple Packet Block", or an event */
    if (wblock.type != BLOCK_TYPE_PB && wblock.type != BLOCK_TYPE_EPB &&
        wblock.type != BLOCK_TYPE_SPB &&
        wblock.type != BLOCK_TYPE_SYSDIG_EVENT && wblock.type != BLOCK_TYPE_SYSDIG_EVF) {
            pcapng_debug("pcapng_seek_read: block type %u not PB/EPB/SPB", wblock.type);
        return FALSE;

    return TRUE;

Both these code blocks are a problem as they don't take into account user defined blocks.


A packet block is encapsulated in a "frame" format. The encapsulation is specified at three levels:

There are 16 available user values (WTAP_ENCAP_USER0 to WTAP_ENCAP_USER15) and I use WTAP_ENCAP_USER11 for the TRBs.

Timestamp Precision

The timestamp precision can be specified at three levels:

wtap_pkthdr structure

In the tsdb_read_block(...) function above, I don't populate any of the fields in the wtap_pkthdr structure. That's OK for a silent block but we need Wireshark to create a dissection chain (?) for the TRBs, i.e. a block that we wish to dissect.

What we need is for the content of the block to be treated as a new protocol, in the same way as the content of an EPB is becomes a Frame.

The wtap_pkthdr structure fields I believe have to be completed by a block read function are:

There isn't a flag to explicitly indicate that the block contains a "Packet". This would have been useful to decide whether a user block is silent or contains a packet. I'm going to propose (via a code change) that WTAP_HAS_TS must be set to signal that the block to contain a packet.

    /* Populate the wtap_pkthdr */
    if (is_byte_swapped) {
        phdr->ts.secs = GUINT32_SWAP_LE_BE(tr_hdr->timestamp_high);
        phdr->ts.nsecs = GUINT32_SWAP_LE_BE(tr_hdr->timestamp_low);
        phdr->caplen = GUINT32_SWAP_LE_BE(block_data_len);
        phdr->len = GUINT32_SWAP_LE_BE(block_data_len);
    else {
        phdr->ts.secs = tr_hdr->timestamp_high;
        phdr->ts.nsecs = tr_hdr->timestamp_low;
        phdr->caplen = block_data_len;
        phdr->len = block_data_len;
    phdr->interface_id = 0;
    phdr->drop_count = -1; /* invalid */
    phdr->user_evt_block = TRUE;
    phdr->caplen = block_data_len;
    phdr->len = block_data_len;
    phdr->pkt_encap = WTAP_ENCAP_USER11;
    phdr->presence_flags |= PINFO_HAS_TS;
    phdr->presence_flags |= WTAP_HAS_INTERFACE_ID;
    phdr->presence_flags |= WTAP_HAS_CAP_LEN;
    phdr->rec_type = REC_TYPE_PACKET;

I'm still working on this.

encap_table_base in wtap.c could be the way we register the dissector against our block, i.e.

Related information

Appendix A - XML Example

<?xml version="1.0" encoding="utf-8" standalone="yes"?>
        <header headerline="false" skipheaderlines="0">
                <description>Descriptor file for Apache access log in common format</description>
                <generator>Babel 3.0</generator>
                <owner>Paul Offord</owner>
                <nativeformat>LogFormat "%h %l %u %t \"%r\" %>s %b" common</nativeformat>
                <example> - user01 [09/Jul/2012:08:25:35 +0100] "GET /Setup.php HTTP/1.1" 200 1824</example>
                <record type="1">
                        <eols enforce="true">
                                <criterium type="string" offset="*">*</criterium>
                                        <informat quoted="false">%i</informat>
                                        <blurb>This is the IP address of the client (remote host) which made the request to the server.</blurb>
                                        <type quoted="false">FT_IPvx</type>
                                        <informat quoted="false">%s</informat>
                                        <blurb>The identity of the client determined by a request to the identd server on the clients machine.</blurb>
                                        <type quoted="false">FT_STRINGZ</type>
                                        <informat quoted="false">%s</informat>
                                        <blurb>This is the userid of the person requesting the document as determined by HTTP authentication.</blurb>
                                        <type quoted="false">FT_STRINGZ</type>
                                        <informat quoted="false" start-bracket="[" end-bracket="]">[%d/%b/%Y:%H:%M:%S %z]</informat>
                                        <blurb>The time that the request was received.</blurb>
                                        <informat quoted="true">%s</informat>
                                        <blurb>The request line from the client is given in double quotes.</blurb>
                                        <informat quoted="false">%d</informat>
                                        <name>response code</name>
                                        <blurb>This is the status code that the server sends back to the client.</blurb>
                                        <informat quoted="false">%d</informat>
                                        <name>bytes returned</name>
                                        <blurb>This indicates the size of the object returned to the client, not including the response headers.</blurb>
                        <infofield>%4 - %5</infofield>

Appendix B - Sample PCAP-NG File


NB: The timestamp in this pcapng file is incorrect. I'll correct this and post a new version.

Appendix C - Request for PCAP-NG Block Types

-----Original Message-----
From: pcap-ng-format [] On Behalf Of
Sent: 22 January 2018 08:24
To: Paul Offord <>
Subject: Your message to pcap-ng-format awaits moderator approval

Your mail to 'pcap-ng-format' with the subject

    Request for Two PCAP-NG Block Types

Is being held until the list moderator can review it for approval.

The reason it is being held:

    Post by non-member to a members-only list

Either the message will get posted to the list, or you will receive notification of the moderator's decision.  If you would like to cancel this posting, please visit the following URL: