Simple Linux C++ application built using ImGUI to capture packets.
The PacketSniffer
class provides functionality for capturing packets from a network interface using raw sockets. It allows starting and stopping packet capture and provides methods to retrieve captured packets.
An example is available in the teste.cpp
file.
- Constructor: Creates a raw socket for packet capturing and initializes
captureActive
tofalse
.
- Destructor: Stops packet capture and closes the socket.
- Starts packet capture in a separate thread.
- Parameters:
packetBuffer
: A reference to a vector where captured packets will be stored.
- Stops packet capture.
- Captures a single packet synchronously.
- Returns:
- A vector containing a single pair of packet size and data.
- Formats and prints the captured packet data.
- Parameters:
packet
: A pair containing packet size and data.
- Returns:
- A string representation of the packet data.
- Raw socket descriptor.
- Atomic boolean flag to control packet capture.
- Creates a raw socket for packet capture.
- Returns:
- The socket descriptor.
- Closes the raw socket.
- Reads data from the raw socket.
- Returns:
- A pair containing the size of the received data and a pointer to the data buffer.
- Thread function for continuously capturing packets.
- Parameters:
packetBuffer
: A reference to a vector where captured packets will be stored.