Skip to content

Commit

Permalink
Filter up interfaces (#53)
Browse files Browse the repository at this point in the history
  • Loading branch information
stephen-soltesz authored Jun 30, 2023
1 parent 240575e commit ce1f6cf
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,20 @@ func processFlags() ([]net.Interface, error) {
if err != nil {
return ifaces, err
}
if i.Flags&net.FlagUp != 0 {
ifaces = append(ifaces, *i)
}
return ifaces, nil
}

func filterUpInterfaces(ifaces []net.Interface) []net.Interface {
result := []net.Interface{}
for _, iface := range ifaces {
if iface.Flags&net.FlagUp != 0 {
// We can only capture packets from interfaces that are up.
ifaces = append(ifaces, *i)
result = append(result, iface)
}
}
return ifaces, nil
return result
}

func main() {
Expand Down Expand Up @@ -157,7 +165,7 @@ func main() {
// Capture packets on every interface.
cleanupWG.Add(1)
go func() {
muxer.MustCaptureTCPOnInterfaces(mainCtx, ifaces, packets, pcapOpenLive, int32(*maxHeaderSize))
muxer.MustCaptureTCPOnInterfaces(mainCtx, filterUpInterfaces(ifaces), packets, pcapOpenLive, int32(*maxHeaderSize))
mainCancel()
cleanupWG.Done()
}()
Expand Down

0 comments on commit ce1f6cf

Please sign in to comment.