diff -uNr net-snmp-5.7.3.orig/Makefile.in net-snmp-5.7.3/Makefile.in
--- net-snmp-5.7.3.orig/Makefile.in	2014-12-08 15:23:22.000000000 -0500
+++ net-snmp-5.7.3/Makefile.in	2016-10-11 13:16:22.000000000 -0400
@@ -18,7 +18,9 @@
 INSTALLHEADERS=version.h net-snmp-features.h
 INCLUDESUBDIR=system
 INCLUDESUBDIRHEADERS= aix.h bsd.h bsdi3.h bsdi4.h bsdi.h cygwin.h \
-	darwin.h darwin7.h darwin8.h darwin9.h darwin10.h dragonfly.h dynix.h \
+	darwin.h darwin7.h darwin8.h darwin9.h darwin10.h darwin11.h \
+	darwin12.h darwin13.h darwin14.h darwin15.h darwin16.h darwin17.h \
+	dragonfly.h dynix.h \
 	freebsd2.h freebsd3.h freebsd4.h freebsd5.h freebsd6.h \
 	freebsd7.h freebsd8.h freebsd9.h freebsd10.h freebsd11.h \
 	freebsd12.h freebsd.h \
diff -uNr net-snmp-5.7.3.orig/agent/mibgroup/host/hr_swrun.c net-snmp-5.7.3/agent/mibgroup/host/hr_swrun.c
--- net-snmp-5.7.3.orig/agent/mibgroup/host/hr_swrun.c	2014-12-08 15:23:22.000000000 -0500
+++ net-snmp-5.7.3/agent/mibgroup/host/hr_swrun.c	2016-10-11 13:16:22.000000000 -0400
@@ -39,9 +39,6 @@
 #if HAVE_SYS_PROC_H
 #include <sys/proc.h>
 #endif
-#if HAVE_KVM_H
-#include <kvm.h>
-#endif
 #if HAVE_SYS_SYSCTL_H
 #include <sys/sysctl.h>
 #endif
diff -uNr net-snmp-5.7.3.orig/agent/mibgroup/ip-mib/ipv4InterfaceTable/ipv4InterfaceTable_data_access.c net-snmp-5.7.3/agent/mibgroup/ip-mib/ipv4InterfaceTable/ipv4InterfaceTable_data_access.c
--- net-snmp-5.7.3.orig/agent/mibgroup/ip-mib/ipv4InterfaceTable/ipv4InterfaceTable_data_access.c	2014-12-08 15:23:22.000000000 -0500
+++ net-snmp-5.7.3/agent/mibgroup/ip-mib/ipv4InterfaceTable/ipv4InterfaceTable_data_access.c	2016-10-11 13:16:22.000000000 -0400
@@ -127,7 +127,7 @@
     /*
      * do we have a corresponding row?
      */
-    ip4if_rrc = CONTAINER_FIND(c, ift_rrc);
+    ip4if_rrc = (ifTable_rowreq_ctx*)CONTAINER_FIND(c, ift_rrc);
     if (NULL == ip4if_rrc) {
         /*
          * no corresponding row. should we have one?
diff -uNr net-snmp-5.7.3.orig/agent/mibgroup/ip-mib/ipv4InterfaceTable/ipv4InterfaceTable_interface.c net-snmp-5.7.3/agent/mibgroup/ip-mib/ipv4InterfaceTable/ipv4InterfaceTable_interface.c
--- net-snmp-5.7.3.orig/agent/mibgroup/ip-mib/ipv4InterfaceTable/ipv4InterfaceTable_interface.c	2014-12-08 15:23:22.000000000 -0500
+++ net-snmp-5.7.3/agent/mibgroup/ip-mib/ipv4InterfaceTable/ipv4InterfaceTable_interface.c	2016-10-11 13:16:22.000000000 -0400
@@ -503,7 +503,7 @@
 {
     int             rc = SNMP_ERR_NOERROR;
     ipv4InterfaceTable_rowreq_ctx *rowreq_ctx =
-        netsnmp_container_table_row_extract(requests);
+        (ipv4InterfaceTable_rowreq_ctx*)netsnmp_container_table_row_extract(requests);
 
     DEBUGMSGTL(("internal:ipv4InterfaceTable:_mfd_ipv4InterfaceTable_object_lookup", "called\n"));
 
@@ -594,7 +594,7 @@
                                    netsnmp_request_info *requests)
 {
     ipv4InterfaceTable_rowreq_ctx *rowreq_ctx =
-        netsnmp_container_table_row_extract(requests);
+        (ipv4InterfaceTable_rowreq_ctx*)netsnmp_container_table_row_extract(requests);
     netsnmp_table_request_info *tri;
     u_char         *old_string;
     void            (*dataFreeHook) (void *);
@@ -760,7 +760,7 @@
                                       netsnmp_request_info *requests)
 {
     ipv4InterfaceTable_rowreq_ctx *rowreq_ctx =
-        netsnmp_container_table_row_extract(requests);
+        (ipv4InterfaceTable_rowreq_ctx*)netsnmp_container_table_row_extract(requests);
     netsnmp_table_request_info *tri;
     int             rc;
 
@@ -844,7 +844,7 @@
 {
     int             rc;
     ipv4InterfaceTable_rowreq_ctx *rowreq_ctx =
-        netsnmp_container_table_row_extract(requests);
+        (ipv4InterfaceTable_rowreq_ctx*)netsnmp_container_table_row_extract(requests);
 
     DEBUGMSGTL(("internal:ipv4InterfaceTable:_mfd_ipv4InterfaceTable_undo_setup", "called\n"));
 
@@ -906,7 +906,7 @@
                                      netsnmp_request_info *requests)
 {
     ipv4InterfaceTable_rowreq_ctx *rowreq_ctx =
-        netsnmp_container_table_row_extract(requests);
+        (ipv4InterfaceTable_rowreq_ctx*)netsnmp_container_table_row_extract(requests);
     int             rc;
 
     DEBUGMSGTL(("internal:ipv4InterfaceTable:_mfd_ipv4InterfaceTable_undo_cleanup", "called\n"));
@@ -986,7 +986,7 @@
                                    netsnmp_request_info *requests)
 {
     ipv4InterfaceTable_rowreq_ctx *rowreq_ctx =
-        netsnmp_container_table_row_extract(requests);
+        (ipv4InterfaceTable_rowreq_ctx*)netsnmp_container_table_row_extract(requests);
     netsnmp_table_request_info *tri;
     int             rc = SNMP_ERR_NOERROR;
 
@@ -1034,7 +1034,7 @@
 {
     int             rc;
     ipv4InterfaceTable_rowreq_ctx *rowreq_ctx =
-        netsnmp_container_table_row_extract(requests);
+        (ipv4InterfaceTable_rowreq_ctx*)netsnmp_container_table_row_extract(requests);
 
     DEBUGMSGTL(("internal:ipv4InterfaceTable:_mfd_ipv4InterfaceTable_commit", "called\n"));
 
@@ -1068,7 +1068,7 @@
 {
     int             rc;
     ipv4InterfaceTable_rowreq_ctx *rowreq_ctx =
-        netsnmp_container_table_row_extract(requests);
+        (ipv4InterfaceTable_rowreq_ctx*)netsnmp_container_table_row_extract(requests);
 
     DEBUGMSGTL(("internal:ipv4InterfaceTable:_mfd_ipv4InterfaceTable_undo_commit", "called\n"));
 
@@ -1147,7 +1147,7 @@
 {
     int             rc;
     ipv4InterfaceTable_rowreq_ctx *rowreq_ctx =
-        netsnmp_container_table_row_extract(requests);
+        (ipv4InterfaceTable_rowreq_ctx*)netsnmp_container_table_row_extract(requests);
     netsnmp_table_request_info *tri;
 
     DEBUGMSGTL(("internal:ipv4InterfaceTable:_mfd_ipv4InterfaceTable_undo_values", "called\n"));
@@ -1202,7 +1202,7 @@
                                             netsnmp_request_info *requests)
 {
     ipv4InterfaceTable_rowreq_ctx *rowreq_ctx =
-        netsnmp_container_table_row_extract(requests);
+        (ipv4InterfaceTable_rowreq_ctx*)netsnmp_container_table_row_extract(requests);
 
     DEBUGMSGTL(("internal:ipv4InterfaceTable:_mfd_ipv4InterfaceTable_irreversible:commit", "called\n"));
 
@@ -1319,7 +1319,7 @@
         return NULL;
 
     rowreq_ctx =
-        CONTAINER_FIND(ipv4InterfaceTable_if_ctx.container, &oid_idx);
+        (ipv4InterfaceTable_rowreq_ctx*)CONTAINER_FIND(ipv4InterfaceTable_if_ctx.container, &oid_idx);
 
     return rowreq_ctx;
 }
diff -uNr net-snmp-5.7.3.orig/agent/mibgroup/mibII/at.c net-snmp-5.7.3/agent/mibgroup/mibII/at.c
--- net-snmp-5.7.3.orig/agent/mibgroup/mibII/at.c	2014-12-08 15:23:22.000000000 -0500
+++ net-snmp-5.7.3/agent/mibgroup/mibII/at.c	2016-10-11 13:16:22.000000000 -0400
@@ -704,7 +704,7 @@
     if (sysctl(mib, 6, NULL, &needed, NULL, 0) < 0)
         snmp_log_perror("route-sysctl-estimate");
     else {
-        if ((at = malloc(needed ? needed : 1)) == NULL)
+        if ((at = (char*)malloc(needed ? needed : 1)) == NULL)
             snmp_log_perror("malloc");
         else {
             if (sysctl(mib, 6, at, &needed, NULL, 0) < 0)
diff -uNr net-snmp-5.7.3.orig/agent/mibgroup/mibII/icmp.h net-snmp-5.7.3/agent/mibgroup/mibII/icmp.h
--- net-snmp-5.7.3.orig/agent/mibgroup/mibII/icmp.h	2014-12-08 15:23:22.000000000 -0500
+++ net-snmp-5.7.3/agent/mibgroup/mibII/icmp.h	2016-10-11 13:16:22.000000000 -0400
@@ -24,6 +24,9 @@
 config_arch_require(darwin11,  mibII/kernel_sysctl)
 config_arch_require(darwin12,  mibII/kernel_sysctl)
 config_arch_require(darwin13,  mibII/kernel_sysctl)
+config_arch_require(darwin14,  mibII/kernel_sysctl)
+config_arch_require(darwin15,  mibII/kernel_sysctl)
+config_arch_require(darwin16,  mibII/kernel_sysctl)
 
 #include <net-snmp/agent/cache_handler.h>
 
diff -uNr net-snmp-5.7.3.orig/agent/mibgroup/mibII/ipAddr.c net-snmp-5.7.3/agent/mibgroup/mibII/ipAddr.c
--- net-snmp-5.7.3.orig/agent/mibgroup/mibII/ipAddr.c	2014-12-08 15:23:22.000000000 -0500
+++ net-snmp-5.7.3/agent/mibgroup/mibII/ipAddr.c	2016-10-11 13:16:22.000000000 -0400
@@ -777,7 +777,7 @@
     if (sysctl(mib, 6, 0, &len, 0, 0) < 0)
         return;
 
-    ifbuf = malloc(len);
+    ifbuf = (char*)malloc(len);
     if (ifbuf == 0)
         return;
     if (sysctl(mib, 6, ifbuf, &len, 0, 0) < 0) {
diff -uNr net-snmp-5.7.3.orig/agent/mibgroup/mibII/tcpTable.c net-snmp-5.7.3/agent/mibgroup/mibII/tcpTable.c
--- net-snmp-5.7.3.orig/agent/mibgroup/mibII/tcpTable.c	2014-12-08 15:23:22.000000000 -0500
+++ net-snmp-5.7.3/agent/mibgroup/mibII/tcpTable.c	2016-10-11 13:16:22.000000000 -0400
@@ -896,7 +896,7 @@
      */
     len = 0;
     if (sysctl(sname, 4, 0, &len, 0, 0) < 0 ||
-       (tcpcb_buf = malloc(len)) == NULL)
+       (tcpcb_buf = (char*)malloc(len)) == NULL)
         return -1;
     if (sysctl(sname, 4, tcpcb_buf, &len, 0, 0) < 0) {
         free(tcpcb_buf);
diff -uNr net-snmp-5.7.3.orig/agent/mibgroup/mibII/udpTable.c net-snmp-5.7.3/agent/mibgroup/mibII/udpTable.c
--- net-snmp-5.7.3.orig/agent/mibgroup/mibII/udpTable.c	2014-12-08 15:23:22.000000000 -0500
+++ net-snmp-5.7.3/agent/mibgroup/mibII/udpTable.c	2016-10-11 13:16:22.000000000 -0400
@@ -643,7 +643,7 @@
      */
     len = 0;
     if (sysctl(sname, 4, 0, &len, 0, 0) < 0 ||
-       (udpcb_buf = malloc(len)) == NULL)
+       (udpcb_buf = (char*)malloc(len)) == NULL)
         return -1;
     if (sysctl(sname, 4, udpcb_buf, &len, 0, 0) < 0) {
         free(udpcb_buf);
diff -uNr net-snmp-5.7.3.orig/agent/mibgroup/mibII/var_route.c net-snmp-5.7.3/agent/mibgroup/mibII/var_route.c
--- net-snmp-5.7.3.orig/agent/mibgroup/mibII/var_route.c	2014-12-08 15:23:22.000000000 -0500
+++ net-snmp-5.7.3/agent/mibgroup/mibII/var_route.c	2016-10-11 13:16:22.000000000 -0400
@@ -1807,7 +1807,7 @@
 
     if (len > rtbuflen) {
         char           *newbuf;
-        newbuf = realloc(rtbuf, len);
+        newbuf = (char*)realloc(rtbuf, len);
         if (newbuf == 0)
             return -1;
         rtbuf = newbuf;
diff -uNr net-snmp-5.7.3.orig/agent/mibgroup/ucd-snmp/dlmod.c net-snmp-5.7.3/agent/mibgroup/ucd-snmp/dlmod.c
--- net-snmp-5.7.3.orig/agent/mibgroup/ucd-snmp/dlmod.c	2014-12-08 15:23:22.000000000 -0500
+++ net-snmp-5.7.3/agent/mibgroup/ucd-snmp/dlmod.c	2016-10-11 13:16:22.000000000 -0400
@@ -221,7 +221,7 @@
         dl_function_ptr dl_init;
 
         snprintf(sym_init, sizeof(sym_init), "init_%s", dlm->name);
-        dl_init = dlmod_dlsym(dlm->handle, sym_init);
+        dl_init = (int (*)())dlmod_dlsym(dlm->handle, sym_init);
         if (dl_init == NULL) {
             dlmod_dlclose(dlm->handle);
             snprintf(dlm->error, sizeof(dlm->error),
@@ -246,10 +246,10 @@
         return;
 
     snprintf(sym_deinit, sizeof(sym_deinit), "deinit_%s", dlm->name);
-    dl_deinit = dlmod_dlsym(dlm->handle, sym_deinit);
+    dl_deinit = (int (*)())dlmod_dlsym(dlm->handle, sym_deinit);
     if (!dl_deinit) {
         snprintf(sym_deinit, sizeof(sym_deinit), "shutdown_%s", dlm->name);
-        dl_deinit = dlmod_dlsym(dlm->handle, sym_deinit);
+        dl_deinit = (int (*)())dlmod_dlsym(dlm->handle, sym_deinit);
     }
     if (dl_deinit) {
         DEBUGMSGTL(("dlmod", "Calling %s()\n", sym_deinit));
diff -uNr net-snmp-5.7.3.orig/agent/mibgroup/ucd-snmp/memory_darwin7.c net-snmp-5.7.3/agent/mibgroup/ucd-snmp/memory_darwin7.c
--- net-snmp-5.7.3.orig/agent/mibgroup/ucd-snmp/memory_darwin7.c	2014-12-08 15:23:22.000000000 -0500
+++ net-snmp-5.7.3/agent/mibgroup/ucd-snmp/memory_darwin7.c	2016-10-11 13:16:22.000000000 -0400
@@ -48,6 +48,12 @@
 #include "memory.h"
 #include "memory_darwin7.h"
 
+#ifdef HAVE_VM_REGION_64
+#define VM_REGION_FUNC vm_region_64
+#else
+#define VM_REGION_FUNC vm_region
+#endif
+
 /*
  *  * Swap info 
  *   */
@@ -387,7 +393,7 @@
             for (address = 0;; address += size) {
                 /* Get memory region. */
                 count = VM_REGION_EXTENDED_INFO_COUNT; 
-                if (vm_region(tasks[j], &address, &size, VM_REGION_EXTENDED_INFO, (vm_region_extended_info_t)&info, &count, &object_name) != KERN_SUCCESS) {
+                if (VM_REGION_FUNC(tasks[j], &address, &size, VM_REGION_EXTENDED_INFO, (vm_region_extended_info_t)&info, &count, &object_name) != KERN_SUCCESS) {
                     /* No more memory regions. */
                     break;
                 }
diff -uNr net-snmp-5.7.3.orig/agent/mibgroup/utilities/iquery.c net-snmp-5.7.3/agent/mibgroup/utilities/iquery.c
--- net-snmp-5.7.3.orig/agent/mibgroup/utilities/iquery.c	2014-12-08 15:23:22.000000000 -0500
+++ net-snmp-5.7.3/agent/mibgroup/utilities/iquery.c	2016-10-11 13:16:22.000000000 -0400
@@ -198,7 +198,7 @@
             ss->community = netsnmp_memdup(secName, strlen(secName));
             ss->community_len = strlen(secName);
         }
-        ss->myvoid = netsnmp_check_outstanding_agent_requests;
+        ss->myvoid = (void*)netsnmp_check_outstanding_agent_requests;
         ss->flags |= SNMP_FLAGS_RESP_CALLBACK | SNMP_FLAGS_DONT_PROBE;
     }
 #endif
diff -uNr net-snmp-5.7.3.orig/configure net-snmp-5.7.3/configure
--- net-snmp-5.7.3.orig/configure	2014-12-08 15:23:37.000000000 -0500
+++ net-snmp-5.7.3/configure	2016-10-11 13:20:58.000000000 -0400
@@ -15658,19 +15658,10 @@
 	fi
 	;;
 
-    darwin8*|darwin9*|darwin10*|darwin11*|darwin12*|darwin13*)
-        #   Flat Namespace linking                      (Mac OS/X)
+    darwin*)
+        #   Add frameworks                              (OS X) 
         #
-        { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether darwin ld might need -flat_namespace" >&5
-$as_echo_n "checking whether darwin ld might need -flat_namespace... " >&6; }
-	if test -z "$MACOSX_DEPLOYMENT_TARGET"; then
-		LDFLAGS="-flat_namespace -framework CoreFoundation -framework CoreServices -framework DiskArbitration -framework IOKit $LDFLAGS"
-		{ $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
-$as_echo "yes" >&6; }
-	else
-		{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
-$as_echo "no" >&6; }
-	fi
+		LDFLAGS="-Wl,-framework,CoreFoundation -Wl,-framework,CoreServices -Wl,-framework,DiskArbitration -Wl,-framework,IOKit $LDFLAGS" 
 	;;
 
     *)
diff -uNr net-snmp-5.7.3.orig/configure.d/config_os_functions net-snmp-5.7.3/configure.d/config_os_functions
--- net-snmp-5.7.3.orig/configure.d/config_os_functions	2014-12-08 15:23:22.000000000 -0500
+++ net-snmp-5.7.3/configure.d/config_os_functions	2016-10-11 13:16:22.000000000 -0400
@@ -101,7 +101,8 @@
                [sigprocmask                                    ] dnl
                [statfs          statvfs       stime            ] dnl
                [strncasecmp     system                         ] dnl
-               [uname           usleep                         ] )
+               [uname           usleep                         ] dnl
+               [vm_region       vm_region_64                   ] )
 
 #  Apps:
 AC_CHECK_FUNCS([getdtablesize                                  ] dnl
diff -uNr net-snmp-5.7.3.orig/configure.d/config_os_progs net-snmp-5.7.3/configure.d/config_os_progs
--- net-snmp-5.7.3.orig/configure.d/config_os_progs	2014-12-08 15:23:22.000000000 -0500
+++ net-snmp-5.7.3/configure.d/config_os_progs	2016-10-11 13:16:22.000000000 -0400
@@ -208,6 +208,7 @@
   ;;
 esac
 
+LD_NO_UNDEFINED=-no-undefined
 AC_SUBST(LD_NO_UNDEFINED)
 
 
@@ -405,12 +406,7 @@
         #   Flat Namespace linking                      (Mac OS/X)
         #
         AC_MSG_CHECKING([whether darwin ld might need -flat_namespace])
-	if test -z "$MACOSX_DEPLOYMENT_TARGET"; then
-		LDFLAGS="-flat_namespace -framework CoreFoundation -framework CoreServices -framework DiskArbitration -framework IOKit $LDFLAGS"
-		AC_MSG_RESULT([yes])
-	else
 		AC_MSG_RESULT([no])
-	fi
 	;;
 
     *)
diff -uNr net-snmp-5.7.3.orig/configure.d/config_project_perl_python net-snmp-5.7.3/configure.d/config_project_perl_python
--- net-snmp-5.7.3.orig/configure.d/config_project_perl_python	2014-12-08 15:23:22.000000000 -0500
+++ net-snmp-5.7.3/configure.d/config_project_perl_python	2016-10-11 13:16:22.000000000 -0400
@@ -87,7 +87,7 @@
     if test "xenable_perl_cc_checks" != "xno" ; then
         AC_MSG_CHECKING([for Perl cc])
         changequote(, )
-        PERLCC=`$myperl -V:cc | $myperl -n -e 'print if (s/^\s*cc=.([-=\w\s\/]+).;\s*/$1/);'`
+        PERLCC=`$myperl -V:cc | $myperl -n -e 'print if (s/^\s*cc=.([-=\w\s\.\/]+).;\s*/$1/);'`
         changequote([, ])
         if test "x$PERLCC" != "x" ; then
             AC_MSG_RESULT([$PERLCC])
@@ -192,7 +192,7 @@
 #
 if test "x$embed_perl" != "xno" ; then
     AC_MSG_CHECKING([for Perl CFLAGS])
-    perlcflags=`$myperl -MExtUtils::Embed -e ccopts`
+    perlcflags=`$myperl -MExtUtils::Embed -e ccopts | /usr/bin/sed -e 's,-arch [^ ]*,,g'`
     if test "x$perlcflags" != "x" ; then
       AC_MSG_RESULT([$perlcflags])
       CFLAGS="$CFLAGS $perlcflags"
@@ -209,7 +209,7 @@
 #
 if test "x$embed_perl" != "xno" ; then
     AC_MSG_CHECKING([for Perl LDFLAGS])
-    netsnmp_perlldopts=`$myperl -MExtUtils::Embed -e ldopts`
+    netsnmp_perlldopts=`$myperl -MExtUtils::Embed -e ldopts | /usr/bin/sed -e 's,-arch [^ ]*,,g'`
     if test "x$netsnmp_perlldopts" != "x" ; then
       AC_MSG_RESULT([$netsnmp_perlldopts])
     else
@@ -228,7 +228,7 @@
       #
       AC_MSG_CHECKING([for Perl CCDLFLAGS])
       changequote(, )
-      netsnmp_perlccdlflags=`$myperl -V:ccdlflags | $myperl -n -e 'print $1 '"if (/^\s*ccdlflags='([^']+)';/);"`
+      netsnmp_perlccdlflags=`$myperl -V:ccdlflags | /usr/bin/sed -e 's,-arch [^ ]*,,g'`
       changequote([, ])
       AC_MSG_RESULT([$netsnmp_perlccdlflags])
       PERLLDOPTS_FOR_APPS="$netsnmp_perlccdlflags"
diff -uNr net-snmp-5.7.3.orig/net-snmp-config.in net-snmp-5.7.3/net-snmp-config.in
--- net-snmp-5.7.3.orig/net-snmp-config.in	2014-12-08 15:23:22.000000000 -0500
+++ net-snmp-5.7.3/net-snmp-config.in	2016-10-11 13:16:22.000000000 -0400
@@ -48,10 +48,10 @@
 datarootdir=@datarootdir@
 NSC_LDFLAGS="@LDFLAGS@"
 
-NSC_LIBS="@LIBS@"
-NSC_LNETSNMPLIBS="@LNETSNMPLIBS@"
-NSC_LAGENTLIBS="@LAGENTLIBS@ @PERLLDOPTS_FOR_APPS@"
-NSC_LMIBLIBS="@LMIBLIBS@"
+#NSC_LIBS="@LIBS@"
+#NSC_LNETSNMPLIBS="@LNETSNMPLIBS@"
+#NSC_LAGENTLIBS="@LAGENTLIBS@ @PERLLDOPTS_FOR_APPS@"
+#NSC_LMIBLIBS="@LMIBLIBS@"
 
 NSC_INCLUDEDIR=${includedir}
 NSC_LIBDIR=-L${libdir}
@@ -67,7 +67,7 @@
 
 NSC_BASE_SNMP_LIBS="-lnetsnmp"
 NSC_BASE_SUBAGENT_LIBS="-lnetsnmpagent ${NSC_BASE_SNMP_LIBS}"
-NSC_BASE_AGENT_LIBS="-lnetsnmpmibs ${NSC_BASE_SUBAGENT_LIBS}"
+NSC_BASE_AGENT_LIBS="-lnetsnmpmibs ${NSC_BASE_SUBAGENT_LIBS} -lnetsnmphelpers"
 
 NSC_SRC_LIBDIRS="agent/.libs snmplib/.libs"
 NSC_SRC_LIBDEPS="agent/.libs/libnetsnmpmibs.a agent/.libs/libnetsnmpagent.a snmplib/.libs/libnetsnmp.a"
@@ -141,7 +141,7 @@
       echo @CFLAGS@ @CPPFLAGS@ -I${NSC_INCLUDEDIR}
       ;;
     --cflags|--cf*)
-      echo @CFLAGS@ @DEVFLAGS@ @CPPFLAGS@ -I. -I${NSC_INCLUDEDIR}
+      echo @CFLAGS@ @DEVFLAGS@ -I. @CPPFLAGS@ -I${NSC_INCLUDEDIR}
       ;;
     --srcdir)
       echo $NSC_SRCDIR
diff -uNr net-snmp-5.7.3.orig/perl/ASN/Makefile.PL net-snmp-5.7.3/perl/ASN/Makefile.PL
--- net-snmp-5.7.3.orig/perl/ASN/Makefile.PL	2014-12-08 15:23:22.000000000 -0500
+++ net-snmp-5.7.3/perl/ASN/Makefile.PL	2016-10-11 13:16:22.000000000 -0400
@@ -83,7 +83,19 @@
       $lib_version = `$opts->{'nsconfig'} --version`;
       
       if (lc($opts->{'insource'}) eq "true") {
-	$Params{'LIBS'} = "-L../../snmplib/.libs -L../../snmplib/ " . $Params{'LIBS'};
+	    my %local_libs = (
+		'netsnmp'        => 'snmplib',
+		'netsnmpagent'   => 'agent',
+		'netsnmphelpers' => 'agent/helpers',
+		'netsnmpmibs'    => 'agent',
+		'netsnmptrapd'   => 'apps',
+		);
+	    foreach (split ' ', $Params{'LIBS'}) {
+		if (s/^-l// && exists $local_libs{$_}) {
+		    $Params{'LDDLFLAGS'} = $opts->{'rootpath'} . "../$local_libs{$_}/.libs/lib$_.dylib " . $Params{'LDDLFLAGS'};
+		}
+	    }
+	    $Params{'LIBS'} = ' ';
 	$Params{'CCFLAGS'} = "-I../../include " . $Params{'CCFLAGS'};
       }
       $Params{'CCFLAGS'} =~ s/ -W(all|inline|strict-prototypes|write-strings|cast-qual|no-char-subscripts)//g; # ignore developer warnings
diff -uNr net-snmp-5.7.3.orig/perl/OID/Makefile.PL net-snmp-5.7.3/perl/OID/Makefile.PL
--- net-snmp-5.7.3.orig/perl/OID/Makefile.PL	2014-12-08 15:23:22.000000000 -0500
+++ net-snmp-5.7.3/perl/OID/Makefile.PL	2016-10-11 13:16:22.000000000 -0400
@@ -81,7 +81,19 @@
 	$Params{'CCFLAGS'} .= " " . $Config{'ccflags'};
         $lib_version = `$opts->{'nsconfig'} --version`;
 	if (lc($opts->{'insource'}) eq "true") {
-	    $Params{'LIBS'} = "-L../../snmplib/.libs -L../../snmplib/ " . $Params{'LIBS'};
+	    my %local_libs = (
+		'netsnmp'        => 'snmplib',
+		'netsnmpagent'   => 'agent',
+		'netsnmphelpers' => 'agent/helpers',
+		'netsnmpmibs'    => 'agent',
+		'netsnmptrapd'   => 'apps',
+		);
+	    foreach (split ' ', $Params{'LIBS'}) {
+		if (s/^-l// && exists $local_libs{$_}) {
+		    $Params{'LDDLFLAGS'} = $opts->{'rootpath'} . "../$local_libs{$_}/.libs/lib$_.dylib " . $Params{'LDDLFLAGS'};
+		}
+	    }
+	    $Params{'LIBS'} = ' ';
 	    $Params{'CCFLAGS'} = "-I../../include " . $Params{'CCFLAGS'};
 #	} else {
 #	    $Params{'PREREQ_PM'} = {'SNMP' => '5.0'};
diff -uNr net-snmp-5.7.3.orig/perl/SNMP/Makefile.PL net-snmp-5.7.3/perl/SNMP/Makefile.PL
--- net-snmp-5.7.3.orig/perl/SNMP/Makefile.PL	2014-12-08 15:23:22.000000000 -0500
+++ net-snmp-5.7.3/perl/SNMP/Makefile.PL	2016-10-11 13:16:22.000000000 -0400
@@ -93,7 +93,19 @@
 	}
         $lib_version = `$opts->{'nsconfig'} --version`;
 	if (lc($opts->{'insource'}) eq "true") {
-	    $Params{'LIBS'} = "-L../../snmplib/.libs -L../../snmplib/ " . $Params{'LIBS'};
+	    my %local_libs = (
+		'netsnmp'        => 'snmplib',
+		'netsnmpagent'   => 'agent',
+		'netsnmphelpers' => 'agent/helpers',
+		'netsnmpmibs'    => 'agent',
+		'netsnmptrapd'   => 'apps',
+		);
+	    foreach (split ' ', $Params{'LIBS'}) {
+		if (s/^-l// && exists $local_libs{$_}) {
+		    $Params{'LDDLFLAGS'} = $opts->{'rootpath'} . "../$local_libs{$_}/.libs/lib$_.dylib " . $Params{'LDDLFLAGS'};
+		}
+	    }
+	    $Params{'LIBS'} = ' ';
 	    $Params{'CCFLAGS'} = "-I../../include " . $Params{'CCFLAGS'};
 #	} else {
 #	    $Params{'PREREQ_PM'} = { 'NetSNMP::default_store' => 0.01 };
diff -uNr net-snmp-5.7.3.orig/perl/TrapReceiver/Makefile.PL net-snmp-5.7.3/perl/TrapReceiver/Makefile.PL
--- net-snmp-5.7.3.orig/perl/TrapReceiver/Makefile.PL	2014-12-08 15:23:22.000000000 -0500
+++ net-snmp-5.7.3/perl/TrapReceiver/Makefile.PL	2016-10-11 13:16:22.000000000 -0400
@@ -118,7 +118,19 @@
 	}
 
 	if (lc($opts->{'insource'}) eq "true") {
-            $Params{'LIBS'} = "-L../../apps/.libs -L../../apps -L../../agent/.libs -L../../agent -L../../snmplib/.libs -L../../snmplib " . $Params{'LIBS'};
+	    my %local_libs = (
+		'netsnmp'        => 'snmplib',
+		'netsnmpagent'   => 'agent',
+		'netsnmphelpers' => 'agent/helpers',
+		'netsnmpmibs'    => 'agent',
+		'netsnmptrapd'   => 'apps',
+		);
+	    foreach (split ' ', $Params{'LIBS'}) {
+		if (s/^-l// && exists $local_libs{$_}) {
+		    $Params{'LDDLFLAGS'} = $opts->{'rootpath'} . "../$local_libs{$_}/.libs/lib$_.dylib " . $Params{'LDDLFLAGS'};
+		}
+	    }
+	    $Params{'LIBS'} = ' ';
 	    $Params{'CCFLAGS'} = "-I../../include " . $Params{'CCFLAGS'};
 	} else {
             $Params{'LIBS'} = `$opts->{'nsconfig'} --libdir` . " $Params{'LIBS'}";
diff -uNr net-snmp-5.7.3.orig/perl/agent/Makefile.PL net-snmp-5.7.3/perl/agent/Makefile.PL
--- net-snmp-5.7.3.orig/perl/agent/Makefile.PL	2014-12-08 15:23:22.000000000 -0500
+++ net-snmp-5.7.3/perl/agent/Makefile.PL	2016-10-11 13:16:22.000000000 -0400
@@ -86,7 +86,19 @@
 	$Params{'CCFLAGS'} .= " " . $Config{'ccflags'};
         $lib_version = `$opts->{'nsconfig'} --version`;
 	if (lc($opts->{'insource'}) eq "true") {
-	    $Params{'LIBS'} = "-L../../snmplib/.libs -L../../snmplib/ -L../../agent/.libs -L../../agent/ " . $Params{'LIBS'};
+	    my %local_libs = (
+		'netsnmp'        => 'snmplib',
+		'netsnmpagent'   => 'agent',
+		'netsnmphelpers' => 'agent/helpers',
+		'netsnmpmibs'    => 'agent',
+		'netsnmptrapd'   => 'apps',
+		);
+	    foreach (split ' ', $Params{'LIBS'}) {
+		if (s/^-l// && exists $local_libs{$_}) {
+		    $Params{'LDDLFLAGS'} = $opts->{'rootpath'} . "../$local_libs{$_}/.libs/lib$_.dylib " . $Params{'LDDLFLAGS'};
+		}
+	    }
+	    $Params{'LIBS'} = ' ';
 	    $Params{'CCFLAGS'} = "-I../../include " . $Params{'CCFLAGS'};
 #	} else {
 	    $Params{'LIBS'} = `$opts->{'nsconfig'} --libdir` . $Params{'LIBS'};
diff -uNr net-snmp-5.7.3.orig/perl/agent/Support/Makefile.PL net-snmp-5.7.3/perl/agent/Support/Makefile.PL
--- net-snmp-5.7.3.orig/perl/agent/Support/Makefile.PL	2014-12-08 15:23:22.000000000 -0500
+++ net-snmp-5.7.3/perl/agent/Support/Makefile.PL	2016-10-11 13:16:22.000000000 -0400
@@ -75,6 +75,7 @@
     else
     {
       $opts = NetSNMPGetOpts("../../");
+	$Params{'LDDLFLAGS'} = "$Config{lddlflags} " . `$opts->{'nsconfig'} --ldflags`;
       $Params{'LIBS'}    = `$opts->{'nsconfig'} --libs`;
       chomp($Params{'LIBS'});
       $Params{'CCFLAGS'} = `$opts->{'nsconfig'} --cflags`;
@@ -83,7 +84,19 @@
       $lib_version = `$opts->{'nsconfig'} --version`;
       
       if (lc($opts->{'insource'}) eq "true") {
-	$Params{'LIBS'} = "-L../../snmplib/.libs -L../../snmplib/ " . $Params{'LIBS'};
+	    my %local_libs = (
+		'netsnmp'        => 'snmplib',
+		'netsnmpagent'   => 'agent',
+		'netsnmphelpers' => 'agent/helpers',
+		'netsnmpmibs'    => 'agent',
+		'netsnmptrapd'   => 'apps',
+		);
+	    foreach (split ' ', $Params{'LIBS'}) {
+		if (s/^-l// && exists $local_libs{$_}) {
+		    $Params{'LDDLFLAGS'} = $opts->{'rootpath'} . "../$local_libs{$_}/.libs/lib$_.dylib " . $Params{'LDDLFLAGS'};
+		}
+	    }
+	    $Params{'LIBS'} = ' ';
 	$Params{'CCFLAGS'} = "-I../../include " . $Params{'CCFLAGS'};
       }
       $Params{'CCFLAGS'} =~ s/ -W(all|inline|strict-prototypes|write-strings|cast-qual|no-char-subscripts)//g; # ignore developer warnings
diff -uNr net-snmp-5.7.3.orig/perl/agent/default_store/Makefile.PL net-snmp-5.7.3/perl/agent/default_store/Makefile.PL
--- net-snmp-5.7.3.orig/perl/agent/default_store/Makefile.PL	2014-12-08 15:23:22.000000000 -0500
+++ net-snmp-5.7.3/perl/agent/default_store/Makefile.PL	2016-10-11 13:16:22.000000000 -0400
@@ -69,6 +69,7 @@
     }
     else {
 	$opts = NetSNMPGetOpts("../../");
+	$Params{'LDDLFLAGS'} = "$Config{lddlflags} " . `$opts->{'nsconfig'} --ldflags`;
 	$Params{'LIBS'}    = `$opts->{'nsconfig'} --libs`;
 	chomp($Params{'LIBS'});
 	$Params{'CCFLAGS'} = `$opts->{'nsconfig'} --cflags`;
@@ -76,7 +77,19 @@
 	$Params{'CCFLAGS'} .= " " . $Config{'ccflags'};
         $lib_version = `$opts->{'nsconfig'} --version`;
 	if ($opts->{'insource'} eq "true") {
-	    $Params{'LIBS'} = "-L../../../snmplib/.libs -L../../../snmplib/ " . $Params{'LIBS'};
+	    my %local_libs = (
+		'netsnmp'        => 'snmplib',
+		'netsnmpagent'   => 'agent',
+		'netsnmphelpers' => 'agent/helpers',
+		'netsnmpmibs'    => 'agent',
+		'netsnmptrapd'   => 'apps',
+		);
+	    foreach (split ' ', $Params{'LIBS'}) {
+		if (s/^-l// && exists $local_libs{$_}) {
+		    $Params{'LDDLFLAGS'} = $opts->{'rootpath'} . "../$local_libs{$_}/.libs/lib$_.dylib " . $Params{'LDDLFLAGS'};
+		}
+	    }
+	    $Params{'LIBS'} = ' ';
 	    $Params{'CCFLAGS'} = "-I../../../include " . $Params{'CCFLAGS'};
 	}
 	$Params{'CCFLAGS'} =~ s/ -W(all|inline|strict-prototypes|write-strings|cast-qual|no-char-subscripts)//g; # ignore developer warnings
diff -uNr net-snmp-5.7.3.orig/perl/default_store/Makefile.PL net-snmp-5.7.3/perl/default_store/Makefile.PL
--- net-snmp-5.7.3.orig/perl/default_store/Makefile.PL	2014-12-08 15:23:22.000000000 -0500
+++ net-snmp-5.7.3/perl/default_store/Makefile.PL	2016-10-11 13:16:22.000000000 -0400
@@ -76,7 +76,19 @@
 	$Params{'CCFLAGS'} .= " " . $Config{'ccflags'};
         $lib_version = `$opts->{'nsconfig'} --version`;
 	if (lc($opts->{'insource'}) eq "true") {
-	    $Params{'LIBS'} = "-L../../snmplib/.libs -L../../snmplib/ " . $Params{'LIBS'};
+	    my %local_libs = (
+		'netsnmp'        => 'snmplib',
+		'netsnmpagent'   => 'agent',
+		'netsnmphelpers' => 'agent/helpers',
+		'netsnmpmibs'    => 'agent',
+		'netsnmptrapd'   => 'apps',
+		);
+	    foreach (split ' ', $Params{'LIBS'}) {
+		if (s/^-l// && exists $local_libs{$_}) {
+		    $Params{'LDDLFLAGS'} = $opts->{'rootpath'} . "../$local_libs{$_}/.libs/lib$_.dylib " . $Params{'LDDLFLAGS'};
+		}
+	    }
+	    $Params{'LIBS'} = ' ';
 	    $Params{'CCFLAGS'} = "-I../../include " . $Params{'CCFLAGS'};
 	}
 	$Params{'CCFLAGS'} =~ s/ -W(all|inline|strict-prototypes|write-strings|cast-qual|no-char-subscripts)//g; # ignore developer warnings
diff -uNr net-snmp-5.7.3.orig/snmplib/md5.c net-snmp-5.7.3/snmplib/md5.c
--- net-snmp-5.7.3.orig/snmplib/md5.c	2014-12-08 15:23:22.000000000 -0500
+++ net-snmp-5.7.3/snmplib/md5.c	2016-10-11 13:16:22.000000000 -0400
@@ -195,7 +195,7 @@
 {
     register unsigned int tmp, A, B, C, D;      /* hpux sysv sun */
 #ifdef WORDS_BIGENDIAN
-    MDreverse(X);
+    MDreverse((unsigned int*)X);
 #endif
     A = MDp->buffer[0];
     B = MDp->buffer[1];
@@ -275,7 +275,7 @@
     MDp->buffer[2] += C;
     MDp->buffer[3] += D;
 #ifdef WORDS_BIGENDIAN
-    MDreverse(X);
+    MDreverse((unsigned int*)X);
 #endif
 }
 
diff -uNr net-snmp-5.7.3.orig/snmplib/system.c net-snmp-5.7.3/snmplib/system.c
--- net-snmp-5.7.3.orig/snmplib/system.c	2014-12-08 15:23:22.000000000 -0500
+++ net-snmp-5.7.3/snmplib/system.c	2016-10-11 13:16:22.000000000 -0400
@@ -150,6 +150,7 @@
 
 #if defined(darwin9)
 #include <crt_externs.h>        /* for _NSGetArgv() */
+#include <mach-o/dyld.h>        /* for _NSGetExecutablePath() */
 #endif
 
 #if HAVE_PWD_H
diff -uNr net-snmp-5.7.3.orig/testing/Makefile.in net-snmp-5.7.3/testing/Makefile.in
--- net-snmp-5.7.3.orig/testing/Makefile.in	2014-12-08 15:23:22.000000000 -0500
+++ net-snmp-5.7.3/testing/Makefile.in	2016-10-11 13:16:22.000000000 -0400
@@ -11,7 +11,7 @@
 @NON_GNU_VPATH@ $(srcdir)
 
 USELIBS		= ../snmplib/libsnmp.$(LIB_EXTENSION)$(LIB_VERSION)
-LIBS		= -L../snmplib $(CC_RUNTIME_ARG) -lsnmp @LIBS@
+LIBS		= $(CC_RUNTIME_ARG) @LIBS@
 
 PARSEOBJS	=
 
diff -Nurd -x'*~' net-snmp-5.7.3.orig/testing/fulltests/default/T070com2sec_simple net-snmp-5.7.3/testing/fulltests/default/T070com2sec_simple
--- net-snmp-5.7.3.orig/testing/fulltests/default/T070com2sec_simple	2014-12-08 15:23:22.000000000 -0500
+++ net-snmp-5.7.3/testing/fulltests/default/T070com2sec_simple	2016-10-17 10:25:30.000000000 -0400
@@ -131,7 +131,8 @@
 SAVECHECKAGENT '<"c405k", 0.0.0.0/0.0.0.0> => "t405k"'
 SAVECHECKAGENT '<"c405l", 0.0.0.0/0.0.0.0> => "t405l"'
 SAVECHECKAGENT '<"c406a", 255.255.255.255/255.255.255.255> => "t406a"'
-SAVECHECKAGENT 'line 30: Error:' # msg from h_strerror so it varies
+# test fails if "no.such.address." resolves due to DNS wildcarding
+# SAVECHECKAGENT 'line 30: Error:' # msg from h_strerror so it varies
 SAVECHECKAGENT 'line 31: Error:' # msg from h_strerror so it varies
 
 CHECKAGENT '<"c408a"'
