diff --git a/README.md b/README.md index e1ee42c..196ec50 100644 --- a/README.md +++ b/README.md @@ -76,6 +76,15 @@ Flags: -v, --version version for sniffer ``` +**Shortcuts** + +| Keys | Description | +| ---- | ----------- | +| Space | pause refreshing | +| Tab | rearrange tables | +| s | switch next view mode | +| q / Ctrl+C | quit | + ## View Mode ***Bytes Mode:*** display traffic stats in bytes by the Table widget. diff --git a/cli.go b/cli.go index 0a7264a..71b4ffe 100644 --- a/cli.go +++ b/cli.go @@ -6,7 +6,7 @@ import ( "github.com/spf13/cobra" ) -const version = "v0.1.1" +const version = "v0.2.0" func NewApp() *cobra.Command { defaultOpts := DefaultOptions() diff --git a/conn_darwin.go b/conn_darwin.go index d6462e0..61e8fdd 100644 --- a/conn_darwin.go +++ b/conn_darwin.go @@ -91,16 +91,6 @@ func (lc *lsofConn) getOpenSockets(pids ...int32) (OpenSockets, error) { if err != nil { continue } - - if len(pids) > 0 { - pid, err := strconv.Atoi(fields[1]) - if err != nil { - continue - } - if !set[int32(pid)] { - continue - } - } sockets[LocalSocket{IP: ipport[0], Port: uint16(port), Protocol: ProtoTCP}] = procName case "UDP": diff --git a/pcap.go b/pcap.go index 7774e2e..51c39cb 100644 --- a/pcap.go +++ b/pcap.go @@ -1,6 +1,7 @@ package main import ( + "errors" "strconv" "strings" "sync" @@ -139,6 +140,10 @@ func (c *PcapClient) getAvailableDevices() error { } } + if len(c.handlers) == 0 { + return errors.New("no available devices found") + } + return nil } diff --git a/sniffer.go b/sniffer.go index cac5ee1..b82a197 100644 --- a/sniffer.go +++ b/sniffer.go @@ -85,6 +85,14 @@ func NewSniffer(opts Options) (*Sniffer, error) { }, nil } +func (s *Sniffer) SwitchViewMode() { + s.opts.ViewMode = (s.opts.ViewMode + 1) % 3 + s.statsManager = NewStatsManager(s.opts) + + s.ui.Close() + s.ui = NewUIComponent(s.opts) +} + func (s *Sniffer) Start() { events := termui.PollEvents() s.Refresh() @@ -102,6 +110,8 @@ func (s *Sniffer) Start() { case "": payload := e.Payload.(termui.Resize) s.ui.viewer.Resize(payload.Width, payload.Height) + case "s", "S": + s.SwitchViewMode() case "q", "Q", "": return } @@ -115,9 +125,9 @@ func (s *Sniffer) Start() { } func (s *Sniffer) Close() { + s.ui.Close() s.pcapClient.Close() s.dnsResolver.Close() - s.ui.Close() } func (s *Sniffer) Refresh() { diff --git a/ui.go b/ui.go index ef7c1fb..bcae97b 100644 --- a/ui.go +++ b/ui.go @@ -76,7 +76,7 @@ func (u Unit) Ratio() float64 { } func newFooter() *widgets.Paragraph { - return newParagraph("Press to pause, / to exit. Use to rearrange tables") + return newParagraph("Press to pause, / to exit, to switch mode. Use to rearrange tables") } func newParagraph(text string) *widgets.Paragraph {