Skip to content

Commit

Permalink
Add a new config suppress-tshark-errors to hide parsing problems
Browse files Browse the repository at this point in the history
I saw this PDML error on macos with tshark 3.4.4:

<field name="irc.response" showname="Response: :Samsung.US.SPUNet.org NOTICE Auth :Welcome to \002SPUNet\002!" size="56" pos="54" show=":Samsung.US.SPUNet.org NOTICE Auth :Welcome to �SPUNet�!" value="3a53616d73756e672e55532e5350554e65742e6f7267204e4f544943452041757468203a57656c636f6d6520746f20025350554e65740221">

The Go XML parser complains about the 0x02 bytes surrounding SPUNet. If
this happens, by default, termshark will display an error dialog. On
this particular PCAP, the error was triggered by many packets, so
navigating around the PCAP popped up the error repeatedly. This config
option allows the user to suppress these errors. The setting is stored
in termshark.toml as main.suppress-tshark-errors.
  • Loading branch information
gcla committed Sep 3, 2021
1 parent dac296d commit 2cbf22d
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 30 deletions.
12 changes: 11 additions & 1 deletion ui/lastline.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ func newSetArg(sub string) substrArg {
"packet-colors",
"pager",
"nopager",
"suppress-tshark-errors",
"term",
"noterm",
},
Expand Down Expand Up @@ -347,6 +348,15 @@ func (d setCommand) Run(app gowid.IApp, args ...string) error {
termshark.SetConf("main.packet-colors", PacketColors)
OpenMessage(fmt.Sprintf("Packet colors are now %s", gwutil.If(b, "on", "off").(string)), appView, app)
}
case "suppress-tshark-errors":
if b, err = parseOnOff(args[2]); err == nil {
termshark.SetConf("main.suppress-tshark-errors", b)
if b {
OpenMessage("tshark errors will be suppressed.", appView, app)
} else {
OpenMessage("tshark errors will be displayed.", appView, app)
}
}
case "term":
if err = termshark.ValidateTerm(args[2]); err == nil {
termshark.SetConf("main.term", args[2])
Expand Down Expand Up @@ -387,7 +397,7 @@ func (d setCommand) Arguments(toks []string, app gowid.IApp) []minibuffer.IArg {
res = append(res, newSetArg(toks[0]))

if len(toks) > 0 {
onOffCmds := []string{"auto-scroll", "dark-mode", "packet-colors"}
onOffCmds := []string{"auto-scroll", "dark-mode", "packet-colors", "suppress-tshark-errors"}
boolCmds := []string{"disable-shark-fin"}
intCmds := []string{"disk-cache-size-mb", "copy-command-timeout"}

Expand Down
19 changes: 10 additions & 9 deletions ui/messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,15 +134,16 @@ Use the cmdline set command to change configuration.
Type :set and hit tab for options.
auto-scroll________ - scroll during live captures
copy-timeout_______ - wait this long before failing a copy
dark-mode__________ - enable or disable dark-mode
disable-shark-fin__ - switch off the secret shark fin
packet-colors______ - use colors in the packet list view
pager______________ - pager (used for termshark's log file)
nopager____________ - disable the pager (use PAGER instead)
term_______________ - make termshark assume this terminal type
noterm_____________ - disable the terminal type (use TERM){{end}}
auto-scroll___________ - scroll during live captures
copy-timeout__________ - wait this long before failing a copy
dark-mode_____________ - enable or disable dark-mode
disable-shark-fin_____ - switch off the secret shark fin
packet-colors_________ - use colors in the packet list view
pager_________________ - pager (used for termshark's log file)
nopager_______________ - disable the pager (use PAGER instead)
suppress-tshark-errors - don't show tshark errors in the UI
term__________________ - make termshark assume this terminal type
noterm________________ - disable the terminal type (use TERM){{end}}
{{define "MapHelp"}}{{template "NameVer" .}}
Expand Down
41 changes: 23 additions & 18 deletions ui/prochandlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,20 +117,21 @@ func (t updatePacketViews) OnError(code pcap.HandlerCode, app gowid.IApp, err er
fmt.Fprintf(os.Stderr, "%v\n", err)
RequestQuit()
} else {

var errstr string
if kverr, ok := err.(gowid.KeyValueError); ok {
errstr = fmt.Sprintf("%v\n\n", kverr.Cause())
kvs := make([]string, 0, len(kverr.KeyVals))
for k, v := range kverr.KeyVals {
kvs = append(kvs, fmt.Sprintf("%v: %v", k, v))
if !termshark.ConfBool("main.suppress-tshark-errors", false) {
var errstr string
if kverr, ok := err.(gowid.KeyValueError); ok {
errstr = fmt.Sprintf("%v\n\n", kverr.Cause())
kvs := make([]string, 0, len(kverr.KeyVals))
for k, v := range kverr.KeyVals {
kvs = append(kvs, fmt.Sprintf("%v: %v", k, v))
}
errstr = errstr + strings.Join(kvs, "\n")
} else {
errstr = fmt.Sprintf("%v", err)
}
errstr = errstr + strings.Join(kvs, "\n")
} else {
errstr = fmt.Sprintf("%v", err)
}

OpenLongError(errstr, app)
OpenLongError(errstr, app)
}
StopEmptyStructViewTimer()
StopEmptyHexViewTimer()
}
Expand All @@ -149,9 +150,11 @@ func (t SimpleErrors) OnError(code pcap.HandlerCode, app gowid.IApp, err error)
log.Error(err)
// Hack to avoid picking up errors at other parts of the load
// cycle. There should be specific handlers for specific errors.
app.Run(gowid.RunFunction(func(app gowid.IApp) {
OpenError(fmt.Sprintf("%v", err), app)
}))
if !termshark.ConfBool("main.suppress-tshark-errors", false) {
app.Run(gowid.RunFunction(func(app gowid.IApp) {
OpenError(fmt.Sprintf("%v", err), app)
}))
}
}

//======================================================================
Expand Down Expand Up @@ -344,9 +347,11 @@ func (s SetStructWidgets) OnError(code pcap.HandlerCode, app gowid.IApp, err err
// Hack to avoid picking up errors at other parts of the load
// cycle. There should be specific handlers for specific errors.
if s.Ld.PdmlLoader.IsLoading() {
app.Run(gowid.RunFunction(func(app gowid.IApp) {
OpenLongError(fmt.Sprintf("%v", err), app)
}))
if !termshark.ConfBool("main.suppress-tshark-errors", false) {
app.Run(gowid.RunFunction(func(app gowid.IApp) {
OpenLongError(fmt.Sprintf("%v", err), app)
}))
}
}
}

Expand Down
3 changes: 1 addition & 2 deletions ui/streamui.go
Original file line number Diff line number Diff line change
Expand Up @@ -339,8 +339,7 @@ func (t *streamParseHandler) OnError(code pcap.HandlerCode, app gowid.IApp, err
if !Running {
fmt.Fprintf(os.Stderr, "%v\n", err)
RequestQuit()
} else {

} else if !termshark.ConfBool("main.suppress-tshark-errors", false) {
var errstr string
if kverr, ok := err.(gowid.KeyValueError); ok {
errstr = fmt.Sprintf("%v\n\n", kverr.Cause())
Expand Down

0 comments on commit 2cbf22d

Please sign in to comment.