Blob Blame History Raw
diff -up net-tools-1.60/man/en_US/netstat.8.trim net-tools-1.60/man/en_US/netstat.8
--- net-tools-1.60/man/en_US/netstat.8.trim	2011-08-24 13:56:54.303033055 +0200
+++ net-tools-1.60/man/en_US/netstat.8	2011-08-24 13:56:54.475030422 +0200
@@ -185,6 +185,10 @@ option, show interfaces that are not mar
 Print routing information from the FIB.  (This is the default.)
 .SS "\-C"
 Print routing information from the route cache.
+.SS "\-Z \-\-context"
+If SELinux enabled print SELinux context.
+.SS "\-T \-\-notrim"
+Stop trimming long addresses.
 .SS delay
 Netstat will cycle printing through statistics every 
 .B delay 
diff -up net-tools-1.60/netstat.c.trim net-tools-1.60/netstat.c
--- net-tools-1.60/netstat.c.trim	2011-08-24 13:56:54.472030469 +0200
+++ net-tools-1.60/netstat.c	2011-08-24 13:56:54.477030390 +0200
@@ -157,6 +157,9 @@ int flag_prg = 0;
 int flag_arg = 0;
 int flag_ver = 0;
 int flag_selinux = 0;
+int flag_trim = 0;
+
+
 
 FILE *procinfo;
 
@@ -983,16 +986,20 @@ static void tcp_do_one(int lnr, const ch
 		 get_sname(htons(local_port), "tcp",
 			   flag_not & FLAG_NUM_PORT));
 
-	if ((strlen(local_addr) + strlen(buffer)) >= 27)
-	    local_addr[27 - strlen(buffer) - 1] = '\0';
+	if (!flag_trim) {
+	    if ((strlen(local_addr) + strlen(buffer)) >= 27)
+		local_addr[27 - strlen(buffer) - 1] = '\0';
+	}
 
 	strcat(local_addr, ":");
 	strncat(local_addr, buffer, sizeof(local_addr)-strlen(local_addr)-1);
 	snprintf(buffer, sizeof(buffer), "%s",
 		 get_sname(htons(rem_port), "tcp", flag_not & FLAG_NUM_PORT));
-
-	if ((strlen(rem_addr) + strlen(buffer)) >= 27)
-	    rem_addr[27 - strlen(buffer) - 1] = '\0';
+	
+	if (!flag_trim) {
+	    if ((strlen(rem_addr) + strlen(buffer)) >= 27)
+		rem_addr[27 - strlen(buffer) - 1] = '\0';
+	}
 
 	strcat(rem_addr, ":");
 	strncat(rem_addr, buffer, sizeof(rem_addr)-strlen(rem_addr)-1);
@@ -1133,8 +1140,10 @@ static void udp_do_one(int lnr, const ch
 	snprintf(buffer, sizeof(buffer), "%s",
 		 get_sname(htons(local_port), "udp",
 			   flag_not & FLAG_NUM_PORT));
-	if ((strlen(local_addr) + strlen(buffer)) >= 27)
-	    local_addr[22 - strlen(buffer)] = '\0';
+	if (!flag_trim) {
+	    if ((strlen(local_addr) + strlen(buffer)) >= 27)
+		local_addr[27 - strlen(buffer)] = '\0';
+	}
 	strcat(local_addr, ":");
 	strncat(local_addr, buffer, sizeof(local_addr)-strlen(local_addr)-1);
 
@@ -1142,8 +1151,10 @@ static void udp_do_one(int lnr, const ch
 		 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)) >= 27)
-	    rem_addr[22 - strlen(buffer)] = '\0';
+	if (!flag_trim) {
+	    if ((strlen(rem_addr) + strlen(buffer)) >= 27)
+		rem_addr[27 - strlen(buffer) - 1] = '\0';
+	}
 	strcat(rem_addr, ":");
 	strncat(rem_addr, buffer, sizeof(rem_addr)-strlen(rem_addr)-1);
 
@@ -1252,8 +1263,10 @@ static void raw_do_one(int lnr, const ch
 			   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)) >= 27)
-	    local_addr[22 - strlen(buffer)] = '\0';
+	if (!flag_trim) {
+	    if ((strlen(local_addr) + strlen(buffer)) >= 27)
+		local_addr[27 - strlen(buffer)] = '\0';
+	}
 	strcat(local_addr, ":");
 	strncat(local_addr, buffer, sizeof(local_addr)-strlen(local_addr)-1);
 
@@ -1261,8 +1274,10 @@ static void raw_do_one(int lnr, const ch
 		 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)) >= 27)
-	    rem_addr[22 - strlen(buffer)] = '\0';
+	if (!flag_trim) {
+	    if ((strlen(rem_addr) + strlen(buffer)) >= 27)
+		rem_addr[27 - strlen(buffer) - 1] = '\0';
+	}
 	strcat(rem_addr, ":");
 	strncat(rem_addr, buffer, sizeof(rem_addr)-strlen(rem_addr)-1);
 
@@ -1723,7 +1738,8 @@ static void usage(void)
     fprintf(stderr, _("        -a, --all, --listening     display all sockets (default: connected)\n"));
     fprintf(stderr, _("        -o, --timers               display timers\n"));
     fprintf(stderr, _("        -F, --fib                  display Forwarding Information Base (default)\n"));
-    fprintf(stderr, _("        -C, --cache                display routing cache instead of FIB\n\n"));
+    fprintf(stderr, _("        -C, --cache                display routing cache instead of FIB\n"));
+    fprintf(stderr, _("        -T, --notrim               stop trimming long addresses\n"));
     fprintf(stderr, _("        -Z, --context              display SELinux security context for sockets\n\n"));
 
     fprintf(stderr, _("  <Iface>: Name of interface to monitor/list.\n"));
@@ -1773,6 +1789,7 @@ int main
 	{"fib", 0, 0, 'F'},
 	{"groups", 0, 0, 'g'},
 	{"context", 0, 0, 'Z'},
+	{"notrim", 0, 0, 'T'},
 	{NULL, 0, 0, 0}
     };
 
@@ -1785,7 +1802,7 @@ int main
 
     afname[0] = '\0';
 
-    while ((i = getopt_long(argc, argv, "MCFA:acdegphiI::nNorstuVv?wxlZ", longopts, &lop)) != EOF)
+    while ((i = getopt_long(argc, argv, "MCFA:acdegphiI::nNorstuVv?wxlZT", longopts, &lop)) != EOF)
 	switch (i) {
 	case -1:
 	    break;
@@ -1901,6 +1918,10 @@ int main
 	    usage();
 	case 's':
 	    flag_sta++;
+	    break;
+	case 'T':
+	    flag_trim++;
+	    break;
 	}
 
     if(argc == optind + 1) {