Compare commits

...
Author SHA1 Message Date
Dima Golomozy 05ed821297 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.
2021-08-19 20:47:56 +03:00
Leonid Bugaev 7ae400413f Merge pull request #996 from DimaGolomozy/fixup-Src-Dst-Add-in-message
https://github.com/buger/goreplay/pull/995
2021-08-16 19:12:01 +03:00
dimagolomozy 25299eca6d no Src and Dst addr in message 2021-08-16 19:07:39 +03:00
2 changed files with 13 additions and 11 deletions
+11 -11
View File
@@ -569,33 +569,33 @@ func (l *Listener) setInterfaces() (err error) {
}
for _, pi := range pifis {
if isDevice(l.host, pi) {
l.Interfaces = []pcap.Interface{pi}
return
}
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()) {
if a.String() == pa.IP.String() {
ni = i
break
}
}
}
if len(addrs) == 0 && i.Name == pi.Name {
ni = i
break
}
}
if ni.Flags&net.FlagLoopback != 0 {
l.loopIndex = ni.Index
}
if isDevice(l.host, pi) {
l.Interfaces = []pcap.Interface{pi}
return
}
if runtime.GOOS != "windows" {
if len(pi.Addresses) == 0 {
continue
+2
View File
@@ -350,6 +350,8 @@ func (parser *MessageParser) processPacket(pckt *Packet) {
m = new(Message)
m.Direction = pckt.Direction
m.SrcAddr = pckt.SrcIP.String()
m.DstAddr = pckt.DstIP.String()
parser.m[mIDX][mID] = m