3-Jun-2004  Mike Slifcak

Patch using net-snmp-5.1.1 or May 2004 V5-1-patdhes branch,
Built using FreeBSD 5.2.1

Impact to other BSD-like systems is not known at time of writing.

diff -ur net-snmp/agent/mibgroup/mibII/tcpTable.c net-snmp/agent/mibgroup/mibII/tcpTable.c
--- net-snmp/agent/mibgroup/mibII/tcpTable.c	Wed Apr  7 00:59:27 2004
+++ net-snmp/agent/mibgroup/mibII/tcpTable.c	Wed Jun  2 13:01:39 2004
@@ -35,6 +34,17 @@
 #include "tcpTable.h"
 #include "sysORTable.h"
 
+static	int StateMap[16] = {
+/* the value "5" represents an established connection.
+ * the value "8" represents a connection in CLOSE_WAIT state.
+ */
+#ifdef hpux
+	1, 2, 3, -1, 4, 5, 8, 6, 10, 9, 7, 11, 0,0,0,0
+#else
+	1, 2, 3,     4, 5, 8, 6, 10, 9, 7, 11, 0,0,0,0,0
+#endif
+};
+
 #ifdef hpux11
 #define	TCPTABLE_ENTRY_TYPE	mib_tcpConnEnt 
 #define	TCPTABLE_STATE		State 
@@ -702,7 +712,13 @@
     char     *tcpcb_buf = NULL;
     struct xinpgen *xig = NULL;
     netsnmp_inpcb  *nnew;
-    int      StateMap[] = { 1, 2, 3, 4, 5, 8, 6, 10, 9, 7, 11 };
+
+#if defined(freebsd4)
+    #define NS_ELEM struct xtcpcb
+#else
+/* this is the original value */
+    #define NS_ELEM struct xinpcb
+#endif
 
     tcpTable_free(NULL, NULL);
 
@@ -729,11 +745,11 @@
         nnew = SNMP_MALLOC_TYPEDEF(netsnmp_inpcb);
         if (!nnew)
             break;
-        nnew->state = StateMap[((struct xinpcb *) xig)->xt_tp.t_state];
+        nnew->state = StateMap[0x0f & ((NS_ELEM *) xig)->xt_tp.t_state];
         if (nnew->state == 5 /* established */ ||
             nnew->state == 8 /*  closeWait  */ )
             tcp_estab++;
-        memcpy(&(nnew->pcb), &(((struct xinpcb *) xig)->xt_inp),
+        memcpy(&(nnew->pcb), &(((NS_ELEM *) xig)->xt_inp),
                            sizeof(struct inpcb));
 
 	nnew->inp_next = tcp_head;
@@ -748,6 +764,7 @@
     }
     DEBUGMSGTL(("mibII/tcpTable", "Failed to load TCP Table (sysctl)\n"));
     return -1;
+#undef NS_ELEM
 }
 #else		/* (defined(CAN_USE_SYSCTL) && defined(TCPCTL_PCBLIST)) */
 #ifdef PCB_TABLE
@@ -758,7 +775,6 @@
     struct inpcb   *entry;
     struct tcpcb    tcpcb;
     netsnmp_inpcb  *nnew;
-    int      StateMap[] = { 1, 2, 3, 4, 5, 8, 6, 10, 9, 7, 11 };
 
     tcpTable_free(NULL, NULL);
 
@@ -778,7 +794,7 @@
             break;
         klookup((unsigned long) entry, (char *)&(nnew->pcb), sizeof(struct inpcb));
         klookup((int) nnew->pcb.inp_ppcb, (char *)&tcpcb, sizeof(struct tcpcb));
-	nnew->state = StateMap[tcpcb.t_state];
+	nnew->state = StateMap[0x0f & tcpcb.t_state];
         if (nnew->state == 5 /* established */ ||
             nnew->state == 8 /*  closeWait  */ )
             tcp_estab++;
@@ -808,11 +824,6 @@
     struct tcpcb   tcpcb;
     netsnmp_inpcb  *nnew;
     struct inpcb   *entry;
-#ifdef hpux
-    int      StateMap[] = { 1, 2, 3, -1, 4, 5, 8, 6, 10, 9, 7, 11 };
-#else
-    int      StateMap[] = { 1, 2, 3,     4, 5, 8, 6, 10, 9, 7, 11 };
-#endif
 
     tcpTable_free(NULL, NULL);
 
@@ -832,7 +843,7 @@
             break;
         klookup((unsigned long) entry, (char *)&(nnew->pcb), sizeof(struct inpcb));
         klookup((int) nnew->pcb.inp_ppcb, (char *)&tcpcb, sizeof(struct tcpcb));
-	nnew->state    = StateMap[tcpcb.t_state];
+	nnew->state    = StateMap[0x0f & tcpcb.t_state];
         if (nnew->state == 5 /* established */ ||
             nnew->state == 8 /*  closeWait  */ )
             tcp_estab++;
diff -ur net-snmp/agent/mibgroup/mibII/udpTable.c net-snmp/agent/mibgroup/mibII/udpTable.c
--- net-snmp/agent/mibgroup/mibII/udpTable.c	Wed Apr  7 00:59:27 2004
+++ net-snmp/agent/mibgroup/mibII/udpTable.c	Wed Jun  2 13:14:30 2004
@@ -65,9 +68,16 @@
 #ifdef linux
 #define INP_NEXT_SYMBOL		inp_next
 #endif
-#define	UDPTABLE_ENTRY_TYPE	struct inpcb 
-#define	UDPTABLE_LOCALADDRESS	inp_laddr.s_addr 
-#define	UDPTABLE_LOCALPORT	inp_lport
+
+typedef struct netsnmp_inpcb_s netsnmp_inpcb;
+struct netsnmp_inpcb_s {
+    struct inpcb    pcb;
+    int             state;
+    netsnmp_inpcb  *inp_next;
+};
+#define	UDPTABLE_ENTRY_TYPE	netsnmp_inpcb 
+#define	UDPTABLE_LOCALADDRESS	pcb.inp_laddr.s_addr 
+#define	UDPTABLE_LOCALPORT	pcb.inp_lport
 #define	UDPTABLE_IS_LINKED_LIST
 
 #endif                          /* WIN32 */
@@ -583,7 +593,7 @@
     int      sname[] = { CTL_NET, PF_INET, IPPROTO_UDP, UDPCTL_PCBLIST };
     char     *udpcb_buf = NULL;
     struct xinpgen *xig = NULL;
-    struct inpcb   *nnew;
+    netsnmp_inpcb   *nnew;
 
     udpTable_free(NULL, NULL);
 
@@ -607,12 +617,12 @@
     xig = (struct xinpgen *) ((char *) xig + xig->xig_len);
 
     while (xig && (xig->xig_len > sizeof(struct xinpgen))) {
-        nnew = SNMP_MALLOC_TYPEDEF(struct inpcb);
+        nnew = SNMP_MALLOC_TYPEDEF(netsnmp_inpcb);
         if (!nnew)
             break;
-        memcpy(nnew, ((struct xinpcb *) xig)->xi_inp, sizeof(struct inpcb));
+        memcpy(nnew, &((struct xinpcb *) xig)->xi_inp, sizeof(struct inpcb));
 
-	nnew->next = udp_head;		/* XXX - ?? Check 'next' pointer */
+	nnew->inp_next = udp_head;
 	udp_head   = nnew;
         xig = (struct xinpgen *) ((char *) xig + xig->xig_len);
     }
