mirror of
git://git.code.sf.net/p/zsh/code
synced 2025-10-27 04:40:59 +01:00
14863: tcp_connect
This commit is contained in:
parent
c26704f7a3
commit
f6ae716fb8
3 changed files with 38 additions and 16 deletions
|
|
@ -1,3 +1,8 @@
|
|||
2001-06-12 Clint Adams <clint@zsh.org>
|
||||
|
||||
* 14863: Src/Modules/tcp.c, Src/Modules/zftp.c:
|
||||
introduce tcp_connect.
|
||||
|
||||
2001-06-12 Peter Stephenson <pws@csr.com>
|
||||
|
||||
* 14858: Doc/Zsh/options.yo, Src/options.c, Src/subst.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 */
|
||||
|
|
|
|||
|
|
@ -1764,6 +1764,8 @@ zftp_open(char *name, char **args, int flags)
|
|||
/* should use herror() here if available, but maybe
|
||||
* needs configure test. on AIX it's present but not
|
||||
* in headers.
|
||||
*
|
||||
* on the other hand, herror() is obsolete
|
||||
*/
|
||||
FAILED();
|
||||
zwarnnam(name, "host not found: %s", args[0], 0);
|
||||
|
|
@ -1775,16 +1777,10 @@ zftp_open(char *name, char **args, int flags)
|
|||
zfsess->control.peer.a.sa_family = af;
|
||||
#ifdef SUPPORT_IPV6
|
||||
if(af == AF_INET6) {
|
||||
zfsess->control.peer.in6.sin6_port = zservp->s_port;
|
||||
zfsess->control.peer.in6.sin6_flowinfo = 0;
|
||||
# ifdef HAVE_STRUCT_SOCKADDR_IN6_SIN6_SCOPE_ID
|
||||
zfsess->control.peer.in6.sin6_scope_id = 0;
|
||||
# endif
|
||||
salen = sizeof(struct sockaddr_in6);
|
||||
} else
|
||||
#endif /* SUPPORT_IPV6 */
|
||||
{
|
||||
zfsess->control.peer.in.sin_port = zservp->s_port;
|
||||
salen = sizeof(struct sockaddr_in);
|
||||
}
|
||||
|
||||
|
|
@ -1809,15 +1805,10 @@ zftp_open(char *name, char **args, int flags)
|
|||
|
||||
/* try all possible IP's */
|
||||
for (addrp = zhostp->h_addr_list; err && *addrp; addrp++) {
|
||||
#ifdef SUPPORT_IPV6
|
||||
if(af == AF_INET6)
|
||||
memcpy(&zfsess->control.peer.in6.sin6_addr, *addrp, zhostp->h_length);
|
||||
else
|
||||
#endif /* SUPPORT_IPV6 */
|
||||
memcpy(&zfsess->control.peer.in.sin_addr, *addrp, zhostp->h_length);
|
||||
if(salen != zhostp->h_length)
|
||||
zwarnnam(name, "address length mismatch", NULL, 0);
|
||||
do {
|
||||
err = connect(zfsess->control.fd, (struct sockaddr *)&zfsess->control.peer,
|
||||
salen);
|
||||
err = tcp_connect(&(zfsess->control), *addrp, zhostp, zservp->s_port);
|
||||
} while (err && errno == EINTR && !errflag);
|
||||
/* you can check whether it's worth retrying here */
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue