diff -urN bforce-0.22.9-v.orig/source/bforce/io_tcpip.c bforce-0.22.9-v/source/bforce/io_tcpip.c
--- bforce-0.22.9-v.orig/source/bforce/io_tcpip.c	2005-02-13 01:13:48.000000000 +0300
+++ bforce-0.22.9-v/source/bforce/io_tcpip.c	2012-01-23 16:32:25.000000000 +0400
@@ -34,91 +34,34 @@
 		log("terminating on signal %d", sig);
 }
 
-static int tcpip_connect2(struct sockaddr_in server)
+int tcpip_connect(const char *hostname, e_tcpmode tcpmode)
 {
+	int rc = 0;
 	int fd;
+	char *host;
+	int hostoffset = 0;
+	char *p;
+	const char *port = NULL;
 
-	DEB((D_INFO, "tcpip_connect2: trying \"%s\" at port %d",
-		inet_ntoa(server.sin_addr), (int)ntohs(server.sin_port)));
+	struct addrinfo hints =	{ .ai_family = PF_UNSPEC, .ai_socktype = SOCK_STREAM, .ai_protocol = IPPROTO_TCP };
+	struct addrinfo *ai, *aiHead;
 
-	if( (fd = socket(AF_INET, SOCK_STREAM, 0)) < 0 )
-	{
-		logerr("can't create socket");
-		return(1);
-	}
-	
-	/* make new fd == stdin if it isn't already */
-	if( fd > 0 )
-	{
-		(void)close(0);
-		if( dup(fd) != 0 )
-		{
-			logerr("cannot dup socket to stdin");
-			return(1);
-		}
-	}
-	
-	/* make stdout and stderr, too */
-	(void)close(1);
-	(void)close(2);
-	
-	if( dup(0) != 1 )
-	{
-		logerr("cannot dup stdin to stdout");
-		return(1);
-	}
-	if( dup(0) != 2 )
-	{
-		logerr("cannot dup stdin to stderr");
-		return(1);
-	}
-	
-	if( fd > 2 ) (void)close(fd);
-
-	/* switch off stdio buffering */
-	setbuf(stdin,  (char *)NULL);
-	setbuf(stdout, (char *)NULL);
-	setbuf(stderr, (char *)NULL);
-	
-	clearerr(stdin);
-	clearerr(stdout);
-	clearerr(stderr);
-	
-	if( connect(0, (struct sockaddr*)&server, sizeof(server)) == -1 )
-	{
-		logerr("can't connect to %s", inet_ntoa(server.sin_addr));
-		close(0);
-		close(1);
-		close(2);
-		return 1;
+	char *ipv6end = strchr (hostname, ']');
+    
+	if (ipv6end && *hostname == '[')
+	{
+		p = strchr (ipv6end, ':');
+		*ipv6end = 0;
+		hostoffset = 1;
 	}
+	else
+		p = strchr (hostname, ':');
 
-	if( tcpip_init() )
+	if (p)
 	{
-		tcpip_shutdown();
-		return 1;
+		*p = '\0';
+		port = p + 1;
 	}
-
-	log("TCP/IP connect to %s on port %d",
-		inet_ntoa(server.sin_addr), (int)ntohs(server.sin_port));
-	
-	return(0);
-}
-
-int tcpip_connect(const char *hostname, e_tcpmode tcpmode)
-{
-	int rc = 0;
-	struct hostent *he = NULL;
-	struct servent *se = NULL;
-	struct sockaddr_in server;
-	char *host = xstrcpy(hostname);
-	char *p = strrchr(host, ':');
-	const char *port = NULL;
-
-	server.sin_family = AF_INET;
-	
-	if( p )
-		{ *p++ = '\0'; port = p; }
 	else if( tcpmode == TCPMODE_BINKP )
 		port = "binkp";
 	else if( tcpmode == TCPMODE_TELNET )
@@ -126,45 +69,97 @@
 	else /* Default service name is "fido" */
 		port = "fido";
 
-	if( ISDEC(port) )
-		server.sin_port = htons(atoi(port));
-	else if( (se = getservbyname(port, "tcp")) )
-		server.sin_port = se->s_port;
-	else
-		{ log("invalid port or service name \"%s\"", port); rc = 1; }
-	
-	if( rc == 0 )
-	{
-		if( (he = gethostbyname(host)) )
-		{
-			memcpy(&server.sin_addr, he->h_addr, he->h_length);
-		}
-		else
-		{
-			rc = 1;
-			switch(h_errno) {
-			case HOST_NOT_FOUND:
-				log("host \"%s\" not found", host);
-				break;
-			case NO_ADDRESS:
-				log("no IP address found for host \"%s\"", host);
-				break;
-			case NO_RECOVERY:
-				log("non-recoverable name server error occured");
-				break;
-			case TRY_AGAIN:
-				log("temporary error occured on name server");
-				break;
-			default:
-				log("unknown error while resolving host \"%s\"", host);
-				break;
+	host = xstrcpy (hostname+=hostoffset);
+
+	rc = getaddrinfo(host, port, &hints, &aiHead);
+	if ( rc != 0 ) {
+		log("resolving error for %s: %s", host, gai_strerror(rc) );
+	} else {
+		for ( ai = aiHead; !tty_online && ai != NULL; ai = ai->ai_next ) {
+			char	hostbuf[MAXHOSTNAMELEN + 1];
+			char	servbuf[NI_MAXSERV + 1];
+			getnameinfo( ai->ai_addr, ai->ai_addrlen, hostbuf, sizeof(hostbuf), servbuf, sizeof(servbuf), NI_NUMERICHOST | NI_NUMERICSERV );
+	
+
+			DEB((D_INFO, "tcpip_connect: trying \"%s\" at port %s", hostbuf, servbuf));
+
+			if (( fd = socket( ai->ai_family, ai->ai_socktype, ai->ai_protocol)) < 0 ) {
+				log("can't create socket: %s", strerror( errno ));
+				continue;
+			}
+
+			/* make new fd == stdin if it isn't already */
+			if( fd > 0 )
+			{
+				(void)close(0);
+				if( dup(fd) != 0 )
+				{
+					logerr("cannot dup socket to stdin");
+					return(1);
+				}
+			}
+
+			/* make stdout and stderr, too */
+			(void)close(1);
+			(void)close(2);
+
+			if( dup(0) != 1 )
+			{
+				logerr("cannot dup stdin to stdout");
+				return(1);
+			}
+			if( dup(0) != 2 )
+			{
+				logerr("cannot dup stdin to stderr");
+				return(1);
 			}
+
+			if( fd > 2 ) (void)close(fd);
+
+			/* switch off stdio buffering */
+			setbuf(stdin,  (char *)NULL);
+			setbuf(stdout, (char *)NULL);
+			setbuf(stderr, (char *)NULL);
+
+			clearerr(stdin);
+			clearerr(stdout);
+			clearerr(stderr);
+
+			if ( connect( 0, ai->ai_addr, ai->ai_addrlen) < 0 ) {
+				log( "can't connect to %s:%s %s", hostbuf, servbuf, strerror( errno ));
+				close ( fd );
+				continue;
+			}
+
+			signal(SIGHUP,  tcpip_interrupt);
+			signal(SIGINT,  tcpip_interrupt);
+			signal(SIGTERM, tcpip_interrupt);
+			signal(SIGPIPE, tcpip_brokenpipe);
+
+			if( tcpip_init() )
+		    	{
+				tcpip_shutdown();
+				continue;
+			}
+
+			log("TCP/IP connect to %s on port %s", hostbuf, servbuf);
+
+			tty_online = TRUE;
 		}
+
+
 	}
 
+	freeaddrinfo(aiHead);
 	if( host ) { free(host); host = NULL; }
-	
-	return rc ? rc : tcpip_connect2(server);
+
+	if ( tty_online ) {
+		return 0;
+	} else {
+		log("Cannection for all addresses failed");
+	}
+
+	return(rc);
 }
 
 int tcpip_init(void)
@@ -173,7 +168,7 @@
 	int alive_arg = 1;
 	struct linger lingeropt;
 
-	tty_online = TRUE;
+	tty_online = FALSE;
 	tty_abort  = FALSE;
 	tty_hangup = FALSE;
 	tty_modem  = FALSE;
diff -urN bforce-0.22.9-v.orig/source/bforce/sess_answ.c bforce-0.22.9-v/source/bforce/sess_answ.c
--- bforce-0.22.9-v.orig/source/bforce/sess_answ.c	2005-02-21 17:16:44.000000000 +0300
+++ bforce-0.22.9-v/source/bforce/sess_answ.c	2012-01-23 15:27:41.000000000 +0400
@@ -22,10 +22,14 @@
 int answ_system(e_session type, char *connstr, int inetd)
 {
 	TIO oldtio;
-	struct sockaddr_in client;
+	struct sockaddr_storage client;
+	char ipaddress[MAXHOSTNAMELEN + 1];
+	char ipport[NI_MAXSERV + 1];
 	int clientlen = sizeof(client);
 	int rc = 0;
 	char *p;
+
+	
 	
 	init_state(&state);
 	state.session  = type;
@@ -81,8 +85,9 @@
 			logerr("can't get client address");
 		else
 		{
-			state.peername = (char*)xstrcpy(inet_ntoa(client.sin_addr));
-			state.peerport = (long)ntohs(client.sin_port);
+			getnameinfo( &client, clientlen, ipaddress, sizeof(ipaddress), ipport, sizeof(ipport), NI_NUMERICHOST | NI_NUMERICSERV );
+			state.peername = (char*)xstrcpy(ipaddress);
+			state.peerport = (char*)xstrcpy(ipport);
 		}
 	}
 	
@@ -95,9 +100,9 @@
 	}
 	else if( inetd && state.peername )
 	{
-		setproctitle("bforce answering, host %.32s:%ld",
+		setproctitle("bforce answering, host %.32s:%s",
 			string_printable(state.peername), state.peerport);
-		log("TCP/IP connect from %s on port %ld",
+		log("TCP/IP connect from %s on port %s",
 			string_printable(state.peername), state.peerport);
 	}
 	else
diff -urN bforce-0.22.9-v.orig/source/bforce/sess_call.c bforce-0.22.9-v/source/bforce/sess_call.c
--- bforce-0.22.9-v.orig/source/bforce/sess_call.c	2006-05-03 05:23:18.000000000 +0400
+++ bforce-0.22.9-v/source/bforce/sess_call.c	2012-01-23 15:27:50.000000000 +0400
@@ -191,7 +191,9 @@
 int call_system_quiet(const char *connstr, bool inet)
 {
 	TIO oldtio;
-	struct sockaddr_in client;
+	struct sockaddr_storage client;
+	char ipaddress [MAXHOSTNAMELEN + 1];
+	char ipport [NI_MAXSERV + 1];
 	int clientlen = sizeof(client);
 	int rc = 0;
 	char *p;
@@ -254,8 +256,9 @@
 			logerr("can't get client address");
 		else
 		{
-			state.peername = (char*)xstrcpy(inet_ntoa(client.sin_addr));
-			state.peerport = (long)ntohs(client.sin_port);
+			getnameinfo( &client, clientlen, ipaddress, sizeof(ipaddress), ipport, sizeof(ipport), NI_NUMERICHOST | NI_NUMERICSERV );
+			state.peername = (char*)xstrcpy(ipaddress);
+			state.peerport = (char*)xstrcpy(ipport);
 		}
 	}
 	
@@ -268,9 +271,9 @@
 	}
 	else if( inet && state.peername )
 	{
-		setproctitle("bforce outgoing, host %.32s:%ld",
+		setproctitle("bforce outgoing, host %.32s:%s",
 			string_printable(state.peername), state.peerport);
-		log("TCP/IP connect from %s on port %ld",
+		log("TCP/IP connect from %s on port %s",
 			string_printable(state.peername), state.peerport);
 	}
 	else
diff -urN bforce-0.22.9-v.orig/source/include/session.h bforce-0.22.9-v/source/include/session.h
--- bforce-0.22.9-v.orig/source/include/session.h	2004-12-30 19:01:02.000000000 +0300
+++ bforce-0.22.9-v/source/include/session.h	2012-01-23 16:37:16.000000000 +0400
@@ -144,7 +144,7 @@
 	long        minspeed;
 	char       *cidstr;        /* Caller Phone/ID when we are answering */
 	char       *peername;      /* Remote peer name than using TCP/IP */
-	long        peerport;      /* Remote port number, we are connected to */
+	char       *peerport;      /* Remote port number, we are connected to */
 	char       *connstr;
 	char       *inbound;       /* Inbound directory for this session */
 	char       *tinbound;      /* Temporary inbound for this session */
