Wireshark is an open source network packet analyzer.
It can capture, dissect, and decode various protocols. This helps Linux sysadmin to troubleshoot network issues.
Apart from using wirehshark as a standlone application for debugging network packets, you can also write your own extension or plugin using wireshark libraries for your custom application.
This tutorial explains how to use wireshark libraries to write custom code to debug network packets using a C example program.
The code explains two parts. First, to capture network packets. Second, to decode packets using libwireshark.
As a prerequisite, your system should have both libpcap and wireshark libraries installed.
To capture a packet, refer to How to Perform Packet Sniffing Using Libpcap with C Example Code.
You can also open an existing pcap file using the following api inside your C program:
pd = pcap_open_offline(pcap_path, errbuf);
Wireshark code uses its own dissection engine (epan module library) to dissect the network packets.