$NetBSD: patch-ag,v 1.1.1.1 1999/09/22 21:11:39 kim Exp $ --- agent/mibgroup/mibII/tcp.c.orig Wed Aug 18 12:30:37 1999 +++ agent/mibgroup/mibII/tcp.c Wed Sep 22 17:04:19 1999 @@ -850,62 +850,16 @@ int TCP_Count_Connections (void) { - int Established; - struct inpcb cb; - register struct inpcb *next; -#if !(defined(freebsd2) || defined(netbsd2) || defined(openbsd2)) - register struct inpcb *prev; -#endif - struct inpcb inpcb; - struct tcpcb tcpcb; + int i, Established, State; + static struct inpcb inpcb; -Again: /* - * Prepare to scan the control blocks - */ - Established = 0; - - auto_nlist(TCP_SYMBOL, (char *)&cb, sizeof(struct inpcb)); - inpcb = cb; -#if !(defined(freebsd2) || defined(netbsd1) || defined(openbsd2)) - prev = (struct inpcb *) auto_nlist_value(TCP_SYMBOL); -#endif /* !(defined(freebsd2) || defined(netbsd1) || defined(openbsd2)) */ - /* - * Scan the control blocks - */ -#if defined(freebsd2) || defined(netbsd1) || defined(openbsd2) - while ((inpcb.INP_NEXT_SYMBOL != NULL) && (inpcb.INP_NEXT_SYMBOL != (struct inpcb *) auto_nlist_value(TCP_SYMBOL))) { -#else /* defined(freebsd2) || defined(netbsd1) || defined(openbsd2) */ - while (inpcb.INP_NEXT_SYMBOL != (struct inpcb *) auto_nlist_value(TCP_SYMBOL)) { -#endif /* defined(freebsd2) || defined(netbsd1) */ - next = inpcb.INP_NEXT_SYMBOL; - - if((klookup((unsigned long)next, (char *)&inpcb, sizeof (inpcb)) == 0)) { - snmp_log_perror("TCP_Count_Connections - inpcb"); - break; - } -#if !(defined(freebsd2) || defined(netbsd1) || defined(openbsd2)) - if (inpcb.INP_PREV_SYMBOL != prev) { /* ??? */ - sleep(1); - goto Again; - } -#endif /* !(defined(freebsd2) || defined(netbsd1) || defined(openbsd2)) */ - if (inet_lnaof(inpcb.inp_laddr) == INADDR_ANY) { -#if !(defined(freebsd2) || defined(netbsd1) || defined(openbsd2)) - prev = next; -#endif /* !(defined(freebsd2) || defined(netbsd1) || defined(openbsd2)) */ - continue; - } - if(klookup((unsigned long)inpcb.inp_ppcb, (char *)&tcpcb, sizeof (tcpcb)) == 0) { - snmp_log_perror("TCP_Count_Connections - tcpcb"); - break; - } - - if ((tcpcb.t_state == TCPS_ESTABLISHED) || - (tcpcb.t_state == TCPS_CLOSE_WAIT)) - Established++; -#if !(defined(freebsd2) || defined(netbsd1) || defined(openbsd2)) - prev = next; -#endif /* !(defined(freebsd2) || defined(netbsd1) || defined(openbsd2)) */ +Again: + TCP_Scan_Init; + for (;;) { + if ((i = TCP_Scan_Next(&State, &inpcb)) < 0) goto Again; + if (i == 0) break; /* Done */ + if ((State == TCPS_ESTABLISHED) || (State == TCPS_CLOSE_WAIT)) + Established++; } return(Established); }