extcap

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2023 License: MIT Imports: 7 Imported by: 2

README

extcap

Extcap helps create cli application for Wireshark capture using extcap interface.

Full example is located in examples/extcapdump

Example:

package main

func main() {
}

Documentation

Overview

Package extcap implements library to help create cli app for capture by Wireshark using extcap interface (https://www.wireshark.org/docs/wsdg_html_chunked/ChCaptureExtcap.html). For flags parsing, package urfave/cli is used (https://github.com/urfave/cli)

For minimal application should be implemented following functions:

GetInterfaces:
GetDLT:
StartCapture:

Full working example can be found in examples folder

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNoInterfaceSpecified is returned when start capture or query configuration options or query supported DLTs
	ErrNoInterfaceSpecified = errors.New("No interface specified")

	// ErrNoPipeProvided is returned when start capture and not provide pipe name to write
	ErrNoPipeProvided = errors.New("No FIFO pipe provided")
)

Functions

This section is empty.

Types

type App

type App struct {
	// Application brief description
	Usage string

	// Application help description
	HelpPage string

	// AdditionalHelp will be displaied in version output.
	Version VersionInfo

	// Usage examples to dispaly in USAGE section of help output.
	// By default add following common examples:
	// <application-name> --extcap-interfaces
	// For example for ciscodump:
	//    --extcap-interface=ciscodump --extcap-dlts
	//    --extcap-interface=ciscodump --extcap-config
	//    --extcap-interface=ciscodump --remote-host myhost --remote-port 22222 --remote-username myuser --remote-interface gigabit0/0 --fifo=FILENAME --capture
	// Will produce ouput
	//    ciscodump --extcap-interfaces
	//    ciscodump --extcap-interface=ciscodump --extcap-dlts
	//    ciscodump --extcap-interface=ciscodump --extcap-config
	//    ciscodump --extcap-interface=ciscodump --remote-host myhost --remote-port 22222 --remote-username myuser --remote-interface gigabit0/0 --fifo=FILENAME --capture
	UsageExamples []string

	// GetInterfaces returns list of intefaces. Should be implement
	GetInterfaces func() ([]CaptureInterface, error)

	// GetDLT returns DLT for given interface. Should be implement.
	GetDLT func(iface string) (DLT, error)

	// GetConfigOptions returns configuration parameters for given interface. Optional
	GetConfigOptions func(iface string) ([]ConfigOption, error)

	// GetAllConfigOptions retrun all possible configuration options. Optional (all interfaces have not configuration options).
	GetAllConfigOptions func() []ConfigOption

	// StartCapture starts capture process. Should be implement. opts is configuration options for capture on given interface
	// which depends on interface
	StartCapture func(iface string, fifo io.WriteCloser, filter string, opts map[string]interface{}) error

	// OpenPipe opens fifo pipe to write capture results. If it not defined then default is used.
	OpenPipe func(string) (io.WriteCloser, error)
}

App is the main structure of a extcap application.

func (App) Run

func (extapp App) Run(arguments []string)

Runs main loop application

type CaptureInterface

type CaptureInterface struct {
	Value   string
	Display string
}

CaptureInterface represents single network interface for capture

func (CaptureInterface) String

func (iface CaptureInterface) String() string

Format to string in format interface {value=example1}{display=Example interface 1 for extcap}

type ConfigBoolOpt

type ConfigBoolOpt struct {
	// contains filtered or unexported fields
}

ConfigBoolOpt impplement ConfigOption interface

func NewConfigBoolOpt

func NewConfigBoolOpt(call, display string) *ConfigBoolOpt

Create new BOOL option

func (*ConfigBoolOpt) Default

func (c *ConfigBoolOpt) Default(val bool) *ConfigBoolOpt

Default sets default value option

func (*ConfigBoolOpt) Required

func (c *ConfigBoolOpt) Required(val bool) *ConfigBoolOpt

Required sets option required

func (*ConfigBoolOpt) String

func (c *ConfigBoolOpt) String() string

String implements string interface arg {number=2}{call=--verify}{display=Verify}{tooltip=Verify package content}{type=boolflag}

func (*ConfigBoolOpt) Tooltip

func (c *ConfigBoolOpt) Tooltip(tooltip string) *ConfigBoolOpt

SetTooltip sets option tooltip

type ConfigIntegerOpt

type ConfigIntegerOpt struct {
	// contains filtered or unexported fields
}

Integer option

func NewConfigIntegerOpt

func NewConfigIntegerOpt(call, display string) *ConfigIntegerOpt

Create new integer option

func (*ConfigIntegerOpt) Default

func (c *ConfigIntegerOpt) Default(val int) *ConfigIntegerOpt

WithDefault sets default value for INTEGER option

func (*ConfigIntegerOpt) Group

func (c *ConfigIntegerOpt) Group(group string) *ConfigIntegerOpt

WithGroup sets option's group

func (*ConfigIntegerOpt) Range

func (c *ConfigIntegerOpt) Range(min, max int) *ConfigIntegerOpt

WithRange sets min and max value for option

func (*ConfigIntegerOpt) Required

func (c *ConfigIntegerOpt) Required(val bool) *ConfigIntegerOpt

WithRequired sets option required

func (*ConfigIntegerOpt) String

func (c *ConfigIntegerOpt) String() string

String implement stringer interface Example output

arg {number=0}{call=--delay}{display=Time delay}{tooltip=Time delay between packages}{type=integer}{range=1,15}{required=true}

func (*ConfigIntegerOpt) Tooltip

func (c *ConfigIntegerOpt) Tooltip(tooltip string) *ConfigIntegerOpt

SetTooltip sets option tooltip

type ConfigOption

type ConfigOption interface {
	// contains filtered or unexported methods
}

ConfigOption

type ConfigStringOpt

type ConfigStringOpt struct {
	// contains filtered or unexported fields
}

ConfigStringOpt impplement ConfigOption interface

func NewConfigStringOpt

func NewConfigStringOpt(call, display string) *ConfigStringOpt

Create new STRING option

func (*ConfigStringOpt) Default

func (c *ConfigStringOpt) Default(val string) *ConfigStringOpt

Default sets default value for STRING option

func (*ConfigStringOpt) Placeholder

func (c *ConfigStringOpt) Placeholder(str string) *ConfigStringOpt

SetTooltip sets option tooltip

func (*ConfigStringOpt) Required

func (c *ConfigStringOpt) Required(val bool) *ConfigStringOpt

Required sets option required

func (*ConfigStringOpt) String

func (c *ConfigStringOpt) String() string

String implements string interface arg {number=0}{call=--server}{display=IP address for log server}{type=string}{validation=\\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\b}

func (*ConfigStringOpt) Tooltip

func (c *ConfigStringOpt) Tooltip(tooltip string) *ConfigStringOpt

SetTooltip sets option tooltip

func (*ConfigStringOpt) Validation

func (c *ConfigStringOpt) Validation(str string) *ConfigStringOpt

Validation sets option validation

type DLT

type DLT struct {
	Number  int
	Name    string
	Display string
}

DLT represents link type supported by interface

func (DLT) String

func (dlt DLT) String() string

Format to string in format dlt {number=147}{name=USER1}{display=Demo Implementation for Extcap}

type VersionInfo

type VersionInfo struct {
	Info string
	Help string
}

func (VersionInfo) String

func (ver VersionInfo) String() string

Format to string in format extcap {version=0.1.0}{help=<some help or URL}

Directories

Path Synopsis
examples
extcapdump command

Jump to

Keyboard shortcuts

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