Import reading of pcap files

Automatically detect if it is a file (by extension), and do not require specify --input-raw-engine option.

Can also run without port, but in this case, it will assume that port value set to `0` and it will show all records from the file.
This commit is contained in:
Leonid Bugaev
2022-01-17 20:55:43 +03:00
parent 9c5f011bb7
commit 3f659a16ce
+12 -1
View File
@@ -51,7 +51,18 @@ func NewRAWInput(address string, config RAWInputConfig) (i *RAWInput) {
host, _ports, err := net.SplitHostPort(address)
if err != nil {
log.Fatalf("input-raw: error while parsing address: %s", err)
// If we are reading pcap file, no port needed
if strings.HasSuffix(address, "pcap") {
host = address
_ports = "0"
err = nil
} else {
log.Fatalf("input-raw: error while parsing address: %s", err)
}
}
if strings.HasSuffix(host, "pcap") {
i.RAWInputConfig.Engine = capture.EnginePcapFile
}
var ports []uint16