1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
|
From b1c72a13d07b59fc67a7b338fa3969b96af7e67d Mon Sep 17 00:00:00 2001
From: Mike Frysinger <vapier@gentoo.org>
Date: Mon, 14 Apr 2008 00:47:37 -0400
Subject: [PATCH] comabug@gmail.com writes:
net-tools' netstat should have a -W flag like FreeBSD.
There is currently no way to get the full hostname from netstat
for local/remote hostnames.
http://bugs.gentoo.org/53731
---
man/en_US/netstat.8 | 3 +++
netstat.c | 20 +++++++++++++-------
2 files changed, 16 insertions(+), 7 deletions(-)
diff --git a/man/en_US/netstat.8 b/man/en_US/netstat.8
index e6be46b..9a3ff44 100644
--- a/man/en_US/netstat.8
+++ b/man/en_US/netstat.8
@@ -24,6 +24,7 @@ netstat \- Print network connections, routing tables, interface statistics, masq
.RB [ \-\-all | \-a ]
.RB [ \-\-numeric | \-n ]
.RB [ \-\-numeric-hosts "] [" \-\-numeric-ports "] [" \-\-numeric-users ]
+.RB [ \-\-wide | \-W]
.RB [ \-\-symbolic | \-N ]
.RB [ \-\-extend | \-e [ \-\-extend | \-e] ]
.RB [ \-\-timers | \-o ]
@@ -130,6 +131,8 @@ host or user names.
.SS "\-\-numeric-users"
shows numerical user IDs but does not affect the resolution of host or
port names.
+.SS "\-\-wide , \-W"
+Don't truncate host names.
.SS "\-\-protocol=\fIfamily \fR, \fB\-A"
Specifies the address families (perhaps better described as low level
diff --git a/netstat.c b/netstat.c
index 843c06b..78bf551 100644
--- a/netstat.c
+++ b/netstat.c
@@ -150,6 +150,7 @@ int flag_exp = 1;
int flag_prg = 0;
int flag_arg = 0;
int flag_ver = 0;
+int flag_wid = 0;
FILE *procinfo;
@@ -780,7 +781,7 @@ static void tcp_do_one(int lnr, const char *line)
get_sname(htons(local_port), "tcp",
flag_not & FLAG_NUM_PORT));
- if ((strlen(local_addr) + strlen(buffer)) > 22)
+ if (!flag_wid && ((strlen(local_addr) + strlen(buffer)) > 22))
local_addr[22 - strlen(buffer)] = '\0';
strcat(local_addr, ":");
@@ -789,7 +790,7 @@ static void tcp_do_one(int lnr, const char *line)
snprintf(buffer, sizeof(buffer), "%s",
get_sname(htons(rem_port), "tcp", flag_not & FLAG_NUM_PORT));
- if ((strlen(rem_addr) + strlen(buffer)) > 22)
+ if (!flag_wid && ((strlen(rem_addr) + strlen(buffer)) > 22))
rem_addr[22 - strlen(buffer)] = '\0';
strcat(rem_addr, ":");
@@ -935,7 +936,7 @@ static void udp_do_one(int lnr, const char *line)
snprintf(buffer, sizeof(buffer), "%s",
get_sname(htons(local_port), "udp",
flag_not & FLAG_NUM_PORT));
- if ((strlen(local_addr) + strlen(buffer)) > 22)
+ if (!flag_wid && ((strlen(local_addr) + strlen(buffer)) > 22))
local_addr[22 - strlen(buffer)] = '\0';
strcat(local_addr, ":");
strncat(local_addr, buffer, sizeof(local_addr));
@@ -945,7 +946,7 @@ static void udp_do_one(int lnr, const char *line)
get_sname(htons(rem_port), "udp", flag_not & FLAG_NUM_PORT));
safe_strncpy(rem_addr, ap->sprint((struct sockaddr *) &remaddr,
flag_not & FLAG_NUM_HOST), sizeof(rem_addr));
- if ((strlen(rem_addr) + strlen(buffer)) > 22)
+ if (!flag_wid && ((strlen(rem_addr) + strlen(buffer)) > 22))
rem_addr[22 - strlen(buffer)] = '\0';
strcat(rem_addr, ":");
strncat(rem_addr, buffer, sizeof(rem_addr));
@@ -1059,7 +1060,7 @@ static void raw_do_one(int lnr, const char *line)
flag_not & FLAG_NUM_PORT));
safe_strncpy(local_addr, ap->sprint((struct sockaddr *) &localaddr,
flag_not & FLAG_NUM_HOST), sizeof(local_addr));
- if ((strlen(local_addr) + strlen(buffer)) > 22)
+ if (!flag_wid && ((strlen(local_addr) + strlen(buffer)) > 22))
local_addr[22 - strlen(buffer)] = '\0';
strcat(local_addr, ":");
strncat(local_addr, buffer, sizeof(local_addr));
@@ -1069,7 +1070,7 @@ static void raw_do_one(int lnr, const char *line)
get_sname(htons(rem_port), "raw", flag_not & FLAG_NUM_PORT));
safe_strncpy(rem_addr, ap->sprint((struct sockaddr *) &remaddr,
flag_not & FLAG_NUM_HOST), sizeof(rem_addr));
- if ((strlen(rem_addr) + strlen(buffer)) > 22)
+ if (!flag_wid && ((strlen(rem_addr) + strlen(buffer)) > 22))
rem_addr[22 - strlen(buffer)] = '\0';
strcat(rem_addr, ":");
strncat(rem_addr, buffer, sizeof(rem_addr));
@@ -1531,6 +1532,7 @@ static void usage(void)
fprintf(stderr, _(" --numeric-hosts don't resolve host names\n"));
fprintf(stderr, _(" --numeric-ports don't resolve port names\n"));
fprintf(stderr, _(" --numeric-users don't resolve user names\n"));
+ fprintf(stderr, _(" -W, --wide don't truncate host 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"));
@@ -1580,6 +1582,7 @@ int main
{"numeric-hosts", 0, 0, '!'},
{"numeric-ports", 0, 0, '@'},
{"numeric-users", 0, 0, '#'},
+ {"wide", 0, 0, 'W'},
{"symbolic", 0, 0, 'N'},
{"cache", 0, 0, 'C'},
{"fib", 0, 0, 'F'},
@@ -1595,7 +1598,7 @@ int main
getroute_init(); /* Set up AF routing support */
afname[0] = '\0';
- while ((i = getopt_long(argc, argv, "MCFA:acdegphinNorstuVv?wxl64", longopts, &lop)) != EOF)
+ while ((i = getopt_long(argc, argv, "MCFA:acdegphinWNorstuVv?wxl64", longopts, &lop)) != EOF)
switch (i) {
case -1:
break;
@@ -1651,6 +1654,9 @@ int main
case '#':
flag_not |= FLAG_NUM_USER;
break;
+ case 'W':
+ flag_wid++;
+ break;
case 'N':
flag_not |= FLAG_SYM;
break;
--
1.5.5
|