mirror of
git://git.code.sf.net/p/zsh/code
synced 2025-09-07 11:41:16 +02:00
17253: ztcp -L gives parseable information on tcp session
This commit is contained in:
parent
4446df3dff
commit
69b570e28c
3 changed files with 78 additions and 10 deletions
|
@ -1,3 +1,8 @@
|
|||
2002-05-30 Peter Stephenson <pws@csr.com>
|
||||
|
||||
* 17253: Src/Modules/tcp.c, Doc/Zsh/mod_tcp.c: ztcp -l provides
|
||||
parseable information on sessions.
|
||||
|
||||
2002-05-29 Sven Wischnowsky <wischnow@zsh.org>
|
||||
|
||||
* 17252: Completion/Unix/Type/_path_files: fix for use of (z)
|
||||
|
|
|
@ -7,12 +7,60 @@ startitem()
|
|||
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()
|
||||
|
||||
|
|
|
@ -369,7 +369,6 @@ bin_ztcp(char *nam, char **args, char *ops, int func)
|
|||
dargs = args;
|
||||
|
||||
|
||||
|
||||
if (ops['c']) {
|
||||
if (!dargs[0]) {
|
||||
tcp_cleanup();
|
||||
|
@ -575,13 +574,29 @@ bin_ztcp(char *nam, char **args, char *ops, int func)
|
|||
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 @@ bin_ztcp(char *nam, char **args, char *ops, int func)
|
|||
}
|
||||
|
||||
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 */
|
||||
|
|
Loading…
Reference in a new issue