pcap handles are not thread safe

they contain an errbuf; there might be other issues too.
So we must use different handles in the sniffer and udplistener
goroutines.
This commit is contained in:
Matthias Radestock committed 2014-08-20 11:42:55 +01:00
1 parent cb2cdc90cc
commit 7c4464c852
2 files changed
+21 -9

No files matched your search

+13 -3
View File
@@ -8,16 +8,26 @@ type PcapIO struct {
handle *pcap.Handle
}
func NewPcapIO(ifName string, bufSz int) (handle *PcapIO, err error) {
func NewPcapIO(ifName string, bufSz int) (pio PacketSourceSink, err error) {
pio, err = newPcapIO(ifName, true, 65535, bufSz)
return
}
func NewPcapO(ifName string) (po PacketSink, err error) {
po, err = newPcapIO(ifName, false, 0, 0)
return
}
func newPcapIO(ifName string, promisc bool, snaplen int, bufSz int) (handle *PcapIO, err error) {
inactive, err := pcap.NewInactiveHandle(ifName)
if err != nil {
return
}
defer inactive.CleanUp()
if inactive.SetPromisc(true) != nil {
if inactive.SetPromisc(promisc) != nil {
return
}
if inactive.SetSnapLen(65535) != nil {
if inactive.SetSnapLen(snaplen) != nil {
return
}
if inactive.SetTimeout(-1) != nil {