diff options
author | Aris Adamantiadis <aris@0xbadc0de.be> | 2006-12-15 12:02:05 +0000 |
---|---|---|
committer | Aris Adamantiadis <aris@0xbadc0de.be> | 2006-12-15 12:02:05 +0000 |
commit | ef5113cc5761d7364b77bc5572031c5ac91fcd54 (patch) | |
tree | 6e9b72f3b8bab4d5f07accd80bcc1968ca3d1745 | |
parent | 1c1e5de2c65e65718a0f7aa69f882285c2881638 (diff) | |
download | libssh-ef5113cc5761d7364b77bc5572031c5ac91fcd54.tar.gz libssh-ef5113cc5761d7364b77bc5572031c5ac91fcd54.tar.xz libssh-ef5113cc5761d7364b77bc5572031c5ac91fcd54.zip |
-rc release
Ipv6 patch from Laurent Bigonville. When the ipv6 targets are
unreachable, it tries all possible targets from the getaddrinfo list.
Norbert: does it break anything ? it works for me but I didn't test it
extensively
git-svn-id: svn+ssh://svn.berlios.de/svnroot/repos/libssh/trunk@99 7dcaeef0-15fb-0310-b436-a5af3365683c
-rw-r--r-- | AUTHORS | 2 | ||||
-rw-r--r-- | Doxyfile | 2 | ||||
-rw-r--r-- | Makefile.in | 5 | ||||
-rw-r--r-- | configure.in | 2 | ||||
-rw-r--r-- | include/libssh/libssh.h | 2 | ||||
-rw-r--r-- | libssh/connect.c | 82 |
6 files changed, 56 insertions, 39 deletions
@@ -5,7 +5,7 @@ Nick Zitzmann <seiryu (at) comcast (dot) net> (mostly client SFTP stuff) Norbert Kiesel <nkiesel (at) tbdnetworks (dot) com> (getaddrinfo and other patches) -Jean-Philippe Garcia Ballester <giga (at) le-pec (dot) org> (Port to libgcrypt and configure.in voodoo) +Jean-Philippe Garcia Ballester <giga (at) le-pec (dot) org> (Port to libgcrypt and configure.in voodoo, debian packaging) Contributor(s): @@ -4,7 +4,7 @@ # Project related configuration options #--------------------------------------------------------------------------- PROJECT_NAME = libssh -PROJECT_NUMBER = 0.2-dev +PROJECT_NUMBER = 0.2rc OUTPUT_DIRECTORY = doxygen/ CREATE_SUBDIRS = NO OUTPUT_LANGUAGE = English diff --git a/Makefile.in b/Makefile.in index 8897a274..a3481e00 100644 --- a/Makefile.in +++ b/Makefile.in @@ -23,7 +23,7 @@ LN = @LN_S@ LIBTOOL = @LIBTOOL@ OBJECTS = sample.o samplesshd.o APPS = samplessh samplesftp samplesshd -VERSION = 0.2-dev +VERSION = 0.2rc DISTLIB = libssh-$(VERSION) CONFIG = include/libssh/config.h @@ -67,7 +67,8 @@ dist: include/libssh/ssh1.h include/libssh/ssh2.h \ include/libssh/server.h $(DISTLIB)/include/libssh/ cp *.c COPYING README AUTHORS CHANGELOG Doxyfile $(DISTLIB)/ - cp doc/* $(DISTLIB)/doc/ + #cp doc/* $(DISTLIB)/doc/ + #docs removed coz they are obsolete tar czf $(DISTLIB).tgz $(DISTLIB)/ .PHONY: doc diff --git a/configure.in b/configure.in index 60bfc597..adf02dd8 100644 --- a/configure.in +++ b/configure.in @@ -2,7 +2,7 @@ # Process this file with autoconf to produce a configure script. AC_PREREQ(2.57) -AC_INIT(libssh, 0.2-dev , aris@0xbadc0de.be) +AC_INIT(libssh, 0.2rc , aris@0xbadc0de.be) AC_CONFIG_SRCDIR([sample.c]) AC_CONFIG_HEADER([config.h]) diff --git a/include/libssh/libssh.h b/include/libssh/libssh.h index bf7877b6..c75b3574 100644 --- a/include/libssh/libssh.h +++ b/include/libssh/libssh.h @@ -24,7 +24,7 @@ MA 02111-1307, USA. */ #include <sys/select.h> /* for fd_set * */ #include <inttypes.h> -#define LIBSSH_VERSION "libssh-0.2-dev" +#define LIBSSH_VERSION "libssh-0.2rc" #ifdef __cplusplus extern "C" { diff --git a/libssh/connect.c b/libssh/connect.c index 44cb6a18..c797dc28 100644 --- a/libssh/connect.c +++ b/libssh/connect.c @@ -38,6 +38,10 @@ MA 02111-1307, USA. */ #error "Your system must have select()" #endif +#ifndef HAVE_GETADDRINFO +#error "Your system must have getaddrinfo()" +#endif + static void sock_set_nonblocking(int sock) { fcntl(sock,F_SETFL,O_NONBLOCK); } @@ -53,6 +57,7 @@ static int getai(const char *host, int port, struct addrinfo **ai) memset(&hints,0,sizeof(hints)); hints.ai_protocol=IPPROTO_TCP; + hints.ai_family=PF_UNSPEC; hints.ai_socktype=SOCK_STREAM; if(port==0){ hints.ai_flags=AI_PASSIVE; @@ -108,51 +113,62 @@ int ssh_connect_ai_timeout(SSH_SESSION *session, const char *host, int port, str int ssh_connect_host(SSH_SESSION *session, const char *host, const char *bind_addr, int port,long timeout, long usec){ - int s; + int s=-1; int my_errno; - struct addrinfo *ai; + struct addrinfo *ai, *ai2; my_errno=getai(host, port, &ai); if (my_errno){ - ssh_set_error(session,SSH_FATAL,"Failed to resolve hostname %s (%d)",host,my_errno); + ssh_set_error(session,SSH_FATAL,"Failed to resolve hostname %s (%s)",host,gai_strerror(my_errno)); return -1; } - /* create socket */ - s=socket(ai->ai_family,ai->ai_socktype,ai->ai_protocol); - if(s<0){ - ssh_set_error(session,SSH_FATAL,"socket : %s",strerror(errno)); - freeaddrinfo(ai); - return s; - } + for(ai2=ai;ai2!=NULL;ai2=ai2->ai_next){ + /* create socket */ + s=socket(ai2->ai_family,ai2->ai_socktype,ai2->ai_protocol); + if(s<0){ + ssh_set_error(session,SSH_FATAL,"socket : %s",strerror(errno)); + continue; + } - if(bind_addr){ - struct addrinfo *bind_ai; + if(bind_addr){ + struct addrinfo *bind_ai, *bind_ai2; - ssh_say(2,"resolving %s\n",bind_addr); - my_errno=getai(host,0,&bind_ai); - if (my_errno){ - ssh_set_error(session,SSH_FATAL,"Failed to resolve bind address %s (%d)",bind_addr,my_errno); - freeaddrinfo(ai); - return -1; - } + ssh_say(2,"resolving %s\n",bind_addr); + my_errno=getai(host,0,&bind_ai); + if (my_errno){ + ssh_set_error(session,SSH_FATAL,"Failed to resolve bind address %s (%s)",bind_addr,gai_strerror(my_errno)); + return -1; + } - if(bind(s,bind_ai->ai_addr,bind_ai->ai_addrlen)<0){ - ssh_set_error(session,SSH_FATAL,"Binding local address : %s",strerror(errno)); - freeaddrinfo(ai); - freeaddrinfo(bind_ai); + for(bind_ai2=bind_ai;bind_ai2!=NULL;bind_ai2=bind_ai2->ai_next){ + if(bind(s,bind_ai2->ai_addr,bind_ai2->ai_addrlen)<0){ + ssh_set_error(session,SSH_FATAL,"Binding local address : %s",strerror(errno)); + continue; + } + else{ + break; + } + } + freeaddrinfo(bind_ai); + if(bind_ai2==NULL){ /*cannot bind to any local addresses*/ + close(s); + s=-1; + continue; + } + } + if(timeout||usec){ + return ssh_connect_ai_timeout(session,host,port,ai2,timeout,usec,s); + } + if(connect(s,ai2->ai_addr,ai2->ai_addrlen)<0){ + ssh_set_error(session,SSH_FATAL,"connect: %s",strerror(errno)); close(s); - return -1; + s=-1; + continue; + } + else{ /*we are connected*/ + break; } - freeaddrinfo(bind_ai); - } - if(timeout||usec){ - return ssh_connect_ai_timeout(session,host,port,ai,timeout,usec,s); - } - if(connect(s,ai->ai_addr,ai->ai_addrlen)<0){ - ssh_set_error(session,SSH_FATAL,"connect: %s",strerror(errno)); - close(s); - s=-1; } freeaddrinfo(ai); return s; |