From be983931fc890b6ffc3194e310b0b1158f16963e Mon Sep 17 00:00:00 2001 From: David Wragg Date: Fri, 1 May 2015 21:40:53 +0100 Subject: [PATCH 1/2] 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. --- router/pcap.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/router/pcap.go b/router/pcap.go index e8594ecd..c3cd96d0 100644 --- a/router/pcap.go +++ b/router/pcap.go @@ -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 { From e40f1fe9a72fe0419689dad5e82a1fe988255549 Mon Sep 17 00:00:00 2001 From: Matthias Radestock Date: Sat, 2 May 2015 17:46:21 +0100 Subject: [PATCH 2/2] fix typo and reformat --- router/pcap.go | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/router/pcap.go b/router/pcap.go index c3cd96d0..b7365f68 100644 --- a/router/pcap.go +++ b/router/pcap.go @@ -45,13 +45,12 @@ 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 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_immediate_mode 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") }