aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBernd Eckenfels <net-tools@lina.inka.de>2009-07-28 01:40:17 +0000
committerBernd Eckenfels <net-tools@lina.inka.de>2009-07-28 01:40:17 +0000
commit0540cf6522752f364f0aaae7900abc3a9ccf57f9 (patch)
tree7f1969018c8d65f795debe666355207b292376cc
parentscanf format length fix (non exploitable?) from (diff)
downloadnet-tools-0540cf6522752f364f0aaae7900abc3a9ccf57f9.tar.gz
net-tools-0540cf6522752f364f0aaae7900abc3a9ccf57f9.tar.bz2
net-tools-0540cf6522752f364f0aaae7900abc3a9ccf57f9.zip
Avoid name resolution for listening or established sockets (-l) by return
fast. Problem reported by Ragnar Hojland Espinosa <ragnar@ragnar-hojland.com>
-rw-r--r--netstat.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/netstat.c b/netstat.c
index 3085199..c50c58f 100644
--- a/netstat.c
+++ b/netstat.c
@@ -6,7 +6,7 @@
* NET-3 Networking Distribution for the LINUX operating
* system.
*
- * Version: $Id: netstat.c,v 1.63 2009/07/08 00:24:03 ecki Exp $
+ * Version: $Id: netstat.c,v 1.64 2009/07/28 01:40:17 ecki Exp $
*
* Authors: Fred Baumgarten, <dc6iq@insu1.etec.uni-karlsruhe.de>
* Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org>
@@ -727,6 +727,9 @@ static void tcp_do_one(int lnr, const char *line, const char *prot)
&d, local_addr, &local_port, rem_addr, &rem_port, &state,
&txq, &rxq, &timer_run, &time_len, &retr, &uid, &timeout, &inode, more);
+ if (!flag_all && ((flag_lst && rem_port) || (!flag_lst && !rem_port)))
+ return;
+
if (strlen(local_addr) > 8) {
#if HAVE_AFINET6
/* Demangle what the kernel gives us */
@@ -765,7 +768,7 @@ static void tcp_do_one(int lnr, const char *line, const char *prot)
flag_not), sizeof(local_addr));
safe_strncpy(rem_addr, ap->sprint((struct sockaddr *) &remaddr, flag_not),
sizeof(rem_addr));
- if (flag_all || (flag_lst && !rem_port) || (!flag_lst && rem_port)) {
+
snprintf(buffer, sizeof(buffer), "%s",
get_sname(htons(local_port), "tcp",
flag_not & FLAG_NUM_PORT));
@@ -819,7 +822,6 @@ static void tcp_do_one(int lnr, const char *line, const char *prot)
prot, rxq, txq, netmax(23,strlen(local_addr)), local_addr, netmax(23,strlen(rem_addr)), rem_addr, _(tcp_state[state]));
finish_this_one(uid,inode,timers);
- }
}
static int tcp_info(void)