parse_layer7 0.1.3

A crate for parsing layer 7 packets, specifically DNS packets.
Documentation

Sure! Here's a comprehensive README for your project, including sections for an introduction, setup, usage, testing, and contribution guidelines.


Layer 7 Packet Parser

This project is a Rust-based library for parsing various types of Layer 7 (application layer) network packets, including DHCP, DNS, HTTP, MODBUS, and TLS packets. It provides functionality to inspect the contents of these packets and extract useful information for network analysis and monitoring purposes.

Table of Contents

Introduction

The Layer 7 Packet Parser library allows users to parse and inspect different types of application layer packets. This can be useful for network monitoring, security analysis, and debugging network applications. The library currently supports the following protocols:

  • DHCP
  • DNS
  • HTTP
  • MODBUS
  • TLS

Features

  • Parse DHCP packets
  • Parse DNS packets
  • Parse HTTP packets
  • Parse MODBUS packets
  • Parse TLS packets

Installation

To use the Layer 7 Packet Parser library in your Rust project, add the following to your Cargo.toml:

[dependencies]
layer_7_packet_parser = { git = "https://github.com/Akmot9/layer_7_packet_parser" }

Usage

Here is an example of how to use the library to parse a packet:

extern crate layer_7_packet_parser;

use layer_7_packet_parser::parse_layer_7_infos;

fn main() {
    let packet: Vec<u8> = vec![/* your packet data here */];
    match parse_layer_7_infos(&packet) {
        Some(layer_7_infos) => {
            println!("Parsed Layer 7 Information: {}", layer_7_infos);
        }
        None => {
            println!("Could not parse Layer 7 information.");
        }
    }
}

Examples

Parsing a DNS Packet

extern crate layer_7_packet_parser;

use layer_7_packet_parser::packet::dns::parse_dns_packet;

fn main() {
    let dns_packet = vec![
        0xdd, 0xc7, // Transaction ID
        0x01, 0x00, // Flags
        0x00, 0x01, // Questions
        0x00, 0x00, // Answers
        0x00, 0x00, // Authority RRs
        0x00, 0x00, // Additional RRs
        // Query
        0x03, 0x77, 0x77, 0x77, // "www"
        0x06, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, // "google"
        0x03, 0x63, 0x6f, 0x6d, // "com"
        0x00, // Null terminator of the domain name
        0x00, 0x01, // Type A
        0x00, 0x01, // Class IN
    ];

    match parse_dns_packet(&dns_packet) {
        Ok(dns) => println!("Parsed DNS Packet: {:?}", dns),
        Err(_) => println!("Failed to parse DNS Packet"),
    }
}

Parsing an HTTP Request

extern crate layer_7_packet_parser;

use layer_7_packet_parser::packet::http::parse_http_request;

fn main() {
    let http_request = b"GET / HTTP/1.1\r\nHost: www.example.com\r\n\r\n";
    
    match parse_http_request(http_request) {
        Ok(request) => println!("Parsed HTTP Request: {:?}", request),
        Err(_) => println!("Failed to parse HTTP Request"),
    }
}

Testing

To run the tests for this project, use the following command:

cargo test

This will compile the project and run all the tests defined in the tests module.

Contributing

Contributions are welcome! Please follow these steps to contribute to the project:

  1. Fork the repository on GitHub.
  2. Create a new branch from the main branch.
  3. Make your changes and commit them to your branch.
  4. Push your changes to your fork.
  5. Open a pull request to the main repository.

Please ensure that your code adheres to the Rust coding standards and passes all tests.

License

This project is licensed under either of

at your option.


Feel free to customize this README to better suit your project and preferences.