diff options
author | Bernd Eckenfels <net-tools@lina.inka.de> | 2000-10-08 01:00:43 +0000 |
---|---|---|
committer | Bernd Eckenfels <net-tools@lina.inka.de> | 2000-10-08 01:00:43 +0000 |
commit | 0ab61b2ab82fae94036968ab09a7a585653f8779 (patch) | |
tree | ecd62716b537dc4bdb25ad6c308ce3c4f4933247 | |
parent | fix from bug#9215 in bugzilla@redhat (ifconfig sl0 mtu 1440 works now) (diff) | |
download | net-tools-0ab61b2ab82fae94036968ab09a7a585653f8779.tar.gz net-tools-0ab61b2ab82fae94036968ab09a7a585653f8779.tar.bz2 net-tools-0ab61b2ab82fae94036968ab09a7a585653f8779.zip |
feature from the guys at RedHat for more selective "-n" option:
-numeric-host, -numeric-port, -numeric-user. Send to me by Jeff Johnson
and reported by jik@kamens.brookline.ma.us
-rw-r--r-- | lib/inet6_gr.c | 2 | ||||
-rw-r--r-- | lib/inet_gr.c | 4 | ||||
-rw-r--r-- | lib/ipx_gr.c | 2 | ||||
-rw-r--r-- | lib/masq_info.c | 19 | ||||
-rw-r--r-- | lib/net-support.h | 19 | ||||
-rw-r--r-- | lib/netrom_gr.c | 4 | ||||
-rw-r--r-- | man/en_US/netstat.8 | 15 | ||||
-rw-r--r-- | netstat.c | 46 |
8 files changed, 77 insertions, 34 deletions
diff --git a/lib/inet6_gr.c b/lib/inet6_gr.c index 6b6bbf8..6573055 100644 --- a/lib/inet6_gr.c +++ b/lib/inet6_gr.c @@ -259,7 +259,7 @@ int rprint_cache6(int ext, int numeric) int INET6_rprint(int options) { int ext = options & FLAG_EXT; - int numeric = options & (FLAG_NUM | FLAG_SYM); + int numeric = options & (FLAG_NUM_HOST | FLAG_SYM); int rc = E_INTERN; if (options & FLAG_FIB) diff --git a/lib/inet_gr.c b/lib/inet_gr.c index 5b7a22a..d1e5efc 100644 --- a/lib/inet_gr.c +++ b/lib/inet_gr.c @@ -1,5 +1,5 @@ /* - $Id: inet_gr.c,v 1.12 1999/12/11 13:35:58 freitag Exp $ + $Id: inet_gr.c,v 1.13 2000/10/08 01:00:44 ecki Exp $ Modifications: 1998-07-01 - Arnaldo Carvalho de Melo - GNU gettext instead of catgets @@ -444,7 +444,7 @@ if (format == 2) { int INET_rprint(int options) { int ext = options & FLAG_EXT; - int numeric = options & (FLAG_NUM | FLAG_SYM); + int numeric = options & (FLAG_NUM_HOST | FLAG_SYM); int rc = E_INTERN; if (options & FLAG_FIB) diff --git a/lib/ipx_gr.c b/lib/ipx_gr.c index b0a740d..3d7ef1d 100644 --- a/lib/ipx_gr.c +++ b/lib/ipx_gr.c @@ -33,7 +33,7 @@ int IPX_rprint(int options) { /* int ext = options & FLAG_EXT; */ - int numeric = options & FLAG_NUM; + int numeric = options & FLAG_NUM_HOST; char buff[1024]; char net[128], router_net[128]; char router_node[128]; diff --git a/lib/masq_info.c b/lib/masq_info.c index 41ad691..45ca689 100644 --- a/lib/masq_info.c +++ b/lib/masq_info.c @@ -6,7 +6,7 @@ * NET-3 Networking Distribution for the LINUX operating * system. (net-tools, net-drivers) * - * Version: $Id: masq_info.c,v 1.6 1999/06/12 23:04:19 philip Exp $ + * Version: $Id: masq_info.c,v 1.7 2000/10/08 01:00:44 ecki Exp $ * * Author: Bernd 'eckes' Eckenfels <net-tools@lina.inka.de> * Copyright 1999 Bernd Eckenfels, Germany @@ -57,7 +57,8 @@ struct masq { static struct aftype *ap; /* current address family */ static int has_pdelta; -static void print_masq(struct masq *ms, int numeric, int ext) +static void print_masq(struct masq *ms, int numeric_host, int numeric_port, + int ext) { unsigned long minutes, seconds, sec100s; @@ -77,12 +78,12 @@ static void print_masq(struct masq *ms, int numeric, int ext) printf("%10lu %5hd - ", ms->initseq, ms->delta); } - printf("%-20s ", ap->sprint((struct sockaddr *) &(ms->src), numeric)); - printf("%-20s ", ap->sprint((struct sockaddr *) &(ms->dst), numeric)); + printf("%-20s ", ap->sprint((struct sockaddr *) &(ms->src), numeric_host)); + printf("%-20s ", ap->sprint((struct sockaddr *) &(ms->dst), numeric_host)); - printf("%s -> ", get_sname(ms->sport, ms->proto, numeric)); - printf("%s", get_sname(ms->dport, ms->proto, numeric)); - printf(" (%s)\n", get_sname(ms->mport, ms->proto, numeric)); + printf("%s -> ", get_sname(ms->sport, ms->proto, numeric_port)); + printf("%s", get_sname(ms->dport, ms->proto, numeric_port)); + printf(" (%s)\n", get_sname(ms->mport, ms->proto, numeric_port)); } @@ -144,7 +145,7 @@ static int read_masqinfo(FILE * f, struct masq *mslist, int nmslist) } -int ip_masq_info(int numeric, int ext) +int ip_masq_info(int numeric_host, int numeric_port, int ext) { FILE *f; int i; @@ -204,7 +205,7 @@ int ip_masq_info(int numeric, int ext) break; } for (i = 0; i < ntotal; i++) - print_masq(&(mslist[i]), numeric, ext); + print_masq(&(mslist[i]), numeric_host, numeric_port, ext); if (mslist) free(mslist); diff --git a/lib/net-support.h b/lib/net-support.h index 32f29a3..568fe81 100644 --- a/lib/net-support.h +++ b/lib/net-support.h @@ -92,14 +92,17 @@ extern int activate_ld(const char *hwname, int fd); #define RTACTION_FLUSH 4 #define RTACTION_SHOW 5 -#define FLAG_EXT 3 /* AND-Mask */ -#define FLAG_NUM 4 -#define FLAG_SYM 8 -#define FLAG_CACHE 16 -#define FLAG_FIB 32 -#define FLAG_VERBOSE 64 - -extern int ip_masq_info(int numeric, int ext); +#define FLAG_EXT 3 /* AND-Mask */ +#define FLAG_NUM_HOST 4 +#define FLAG_NUM_PORT 8 +#define FLAG_NUM_USER 16 +#define FLAG_NUM (FLAG_NUM_HOST|FLAG_NUM_PORT|FLAG_NUM_USER) +#define FLAG_SYM 32 +#define FLAG_CACHE 64 +#define FLAG_FIB 128 +#define FLAG_VERBOSE 256 + +extern int ip_masq_info(int numeric_host, int numeric_port, int ext); extern int INET_rprint(int options); extern int INET6_rprint(int options); diff --git a/lib/netrom_gr.c b/lib/netrom_gr.c index 08a3e42..adf54b2 100644 --- a/lib/netrom_gr.c +++ b/lib/netrom_gr.c @@ -2,7 +2,7 @@ * lib/netrom_gr.c This file contains an implementation of the NET/ROM * route support functions. * - * Version: $Id: netrom_gr.c,v 1.4 1999/01/05 20:53:55 philip Exp $ + * Version: $Id: netrom_gr.c,v 1.5 2000/10/08 01:00:44 ecki Exp $ * * Author: Bernd Eckenfels, <ecki@lina.inka.de> * Copyright 1999 Bernd Eckenfels, Germany @@ -37,7 +37,7 @@ int NETROM_rprint(int options) char buffer[256]; int qual, n, w; /*int ext = options & FLAG_EXT; - int numeric = options & FLAG_NUM; */ + int numeric = options & FLAG_NUM_HOST; */ f1 = fopen(_PATH_PROCNET_NR_NODES, "r"); if (!f1) perror(_PATH_PROCNET_NR_NODES); diff --git a/man/en_US/netstat.8 b/man/en_US/netstat.8 index 2fd8cca..94a8710 100644 --- a/man/en_US/netstat.8 +++ b/man/en_US/netstat.8 @@ -23,6 +23,7 @@ netstat \- Print network connections, routing tables, interface statistics, masq .RB [ \-\-listening | \-l ] .RB [ \-\-all | \-a ] .RB [ \-\-numeric | \-n ] +.RB [ \-\-numeric-hosts ] [ \-\-numeric-ports ] [ \-\-numeric-ports ] .RB [ \-\-symbolic | \-N ] .RB [ \-\-extend | \-e [ \-\-extend | \-e] ] .RB [ \-\-timers | \-o ] @@ -36,6 +37,7 @@ netstat \- Print network connections, routing tables, interface statistics, masq .RB [ \-\-extend | \-e [ \-\-extend | \-e] ] .RB [ \-\-verbose | \-v ] .RB [ \-\-numeric | \-n ] +.RB [ \-\-numeric-hosts ] [ \-\-numeric-ports ] [ \-\-numeric-ports ] .RB [ \-\-continuous | \-c] .P .B netstat @@ -46,17 +48,20 @@ netstat \- Print network connections, routing tables, interface statistics, masq .RB [ \-\-verbose | \-v ] .RB [ \-\-program | \-p ] .RB [ \-\-numeric | \-n ] +.RB [ \-\-numeric-hosts ] [ \-\-numeric-ports ] [ \-\-numeric-ports ] .RB [ \-\-continuous | \-c] .P .B netstat .RB { \-\-groups | \-g } .RB [ \-\-numeric | \-n ] +.RB [ \-\-numeric-hosts ] [ \-\-numeric-ports ] [ \-\-numeric-ports ] .RB [ \-\-continuous | \-c] .P .B netstat .RB { \-\-masquerade | \-M } .RB [ \-\-extend | \-e ] .RB [ \-\-numeric | \-n ] +.RB [ \-\-numeric-hosts ] [ \-\-numeric-ports ] [ \-\-numeric-ports ] .RB [ \-\-continuous | \-c] .P .B netstat @@ -110,6 +115,16 @@ useful information about unconfigured address families. .SS "\-\-numeric , \-n" Show numerical addresses instead of trying to determine symbolic host, port or user names. +.SS "\-\-numeric-hosts" +shows numerical host addresses but does not affect the resolution of +port or user names. +.SS "\-\-numeric-ports" +shows numerical port numbers but does not affect the resolution of +host or user names. +.SS "\-\-numeric-users" +shows numerical user IDs but does not affect the resolution of host or +port names. + .SS "\-\-protocol=\fIfamily \fR, \fB\-A" Specifies the address families (perhaps better described as low level protocols) for which connections are to be shown. @@ -6,7 +6,7 @@ * NET-3 Networking Distribution for the LINUX operating * system. * - * Version: $Id: netstat.c,v 1.38 2000/05/28 15:19:15 pb Exp $ + * Version: $Id: netstat.c,v 1.39 2000/10/08 01:00:43 ecki Exp $ * * Authors: Fred Baumgarten, <dc6iq@insu1.etec.uni-karlsruhe.de> * Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org> @@ -525,7 +525,7 @@ static void finish_this_one(int uid, unsigned long inode, const char *timers) struct passwd *pw; if (flag_exp > 1) { - if (!flag_not && ((pw = getpwuid(uid)) != NULL)) + if (!(flag_not & FLAG_NUM_USER) && ((pw = getpwuid(uid)) != NULL)) printf("%-10s ", pw->pw_name); else printf("%-10d ", uid); @@ -763,14 +763,17 @@ static void tcp_do_one(int lnr, const char *line) 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)); + snprintf(buffer, sizeof(buffer), "%s", + get_sname(htons(local_port), "tcp", + flag_not & FLAG_NUM_PORT)); if ((strlen(local_addr) + strlen(buffer)) > 22) local_addr[22 - strlen(buffer)] = '\0'; strcat(local_addr, ":"); strcat(local_addr, buffer); - snprintf(buffer, sizeof(buffer), "%s", get_sname(htons(rem_port), "tcp", flag_not)); + snprintf(buffer, sizeof(buffer), "%s", + get_sname(htons(rem_port), "tcp", flag_not & FLAG_NUM_PORT)); if ((strlen(rem_addr) + strlen(buffer)) > 22) rem_addr[22 - strlen(buffer)] = '\0'; @@ -911,13 +914,16 @@ static void udp_do_one(int lnr, const char *line) { safe_strncpy(local_addr, ap->sprint((struct sockaddr *) &localaddr, flag_not), sizeof(local_addr)); - snprintf(buffer, sizeof(buffer), "%s", get_sname(htons(local_port), "udp", flag_not)); + snprintf(buffer, sizeof(buffer), "%s", + get_sname(htons(local_port), "udp", + flag_not & FLAG_NUM_PORT)); if ((strlen(local_addr) + strlen(buffer)) > 22) local_addr[22 - strlen(buffer)] = '\0'; strcat(local_addr, ":"); strcat(local_addr, buffer); - snprintf(buffer, sizeof(buffer), "%s", get_sname(htons(rem_port), "udp", flag_not)); + snprintf(buffer, sizeof(buffer), "%s", + get_sname(htons(rem_port), "udp", flag_not & FLAG_NUM_PORT)); safe_strncpy(rem_addr, ap->sprint((struct sockaddr *) &remaddr, flag_not), sizeof(rem_addr)); if ((strlen(rem_addr) + strlen(buffer)) > 22) @@ -1025,7 +1031,9 @@ static void raw_do_one(int lnr, const char *line) if (flag_all || (notnull(remaddr) && !flag_lst) || (!notnull(remaddr) && flag_lst)) { - snprintf(buffer, sizeof(buffer), "%s", get_sname(htons(local_port), "raw", flag_not)); + snprintf(buffer, sizeof(buffer), "%s", + get_sname(htons(local_port), "raw", + flag_not & FLAG_NUM_PORT)); safe_strncpy(local_addr, ap->sprint((struct sockaddr *) &localaddr, flag_not), sizeof(local_addr)); if ((strlen(local_addr) + strlen(buffer)) > 22) @@ -1033,7 +1041,8 @@ static void raw_do_one(int lnr, const char *line) strcat(local_addr, ":"); strcat(local_addr, buffer); - snprintf(buffer, sizeof(buffer), "%s", get_sname(htons(rem_port), "raw", flag_not)); + snprintf(buffer, sizeof(buffer), "%s", + get_sname(htons(rem_port), "raw", flag_not & FLAG_NUM_PORT)); safe_strncpy(rem_addr, ap->sprint((struct sockaddr *) &remaddr, flag_not), sizeof(rem_addr)); if ((strlen(rem_addr) + strlen(buffer)) > 22) @@ -1412,7 +1421,7 @@ static int ipx_info(void) printf("IPX %6ld %6ld %-26s %-26s %-5s", txq, rxq, sad, dad, st); if (flag_exp > 1) { - if (!flag_not && ((pw = getpwuid(uid)) != NULL)) + if (!(flag_not & FLAG_NUM_USER) && ((pw = getpwuid(uid)) != NULL)) printf(" %-10s", pw->pw_name); else printf(" %-10d", uid); @@ -1475,6 +1484,9 @@ static void usage(void) #endif fprintf(stderr, _(" -v, --verbose be verbose\n")); fprintf(stderr, _(" -n, --numeric dont resolve names\n")); + fprintf(stderr, _(" --numeric-hosts dont resolve host names\n")); + fprintf(stderr, _(" --numeric-ports dont resolve port names\n")); + fprintf(stderr, _(" --numeric-users dont resolve user names\n")); fprintf(stderr, _(" -N, --symbolic resolve hardware names\n")); fprintf(stderr, _(" -e, --extend display other/more information\n")); fprintf(stderr, _(" -p, --programs display PID/Program name for sockets\n")); @@ -1521,6 +1533,9 @@ int main {"verbose", 0, 0, 'v'}, {"statistics", 0, 0, 's'}, {"numeric", 0, 0, 'n'}, + {"numeric-hosts", 0, 0, '!'}, + {"numeric-ports", 0, 0, '@'}, + {"numeric-users", 0, 0, '#'}, {"symbolic", 0, 0, 'N'}, {"cache", 0, 0, 'C'}, {"fib", 0, 0, 'F'}, @@ -1579,10 +1594,18 @@ int main case 'i': flag_int++; break; - case 'n': flag_not |= FLAG_NUM; break; + case '!': + flag_not |= FLAG_NUM_HOST; + break; + case '@': + flag_not |= FLAG_NUM_PORT; + break; + case '#': + flag_not |= FLAG_NUM_USER; + break; case 'N': flag_not |= FLAG_SYM; break; @@ -1645,7 +1668,8 @@ int main strcpy(afname, DFLT_AF); #endif for (;;) { - i = ip_masq_info(flag_not, flag_exp); + i = ip_masq_info(flag_not & FLAG_NUM_HOST, + flag_not & FLAG_NUM_PORT, flag_exp); if (i || !flag_cnt) break; sleep(1); |