about summary refs log tree commit diff
path: root/Src/Modules/tcp.c
diff options
context:
space:
mode:
authorClint Adams <clint@users.sourceforge.net>2001-06-12 15:57:25 +0000
committerClint Adams <clint@users.sourceforge.net>2001-06-12 15:57:25 +0000
commitf6ae716fb826abc0345263dc0ebb98df1cfdd05e (patch)
tree796cea48f6ad4b24136b130cc89652d9d5e6017a /Src/Modules/tcp.c
parentc26704f7a37f615820cebeacb763aa2748c290ec (diff)
downloadzsh-f6ae716fb826abc0345263dc0ebb98df1cfdd05e.tar.gz
zsh-f6ae716fb826abc0345263dc0ebb98df1cfdd05e.tar.xz
zsh-f6ae716fb826abc0345263dc0ebb98df1cfdd05e.zip
14863: tcp_connect
Diffstat (limited to 'Src/Modules/tcp.c')
-rw-r--r--Src/Modules/tcp.c30
1 files changed, 28 insertions, 2 deletions
diff --git a/Src/Modules/tcp.c b/Src/Modules/tcp.c
index 44a380170..6f7a05cb2 100644
--- a/Src/Modules/tcp.c
+++ b/Src/Modules/tcp.c
@@ -243,8 +243,34 @@ tcp_cleanup(void)
 mod_export int
 tcp_close(Tcp_session sess)
 {
-    close(sess->fd);
-    sess->fd = -1;
+    if(!close(sess->fd))
+    {
+	sess->fd = -1;
+	return 0;
+    }
+       else return -1;
+}
+
+/**/
+mod_export int
+tcp_connect(Tcp_session sess, char *addrp, struct hostent *zhost, int d_port)
+{
+#ifdef SUPPORT_IPV6
+    if(zhost->h_addrtype==AF_INET6) {
+	memcpy(&(sess->peer.in6.sin6_addr), addrp, zhost->h_length);
+	sess->peer.in6.sin6_port = d_port;
+	sess->peer.in6.sin6_flowinfo = 0;
+# ifdef HAVE_STRUCT_SOCKADDR_IN6_SIN6_SCOPE_ID
+	sess->peer.in6.sin6_scope_id = 0;
+# endif
+    } else
+#endif /* SUPPORT_IPV6 */
+    {
+	memcpy(&(sess->peer.in.sin_addr), addrp, zhost->h_length);
+	sess->peer.in.sin_port = d_port;
+    }
+
+    return connect(sess->fd, (struct sockaddr *)&(sess->peer), zhost->h_length);
 }
 
 /* The load/unload routines required by the zsh library interface */