Index: agent/auto_nlist.c
diff -Nau agent/auto_nlist.c.orig agent/auto_nlist.c
--- agent/auto_nlist.c.orig	2011-07-02 00:35:46.000000000 +0200
+++ agent/auto_nlist.c	2011-09-15 09:22:50.256627584 +0200
@@ -53,6 +53,7 @@
     }
     if (*ptr == 0) {
         *ptr = (struct autonlist *) malloc(sizeof(struct autonlist));
+	memset(*ptr, 0, sizeof(struct autonlist));
         it = *ptr;
         it->left = 0;
         it->right = 0;
Index: agent/mibgroup/mibII/tcp.c
diff -Nau agent/mibgroup/mibII/tcp.c.orig agent/mibgroup/mibII/tcp.c
--- agent/mibgroup/mibII/tcp.c.orig	2011-07-02 00:35:46.000000000 +0200
+++ agent/mibgroup/mibII/tcp.c	2011-09-15 09:22:50.258135285 +0200
@@ -88,7 +88,7 @@
                  * But only define it under FreeBSD, since it
                  *   breaks other systems (notable AIX)
                  */
-#ifdef freebsd4
+#if defined (freebsd4) || defined (__NetBSD__)
 int  hz = 1000;
 #endif
 
Index: agent/mibgroup/mibII/tcpTable.c
diff -Nau agent/mibgroup/mibII/tcpTable.c.orig agent/mibgroup/mibII/tcpTable.c
--- agent/mibgroup/mibII/tcpTable.c.orig	2011-07-02 00:35:46.000000000 +0200
+++ agent/mibgroup/mibII/tcpTable.c	2011-09-15 09:22:50.260414149 +0200
@@ -110,6 +110,11 @@
 #define	TCPTABLE_REMOTEPORT	pcb.inp_fport
 #define	TCPTABLE_IS_LINKED_LIST
 
+#if defined(__FreeBSD__)
+#undef  INP_NEXT_SYMBOL
+#define INP_NEXT_SYMBOL inp_next
+#endif
+
 #endif                          /* linux */
 #endif                          /* WIN32 cygwin */
 #endif                          /* solaris2 */
@@ -892,12 +897,17 @@
         nnew = SNMP_MALLOC_TYPEDEF(netsnmp_inpcb);
         if (!nnew)
             break;
+#if defined(__FreeBSD__)
+        memcpy(&(nnew->pcb), &(((struct xinpcb *) xig)->xi_inp),
+                           sizeof(struct inpcb));
+#else
         nnew->state = StateMap[((NS_ELEM *) xig)->xt_tp.t_state];
         if (nnew->state == 5 /* established */ ||
             nnew->state == 8 /*  closeWait  */ )
             tcp_estab++;
         memcpy(&(nnew->pcb), &(((NS_ELEM *) xig)->xt_inp),
                            sizeof(struct inpcb));
+#endif
 
 	if (nnew->pcb.inp_vflag & INP_IPV6)
 	    free(nnew);
Index: agent/mibgroup/ucd-snmp/diskio.c
diff -Nau agent/mibgroup/ucd-snmp/diskio.c.orig agent/mibgroup/ucd-snmp/diskio.c
--- agent/mibgroup/ucd-snmp/diskio.c.orig	2011-07-02 00:35:46.000000000 +0200
+++ agent/mibgroup/ucd-snmp/diskio.c	2011-09-15 09:22:50.263188251 +0200
@@ -800,6 +800,20 @@
     case DISKIO_DEVICE:
         *var_len = strlen(stat->dinfo->devices[indx].device_name);
         return (u_char *) stat->dinfo->devices[indx].device_name;
+#if defined(freebsd5) && (__FreeBSD_version >= 500107)
+    case DISKIO_NREAD:
+        long_ret = (signed long) stat->dinfo->devices[indx].bytes[DEVSTAT_READ];
+        return (u_char *) & long_ret;
+    case DISKIO_NWRITTEN:
+        long_ret = (signed long) stat->dinfo->devices[indx].bytes[DEVSTAT_WRITE];
+        return (u_char *) & long_ret;
+    case DISKIO_READS:
+        long_ret = (signed long) stat->dinfo->devices[indx].operations[DEVSTAT_READ];
+        return (u_char *) & long_ret;
+    case DISKIO_WRITES:
+        long_ret = (signed long) stat->dinfo->devices[indx].operations[DEVSTAT_WRITE];
+        return (u_char *) & long_ret;
+#else
     case DISKIO_NREAD:
 #if defined(freebsd5) && __FreeBSD_version >= 500107
         long_ret = (signed long) stat->dinfo->devices[indx].bytes[DEVSTAT_READ];
@@ -857,6 +871,7 @@
     case DISKIO_LA15:
         long_ret = devloads[indx].la15;
         return (u_char *) & long_ret;
+#endif
 
     default:
         ERROR_MSG("diskio.c: don't know how to handle this request.");
Index: agent/mibgroup/ucd-snmp/memory_solaris2.c
diff -Nau agent/mibgroup/ucd-snmp/memory_solaris2.c.orig agent/mibgroup/ucd-snmp/memory_solaris2.c
--- agent/mibgroup/ucd-snmp/memory_solaris2.c.orig	2011-07-02 00:35:46.000000000 +0200
+++ agent/mibgroup/ucd-snmp/memory_solaris2.c	2011-09-15 09:22:50.264370106 +0200
@@ -1,3 +1,4 @@
+#undef _FILE_OFFSET_BITS /* swapctl doesn't support 64bit off_t */
 #include <net-snmp/net-snmp-config.h>   /* local SNMP configuration details */
 #if HAVE_STRING_H
 #include <string.h>
Index: agent/mibgroup/ucd-snmp/proc.c
diff -Nau agent/mibgroup/ucd-snmp/proc.c.orig agent/mibgroup/ucd-snmp/proc.c
--- agent/mibgroup/ucd-snmp/proc.c.orig	2011-07-02 00:35:46.000000000 +0200
+++ agent/mibgroup/ucd-snmp/proc.c	2011-09-15 09:22:50.265801863 +0200
@@ -1,3 +1,6 @@
+#ifdef solaris2
+#undef _FILE_OFFSET_BITS /* solaris procfs doesn't support 64bit off_t */
+#endif
 #include <net-snmp/net-snmp-config.h>
 #include <net-snmp/net-snmp-features.h>
 
Index: agent/mibgroup/util_funcs.c
diff -Nau agent/mibgroup/util_funcs.c.orig agent/mibgroup/util_funcs.c
--- agent/mibgroup/util_funcs.c.orig	2011-07-02 00:35:46.000000000 +0200
+++ agent/mibgroup/util_funcs.c	2011-09-15 09:22:50.267863457 +0200
@@ -477,6 +477,9 @@
     int             fd[2][2], i, cnt;
     char            ctmp[STRMAX], *cptr1, *cptr2, argvs[STRMAX], **argv,
         **aptr;
+
+    *pid = -1;  /* open_persist_pipe ignores return code but checks *pid */
+
     /*
      * Setup our pipes 
      */
Index: agent/snmpd.c
diff -Nau agent/snmpd.c.orig agent/snmpd.c
--- agent/snmpd.c.orig	2011-07-02 00:35:46.000000000 +0200
+++ agent/snmpd.c	2011-09-15 09:22:41.994430685 +0200
@@ -440,7 +440,7 @@
     int             log_set = 0;
     int             uid = 0, gid = 0;
     int             agent_mode = -1;
-    char           *pid_file = NULL;
+    char           *pid_file = "@l_prefix@/var/snmp/snmpd.pid";
     char            option_compatability[] = "-Le";
 #if HAVE_GETPID
     int fd;
Index: apps/snmptrapd.c
diff -Nau apps/snmptrapd.c.orig apps/snmptrapd.c
--- apps/snmptrapd.c.orig	2011-07-02 00:35:46.000000000 +0200
+++ apps/snmptrapd.c	2011-09-15 09:22:50.270293197 +0200
@@ -653,6 +653,7 @@
      */
 #if HAVE_GETPID
     strcat(options, "p:");
+    parse_config_pidFile(NULL, "@l_prefix@/var/snmp/snmptrapd.pid");
 #endif
 
 #ifndef NETSNMP_FEATURE_REMOVE_LOGGING_SYSLOG
Index: include/net-snmp/library/system.h
diff -Nau include/net-snmp/library/system.h.orig include/net-snmp/library/system.h
--- include/net-snmp/library/system.h.orig	2011-07-02 00:35:46.000000000 +0200
+++ include/net-snmp/library/system.h	2011-09-15 09:22:50.271350973 +0200
@@ -155,7 +155,8 @@
 #endif
 #ifndef HAVE_SETENV
     NETSNMP_IMPORT
-    int             setenv(const char *, const char *, int);
+    int             __netsnmp_setenv(const char *, const char *, int);
+#   define          setenv(a,b,c) __netsnmp_setenv(a,b,c)
 #endif
 
     NETSNMP_IMPORT
Index: snmplib/system.c
diff -Nau snmplib/system.c.orig snmplib/system.c
--- snmplib/system.c.orig	2011-07-02 00:35:46.000000000 +0200
+++ snmplib/system.c	2011-09-15 09:22:50.274625796 +0200
@@ -1048,7 +1048,7 @@
 
 #ifndef HAVE_SETENV
 int
-setenv(const char *name, const char *value, int overwrite)
+__netsnmp_setenv(const char *name, const char *value, int overwrite)
 {
     char           *cp;
     int             ret;
Index: include/net-snmp/system/freebsd8.h
--- include/net-snmp/system/freebsd8.h.orig	2011-09-28 06:53:47.000000000 +0200
+++ include/net-snmp/system/freebsd8.h	2011-12-11 11:33:36.000000000 +0100
@@ -1,3 +1,6 @@
+/* freebsd8 is a superset of freebsd7 */
+#include "freebsd7.h"
+#define freebsd7 freebsd7
 /* freebsd8 is a superset of freebsd4 */
 #include "freebsd7.h"
 #define freebsd7 freebsd7
Index: include/net-snmp/system/freebsd9.h
--- include/net-snmp/system/freebsd9.h.orig	2011-09-28 06:53:47.000000000 +0200
+++ include/net-snmp/system/freebsd9.h	2011-12-11 11:33:36.000000000 +0100
@@ -1,3 +1,6 @@
+/* freebsd9 is a superset of freebsd8 */
+#include "freebsd8.h"
+#define freebsd8 freebsd8
 /* freebsd9 is a superset of freebsd4 */
 #include "freebsd8.h"
 #define freebsd9 freebsd9
