Tcpdump and wireshark are built on top of libpcap. If you are interested in learning how to write programs in C or Go using libpcap check out these posts.
http://www.devdungeon.com/content/using-libpcap-c
http://www.devdungeon.com/content/packet-capture-injection-a...