Main Content

pcapWriter

PCAP file writer of protocol packets

Since R2020b

    Description

    The pcapWriter object writes generated and recovered protocol packets to a packet capture (PCAP) file (.pcap).

    You can write these packet types to a PCAP 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™)

    Creation

    Description

    pcapObj = pcapWriter creates a default PCAP file writer object.

    pcapObj = pcapWriter(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.

    example

    Properties

    expand all

    Note

    The pcapWriter object does not overwrite the existing PCAP file. Each time when you call this object, specify a unique PCAP file name.

    Name of the PCAP 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

    Object Functions

    expand all

    writeWrite protocol packet data to PCAP or PCAPNG file
    writeGlobalHeaderWrite global header to PCAP file

    Examples

    collapse all

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

    pcapObj = pcapWriter('FileName','writeBluetoothLE');
    bleLinkType = 251;

    Write a global header to the PCAP file.

    writeGlobalHeader(pcapObj,bleLinkType);

    Specify a Bluetooth LE LL packet.

    llpacket = '42BC13E206120E00050014010A001F0040001700170000007D47C0';

    Write the Bluetooth LE LL packet to the PCAP file.

    timestamp = 129100;                % Packet arrival time in POSIX® microseconds elapsed since 1/1/1970
    write(pcapObj,llpacket,timestamp);

    References

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

    [2] “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™.

    Version History

    Introduced in R2020b

    See Also

    Objects