Produce a better error message when there is no real SetImmediateMode
If gopacket is compiled against an older pcap.h that doesn't have pcap_set_immediate_mode, it supplies a dummy definition that always returns PCAP_ERROR. That becomes "Generic error", which is not very helpful. The real pcap_set_set_immediate never returns PCAP_ERROR, so this turns it into a more informative message.
This commit is contained in:
1 parent
64f7e04e14
commit
be983931fc
1 file changed
+12
@@ -2,6 +2,7 @@ package router
|
||||
|
||||
import (
|
||||
"code.google.com/p/gopacket/pcap"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type PcapIO struct {
|
||||
@@ -44,6 +45,17 @@ func newPcapIO(ifName string, promisc bool, snaplen int, bufSz int) (handle *Pca
|
||||
return
|
||||
}
|
||||
if err = inactive.SetImmediateMode(true); err != nil {
|
||||
// If gopacket is compiled against an older pcap.h
|
||||
// that doesn't have pcap_set_immediate_mode, it
|
||||
// supplies a dummy definition that always returns
|
||||
// PCAP_ERROR. That becomes "Generic error", which is
|
||||
// not very helpful. The real pcap_set_set_immediate
|
||||
// never returns PCAP_ERROR, so this turns it into a
|
||||
// more informative message.
|
||||
if fmt.Sprint(err) == "Generic error" {
|
||||
err = fmt.Errorf("compiled against an old version of libpcap; please compile against libpcap-1.5.0 or later")
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
if err = inactive.SetBufferSize(bufSz); err != nil {
|
||||
|
||||
Reference in new issue
Block a user