diff --git a/arp.go b/arp.go index 9736c09..5a07e0c 100644 --- a/arp.go +++ b/arp.go @@ -37,6 +37,9 @@ func (t *Tendrils) readARPTable() { entries := t.parseARPTable() for _, entry := range entries { + if t.iface != "" && entry.iface != t.iface { + continue + } if isBroadcastOrZero(entry.mac) { continue } diff --git a/cmd/tendrils/main.go b/cmd/tendrils/main.go index 8d13302..ee11f95 100644 --- a/cmd/tendrils/main.go +++ b/cmd/tendrils/main.go @@ -1,10 +1,15 @@ package main import ( + "flag" + "github.com/gopatchy/tendrils" ) func main() { - t := tendrils.New() + iface := flag.String("i", "", "interface to use (default: all interfaces)") + flag.Parse() + + t := tendrils.New(*iface) t.Run() } diff --git a/tendrils.go b/tendrils.go index 56534f4..54d7da8 100644 --- a/tendrils.go +++ b/tendrils.go @@ -11,12 +11,14 @@ import ( type Tendrils struct { activeInterfaces map[string]context.CancelFunc nodes *Nodes + iface string } -func New() *Tendrils { +func New(iface string) *Tendrils { return &Tendrils{ activeInterfaces: map[string]context.CancelFunc{}, nodes: NewNodes(), + iface: iface, } } @@ -88,6 +90,9 @@ func (t *Tendrils) listInterfaces() []net.Interface { var validInterfaces []net.Interface for _, iface := range interfaces { + if t.iface != "" && iface.Name != t.iface { + continue + } if iface.Flags&net.FlagUp == 0 { continue }