Browse Source

add descriptive error message on activate (#718)

Christian Mehlmauer 3 months ago
parent
commit
5d80840360
2 changed files with 5 additions and 1 deletions
  1. 4 1
      pcap/pcap.go
  2. 1 0
      pcap/pcap_unix.go

+ 4 - 1
pcap/pcap.go

@@ -271,6 +271,7 @@ const (
 	aeDenied       = activateError(pcapErrorDenied)
 	aeNotUp        = activateError(pcapErrorNotUp)
 	aeWarning      = activateError(pcapWarning)
+	aeError        = activateError(pcapError)
 )
 
 func (a activateError) Error() string {
@@ -289,6 +290,8 @@ func (a activateError) Error() string {
 		return "Interface Not Up"
 	case aeWarning:
 		return fmt.Sprintf("Warning: %v", activateErrMsg.Error())
+	case aeError:
+		return fmt.Sprintf("Error: %v", activateErrMsg.Error())
 	default:
 		return fmt.Sprintf("unknown activated error: %d", a)
 	}
@@ -763,7 +766,7 @@ func (p *InactiveHandle) Activate() (*Handle, error) {
 	pcapSetTstampPrecision(p.cptr, pcapTstampPrecisionNano)
 	handle, err := p.pcapActivate()
 	if err != aeNoError {
-		if err == aeWarning {
+		if err == aeWarning || err == aeError {
 			activateErrMsg = p.Error()
 		}
 		return nil, err

+ 1 - 0
pcap/pcap_unix.go

@@ -179,6 +179,7 @@ const (
 	pcapErrorDenied          = C.PCAP_ERROR_PERM_DENIED
 	pcapErrorNotUp           = C.PCAP_ERROR_IFACE_NOT_UP
 	pcapWarning              = C.PCAP_WARNING
+	pcapError                = C.PCAP_ERROR
 	pcapDIN                  = C.PCAP_D_IN
 	pcapDOUT                 = C.PCAP_D_OUT
 	pcapDINOUT               = C.PCAP_D_INOUT