From 7093e779e6abcef332c2f7dbde0a340e5291918e Mon Sep 17 00:00:00 2001 From: Clint Adams Date: Mon, 10 Sep 2001 02:17:55 +0000 Subject: 15771: ztcp -t --- Src/Modules/tcp.c | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) (limited to 'Src/Modules') diff --git a/Src/Modules/tcp.c b/Src/Modules/tcp.c index e3bec75c5..884b2b25f 100644 --- a/Src/Modules/tcp.c +++ b/Src/Modules/tcp.c @@ -383,17 +383,20 @@ tcp_connect(Tcp_session sess, char *addrp, struct hostent *zhost, int d_port) static int bin_ztcp(char *nam, char **args, char *ops, int func) { - int herrno, err=1, destport, force=0, verbose=0, len; + int herrno, err=1, destport, force=0, verbose=0, test=0, len; char **addrp, *desthost, *localname, *remotename; struct hostent *zthost = NULL, *ztpeer = NULL; struct servent *srv; Tcp_session sess; if (ops['f']) - force=1; + force = 1; if (ops['v']) - verbose=1; + verbose = 1; + + if (ops['t']) + test = 1; if (ops['c']) { if (!args[0]) { @@ -428,7 +431,7 @@ bin_ztcp(char *nam, char **args, char *ops, int func) return 1; } - srv = getservbyname(args[0],"tcp"); + srv = getservbyname(args[0], "tcp"); if (srv) lport = srv->s_port; else @@ -509,6 +512,20 @@ bin_ztcp(char *nam, char **args, char *ops, int func) return 1; } + if(test) { + struct pollfd pfd; + int ret; + + pfd.fd = lfd; + pfd.events = POLLIN; + if((ret = poll(&pfd, 1, 0)) == 0) return 1; + else if (ret == -1) + { + zwarnnam(nam, "poll error: %e", NULL, errno); + return 1; + } + + } sess = zts_alloc(ZTCP_INBOUND); if ((rfd = accept(lfd, (struct sockaddr *)&sess->peer.in, &len)) == -1) @@ -613,7 +630,7 @@ bin_ztcp(char *nam, char **args, char *ops, int func) } static struct builtin bintab[] = { - BUILTIN("ztcp", 0, bin_ztcp, 0, 2, 0, "acflv", NULL), + BUILTIN("ztcp", 0, bin_ztcp, 0, 2, 0, "acfltv", NULL), }; /* The load/unload routines required by the zsh library interface */ -- cgit 1.4.1