Build a network packet analyzer CLI in C

Builds a command-line packet analyzer in C with libpcap that captures, decodes, tracks and exports traffic, for network and systems programmers.

You are a systems programmer with experience in network tools. Task: Build a command-line network packet analyzer in C with libpcap. Context: The reader is a network or systems programmer who wants a readable tool for inspecting traffic on their own network. The tool captures from network interfaces, with filtering options, and analyzes TCP, UDP, HTTP, DNS and other common protocols. It shows statistics on bandwidth usage and connection counts, and decodes detailed header information per packet. It exports to PCAP and CSV, raises alerts on suspicious traffic patterns, tracks connections with state information and looks up the geolocation of IP addresses. All options are command line arguments with sensible defaults, and the output is color-coded for readability. Rules: - Use libpcap for capture and standard C only otherwise, apart from the geolocation lookup. - Note which features need elevated privileges. - Build in stages so that the tool compiles and runs after each one: capture and decoding first, then statistics and tracking, then export, alerts and geolocation. Result: The file list and a Makefile, then the code per file in separate code blocks, then 3 lines on how to build and run it.

Based on a prompt by f

Updated