Hello,

When I tried to compile net-snmp 5.4.2.1 with Visual Studio 2005 this
resulted in several compiler warnings and one compiler error. Can
someone please review the patch below and either apply or reject it ?

Thanks,

Bart.

--------------------------------------------------------------------------------------------------------------------------------------------------------------

The patch below fixes the following issues:
- Compilation now succeeds -- <cstdio> should only be included in C++
source files, C source files should include <stdio.h>.
- The correct data type for an array of HANDLE's is HANDLE[] and not HANDLE*[].
- Fixed a warning on conversion between function types for the
function subagentTrapCheck by adding two ignored arguments to this
function.
- Removed several unused stack variables.
- Replaced "return (-1);" by "return;" inside functions with return type "void".
- Inserted a cast in front of the pointers passed to a function that
expects a pointer of a different type.
- Replaced "NULL" by "0" where the compiler expects an integer.
- Removed the statement "ResetEvent(dwWaitResult)" because passing an
integer to ResetEvent() does not make sense. I did not replace this
statement by a call to ResetEvent(subagentTrapEvents[dwWaitResult])
since this would introduce a race condition.


Index: winExtDLL.c
===================================================================
--- winExtDLL.c (revision 7916)
+++ winExtDLL.c (revision 7921)
@@ -23,7 +23,7 @@
  */

 #include <windows.h>
-#include <cstdio>
+#include <stdio.h>
 #include <Snmp-winExtDLL.h>                  // Modified Windows SDK
snmp.h.  See Notes above
 #include <mgmtapi.h>
 #include <string.h>
@@ -107,7 +107,7 @@
 char *extDLLs[MAX_WINEXT_DLLS];
 int extDLLs_index = 0;

-HANDLE *subagentTrapEvents[MAX_WINEXT_TRAP_EVENTS];
+HANDLE subagentTrapEvents[MAX_WINEXT_TRAP_EVENTS];
 int subagentTrapEvents_index = 0;

 void winExtDLL_free_config_winExtDLL(void);
@@ -115,7 +115,7 @@
 void read_ExtensionAgents_list();
 void read_ExtensionAgents_list2(const TCHAR *);

-void subagentTrapCheck();
+void subagentTrapCheck(unsigned int clientreg, void *clientarg);

 void send_trap(
     AsnObjectIdentifier *,
@@ -131,8 +131,6 @@
   HANDLE subagentTrapEvent;
   AsnObjectIdentifier pSupportedView;
   BOOL result;
-  HANDLE hThread;
-  DWORD IDThread;

   char dll_name[SZBUF_DLLNAME_MAX];
   DWORD (WINAPI *xSnmpExtensionInit)(DWORD, HANDLE*, AsnObjectIdentifier*);
@@ -150,8 +148,6 @@

   int iter, indx;

-  netsnmp_handler_registration *my_handler;
-
   HANDLE hInst = NULL;

   DEBUGMSGTL(("winExtDLL", "init_winExtDLL called\n"));
@@ -264,7 +260,7 @@
       snmp_log(LOG_ERR,
           "malloc failed registering handler for winExtDLL");
       DEBUGMSGTL(("winExtDLL", "malloc failed registering handler for
winExtDLL"));
-      return (-1);
+      return;
     }
     else {
       DEBUGMSGTL(("winExtDLL", "handler registered\n"));
@@ -330,7 +326,7 @@
           snmp_log(LOG_ERR,
               "malloc failed registering handler for winExtDLL");
           DEBUGMSGTL(("winExtDLL", "malloc failed registering handler
for winExtDLL"));
-          return (-1);
+          return;
         }
         else {
           DEBUGMSGTL(("winExtDLL", "handler registered\n"));
@@ -410,8 +406,6 @@
     u_char          netsnmp_ASN_type;
     u_char          windows_ASN_type;

-    char          *stringtemp;
-
     // WinSNMP variables:
     BOOL result;
     SnmpVarBind *mySnmpVarBind;
@@ -565,7 +560,7 @@
             pVarBindList.list->name.idLength = i;

             DEBUGMSGTL(("winExtDLL", "Windows OID: "));
-            DEBUGMSGWINOID(("winExtDLL", pVarBindList.list));
+            DEBUGMSGWINOID(("winExtDLL",
(AsnObjectIdentifier*)pVarBindList.list));
             DEBUGMSG(("winExtDLL", "\n"));

           }
@@ -606,7 +601,7 @@
           }

           DEBUGMSGTL(("winExtDLL", "Windows OID returned from
xSnmpExtensionQuery(Ex): "));
-          DEBUGMSGWINOID(("winExtDLL", pVarBindList.list));
+          DEBUGMSGWINOID(("winExtDLL",
(AsnObjectIdentifier*)pVarBindList.list));
           DEBUGMSG(("winExtDLL", "\n"));

           // Convert OID from Windows to Net-SNMP so Net-SNMP has the
new 'next' OID
@@ -767,7 +762,7 @@

             // Return results
             snmp_set_var_typed_value(var, netsnmp_ASN_type,
-                &ret_long,
+                (u_char*)&ret_long,
                 sizeof(ret_long));
             //return SNMP_ERR_NOERROR;
             break;
@@ -791,7 +786,7 @@
             DEBUGMSG(("winExtDLL", "\n"));

             snmp_set_var_typed_value(var, netsnmp_ASN_type,
-                ret_oid,
+                (u_char*)ret_oid,
                 ret_oid_length  * sizeof(oid));
             //return SNMP_ERR_NOERROR;

@@ -800,9 +795,9 @@
           default:
             // The Windows agent didn't return data so set values to NULL
             // FIXME:  We never get here.  We set it to INTEGER above..
-            snmp_set_var_typed_value(var, NULL,
+            snmp_set_var_typed_value(var, 0,
                 NULL,
-                NULL);
+                0);
             break;
         }
         if (&pVarBindList)
@@ -922,7 +917,7 @@
             // Print OID
             DEBUGMSGTL(("winExtDLL","Windows OID length:
%d\n",pVarBindList.list->name.idLength));
             DEBUGMSGTL(("winExtDLL","Windows OID: "));
-            DEBUGMSGWINOID(("winExtDLL", pVarBindList.list));
+            DEBUGMSGWINOID(("winExtDLL",
(AsnObjectIdentifier*)pVarBindList.list));
             DEBUGMSG(("winExtDLL", "\n"));
           }
           else {
@@ -994,7 +989,7 @@
               // Print OID
               DEBUGMSGTL(("winExtDLL","Windows OID length:
%d\n",mySnmpVarBind->name.idLength));
               DEBUGMSGTL(("winExtDLL","Windows OID: "));
-              DEBUGMSGWINOID(("winExtDLL", mySnmpVarBind));
+              DEBUGMSGWINOID(("winExtDLL",
(AsnObjectIdentifier*)mySnmpVarBind));
               DEBUGMSG(("winExtDLL", "\n"));
             }
             else {
@@ -1137,7 +1132,6 @@
   DWORD         valueSize = MAX_VALUE_NAME;
   TCHAR         valueName[MAX_VALUE_NAME];
   TCHAR         valueNameExpanded[MAX_VALUE_NAME];
-  int           i;
   DWORD         retCode;

   DEBUGMSGTL(("winExtDLL", "read_ExtensionAgents_list2 called\n"));
@@ -1166,7 +1160,7 @@
         &key_value_size);

     if (retCode == ERROR_SUCCESS) {
-      valueName[key_value_size-1] = NULL;               /* Make sure
last element is a NULL */
+      valueName[key_value_size-1] = '\0';               /* Make sure
last element is a '\0' */
       DEBUGMSGTL(("winExtDLL", "Extension agent Pathname size:
%d\n",key_value_size));
       DEBUGMSGTL(("winExtDLL", "Extension agent Pathname: %s\n",valueName));

@@ -1194,7 +1188,7 @@
 }

 // Called by alarm to check for traps waiting to be processed.
-void subagentTrapCheck() {
+void subagentTrapCheck(unsigned int clientreg, void *clientarg) {
   DWORD dwWaitResult;
   BOOL bResult;
   int i;
@@ -1239,7 +1233,7 @@

       pEnterprise.ids = NULL;
       pEnterprise.idLength = 0;
-      pGenericTrap = pSpecificTrap = NULL;
+      pGenericTrap = pSpecificTrap = 0;
       pTimeStamp = 0;
       pVariableBindings.list = NULL;
       pVariableBindings.len = 0;
@@ -1282,7 +1276,7 @@

         pEnterprise.ids = NULL;
         pEnterprise.idLength = 0;
-        pGenericTrap = pSpecificTrap = NULL;
+        pGenericTrap = pSpecificTrap = 0;
         pTimeStamp = 0;
         pVariableBindings.list = NULL;
         pVariableBindings.len = 0;
@@ -1322,10 +1316,6 @@
     }
   }

-  // Events should be auto-reset, but just in case..
-  ResetEvent(dwWaitResult);
-
-  return 1;
 }

Attachment: winextdll.patch
Description: Binary data

------------------------------------------------------------------------------
_______________________________________________
Net-snmp-coders mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/net-snmp-coders

Reply via email to