Skip to content

Latest commit

History

69 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

Groinc

Groinc is a network packet sniffer and analyzer for Linux. It captures packets from a live network interface or reads them from files, parses protocol headers across multiple layers (datalink, network, transport), applies filters, and produces configurable reports.

Features

  • Live packet capture using Linux PF_PACKET raw sockets
  • Read/write packet data from/to files
  • Multi-layer protocol parsing: Ethernet, IPv4, ARP, TCP, UDP, ICMP
  • Flexible filtering by MAC address, IP address (with CIDR support), port, protocol, substring, or regex
  • Configurable display: raw data, hex dump, per-layer headers, simple or verbose output
  • Report generation with packet counts and capture timing

Usage

groinc [options]

Running groinc with no arguments captures and displays all packets on the default interface. Root privileges (or CAP_NET_RAW) are required for live capture.

Examples

Capture all traffic and display payload data:

groinc -a

Capture TCP traffic on port 80 with verbose headers:

groinc -p TCP -d 80 -v

Capture 100 packets from a subnet and write to a file:

groinc -S 192.168.1.0/24 -l 100 -w capture.dat

Read a capture file and filter for HTTP content:

groinc -r capture.dat -f "HTTP" -a

Quiet capture with a report of total and filtered packet counts over 60 seconds:

groinc -q -c -C -t 60

Hex dump of ICMP packets:

groinc -p ICMP -H

Options

Display options

FlagLong formDescription
-a--displaydataShow packet payload data
-A--simpledisplaySimple display format
-v--verboseVerbose header information
-n--displaypacketsShow packet numbers
-H--hexaHexadecimal dump of packet
-j--displayprotodatalinkShow datalink layer protocol info
-b--displayprototransportShow transport layer protocol info
-B--displayprotonetworkShow network layer protocol info
-N--displayallpacketsDisplay all packets including empty ones

Filter options

FlagLong formArgumentDescription
-d--destportPORTFilter by destination port
-s--sourceportPORTFilter by source port
-g--globalportPORTFilter by either source or destination port
-D--destipIP[/CIDR]Filter by destination IP
-S--sourceipIP[/CIDR]Filter by source IP
-G--globalipIP[/CIDR]Filter by either source or destination IP
-m--sourcemacMACFilter by source MAC address
-M--destmacMACFilter by destination MAC address
-p--protocolPROTOFilter by protocol (TCP, UDP, ICMP, ARP, IP)
-f--filterSTRINGSubstring match in packet payload
-F--filter-regexREGEXPOSIX regex match on packet payload
-l--limitnbNUMBERStop after capturing N packets
-t--timelimitSECONDSStop after N seconds
-z--dontdisplayemptysl-Hide packets with empty payloads
-q--quiet-Suppress packet display

IP addresses accept several formats: a single IP (192.168.1.1), CIDR notation (192.168.1.0/24), colon-separated netmask (192.168.1.0:255.255.255.0), or a hostname.

Input/output options

FlagLong formArgumentDescription
-r--readFILERead packets from a file
-w--writeFILEWrite captured packets to a file
-o--outputdataFILEWrite packet data to a file
-O--outputFILEWrite packet headers to a file
-j--noresolv-Disable hostname resolution

Report options

FlagLong formDescription
-T--reportotaltimeReport total capture time
-c--countpacketstotReport total packet count
-C--countpacketsfiltredReport filtered packet count

Miscellaneous

FlagLong formDescription
-h--helpShow help message
--versionShow version
--licenseShow GPLv3 license text

Implementation

Groinc is written in ANSI C with no external dependencies beyond the C standard library and Linux system headers.

Architecture

Packet capture uses select() for I/O multiplexing on a PF_PACKET socket. Each captured packet is passed through a three-stage parsing pipeline:

  1. Datalink layer - Ethernet (IEEE 802.3) header parsing
  2. Network layer - IPv4 (RFC 791), ARP
  3. Transport layer - TCP (RFC 793), UDP, ICMP

Protocol implementations are modular: each protocol provides scan (parse) and print functions registered via function pointer tables, making it straightforward to add new protocols.

Key data structures

  • struct data - Tracks the raw packet buffer, current parse offset, and total length
  • struct protocol_header - Holds a parsed header's protocol ID, length, and data pointer
  • A union-based linked list is used throughout for filters, display options, reports, and errors
  • A hash table backs the error lookup system

Filtering

All active filters are AND-composed. The filter chain is evaluated sequentially with early exit. Compiler branch-prediction hints (likely/unlikely macros) optimize the hot path.

Building

Requires GCC and standard Linux headers.

make

To install the binary and man page system-wide:

make install

Other targets:

TargetDescription
allBuild the executable (default)
devDevelopment build (keeps intermediate objects)
installInstall binary to /usr/bin and man page
cleanRemove object files
cleanallRemove object files and the executable

The default build uses -Wall -ansi -pedantic -O3 -fomit-frame-pointer -g.

Note: the code in the main branch has been preserved in it's original 2005-ish state, therefore it doesn't compile on modern versions of Linux & GCC. An AI-fixed version of the code, which compiles on modern tech stacks, is available in the fix-build-for-modern-linux-and-gcc branch.

About

Ethernet packet sniffer/analyzer

Topics

Resources

Stars

2 stars

Watchers

1 watching

Forks

Contributors

Languages