Skip to content

Commit

Permalink
add -r option
Browse files Browse the repository at this point in the history
  • Loading branch information
zaftzaft committed Nov 12, 2016
1 parent 8f76940 commit 9e68102
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions dcatch.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,15 @@ import (
"time"
)

var version = "0.0.1"
var version = "0.0.2"

func main() {
var device string
flag.StringVar(&device, "i", "any", "interface name")

var filename string
flag.StringVar(&filename, "r", "", "pcap file")

var showVersion bool
flag.BoolVar(&showVersion, "v", false, "show version")
flag.BoolVar(&showVersion, "version", false, "show version")
Expand All @@ -29,9 +32,18 @@ func main() {
return
}

handle, err := pcap.OpenLive(device, 65536, true, time.Second)
if err != nil {
log.Fatal("pcap openlive err:", err)
var handle *pcap.Handle
var err error
if filename != "" {
handle, err = pcap.OpenOffline(filename)
if err != nil {
log.Fatal("[Error] pcap OpenOffline err", err)
}
} else {
handle, err = pcap.OpenLive(device, 65536, true, time.Second)
if err != nil {
log.Fatal("pcap openlive err:", err)
}
}

defer handle.Close()
Expand Down

0 comments on commit 9e68102

Please sign in to comment.