Check-in agent changes to support Win32 agent built with MSVC++.
Thanks to Robert Story.


git-svn-id: file:///home/hardaker/lib/sf-bkups/net-snmp-convert-svnrepo/trunk@3393 06827809-a52a-0410-b366-d66718629ded
diff --git a/agent/agent_read_config.c b/agent/agent_read_config.c
index e5f11af..6d33874 100644
--- a/agent/agent_read_config.c
+++ b/agent/agent_read_config.c
@@ -17,19 +17,36 @@
 #include <ctype.h>
 #include <errno.h>
 
-#include <sys/time.h>
+#if TIME_WITH_SYS_TIME
+# ifdef WIN32
+#  include <sys/timeb.h>
+# else
+#  include <sys/time.h>
+# endif
+# include <time.h>
+#else
+# if HAVE_SYS_TIME_H
+#  include <sys/time.h>
+# else
+#  include <time.h>
+# endif
+#endif
 #if HAVE_NETINET_IN_H
 #include <netinet/in.h>
 #endif
 #if HAVE_NETINET_IN_SYSTM_H
 #include <netinet/in_systm.h>
 #endif
+#if HAVE_NETINET_IP_H
 #include <netinet/ip.h>
+#endif
 #if HAVE_SYS_QUEUE_H
 #include <sys/queue.h>
 #endif
 #if HAVE_SYS_SOCKET_H
 #include <sys/socket.h>
+#elif HAVE_WINSOCK_H
+#include <winsock.h>
 #endif 
 #if HAVE_SYS_STREAM_H
 #include <sys/stream.h>
@@ -63,7 +80,7 @@
 #include "snmp_debug.h"
 #include "default_store.h"
 #include "ds_agent.h"
-#include "mibgroup/mib_module_includes.h"
+#include "mib_module_includes.h"
 
 char dontReadConfigFiles;
 char *optconfigfile;
@@ -89,7 +106,7 @@
                           snmpd_parse_config_trapcommunity,
                           snmpd_free_trapcommunity,
                           "community-string");
-#include "mibgroup/mib_module_dot_conf.h"
+#include "mib_module_dot_conf.h"
 #ifdef TESTING
   print_config_handlers();
 #endif
diff --git a/agent/agent_registry.c b/agent/agent_registry.c
index e6a8220..35a81db 100644
--- a/agent/agent_registry.c
+++ b/agent/agent_registry.c
@@ -15,9 +15,25 @@
 #include <stdlib.h>
 #endif
 #include <sys/types.h>
-#include <sys/time.h>
 #include <stdio.h>
 #include <fcntl.h>
+#if HAVE_WINSOCK_H
+#include <winsock.h>
+#endif
+#if TIME_WITH_SYS_TIME
+# ifdef WIN32
+#  include <sys/timeb.h>
+# else
+#  include <sys/time.h>
+# endif
+# include <time.h>
+#else
+# if HAVE_SYS_TIME_H
+#  include <sys/time.h>
+# else
+#  include <time.h>
+# endif
+#endif
 
 #if HAVE_DMALLOC_H
 #include <dmalloc.h>
@@ -32,7 +48,7 @@
 
 #include "snmpd.h"
 #include "mibgroup/struct.h"
-#include "mibgroup/mib_module_includes.h"
+#include "mib_module_includes.h"
 
 #ifdef USING_AGENTX_SUBAGENT_MODULE
 #include "agentx/subagent.h"
@@ -314,7 +330,7 @@
 	 *   for the rest of the range
 	 */
   if (( res == MIB_REGISTERED_OK ) && ( range_subid != 0 )) {
-    for ( i = mibloc[range_subid-1] +1 ; i < range_ubound ; i++ ) {
+    for ( i = mibloc[range_subid-1] +1 ; i < (int)range_ubound ; i++ ) {
 	sub2 = (struct subtree *) malloc(sizeof(struct subtree));
 	if ( sub2 == NULL ) {
 	    unregister_mib_range( mibloc, mibloclen, priority,
diff --git a/agent/agent_trap.c b/agent/agent_trap.c
index d61b2a8..2a35b02 100644
--- a/agent/agent_trap.c
+++ b/agent/agent_trap.c
@@ -15,7 +15,11 @@
 #include <strings.h>
 #endif
 #if TIME_WITH_SYS_TIME
-# include <sys/time.h>
+# ifdef WIN32
+#  include <sys/timeb.h>
+# else
+#  include <sys/time.h>
+# endif
 # include <time.h>
 #else
 # if HAVE_SYS_TIME_H
@@ -26,6 +30,8 @@
 #endif
 #if HAVE_SYS_SOCKET_H
 #include <sys/socket.h>
+#elif HAVE_WINSOCK_H
+#include <winsock.h>
 #endif
 #if HAVE_NETINET_IN_H
 #include <netinet/in.h>
diff --git a/agent/kernel.c b/agent/kernel.c
index 6ad0a70..b3cc46c 100644
--- a/agent/kernel.c
+++ b/agent/kernel.c
@@ -27,8 +27,10 @@
 #include "snmp_api.h"
 #include "snmp_impl.h"
 #include "snmp_logging.h"
+#include "default_store.h"
 
 #include "kernel.h"
+#include "ds_agent.h"
 
 #ifndef NULL
 #define NULL 0
diff --git a/agent/mib_modules.c b/agent/mib_modules.c
index 4020d94..8106634 100644
--- a/agent/mib_modules.c
+++ b/agent/mib_modules.c
@@ -15,6 +15,9 @@
 #if HAVE_NETINET_IN_H
 #include <netinet/in.h>
 #endif
+#if HAVE_WINSOCK_H
+#include <winsock.h>
+#endif
 
 #include "asn1.h"
 #include "snmp_api.h"
@@ -34,12 +37,12 @@
 
 #include "mibgroup/struct.h"
 #include "mib_modules.h"
-#include "mibgroup/mib_module_includes.h"
+#include "mib_module_includes.h"
 #ifdef USING_AGENTX_SUBAGENT_MODULE
 #include "mibgroup/agentx/subagent.h"
 #endif
 
 void
 init_mib_modules(void) {
-  #include "mibgroup/mib_module_inits.h"
+  #include "mib_module_inits.h"
 }
diff --git a/agent/mibgroup/mibII/system_mib.c b/agent/mibgroup/mibII/system_mib.c
index 4747ae5..c19445b 100644
--- a/agent/mibgroup/mibII/system_mib.c
+++ b/agent/mibgroup/mibII/system_mib.c
@@ -15,6 +15,9 @@
 #else
 #include <strings.h>
 #endif
+#if HAVE_WINSOCK_H
+#include <winsock.h>
+#endif
 #include "../mibincl.h"
 
 #ifdef HAVE_SYS_TIME_H
@@ -143,6 +146,7 @@
   sprintf(version_descr, "%s %s %s %s %s", utsName.sysname, utsName.nodename,
           utsName.release, utsName.version, utsName.machine);
 #else
+#if HAVE_EXECV
   struct extensible extmp;
 
   /* set default values of system stuff */
@@ -153,6 +157,9 @@
   exec_command(&extmp);
   strncpy(version_descr,extmp.output, sizeof(version_descr));
   version_descr[strlen(version_descr)-1] = 0; /* chomp new line */
+#else
+  strcpy(version_descr, "unknown" );
+#endif
 #endif
 
 #ifdef HAVE_GETHOSTNAME
@@ -363,7 +370,7 @@
 		return SNMP_ERR_WRONGLENGTH;
 	    }
 	    
-	    for(cp = var_val, count = 0; count < var_val_len; count++, cp++){
+	    for(cp = var_val, count = 0; count < (int)var_val_len; count++, cp++){
 		if (!isprint(*cp)){
                     snmp_log(LOG_ERR, "not print %x\n", *cp);
 		    return SNMP_ERR_WRONGVALUE;
diff --git a/agent/mibgroup/mibII/vacm_vars.c b/agent/mibgroup/mibII/vacm_vars.c
index 08a7889..0d11173 100644
--- a/agent/mibgroup/mibII/vacm_vars.c
+++ b/agent/mibgroup/mibII/vacm_vars.c
@@ -31,7 +31,12 @@
 #include <dmalloc.h>
 #endif
 
+#if HAVE_NETDB_H
 #include <netdb.h>
+#endif
+#if HAVE_WINSOCK_H
+#include <winsock.h>
+#endif
 
 #include "mibincl.h"
 #include "read_config.h"
@@ -42,7 +47,7 @@
 #include "agent_registry.h"
 #include "agent_callbacks.h"
 #include "vacm_vars.h"
-#include "../../mib_module_config.h"
+#include "mib_module_config.h"
 #ifdef USING_MIBII_SYSORTABLE_MODULE
 #if TIME_WITH_SYS_TIME
 # include <sys/time.h>
diff --git a/agent/mibgroup/mibincl.h b/agent/mibgroup/mibincl.h
index 9658964..26e87b3 100644
--- a/agent/mibgroup/mibincl.h
+++ b/agent/mibgroup/mibincl.h
@@ -6,7 +6,11 @@
 #include <sys/types.h>
 
 #if TIME_WITH_SYS_TIME
-# include <sys/time.h>
+# ifdef WIN32
+#  include <sys/timeb.h>
+# else
+#  include <sys/time.h>
+# endif
 # include <time.h>
 #else
 # if HAVE_SYS_TIME_H
@@ -21,20 +25,6 @@
 #if HAVE_SYS_SOCKET_H
 #include <sys/socket.h>
 #endif
-/* XX already included by sources including this file.
-   XX commented here because on some systems (older AIX)
-   XX the headers are not #ifndef protected.
-#if HAVE_NET_ROUTE_H
-#include <net/route.h>
-#endif
-#if HAVE_NETINET_IN_SYSTM_H
-#include <netinet/in_systm.h>
-#endif
-#include <netinet/ip.h>
-#if HAVE_NETINET_IN_PCB_H
-#include <netinet/in_pcb.h>
-#endif
- XX */
 
 #include "../../snmplib/asn1.h"
 #include "../../snmplib/snmp_api.h"
diff --git a/agent/mibgroup/smux/smux.c b/agent/mibgroup/smux/smux.c
index 8c644a9..86233ae 100644
--- a/agent/mibgroup/smux/smux.c
+++ b/agent/mibgroup/smux/smux.c
@@ -7,6 +7,9 @@
 #include <sys/types.h>
 #include <ctype.h>
 
+#if HAVE_IO_H  /* win32 */
+#include <io.h>
+#endif
 #include <stdio.h>
 #if HAVE_STDLIB_H
 #include <stdlib.h>
@@ -23,7 +26,11 @@
 #include <err.h>
 #endif
 #if TIME_WITH_SYS_TIME
-# include <sys/time.h>
+# ifdef WIN32
+#  include <sys/timeb.h>
+# else
+#  include <sys/time.h>
+# endif
 # include <time.h>
 #else
 # if HAVE_SYS_TIME_H
@@ -33,10 +40,16 @@
 # endif
 #endif
 #include <errno.h>
+#if HAVE_NETDB_H
 #include <netdb.h>
+#endif
 
 #include <sys/stat.h>
+#if HAVE_SYS_SOCKET_H
 #include <sys/socket.h>
+#elif HAVE_WINSOCK_H
+#include <winsock.h>
+#endif
 #if HAVE_SYS_FILIO_H
 #include <sys/filio.h>
 #endif
@@ -280,7 +293,6 @@
 	size_t len, var_len, datalen, name_length;
 	long reqid, errsts, erridx;
 	u_char var_type, *dataptr;
-	long lval;
 
 	DEBUGMSGTL (("smux","[var_smux_write] entering var_smux_write\n"));
 
@@ -652,7 +664,7 @@
 
         if (snmp_get_do_debugging()) {
           DEBUGMSGTL (("smux","[smux_open_process] smux peer:")); 
-          for (i=0; i<oid_name_len; i++) 
+          for (i=0; i < (int)oid_name_len; i++) 
             DEBUGMSG (("smux",".%d", oid_name[i]));
           DEBUGMSG (("smux"," \n"));
           DEBUGMSGTL (("smux","[smux_open_process] len %d, type %d\n", *len, (int)type));
@@ -668,7 +680,7 @@
 
         if (snmp_get_do_debugging()) {
           DEBUGMSGTL (("smux","[smux_open_process] smux peer descr:")); 
-          for (i=0; i<string_len; i++) 
+          for (i=0; i < (int)string_len; i++) 
             DEBUGMSG (("smux","%c", string[i]));
           DEBUGMSG (("smux"," \n"));
           DEBUGMSGTL (("smux","[smux_open_process] len %d, type %d\n", *len, (int)type));
@@ -684,7 +696,7 @@
 
         if (snmp_get_do_debugging()) {
           DEBUGMSGTL (("smux","[smux_open_process] smux peer passwd:")); 
-          for (i=0; i<string_len; i++) 
+          for (i=0; i < (int)string_len; i++) 
             DEBUGMSG (("smux","%c", string[i]));
           DEBUGMSG (("smux"," \n"));
           DEBUGMSGTL (("smux","[smux_open_process] len %d, type %d\n", *len, (int)type));
@@ -693,7 +705,7 @@
 	if(!smux_auth_peer(oid_name, oid_name_len, string, fd)) {
 		if(snmp_get_do_debugging()) {
 		    DEBUGMSGTL (("smux","[smux_open_process] peer authentication failed for oid\n"));
-		    for (i = 0; i < oid_name_len; i++) 
+		    for (i = 0; i < (int)oid_name_len; i++) 
 			DEBUGMSG (("smux","\t.%d", oid_name[i]));
 		    DEBUGMSG (("smux"," password %s\n", string));
 		}
@@ -851,7 +863,7 @@
 		nrptr->sr_priority = priority;
 		nrptr->sr_name_len = oid_name_len;
 		nrptr->sr_fd = sd;
-		for(i = 0; i < oid_name_len; i++)
+		for(i = 0; i < (int)oid_name_len; i++)
 			nrptr->sr_name[i] = oid_name[i];
 
 		/* See if this tree matches or scopes any of the
diff --git a/agent/mibgroup/snmpv3/snmpEngine.c b/agent/mibgroup/snmpv3/snmpEngine.c
index 4f7440a..c0a6678 100644
--- a/agent/mibgroup/snmpv3/snmpEngine.c
+++ b/agent/mibgroup/snmpv3/snmpEngine.c
@@ -2,15 +2,8 @@
 
 #include <config.h>
 
-#if TIME_WITH_SYS_TIME
-# include <sys/time.h>
-# include <time.h>
-#else
-# if HAVE_SYS_TIME_H
-#  include <sys/time.h>
-# else
-#  include <time.h>
-# endif
+#if HAVE_WINSOCK_H
+#include <winsock.h>
 #endif
 
 #include "mibincl.h"
diff --git a/agent/mibgroup/snmpv3/snmpMPDStats.c b/agent/mibgroup/snmpv3/snmpMPDStats.c
index ade78b6..f5635e8 100644
--- a/agent/mibgroup/snmpv3/snmpMPDStats.c
+++ b/agent/mibgroup/snmpv3/snmpMPDStats.c
@@ -2,15 +2,8 @@
 
 #include <config.h>
 
-#if TIME_WITH_SYS_TIME
-# include <sys/time.h>
-# include <time.h>
-#else
-# if HAVE_SYS_TIME_H
-#  include <sys/time.h>
-# else
-#  include <time.h>
-# endif
+#if HAVE_WINSOCK_H
+#include <winsock.h>
 #endif
 
 #include "mibincl.h"
diff --git a/agent/mibgroup/snmpv3/usmStats.c b/agent/mibgroup/snmpv3/usmStats.c
index bba0fcf..7c69611 100644
--- a/agent/mibgroup/snmpv3/usmStats.c
+++ b/agent/mibgroup/snmpv3/usmStats.c
@@ -3,15 +3,8 @@
 
 #include <config.h>
 
-#if TIME_WITH_SYS_TIME
-# include <sys/time.h>
-# include <time.h>
-#else
-# if HAVE_SYS_TIME_H
-#  include <sys/time.h>
-# else
-#  include <time.h>
-# endif
+#if HAVE_WINSOCK_H
+#include <winsock.h>
 #endif
 
 #include "mibincl.h"
diff --git a/agent/mibgroup/snmpv3/usmUser.c b/agent/mibgroup/snmpv3/usmUser.c
index ac42cc0..ccde5b7 100644
--- a/agent/mibgroup/snmpv3/usmUser.c
+++ b/agent/mibgroup/snmpv3/usmUser.c
@@ -17,6 +17,9 @@
 #ifdef HAVE_KMT_ALGS_H
 #	include <kmt_algs.h>
 #endif
+#if HAVE_WINSOCK_H
+#include <winsock.h>
+#endif
 
 #include "mibincl.h"
 #include "snmpusm.h"
@@ -113,11 +116,11 @@
     memmove(indexOid, prefix, prefixLen * sizeof (oid));
 
     indexOid[prefixLen] = uptr->engineIDLen;
-    for(i = 0; i < uptr->engineIDLen; i++)
+    for(i = 0; i < (int)uptr->engineIDLen; i++)
       indexOid[prefixLen+1+i] = (oid) uptr->engineID[i];
 
     indexOid[prefixLen + uptr->engineIDLen + 1] = strlen(uptr->name);
-    for(i = 0; i < strlen(uptr->name); i++)
+    for(i = 0; i < (int)strlen(uptr->name); i++)
       indexOid[prefixLen + uptr->engineIDLen + 2 + i] = (oid) uptr->name[i];
   }
   return indexOid;
@@ -149,12 +152,12 @@
     return 1;
   }
   engineIDL = *oidIndex;		/* initial engineID length */
-  if (oidLen < engineIDL + 2) {
+  if ((int)oidLen < engineIDL + 2) {
     DEBUGMSGTL(("usmUser","parse_oid: invalid oid length: less than the engineIDLen\n"));
     return 1;
   }
   nameL = oidIndex[engineIDL+1];	/* the initial name length */
-  if (oidLen != engineIDL + nameL + 2) {
+  if ((int)oidLen != engineIDL + nameL + 2) {
     DEBUGMSGTL(("usmUser","parse_oid: invalid oid length: length is not exact\n"));
     return 1;
   }
@@ -302,7 +305,7 @@
         indexOid = usm_generate_OID(vp->name, vp->namelen, nptr, &len);
         result = snmp_oid_compare(name, *length, indexOid, len);
         DEBUGMSGTL(("usmUser", "Checking user: %s - ", nptr->name));
-        for(i = 0; i < nptr->engineIDLen; i++) {
+        for(i = 0; i < (int)nptr->engineIDLen; i++) {
           DEBUGMSG(("usmUser", " %x",nptr->engineID[i]));
         }
         DEBUGMSG(("usmUser"," - %d \n  -> OID: ", result));
@@ -335,7 +338,7 @@
       *length = len;
       memmove(name, indexOid, len*sizeof(oid));
       DEBUGMSGTL(("usmUser", "Found user: %s - ", uptr->name));
-      for(i = 0; i < uptr->engineIDLen; i++) {
+      for(i = 0; i < (int)uptr->engineIDLen; i++) {
         DEBUGMSG(("usmUser", " %x",uptr->engineID[i]));
       }
       DEBUGMSG(("usmUser","\n  -> OID: "));
@@ -473,7 +476,7 @@
       return SNMP_ERR_WRONGLENGTH;
   }
   long_ret = *((long *) var_val);
-  if (long_ret != usmUserSpinLock)
+  if (long_ret != (long)usmUserSpinLock)
     return SNMP_ERR_INCONSISTENTVALUE;
   if (action == COMMIT) {
     if (usmUserSpinLock == 2147483647)
diff --git a/agent/mibgroup/target/snmpTargetAddrEntry.c b/agent/mibgroup/target/snmpTargetAddrEntry.c
index ac2d767..6471500 100644
--- a/agent/mibgroup/target/snmpTargetAddrEntry.c
+++ b/agent/mibgroup/target/snmpTargetAddrEntry.c
@@ -14,6 +14,9 @@
 #endif
 #include <stdlib.h>
 #include <ctype.h>
+#if HAVE_WINSOCK_H
+#include <winsock.h>
+#endif
 
 #include "mibincl.h"
 #include "snmpTargetAddrEntry.h"
@@ -96,14 +99,14 @@
   else {
     /* get the 'OID' value of the new entry */
     newOIDLen = strlen(newEntry->name);
-    for(i=0; i < newOIDLen ;i++) {
+    for(i=0; i < (int)newOIDLen ;i++) {
       newOID[i] = newEntry->name[i];
     }
 
     /* search through the list for an equal or greater OID value */
     while (curr_struct != 0) {
       currOIDLen = strlen(curr_struct->name);
-      for(i=0; i < currOIDLen ;i++) {
+      for(i=0; i < (int)currOIDLen ;i++) {
 	currOID[i] = curr_struct->name[i];
       }
 
@@ -177,7 +180,7 @@
    memcpy(newNum, baseName, baseNameLen*sizeof(oid));
   
    for( temp_struct = aAddrTable; temp_struct != 0; temp_struct = temp_struct->next) {
-     for(i=0; i < strlen(temp_struct->name) ;i++) {
+     for(i=0; i < (int)strlen(temp_struct->name) ;i++) {
        newNum[baseNameLen+i] = temp_struct->name[i];
      }
      myOIDLen = baseNameLen+strlen(temp_struct->name);
@@ -735,7 +738,7 @@
 
   /* Finally, we're golden, check if we should save value */
   if (action == COMMIT)  {    
-    for (i=0;i<objSize;i++) 
+    for (i=0;i < (int)objSize; i++) 
       temp_struct->tDomain[i] = objid[i];
     temp_struct->tDomainLen = objSize;
 
@@ -1099,7 +1102,7 @@
     temp_struct       = snmpTargetAddrTable_create();
     temp_struct->name = (char *)malloc(sizeof(char)*(newNameLen + 1));
 
-    for (i = 0; i < newNameLen; i++) {
+    for (i = 0; i < (int)newNameLen; i++) {
       temp_struct->name[i] = (char)name[i+snmpTargetAddrOIDLen];
     }
 
diff --git a/agent/mibgroup/target/snmpTargetParamsEntry.c b/agent/mibgroup/target/snmpTargetParamsEntry.c
index f9b9212..22c4627 100644
--- a/agent/mibgroup/target/snmpTargetParamsEntry.c
+++ b/agent/mibgroup/target/snmpTargetParamsEntry.c
@@ -14,6 +14,9 @@
 #endif
 #include <stdlib.h>
 #include <ctype.h>
+#if HAVE_WINSOCK_H
+#include <winsock.h>
+#endif
 
 #include "mibincl.h"
 #include "snmpTargetParamsEntry.h"
@@ -89,14 +92,14 @@
   else {
     /* get the 'OID' value of the new entry */
     newOIDLen = strlen(newEntry->paramName);
-    for(i=0; i < newOIDLen ;i++) {
+    for(i=0; i < (int)newOIDLen ;i++) {
       newOID[i] = newEntry->paramName[i];
     }
 
     /* search through the list for an equal or greater OID value */
     while (curr_struct != 0) {
       currOIDLen = strlen(curr_struct->paramName);
-      for(i=0; i < currOIDLen ;i++) {
+      for(i=0; i < (int)currOIDLen ;i++) {
 	currOID[i] = curr_struct->paramName[i];
       }
 
@@ -170,7 +173,7 @@
    memcpy(newNum, baseName, baseNameLen*sizeof(oid));
   
    for( temp_struct = aPTable; temp_struct != 0; temp_struct = temp_struct->next) {
-     for(i=0; i < strlen(temp_struct->paramName) ;i++) {
+     for(i=0; i < (int)strlen(temp_struct->paramName) ;i++) {
        newNum[baseNameLen+i] = temp_struct->paramName[i];
      }
      myOIDLen = baseNameLen+strlen(temp_struct->paramName);
diff --git a/agent/mibgroup/ucd-snmp/disk.c b/agent/mibgroup/ucd-snmp/disk.c
index 7ce862e..286a6bf 100644
--- a/agent/mibgroup/ucd-snmp/disk.c
+++ b/agent/mibgroup/ucd-snmp/disk.c
@@ -110,7 +110,11 @@
 #include <netinet/in.h>
 #endif
 #if TIME_WITH_SYS_TIME
-# include <sys/time.h>
+# ifdef WIN32
+#  include <sys/timeb.h>
+# else
+#  include <sys/time.h>
+# endif
 # include <time.h>
 #else
 # if HAVE_SYS_TIME_H
@@ -119,6 +123,9 @@
 #  include <time.h>
 # endif
 #endif
+#if HAVE_WINSOCK_H
+#include <winsock.h>
+#endif
 
 #if HAVE_DMALLOC_H
 #include <dmalloc.h>
diff --git a/agent/mibgroup/ucd-snmp/errormib.c b/agent/mibgroup/ucd-snmp/errormib.c
index 8c162e6..dd0e503 100644
--- a/agent/mibgroup/ucd-snmp/errormib.c
+++ b/agent/mibgroup/ucd-snmp/errormib.c
@@ -11,7 +11,11 @@
 #endif
 #include <signal.h>
 #if TIME_WITH_SYS_TIME
-# include <sys/time.h>
+# ifdef WIN32
+#  include <sys/timeb.h>
+# else
+#  include <sys/time.h>
+# endif
 # include <time.h>
 #else
 # if HAVE_SYS_TIME_H
@@ -107,6 +111,9 @@
 #if HAVE_STRING_H
 #include <string.h>
 #endif
+#if HAVE_WINSOCK_H
+#include <winsock.h>
+#endif
 
 #if HAVE_DMALLOC_H
 #include <dmalloc.h>
diff --git a/agent/mibgroup/ucd-snmp/extensible.c b/agent/mibgroup/ucd-snmp/extensible.c
index 3fe4628..7f28f4e 100644
--- a/agent/mibgroup/ucd-snmp/extensible.c
+++ b/agent/mibgroup/ucd-snmp/extensible.c
@@ -10,7 +10,11 @@
 #include <fcntl.h>
 #endif
 #if TIME_WITH_SYS_TIME
-# include <sys/time.h>
+# ifdef WIN32
+#  include <sys/timeb.h>
+# else
+#  include <sys/time.h>
+# endif
 # include <time.h>
 #else
 # if HAVE_SYS_TIME_H
@@ -96,6 +100,12 @@
 #include <string.h>
 #endif
 #include <ctype.h>
+#if HAVE_WINSOCK_H
+#include <winsock.h>
+#endif
+#ifndef HAVE_STRNCASECMP
+int strncasecmp(const char *s1, const char *s2, size_t n);
+#endif
 
 #if HAVE_DMALLOC_H
 #include <dmalloc.h>
@@ -247,7 +257,7 @@
   int i;
   
   if (exten == NULL) return(NULL);
-  for (i=1;i != inst && exten != NULL; i++) exten = exten->next;
+  for (i=1;i != (int)inst && exten != NULL; i++) exten = exten->next;
   return(exten);
 }
 
@@ -409,7 +419,7 @@
 {
 
   int fd;
-  size_t i;
+  int i;
   FILE *file;
   struct extensible *exten = 0;
   static long long_ret;
@@ -420,9 +430,9 @@
   memcpy(&myvp,vp,sizeof(struct variable));
 
   long_ret = *length;
-  for(i=1; i<= numrelocs; i++) {
+  for(i=1; i <= (int)numrelocs; i++) {
     exten = get_exten_instance(relocs,i);
-    if (exten->miblen == vp->namelen-1){
+    if ((int)exten->miblen == (int)vp->namelen-1){
       memcpy(myvp.name,exten->miboid,exten->miblen*sizeof(oid));
       myvp.namelen = exten->miblen;
       *length = vp->namelen;
@@ -433,7 +443,7 @@
         exten = NULL;
     }
   }
-  if (i > numrelocs || exten == NULL) {
+  if (i > (int)numrelocs || exten == NULL) {
     *length = long_ret;
     *var_len = 0;
     *write_method = NULL;
@@ -466,7 +476,7 @@
       if (exten->type == EXECPROC) {
         if ((fd = get_exec_output(exten))){
           file = fdopen(fd,"r");
-          for (i=0;i != name[*length-1];i++) {
+          for (i=0;i != (int)name[*length-1];i++) {
             if (fgets(errmsg,sizeof(errmsg),file) == NULL) {
               *var_len = 0;
               fclose(file);
@@ -503,13 +513,13 @@
 				int exact)
 {
   size_t tmp;
-  size_t i;
+  int i;
   struct extensible *exten = 0;
   struct variable myvp;
   oid name[MAX_OID_LEN];
   static struct subtree mysubtree[2];
 
-  for(i=1; i<= numrelocs; i++) {
+  for(i=1; i <= (int)numrelocs; i++) {
     exten = get_exten_instance(relocs,i);
     if (exten->miblen != 0){
       memcpy(myvp.name,exten->miboid,exten->miblen*sizeof(oid));
@@ -521,7 +531,7 @@
         break;
     }
   }
-  if (i > numrelocs || exten == NULL)
+  if (i > (int)numrelocs || exten == NULL)
     return(tp);
   memcpy(mysubtree[0].name,exten->miboid,exten->miblen*sizeof(oid));
   mysubtree[0].namelen = exten->miblen;
diff --git a/agent/mibgroup/ucd-snmp/file.c b/agent/mibgroup/ucd-snmp/file.c
index 5581832..fa92f2e 100644
--- a/agent/mibgroup/ucd-snmp/file.c
+++ b/agent/mibgroup/ucd-snmp/file.c
@@ -3,7 +3,11 @@
 #include <sys/types.h>
 #include <sys/stat.h>
 #if TIME_WITH_SYS_TIME
-# include <sys/time.h>
+# ifdef WIN32
+#  include <sys/timeb.h>
+# else
+#  include <sys/time.h>
+# endif
 # include <time.h>
 #else
 # if HAVE_SYS_TIME_H
@@ -12,6 +16,9 @@
 #  include <time.h>
 # endif
 #endif
+#if HAVE_WINSOCK_H
+#include <winsock.h>
+#endif
 
 #if HAVE_DMALLOC_H
 #include <dmalloc.h>
diff --git a/agent/mibgroup/ucd-snmp/loadave.c b/agent/mibgroup/ucd-snmp/loadave.c
index 454f508..8eecda3 100644
--- a/agent/mibgroup/ucd-snmp/loadave.c
+++ b/agent/mibgroup/ucd-snmp/loadave.c
@@ -98,7 +98,11 @@
 #include <string.h>
 #endif
 #if TIME_WITH_SYS_TIME
-# include <sys/time.h>
+# ifdef WIN32
+#  include <sys/timeb.h>
+# else
+#  include <sys/time.h>
+# endif
 # include <time.h>
 #else
 # if HAVE_SYS_TIME_H
@@ -107,6 +111,9 @@
 #  include <time.h>
 # endif
 #endif
+#if HAVE_WINSOCK_H
+#include <winsock.h>
+#endif
 
 #include "mibincl.h"
 #include "struct.h"
@@ -211,7 +218,9 @@
   for(i=0;i<s_ave;i++)
     *(pave+i) = FIX_TO_DBL(favenrun[i]);
 #elif !defined(cygwin)
+#ifdef CAN_USE_NLIST
   if (auto_nlist(LOADAVE_SYMBOL,(char *) pave, sizeof(double)*s_ave) == 0)
+#endif
     return (-1);
 #endif
 /*
@@ -276,7 +285,7 @@
       return((u_char *) (&long_ret));
 #ifdef OPAQUE_SPECIAL_TYPES
     case LOADAVEFLOAT:
-      float_ret = avenrun[name[*length-1]-1];
+      float_ret = (float)avenrun[name[*length-1]-1];
       *var_len = sizeof(float_ret);
       return((u_char *) (&float_ret));
 #endif
diff --git a/agent/mibgroup/ucd-snmp/pass.c b/agent/mibgroup/ucd-snmp/pass.c
index 9dce749..825e045 100644
--- a/agent/mibgroup/ucd-snmp/pass.c
+++ b/agent/mibgroup/ucd-snmp/pass.c
@@ -17,19 +17,12 @@
 #if HAVE_NETINET_IN_H
 #include <netinet/in.h>
 #endif
-#if TIME_WITH_SYS_TIME
-# include <sys/time.h>
-# include <time.h>
-#else
-# if HAVE_SYS_TIME_H
-#  include <sys/time.h>
-# else
-#  include <time.h>
-# endif
-#endif
 #if HAVE_SYS_WAIT_H
 # include <sys/wait.h>
 #endif
+#if HAVE_WINSOCK_H
+#include <winsock.h>
+#endif
 
 #if HAVE_DMALLOC_H
 #include <dmalloc.h>
@@ -75,12 +68,12 @@
     int i, flag = 0;
     char buffer[BUFMAX];
 
-    for (i = 0; i < n; i++) {
+    for (i = 0; i < (int)n; i++) {
         buffer[i] = p[i];
         if (!isprint(p[i])) flag = 1;
     }
     if (flag == 0) return n;
-    for (i = 0; i < n; i++) {
+    for (i = 0; i < (int)n; i++) {
         sprintf(p, "%02x ", (unsigned char)(buffer[i] & 0xff));
         p += 3;
     }
@@ -143,13 +136,7 @@
         i++, ptmp = ptmp->next)
       etmp[i] = ptmp;
     qsort(etmp, numpassthrus, sizeof(struct extensible *),
-#ifdef __STDC__
-         (int (*)(const void *, const void *)) pass_compare
-#else
-	  pass_compare
-#endif
-          
-      );
+	  pass_compare);
     passthrus = (struct extensible *) etmp[0];
     ptmp = (struct extensible *) etmp[0];
     
@@ -383,7 +370,7 @@
           memset(buf2,(0),itmp);
           memcpy(buf2, var_val, var_val_len);
           buf2[var_val_len] = 0;
-          if (bin2asc(buf2, itmp) == itmp)
+          if ((int)bin2asc(buf2, itmp) == (int)itmp)
               sprintf(buf,"string %s",buf2);
           else
               sprintf(buf,"octet %s",buf2);
@@ -413,7 +400,7 @@
   return SNMP_ERR_NOSUCHNAME;
 }
 
-int pass_compare(void *a, void *b)
+int pass_compare(const void *a, const void *b)
 {
   struct extensible **ap, **bp;
   ap = (struct extensible **) a;
diff --git a/agent/mibgroup/ucd-snmp/pass.h b/agent/mibgroup/ucd-snmp/pass.h
index 51453d7..8c29169 100644
--- a/agent/mibgroup/ucd-snmp/pass.h
+++ b/agent/mibgroup/ucd-snmp/pass.h
@@ -10,7 +10,7 @@
 
 extern FindVarMethod var_extensible_pass;
 WriteMethod setPass;
-int pass_compare (void *, void *);
+int pass_compare (const void *, const void *);
 
 /* config file parsing routines */
 void pass_free_config (void);
diff --git a/agent/mibgroup/ucd-snmp/pass_persist.c b/agent/mibgroup/ucd-snmp/pass_persist.c
index 15f210f..83f083a 100644
--- a/agent/mibgroup/ucd-snmp/pass_persist.c
+++ b/agent/mibgroup/ucd-snmp/pass_persist.c
@@ -17,16 +17,6 @@
 #if HAVE_NETINET_IN_H
 #include <netinet/in.h>
 #endif
-#if TIME_WITH_SYS_TIME
-# include <sys/time.h>
-# include <time.h>
-#else
-# if HAVE_SYS_TIME_H
-#  include <sys/time.h>
-# else
-#  include <time.h>
-# endif
-#endif
 
 #if HAVE_DMALLOC_H
 #include <dmalloc.h>
@@ -115,12 +105,7 @@
         i++, ptmp = ptmp->next)
       etmp[i] = ptmp;
     qsort(etmp, numpersistpassthrus, sizeof(struct extensible *),
-#ifdef __STDC__
-         (int (*)(const void *, const void *)) pass_persist_compare
-#else
-          pass_persist_compare
-#endif
-      );
+          pass_persist_compare);
     persistpassthrus = (struct extensible *) etmp[0];
     ptmp = (struct extensible *) etmp[0];
 
@@ -407,7 +392,7 @@
   return SNMP_ERR_NOSUCHNAME;
 }
 
-int pass_persist_compare(void *a, void *b)
+int pass_persist_compare(const void *a, const void *b)
 {
   struct extensible **ap, **bp;
   ap = (struct extensible **) a;
diff --git a/agent/mibgroup/ucd-snmp/pass_persist.h b/agent/mibgroup/ucd-snmp/pass_persist.h
index a60f4e4..a90b3dd 100644
--- a/agent/mibgroup/ucd-snmp/pass_persist.h
+++ b/agent/mibgroup/ucd-snmp/pass_persist.h
@@ -12,7 +12,7 @@
 /* config file parsing routines */
 void pass_persist_free_config (void);
 void pass_persist_parse_config (char *, char *);
-int pass_persist_compare (void *, void *);
+int pass_persist_compare (const void *, const void *);
 
 #include "mibdefs.h"
 
diff --git a/agent/mibgroup/ucd-snmp/proc.c b/agent/mibgroup/ucd-snmp/proc.c
index ef56ab2..18bc78b 100644
--- a/agent/mibgroup/ucd-snmp/proc.c
+++ b/agent/mibgroup/ucd-snmp/proc.c
@@ -5,6 +5,9 @@
 #include <sys/types.h>   /* helps define struct rlimit */
 #endif
 
+#if HAVE_IO_H  /* win32 */
+#include <io.h>
+#endif
 #if HAVE_STDLIB_H
 #include <stdlib.h>
 #endif
@@ -26,7 +29,11 @@
 #include <netinet/in.h>
 #endif
 #if TIME_WITH_SYS_TIME
-# include <sys/time.h>
+# ifdef WIN32
+#  include <sys/timeb.h>
+# else
+#  include <sys/time.h>
+# endif
 # include <time.h>
 #else
 # if HAVE_SYS_TIME_H
@@ -35,6 +42,9 @@
 #  include <time.h>
 # endif
 #endif
+#if HAVE_WINSOCK_H
+#include <winsock.h>
+#endif
 
 #if HAVE_DMALLOC_H
 #include <dmalloc.h>
@@ -54,6 +64,10 @@
 #include "mib_module_config.h"
 #include "system.h"
 
+#ifdef USING_UCD_SNMP_ERRORMIB_MODULE
+#include "errormib.h"
+#endif
+
 static struct myproc *get_proc_instance (struct myproc *, oid);
 struct myproc *procwatch = NULL;
 static struct extensible fixproc;
@@ -303,7 +317,7 @@
   int i;
   
   if (proc == NULL) return(NULL);
-  for (i=1;i != inst && proc != NULL; i++) proc = proc->next;
+  for (i=1; (i != (int)inst) && (proc != NULL); i++) proc = proc->next;
   return(proc);
 }
 
diff --git a/agent/mibgroup/ucd-snmp/registry.c b/agent/mibgroup/ucd-snmp/registry.c
index 79cdfae..45d0df0 100644
--- a/agent/mibgroup/ucd-snmp/registry.c
+++ b/agent/mibgroup/ucd-snmp/registry.c
@@ -11,6 +11,9 @@
 #if HAVE_NETINET_IN_H
 #include <netinet/in.h>
 #endif
+#if HAVE_WINSOCK_H
+#include <winsock.h>
+#endif
 
 #include "mibincl.h"
 #include "registry.h"
diff --git a/agent/mibgroup/ucd-snmp/versioninfo.c b/agent/mibgroup/ucd-snmp/versioninfo.c
index 641bad2..2d3dc1a 100644
--- a/agent/mibgroup/ucd-snmp/versioninfo.c
+++ b/agent/mibgroup/ucd-snmp/versioninfo.c
@@ -2,7 +2,11 @@
 
 #include <sys/types.h>
 #if TIME_WITH_SYS_TIME
-# include <sys/time.h>
+# ifdef WIN32
+#  include <sys/timeb.h>
+# else
+#  include <sys/time.h>
+# endif
 # include <time.h>
 #else
 # if HAVE_SYS_TIME_H
@@ -14,6 +18,9 @@
 #if HAVE_NETINET_IN_H
 #include <netinet/in.h>
 #endif
+#if HAVE_WINSOCK_H
+#include <winsock.h>
+#endif
 
 #include "mibincl.h"
 #include "struct.h"
diff --git a/agent/mibgroup/util_funcs.c b/agent/mibgroup/util_funcs.c
index f69f2d0..e5835a2 100644
--- a/agent/mibgroup/util_funcs.c
+++ b/agent/mibgroup/util_funcs.c
@@ -4,6 +4,9 @@
 
 #include <config.h>
 
+#if HAVE_IO_H
+#include <io.h>
+#endif
 #include <stdio.h>
 #if HAVE_STDLIB_H
 #include <stdlib.h>
@@ -34,7 +37,11 @@
 # define WIFEXITED(stat_val) (((stat_val) & 255) == 0)
 #endif
 #if TIME_WITH_SYS_TIME
-# include <sys/time.h>
+# ifdef WIN32
+#  include <sys/timeb.h>
+# else
+#  include <sys/time.h>
+# endif
 # include <time.h>
 #else
 # if HAVE_SYS_TIME_H
@@ -57,7 +64,16 @@
 #include <strings.h>
 #endif
 #include <ctype.h>
-
+#if HAVE_WINSOCK_H
+#include <winsock.h>
+#endif
+#if HAVE_BASETSD_H
+#include <basetsd.h>
+#define ssize_t SSIZE_T
+#endif
+#if HAVE_RAISE
+#define alarm raise
+#endif
 #include "mibincl.h"
 #include "struct.h"
 #include "util_funcs.h"
@@ -88,6 +104,7 @@
 
 int shell_command(struct extensible *ex)
 {
+#if HAVE_SYSTEM
   char shellline[STRMAX];
   FILE *shellout;
   
@@ -102,6 +119,10 @@
     fclose(shellout);
   }
   unlink("/tmp/shoutput");
+#else
+  ex->output[0] = 0;
+  ex->result = 0;
+#endif
   return(ex->result);
 }
 
@@ -109,6 +130,7 @@
 
 int exec_command(struct extensible *ex)
 {
+#if HAVE_EXECV
   int fd;
   FILE *file;
   
@@ -119,7 +141,9 @@
     }
     fclose(file);
     wait_on_exec(ex);
-  } else {
+  } else
+#endif
+  {
     ex->output[0] = 0;
     ex->result = 0;
   }
@@ -140,6 +164,7 @@
 
 int get_exec_output(struct extensible *ex)
 {
+#if HAVE_EXECV
   int fd[2],i, cnt;
   char ctmp[STRMAX], *cptr1, *cptr2, argvs[STRMAX], **argv, **aptr;
 #ifdef EXCACHETIME
@@ -257,7 +282,7 @@
         ex->pid = 0;
         ex->result = WEXITSTATUS(ex->result);
         lastresult = ex->result;
-#else
+#else /* !EXCACHETIME */
         return(fd[0]);
 #endif
       }
@@ -272,6 +297,10 @@
   }
   return(cfd);
 #endif
+
+#else /* !HAVE_EXECV */
+  return 0;
+#endif
 }
 
 int get_exec_pipes(char *cmd,
@@ -280,6 +309,7 @@
 		   int *pid)
 
 {
+#if HAVE_EXECV
   int fd[2][2],i, cnt;
   char ctmp[STRMAX], *cptr1, *cptr2, argvs[STRMAX], **argv, **aptr;
   /* Setup our pipes */
@@ -347,6 +377,8 @@
       *fdOut = fd[0][1];
       return(1); /* We are returning 0 for error... */
     }
+#endif /* !HAVE_EXECV */
+  return 0;
 }
 
 int clear_cache(int action,
@@ -384,8 +416,10 @@
     close(i);
 
   /* do the exec */
+#if HAVE_EXECV
   execv(argvrestartname,argvrestartp);
   setPerrorstatus("execv");
+#endif
 }
 
 int
@@ -406,7 +440,9 @@
   }
   tmp = *((long *) var_val);
   if (tmp == 1 && action == COMMIT) {
+#ifdef SIGALRM
     signal(SIGALRM,restart_doit);
+#endif
     alarm(RESTARTSLEEP);
   } 
   return SNMP_ERR_NOERROR;
@@ -433,7 +469,7 @@
 	       size_t len)
 {
   int i;
-  for(i=0; i < len; i++) {
+  for(i=0; i < (int)len; i++) {
     sprintf(buf,".%d",(int) name[i]);
     while (*buf != 0)
       buf++;
@@ -487,8 +523,8 @@
     }
   }
   if (rtest > 0 ||
-      (rtest == 0 && !exact && (int) vp->namelen+1 < (int) *length) ||
-    (exact == 1 && (rtest || *length != vp->namelen+1))) {
+      (rtest == 0 && !exact && (int)(vp->namelen+1) < (int) *length) ||
+    (exact == 1 && (rtest || (int)*length != (int)(vp->namelen+1)))) {
     if (var_len)
 	*var_len = 0;
     return MATCH_FAILED;
@@ -509,7 +545,7 @@
     else
       newname[*length-1] = name[*length-1];
   }  
-  if (max >= 0 && newname[*length-1] > max) {
+  if (max >= 0 && ((int)newname[*length-1] > max)) {
     if(var_len)
       *var_len = 0;
     return MATCH_FAILED;
diff --git a/agent/snmp_agent.c b/agent/snmp_agent.c
index 35e817e..67cd103 100644
--- a/agent/snmp_agent.c
+++ b/agent/snmp_agent.c
@@ -32,7 +32,11 @@
 #include <stdlib.h>
 #endif
 #if TIME_WITH_SYS_TIME
-# include <sys/time.h>
+# ifdef WIN32
+#  include <sys/timeb.h>
+# else
+#  include <sys/time.h>
+# endif
 # include <time.h>
 #else
 # if HAVE_SYS_TIME_H
@@ -48,6 +52,9 @@
 #include <netinet/in.h>
 #endif
 #include <errno.h>
+#if HAVE_WINSOCK_H
+#include <winsock.h>
+#endif
 
 #if HAVE_DMALLOC_H
 #include <dmalloc.h>
diff --git a/agent/snmp_vars.c b/agent/snmp_vars.c
index 5020638..27c33e9 100644
--- a/agent/snmp_vars.c
+++ b/agent/snmp_vars.c
@@ -41,12 +41,27 @@
 #include <stdlib.h>
 #endif
 #include <sys/types.h>
-#include <sys/time.h>
 #include <stdio.h>
 #include <fcntl.h>
 
+#if TIME_WITH_SYS_TIME
+# ifdef WIN32
+#  include <sys/timeb.h>
+# else
+#  include <sys/time.h>
+# endif
+# include <time.h>
+#else
+# if HAVE_SYS_TIME_H
+#  include <sys/time.h>
+# else
+#  include <time.h>
+# endif
+#endif
 #if HAVE_SYS_SOCKET_H
 #include <sys/socket.h>
+#elif HAVE_WINSOCK_H
+#include <winsock.h>
 #endif
 #if HAVE_NETINET_IN_H
 #include <netinet/in.h>
@@ -54,7 +69,9 @@
 #if HAVE_NETINET_IN_SYSTM_H
 #include <netinet/in_systm.h>
 #endif
+#if HAVE_NETINET_IP_H
 #include <netinet/ip.h>
+#endif
 #if HAVE_SYS_QUEUE_H
 #include <sys/queue.h>
 #endif
@@ -94,7 +111,7 @@
 #include "transform_oids.h"
 #include "callback.h"
 #include "snmpd.h"
-#include "mibgroup/mib_module_includes.h"
+#include "mib_module_includes.h"
 
 #ifndef  MIN
 #define  MIN(a,b)                     (((a) < (b)) ? (a) : (b)) 
@@ -393,7 +410,7 @@
     struct snmp_pdu *pdu,   /* IN - relevant auth info re PDU */
     int		*noSuchObject)
 {
-    struct subtree	*tp, *prev;
+    struct subtree	*tp;
     oid			save[MAX_OID_LEN];
     size_t		savelen = 0;
     u_char              result_type;
diff --git a/agent/snmpd.c b/agent/snmpd.c
index 05c81d8..3d0ccd6 100644
--- a/agent/snmpd.c
+++ b/agent/snmpd.c
@@ -46,7 +46,11 @@
 #include <arpa/inet.h>
 #endif
 #if TIME_WITH_SYS_TIME
-# include <sys/time.h>
+# ifdef WIN32
+#  include <sys/timeb.h>
+# else
+#  include <sys/time.h>
+# endif
 # include <time.h>
 #else
 # if HAVE_SYS_TIME_H
@@ -60,6 +64,8 @@
 #endif
 #if HAVE_SYS_SOCKET_H
 #include <sys/socket.h>
+#elif HAVE_WINSOCK_H
+#include <winsock.h>
 #endif
 #if HAVE_NET_IF_H
 #include <net/if.h>
@@ -76,7 +82,9 @@
 #ifdef HAVE_FCNTL_H
 #include <fcntl.h>
 #endif
+#if HAVE_SYS_WAIT_H
 #include <sys/wait.h>
+#endif
 #include <signal.h>
 
 #ifndef FD_SET
@@ -290,9 +298,10 @@
 	int             dont_fork = 0;
 	char            logfile[SNMP_MAXBUF_SMALL];
 	char           *cptr, **argvptr;
-	struct usmUser *user, *userListPtr;
 	char           *pid_file = NULL;
+#if HAVE_GETPID
 	FILE           *PID;
+#endif
 	int             dont_zero_log = 0;
 	int             stderr_log=0, syslog_log=0;
 	int             uid=0, gid=0;
@@ -500,10 +509,13 @@
      * Initialize the world.  Detach from the shell.
      * Create initial user.
      */
+#if HAVE_FORK
     if (!dont_fork && fork() != 0) {
       exit(0);
     }
+#endif
 
+#if HAVE_GETPID
     if (pid_file != NULL) {
       if ((PID = fopen(pid_file, "w")) == NULL) {
         snmp_log_perror("fopen");
@@ -512,7 +524,9 @@
       fprintf(PID, "%d\n", (int)getpid());
       fclose(PID);
     }
+#endif
 
+    SOCK_STARTUP;
     init_agent();		/* do what we need to do first. */
     init_mib_modules();
     
diff --git a/apps/snmpbulkget.c b/apps/snmpbulkget.c
index a3cb791..940d24f 100644
--- a/apps/snmpbulkget.c
+++ b/apps/snmpbulkget.c
@@ -77,6 +77,7 @@
 #include "snmp_impl.h"
 #include "system.h"
 #include "snmp_parse_args.h"
+#include "getopt.h"
 
 oid objid_mib[] = {1, 3, 6, 1, 2, 1};
 int max_repetitions = 100;
diff --git a/config.h.in b/config.h.in
index c8ef29c..45ae892 100644
--- a/config.h.in
+++ b/config.h.in
@@ -190,6 +190,12 @@
 /* Define if you have the bcopy function.  */
 #undef HAVE_BCOPY
 
+/* Define if you have the execv function.  */
+#undef HAVE_EXECV
+
+/* Define if you have the fork function.  */
+#undef HAVE_FORK
+
 /* Define if you have the getdtablesize function.  */
 #undef HAVE_GETDTABLESIZE
 
@@ -205,6 +211,9 @@
 /* Define if you have the getloadavg function.  */
 #undef HAVE_GETLOADAVG
 
+/* Define if you have the getpid function.  */
+#undef HAVE_GETPID
+
 /* Define if you have the getservbyname function.  */
 #undef HAVE_GETSERVBYNAME
 
@@ -259,6 +268,9 @@
 /* Define if you have the setmntent function.  */
 #undef HAVE_SETMNTENT
 
+/* Define if you have the sigalrm function.  */
+#undef HAVE_SIGALRM
+
 /* Define if you have the sigblock function.  */
 #undef HAVE_SIGBLOCK
 
@@ -292,6 +304,9 @@
 /* Define if you have the strtol function.  */
 #undef HAVE_STRTOL
 
+/* Define if you have the system function.  */
+#undef HAVE_SYSTEM
+
 /* Define if you have the tcgetattr function.  */
 #undef HAVE_TCGETATTR
 
diff --git a/configure b/configure
index 87a4cb6..d9fa212 100755
--- a/configure
+++ b/configure
@@ -5061,6 +5061,61 @@
 fi
 done
 
+for ac_func in execv system fork getpid strncasecmp sigalrm
+do
+echo $ac_n "checking for $ac_func""... $ac_c" 1>&6
+echo "configure:5013: checking for $ac_func" >&5
+if eval "test \"`echo '$''{'ac_cv_func_$ac_func'+set}'`\" = set"; then
+  echo $ac_n "(cached) $ac_c" 1>&6
+else
+  cat > conftest.$ac_ext <<EOF
+#line 5018 "configure"
+#include "confdefs.h"
+/* System header to define __stub macros and hopefully few prototypes,
+    which can conflict with char $ac_func(); below.  */
+#include <assert.h>
+/* Override any gcc2 internal prototype to avoid an error.  */
+/* We use char because int might match the return type of a gcc2
+    builtin and then its argument prototype would still apply.  */
+char $ac_func();
+
+int main() {
+
+/* The GNU C library defines this for functions which it implements
+    to always fail with ENOSYS.  Some functions are actually named
+    something starting with __ and the normal name is an alias.  */
+#if defined (__stub_$ac_func) || defined (__stub___$ac_func)
+choke me
+#else
+$ac_func();
+#endif
+
+; return 0; }
+EOF
+if { (eval echo configure:5041: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+  rm -rf conftest*
+  eval "ac_cv_func_$ac_func=yes"
+else
+  echo "configure: failed program was:" >&5
+  cat conftest.$ac_ext >&5
+  rm -rf conftest*
+  eval "ac_cv_func_$ac_func=no"
+fi
+rm -f conftest*
+fi
+
+if eval "test \"`echo '$ac_cv_func_'$ac_func`\" = yes"; then
+  echo "$ac_t""yes" 1>&6
+    ac_tr_func=HAVE_`echo $ac_func | tr 'abcdefghijklmnopqrstuvwxyz' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'`
+  cat >> confdefs.h <<EOF
+#define $ac_tr_func 1
+EOF
+ 
+else
+  echo "$ac_t""no" 1>&6
+fi
+done
+
 for ac_func in rpmGetPath
 do
 echo $ac_n "checking for $ac_func""... $ac_c" 1>&6
diff --git a/configure.in b/configure.in
index d01ab70..d290f4b 100644
--- a/configure.in
+++ b/configure.in
@@ -1034,6 +1034,7 @@
 AC_CHECK_FUNCS(strchr strdup memcpy memmove index bcopy)
 AC_CHECK_FUNCS(signal sigset sigblock sighold strerror setenv vsnprintf)
 AC_CHECK_FUNCS(random lrand48 rand)
+AC_CHECK_FUNCS(execv system fork getpid strncasecmp sigalrm)
 AC_CHECK_FUNCS(rpmGetPath)
 
 AC_CHECK_FUNCS(getloadavg)