capture

package
v0.0.0-...-ba37d73 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 20, 2022 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package capture implements the main capture logic. It is meant to be re-usable and use only standard interfaces.

Example usage:

package main

// Importing fmt and time
import (
    "time"

    "github.com/yadutaf/ddump/pkg/capture"
)

func main() {
    // Prepare the capture file
    f, err := os.Create("/tmp/capture.pcap")
    if err != nil {
        panic(e)
    }

    // Start the capture in the background
    done := make(chan struct{})
    go func() {
        err := capture.Capture("eth0", "tcp port 80")
        if err != nil {
              panic(e)
        }
        close(done)
    }

    // Stop the capture after 3s, or early exit
    select {
    case <-time.After(3 * time.Second):
    case <-done:
    }

    // Close the writer
    f.Close()

    // Wait until done
    <-done
}

Index

Constants

View Source
const (
	MAX_PACKET_LENGTH = 9000 // Maximum packet size supported by ddump, in bytes. 9000 is a "Jumbo frame"
)

Variables

This section is empty.

Functions

func Capture

func Capture(ifName string, filter string, w io.Writer) error

Capture is a long running function. It starts a live capture session on interface ifName for all packets matching the provided filter. Matching packets are copied to the w writer. Note: ifName can be the name of an actual interface or the special "any" to capture from all interfaces.

This function exits when a write error occurs. For example, if the writer is a TCP connection, this function will exit when the downstream connection is closed. Conversly, a caller may close the writer to request the capture end.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL