Holds pcap file information and provides methods for pcap manipulation.
Pcap()
Default constructor of a new Pcap::Pcap object. Needs opening afterwards.
Pcap(const std::string& filename)
Constructs Pcap objects, opens pcap file and initializes data.
- param file_name
Path to pcap.
void open_pcap(const std::string& filename)
Opens pcap. Only needed if Pcap object created with default constructor.
- param file_name
Path to pcap.
std::unique_ptr<Packet> next_packet()
Read next packet from a pcap file. Returns nullptr if no more packets.
- returns
Next
Packet
parsed out of pcap file.
Packet(uint8_t* data, unsigned int length)
Constructor of a new Packet Packet
object.
- param data
Pointer to start of pcap bytes.
- param length
Length of read packet.
const Ethernet* ethernet() const
- returns
Ethernet
object ornullptr
.
const IPv4* ipv4() const
- returns
IPv4
object ornullptr
.
const IPv6* ipv6() const
- returns
IPv6
object ornullptr
.
const UDP* udp() const
- returns
UDP
object ornullptr
.
const TCP* tcp() const
- returns
TCP
object ornullptr
.
const DNS* dns() const
- returns
DNS
object ornullptr
.
unsigned int length() const
- returns
Packet length.
unsigned int payload_length() const
- returns
Payload length (packet data following transport protocols).
uint8_t* payload()
- returns
Payload data
const std::string& source() const
- returns
Source MAC address. (e.g.
"54:75:d0:c9:0b:81"
)
const std::string& destination() const
- destination
Source MAC address. (e.g.
"54:75:d0:c9:0b:81"
)
const std::string& type() const
- returns
"IPv4"
,"IPv6"
or"ARP"
const std::string& source() const
- returns
Source IPv4 address. (e.g.
"192.168.0.1"
)
const std::string& destination() const
- returns
Destination IPv4 address. (e.g.
"192.168.0.1"
)
const std::string& protocol() const
- returns
Next protocol. (e.g.,
"TCP"
,"UDP"
,"ICMP"
...)
const std::string& header_length() const
- returns
IPv4 header length.
const std::string& source() const
- returns
Source IPv6 address. (e.g.
"fe80::0202:b3ff:fe1e:8329"
)
const std::string& destination() const
- returns
Destination IPv6 address. (e.g.
"fe80::0202:b3ff:fe1e:8329"
)
const std::string& next_header() const
- returns
Next header type. (e.g.,
"TCP"
,"UDP"
,"ICMP"
...)
unsigned int source_port() const
- returns
Source port number.
unsigned int destination_port() const
- returns
Destination port number.
unsigned int source_port() const
- returns
Source port number.
unsigned int destination_port() const
- returns
Destination port number.
unsigned int qr() const
- returns
0
(Query) or1
(Response).
unsigned int question_count() const
- returns
Number of question entries.
unsigned int answer_count() const
- returns
Number of answer entries.
unsigned int authority_count() const
- returns
Number of entries in authoritative NS section.
unsigned int additional_count() const
- returns
Number of additional resource records.
const std::vector<std::string>& answers() const
- returns
Answer RRs. Vector of std::string formatted as:
"google.com A 172.217.23.206"
const std::vector<std::string>& authoritatives() const
- returns
Authoritative NS RRs. Vector of std::string formatted as:
"google.com NS ns4.google.com"
const std::vector<std::string>& additionals() const
- returns
Additional RRs. Vector of std::string formatted as:
"google.com A 172.217.23.206"