Wireshark 4.7.0
The Wireshark network protocol analyzer
Loading...
Searching...
No Matches
Functions
pcapio.h File Reference
#include <wsutil/file_compressed.h>

Go to the source code of this file.

Functions

bool libpcap_write_file_header (ws_cwstream *pfile, int linktype, int snaplen, bool ts_nsecs, uint64_t *bytes_written, int *err)
 Writes a pcap file header to the specified output stream.
 
bool libpcap_write_packet (ws_cwstream *pfile, time_t sec, uint32_t usec, uint32_t caplen, uint32_t len, const uint8_t *pd, uint64_t *bytes_written, int *err)
 Writes a packet to a pcap file.
 
bool pcapng_write_block (ws_cwstream *pfile, const uint8_t *data, uint32_t block_total_length, uint64_t *bytes_written, int *err)
 Write a pre-formatted pcapng block to the output stream.
 
bool pcapng_write_section_header_block (ws_cwstream *pfile, GPtrArray *comments, const char *hw, const char *os, const char *appname, uint64_t section_length, uint64_t *bytes_written, int *err)
 Write a section header block (SHB)
 
bool pcapng_write_interface_description_block (ws_cwstream *pfile, const char *comment, const char *name, const char *descr, const char *filter, const char *os, const char *hardware, int link_type, int snap_len, uint64_t *bytes_written, uint64_t if_speed, uint8_t tsresol, int *err)
 Writes an Interface Description Block (IDB) to a pcapng file.
 
bool pcapng_write_interface_statistics_block (ws_cwstream *pfile, uint32_t interface_id, uint64_t *bytes_written, const char *comment, uint64_t isb_starttime, uint64_t isb_endtime, uint64_t isb_ifrecv, uint64_t isb_ifdrop, int *err)
 Writes an Interface Statistics Block to a pcapng file.
 
bool pcapng_write_enhanced_packet_block (ws_cwstream *pfile, const char *comment, time_t sec, uint32_t usec, uint32_t caplen, uint32_t len, uint32_t interface_id, unsigned ts_mul, const uint8_t *pd, uint32_t flags, uint64_t *bytes_written, int *err)
 Writes an Enhanced Packet Block (EPB) to a pcapng file.
 

Detailed Description

Declarations of our own routines for writing pcap and pcapng files.

Wireshark - Network traffic analyzer By Gerald Combs geral.nosp@m.d@wi.nosp@m.resha.nosp@m.rk.o.nosp@m.rg Copyright 1998 Gerald Combs

Derived from code in the Wiretap Library Copyright (c) 1998 by Gilbert Ramirez gram@.nosp@m.alum.nosp@m.ni.ri.nosp@m.ce.e.nosp@m.du

SPDX-License-Identifier: GPL-2.0-or-later

Function Documentation

◆ libpcap_write_file_header()

bool libpcap_write_file_header ( ws_cwstream pfile,
int  linktype,
int  snaplen,
bool  ts_nsecs,
uint64_t *  bytes_written,
int *  err 
)
extern

Writes a pcap file header to the specified output stream.

Write the file header to a dump file. Returns true on success, false on failure. Sets "*err" to an error code, or 0 for a short write, on failure

Parameters
pfileThe output stream to which the header will be written.
linktypeThe data link type of the packets that will be captured.
snaplenThe snapshot length for each packet.
ts_nsecsIndicates whether the timestamp should have nanosecond resolution.
bytes_writtenPointer to a variable where the number of bytes written will be stored.
errPointer to an integer where any error code will be stored.
Returns
true on success, false on failure.

◆ libpcap_write_packet()

bool libpcap_write_packet ( ws_cwstream pfile,
time_t  sec,
uint32_t  usec,
uint32_t  caplen,
uint32_t  len,
const uint8_t *  pd,
uint64_t *  bytes_written,
int *  err 
)
extern

Writes a packet to a pcap file.

Write a record for a packet to a dump file. Returns true on success, false on failure

Parameters
pfileThe output stream for the pcap file.
secThe timestamp seconds of the packet.
usecThe timestamp microseconds of the packet.
caplenThe captured length of the packet.
lenThe original length of the packet.
pdThe data of the packet.
bytes_writtenPointer to store the number of bytes written.
errPointer to store any error code.
Returns
true if the packet was successfully written, false otherwise.

◆ pcapng_write_block()

bool pcapng_write_block ( ws_cwstream pfile,
const uint8_t *  data,
uint32_t  block_total_length,
uint64_t *  bytes_written,
int *  err 
)
extern

Write a pre-formatted pcapng block to the output stream.

Checks if the data and length are aligned to 4 bytes, and if the block_total_length field is consistent at both ends of the block.

Parameters
pfileThe output stream to write the block to.
dataThe data to be written as a pcapng block.
block_total_lengthThe length of the data.
bytes_writtenPointer to store the number of bytes written.
errPointer to store any error encountered during writing.
Returns
true if the block was successfully written, false otherwise.

◆ pcapng_write_enhanced_packet_block()

bool pcapng_write_enhanced_packet_block ( ws_cwstream pfile,
const char *  comment,
time_t  sec,
uint32_t  usec,
uint32_t  caplen,
uint32_t  len,
uint32_t  interface_id,
unsigned  ts_mul,
const uint8_t *  pd,
uint32_t  flags,
uint64_t *  bytes_written,
int *  err 
)
extern

Writes an Enhanced Packet Block (EPB) to a pcapng file.

Parameters
pfilePointer to the write context.
commentOptional comment for the packet.
secSeconds part of the timestamp.
usecMicroseconds part of the timestamp.
caplenLength of the captured data.
lenTotal length of the packet.
interface_idID of the network interface on which the packet was received.
ts_mulTimestamp multiplier.
pdPointer to the captured data.
flagsFlags for the packet.
bytes_writtenPointer to store the number of bytes written.
Returns
true if successful, false otherwise.

◆ pcapng_write_interface_description_block()

bool pcapng_write_interface_description_block ( ws_cwstream pfile,
const char *  comment,
const char *  name,
const char *  descr,
const char *  filter,
const char *  os,
const char *  hardware,
int  link_type,
int  snap_len,
uint64_t *  bytes_written,
uint64_t  if_speed,
uint8_t  tsresol,
int *  err 
)
extern

Writes an Interface Description Block (IDB) to a pcapng file.

This function writes an IDB to the specified pcapng file stream, containing information about the network interface.

Parameters
pfileThe pcapng file stream to write to.
commentA comment string for the IDB (optional).
nameThe name of the network interface.
descrA description of the network interface.
filterA display filter for the interface.
osThe operating system on which the interface is running.
hardwareThe hardware description of the interface.
link_typeThe link type of the interface (e.g., Ethernet, Wi-Fi).
snap_lenThe snapshot length for packet capture.
Returns
true if the IDB was successfully written, false otherwise.

◆ pcapng_write_interface_statistics_block()

bool pcapng_write_interface_statistics_block ( ws_cwstream pfile,
uint32_t  interface_id,
uint64_t *  bytes_written,
const char *  comment,
uint64_t  isb_starttime,
uint64_t  isb_endtime,
uint64_t  isb_ifrecv,
uint64_t  isb_ifdrop,
int *  err 
)
extern

Writes an Interface Statistics Block to a pcapng file.

Parameters
pfileThe write context for the pcapng file.
interface_idThe ID of the network interface.
bytes_writtenPointer to store the number of bytes written.
commentOptional comment string (OPT_COMMENT).
isb_starttimeStart time of the statistics block in 100-nanosecond intervals since January 1, 1601 (ISB_STARTTIME).
isb_endtimeEnd time of the statistics block in 100-nanosecond intervals since January 1, 1601 (ISB_ENDTIME).
isb_ifrecvNumber of packets received by the interface (ISB_IFRECV).
isb_ifdropNumber of packets dropped by the interface (ISB_IFDROP).
errPointer to store any error code.
Returns
true if successful, false otherwise.

◆ pcapng_write_section_header_block()

bool pcapng_write_section_header_block ( ws_cwstream pfile,
GPtrArray *  comments,
const char *  hw,
const char *  os,
const char *  appname,
uint64_t  section_length,
uint64_t *  bytes_written,
int *  err 
)
extern

Write a section header block (SHB)

Parameters
pfileWrite information
commentsComments on the section, Option 1 opt_comment UTF-8 strings containing comments that areassociated to the current block.
hwHW, Option 2 shb_hardware An UTF-8 string containing the description of the hardware used to create this section.
osOperating system name, Option 3 shb_os An UTF-8 string containing the name of the operating system used to create this section.
appnameApplication name, Option 4 shb_userappl An UTF-8 string containing the name of the application used to create this section.
section_lengthLength of section
bytes_writtenNumber of written bytes
errError type