Browse Source

loadkernel renamed to download_url, substantially restructured, and moved

to nic.c
tags/v0.9.3
Michael Brown 19 years ago
parent
commit
56825df041
1 changed files with 62 additions and 2 deletions
  1. 62
    2
      src/core/nic.c

+ 62
- 2
src/core/nic.c View File

@@ -16,6 +16,9 @@ Literature dealing with the network protocols:
16 16
 **************************************************************************/
17 17
 #include "etherboot.h"
18 18
 #include "console.h"
19
+#include "url.h"
20
+#include "proto.h"
21
+#include "resolv.h"
19 22
 #include "dev.h"
20 23
 #include "nic.h"
21 24
 #include "elf.h" /* FOR EM_CURRENT */
@@ -293,6 +296,62 @@ static int nic_configure ( struct type_dev *type_dev ) {
293 296
 }
294 297
 
295 298
 
299
+/*
300
+ * Download a file from the specified URL and process it with the
301
+ * specified function
302
+ *
303
+ */
304
+int download_url ( char *url,
305
+		   int ( * process ) ( unsigned char *data,
306
+				       unsigned int blocknum,
307
+				       unsigned int len, int eof ) ) {
308
+	struct url_info url_info;
309
+	struct protocol *proto;
310
+	struct sockaddr_in server;
311
+	
312
+	DBG ( "Loading %s\n", url );
313
+
314
+	/* Parse URL */
315
+	parse_url ( &url_info, url );
316
+	
317
+	/* Identify protocol */
318
+	proto = identify_protocol ( url_info.protocol );
319
+	if ( ! proto ) {
320
+		if ( url_info.protocol ) {
321
+			printf ( "Unknown protocol %s\n", url_info.protocol );
322
+		} else {
323
+			printf ( "No default protocols\n" );
324
+		}
325
+		goto error_out;
326
+	}
327
+
328
+	/* Resolve hostname */
329
+	server.sin_addr = arptable[ARP_SERVER].ipaddr;
330
+	if ( url_info.host ) {
331
+		if ( ! resolv ( &server.sin_addr, url_info.host ) ) {
332
+			printf ( "Cannot resolve host %s\n", url_info.host );
333
+			goto error_out;
334
+		}
335
+	}
336
+
337
+	/* Resolve port number */
338
+	server.sin_port = url_info.port ?
339
+		strtoul ( url_info.port, NULL, 10 ) : 0;
340
+
341
+	/* Restore URL */
342
+	unparse_url ( &url_info );
343
+
344
+	/* Call protocol's method to download the file */
345
+	return proto->load ( url, &server, process );
346
+
347
+ error_out:
348
+	unparse_url ( &url_info );
349
+	return 0;
350
+}
351
+
352
+
353
+
354
+
296 355
 /**************************************************************************
297 356
 LOAD - Try to get booted
298 357
 **************************************************************************/
@@ -300,7 +359,7 @@ static int nic_load ( struct type_dev *type_dev,
300 359
 		      int ( * process ) ( unsigned char *data,
301 360
 					  unsigned int blocknum,
302 361
 					  unsigned int size, int eof ) ) {
303
-	const char	*kernel;
362
+	char	*kernel;
304 363
 
305 364
 	/* Now use TFTP to load file */
306 365
 #ifdef	DOWNLOAD_PROTO_NFS
@@ -314,7 +373,7 @@ static int nic_load ( struct type_dev *type_dev,
314 373
 #endif
315 374
 		: KERNEL_BUF;
316 375
 	if ( kernel ) {
317
-		loadkernel(kernel,process); /* We don't return except on error */
376
+		download_url(kernel,process); /* We don't return except on error */
318 377
 		printf("Unable to load file.\n");
319 378
 	} else {	
320 379
 		printf("No filename\n");
@@ -1757,3 +1816,4 @@ long rfc1112_sleep_interval(long base, int exp)
1757 1816
 	return tmo;
1758 1817
 }
1759 1818
 #endif /* MULTICAST_LEVEL_2 */
1819
+

Loading…
Cancel
Save