Hello.

These are my changes to the transport framework.

They do depend on each other so please apply them in the order I
introduce them below.

kill-IPBase.diff:
        This patch removes snmpIPBaseDomain since netsnmp_sockaddr_in
        and netsnmp_sockaddr_in2 logically belongs in snmpIPv4Domain and
        netsnmp_set_non_blocking_mode logically belongs in
        snmpSocketBaseDomain as there is nothing that prevents e.g. an
        IPX or AAL5PVC link from being non-blocking. After these changes
        IPBase ends up empty and so it dies.
        
        This patch require regeneration of many Makefile.depend.

fix-dependencies.diff:
        Corrects the config_requires of the transports so that they
        depend on the ones that declare the functions they use.
        Note that I ignored the dependency from UDPBase to UDP since
        that looked odd and made the configure script loop.

generate-netsnmp_transport.diff:
        Let autoheader generate the templates for
        NETSNMP_TRANSPORT_*_DOMAIN.
        The drawback of this is that all domains are included regardless
        of how uncommitted they are but that is not - as I see it - a
        big problem.
        
        This patch require regeneration of configure and
        net-snmp-config.h.in

disable-udp-ip.diff:
        This patch removes the forced inclusion of the UDP transport but
        retains UDP as a default transport so it makes it possible to
        configure --with-out-transports=UDP.
        I do require that at least one transport is configured but that
        is open for debate, there is no real reason to require that save
        that the agent becomes utterly useless without any transport but
        on the other hand e.g. the Alias transport is enough to get past
        that test so maybe I should just skip it.

Now, I would love to hear some kind of comments on this.

/MF
Index: agent/mibgroup/smux/smux.h
===================================================================
--- agent/mibgroup/smux/smux.h.orig	2010-05-19 21:52:12.000000000 +0200
+++ agent/mibgroup/smux/smux.h	2010-05-20 09:13:26.000000000 +0200
@@ -2,6 +2,11 @@
  * Smux module authored by Rohit Dube.
  * Rewritten by Nick Amato <[email protected]>.
  */
+
+#ifndef NETSNMP_TRANSPORT_IPV4BASE_DOMAIN
+config_error(smux/smux depends on the IPv4Base transport domain)
+#endif
+
 config_belongs_in(agent_module)
 
 #define SMUXPORT 199
Index: agent/mibgroup/mibII/vacm_conf.c
===================================================================
--- agent/mibgroup/mibII/vacm_conf.c.orig	2010-05-20 09:13:53.000000000 +0200
+++ agent/mibgroup/mibII/vacm_conf.c	2010-05-20 09:14:26.000000000 +0200
@@ -943,6 +943,7 @@
     commcount++;
 
 #if !defined(NETSNMP_DISABLE_SNMPV1) || !defined(NETSNMP_DISABLE_SNMPV2C)
+#ifdef NETSNMP_TRANSPORT_UDP_DOMAIN
     if (parsetype == VACM_CREATE_SIMPLE_COMIPV4 ||
         parsetype == VACM_CREATE_SIMPLE_COM) {
         vacm_gen_com2sec(commcount, community, addressname,
@@ -950,7 +951,8 @@
                          secname, sizeof(secname),
                          view_ptr, sizeof(viewname), commversion);
     }
-    
+#endif
+
 #ifdef NETSNMP_TRANSPORT_UNIX_DOMAIN
     if (parsetype == VACM_CREATE_SIMPLE_COMUNIX ||
         parsetype == VACM_CREATE_SIMPLE_COM) {
@@ -1301,7 +1303,9 @@
          * community string to a security name for us.  
          */
 
-        if (pdu->tDomain == netsnmpUDPDomain
+        if (0) {
+#ifdef NETSNMP_TRANSPORT_UDP_DOMAIN
+        } else if (pdu->tDomain == netsnmpUDPDomain
 #ifdef NETSNMP_TRANSPORT_TCP_DOMAIN
             || pdu->tDomain == netsnmp_snmpTCPDomain
 #endif
@@ -1320,6 +1324,7 @@
             SNMP_FREE(pdu->contextName);
             pdu->contextName = strdup(contextName);
             pdu->contextNameLen = strlen(contextName);
+#endif
 #ifdef NETSNMP_TRANSPORT_UDPIPV6_DOMAIN
         } else if (pdu->tDomain == netsnmp_UDPIPv6Domain
 #ifdef NETSNMP_TRANSPORT_TCPIPV6_DOMAIN
Index: configure.d/config_modules_lib
===================================================================
--- configure.d/config_modules_lib.orig	2010-05-20 09:13:53.000000000 +0200
+++ configure.d/config_modules_lib	2010-05-20 09:14:26.000000000 +0200
@@ -141,15 +141,10 @@
   future_new_transport_list=""
   for i in $new_transport_list; do
     if echo " $new_with_out_transport_list " | $GREP " $i " >/dev/null; then
-      if test "x$i" = "xUDP"; then
-        echo
-        AC_MSG_ERROR(It is not possible to compile without UDP/IP support.)
-      fi
-      continue
+      true
     else
-      if test ! "x$enable_ipv6" = "xyes"; then
+      if test "x$enable_ipv6" != "xyes"; then
           if test "x$i" = "xUDPIPv6" -o "x$i" = "xTCPIPv6"; then
-              echo
               AC_MSG_ERROR(IPv6 transports not available if IPv6 support is not enabled)
           fi
       fi
@@ -222,7 +217,7 @@
   done # for each new transport
   new_transport_list="$future_new_transport_list"
 done # while new transports exist
-transport_obj_list=`echo " $transport_src_list " | $SED 's/\.c/\.o/g'` 	 
+transport_obj_list=`echo " $transport_src_list " | $SED 's/\.c/\.o/g'`
 transport_lobj_list=`echo " $transport_src_list " | $SED 's/\.c/\.lo/g'`
 for i in $tr_init_list ; do
    echo "$i();" >> $ctor_header
@@ -236,6 +231,10 @@
   fi
 fi
 
+if test "x$transport_result_list" = x ; then
+   AC_MSG_ERROR([No transports configured, at least one must be provided])
+fi
+
 AC_SUBST(transport_hdr_list)
 AC_SUBST(transport_src_list)
 AC_SUBST(transport_obj_list)
Index: include/net-snmp/library/snmpIPv6BaseDomain.h
===================================================================
--- include/net-snmp/library/snmpIPv6BaseDomain.h.orig	2010-05-20 08:53:18.000000000 +0200
+++ include/net-snmp/library/snmpIPv6BaseDomain.h	2010-05-20 09:12:48.000000000 +0200
@@ -3,18 +3,16 @@
 #ifndef SNMPIPV6BASE_H
 #define SNMPIPV6BASE_H
 
-#ifdef __cplusplus
-extern          "C" {
+#if HAVE_NETINET_IN_H
+#include <netinet/in.h>
 #endif
 
-#include <net-snmp/library/snmp_transport.h>
-#include <net-snmp/library/asn1.h>
+config_require(SocketBase)
 
-#if HAVE_SYS_SOCKET_H
-#include <sys/socket.h>
-#endif
-#if HAVE_NETINET_IN_H
-#include <netinet/in.h>
+#include <net-snmp/library/snmpSocketBaseDomain.h>
+
+#ifdef __cplusplus
+extern          "C" {
 #endif
 
 /*
Index: include/net-snmp/library/snmpTCPBaseDomain.h
===================================================================
--- include/net-snmp/library/snmpTCPBaseDomain.h.orig	2010-05-20 08:50:54.000000000 +0200
+++ include/net-snmp/library/snmpTCPBaseDomain.h	2010-05-20 09:12:48.000000000 +0200
@@ -5,9 +5,6 @@
 extern          "C" {
 #endif
 
-config_require(SocketBase)
-#include <net-snmp/library/snmpSocketBaseDomain.h>
-
 /*
  * Prototypes
  */
Index: include/net-snmp/library/snmpUDPDomain.h
===================================================================
--- include/net-snmp/library/snmpUDPDomain.h.orig	2010-05-20 08:50:54.000000000 +0200
+++ include/net-snmp/library/snmpUDPDomain.h	2010-05-20 09:12:48.000000000 +0200
@@ -16,9 +16,7 @@
 #endif
 
 config_require(UDPIPv4Base)
-config_require(SocketBase)
 #include <net-snmp/library/snmpUDPIPv4BaseDomain.h>
-#include <net-snmp/library/snmpSocketBaseDomain.h>
 
 netsnmp_transport *netsnmp_udp_transport(struct sockaddr_in *addr, int local);
 
Index: include/net-snmp/library/snmpUDPIPv4BaseDomain.h
===================================================================
--- include/net-snmp/library/snmpUDPIPv4BaseDomain.h.orig	2010-05-20 08:53:18.000000000 +0200
+++ include/net-snmp/library/snmpUDPIPv4BaseDomain.h	2010-05-20 09:12:48.000000000 +0200
@@ -3,17 +3,6 @@
 #ifndef SNMPUDPIPV4BASE_H
 #define SNMPUDPIPV4BASE_H
 
-#ifdef __cplusplus
-extern          "C" {
-#endif
-
-#include <net-snmp/library/snmp_transport.h>
-#include <net-snmp/library/asn1.h>
-#include <net-snmp/library/snmpUDPBaseDomain.h>
-
-config_require(UDPBase)
-config_require(IPv4Base)
-
 #if HAVE_SYS_SOCKET_H
 #include <sys/socket.h>
 #endif
@@ -21,6 +10,16 @@
 #include <netinet/in.h>
 #endif
 
+config_require(UDPBase)
+config_require(IPv4Base)
+
+#include <net-snmp/library/snmpIPv4BaseDomain.h>
+#include <net-snmp/library/snmpUDPBaseDomain.h>
+
+#ifdef __cplusplus
+extern          "C" {
+#endif
+
 /*
  * Definitions
  */
Index: include/net-snmp/library/snmpUDPIPv6Domain.h
===================================================================
--- include/net-snmp/library/snmpUDPIPv6Domain.h.orig	2010-05-20 08:50:54.000000000 +0200
+++ include/net-snmp/library/snmpUDPIPv6Domain.h	2010-05-20 09:12:48.000000000 +0200
@@ -12,6 +12,7 @@
 
 config_require(SocketBase)
 config_require(IPv6Base)
+config_require(UDPBase)
 #include <net-snmp/library/snmpIPv6BaseDomain.h>
 
 /*
Index: include/net-snmp/library/snmpUnixDomain.h
===================================================================
--- include/net-snmp/library/snmpUnixDomain.h.orig	2010-05-20 08:50:55.000000000 +0200
+++ include/net-snmp/library/snmpUnixDomain.h	2010-05-20 09:12:48.000000000 +0200
@@ -3,10 +3,6 @@
 
 #ifdef NETSNMP_TRANSPORT_UNIX_DOMAIN
 
-#ifdef __cplusplus
-extern          "C" {
-#endif
-
 #if defined(cygwin) || defined(mingw32) || defined(mingw32msvc)
     config_error(Unix domain protocol support unavailable for this platform)
 #endif
@@ -18,11 +14,14 @@
 #include <sys/un.h>
 #endif
 
-#include <net-snmp/library/snmp_transport.h>
-#include <net-snmp/library/asn1.h>
+#include <net-snmp/library/snmpSocketBaseDomain.h>
 
 config_require(SocketBase)
 
+#ifdef __cplusplus
+extern          "C" {
+#endif
+
 /*
  * The SNMP over local socket transport domain is identified by
  * transportDomainLocal as defined in RFC 3419.
Index: snmplib/transports/snmpUDPBaseDomain.c
===================================================================
--- snmplib/transports/snmpUDPBaseDomain.c.orig	2010-05-20 08:50:54.000000000 +0200
+++ snmplib/transports/snmpUDPBaseDomain.c	2010-05-20 09:12:48.000000000 +0200
@@ -31,6 +31,7 @@
 
 #include <net-snmp/types.h>
 #include <net-snmp/library/snmpUDPBaseDomain.h>
+#include <net-snmp/library/snmpUDPDomain.h>
 #include <net-snmp/library/snmp_debug.h>
 #include <net-snmp/library/tools.h>
 #include <net-snmp/library/default_store.h>
Index: snmplib/transports/snmpUDPIPv6Domain.c
===================================================================
--- snmplib/transports/snmpUDPIPv6Domain.c.orig	2010-05-20 08:50:54.000000000 +0200
+++ snmplib/transports/snmpUDPIPv6Domain.c	2010-05-20 09:12:48.000000000 +0200
@@ -57,6 +57,7 @@
 
 #include <net-snmp/library/snmp_transport.h>
 #include <net-snmp/library/snmpUDPIPv6Domain.h>
+#include <net-snmp/library/snmpSocketBaseDomain.h>
 
 #include "inet_ntop.h"
 #include "inet_pton.h"
Index: acconfig.h
===================================================================
--- acconfig.h.orig	2010-05-19 21:52:12.000000000 +0200
+++ acconfig.h	2010-05-20 09:13:10.000000000 +0200
@@ -346,63 +346,6 @@
 /* internal define */
 #define NETSNMP_LASTFIELD -1
 
-/*  Pluggable transports.  */
-
-/*  This is defined if support for the UDP/IP transport domain is
-    available.   */
-#undef NETSNMP_TRANSPORT_UDP_DOMAIN
-
-/*  This is defined if support for the "callback" transport domain is
-    available.   */
-#undef NETSNMP_TRANSPORT_CALLBACK_DOMAIN
-
-/*  This is defined if support for the TCP/IP transport domain is
-    available.  */
-#undef NETSNMP_TRANSPORT_TCP_DOMAIN
-
-/*  This is defined if support for the Unix transport domain
-    (a.k.a. "local IPC") is available.  */
-#undef NETSNMP_TRANSPORT_UNIX_DOMAIN
-
-/*  This is defined if support for the AAL5 PVC transport domain is
-    available.  */
-#undef NETSNMP_TRANSPORT_AAL5PVC_DOMAIN
-
-/*  This is defined if support for the IPX transport domain is
-    available.  */
-#undef NETSNMP_TRANSPORT_IPX_DOMAIN
-
-/*  This is defined if support for the UDP/IPv6 transport domain is
-    available.  */
-#undef NETSNMP_TRANSPORT_UDPIPV6_DOMAIN
-
-/*  This is defined if support for the TCP/IPv6 transport domain is
-    available.  */
-#undef NETSNMP_TRANSPORT_TCPIPV6_DOMAIN
-
-/*  This is defined if support for the TLS transport domain is
-    available.   */
-#undef NETSNMP_TRANSPORT_TLS_DOMAIN
-
-/*  This is defined if support for the Alias transport domain is
-    available.   */
-#undef NETSNMP_TRANSPORT_ALIAS_DOMAIN
-
-/*  This is defined if support for the SSH transport domain is
-    available.   */
-#undef NETSNMP_TRANSPORT_SSH_DOMAIN
-
-/*  This is defined if support for the DTLS/UDP transport domain is
-    available.   */
-#undef NETSNMP_TRANSPORT_DTLSUDP_DOMAIN
-
-/*  This is defined if support for the DTLS/UDP transport domain is
-    available.   */
-#undef NETSNMP_TRANSPORT_TLSTCP_DOMAIN
-
-/*  This is defined if support for stdin/out transport domain is available.   */
-#undef NETSNMP_TRANSPORT_STD_DOMAIN
-
 /* define this if the USM security module is available */
 #undef NETSNMP_SECMOD_USM
 
Index: configure.d/config_modules_lib
===================================================================
--- configure.d/config_modules_lib.orig	2010-05-19 21:52:12.000000000 +0200
+++ configure.d/config_modules_lib	2010-05-20 09:13:10.000000000 +0200
@@ -85,6 +85,21 @@
 fi
 
 #
+# Declare transport module macros in net-snmp-config.h.in
+#
+m4_foreach_w(
+  name,
+  m4_bpatsubst(
+    m4_esyscmd(
+      [echo include/net-snmp/library/snmp*Domain.h]),
+      [include/net-snmp/library/snmp\([A-Za-z0-9_]*\)Domain.h[^a-zA-Z0-9_ ]*],
+      [\1]),
+  [AH_TEMPLATE(
+     [NETSNMP_TRANSPORT_]m4_toupper(name)[_DOMAIN],
+     [This is defined if support for the ]name[ transport domain is
+      available.])])
+
+#
 # Do transport module processing.
 #
 AC_MSG_CHECKING([for and configuring transport modules to use])
Index: include/net-snmp/library/snmpIPBaseDomain.h
===================================================================
--- include/net-snmp/library/snmpIPBaseDomain.h	2010-05-20 08:52:18.000000000 +0200
+++ /dev/null	1970-01-01 00:00:00.000000000 +0000
@@ -1,46 +0,0 @@
-/* IP base transport support functions
- */
-#ifndef SNMPIPBASEDOMAIN_H
-#define SNMPIPBASEDOMAIN_H
-
-#ifdef __cplusplus
-extern          "C" {
-#endif
-
-#include <net-snmp/library/snmp_transport.h>
-#include <net-snmp/library/asn1.h>
-
-#if HAVE_SYS_SOCKET_H
-#include <sys/socket.h>
-#endif
-#if HAVE_NETINET_IN_H
-#include <netinet/in.h>
-#endif
-
-/*
- * Convert a "traditional" peername into a sockaddr_in structure which is
- * written to *addr_  Returns 1 if the conversion was successful, or 0 if it
- * failed_  
- */
-
-    int netsnmp_sockaddr_in(struct sockaddr_in *addr, const char *peername,
-                            int remote_port);
-    int netsnmp_sockaddr_in2(struct sockaddr_in *addr, const char *inpeername,
-                             const char *default_target);
-
-    /**
-     * Sets the mode of a socket for all subsequent I/O operations.
-     *
-     * @param[in] sock Socket descriptor (Unix) or socket handle (Windows).
-     * @param[in] non_blocking_mode I/O mode: non-zero selects non-blocking mode;
-     *   zero selects blocking mode.
-     *
-     * @return zero upon success and a negative value upon error.
-     */
-    int             netsnmp_set_non_blocking_mode(int sock,
-                                                  int non_blocking_mode);
-
-#ifdef __cplusplus
-}
-#endif
-#endif /* SNMPIPBASEDOMAIN_H */
Index: include/net-snmp/library/snmpIPv4BaseDomain.h
===================================================================
--- include/net-snmp/library/snmpIPv4BaseDomain.h.orig	2010-05-20 08:52:18.000000000 +0200
+++ include/net-snmp/library/snmpIPv4BaseDomain.h	2010-05-20 08:53:18.000000000 +0200
@@ -3,21 +3,16 @@
 #ifndef SNMPIPV4BASE_H
 #define SNMPIPV4BASE_H
 
-#ifdef __cplusplus
-extern          "C" {
+#if HAVE_NETINET_IN_H
+#include <netinet/in.h>
 #endif
 
-#include <net-snmp/library/snmp_transport.h>
-#include <net-snmp/library/asn1.h>
-#include <net-snmp/library/snmpIPBaseDomain.h>
+config_require(SocketBase)
 
-config_require(IPBase)
+#include <net-snmp/library/snmpSocketBaseDomain.h>
 
-#if HAVE_SYS_SOCKET_H
-#include <sys/socket.h>
-#endif
-#if HAVE_NETINET_IN_H
-#include <netinet/in.h>
+#ifdef __cplusplus
+extern          "C" {
 #endif
 
 /*
@@ -27,6 +22,17 @@
     char *netsnmp_ipv4_fmtaddr(const char *prefix, netsnmp_transport *t,
                                void *data, int len);
 
+/*
+ * Convert a "traditional" peername into a sockaddr_in structure which is
+ * written to *addr_  Returns 1 if the conversion was successful, or 0 if it
+ * failed
+ */
+
+    int netsnmp_sockaddr_in(struct sockaddr_in *addr, const char *peername,
+                            int remote_port);
+    int netsnmp_sockaddr_in2(struct sockaddr_in *addr, const char *inpeername,
+                             const char *default_target);
+
 #ifdef __cplusplus
 }
 #endif
Index: include/net-snmp/library/snmpIPv6BaseDomain.h
===================================================================
--- include/net-snmp/library/snmpIPv6BaseDomain.h.orig	2010-05-20 08:52:18.000000000 +0200
+++ include/net-snmp/library/snmpIPv6BaseDomain.h	2010-05-20 08:53:18.000000000 +0200
@@ -9,9 +9,6 @@
 
 #include <net-snmp/library/snmp_transport.h>
 #include <net-snmp/library/asn1.h>
-#include <net-snmp/library/snmpIPBaseDomain.h>
-
-config_require(IPBase)
 
 #if HAVE_SYS_SOCKET_H
 #include <sys/socket.h>
Index: include/net-snmp/library/snmpSocketBaseDomain.h
===================================================================
--- include/net-snmp/library/snmpSocketBaseDomain.h.orig	2010-05-20 08:52:18.000000000 +0200
+++ include/net-snmp/library/snmpSocketBaseDomain.h	2010-05-20 08:53:18.000000000 +0200
@@ -1,6 +1,12 @@
 #ifndef SNMPSOCKETBASEDOMAIN_H
 #define SNMPSOCKETBASEDOMAIN_H
 
+#if HAVE_SYS_SOCKET_H
+#include <sys/socket.h>
+#endif
+
+#include <net-snmp/library/snmp_transport.h>
+
 #ifdef __cplusplus
 extern          "C" {
 #endif
@@ -10,6 +16,7 @@
  */
     int netsnmp_socketbase_close(netsnmp_transport *t);
     int netsnmp_sock_buffer_set(int s, int optname, int local, int size);
+    int netsnmp_set_non_blocking_mode(int sock, int non_blocking_mode);
 
 #ifdef __cplusplus
 }
Index: include/net-snmp/library/snmpTLSTCPDomain.h
===================================================================
--- include/net-snmp/library/snmpTLSTCPDomain.h.orig	2010-05-20 08:52:18.000000000 +0200
+++ include/net-snmp/library/snmpTLSTCPDomain.h	2010-05-20 08:53:18.000000000 +0200
@@ -18,7 +18,7 @@
 #endif
 
 config_require(SocketBase)
-config_require(IPBase)
+config_require(IPv4Base)
 config_require(TLSBase)
 
 #define TRANSPORT_DOMAIN_TLS_TCP_IP	1,3,6,1,6,1,8
Index: include/net-snmp/library/snmpUDPIPv4BaseDomain.h
===================================================================
--- include/net-snmp/library/snmpUDPIPv4BaseDomain.h.orig	2010-05-20 08:52:18.000000000 +0200
+++ include/net-snmp/library/snmpUDPIPv4BaseDomain.h	2010-05-20 08:53:18.000000000 +0200
@@ -9,7 +9,6 @@
 
 #include <net-snmp/library/snmp_transport.h>
 #include <net-snmp/library/asn1.h>
-#include <net-snmp/library/snmpIPBaseDomain.h>
 #include <net-snmp/library/snmpUDPBaseDomain.h>
 
 config_require(UDPBase)
Index: snmplib/transports/snmpIPBaseDomain.c
===================================================================
--- snmplib/transports/snmpIPBaseDomain.c	2010-05-20 08:52:18.000000000 +0200
+++ /dev/null	1970-01-01 00:00:00.000000000 +0000
@@ -1,199 +0,0 @@
-/* IP base transport support functions
- */
-
-#include <net-snmp/net-snmp-config.h>
-
-#include <stddef.h>
-#include <stdio.h>
-#include <sys/types.h>
-#include <ctype.h>
-#if HAVE_STDLIB_H
-#include <stdlib.h>
-#endif
-#if HAVE_STRING_H
-#include <string.h>
-#else
-#include <strings.h>
-#endif
-#if HAVE_FCNTL_H
-#include <fcntl.h>
-#endif
-#if HAVE_SYS_SOCKET_H
-#include <sys/socket.h>
-#endif
-#if HAVE_NETINET_IN_H
-#include <netinet/in.h>
-#endif
-#if HAVE_ARPA_INET_H
-#include <arpa/inet.h>
-#endif
-
-#include <net-snmp/types.h>
-#include <net-snmp/library/snmpIPBaseDomain.h>
-#include <net-snmp/library/snmp_debug.h>
-#include <net-snmp/library/default_store.h>
-#include <net-snmp/library/system.h>
-
-#ifndef INADDR_NONE
-#define INADDR_NONE     -1
-#endif
-
-int
-netsnmp_sockaddr_in(struct sockaddr_in *addr,
-                    const char *inpeername, int remote_port)
-{
-    char buf[sizeof(int) * 3 + 2];
-    sprintf(buf, ":%u", remote_port);
-    return netsnmp_sockaddr_in2(addr, inpeername, remote_port ? buf : NULL);
-}
-
-int
-netsnmp_sockaddr_in2(struct sockaddr_in *addr,
-                     const char *inpeername, const char *default_target)
-{
-    int ret;
-
-    if (addr == NULL) {
-        return 0;
-    }
-
-    DEBUGMSGTL(("netsnmp_sockaddr_in",
-                "addr %p, inpeername \"%s\", default_target \"%s\"\n",
-                addr, inpeername ? inpeername : "[NIL]",
-                default_target ? default_target : "[NIL]"));
-
-    memset(addr, 0, sizeof(struct sockaddr_in));
-    addr->sin_addr.s_addr = htonl(INADDR_ANY);
-    addr->sin_family = AF_INET;
-    addr->sin_port = htons((u_short)SNMP_PORT);
-
-    {
-	int port = netsnmp_ds_get_int(NETSNMP_DS_LIBRARY_ID,
-				      NETSNMP_DS_LIB_DEFAULT_PORT);
-
-	if (port != 0) {
-	    addr->sin_port = htons((u_short)port);
-	} else if (default_target != NULL)
-	    netsnmp_sockaddr_in2(addr, default_target, NULL);
-    }
-
-    if (inpeername != NULL && *inpeername != '\0') {
-	const char     *host, *port;
-	char           *peername = NULL;
-        char           *cp;
-        /*
-         * Duplicate the peername because we might want to mank around with
-         * it.  
-         */
-
-        peername = strdup(inpeername);
-        if (peername == NULL) {
-            return 0;
-        }
-
-        /*
-         * Try and extract an appended port number.  
-         */
-        cp = strchr(peername, ':');
-        if (cp != NULL) {
-            *cp = '\0';
-            port = cp + 1;
-            host = peername;
-        } else {
-            host = NULL;
-            port = peername;
-        }
-
-        /*
-         * Try to convert the user port specifier
-         */
-        if (port && *port == '\0')
-            port = NULL;
-
-        if (port != NULL) {
-            long int l;
-            char* ep;
-
-            DEBUGMSGTL(("netsnmp_sockaddr_in", "check user service %s\n",
-                        port));
-
-            l = strtol(port, &ep, 10);
-            if (ep != port && *ep == '\0' && 0 <= l && l <= 0x0ffff)
-                addr->sin_port = htons((u_short)l);
-            else {
-                if (host == NULL) {
-                    DEBUGMSGTL(("netsnmp_sockaddr_in",
-                                "servname not numeric, "
-				"check if it really is a destination)\n"));
-                    host = port;
-                    port = NULL;
-                } else {
-                    DEBUGMSGTL(("netsnmp_sockaddr_in",
-                                "servname not numeric\n"));
-                    free(peername);
-                    return 0;
-                }
-            }
-        }
-
-        /*
-         * Try to convert the user host specifier
-         */
-        if (host && *host == '\0')
-            host = NULL;
-
-        if (host != NULL) {
-            DEBUGMSGTL(("netsnmp_sockaddr_in",
-                        "check destination %s\n", host));
-
-
-            if (strcmp(peername, "255.255.255.255") == 0 ) {
-                /*
-                 * The explicit broadcast address hack
-                 */
-                DEBUGMSGTL(("netsnmp_sockaddr_in", "Explicit UDP broadcast\n"));
-                addr->sin_addr.s_addr = INADDR_NONE;
-            } else {
-                ret =
-                    netsnmp_gethostbyname_v4(peername, &addr->sin_addr.s_addr);
-                if (ret < 0) {
-                    DEBUGMSGTL(("netsnmp_sockaddr_in",
-                                "couldn't resolve hostname\n"));
-                    free(peername);
-                    return 0;
-                }
-                DEBUGMSGTL(("netsnmp_sockaddr_in",
-                            "hostname (resolved okay)\n"));
-            }
-        }
-	free(peername);
-    }
-
-    /*
-     * Finished
-     */
-
-    DEBUGMSGTL(("netsnmp_sockaddr_in", "return { AF_INET, %s:%hu }\n",
-                inet_ntoa(addr->sin_addr), ntohs(addr->sin_port)));
-    return 1;
-}
-
-int
-netsnmp_set_non_blocking_mode(int sock, int non_blocking_mode)
-{
-#ifdef WIN32
-    u_long          arg;
-
-    arg = non_blocking_mode;
-    return ioctlsocket(sock, FIONBIO, &arg);
-#else
-    int             sockflags;
-
-    if ((sockflags = fcntl(sock, F_GETFL, 0)) >= 0) {
-        return fcntl(sock, F_SETFL,
-                     non_blocking_mode ? sockflags | O_NONBLOCK
-                     : sockflags & ~O_NONBLOCK);
-    } else
-        return -1;
-#endif
-}
Index: snmplib/transports/snmpIPv4BaseDomain.c
===================================================================
--- snmplib/transports/snmpIPv4BaseDomain.c.orig	2010-05-20 08:52:18.000000000 +0200
+++ snmplib/transports/snmpIPv4BaseDomain.c	2010-05-20 08:53:18.000000000 +0200
@@ -29,8 +29,155 @@
 #endif
 
 #include <net-snmp/types.h>
+#include <net-snmp/library/snmp_debug.h>
+#include <net-snmp/library/default_store.h>
 #include <net-snmp/library/snmpIPv4BaseDomain.h>
 
+
+#ifndef INADDR_NONE
+#define INADDR_NONE     -1
+#endif
+
+int
+netsnmp_sockaddr_in(struct sockaddr_in *addr,
+                    const char *inpeername, int remote_port)
+{
+    char buf[sizeof(int) * 3 + 2];
+    sprintf(buf, ":%u", remote_port);
+    return netsnmp_sockaddr_in2(addr, inpeername, remote_port ? buf : NULL);
+}
+
+int
+netsnmp_sockaddr_in2(struct sockaddr_in *addr,
+                     const char *inpeername, const char *default_target)
+{
+    int ret;
+
+    if (addr == NULL) {
+        return 0;
+    }
+
+    DEBUGMSGTL(("netsnmp_sockaddr_in",
+                "addr %p, inpeername \"%s\", default_target \"%s\"\n",
+                addr, inpeername ? inpeername : "[NIL]",
+                default_target ? default_target : "[NIL]"));
+
+    memset(addr, 0, sizeof(struct sockaddr_in));
+    addr->sin_addr.s_addr = htonl(INADDR_ANY);
+    addr->sin_family = AF_INET;
+    addr->sin_port = htons((u_short)SNMP_PORT);
+
+    {
+	int port = netsnmp_ds_get_int(NETSNMP_DS_LIBRARY_ID,
+				      NETSNMP_DS_LIB_DEFAULT_PORT);
+
+	if (port != 0) {
+	    addr->sin_port = htons((u_short)port);
+	} else if (default_target != NULL)
+	    netsnmp_sockaddr_in2(addr, default_target, NULL);
+    }
+
+    if (inpeername != NULL && *inpeername != '\0') {
+	const char     *host, *port;
+	char           *peername = NULL;
+        char           *cp;
+        /*
+         * Duplicate the peername because we might want to mank around with
+         * it.
+         */
+
+        peername = strdup(inpeername);
+        if (peername == NULL) {
+            return 0;
+        }
+
+        /*
+         * Try and extract an appended port number.
+         */
+        cp = strchr(peername, ':');
+        if (cp != NULL) {
+            *cp = '\0';
+            port = cp + 1;
+            host = peername;
+        } else {
+            host = NULL;
+            port = peername;
+        }
+
+        /*
+         * Try to convert the user port specifier
+         */
+        if (port && *port == '\0')
+            port = NULL;
+
+        if (port != NULL) {
+            long int l;
+            char* ep;
+
+            DEBUGMSGTL(("netsnmp_sockaddr_in", "check user service %s\n",
+                        port));
+
+            l = strtol(port, &ep, 10);
+            if (ep != port && *ep == '\0' && 0 <= l && l <= 0x0ffff)
+                addr->sin_port = htons((u_short)l);
+            else {
+                if (host == NULL) {
+                    DEBUGMSGTL(("netsnmp_sockaddr_in",
+                                "servname not numeric, "
+				"check if it really is a destination)\n"));
+                    host = port;
+                    port = NULL;
+                } else {
+                    DEBUGMSGTL(("netsnmp_sockaddr_in",
+                                "servname not numeric\n"));
+                    free(peername);
+                    return 0;
+                }
+            }
+        }
+
+        /*
+         * Try to convert the user host specifier
+         */
+        if (host && *host == '\0')
+            host = NULL;
+
+        if (host != NULL) {
+            DEBUGMSGTL(("netsnmp_sockaddr_in",
+                        "check destination %s\n", host));
+
+
+            if (strcmp(peername, "255.255.255.255") == 0 ) {
+                /*
+                 * The explicit broadcast address hack
+                 */
+                DEBUGMSGTL(("netsnmp_sockaddr_in", "Explicit UDP broadcast\n"));
+                addr->sin_addr.s_addr = INADDR_NONE;
+            } else {
+                ret =
+                    netsnmp_gethostbyname_v4(peername, &addr->sin_addr.s_addr);
+                if (ret < 0) {
+                    DEBUGMSGTL(("netsnmp_sockaddr_in",
+                                "couldn't resolve hostname\n"));
+                    free(peername);
+                    return 0;
+                }
+                DEBUGMSGTL(("netsnmp_sockaddr_in",
+                            "hostname (resolved okay)\n"));
+            }
+        }
+	free(peername);
+    }
+
+    /*
+     * Finished
+     */
+
+    DEBUGMSGTL(("netsnmp_sockaddr_in", "return { AF_INET, %s:%hu }\n",
+                inet_ntoa(addr->sin_addr), ntohs(addr->sin_port)));
+    return 1;
+}
+
 char *
 netsnmp_ipv4_fmtaddr(const char *prefix, netsnmp_transport *t,
                      void *data, int len)
Index: snmplib/transports/snmpSocketBaseDomain.c
===================================================================
--- snmplib/transports/snmpSocketBaseDomain.c.orig	2010-05-20 08:52:18.000000000 +0200
+++ snmplib/transports/snmpSocketBaseDomain.c	2010-05-20 08:53:18.000000000 +0200
@@ -18,6 +18,9 @@
 #else
 #include <strings.h>
 #endif
+#if HAVE_FCNTL_H
+#include <fcntl.h>
+#endif
 #if HAVE_SYS_SOCKET_H
 #include <sys/socket.h>
 #endif
@@ -332,3 +335,32 @@
 #endif
 }
 
+
+/**
+ * Sets the mode of a socket for all subsequent I/O operations.
+ *
+ * @param[in] sock Socket descriptor (Unix) or socket handle (Windows).
+ * @param[in] non_blocking_mode I/O mode: non-zero selects non-blocking mode;
+ *   zero selects blocking mode.
+ *
+ * @return zero upon success and a negative value upon error.
+ */
+int
+netsnmp_set_non_blocking_mode(int sock, int non_blocking_mode)
+{
+#ifdef WIN32
+    u_long          arg;
+
+    arg = non_blocking_mode;
+    return ioctlsocket(sock, FIONBIO, &arg);
+#else
+    int             sockflags;
+
+    if ((sockflags = fcntl(sock, F_GETFL, 0)) >= 0) {
+        return fcntl(sock, F_SETFL,
+                     non_blocking_mode ? sockflags | O_NONBLOCK
+                     : sockflags & ~O_NONBLOCK);
+    } else
+        return -1;
+#endif
+}
------------------------------------------------------------------------------

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

Reply via email to