Index: mplayer/libmpdemux/network.c
diff -u mplayer/libmpdemux/network.c:1.1.1.2 mplayer/libmpdemux/network.c:1.5
--- mplayer/libmpdemux/network.c:1.1.1.2	Mon Nov 25 08:59:14 2002
+++ mplayer/libmpdemux/network.c	Tue Jan  7 09:35:06 2003
@@ -152,82 +152,94 @@
 int
 connect2Server(char *host, int port) {
 	int socket_server_fd;
-	int err, err_len;
+	int err, err_len, error;
 	int ret,count = 0;
 	fd_set set;
 	struct timeval tv;
-	struct sockaddr_in server_address;
-	struct hostent *hp=NULL;
+	struct sockaddr_storage server_address;
+	struct addrinfo hints, *res, *res0;
+	char hbuf[NI_MAXHOST], sbuf[NI_MAXSERV];
 
-	socket_server_fd = socket(AF_INET, SOCK_STREAM, 0);
-	if( socket_server_fd==-1 ) {
-		mp_msg(MSGT_NETWORK,MSGL_ERR,"Failed to create socket\n");
+	memset(&hints, 0, sizeof(hints));
+	hints.ai_flags = AI_CANONNAME;
+	hints.ai_family = PF_UNSPEC;
+	hints.ai_socktype = SOCK_STREAM;
+	hints.ai_protocol = IPPROTO_TCP;
+	sprintf(sbuf, "%d\0", port);
+	mp_msg(MSGT_NETWORK,MSGL_STATUS,"Resolving %s ...\n", host);
+	error = getaddrinfo(host, sbuf, &hints, &res0);
+	if (error) {
+		mp_msg(MSGT_NETWORK,MSGL_ERR,"Couldn't resolve name: %s\n", host);
 		return -2;
 	}
 
-	if( isalpha(host[0]) ) {
-		mp_msg(MSGT_NETWORK,MSGL_STATUS,"Resolving %s ...\n", host );
-		hp=(struct hostent*)gethostbyname( host );
-		if( hp==NULL ) {
-			mp_msg(MSGT_NETWORK,MSGL_ERR,"Counldn't resolve name: %s\n", host);
-			return -2;
-		}
-		memcpy( (void*)&server_address.sin_addr.s_addr, (void*)hp->h_addr, hp->h_length );
-	} else {
-		inet_pton(AF_INET, host, &server_address.sin_addr);
-	}
-	server_address.sin_family=AF_INET;
-	server_address.sin_port=htons(port);
-	
-	// Turn the socket as non blocking so we can timeout on the connection
-	if( isalpha(host[0]) && hp!=NULL ) {
-		mp_msg(MSGT_NETWORK,MSGL_STATUS,"Connecting to server %s[%d.%d.%d.%d]:%d ...\n", host, (hp->h_addr_list[0][0])&0xff, (hp->h_addr_list[0][1])&0xff, (hp->h_addr_list[0][2])&0xff, (hp->h_addr_list[0][3])&0xff, port );
-	} else {
-		mp_msg(MSGT_NETWORK,MSGL_STATUS,"Connecting to server %s:%d ...\n", host, port );
-	}
-	fcntl( socket_server_fd, F_SETFL, fcntl(socket_server_fd, F_GETFL) | O_NONBLOCK );
-	if( connect( socket_server_fd, (struct sockaddr*)&server_address, sizeof(server_address) )==-1 ) {
-		if( errno!=EINPROGRESS ) {
-			mp_msg(MSGT_NETWORK,MSGL_ERR,"Failed to connect to server\n");
-			close(socket_server_fd);
-			return -1;
+	for( res = res0; res; res = res->ai_next ) {
+		socket_server_fd = socket(res->ai_family, SOCK_STREAM, 0);
+		if( socket_server_fd==-1 ) {
+			mp_msg(MSGT_NETWORK,MSGL_ERR,"Failed to create socket. Try next\n");
+			continue;
+		}
+		memcpy( (void*)&server_address, (void*)res->ai_addr, res->ai_addrlen );
+		if(!getnameinfo(res->ai_addr, res->ai_addrlen, hbuf, sizeof(hbuf),
+		    sbuf, sizeof(sbuf), NI_NUMERICHOST | NI_NUMERICSERV)) {
+			mp_msg(MSGT_NETWORK,MSGL_STATUS,"Connecting to server %s[%s]:%s ...\n", host, hbuf, sbuf);
+		} else {
+			mp_msg(MSGT_NETWORK,MSGL_STATUS,"Connecting to server %s:%d ...\n", host, port);
 		}
-	}
-	tv.tv_sec = 0;
-	tv.tv_usec = 500000;
-	FD_ZERO( &set );
-	FD_SET( socket_server_fd, &set );
-	// When the connection will be made, we will have a writable fd
-	while((ret = select(socket_server_fd+1, NULL, &set, NULL, &tv)) == 0) {
-	      if( ret<0 ) mp_msg(MSGT_NETWORK,MSGL_ERR,"select failed\n");
-	      else if(ret > 0) break;
-	      else if(count > 30 || mp_input_check_interrupt(500)) {
-		if(count > 30)
-		  mp_msg(MSGT_NETWORK,MSGL_ERR,"Connection timeout\n");
-		else
-		  mp_msg(MSGT_NETWORK,MSGL_V,"Connection interuppted by user\n");
-		return -2;
-	      }
-	      count++;
-	      FD_ZERO( &set );
-	      FD_SET( socket_server_fd, &set );
-	      tv.tv_sec = 0;
-	      tv.tv_usec = 500000;
-	}
 
-	// Turn back the socket as blocking
-	fcntl( socket_server_fd, F_SETFL, fcntl(socket_server_fd, F_GETFL) & ~O_NONBLOCK );
-	// Check if there were any error
-	err_len = sizeof(int);
-	ret =  getsockopt(socket_server_fd,SOL_SOCKET,SO_ERROR,&err,&err_len);
-	if(ret < 0) {
-		mp_msg(MSGT_NETWORK,MSGL_ERR,"getsockopt failed : %s\n",strerror(errno));
-		return -2;
-	}
-	if(err > 0) {
-		mp_msg(MSGT_NETWORK,MSGL_ERR,"Connect error : %s\n",strerror(err));
-		return -1;
+		// Turn the socket as non blocking so we can timeout on the connection
+		fcntl( socket_server_fd, F_SETFL, fcntl(socket_server_fd, F_GETFL) | O_NONBLOCK );
+		if( connect( socket_server_fd, (struct sockaddr*)&server_address, res->ai_addrlen )==-1 ) {
+			if( errno!=EINPROGRESS ) {
+				mp_msg(MSGT_NETWORK,MSGL_ERR,"Failed to connect to server : %s\n", strerror(errno));
+				close(socket_server_fd);
+				socket_server_fd = -1;
+				continue;
+			}
+		}
+		tv.tv_sec = 0;
+		tv.tv_usec = 500000;
+		FD_ZERO( &set );
+		FD_SET( socket_server_fd, &set );
+		// When the connection will be made, we will have a writable fd
+		while((ret = select(socket_server_fd+1, NULL, &set, NULL, &tv)) == 0) {
+			if( ret<0 ) mp_msg(MSGT_NETWORK,MSGL_ERR,"select failed\n");
+			else if(ret > 0) break;
+			else if(count > 30 || mp_input_check_interrupt(500)) {
+				if(count > 30)
+					mp_msg(MSGT_NETWORK,MSGL_ERR,"Connection timeout\n");
+				else
+					mp_msg(MSGT_NETWORK,MSGL_V,"Connection interuppted by user\n");
+				freeaddrinfo(res0);
+				return -2;
+			}
+			count++;
+			FD_ZERO( &set );
+			FD_SET( socket_server_fd, &set );
+			tv.tv_sec = 0;
+			tv.tv_usec = 500000;
+		}
+
+		// Turn back the socket as blocking
+		fcntl( socket_server_fd, F_SETFL, fcntl(socket_server_fd, F_GETFL) & ~O_NONBLOCK );
+		// Check if there were any error
+		err_len = sizeof(int);
+		ret =  getsockopt(socket_server_fd,SOL_SOCKET,SO_ERROR,&err,&err_len);
+		if(ret < 0) {
+			mp_msg(MSGT_NETWORK,MSGL_ERR,"getsockopt failed : %s\n",strerror(errno));
+			close(socket_server_fd);
+			socket_server_fd = -1;
+			continue;
+		}
+		if(err > 0) {
+			mp_msg(MSGT_NETWORK,MSGL_ERR,"Connect error : %s\n",strerror(err));
+			close(socket_server_fd);
+			socket_server_fd = -1;
+			continue;
+		}
+		break;
 	}
+	freeaddrinfo(res0);
 	return socket_server_fd;
 }
 
Index: mplayer/libmpdemux/url.c
diff -u mplayer/libmpdemux/url.c:1.1.1.2 mplayer/libmpdemux/url.c:1.4
--- mplayer/libmpdemux/url.c:1.1.1.2	Mon Nov 25 08:59:16 2002
+++ mplayer/libmpdemux/url.c	Thu Dec 19 16:53:36 2002
@@ -97,6 +97,9 @@
 	
 	// look if the port is given
 	ptr2 = strstr(ptr1, ":");
+	if(ptr2 && (ptr3 = strstr(ptr2, "]"))) {
+		ptr2 = strstr(ptr3, ":");
+	}
 	// If the : is after the first / it isn't the port
 	ptr3 = strstr(ptr1, "/");
 	if(ptr3 && ptr3 - ptr2 < 0) ptr2 = NULL;
@@ -119,6 +122,10 @@
 		pos2 = ptr2-url;
 	}
 	// copy the hostname in the URL container
+	if( (*ptr1 == '[') && (*(ptr2-1) == ']') ) {
+		ptr1++;
+		pos2 -= 2;
+	}
 	Curl->hostname = (char*)malloc(pos2-pos1+1);
 	if( Curl->hostname==NULL ) {
 		mp_msg(MSGT_NETWORK,MSGL_FATAL,"Memory allocation failed!\n");
@@ -153,7 +160,7 @@
 		}
 		strcpy(Curl->file, "/");
 	}
-	
+
 	return Curl;
 }
 
