Skip to content

Commit

Permalink
👍 Add interface flag
Browse files Browse the repository at this point in the history
  • Loading branch information
Takumasa Sakao committed Feb 12, 2018
1 parent ddafdeb commit 2474913
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,33 @@ var (
handle *pcap.Handle
)

func main() {
var device string = "lo"
func findDevice(c *cli.Context) string {
if c.String("interface") != "" {
return c.String("interface")
}
devices, err := pcap.FindAllDevs()
if err != nil {
panic(err)
}

return devices[0].Name
}

func main() {
app := cli.NewApp()
app.Name = "tcpterm"
app.Usage = "tcpdump for human"
app.Version = "0.0.1"

app.Flags = []cli.Flag{
cli.StringFlag{
Name: "interface, i",
Usage: "If unspecified, use lowest numbered interface.",
},
}

app.Action = func(c *cli.Context) error {
device := findDevice(c)
handle, err = pcap.OpenLive(device, snapshot_len, promiscuous, timeout)
if err != nil {
log.Fatal(err)
Expand Down

0 comments on commit 2474913

Please sign in to comment.