From 25ea34a8d75f637c4b4e80c4ec3891ddc56e80b0 Mon Sep 17 00:00:00 2001 From: Derek Pryor Date: Fri, 11 Aug 2006 14:13:02 +0000 Subject: New HTTP protocol and test code --- src/tests/dhcptest.c | 22 ++++++++++++++++++++++ src/tests/httptest.c | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+) create mode 100644 src/tests/httptest.c (limited to 'src/tests') diff --git a/src/tests/dhcptest.c b/src/tests/dhcptest.c index 47e0e8b48..38bbac371 100644 --- a/src/tests/dhcptest.c +++ b/src/tests/dhcptest.c @@ -57,6 +57,26 @@ static int test_dhcp_hello ( char *helloname ) { return 0; } +static int test_dhcp_http ( struct net_device *netdev, char *url ) { + union { + struct sockaddr_in sin; + struct sockaddr_tcpip st; + } target; + + memset ( &target, 0, sizeof ( target ) ); + target.sin.sin_family = AF_INET; + target.sin.sin_port = htons ( 80 ); + + char *addr = url + 7; // http:// + char *file = strchr(addr, '/'); + *file = '\0'; // for printf and inet_aton to work + printf("connecting to %s\n", addr); + inet_aton ( addr, &target.sin.sin_addr ); + *file = '/'; + test_http ( netdev, &target.st, file ); + return 0; +} + static int test_dhcp_tftp ( struct net_device *netdev, char *tftpname ) { union { struct sockaddr_in sin; @@ -79,6 +99,8 @@ static int test_dhcp_boot ( struct net_device *netdev, char *filename ) { return test_dhcp_iscsi_boot ( &filename[6] ); } else if ( strncmp ( filename, "hello:", 6 ) == 0 ) { return test_dhcp_hello ( &filename[6] ); + } else if ( strncmp ( filename, "http:", 5 ) == 0 ) { + return test_dhcp_http ( netdev, filename ); } else { return test_dhcp_tftp ( netdev, filename ); } diff --git a/src/tests/httptest.c b/src/tests/httptest.c new file mode 100644 index 000000000..4b569e854 --- /dev/null +++ b/src/tests/httptest.c @@ -0,0 +1,37 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "pxe.h" + +static void test_http_callback ( struct http_request *http, char *data, size_t len ) { + userptr_t pxe_buffer = real_to_user ( 0, 0x7c00 ); + unsigned long offset = http->file_recv; + http->file_recv += len; + copy_to_user ( pxe_buffer, offset, data, len ); +} + +void test_http ( struct net_device *netdev, struct sockaddr_tcpip *server, const char *filename ) { + struct http_request http; + int rc; + + memset ( &http, 0, sizeof ( http ) ); + memcpy ( &http.tcp.peer, server, sizeof ( http.tcp.peer ) ); + http.filename = filename; + http.callback = test_http_callback; + + rc = async_wait ( get_http ( &http ) ); + if ( rc ) { + printf ( "HTTP fetch failed\n" ); + } + + printf ( "Attempting PXE boot\n" ); + pxe_netdev = netdev; + rc = pxe_boot(); + printf ( "PXE NBP returned with status %04x\n", rc); +} -- cgit v1.2.3-55-g7522