From owner-freebsd-bugs@FreeBSD.ORG Fri May 20 11:10:03 2005 Return-Path: Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 2CD8016A4CE for ; Fri, 20 May 2005 11:10:03 +0000 (GMT) Received: from freefall.freebsd.org (freefall.freebsd.org [216.136.204.21]) by mx1.FreeBSD.org (Postfix) with ESMTP id ABB9B43D75 for ; Fri, 20 May 2005 11:10:02 +0000 (GMT) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.13.3/8.13.3) with ESMTP id j4KBA2mF023817 for ; Fri, 20 May 2005 11:10:02 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.13.3/8.13.1/Submit) id j4KBA2ZZ023816; Fri, 20 May 2005 11:10:02 GMT (envelope-from gnats) Resent-Date: Fri, 20 May 2005 11:10:02 GMT Resent-Message-Id: <200505201110.j4KBA2ZZ023816@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-bugs@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, Lolownia Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id AB41616A4CE for ; Fri, 20 May 2005 11:05:15 +0000 (GMT) Received: from www.freebsd.org (www.freebsd.org [216.136.204.117]) by mx1.FreeBSD.org (Postfix) with ESMTP id 7110A43D88 for ; Fri, 20 May 2005 11:05:15 +0000 (GMT) (envelope-from nobody@FreeBSD.org) Received: from www.freebsd.org (localhost [127.0.0.1]) by www.freebsd.org (8.13.1/8.13.1) with ESMTP id j4KB5E03006350 for ; Fri, 20 May 2005 11:05:14 GMT (envelope-from nobody@www.freebsd.org) Received: (from nobody@localhost) by www.freebsd.org (8.13.1/8.13.1/Submit) id j4KB5EB3006349; Fri, 20 May 2005 11:05:14 GMT (envelope-from nobody) Message-Id: <200505201105.j4KB5EB3006349@www.freebsd.org> Date: Fri, 20 May 2005 11:05:14 GMT From: Lolownia To: freebsd-gnats-submit@FreeBSD.org X-Send-Pr-Version: www-2.3 Subject: bin/81300: [PATCH] add option to sockstat(1) to always separate X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 20 May 2005 11:10:03 -0000 >Number: 81300 >Category: bin >Synopsis: [PATCH] add option to sockstat(1) to always separate >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: change-request >Submitter-Id: current-users >Arrival-Date: Fri May 20 11:10:02 GMT 2005 >Closed-Date: >Last-Modified: >Originator: Lolownia >Release: FreeBSD 5.2.1-RELEASE-p9 >Organization: DESK.pl >Environment: FreeBSD niobe.desk.pl 5.2.1-RELEASE-p9 FreeBSD 5.2.1-RELEASE-p9 #0: Mon Aug 9 14:20:31 CEST 2004 creep@niobe.desk.pl:/home/hate/src/sys/i386/compile/SAMSARA i386 >Description: If You use sockstat(1) and there are in its output users or program names longer then 8 and 10 chars respectively, the whitespace separating the fields disappears e.g. spinacz100BitchX-1.029557 5 tcp4 *:63322 *:* This makes sockstat(1) to be unreliable to use in scripts. >How-To-Repeat: Make a connection with credentials of user with name longer than 8 characters or with a program which name is longer then 10 characters. >Fix: Apply a patch: =============8<=================8<================= --- usr.bin/sockstat/sockstat.c.orig Fri May 20 12:58:28 2005 +++ usr.bin/sockstat/sockstat.c Fri May 20 12:59:00 2005 @@ -62,6 +62,7 @@ static int opt_4; /* Show IPv4 sockets */ static int opt_6; /* Show IPv6 sockets */ static int opt_c; /* Show connected sockets */ +static int opt_n; /* always display spaces */ static int opt_l; /* Show listening sockets */ static int opt_u; /* Show Unix domain sockets */ static int opt_v; /* Verbose mode */ @@ -487,6 +488,17 @@ return (0); } + +static int +padspace(int pos, int to) +{ + if (pos >= to && opt_n) + pos += xprintf(" "); + while (pos < to) + pos += xprintf(" "); + return (pos); +} + static void display(void) { @@ -516,30 +528,24 @@ pos += xprintf("%lu", (u_long)xf->xf_uid); else pos += xprintf("%s", pwd->pw_name); - while (pos < 9) - pos += xprintf(" "); + pos = padspace(pos,9); pos += xprintf("%.10s", getprocname(xf->xf_pid)); - while (pos < 20) - pos += xprintf(" "); + pos = padspace(pos,20); pos += xprintf("%lu", (u_long)xf->xf_pid); - while (pos < 26) - pos += xprintf(" "); + pos = padspace(pos,26); pos += xprintf("%d", xf->xf_fd); - while (pos < 29) - pos += xprintf(" "); + pos = padspace(pos,29); pos += xprintf("%s", s->protoname); if (s->vflag & INP_IPV4) pos += xprintf("4"); if (s->vflag & INP_IPV6) pos += xprintf("6"); - while (pos < 36) - pos += xprintf(" "); + pos = padspace(pos,36); switch (s->family) { case AF_INET: case AF_INET6: pos += printaddr(s->family, &s->laddr); - while (pos < 58) - pos += xprintf(" "); + pos = padspace(pos,58); pos += printaddr(s->family, &s->faddr); break; case AF_UNIX: @@ -577,7 +583,7 @@ static void usage(void) { - fprintf(stderr, "Usage: sockstat [-46clu] [-p ports]\n"); + fprintf(stderr, "Usage: sockstat [-46cnlu] [-p ports]\n"); exit(1); } @@ -586,7 +592,7 @@ { int o; - while ((o = getopt(argc, argv, "46clp:uv")) != -1) + while ((o = getopt(argc, argv, "46cnlp:uv")) != -1) switch (o) { case '4': opt_4 = 1; @@ -596,6 +602,9 @@ break; case 'c': opt_c = 1; + break; + case 'n': + opt_n = 1; break; case 'l': opt_l = 1; ===========8<====================8<====================== This adds option -n which makes sure there is a space separator in output. spinacz100 BitchX-1.0 29557 4 tcp4 81.219.11.27:63318 212.182.63.110:6667 >Release-Note: >Audit-Trail: >Unformatted: