Skip to content

Latest commit

 

History

History
211 lines (107 loc) · 4.78 KB

cppapi.rst

File metadata and controls

211 lines (107 loc) · 4.78 KB

C++ API

Pcap

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

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 or nullptr.

const IPv4* ipv4() const

returns

IPv4 object or nullptr.

const IPv6* ipv6() const

returns

IPv6 object or nullptr.

const UDP* udp() const

returns

UDP object or nullptr.

const TCP* tcp() const

returns

TCP object or nullptr.

const DNS* dns() const

returns

DNS object or nullptr.

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

Ethernet

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"

IPv4

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.

IPv6

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"...)

UDP

unsigned int source_port() const

returns

Source port number.

unsigned int destination_port() const

returns

Destination port number.

TCP

unsigned int source_port() const

returns

Source port number.

unsigned int destination_port() const

returns

Destination port number.

DNS

unsigned int qr() const

returns

0 (Query) or 1 (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"