Giter Club home page Giter Club logo

jlamprou / pcapmonitor Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 11 KB

This project is a packet sniffer and analyzer that uses the pcap library to capture packets from a network interface or read packets from a pcap file. It provides detailed information about the Ethernet, IP, TCP, and UDP headers, as well as the payload of each packet. It also keeps track of TCP and UDP flows and identifies TCP retransmissions.

C 99.36% Makefile 0.64%

pcapmonitor's Introduction

Pcap Monitor

This project is a packet sniffer and analyzer that uses the pcap library to capture packets from a network interface or read packets from a pcap file. It provides detailed information about the Ethernet, IP, TCP, and UDP headers, as well as the payload of each packet. It also keeps track of TCP and UDP flows and identifies TCP retransmissions.

Getting Started

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes.

Building

To build the project, use the provided Makefile. In the project directory, run:

make

This will compile the source code and produce an executable named pcap_ex.

Usage

You can run the program with the following command:

sudo ./pcap_ex -i interface_name -f filter_exp

or

./pcap_ex -r file_name -f filter_exp

Here, interface_name is the name of the network interface from which to capture packets, file_name is the name of a pcap file from which to read packets, and filter_exp is a filter expression that specifies which packets to capture or read.

The -i and -r options are mutually exclusive. If you provide both, the program will print a help message and exit. If you do not provide either, the program will also print a help message and exit.

The filter expression is optional. If you do not provide it, the program will capture or read all packets.

Filter Expressions

The program supports the following filter expressions: (You can find more information about filter expressions here.)

  • dst host ip_address
  • src host ip_address
  • host ip_address
  • ether dst mac_address
  • ether src mac_address
  • ether host mac_address
  • gateway ip_address
  • dst net network
  • src net network
  • net network
  • dst port port_number
  • src port port_number
  • port port_number
  • tcp
  • udp
  • icmp
  • less size
  • greater size

Implementation Details

The program uses a hash map to keep track of TCP and UDP flows and to identify TCP retransmissions. Each entry in the hash map represents a flow and contains a key and a value. The key is a string that consists of the source IP address, destination IP address, source port number, destination port number, and sequence number, separated by colons. The value is an integer that represents the number of packets in the flow.

When the program captures or reads a packet, it constructs the key from the packet's header fields and checks if the key is in the hash map. If the key is in the hash map, the program increments the value associated with the key. If the key is not in the hash map, the program adds a new entry to the hash map with the key and a value of 1.

The program uses the pcap library to capture packets from a network interface or read packets from a pcap file. It uses the pcap_next_ex function to get the next packet, and then it processes the packet's headers and payload.

The program prints detailed information about each packet, including the Ethernet, IP, TCP, and UDP headers, as well as the payload. It also prints statistics about the total number of packets, the total number of TCP and UDP packets, the total number of TCP and UDP bytes, the total number of TCP retransmissions, and the total number of TCP and UDP flows.

pcapmonitor's People

Contributors

jlamprou avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.