Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!linus!decvax!ittvax!dcdwest!sdcsvax!sdcrdcf!hplabs!sri-unix!dpk@BRL-VGR.ARPA From: dpk@BRL-VGR.ARPA Newsgroups: net.unix-wizards Subject: Netstat is SLOW, 4.2BSD, Easy FIX Message-ID: <1570@sri-arpa.UUCP> Date: Tue, 3-Jul-84 22:32:53 EDT Article-I.D.: sri-arpa.1570 Posted: Tue Jul 3 22:32:53 1984 Date-Received: Sat, 14-Jul-84 13:46:01 EDT Lines: 44 From: Doug Kingston Index: ucb/netstat/inet.c 4.2BSD FIX Description: Depressed at how slow netstat was on the VAX after hashing the host tables, I profiled netstat and found that it was spending 90 percent of its time in inetname() and most of that in getnetent(). A look at the code revealed that it was ALWAYS trying to look up the net name for a net even when that net was INADDR_ANY (all zeros). After looking this up (and failing, since that is not a valid net), it checked for that case and copied "*" into a buffer and returned. Repeat-By: Run "time netstat -a". Sit and wait. Look at the large CPU time. Fix: The fix is to move the check for INADDR_ANY to the start of the inetname() function to catch this trivial case and prevent any expensive and fruitless lookups. A diff listing follows, although the line numbers will be offset due to a header we add to the file. The fix is simple. 312a316,319 > if (in.s_addr == INADDR_ANY) { /* A quick check for the easy case */ > strcpy(line, "*"); > return (line); > } 329,331c336 < if (in.s_addr == INADDR_ANY) < strcpy(line, "*"); < else if (cp) --- > if (cp) Yours for a better 4.2BSD, -Doug- Douglas P. Kingston III Advanced Computer Systems Team Ballistics Research Lab Attn: DRSMC-BLV-V (A) APG, Md. 21005 (301) 278-6651