about summary refs log tree commit diff
diff options
context:
space:
mode:
authorClint Adams <clint@users.sourceforge.net>2001-09-10 02:17:55 +0000
committerClint Adams <clint@users.sourceforge.net>2001-09-10 02:17:55 +0000
commit7093e779e6abcef332c2f7dbde0a340e5291918e (patch)
tree64e8094f66b37ac44256fbad638eeaf270201f89
parent5eb6315b3e4a7583a86c45ba87f581e30c17e41c (diff)
downloadzsh-7093e779e6abcef332c2f7dbde0a340e5291918e.tar.gz
zsh-7093e779e6abcef332c2f7dbde0a340e5291918e.tar.xz
zsh-7093e779e6abcef332c2f7dbde0a340e5291918e.zip
15771: ztcp -t
-rw-r--r--ChangeLog7
-rw-r--r--Src/Modules/tcp.c27
2 files changed, 28 insertions, 6 deletions
diff --git a/ChangeLog b/ChangeLog
index 22e8c32d2..c50205193 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,11 @@
+2001-09-10  Clint Adams  <clint@zsh.org>
+
+	* 15771: Src/Modules/tcp.c:
+	add -t (test) for ztcp.
+
 2001-09-09  Clint Adams  <clint@zsh.org>
 
-	* 15769: Src/Modules/tcp.c, Src/Modules/tcp.h:
+	* 15770: Src/Modules/tcp.c, Src/Modules/tcp.h:
 	add -a (accept) for ztcp.
 
 	* 15768: Src/Modules/tcp.c:
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 */