Skip to content

Commit

Permalink
Fix windows interface matching
Browse files Browse the repository at this point in the history
In windows pcap.Name differ from net.Interface Name, so instead we have to match by interface addrs
  • Loading branch information
buger committed Jul 7, 2021
1 parent 8edb74e commit 889c1e6
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions capture/capture.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ func (l *Listener) PcapHandle(ifi pcap.Interface) (handle *pcap.Handle, err erro
if l.TimestampType != "" && l.TimestampType != "go" {
var ts pcap.TimestampSource
ts, err = pcap.TimestampSourceFromString(l.TimestampType)
fmt.Println("Setting custom Timestamp Source. Supported values: `simple`, ", inactive.SupportedTimestamps())
fmt.Println("Setting custom Timestamp Source. Supported values: `go`, ", inactive.SupportedTimestamps())
err = inactive.SetTimestampSource(ts)
if err != nil {
return nil, fmt.Errorf("%q: supported timestamps: %q, interface: %q", err, inactive.SupportedTimestamps(), ifi.Name)
Expand Down Expand Up @@ -517,11 +517,20 @@ func (l *Listener) setInterfaces() (err error) {
}

for _, pi := range pifis {
if len(pi.Addresses) == 0 {
continue
}

var ni net.Interface
for _, i := range ifis {
if i.Name == pi.Name {
ni = i
break
addrs, _ := i.Addrs()
for _, a := range addrs {
for _, pa := range pi.Addresses {
if strings.HasPrefix(a.String(), pa.IP.String()) {
ni = i
break
}
}
}
}

Expand All @@ -537,9 +546,7 @@ func (l *Listener) setInterfaces() (err error) {
return
}

if len(pi.Addresses) != 0 {
l.Interfaces = append(l.Interfaces, pi)
}
l.Interfaces = append(l.Interfaces, pi)
}
return
}
Expand Down

0 comments on commit 889c1e6

Please sign in to comment.