Skip to content

Commit 05ed821

Browse files
DimaGolomozybuger
authored andcommitted
capture nics (#1000)
1. move the `isDevice(l.host, pi)` to be first, as no need to iterate on all nics if it returns `true` 2. first compare by name, as same nics will have same names 3. if not found by name, compare by ips. the bug was the `strings.HasPrefix` 2 different nics with ipv6: ``` #nic1 ip: f1234::55 #nic2 ip: f1234::55::66::66 ``` so because of the `strings.HasPrefix` it was evaluated as the name nics. but they are not.
1 parent 7ae4004 commit 05ed821

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

capture/capture.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -569,33 +569,33 @@ func (l *Listener) setInterfaces() (err error) {
569569
}
570570

571571
for _, pi := range pifis {
572+
if isDevice(l.host, pi) {
573+
l.Interfaces = []pcap.Interface{pi}
574+
return
575+
}
576+
572577
var ni net.Interface
573578
for _, i := range ifis {
579+
if i.Name == pi.Name {
580+
ni = i
581+
break
582+
}
583+
574584
addrs, _ := i.Addrs()
575585
for _, a := range addrs {
576586
for _, pa := range pi.Addresses {
577-
if strings.HasPrefix(a.String(), pa.IP.String()) {
587+
if a.String() == pa.IP.String() {
578588
ni = i
579589
break
580590
}
581591
}
582592
}
583-
584-
if len(addrs) == 0 && i.Name == pi.Name {
585-
ni = i
586-
break
587-
}
588593
}
589594

590595
if ni.Flags&net.FlagLoopback != 0 {
591596
l.loopIndex = ni.Index
592597
}
593598

594-
if isDevice(l.host, pi) {
595-
l.Interfaces = []pcap.Interface{pi}
596-
return
597-
}
598-
599599
if runtime.GOOS != "windows" {
600600
if len(pi.Addresses) == 0 {
601601
continue

0 commit comments

Comments
 (0)