Explorar el Código

Quickly hack in DNS resolution as a proof of concept

tags/v0.9.3
Michael Brown hace 18 años
padre
commit
143d14614d
Se han modificado 1 ficheros con 22 adiciones y 6 borrados
  1. 22
    6
      src/net/tcp/http.c

+ 22
- 6
src/net/tcp/http.c Ver fichero

@@ -311,9 +311,6 @@ static void http_senddata ( struct tcp_application *app,
311 311
 	if ( ! path )
312 312
 		path = "/";
313 313
 
314
-	if ( ! host )
315
-		host = "";
316
-
317 314
 	len = snprintf ( buf, len,
318 315
 			 "GET %s HTTP/1.1\r\n"
319 316
 			 "User-Agent: gPXE/" VERSION "\r\n"
@@ -386,9 +383,15 @@ static struct async_operations http_async_operations = {
386 383
  * @ret rc		Return status code
387 384
  */
388 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 387
 	int rc;
391 388
 
389
+	/* Sanity check */
390
+	if ( ! uri->host ) {
391
+		rc = -EINVAL;
392
+		goto err;
393
+	}
394
+
392 395
 	/* Allocate and populate HTTP structure */
393 396
 	http = malloc ( sizeof ( *http ) );
394 397
 	if ( ! http ) {
@@ -408,9 +411,22 @@ int http_get ( struct uri *uri, struct buffer *buffer, struct async *parent ) {
408 411
 	server.sin.sin_port = htons ( HTTP_PORT );
409 412
 	server.sin.sin_family = AF_INET;
410 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 431
 	if ( ( rc = tcp_connect ( &http->tcp, &server.st, 0 ) ) != 0 )
416 432
 		goto err;

Loading…
Cancelar
Guardar