Main Content


PCAPNG file writer of protocol packets

Since R2020b


    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 Bluetooth low energy (LE) link layer (LL) packets (requires Bluetooth® Toolbox)

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

    • Generated and recovered WLAN protocol packets (requires WLAN Toolbox™)



    pcapngObj = pcapngWriter creates a default PCAPNG file writer object.


    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.


    expand all


    The pcapngWriter object does not overwrite the existing PCAPNG file. Each time when you create 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


    collapse all

    Create a PCAPNG file writer object, specifying the name of the PCAPNG file. Specify the Bluetooth LE link type.

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

    Write an interface description block for Bluetooth LE.

    interfaceName = 'Bluetooth LE interface';
    bleLinkType = 251;
    interfaceId = writeInterfaceDescriptionBlock(pcapngObj,bleLinkType, ...

    Specify a Bluetooth LE LL packet.

    llpacket = '42BC13E206120E00050014010A001F0040001700170000007D47C0';

    Write the Bluetooth LE LL packet to the PCAPNG format file.

    timestamp = 0;                                 % Packet arrival time in POSIX® microseconds elapsed since 1/1/1970
    packetComment = 'This is a Bluetooth LE packet';
    write(pcapngObj,llpacket,timestamp,interfaceId,'PacketComment', ...


    [1] Tuexen, M. “PCAP Next Generation (Pcapng) Capture File Format.” 2020.

    [2] Group, The Tcpdump. “Tcpdump/Libpcap Public Repository.” Accessed May 20, 2020.

    [3] “Development/LibpcapFileFormat - The Wireshark Wiki.” Accessed May 20, 2020.

    Extended Capabilities

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

    Version History

    Introduced in R2020b

    See Also