Main Content

pcapngWriter

PCAPNG file writer of protocol packets

    Description

    The pcapngWriter object writes generated and recovered protocol packets to a packet capture next generation (PCAPNG) file (.pcapng).

    You can write these packet types to a PCAPNG file:

    • Generated and recovered WLAN protocol packets

    • Generated and recovered 5G NR protocol packets (requires 5G Toolbox™)

    • Generated and recovered Bluetooth® low energy (BLE) link layer (LL) packets (requires Communications Toolbox™ Library for the Bluetooth Protocol)

    Creation

    Description

    pcapngObj = pcapngWriter creates a default PCAPNG file writer object.

    example

    pcapngObj = pcapngWriter(Name,Value) sets properties using one or more name-value pair arguments. Enclose each property name in quotes. For example, 'ByteOrder','big-endian' specifies the byte order as big-endian.

    Properties

    expand all

    Note

    The pcapngWriter object does not overwrite the existing PCAPNG file. During each call of this object, specify a unique PCAPNG file name.

    Name of the PCAPNG file, specified as a character row vector or a string scalar.

    Data Types: char | string

    Byte order, specified as 'little-endian' or 'big-endian'.

    Data Types: char | string

    Comment for the PCAPNG file, specified as a character vector or a string scalar.

    Data Types: char | string

    Object Functions

    expand all

    writeWrite protocol packet data to PCAP or PCAPNG file
    writeCustomBlockWrite custom block to PCAPNG file
    writeInterfaceDescriptionBlockWrite interface description block to PCAPNG file

    Examples

    collapse all

    Create a PCAPNG file writer object, specifying the name of the PCAPNG file.

    pcapngObj = pcapngWriter('FileName','writeWLANpacket');

    Write the interface block for WLAN.

    interfaceName = 'WLAN';
    wlanLinkType = 105;
    interfaceId = writeInterfaceDescriptionBlock(pcapngObj,wlanLinkType, ...
        interfaceName);

    Specify a WLAN packet.

    mpdu = 'B4000000FFFFFFFFFFFF00123456789BA79A5B28';

    Specify the packet comment. Write the WLAN packet to the PCAPNG file, specifying the packet comment.

    timestamp = 0; % Number of microseconds
    packetComment = 'This is the first packet';
    write(pcapngObj,mpdu,timestamp,interfaceId,'PacketComment', ...
        packetComment);

    Create a PCAPNG file writer object, specifying the name of the PCAPNG file.

    pcapngObj = pcapngWriter('FileName','writeWLANBLEpackets');

    Write the interface block for WLAN.

    interfaceName = 'WLAN';
    wlanLinkType = 105;
    interfaceId = writeInterfaceDescriptionBlock(pcapngObj,wlanLinkType, ...
        interfaceName);

    Specify a WLAN packet.

    mpdu = 'B4000000FFFFFFFFFFFF00123456789BA79A5B28';

    Specify the packet comment. Write the WLAN packet to the PCAPNG file, specifying the packet comment.

    timestamp = 0; % Number of microseconds
    packetComment = 'This is a WLAN packet';
    write(pcapngObj,mpdu,timestamp,interfaceId,'PacketComment', ...
        packetComment);

    Write the interface block for Bluetooth low energy (BLE).

    interfaceName = 'BLE';
    bleLinkType = 251;
    interfaceId = writeInterfaceDescriptionBlock(pcapngObj,bleLinkType, ...
        interfaceName);

    Specify a BLE packet.

    llpacket = '42BC13E206120E00050014010A001F0040001700170000007D47C0';

    Specify the packet comment. Write the BLE packet to the PCAPNG file, specifying the packet comment.

    timestamp = 0; % Number of microseconds
    packetComment = 'This is a BLE packet';
    write(pcapngObj,llpacket,timestamp,interfaceId,'PacketComment', ...
        packetComment);

    References

    [1] Tuexen, M. “PCAP Next Generation (Pcapng) Capture File Format.” 2020. https://www.ietf.org/.

    [2] “Radiotap - Introduction.” Accessed May 20, 2020. https://www.radiotap.org/.

    [3] Group, The Tcpdump. “Tcpdump/Libpcap Public Repository.” Accessed May 20, 2020. https://www.tcpdump.org.

    [4] “Development/LibpcapFileFormat - The Wireshark Wiki.” Accessed May 20, 2020. https://www.wireshark.org/.

    Extended Capabilities

    C/C++ Code Generation
    Generate C and C++ code using MATLAB® Coder™.

    See Also

    Objects

    Introduced in R2020b