david/ipxe
david
/
ipxe
Archived
1
0
Fork 0

Quickly hack in DNS resolution as a proof of concept

This commit is contained in:
Michael Brown 2007-01-15 17:32:52 +00:00
parent 9af12d5fba
commit 143d14614d
1 changed files with 22 additions and 6 deletions

View File

@ -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;