Skip to content

Commit 889c1e6

Browse files
committed
Fix windows interface matching
In windows pcap.Name differ from net.Interface Name, so instead we have to match by interface addrs
1 parent 8edb74e commit 889c1e6

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

capture/capture.go

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ func (l *Listener) PcapHandle(ifi pcap.Interface) (handle *pcap.Handle, err erro
232232
if l.TimestampType != "" && l.TimestampType != "go" {
233233
var ts pcap.TimestampSource
234234
ts, err = pcap.TimestampSourceFromString(l.TimestampType)
235-
fmt.Println("Setting custom Timestamp Source. Supported values: `simple`, ", inactive.SupportedTimestamps())
235+
fmt.Println("Setting custom Timestamp Source. Supported values: `go`, ", inactive.SupportedTimestamps())
236236
err = inactive.SetTimestampSource(ts)
237237
if err != nil {
238238
return nil, fmt.Errorf("%q: supported timestamps: %q, interface: %q", err, inactive.SupportedTimestamps(), ifi.Name)
@@ -517,11 +517,20 @@ func (l *Listener) setInterfaces() (err error) {
517517
}
518518

519519
for _, pi := range pifis {
520+
if len(pi.Addresses) == 0 {
521+
continue
522+
}
523+
520524
var ni net.Interface
521525
for _, i := range ifis {
522-
if i.Name == pi.Name {
523-
ni = i
524-
break
526+
addrs, _ := i.Addrs()
527+
for _, a := range addrs {
528+
for _, pa := range pi.Addresses {
529+
if strings.HasPrefix(a.String(), pa.IP.String()) {
530+
ni = i
531+
break
532+
}
533+
}
525534
}
526535
}
527536

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

540-
if len(pi.Addresses) != 0 {
541-
l.Interfaces = append(l.Interfaces, pi)
542-
}
549+
l.Interfaces = append(l.Interfaces, pi)
543550
}
544551
return
545552
}

0 commit comments

Comments
 (0)