Browse Source

Quickly hack in DNS resolution as a proof of concept

tags/v0.9.3
Michael Brown 18 years ago
parent
commit
143d14614d
1 changed files with 22 additions and 6 deletions
  1. 22
    6
      src/net/tcp/http.c

+ 22
- 6
src/net/tcp/http.c View File

311
 	if ( ! path )
311
 	if ( ! path )
312
 		path = "/";
312
 		path = "/";
313
 
313
 
314
-	if ( ! host )
315
-		host = "";
316
-
317
 	len = snprintf ( buf, len,
314
 	len = snprintf ( buf, len,
318
 			 "GET %s HTTP/1.1\r\n"
315
 			 "GET %s HTTP/1.1\r\n"
319
 			 "User-Agent: gPXE/" VERSION "\r\n"
316
 			 "User-Agent: gPXE/" VERSION "\r\n"
386
  * @ret rc		Return status code
383
  * @ret rc		Return status code
387
  */
384
  */
388
 int http_get ( struct uri *uri, struct buffer *buffer, struct async *parent ) {
385
 int http_get ( struct uri *uri, struct buffer *buffer, struct async *parent ) {
389
-	struct http_request *http;
386
+	struct http_request *http = NULL;
390
 	int rc;
387
 	int rc;
391
 
388
 
389
+	/* Sanity check */
390
+	if ( ! uri->host ) {
391
+		rc = -EINVAL;
392
+		goto err;
393
+	}
394
+
392
 	/* Allocate and populate HTTP structure */
395
 	/* Allocate and populate HTTP structure */
393
 	http = malloc ( sizeof ( *http ) );
396
 	http = malloc ( sizeof ( *http ) );
394
 	if ( ! http ) {
397
 	if ( ! http ) {
408
 	server.sin.sin_port = htons ( HTTP_PORT );
411
 	server.sin.sin_port = htons ( HTTP_PORT );
409
 	server.sin.sin_family = AF_INET;
412
 	server.sin.sin_family = AF_INET;
410
 	if ( inet_aton ( uri->host, &server.sin.sin_addr ) == 0 ) {
413
 	if ( inet_aton ( uri->host, &server.sin.sin_addr ) == 0 ) {
411
-		rc = -EINVAL;
412
-		goto err;
414
+		/* Try DNS */
415
+		struct async async;
416
+		
417
+		extern int dns_resolv ( const char *name,
418
+					struct sockaddr_tcpip *st,
419
+					struct async *parent );
420
+		
421
+		async_init_orphan ( &async );
422
+		if ( ( rc = dns_resolv ( uri->host, &server.st,
423
+					 &async ) ) != 0 )
424
+			goto err;
425
+		async_wait ( &async, &rc, 1 );
426
+		if ( rc != 0 )
427
+			goto err;
413
 	}
428
 	}
429
+	
414
 
430
 
415
 	if ( ( rc = tcp_connect ( &http->tcp, &server.st, 0 ) ) != 0 )
431
 	if ( ( rc = tcp_connect ( &http->tcp, &server.st, 0 ) ) != 0 )
416
 		goto err;
432
 		goto err;

Loading…
Cancel
Save