Closed GalenMa closed 4 years ago
I can confirm the following program works fine on my network and am not sure what you're asking, so closing:
package main
import (
"log"
"net"
"github.com/davecgh/go-spew/spew"
"github.com/mdlayher/ethernet"
"github.com/mdlayher/lldp"
"github.com/mdlayher/raw"
)
func main() {
ifi, err := net.InterfaceByName("enp5s0")
if err != nil {
log.Fatalf("failed to get interface: %v", err)
}
c, err := raw.ListenPacket(ifi, uint16(lldp.EtherType), nil)
if err != nil {
log.Fatalf("failed to listen: %v", err)
}
defer c.Close()
var (
ef ethernet.Frame
lf lldp.Frame
b = make([]byte, ifi.MTU)
)
for {
n, addr, err := c.ReadFrom(b)
if err != nil {
log.Fatalf("failed to read: %v", err)
}
if err := ef.UnmarshalBinary(b[:n]); err != nil {
log.Fatalf("failed to unmarshal Ethernet: %v", err)
}
if err := lf.UnmarshalBinary(ef.Payload); err != nil {
log.Fatalf("failed to unmarshal LLDP: %v", err)
}
spew.Dump(addr, ef, lf)
}
}
$ sudo ./lldptest
(*raw.Addr)(0xc00000e280)(f0:9f:c2:ce:7e:e2)
(ethernet.Frame) {
Destination: (net.HardwareAddr) (len=6 cap=102) 01:80:c2:00:00:0e,
Source: (net.HardwareAddr) (len=6 cap=96) f0:9f:c2:ce:7e:e2,
...
@GalenMa I hit the same issue and it turned out you need to SetPromiscuous(true) on a connection object, since the destination mac address for LLDP packets is multicast, LLDP packets are getting ignored. Once I set promiscuous mode it started working.
@GalenMa I hit the same issue and it turned out you need to SetPromiscuous(true) on a connection object, since the destination mac address for LLDP packets is multicast, LLDP packets are getting ignored. Once I set promiscuous mode it started working.
thanks @sbezverk , I still have same problem when set promiscuous. Also, I got the lldp packages by tcpdump. Now, I changed to use GoPacket and solved this problem.
hello, I listen packet use: conn, err := raw.ListenPacket(&ifi, uint16(lldp.EtherType), &raw.Config{}) when read package : n, addr, err := conn.ReadFrom(b)
the lldp package can not be captured, but when change IPv4 and ARP, the packages can be captured.