How irontec/sngrep works
Project type and purpose
• This is an open-source CLI application (sngrep) that captures network traffic (SIP/RTP), parses it, applies filters, and displays call-flow and message details in a curses-based UI.
• Key indicators: presence of src/capture_*.c, src/sip*.c, src/rtp.c, src/curses/*, pkg/* packaging files, and standard GNU build scripts.
File structure
• Top-level directories:
– src/ Core C modules (capture, parsing, filtering, UI, utils)
– src/curses/ UI components (panels, call flow/list/raw, stats, settings)
– config/ Default config (sngreprc)
– tests/ Unit tests and sample pcap files
– doc/ Man pages and HTML snippets
– pkg/ Packaging (apk, deb, rpm)
– build scripts: configure.ac, Makefile.am, CMakeLists.txt, bootstrap.sh
• Architectural pattern: layered, modular C code with clear separation of capture, parsing, filtering, session management, and presentation (MVC-like).
Extract additional insights (README incomplete)
1) Engine
• Modules: capture.c, capture_eep.c, capture_gnutls.c, capture_openssl.c
• Depends on libpcap, optionally GnuTLS/OpenSSL
2) Packet Parser & Session Manager
• packet.c, sip.c, sip_msg.c, sip_call.c, sip_attr.c, rtp.c
• Builds SIP/RTP sessions and attributes
3) Filter Engine
• filter.c
• Applies user-defined BPF/SIP filters
4) Data Models & Utilities
• .c, media.c, option.c, setting.c, util.c, hash.c, vector.c
5) UI Layer (ncurses)
• ui_manager, ui_call_list, ui_call_flow, ui_call_raw, ui_stats, ui_filter, ui_settings, etc.
• Keybindings (keybinding.c), panels, scrollbars
6) Configuration & Persistence
• config/sngreprc, src/setting.c, src/option.c
• Save captured sessions (ui_save.c)
7) Build & Packaging
• Autotools/CMake (configure.ac, Makefile.am), packaging under pkg/
8) Tests
• Unit tests invoking core modules against test pcap traces
• Engine → Packet Parser
• Packet Parser ↔ Filter Engine (filter may drop or pass packets)
• Filtered packets → Session Manager (groups, call/session state)
• UI Layer → Capture Engine (start/stop capture via commands)
• UI Layer → Filter Engine (update filter expressions at runtime)
• Configuration → Capture Engine, Filter Engine, UI Layer (load on startup)
• Tests → Individual modules (validate behavior)
c. Architectural patterns & principles
• Layered architecture: separation of capture, processing, and presentation
• Event-driven UI loop (ncurses manager dispatches keybindings)
• Modular design: each subsystem (capture, parsing, UI) in its own compile unit
d. Key technologies/frameworks/libraries
• libpcap (packet capture)
• ncurses (text UI)
• GnuTLS/OpenSSL (if encrypted capture support)
• Autotools/CMake (build system)
• Standard C (POSIX)