diff -ruN ./net-snmp-5.4.2.1.orig/perl/TrapReceiver/TrapReceiver.pm ./net-snmp-5.4.2.1/perl/TrapReceiver/TrapReceiver.pm
--- ./net-snmp-5.4.2.1.orig/perl/TrapReceiver/TrapReceiver.pm	2008-10-31 16:22:23.000000000 +0100
+++ ./net-snmp-5.4.2.1/perl/TrapReceiver/TrapReceiver.pm	2009-03-27 14:45:26.000000000 +0100
@@ -135,6 +135,34 @@
 associated with it, and the value's numeric type (see NetSNMP::ASN for
 further details on SNMP typing information).
 
+Registered functions should return one of the following values:
+
+=over 2
+
+=item NETSNMPTRAPD_HANDLER_OK
+
+Handling the trap succeeded, but lets the snmptrapd demon check for
+further appropriate handlers.
+
+=item NETSNMPTRAPD_HANDLER_FAIL
+
+Handling the trap failed, but lets the snmptrapd demon check for
+further appropriate handlers.
+
+=item NETSNMPTRAPD_HANDLER_BREAK
+
+Stops evaluating the list of handlers for this specific trap, but lets
+the snmptrapd demon apply global handlers.
+
+=item NETSNMPTRAPD_HANDLER_FINISH
+
+Stops searching for further appropriate handlers.
+
+=back
+
+If a handler function does not return anything appropriate or even
+nothing at all, a return value of NETSNMPTRAPD_HANDLER_OK is assumed.
+
 Subroutines are registered using the NetSNMP::TrapReceiver::register
 function, which takes two arguments.  The first is a string describing
 the notification you want to register for (such as "linkUp" or
@@ -144,6 +172,7 @@
 no other handlers are called.  The "all" keyword indicates that the
 handler should ALWAYS be called for every notification.
 
+
 =head1 EXAMPLE
 
 As an example, put the following code into a file (say
diff -ruN ./net-snmp-5.4.2.1.orig/perl/TrapReceiver/TrapReceiver.xs ./net-snmp-5.4.2.1/perl/TrapReceiver/TrapReceiver.xs
--- ./net-snmp-5.4.2.1.orig/perl/TrapReceiver/TrapReceiver.xs	2008-06-01 08:45:23.000000000 +0200
+++ ./net-snmp-5.4.2.1/perl/TrapReceiver/TrapReceiver.xs	2009-03-26 14:25:39.000000000 +0100
@@ -39,6 +39,9 @@
     size_t ob_len = 0, oo_len = 0;
     AV *varbinds;
     HV *pduinfo;
+    int noValuesReturned;
+    int callingCFfailed = 0;
+    int result = NETSNMPTRAPD_HANDLER_OK;
 
     dSP;
     ENTER;
@@ -182,13 +185,42 @@
 
     /* actually call the callback function */
     if (SvTYPE(pcallback) == SVt_PVCV) {
-        perl_call_sv(pcallback, G_DISCARD);
+        noValuesReturned = perl_call_sv(pcallback, G_SCALAR);
         /* XXX: it discards the results, which isn't right */
     } else if (SvROK(pcallback) && SvTYPE(SvRV(pcallback)) == SVt_PVCV) {
         /* reference to code */
-        perl_call_sv(SvRV(pcallback), G_DISCARD);
+        noValuesReturned = perl_call_sv(SvRV(pcallback), G_SCALAR);
     } else {
         snmp_log(LOG_ERR, " tried to call a perl function but failed to understand its type: (ref = %x, svrok: %lu, SVTYPE: %lu)\n", (uintptr_t)pcallback, SvROK(pcallback), SvTYPE(pcallback));
+	callingCFfailed = 1;
+    }
+
+    if (!callingCFfailed) {
+      SPAGAIN;
+
+      if ( noValuesReturned == 0 ) {
+        snmp_log(LOG_WARNING, " perl callback function %x did not return a scalar, assuming %d (NETSNMPTRAPD_HANDLER_OK)\n", (uintptr_t)pcallback, NETSNMPTRAPD_HANDLER_OK);
+      }
+      else {
+	SV *rv = POPs;
+
+	if (SvTYPE(rv) != SVt_IV) {
+	  snmp_log(LOG_WARNING, " perl callback function %x returned a scalar of type %d instead of an integer, assuming %d (NETSNMPTRAPD_HANDLER_OK)\n", (uintptr_t)pcallback, SvTYPE(rv), NETSNMPTRAPD_HANDLER_OK);
+	}
+	else {
+	  int rvi = (IV)SvIVx(rv);
+
+	  if ((NETSNMPTRAPD_HANDLER_OK <= rvi) && (rvi <= NETSNMPTRAPD_HANDLER_FINISH)) {
+	    snmp_log(LOG_DEBUG, " perl callback function %x returns %d\n", (uintptr_t)pcallback, rvi);
+	    result = rvi;
+	  }
+	  else {
+	    snmp_log(LOG_WARNING, " perl callback function %x returned an invalid scalar integer value (%d), assuming %d (NETSNMPTRAPD_HANDLER_OK)\n", (uintptr_t)pcallback, rvi, NETSNMPTRAPD_HANDLER_OK);
+	  }
+	}
+      }
+
+      PUTBACK;
     }
 
 #ifdef DUMPIT
@@ -210,12 +242,9 @@
 #endif    
     free(tmparray);
 
-    /* Not needed because of the G_DISCARD flag (I think) */
-    /* SPAGAIN; */
-    /* PUTBACK; */
     FREETMPS;
     LEAVE;
-    return NETSNMPTRAPD_HANDLER_OK;
+    return result;
 }
 
 MODULE = NetSNMP::TrapReceiver		PACKAGE = NetSNMP::TrapReceiver		
