Skip to content

Commit

Permalink
fix(plc4go/tools): minor fixes on plc4xpcapanalyzer
Browse files Browse the repository at this point in the history
  • Loading branch information
sruehl committed May 27, 2022
1 parent eda641e commit fd38251
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
12 changes: 6 additions & 6 deletions plc4go/tools/plc4xpcapanalyzer/cmd/analyze.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,13 @@ TODO: document me
if !noFilter {
switch protocolType {
case "bacnet":
bacnetFilter, err := cmd.Flags().GetString("default-bacnet-filter")
if err != nil {
log.Fatal().Err(err).Msg("could not get default-bacnet-filter argument")
}
if bacnetFilter != "" {
filter = bacnetFilter
if filter != "" && bacnetFilter != "" {
log.Debug().Str("filter", filter).Msg("Setting bacnet filter")
filter = bacnetFilter
}
}
} else {
log.Info().Msg("All filtering disabled")
}
analyzer.Analyze(pcapFile, protocolType, filter, onlyParse, noBytesCompare)
},
Expand All @@ -84,6 +82,8 @@ func init() {

analyzeCmd.Flags().StringVarP(&filter, "filter", "f", "", "BFF filter to apply")
analyzeCmd.Flags().BoolVarP(&noFilter, "no-filter", "n", false, "disable filter")
analyzeCmd.Flags().BoolVarP(&onlyParse, "onlyParse", "o", false, "only parse messaged")
analyzeCmd.Flags().BoolVarP(&noBytesCompare, "noBytesCompare", "c", false, "don't compare original bytes with serialized bytes")
analyzeCmd.PersistentFlags().StringVarP(&bacnetFilter, "default-bacnet-filter", "", "udp port 47808 and udp[4:2] > 29", "Defines the default filter when bacnet is selected")
// TODO: support other protocols
}
3 changes: 2 additions & 1 deletion plc4go/tools/plc4xpcapanalyzer/internal/analyzer/analyzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@ func Analyze(pcapFile, protocolType, filter string, onlyParse, noBytesCompare bo
log.Info().Msgf("Analyzing pcap file '%s' with protocolType '%s' and filter '%s' now", pcapFile, protocolType, filter)

handle, numberOfPackage, timestampToIndexMap := pcaphandler.GetIndexedPcapHandle(pcapFile, filter)
log.Info().Msgf("Starting to analyze %d packages", numberOfPackage)
defer handle.Close()
log.Debug().Interface("handle", handle).Int("numberOfPackage", numberOfPackage).Interface("timestampToIndexMap", timestampToIndexMap).Msg("got handle")
log.Debug().Interface("handle", handle).Int("numberOfPackage", numberOfPackage).Msg("got handle")
source := pcaphandler.GetPacketSource(handle)
var packageParse func(string, []byte) (interface{}, error)
var serializePackage func(interface{}) ([]byte, error)
Expand Down

0 comments on commit fd38251

Please sign in to comment.