Browse Source

fix resolve host name issue

git-svn-id: https://rt-thread.googlecode.com/svn/trunk@454 bbd45198-f89e-11dd-88c7-29a3b14d5316
bernard.xiong 15 years ago
parent
commit
9f58705a39
1 changed files with 7 additions and 3 deletions
  1. 7 3
      bsp/stm32_radio/http.c

+ 7 - 3
bsp/stm32_radio/http.c

@@ -156,7 +156,7 @@ int http_resolve_address(struct sockaddr_in *server, const char * url, char *hos
 		if (*url == ':')
 		{
 			unsigned char w;
-			for (w = 0; w < 5 && url[w] != '/' && url[w] != '\0'; w ++)
+			for (w = 0; w < 5 && url[w + 1] != '/' && url[w + 1] != '\0'; w ++)
 				port[w] = url[w + 1];
 			
 			/* get port ok */
@@ -165,6 +165,8 @@ int http_resolve_address(struct sockaddr_in *server, const char * url, char *hos
 			break;
 		}
 
+		if ((*url < '0' || *url > '9') && *url != '.')
+			is_domain = 1;
 		host_addr[i++] = *url;
 		url ++;
 	}
@@ -395,9 +397,9 @@ static int shoutcast_connect(struct shoutcast_session* session,
 
 		buf = rt_malloc (512);
 		if (*url)
-			length = rt_snprintf(buf, 512, _shoutcast_get, url, host_addr, server->sin_port);
+			length = rt_snprintf(buf, 512, _shoutcast_get, url, host_addr, ntohs(server->sin_port));
 		else
-			length = rt_snprintf(buf, 512, _shoutcast_get, "/", host_addr, server->sin_port);
+			length = rt_snprintf(buf, 512, _shoutcast_get, "/", host_addr, ntohs(server->sin_port));
 
 		rc = send(peer_handle, buf, length, 0);
 		rt_kprintf("SHOUTCAST request:\n%s", buf);
@@ -511,6 +513,8 @@ struct shoutcast_session* shoutcast_session_open(char* url)
 		return RT_NULL;
 	}
 
+	rt_kprintf("connect to: %s...\n", host_addr);
+
 	// Now we connect and initiate the transfer by sending a
 	// request header to the server, and receiving the response header
 	if((peer_handle = shoutcast_connect(session, &server, host_addr, request)) < 0)