summaryrefslogtreecommitdiffstats
path: root/src/net
diff options
context:
space:
mode:
authorMichael Brown2007-01-15 18:32:52 +0100
committerMichael Brown2007-01-15 18:32:52 +0100
commit143d14614d69cc3918a33930b2d609e0fb219305 (patch)
tree741e14a730d9b3a03d2e08c1db3581e71be0845e /src/net
parentA working DNS resolver (not yet tied in to anything) (diff)
downloadipxe-143d14614d69cc3918a33930b2d609e0fb219305.tar.gz
ipxe-143d14614d69cc3918a33930b2d609e0fb219305.tar.xz
ipxe-143d14614d69cc3918a33930b2d609e0fb219305.zip
Quickly hack in DNS resolution as a proof of concept
Diffstat (limited to 'src/net')
-rw-r--r--src/net/tcp/http.c28
1 files changed, 22 insertions, 6 deletions
diff --git a/src/net/tcp/http.c b/src/net/tcp/http.c
index 3ae7b1e95..966351cb1 100644
--- a/src/net/tcp/http.c
+++ b/src/net/tcp/http.c
@@ -311,9 +311,6 @@ static void http_senddata ( struct tcp_application *app,
if ( ! path )
path = "/";
- if ( ! host )
- host = "";
-
len = snprintf ( buf, len,
"GET %s HTTP/1.1\r\n"
"User-Agent: gPXE/" VERSION "\r\n"
@@ -386,9 +383,15 @@ static struct async_operations http_async_operations = {
* @ret rc Return status code
*/
int http_get ( struct uri *uri, struct buffer *buffer, struct async *parent ) {
- struct http_request *http;
+ struct http_request *http = NULL;
int rc;
+ /* Sanity check */
+ if ( ! uri->host ) {
+ rc = -EINVAL;
+ goto err;
+ }
+
/* Allocate and populate HTTP structure */
http = malloc ( sizeof ( *http ) );
if ( ! http ) {
@@ -408,9 +411,22 @@ int http_get ( struct uri *uri, struct buffer *buffer, struct async *parent ) {
server.sin.sin_port = htons ( HTTP_PORT );
server.sin.sin_family = AF_INET;
if ( inet_aton ( uri->host, &server.sin.sin_addr ) == 0 ) {
- rc = -EINVAL;
- goto err;
+ /* Try DNS */
+ struct async async;
+
+ extern int dns_resolv ( const char *name,
+ struct sockaddr_tcpip *st,
+ struct async *parent );
+
+ async_init_orphan ( &async );
+ if ( ( rc = dns_resolv ( uri->host, &server.st,
+ &async ) ) != 0 )
+ goto err;
+ async_wait ( &async, &rc, 1 );
+ if ( rc != 0 )
+ goto err;
}
+
if ( ( rc = tcp_connect ( &http->tcp, &server.st, 0 ) ) != 0 )
goto err;