mirror of
https://github.com/buger/goreplay.git
synced 2024-04-21 12:32:02 +00:00
Capture interfaces with ip (#944)
* capture nic only with ips * pcap.Interface and net.Interface flags are not the same. using net.Flags
This commit is contained in:
+18
-9
@@ -451,6 +451,7 @@ func (l *Listener) setInterfaces() (err error) {
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
for _, pi := range pifis {
|
||||
var ni net.Interface
|
||||
for _, i := range ifis {
|
||||
@@ -460,29 +461,37 @@ func (l *Listener) setInterfaces() (err error) {
|
||||
}
|
||||
}
|
||||
|
||||
if net.Flags(pi.Flags)&net.FlagLoopback != 0 {
|
||||
if ni.Flags&net.FlagLoopback != 0 {
|
||||
l.loopIndex = ni.Index
|
||||
}
|
||||
if net.Flags(pi.Flags)&net.FlagUp == 0 {
|
||||
if ni.Flags&net.FlagUp == 0 {
|
||||
continue
|
||||
}
|
||||
|
||||
if isDevice(l.host, pi) {
|
||||
l.Interfaces = []pcap.Interface{pi}
|
||||
return
|
||||
}
|
||||
for _, addr := range pi.Addresses {
|
||||
if addr.IP.String() == l.host {
|
||||
l.Interfaces = []pcap.Interface{pi}
|
||||
return
|
||||
}
|
||||
|
||||
if len(pi.Addresses) != 0 {
|
||||
l.Interfaces = append(l.Interfaces, pi)
|
||||
}
|
||||
}
|
||||
l.Interfaces = pifis
|
||||
return
|
||||
}
|
||||
|
||||
func isDevice(addr string, ifi pcap.Interface) bool {
|
||||
return addr == ifi.Name
|
||||
if addr == ifi.Name {
|
||||
return true
|
||||
}
|
||||
|
||||
for _, _addr := range ifi.Addresses {
|
||||
if _addr.IP.String() == addr {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
func interfaceAddresses(ifi pcap.Interface) []string {
|
||||
|
||||
Reference in New Issue
Block a user