zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <pws@csr.com>
To: zsh-workers@sunsite.dk (Zsh hackers list)
Subject: PATCH: ztcp -L
Date: Wed, 29 May 2002 16:16:48 +0100	[thread overview]
Message-ID: <2702.1022685408@csr.com> (raw)

Here's a tweak to ztcp to allow listing of sessions in a form which can
more easily be parsed automatically by `ztcp -L'.  Comments on the
format or the documentation (which I may have garbled) are welcome.

Index: Src/Modules/tcp.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Modules/tcp.c,v
retrieving revision 1.30
diff -u -r1.30 tcp.c
--- Src/Modules/tcp.c	29 May 2002 13:17:49 -0000	1.30
+++ Src/Modules/tcp.c	29 May 2002 15:14:24 -0000
@@ -369,7 +369,6 @@
 	dargs = args;
 
 
-    
     if (ops['c']) {
 	if (!dargs[0]) {
 	    tcp_cleanup();
@@ -575,13 +574,29 @@
 			remotename = ztpeer->h_name;
 		    else
 			remotename = ztrdup(inet_ntoa(sess->peer.in.sin_addr));
-		    printf("%s:%d %s %s:%d is on fd %d%s\n",
-			    localname, ntohs(sess->sock.in.sin_port),
-			    ((sess->flags & ZTCP_LISTEN) ? "-<" :
-			     ((sess->flags & ZTCP_INBOUND) ? "<-" : "->")),
-			    remotename, ntohs(sess->peer.in.sin_port),
-			    sess->fd,
-			    (sess->flags & ZTCP_ZFTP) ? " ZFTP" : "");
+		    if (ops['L']) {
+			int schar;
+			if (sess->flags & ZTCP_ZFTP)
+			    schar = 'Z';
+			else if (sess->flags & ZTCP_LISTEN)
+			    schar = 'L';
+			else if (sess->flags & ZTCP_INBOUND)
+			    schar = 'I';
+			else
+			    schar = 'O';
+			printf("%d %c %s %d %s %d\n",
+			       sess->fd, schar,
+			       localname, ntohs(sess->sock.in.sin_port),
+			       remotename, ntohs(sess->peer.in.sin_port));
+		    } else {
+			printf("%s:%d %s %s:%d is on fd %d%s\n",
+			       localname, ntohs(sess->sock.in.sin_port),
+			       ((sess->flags & ZTCP_LISTEN) ? "-<" :
+				((sess->flags & ZTCP_INBOUND) ? "<-" : "->")),
+			       remotename, ntohs(sess->peer.in.sin_port),
+			       sess->fd,
+			       (sess->flags & ZTCP_ZFTP) ? " ZFTP" : "");
+		    }
 		}
 	    }
 	    return 0;
@@ -660,7 +675,7 @@
 }
 
 static struct builtin bintab[] = {
-    BUILTIN("ztcp", 0, bin_ztcp, 0, 3, 0, "acdfltv", NULL),
+    BUILTIN("ztcp", 0, bin_ztcp, 0, 3, 0, "acdflLtv", NULL),
 };
 
 /* The load/unload routines required by the zsh library interface */
Index: Doc/Zsh/mod_tcp.yo
===================================================================
RCS file: /cvsroot/zsh/zsh/Doc/Zsh/mod_tcp.yo,v
retrieving revision 1.2
diff -u -r1.2 mod_tcp.yo
--- Doc/Zsh/mod_tcp.yo	21 May 2002 13:12:52 -0000	1.2
+++ Doc/Zsh/mod_tcp.yo	29 May 2002 15:14:24 -0000
@@ -7,12 +7,60 @@
 findex(ztcp)
 cindex(TCP)
 cindex(sockets, TCP)
-item(tt(ztcp) [ tt(-acdfltv) ] [ var(args) ])(
+item(tt(ztcp) [ tt(-acdflLtv) ] [ var(args) ])(
 tt(ztcp) is implemented as a builtin to allow full use of shell
 command line editing, file I/O, and job control mechanisms.
 
 If tt(ztcp) is run with no options, it will output
 the contents of its session table.
+
+If it is run with only the option tt(-L), it will output the contents of
+the session table in a format suitable for automatic parsing.  The option
+is ignored if given with a command to open or close a session.  The output
+consists of a set of lines, one per session, each containing the following
+elements separated by spaces:
+
+startitem()
+item(File descriptor)(
+The file descriptor in use for the connection.  For normal inbound (tt(I))
+and outbound (tt(O)) connections this may be read and written by the usual
+shell mechanisms.  However, it should only be close with `tt(ztcp -c)'.
+)
+item(Connection type)(
+A letter indicating how the session was created:
+
+startitem()
+item(tt(Z))(
+A session created with the tt(zftp) command.
+)
+item(tt(L))(
+A connection opened for listening with `tt(ztcp -l)'.
+)
+item(tt(I))(
+An inbound connection accepted with `tt(ztcp -a)'.
+)
+item(tt(O))(
+An outbound connection created with `tt(ztcp) var(host) var(...)'.
+)
+enditem()
+
+)
+item(The local host)(
+This is usually set to an all-zero IP address as the address of the
+localhost is irrelevant.
+)
+item(The local port)(
+This is likely to be zero unless the connection is for listening.
+)
+item(The remote host)(
+This is the fully qualified domain name of the peer, if available, else an
+IP address.  It is an all-zero IP adress for a session opened for
+listening.
+)
+item(The remote port)(
+This is zero for a connection opened for listening.
+)
+enditem()
 )
 enditem()
 

-- 
Peter Stephenson <pws@csr.com>                  Software Engineer
CSR Ltd., Science Park, Milton Road,
Cambridge, CB4 0WH, UK                          Tel: +44 (0)1223 392070


**********************************************************************
The information transmitted is intended only for the person or
entity to which it is addressed and may contain confidential 
and/or privileged material. 
Any review, retransmission, dissemination or other use of, or
taking of any action in reliance upon, this information by 
persons or entities other than the intended recipient is 
prohibited.  
If you received this in error, please contact the sender and 
delete the material from any computer.
**********************************************************************


             reply	other threads:[~2002-05-29 15:17 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-05-29 15:16 Peter Stephenson [this message]
  -- strict thread matches above, loose matches on Subject: below --
2001-09-09  9:36 PATCH: ztcp -l Clint Adams

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=2702.1022685408@csr.com \
    --to=pws@csr.com \
    --cc=zsh-workers@sunsite.dk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).